user32/tests: Fix test failures when the low-level hook cannot be set.
[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 0x0600 /* For WM_CHANGEUISTATE,QS_RAWINPUT,WM_DWMxxxx */
24 #define WINVER 0x0600 /* for WM_GETTITLEBARINFOEX */
25
26 #include <assert.h>
27 #include <stdarg.h>
28 #include <stdio.h>
29
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winuser.h"
34 #include "winnls.h"
35
36 #include "wine/test.h"
37
38 #define MDI_FIRST_CHILD_ID 2004
39
40 /* undocumented SWP flags - from SDK 3.1 */
41 #define SWP_NOCLIENTSIZE        0x0800
42 #define SWP_NOCLIENTMOVE        0x1000
43 #define SWP_STATECHANGED        0x8000
44
45 #define SW_NORMALNA             0xCC    /* undoc. flag in MinMaximize */
46
47 #ifndef WM_KEYF1
48 #define WM_KEYF1 0x004d
49 #endif
50
51 #ifndef WM_SYSTIMER
52 #define WM_SYSTIMER         0x0118
53 #endif
54
55 #define WND_PARENT_ID           1
56 #define WND_POPUP_ID            2
57 #define WND_CHILD_ID            3
58
59 #ifndef WM_LBTRACKPOINT
60 #define WM_LBTRACKPOINT  0x0131
61 #endif
62
63 /* encoded DRAWITEMSTRUCT into an LPARAM */
64 typedef struct
65 {
66     union
67     {
68         struct
69         {
70             UINT type    : 4;  /* ODT_* flags */
71             UINT ctl_id  : 4;  /* Control ID */
72             UINT item_id : 4;  /* Menu item ID */
73             UINT action  : 4;  /* ODA_* flags */
74             UINT state   : 16; /* ODS_* flags */
75         } item;
76         LPARAM lp;
77     } u;
78 } DRAW_ITEM_STRUCT;
79
80 static BOOL test_DestroyWindow_flag;
81 static HWINEVENTHOOK hEvent_hook;
82 static HHOOK hKBD_hook;
83 static HHOOK hCBT_hook;
84 static DWORD cbt_hook_thread_id;
85
86 static const WCHAR testWindowClassW[] =
87 { 'T','e','s','t','W','i','n','d','o','w','C','l','a','s','s','W',0 };
88
89 /*
90 FIXME: add tests for these
91 Window Edge Styles (Win31/Win95/98 look), in order of precedence:
92  WS_EX_DLGMODALFRAME: double border, WS_CAPTION allowed
93  WS_THICKFRAME: thick border
94  WS_DLGFRAME: double border, WS_CAPTION not allowed (but possibly shown anyway)
95  WS_BORDER (default for overlapped windows): single black border
96  none (default for child (and popup?) windows): no border
97 */
98
99 typedef enum {
100     sent=0x1,
101     posted=0x2,
102     parent=0x4,
103     wparam=0x8,
104     lparam=0x10,
105     defwinproc=0x20,
106     beginpaint=0x40,
107     optional=0x80,
108     hook=0x100,
109     winevent_hook=0x200,
110     kbd_hook=0x400
111 } msg_flags_t;
112
113 struct message {
114     UINT message;          /* the WM_* code */
115     msg_flags_t flags;     /* message props */
116     WPARAM wParam;         /* expected value of wParam */
117     LPARAM lParam;         /* expected value of lParam */
118     WPARAM wp_mask;        /* mask for wParam checks */
119     LPARAM lp_mask;        /* mask for lParam checks */
120 };
121
122 struct recvd_message {
123     UINT message;          /* the WM_* code */
124     msg_flags_t flags;     /* message props */
125     HWND hwnd;             /* window that received the message */
126     WPARAM wParam;         /* expected value of wParam */
127     LPARAM lParam;         /* expected value of lParam */
128     int line;              /* source line where logged */
129     const char *descr;     /* description for trace output */
130     char output[512];      /* trace output */
131 };
132
133 /* Empty message sequence */
134 static const struct message WmEmptySeq[] =
135 {
136     { 0 }
137 };
138 /* CreateWindow (for overlapped window, not initially visible) (16/32) */
139 static const struct message WmCreateOverlappedSeq[] = {
140     { HCBT_CREATEWND, hook },
141     { WM_GETMINMAXINFO, sent },
142     { WM_NCCREATE, sent },
143     { WM_NCCALCSIZE, sent|wparam, 0 },
144     { 0x0093, sent|defwinproc|optional },
145     { 0x0094, sent|defwinproc|optional },
146     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
147     { WM_CREATE, sent },
148     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
149     { 0 }
150 };
151 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
152  * for a not visible overlapped window.
153  */
154 static const struct message WmSWP_ShowOverlappedSeq[] = {
155     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
156     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
157     { WM_NCPAINT, sent|wparam|optional, 1 },
158     { WM_GETTEXT, sent|defwinproc|optional },
159     { WM_ERASEBKGND, sent|optional },
160     { HCBT_ACTIVATE, hook },
161     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
162     { WM_NOTIFYFORMAT, sent|optional },
163     { WM_QUERYUISTATE, sent|optional },
164     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
165     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x: SWP_NOSENDCHANGING */
166     { WM_ACTIVATEAPP, sent|wparam, 1 },
167     { WM_NCACTIVATE, sent },
168     { WM_GETTEXT, sent|defwinproc|optional },
169     { WM_ACTIVATE, sent|wparam, 1 },
170     { HCBT_SETFOCUS, hook },
171     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
172     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
173     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
174     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
175     { WM_GETTEXT, sent|optional },
176     { WM_NCPAINT, sent|wparam|optional, 1 },
177     { WM_GETTEXT, sent|defwinproc|optional },
178     { WM_ERASEBKGND, sent|optional },
179     /* Win9x adds SWP_NOZORDER below */
180     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
181     { WM_GETTEXT, sent|optional },
182     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
183     { WM_NCPAINT, sent|wparam|optional, 1 },
184     { WM_ERASEBKGND, sent|optional },
185     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
186     { WM_SYNCPAINT, sent|optional },
187     { WM_GETTITLEBARINFOEX, sent|optional },
188     { WM_PAINT, sent|optional },
189     { WM_NCPAINT, sent|beginpaint|optional },
190     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
191     { WM_ERASEBKGND, sent|beginpaint|optional },
192     { 0 }
193 };
194 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
195  * for a visible overlapped window.
196  */
197 static const struct message WmSWP_HideOverlappedSeq[] = {
198     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
199     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
200     { HCBT_ACTIVATE, hook|optional },
201     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
202     { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
203     { WM_NCACTIVATE, sent|optional },
204     { WM_ACTIVATE, sent|optional },
205     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
206     { 0 }
207 };
208
209 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
210  * for a visible overlapped window.
211  */
212 static const struct message WmSWP_ResizeSeq[] = {
213     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
214     { WM_GETMINMAXINFO, sent|defwinproc },
215     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
216     { WM_NCPAINT, sent|optional },
217     { WM_GETTEXT, sent|defwinproc|optional },
218     { WM_ERASEBKGND, sent|optional },
219     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
220     { WM_SIZE, sent|defwinproc|optional },
221     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
222     { WM_NCPAINT, sent|optional },
223     { WM_GETTEXT, sent|defwinproc|optional },
224     { WM_ERASEBKGND, sent|optional },
225     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
226     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
227     { 0 }
228 };
229
230 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
231  * for a visible popup window.
232  */
233 static const struct message WmSWP_ResizePopupSeq[] = {
234     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
235     { WM_GETMINMAXINFO, sent|defwinproc|optional }, /* Win9x */
236     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
237     { WM_NCPAINT, sent|optional },
238     { WM_GETTEXT, sent|defwinproc|optional },
239     { WM_ERASEBKGND, sent|optional },
240     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
241     { WM_SIZE, sent|defwinproc|wparam|optional, SIZE_RESTORED },
242     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
243     { WM_NCPAINT, sent|optional },
244     { WM_GETTEXT, sent|defwinproc|optional },
245     { WM_ERASEBKGND, sent|optional },
246     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
247     { 0 }
248 };
249
250 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
251  * for a visible overlapped window.
252  */
253 static const struct message WmSWP_MoveSeq[] = {
254     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE },
255     { WM_NCPAINT, sent|optional },
256     { WM_GETTEXT, sent|defwinproc|optional },
257     { WM_ERASEBKGND, sent|optional },
258     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
259     { WM_MOVE, sent|defwinproc|wparam, 0 },
260     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
261     { 0 }
262 };
263 /* Resize with SetWindowPos(SWP_NOZORDER)
264  * for a visible overlapped window
265  * SWP_NOZORDER is stripped by the logging code
266  */
267 static const struct message WmSWP_ResizeNoZOrder[] = {
268     { WM_WINDOWPOSCHANGING, sent|wparam, /*SWP_NOZORDER|*/SWP_NOACTIVATE },
269     { WM_GETMINMAXINFO, sent|defwinproc },
270     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
271     { WM_NCPAINT, sent|optional },
272     { WM_GETTEXT, sent|defwinproc|optional },
273     { WM_ERASEBKGND, sent|optional },
274     { WM_WINDOWPOSCHANGED, sent|wparam|optional, /*SWP_NOZORDER|*/SWP_NOACTIVATE, 0,
275       SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
276     { WM_MOVE, sent|defwinproc|optional },
277     { WM_SIZE, sent|defwinproc|optional },
278     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
279     { WM_NCPAINT, sent|optional }, /* Win9x doesn't send it */
280     { WM_GETTEXT, sent|defwinproc|optional }, /* Win9x doesn't send it */
281     { WM_ERASEBKGND, sent|optional }, /* Win9x doesn't send it */
282     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
283     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
284     { 0 }
285 };
286
287 /* Switch visible mdi children */
288 static const struct message WmSwitchChild[] = {
289     /* Switch MDI child */
290     { WM_MDIACTIVATE, sent },/* in the MDI client */
291     { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 1st MDI child */
292     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
293     { WM_CHILDACTIVATE, sent },/* in the 1st MDI child */
294     /* Deactivate 2nd MDI child */
295     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
296     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
297     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
298     /* Preparing for maximize and maximaze the 1st MDI child */
299     { WM_GETMINMAXINFO, sent|defwinproc }, /* in the 1st MDI child */
300     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED }, /* in the 1st MDI child */
301     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
302     { WM_CHILDACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
303     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 1st MDI child */
304     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED }, /* in the 1st MDI child */
305     /* Lock redraw 2nd MDI child */
306     { WM_SETREDRAW, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
307     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
308     /* Restore 2nd MDI child */
309     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },/* in the 2nd MDI child */
310     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
311     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
312     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 2nd MDI child */
313     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED }, /* in the 2nd MDI child */
314     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
315     /* Redraw 2nd MDI child */
316     { WM_SETREDRAW, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
317     /* Redraw MDI frame */
318     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },/* in MDI frame */
319     { WM_NCCALCSIZE, sent|wparam, 1 },/* in MDI frame */
320     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in MDI frame */
321     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in MDI frame */
322     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
323     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
324     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
325     { HCBT_SETFOCUS, hook },
326     { WM_KILLFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
327     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },/* in the 1st MDI child */
328     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
329     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
330     { WM_SETFOCUS, sent },/* in the MDI client */
331     { HCBT_SETFOCUS, hook },
332     { WM_KILLFOCUS, sent },/* in the MDI client */
333     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
334     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 }, /* in the 1st MDI child */
335     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
336     { WM_SETFOCUS, sent|defwinproc }, /* in the 1st MDI child */
337     { WM_MDIACTIVATE, sent|defwinproc },/* in the 1st MDI child */
338     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* in the 1st MDI child */
339     { 0 }
340 };
341
342 /* Switch visible not maximized mdi children */
343 static const struct message WmSwitchNotMaximizedChild[] = {
344     /* Switch not maximized MDI child */
345     { WM_MDIACTIVATE, sent },/* in the MDI client */
346     { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 2nd MDI child */
347     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
348     { WM_CHILDACTIVATE, sent },/* in the 2nd MDI child */
349     /* Deactivate 1st MDI child */
350     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
351     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
352     /* Activate 2nd MDI child */
353     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE}, /* in the 2nd MDI child */
354     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 2nd MDI child */
355     { HCBT_SETFOCUS, hook }, /* in the 1st MDI child */
356     { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
357     { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
358     { WM_IME_SETCONTEXT, sent|optional }, /* in the  MDI client */
359     { WM_SETFOCUS, sent, 0 }, /* in the  MDI client */
360     { HCBT_SETFOCUS, hook },
361     { WM_KILLFOCUS, sent }, /* in the  MDI client */
362     { WM_IME_SETCONTEXT, sent|optional }, /* in the  MDI client */
363     { WM_IME_SETCONTEXT, sent|defwinproc|optional  }, /* in the 1st MDI child */
364     { WM_SETFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
365     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
366     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in the 2nd MDI child */
367     { 0 }
368 };
369
370
371 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
372                 SWP_NOZORDER|SWP_FRAMECHANGED)
373  * for a visible overlapped window with WS_CLIPCHILDREN style set.
374  */
375 static const struct message WmSWP_FrameChanged_clip[] = {
376     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
377     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
378     { WM_NCPAINT, sent|parent|optional }, /* wparam != 1 */
379     { WM_GETTEXT, sent|parent|defwinproc|optional },
380     { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
381     { WM_NCPAINT, sent }, /* wparam != 1 */
382     { WM_ERASEBKGND, sent },
383     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
384     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
385     { WM_PAINT, sent },
386     { 0 }
387 };
388 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|
389                 SWP_NOZORDER|SWP_FRAMECHANGED)
390  * for a visible overlapped window.
391  */
392 static const struct message WmSWP_FrameChangedDeferErase[] = {
393     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
394     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
395     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
396     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
397     { WM_PAINT, sent|parent|optional },
398     { WM_NCPAINT, sent|beginpaint|parent|optional }, /* wparam != 1 */
399     { WM_GETTEXT, sent|beginpaint|parent|defwinproc|optional },
400     { WM_PAINT, sent },
401     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
402     { WM_ERASEBKGND, sent|beginpaint|optional },
403     { 0 }
404 };
405
406 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
407                 SWP_NOZORDER|SWP_FRAMECHANGED)
408  * for a visible overlapped window without WS_CLIPCHILDREN style set.
409  */
410 static const struct message WmSWP_FrameChanged_noclip[] = {
411     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
412     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
413     { WM_NCPAINT, sent|parent|optional }, /* wparam != 1 */
414     { WM_GETTEXT, sent|parent|defwinproc|optional },
415     { WM_ERASEBKGND, sent|parent|optional },
416     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
417     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
418     { WM_PAINT, sent },
419     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
420     { WM_ERASEBKGND, sent|beginpaint|optional },
421     { 0 }
422 };
423
424 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
425 static const struct message WmShowOverlappedSeq[] = {
426     { WM_SHOWWINDOW, sent|wparam, 1 },
427     { WM_NCPAINT, sent|wparam|optional, 1 },
428     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
429     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
430     { WM_NCPAINT, sent|wparam|optional, 1 },
431     { WM_GETTEXT, sent|defwinproc|optional },
432     { WM_ERASEBKGND, sent|optional },
433     { HCBT_ACTIVATE, hook },
434     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
435     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
436     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
437     { WM_NCPAINT, sent|wparam|optional, 1 },
438     { WM_ACTIVATEAPP, sent|wparam, 1 },
439     { WM_NCACTIVATE, sent|wparam, 1 },
440     { WM_GETTEXT, sent|defwinproc|optional },
441     { WM_ACTIVATE, sent|wparam, 1 },
442     { HCBT_SETFOCUS, hook },
443     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
444     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
445     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
446     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
447     { WM_GETTEXT, sent|optional },
448     { WM_NCPAINT, sent|wparam|optional, 1 },
449     { WM_GETTEXT, sent|defwinproc|optional },
450     { WM_ERASEBKGND, sent|optional },
451     /* Win9x adds SWP_NOZORDER below */
452     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
453     { WM_NCCALCSIZE, sent|optional },
454     { WM_GETTEXT, sent|optional },
455     { WM_NCPAINT, sent|optional },
456     { WM_ERASEBKGND, sent|optional },
457     { WM_SYNCPAINT, sent|optional },
458 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
459        * messages. Does that mean that CreateWindow doesn't set initial
460        * window dimensions for overlapped windows?
461        */
462     { WM_SIZE, sent },
463     { WM_MOVE, sent },
464 #endif
465     { WM_PAINT, sent|optional },
466     { WM_NCPAINT, sent|beginpaint|optional },
467     { 0 }
468 };
469 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible overlapped window */
470 static const struct message WmShowMaxOverlappedSeq[] = {
471     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
472     { WM_GETMINMAXINFO, sent },
473     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
474     { WM_GETMINMAXINFO, sent|defwinproc },
475     { WM_NCCALCSIZE, sent|wparam, TRUE },
476     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
477     { HCBT_ACTIVATE, hook },
478     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
479     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
480     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
481     { WM_ACTIVATEAPP, sent|wparam, 1 },
482     { WM_NCACTIVATE, sent|wparam, 1 },
483     { WM_GETTEXT, sent|defwinproc|optional },
484     { WM_ACTIVATE, sent|wparam, 1 },
485     { HCBT_SETFOCUS, hook },
486     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
487     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
488     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
489     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
490     { WM_GETTEXT, sent|optional },
491     { WM_NCPAINT, sent|wparam|optional, 1 },
492     { WM_GETTEXT, sent|defwinproc|optional },
493     { WM_ERASEBKGND, sent|optional },
494     /* Win9x adds SWP_NOZORDER below */
495     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
496     { WM_MOVE, sent|defwinproc },
497     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
498     { WM_GETTEXT, sent|optional },
499     { WM_NCCALCSIZE, sent|optional },
500     { WM_NCPAINT, sent|optional },
501     { WM_ERASEBKGND, sent|optional },
502     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
503     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
504     { WM_SYNCPAINT, sent|optional },
505     { WM_GETTITLEBARINFOEX, sent|optional },
506     { WM_PAINT, sent|optional },
507     { WM_NCPAINT, sent|beginpaint|optional },
508     { WM_ERASEBKGND, sent|beginpaint|optional },
509     { 0 }
510 };
511 /* ShowWindow(SW_RESTORE) for a not visible maximized overlapped window */
512 static const struct message WmShowRestoreMaxOverlappedSeq[] = {
513     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
514     { WM_GETTEXT, sent|optional },
515     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
516     { WM_GETMINMAXINFO, sent|defwinproc },
517     { WM_NCCALCSIZE, sent|wparam, TRUE },
518     { WM_NCPAINT, sent|optional },
519     { WM_GETTEXT, sent|defwinproc|optional },
520     { WM_ERASEBKGND, sent|optional },
521     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
522     { WM_MOVE, sent|defwinproc|optional },
523     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
524     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
525     { WM_NCPAINT, sent|optional },
526     { WM_ERASEBKGND, sent|optional },
527     { WM_PAINT, sent|optional },
528     { WM_GETTITLEBARINFOEX, sent|optional },
529     { WM_NCPAINT, sent|beginpaint|optional },
530     { WM_ERASEBKGND, sent|beginpaint|optional },
531     { 0 }
532 };
533 /* ShowWindow(SW_RESTORE) for a not visible minimized overlapped window */
534 static const struct message WmShowRestoreMinOverlappedSeq[] = {
535     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
536     { WM_QUERYOPEN, sent|optional },
537     { WM_GETTEXT, sent|optional },
538     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED|SWP_NOCOPYBITS },
539     { WM_GETMINMAXINFO, sent|defwinproc },
540     { WM_NCCALCSIZE, sent|wparam, TRUE },
541     { HCBT_ACTIVATE, hook },
542     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
543     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
544     { WM_ACTIVATEAPP, sent|wparam, 1 },
545     { WM_NCACTIVATE, sent|wparam, 1 },
546     { WM_GETTEXT, sent|defwinproc|optional },
547     { WM_ACTIVATE, sent|wparam, 1 },
548     { HCBT_SETFOCUS, hook },
549     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
550     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
551     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
552     { WM_GETTEXT, sent|optional },
553     { WM_NCPAINT, sent|wparam|optional, 1 },
554     { WM_GETTEXT, sent|defwinproc|optional },
555     { WM_ERASEBKGND, sent },
556     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_STATECHANGED|SWP_FRAMECHANGED|SWP_NOCOPYBITS },
557     { WM_MOVE, sent|defwinproc },
558     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
559     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
560     { WM_NCPAINT, sent|wparam|optional, 1 },
561     { WM_ERASEBKGND, sent|optional },
562     { WM_ACTIVATE, sent|wparam, 1 },
563     { WM_GETTEXT, sent|optional },
564     { WM_PAINT, sent|optional },
565     { WM_GETTITLEBARINFOEX, sent|optional },
566     { WM_NCPAINT, sent|beginpaint|optional },
567     { WM_ERASEBKGND, sent|beginpaint|optional },
568     { 0 }
569 };
570 /* ShowWindow(SW_SHOWMINIMIZED) for a not visible overlapped window */
571 static const struct message WmShowMinOverlappedSeq[] = {
572     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
573     { HCBT_SETFOCUS, hook },
574     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
575     { WM_KILLFOCUS, sent },
576     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
577     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
578     { WM_GETTEXT, sent|optional },
579     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCOPYBITS|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
580     { WM_GETMINMAXINFO, sent|defwinproc },
581     { WM_NCCALCSIZE, sent|wparam, TRUE },
582     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
583     { WM_NCPAINT, sent|optional },
584     { WM_GETTEXT, sent|defwinproc|optional },
585     { WM_WINDOWPOSCHANGED, sent },
586     { WM_MOVE, sent|defwinproc },
587     { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
588     { WM_NCCALCSIZE, sent|optional },
589     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
590     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
591     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
592     { WM_NCACTIVATE, sent|wparam, 0 },
593     { WM_GETTEXT, sent|defwinproc|optional },
594     { WM_ACTIVATE, sent },
595     { WM_ACTIVATEAPP, sent|wparam, 0 },
596
597     /* Vista sometimes restores the window right away... */
598     { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
599     { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
600     { HCBT_MINMAX, hook|optional|lparam, 0, SW_RESTORE },
601     { WM_QUERYOPEN, sent|optional },
602     { WM_WINDOWPOSCHANGING, sent|optional|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
603     { WM_GETMINMAXINFO, sent|optional|defwinproc },
604     { WM_NCCALCSIZE, sent|optional|wparam, TRUE },
605     { HCBT_ACTIVATE, hook|optional },
606     { WM_ACTIVATEAPP, sent|optional|wparam, 1 },
607     { WM_NCACTIVATE, sent|optional },
608     { WM_GETTEXT, sent|optional },
609     { WM_ACTIVATE, sent|optional|wparam, 1 },
610     { HCBT_SETFOCUS, hook|optional },
611     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
612     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
613     { WM_SETFOCUS, sent|optional },
614     { WM_NCPAINT, sent|optional },
615     { WM_GETTEXT, sent|defwinproc|optional },
616     { WM_ERASEBKGND, sent|optional },
617     { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
618     { WM_MOVE, sent|defwinproc|optional },
619     { WM_SIZE, sent|defwinproc|optional|wparam, SIZE_RESTORED },
620     { WM_ACTIVATE, sent|optional|wparam, 1 },
621     { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
622     { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
623
624     { WM_PAINT, sent|optional },
625     { WM_NCPAINT, sent|beginpaint|optional },
626     { WM_ERASEBKGND, sent|beginpaint|optional },
627     { 0 }
628 };
629 /* ShowWindow(SW_HIDE) for a visible overlapped window */
630 static const struct message WmHideOverlappedSeq[] = {
631     { WM_SHOWWINDOW, sent|wparam, 0 },
632     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
633     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
634     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
635     { WM_SIZE, sent|optional }, /* XP doesn't send it */
636     { WM_MOVE, sent|optional }, /* XP doesn't send it */
637     { WM_NCACTIVATE, sent|wparam|optional, 0 },
638     { WM_ACTIVATE, sent|wparam|optional, 0 },
639     { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
640     { HCBT_SETFOCUS, hook|optional },
641     { WM_KILLFOCUS, sent|wparam, 0 },
642     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
643     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
644     { 0 }
645 };
646 /* DestroyWindow for a visible overlapped window */
647 static const struct message WmDestroyOverlappedSeq[] = {
648     { HCBT_DESTROYWND, hook },
649     { 0x0090, sent|optional },
650     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
651     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
652     { 0x0090, sent|optional },
653     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
654     { WM_NCACTIVATE, sent|optional|wparam, 0 },
655     { WM_ACTIVATE, sent|optional },
656     { WM_ACTIVATEAPP, sent|optional|wparam, 0 },
657     { WM_KILLFOCUS, sent|optional|wparam, 0 },
658     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
659     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
660     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
661     { WM_DESTROY, sent },
662     { WM_NCDESTROY, sent },
663     { 0 }
664 };
665 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
666 static const struct message WmCreateMaxPopupSeq[] = {
667     { HCBT_CREATEWND, hook },
668     { WM_NCCREATE, sent },
669     { WM_NCCALCSIZE, sent|wparam, 0 },
670     { WM_CREATE, sent },
671     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
672     { WM_SIZE, sent|wparam, SIZE_RESTORED },
673     { WM_MOVE, sent },
674     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
675     { WM_GETMINMAXINFO, sent },
676     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
677     { WM_NCCALCSIZE, sent|wparam, TRUE },
678     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
679     { WM_MOVE, sent|defwinproc },
680     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
681     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
682     { WM_SHOWWINDOW, sent|wparam, 1 },
683     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
684     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
685     { HCBT_ACTIVATE, hook },
686     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
687     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
688     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
689     { WM_NCPAINT, sent|wparam|optional, 1 },
690     { WM_ERASEBKGND, sent|optional },
691     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_NOMOVE|SWP_NOSIZE },
692     { WM_ACTIVATEAPP, sent|wparam, 1 },
693     { WM_NCACTIVATE, sent },
694     { WM_ACTIVATE, sent|wparam, 1 },
695     { HCBT_SETFOCUS, hook },
696     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
697     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
698     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
699     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
700     { WM_GETTEXT, sent|optional },
701     { WM_SYNCPAINT, sent|wparam|optional, 4 },
702     { WM_NCPAINT, sent|wparam|optional, 1 },
703     { WM_ERASEBKGND, sent|optional },
704     { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
705     { WM_ERASEBKGND, sent|defwinproc|optional },
706     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
707     { 0 }
708 };
709 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
710 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
711     { HCBT_CREATEWND, hook },
712     { WM_NCCREATE, sent },
713     { WM_NCCALCSIZE, sent|wparam, 0 },
714     { WM_CREATE, sent },
715     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
716     { WM_SIZE, sent|wparam, SIZE_RESTORED },
717     { WM_MOVE, sent },
718     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
719     { WM_GETMINMAXINFO, sent },
720     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED  },
721     { WM_NCCALCSIZE, sent|wparam, TRUE },
722     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
723     { WM_MOVE, sent|defwinproc },
724     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
725     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
726     { 0 }
727 };
728 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
729 static const struct message WmShowMaxPopupResizedSeq[] = {
730     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
731     { WM_GETMINMAXINFO, sent },
732     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
733     { WM_NCCALCSIZE, sent|wparam, TRUE },
734     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
735     { HCBT_ACTIVATE, hook },
736     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
737     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
738     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
739     { WM_NCPAINT, sent|wparam|optional, 1 },
740     { WM_ERASEBKGND, sent|optional },
741     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
742     { WM_ACTIVATEAPP, sent|wparam, 1 },
743     { WM_NCACTIVATE, sent },
744     { WM_ACTIVATE, sent|wparam, 1 },
745     { HCBT_SETFOCUS, hook },
746     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
747     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
748     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
749     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
750     { WM_GETTEXT, sent|optional },
751     { WM_NCPAINT, sent|wparam|optional, 1 },
752     { WM_ERASEBKGND, sent|optional },
753     { WM_WINDOWPOSCHANGED, sent },
754     /* WinNT4.0 sends WM_MOVE */
755     { WM_MOVE, sent|defwinproc|optional },
756     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
757     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
758     { 0 }
759 };
760 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
761 static const struct message WmShowMaxPopupSeq[] = {
762     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
763     { WM_GETMINMAXINFO, sent },
764     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
765     { WM_NCCALCSIZE, sent|wparam, TRUE },
766     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
767     { HCBT_ACTIVATE, hook },
768     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
769     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
770     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
771     { WM_ACTIVATEAPP, sent|wparam, 1 },
772     { WM_NCACTIVATE, sent },
773     { WM_ACTIVATE, sent|wparam, 1 },
774     { HCBT_SETFOCUS, hook },
775     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
776     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
777     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
778     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
779     { WM_GETTEXT, sent|optional },
780     { WM_SYNCPAINT, sent|wparam|optional, 4 },
781     { WM_NCPAINT, sent|wparam|optional, 1 },
782     { WM_ERASEBKGND, sent|optional },
783     { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
784     { WM_ERASEBKGND, sent|defwinproc|optional },
785     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
786     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
787     { 0 }
788 };
789 /* CreateWindow(WS_VISIBLE) for popup window */
790 static const struct message WmCreatePopupSeq[] = {
791     { HCBT_CREATEWND, hook },
792     { WM_NCCREATE, sent },
793     { WM_NCCALCSIZE, sent|wparam, 0 },
794     { WM_CREATE, sent },
795     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
796     { WM_SIZE, sent|wparam, SIZE_RESTORED },
797     { WM_MOVE, sent },
798     { WM_SHOWWINDOW, sent|wparam, 1 },
799     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
800     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
801     { HCBT_ACTIVATE, hook },
802     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
803     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
804     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
805     { WM_NCPAINT, sent|wparam|optional, 1 },
806     { WM_ERASEBKGND, sent|optional },
807     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
808     { WM_ACTIVATEAPP, sent|wparam, 1 },
809     { WM_NCACTIVATE, sent },
810     { WM_ACTIVATE, sent|wparam, 1 },
811     { HCBT_SETFOCUS, hook },
812     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
813     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
814     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
815     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
816     { WM_GETTEXT, sent|optional },
817     { WM_SYNCPAINT, sent|wparam|optional, 4 },
818     { WM_NCPAINT, sent|wparam|optional, 1 },
819     { WM_ERASEBKGND, sent|optional },
820     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
821     { 0 }
822 };
823 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
824 static const struct message WmShowVisMaxPopupSeq[] = {
825     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
826     { WM_GETMINMAXINFO, sent },
827     { WM_GETTEXT, sent|optional },
828     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
829     { WM_GETTEXT, sent|optional },
830     { WM_NCCALCSIZE, sent|wparam, TRUE },
831     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
832     { WM_NCPAINT, sent|wparam|optional, 1 },
833     { WM_ERASEBKGND, sent|optional },
834     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
835     { WM_MOVE, sent|defwinproc },
836     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
837     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
838     { 0 }
839 };
840 /* CreateWindow (for a child popup window, not initially visible) */
841 static const struct message WmCreateChildPopupSeq[] = {
842     { HCBT_CREATEWND, hook },
843     { WM_NCCREATE, sent }, 
844     { WM_NCCALCSIZE, sent|wparam, 0 },
845     { WM_CREATE, sent },
846     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
847     { WM_SIZE, sent|wparam, SIZE_RESTORED },
848     { WM_MOVE, sent },
849     { 0 }
850 };
851 /* CreateWindow (for a popup window, not initially visible,
852  * which sets WS_VISIBLE in WM_CREATE handler)
853  */
854 static const struct message WmCreateInvisiblePopupSeq[] = {
855     { HCBT_CREATEWND, hook },
856     { WM_NCCREATE, sent }, 
857     { WM_NCCALCSIZE, sent|wparam, 0 },
858     { WM_CREATE, sent },
859     { WM_STYLECHANGING, sent },
860     { WM_STYLECHANGED, sent },
861     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
862     { WM_SIZE, sent|wparam, SIZE_RESTORED },
863     { WM_MOVE, sent },
864     { 0 }
865 };
866 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
867  * for a popup window with WS_VISIBLE style set
868  */
869 static const struct message WmShowVisiblePopupSeq_2[] = {
870     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
871     { 0 }
872 };
873 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
874  * for a popup window with WS_VISIBLE style set
875  */
876 static const struct message WmShowVisiblePopupSeq_3[] = {
877     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
878     { HCBT_ACTIVATE, hook },
879     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
880     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
881     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
882     { WM_NCACTIVATE, sent },
883     { WM_ACTIVATE, sent|wparam, 1 },
884     { HCBT_SETFOCUS, hook },
885     { WM_KILLFOCUS, sent|parent },
886     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
887     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
888     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
889     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
890     { WM_SETFOCUS, sent|defwinproc },
891     { WM_GETTEXT, sent|optional },
892     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_SHOWWINDOW },
893     { 0 }
894 };
895 /* CreateWindow (for child window, not initially visible) */
896 static const struct message WmCreateChildSeq[] = {
897     { HCBT_CREATEWND, hook },
898     { WM_NCCREATE, sent }, 
899     /* child is inserted into parent's child list after WM_NCCREATE returns */
900     { WM_NCCALCSIZE, sent|wparam, 0 },
901     { WM_CREATE, sent },
902     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
903     { WM_SIZE, sent|wparam, SIZE_RESTORED },
904     { WM_MOVE, sent },
905     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
906     { 0 }
907 };
908 /* CreateWindow (for maximized child window, not initially visible) */
909 static const struct message WmCreateMaximizedChildSeq[] = {
910     { HCBT_CREATEWND, hook },
911     { WM_NCCREATE, sent }, 
912     { WM_NCCALCSIZE, sent|wparam, 0 },
913     { WM_CREATE, sent },
914     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
915     { WM_SIZE, sent|wparam, SIZE_RESTORED },
916     { WM_MOVE, sent },
917     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
918     { WM_GETMINMAXINFO, sent },
919     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
920     { WM_NCCALCSIZE, sent|wparam, 1 },
921     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
922     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
923     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
924     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
925     { 0 }
926 };
927 /* CreateWindow (for a child window, initially visible) */
928 static const struct message WmCreateVisibleChildSeq[] = {
929     { HCBT_CREATEWND, hook },
930     { WM_NCCREATE, sent }, 
931     /* child is inserted into parent's child list after WM_NCCREATE returns */
932     { WM_NCCALCSIZE, sent|wparam, 0 },
933     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
934     { WM_CREATE, sent },
935     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
936     { WM_SIZE, sent|wparam, SIZE_RESTORED },
937     { WM_MOVE, sent },
938     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
939     { WM_SHOWWINDOW, sent|wparam, 1 },
940     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
941     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
942     { WM_ERASEBKGND, sent|parent|optional },
943     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
944     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
945     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
946     { 0 }
947 };
948 /* ShowWindow(SW_SHOW) for a not visible child window */
949 static const struct message WmShowChildSeq[] = {
950     { WM_SHOWWINDOW, sent|wparam, 1 },
951     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
952     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
953     { WM_ERASEBKGND, sent|parent|optional },
954     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
955     { 0 }
956 };
957 /* ShowWindow(SW_HIDE) for a visible child window */
958 static const struct message WmHideChildSeq[] = {
959     { WM_SHOWWINDOW, sent|wparam, 0 },
960     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
961     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
962     { WM_ERASEBKGND, sent|parent|optional },
963     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
964     { 0 }
965 };
966 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
967 static const struct message WmHideChildSeq2[] = {
968     { WM_SHOWWINDOW, sent|wparam, 0 },
969     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
970     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
971     { WM_ERASEBKGND, sent|parent|optional },
972     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
973     { 0 }
974 };
975 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
976  * for a not visible child window
977  */
978 static const struct message WmShowChildSeq_2[] = {
979     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
980     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
981     { WM_CHILDACTIVATE, sent },
982     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
983     { 0 }
984 };
985 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
986  * for a not visible child window
987  */
988 static const struct message WmShowChildSeq_3[] = {
989     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
990     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
991     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
992     { 0 }
993 };
994 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
995  * for a visible child window with a caption
996  */
997 static const struct message WmShowChildSeq_4[] = {
998     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
999     { WM_CHILDACTIVATE, sent },
1000     { 0 }
1001 };
1002 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
1003 static const struct message WmShowChildInvisibleParentSeq_1[] = {
1004     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
1005     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
1006     { WM_NCCALCSIZE, sent|wparam, 1 },
1007     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1008     { WM_CHILDACTIVATE, sent|optional },
1009     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
1010     { WM_MOVE, sent|defwinproc },
1011     { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1012     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1013     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1014     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1015     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1016     { WM_GETTEXT, sent|optional },
1017     { 0 }
1018 };
1019 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
1020 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
1021     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
1022     { 0 }
1023 };
1024 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1025 static const struct message WmShowChildInvisibleParentSeq_2[] = {
1026     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1027     { WM_GETMINMAXINFO, sent },
1028     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
1029     { WM_NCCALCSIZE, sent|wparam, 1 },
1030     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1031     { WM_CHILDACTIVATE, sent },
1032     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
1033     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
1034     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1035     { 0 }
1036 };
1037 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1038 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
1039     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1040     { 0 }
1041 };
1042 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1043 static const struct message WmShowChildInvisibleParentSeq_3[] = {
1044     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1045     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
1046     { WM_NCCALCSIZE, sent|wparam, 1 },
1047     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1048     { WM_CHILDACTIVATE, sent },
1049     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1050     { WM_MOVE, sent|defwinproc },
1051     { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1052     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1053     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1054     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1055     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1056     { WM_GETTEXT, sent|optional },
1057     { 0 }
1058 };
1059 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1060 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
1061     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1062     { 0 }
1063 };
1064 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1065 static const struct message WmShowChildInvisibleParentSeq_4[] = {
1066     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1067     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
1068     { WM_NCCALCSIZE, sent|wparam, 1 },
1069     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1070     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1071     { WM_MOVE, sent|defwinproc },
1072     { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1073     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1074     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1075     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1076     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1077     { WM_GETTEXT, sent|optional },
1078     { 0 }
1079 };
1080 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1081 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
1082     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1083     { 0 }
1084 };
1085 /* ShowWindow(SW_SHOW) for child with invisible parent */
1086 static const struct message WmShowChildInvisibleParentSeq_5[] = {
1087     { WM_SHOWWINDOW, sent|wparam, 1 },
1088     { 0 }
1089 };
1090 /* ShowWindow(SW_HIDE) for child with invisible parent */
1091 static const struct message WmHideChildInvisibleParentSeq[] = {
1092     { WM_SHOWWINDOW, sent|wparam, 0 },
1093     { 0 }
1094 };
1095 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
1096 static const struct message WmShowChildInvisibleParentSeq_6[] = {
1097     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1098     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1099     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1100     { 0 }
1101 };
1102 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
1103 static const struct message WmHideChildInvisibleParentSeq_2[] = {
1104     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1105     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1106     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1107     { 0 }
1108 };
1109 /* DestroyWindow for a visible child window */
1110 static const struct message WmDestroyChildSeq[] = {
1111     { HCBT_DESTROYWND, hook },
1112     { 0x0090, sent|optional },
1113     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1114     { WM_SHOWWINDOW, sent|wparam, 0 },
1115     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1116     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1117     { WM_ERASEBKGND, sent|parent|optional },
1118     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1119     { HCBT_SETFOCUS, hook }, /* set focus to a parent */
1120     { WM_KILLFOCUS, sent },
1121     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1122     { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
1123     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1124     { WM_SETFOCUS, sent|parent },
1125     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1126     { WM_DESTROY, sent },
1127     { WM_DESTROY, sent|optional }, /* some other (IME?) window */
1128     { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
1129     { WM_NCDESTROY, sent },
1130     { 0 }
1131 };
1132 /* visible child window destroyed by thread exit */
1133 static const struct message WmExitThreadSeq[] = {
1134     { WM_NCDESTROY, sent },  /* actually in grandchild */
1135     { WM_PAINT, sent|parent },
1136     { WM_ERASEBKGND, sent|parent|beginpaint },
1137     { 0 }
1138 };
1139 /* DestroyWindow for a visible child window with invisible parent */
1140 static const struct message WmDestroyInvisibleChildSeq[] = {
1141     { HCBT_DESTROYWND, hook },
1142     { 0x0090, sent|optional },
1143     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1144     { WM_SHOWWINDOW, sent|wparam, 0 },
1145     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1146     { WM_DESTROY, sent },
1147     { WM_NCDESTROY, sent },
1148     { 0 }
1149 };
1150 /* Moving the mouse in nonclient area */
1151 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
1152     { WM_NCHITTEST, sent },
1153     { WM_SETCURSOR, sent },
1154     { WM_NCMOUSEMOVE, posted },
1155     { 0 }
1156 };
1157 /* Moving the mouse in client area */
1158 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
1159     { WM_NCHITTEST, sent },
1160     { WM_SETCURSOR, sent },
1161     { WM_MOUSEMOVE, posted },
1162     { 0 }
1163 };
1164 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1165 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
1166     { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
1167     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
1168     { WM_GETMINMAXINFO, sent|defwinproc },
1169     { WM_ENTERSIZEMOVE, sent|defwinproc },
1170     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1171     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1172     { WM_MOVE, sent|defwinproc },
1173     { WM_EXITSIZEMOVE, sent|defwinproc },
1174     { 0 }
1175 };
1176 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1177 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
1178     { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
1179     { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
1180     { WM_GETMINMAXINFO, sent|defwinproc },
1181     { WM_ENTERSIZEMOVE, sent|defwinproc },
1182     { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
1183     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1184     { WM_GETMINMAXINFO, sent|defwinproc },
1185     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1186     { WM_NCPAINT, sent|defwinproc|wparam, 1 },
1187     { WM_GETTEXT, sent|defwinproc },
1188     { WM_ERASEBKGND, sent|defwinproc },
1189     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1190     { WM_MOVE, sent|defwinproc },
1191     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1192     { WM_EXITSIZEMOVE, sent|defwinproc },
1193     { 0 }
1194 };
1195 /* Resizing child window with MoveWindow (32) */
1196 static const struct message WmResizingChildWithMoveWindowSeq[] = {
1197     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1198     { WM_NCCALCSIZE, sent|wparam, 1 },
1199     { WM_ERASEBKGND, sent|parent|optional },
1200     { WM_ERASEBKGND, sent|optional },
1201     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
1202     { WM_MOVE, sent|defwinproc },
1203     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1204     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1205     { 0 }
1206 };
1207 /* Clicking on inactive button */
1208 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
1209     { WM_NCHITTEST, sent },
1210     { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
1211     { WM_MOUSEACTIVATE, sent },
1212     { WM_MOUSEACTIVATE, sent|parent|defwinproc },
1213     { WM_SETCURSOR, sent },
1214     { WM_SETCURSOR, sent|parent|defwinproc },
1215     { WM_LBUTTONDOWN, posted },
1216     { WM_KILLFOCUS, posted|parent },
1217     { WM_SETFOCUS, posted },
1218     { WM_CTLCOLORBTN, posted|parent },
1219     { BM_SETSTATE, posted },
1220     { WM_CTLCOLORBTN, posted|parent },
1221     { WM_LBUTTONUP, posted },
1222     { BM_SETSTATE, posted },
1223     { WM_CTLCOLORBTN, posted|parent },
1224     { WM_COMMAND, posted|parent },
1225     { 0 }
1226 };
1227 /* Reparenting a button (16/32) */
1228 /* The last child (button) reparented gets topmost for its new parent. */
1229 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
1230     { WM_SHOWWINDOW, sent|wparam, 0 },
1231     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1232     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1233     { WM_ERASEBKGND, sent|parent },
1234     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1235     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
1236     { WM_CHILDACTIVATE, sent },
1237     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
1238     { WM_MOVE, sent|defwinproc },
1239     { WM_SHOWWINDOW, sent|wparam, 1 },
1240     { 0 }
1241 };
1242 /* Creation of a custom dialog (32) */
1243 static const struct message WmCreateCustomDialogSeq[] = {
1244     { HCBT_CREATEWND, hook },
1245     { WM_GETMINMAXINFO, sent },
1246     { WM_NCCREATE, sent },
1247     { WM_NCCALCSIZE, sent|wparam, 0 },
1248     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1249     { WM_CREATE, sent },
1250     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1251     { WM_NOTIFYFORMAT, sent|optional },
1252     { WM_QUERYUISTATE, sent|optional },
1253     { WM_WINDOWPOSCHANGING, sent|optional },
1254     { WM_GETMINMAXINFO, sent|optional },
1255     { WM_NCCALCSIZE, sent|optional },
1256     { WM_WINDOWPOSCHANGED, sent|optional },
1257     { WM_SHOWWINDOW, sent|wparam, 1 },
1258     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1259     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1260     { HCBT_ACTIVATE, hook },
1261     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1262
1263
1264     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1265
1266     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1267
1268     { WM_NCACTIVATE, sent },
1269     { WM_GETTEXT, sent|optional|defwinproc },
1270     { WM_GETTEXT, sent|optional|defwinproc },
1271     { WM_GETTEXT, sent|optional|defwinproc },
1272     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1273     { WM_ACTIVATE, sent|wparam, 1 },
1274     { WM_GETTEXT, sent|optional },
1275     { WM_KILLFOCUS, sent|parent },
1276     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1277     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1278     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1279     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1280     { WM_SETFOCUS, sent },
1281     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1282     { WM_NCPAINT, sent|wparam, 1 },
1283     { WM_GETTEXT, sent|optional|defwinproc },
1284     { WM_GETTEXT, sent|optional|defwinproc },
1285     { WM_ERASEBKGND, sent },
1286     { WM_CTLCOLORDLG, sent|optional|defwinproc },
1287     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1288     { WM_GETTEXT, sent|optional },
1289     { WM_GETTEXT, sent|optional },
1290     { WM_NCCALCSIZE, sent|optional },
1291     { WM_NCPAINT, sent|optional },
1292     { WM_GETTEXT, sent|optional|defwinproc },
1293     { WM_GETTEXT, sent|optional|defwinproc },
1294     { WM_ERASEBKGND, sent|optional },
1295     { WM_CTLCOLORDLG, sent|optional|defwinproc },
1296     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1297     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1298     { WM_MOVE, sent },
1299     { 0 }
1300 };
1301 /* Calling EndDialog for a custom dialog (32) */
1302 static const struct message WmEndCustomDialogSeq[] = {
1303     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1304     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1305     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1306     { WM_GETTEXT, sent|optional },
1307     { HCBT_ACTIVATE, hook },
1308     { WM_NCACTIVATE, sent|wparam, 0 },
1309     { WM_GETTEXT, sent|optional|defwinproc },
1310     { WM_GETTEXT, sent|optional|defwinproc },
1311     { WM_ACTIVATE, sent|wparam, 0 },
1312     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1313     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1314     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1315     { WM_GETTEXT, sent|optional|defwinproc },
1316     { WM_GETTEXT, sent|optional|defwinproc },
1317     { HCBT_SETFOCUS, hook },
1318     { WM_KILLFOCUS, sent },
1319     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1320     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1321     { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1322     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1323     { WM_SETFOCUS, sent|parent|defwinproc },
1324     { 0 }
1325 };
1326 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1327 static const struct message WmShowCustomDialogSeq[] = {
1328     { WM_SHOWWINDOW, sent|wparam, 1 },
1329     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1330     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1331     { HCBT_ACTIVATE, hook },
1332     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1333
1334     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1335
1336     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1337     { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1338     { WM_NCACTIVATE, sent },
1339     { WM_ACTIVATE, sent|wparam, 1 },
1340     { WM_GETTEXT, sent|optional },
1341
1342     { WM_KILLFOCUS, sent|parent },
1343     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1344     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1345     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1346     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1347     { WM_SETFOCUS, sent },
1348     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1349     { WM_NCPAINT, sent|wparam, 1 },
1350     { WM_ERASEBKGND, sent },
1351     { WM_CTLCOLORDLG, sent|defwinproc },
1352     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1353     { 0 }
1354 };
1355 /* Creation and destruction of a modal dialog (32) */
1356 static const struct message WmModalDialogSeq[] = {
1357     { WM_CANCELMODE, sent|parent },
1358     { HCBT_SETFOCUS, hook },
1359     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1360     { WM_KILLFOCUS, sent|parent },
1361     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1362     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1363     { WM_ENABLE, sent|parent|wparam, 0 },
1364     { HCBT_CREATEWND, hook },
1365     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1366     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1367     { WM_SETFONT, sent },
1368     { WM_INITDIALOG, sent },
1369     { WM_CHANGEUISTATE, sent|optional },
1370     { WM_UPDATEUISTATE, sent|optional },
1371     { WM_SHOWWINDOW, sent },
1372     { HCBT_ACTIVATE, hook },
1373     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1374     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1375     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1376     { WM_NCACTIVATE, sent },
1377     { WM_GETTEXT, sent|optional },
1378     { WM_ACTIVATE, sent|wparam, 1 },
1379     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1380     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1381     { WM_NCPAINT, sent|optional },
1382     { WM_GETTEXT, sent|optional },
1383     { WM_ERASEBKGND, sent|optional },
1384     { WM_CTLCOLORDLG, sent|optional },
1385     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1386     { WM_GETTEXT, sent|optional },
1387     { WM_NCCALCSIZE, sent|optional },
1388     { WM_NCPAINT, sent|optional },
1389     { WM_GETTEXT, sent|optional },
1390     { WM_ERASEBKGND, sent|optional },
1391     { WM_CTLCOLORDLG, sent|optional },
1392     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1393     { WM_PAINT, sent|optional },
1394     { WM_CTLCOLORBTN, sent|optional },
1395     { WM_GETTITLEBARINFOEX, sent|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_ENTERIDLE, sent|parent|optional },
1414     { WM_ENTERIDLE, sent|parent|optional },
1415     { WM_ENTERIDLE, sent|parent|optional },
1416     { WM_TIMER, sent },
1417     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1418     { WM_ENABLE, sent|parent|wparam, 1 },
1419     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1420     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1421     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1422     { WM_GETTEXT, sent|optional },
1423     { HCBT_ACTIVATE, hook },
1424     { WM_NCACTIVATE, sent|wparam, 0 },
1425     { WM_GETTEXT, sent|optional },
1426     { WM_ACTIVATE, sent|wparam, 0 },
1427     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1428     { WM_WINDOWPOSCHANGING, sent|optional },
1429     { WM_WINDOWPOSCHANGED, sent|optional },
1430     { HCBT_SETFOCUS, hook },
1431     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1432     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1433     { WM_SETFOCUS, sent|parent|defwinproc },
1434     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1435     { HCBT_DESTROYWND, hook },
1436     { 0x0090, sent|optional },
1437     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1438     { WM_DESTROY, sent },
1439     { WM_NCDESTROY, sent },
1440     { 0 }
1441 };
1442 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1443 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1444     /* (inside dialog proc, handling WM_INITDIALOG) */
1445     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1446     { WM_NCCALCSIZE, sent },
1447     { WM_NCACTIVATE, sent|parent|wparam, 0 },
1448     { WM_GETTEXT, sent|defwinproc },
1449     { WM_ACTIVATE, sent|parent|wparam, 0 },
1450     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1451     { WM_WINDOWPOSCHANGING, sent|parent },
1452     { WM_NCACTIVATE, sent|wparam, 1 },
1453     { WM_ACTIVATE, sent|wparam, 1 },
1454     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1455     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1456     /* (setting focus) */
1457     { WM_SHOWWINDOW, sent|wparam, 1 },
1458     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1459     { WM_NCPAINT, sent },
1460     { WM_GETTEXT, sent|defwinproc },
1461     { WM_ERASEBKGND, sent },
1462     { WM_CTLCOLORDLG, sent|defwinproc },
1463     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1464     { WM_PAINT, sent },
1465     /* (bunch of WM_CTLCOLOR* for each control) */
1466     { WM_PAINT, sent|parent },
1467     { WM_ENTERIDLE, sent|parent|wparam, 0 },
1468     { WM_SETCURSOR, sent|parent },
1469     { 0 }
1470 };
1471 /* SetMenu for NonVisible windows with size change*/
1472 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1473     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1474     { WM_NCCALCSIZE, sent|wparam, 1 },
1475     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1476     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1477     { WM_MOVE, sent|defwinproc },
1478     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1479     { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1480     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1481     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1482     { WM_GETTEXT, sent|optional },
1483     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1484     { 0 }
1485 };
1486 /* SetMenu for NonVisible windows with no size change */
1487 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1488     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1489     { WM_NCCALCSIZE, sent|wparam, 1 },
1490     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1491     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1492     { 0 }
1493 };
1494 /* SetMenu for Visible windows with size change */
1495 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1496     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1497     { WM_NCCALCSIZE, sent|wparam, 1 },
1498     { 0x0093, sent|defwinproc|optional },
1499     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1500     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1501     { 0x0093, sent|defwinproc|optional },
1502     { 0x0093, sent|defwinproc|optional },
1503     { 0x0091, sent|defwinproc|optional },
1504     { 0x0092, sent|defwinproc|optional },
1505     { WM_GETTEXT, sent|defwinproc|optional },
1506     { WM_ERASEBKGND, sent|optional },
1507     { WM_ACTIVATE, sent|optional },
1508     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1509     { WM_MOVE, sent|defwinproc },
1510     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1511     { 0x0093, sent|optional },
1512     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1513     { 0x0093, sent|defwinproc|optional },
1514     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1515     { 0x0093, sent|defwinproc|optional },
1516     { 0x0093, sent|defwinproc|optional },
1517     { 0x0091, sent|defwinproc|optional },
1518     { 0x0092, sent|defwinproc|optional },
1519     { WM_ERASEBKGND, sent|optional },
1520     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1521     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1522     { 0 }
1523 };
1524 /* SetMenu for Visible windows with no size change */
1525 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1526     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1527     { WM_NCCALCSIZE, sent|wparam, 1 },
1528     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1529     { WM_GETTEXT, sent|defwinproc|optional },
1530     { WM_ERASEBKGND, sent|optional },
1531     { WM_ACTIVATE, sent|optional },
1532     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1533     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1534     { 0 }
1535 };
1536 /* DrawMenuBar for a visible window */
1537 static const struct message WmDrawMenuBarSeq[] =
1538 {
1539     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1540     { WM_NCCALCSIZE, sent|wparam, 1 },
1541     { 0x0093, sent|defwinproc|optional },
1542     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1543     { 0x0093, sent|defwinproc|optional },
1544     { 0x0093, sent|defwinproc|optional },
1545     { 0x0091, sent|defwinproc|optional },
1546     { 0x0092, sent|defwinproc|optional },
1547     { WM_GETTEXT, sent|defwinproc|optional },
1548     { WM_ERASEBKGND, sent|optional },
1549     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1550     { 0x0093, sent|optional },
1551     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1552     { 0 }
1553 };
1554
1555 static const struct message WmSetRedrawFalseSeq[] =
1556 {
1557     { WM_SETREDRAW, sent|wparam, 0 },
1558     { 0 }
1559 };
1560
1561 static const struct message WmSetRedrawTrueSeq[] =
1562 {
1563     { WM_SETREDRAW, sent|wparam, 1 },
1564     { 0 }
1565 };
1566
1567 static const struct message WmEnableWindowSeq_1[] =
1568 {
1569     { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1570     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1571     { HCBT_SETFOCUS, hook|optional },
1572     { WM_KILLFOCUS, sent|optional },
1573     { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1574     { 0 }
1575 };
1576
1577 static const struct message WmEnableWindowSeq_2[] =
1578 {
1579     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1580     { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1581     { 0 }
1582 };
1583
1584 static const struct message WmGetScrollRangeSeq[] =
1585 {
1586     { SBM_GETRANGE, sent },
1587     { 0 }
1588 };
1589 static const struct message WmGetScrollInfoSeq[] =
1590 {
1591     { SBM_GETSCROLLINFO, sent },
1592     { 0 }
1593 };
1594 static const struct message WmSetScrollRangeSeq[] =
1595 {
1596     /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1597        sends SBM_SETSCROLLINFO.
1598      */
1599     { SBM_SETSCROLLINFO, sent },
1600     { 0 }
1601 };
1602 /* SetScrollRange for a window without a non-client area */
1603 static const struct message WmSetScrollRangeHSeq_empty[] =
1604 {
1605     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1606     { 0 }
1607 };
1608 static const struct message WmSetScrollRangeVSeq_empty[] =
1609 {
1610     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1611     { 0 }
1612 };
1613 static const struct message WmSetScrollRangeHVSeq[] =
1614 {
1615     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1616     { WM_NCCALCSIZE, sent|wparam, 1 },
1617     { WM_GETTEXT, sent|defwinproc|optional },
1618     { WM_ERASEBKGND, sent|optional },
1619     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1620     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1621     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1622     { 0 }
1623 };
1624 /* SetScrollRange for a window with a non-client area */
1625 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1626 {
1627     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1628     { WM_NCCALCSIZE, sent|wparam, 1 },
1629     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1630     { WM_NCPAINT, sent|optional },
1631     { WM_STYLECHANGING, sent|defwinproc|optional },
1632     { WM_STYLECHANGED, sent|defwinproc|optional },
1633     { WM_STYLECHANGING, sent|defwinproc|optional },
1634     { WM_STYLECHANGED, sent|defwinproc|optional },
1635     { WM_STYLECHANGING, sent|defwinproc|optional },
1636     { WM_STYLECHANGED, sent|defwinproc|optional },
1637     { WM_STYLECHANGING, sent|defwinproc|optional },
1638     { WM_STYLECHANGED, sent|defwinproc|optional },
1639     { WM_GETTEXT, sent|defwinproc|optional },
1640     { WM_GETTEXT, sent|defwinproc|optional },
1641     { WM_ERASEBKGND, sent|optional },
1642     { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1643     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOCLIENTSIZE },
1644     { WM_SIZE, sent|defwinproc|optional },
1645     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1646     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1647     { WM_GETTEXT, sent|optional },
1648     { WM_GETTEXT, sent|optional },
1649     { WM_GETTEXT, sent|optional },
1650     { WM_GETTEXT, sent|optional },
1651     { 0 }
1652 };
1653 /* test if we receive the right sequence of messages */
1654 /* after calling ShowWindow( SW_SHOWNA) */
1655 static const struct message WmSHOWNAChildInvisParInvis[] = {
1656     { WM_SHOWWINDOW, sent|wparam, 1 },
1657     { 0 }
1658 };
1659 static const struct message WmSHOWNAChildVisParInvis[] = {
1660     { WM_SHOWWINDOW, sent|wparam, 1 },
1661     { 0 }
1662 };
1663 static const struct message WmSHOWNAChildVisParVis[] = {
1664     { WM_SHOWWINDOW, sent|wparam, 1 },
1665     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1666     { 0 }
1667 };
1668 static const struct message WmSHOWNAChildInvisParVis[] = {
1669     { WM_SHOWWINDOW, sent|wparam, 1 },
1670     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1671     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1672     { WM_ERASEBKGND, sent|optional },
1673     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1674     { 0 }
1675 };
1676 static const struct message WmSHOWNATopVisible[] = {
1677     { WM_SHOWWINDOW, sent|wparam, 1 },
1678     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1679     { WM_NCPAINT, sent|wparam|optional, 1 },
1680     { WM_GETTEXT, sent|defwinproc|optional },
1681     { WM_ERASEBKGND, sent|optional },
1682     { WM_WINDOWPOSCHANGED, sent|optional },
1683     { 0 }
1684 };
1685 static const struct message WmSHOWNATopInvisible[] = {
1686     { WM_NOTIFYFORMAT, sent|optional },
1687     { WM_QUERYUISTATE, sent|optional },
1688     { WM_WINDOWPOSCHANGING, sent|optional },
1689     { WM_GETMINMAXINFO, sent|optional },
1690     { WM_NCCALCSIZE, sent|optional },
1691     { WM_WINDOWPOSCHANGED, sent|optional },
1692     { WM_SHOWWINDOW, sent|wparam, 1 },
1693     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1694     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1695     { WM_NCPAINT, sent|wparam|optional, 1 },
1696     { WM_GETTEXT, sent|defwinproc|optional },
1697     { WM_ERASEBKGND, sent|optional },
1698     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1699     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1700     { WM_NCPAINT, sent|wparam|optional, 1 },
1701     { WM_ERASEBKGND, sent|optional },
1702     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1703     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1704     { WM_MOVE, sent },
1705     { 0 }
1706 };
1707
1708 static int after_end_dialog, test_def_id;
1709 static int sequence_cnt, sequence_size;
1710 static struct recvd_message* sequence;
1711 static int log_all_parent_messages;
1712 static int paint_loop_done;
1713
1714 /* user32 functions */
1715 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1716 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
1717 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1718 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
1719 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1720 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1721 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1722 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
1723 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
1724 /* kernel32 functions */
1725 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1726
1727 static void init_procs(void)
1728 {
1729     HMODULE user32 = GetModuleHandleA("user32.dll");
1730     HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1731
1732 #define GET_PROC(dll, func) \
1733     p ## func = (void*)GetProcAddress(dll, #func); \
1734     if(!p ## func) { \
1735       trace("GetProcAddress(%s) failed\n", #func); \
1736     }
1737
1738     GET_PROC(user32, GetAncestor)
1739     GET_PROC(user32, GetMenuInfo)
1740     GET_PROC(user32, NotifyWinEvent)
1741     GET_PROC(user32, SetMenuInfo)
1742     GET_PROC(user32, SetWinEventHook)
1743     GET_PROC(user32, TrackMouseEvent)
1744     GET_PROC(user32, UnhookWinEvent)
1745     GET_PROC(user32, GetMonitorInfoA)
1746     GET_PROC(user32, MonitorFromPoint)
1747
1748     GET_PROC(kernel32, GetCPInfoExA)
1749
1750 #undef GET_PROC
1751 }
1752
1753 static const char *get_winpos_flags(UINT flags)
1754 {
1755     static char buffer[300];
1756
1757     buffer[0] = 0;
1758 #define DUMP(flag) do { if (flags & flag) { strcat( buffer, "|" #flag ); flags &= ~flag; } } while(0)
1759     DUMP( SWP_SHOWWINDOW );
1760     DUMP( SWP_HIDEWINDOW );
1761     DUMP( SWP_NOACTIVATE );
1762     DUMP( SWP_FRAMECHANGED );
1763     DUMP( SWP_NOCOPYBITS );
1764     DUMP( SWP_NOOWNERZORDER );
1765     DUMP( SWP_NOSENDCHANGING );
1766     DUMP( SWP_DEFERERASE );
1767     DUMP( SWP_ASYNCWINDOWPOS );
1768     DUMP( SWP_NOZORDER );
1769     DUMP( SWP_NOREDRAW );
1770     DUMP( SWP_NOSIZE );
1771     DUMP( SWP_NOMOVE );
1772     DUMP( SWP_NOCLIENTSIZE );
1773     DUMP( SWP_NOCLIENTMOVE );
1774     if (flags) sprintf(buffer + strlen(buffer),"|0x%04x", flags);
1775     return buffer + 1;
1776 #undef DUMP
1777 }
1778
1779 static BOOL ignore_message( UINT message )
1780 {
1781     /* these are always ignored */
1782     return (message >= 0xc000 ||
1783             message == WM_GETICON ||
1784             message == WM_GETOBJECT ||
1785             message == WM_TIMECHANGE ||
1786             message == WM_DISPLAYCHANGE ||
1787             message == WM_DEVICECHANGE ||
1788             message == WM_DWMNCRENDERINGCHANGED);
1789 }
1790
1791
1792 #define add_message(msg) add_message_(__LINE__,msg);
1793 static void add_message_(int line, const struct recvd_message *msg)
1794 {
1795     struct recvd_message *seq;
1796
1797     if (!sequence) 
1798     {
1799         sequence_size = 10;
1800         sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof(*sequence) );
1801     }
1802     if (sequence_cnt == sequence_size) 
1803     {
1804         sequence_size *= 2;
1805         sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof(*sequence) );
1806     }
1807     assert(sequence);
1808
1809     seq = &sequence[sequence_cnt];
1810     seq->hwnd = msg->hwnd;
1811     seq->message = msg->message;
1812     seq->flags = msg->flags;
1813     seq->wParam = msg->wParam;
1814     seq->lParam = msg->lParam;
1815     seq->line   = line;
1816     seq->descr  = msg->descr;
1817     seq->output[0] = 0;
1818
1819     if (msg->descr)
1820     {
1821         if (msg->flags & hook)
1822         {
1823             static const char * const CBT_code_name[10] =
1824             {
1825                 "HCBT_MOVESIZE",
1826                 "HCBT_MINMAX",
1827                 "HCBT_QS",
1828                 "HCBT_CREATEWND",
1829                 "HCBT_DESTROYWND",
1830                 "HCBT_ACTIVATE",
1831                 "HCBT_CLICKSKIPPED",
1832                 "HCBT_KEYSKIPPED",
1833                 "HCBT_SYSCOMMAND",
1834                 "HCBT_SETFOCUS"
1835             };
1836             const char *code_name = (msg->message <= HCBT_SETFOCUS) ? CBT_code_name[msg->message] : "Unknown";
1837
1838             sprintf( seq->output, "%s: hook %d (%s) wp %08lx lp %08lx",
1839                      msg->descr, msg->message, code_name, msg->wParam, msg->lParam );
1840         }
1841         else if (msg->flags & winevent_hook)
1842         {
1843             sprintf( seq->output, "%s: winevent %p %08x %08lx %08lx",
1844                      msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1845         }
1846         else
1847         {
1848             switch (msg->message)
1849             {
1850             case WM_WINDOWPOSCHANGING:
1851             case WM_WINDOWPOSCHANGED:
1852             {
1853                 WINDOWPOS *winpos = (WINDOWPOS *)msg->lParam;
1854
1855                 sprintf( seq->output, "%s: %p WM_WINDOWPOS%s wp %08lx lp %08lx after %p x %d y %d cx %d cy %d flags %s",
1856                           msg->descr, msg->hwnd,
1857                           (msg->message == WM_WINDOWPOSCHANGING) ? "CHANGING" : "CHANGED",
1858                           msg->wParam, msg->lParam, winpos->hwndInsertAfter,
1859                           winpos->x, winpos->y, winpos->cx, winpos->cy,
1860                           get_winpos_flags(winpos->flags) );
1861
1862                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
1863                  * in the high word for internal purposes
1864                  */
1865                 seq->wParam = winpos->flags & 0xffff;
1866                 /* We are not interested in the flags that don't match under XP and Win9x */
1867                 seq->wParam &= ~SWP_NOZORDER;
1868                 break;
1869             }
1870
1871             case WM_DRAWITEM:
1872             {
1873                 DRAW_ITEM_STRUCT di;
1874                 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)msg->lParam;
1875
1876                 sprintf( seq->output, "%s: %p WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x",
1877                          msg->descr, msg->hwnd, dis->CtlType, dis->CtlID,
1878                          dis->itemID, dis->itemAction, dis->itemState);
1879
1880                 di.u.lp = 0;
1881                 di.u.item.type = dis->CtlType;
1882                 di.u.item.ctl_id = dis->CtlID;
1883                 if (dis->CtlType == ODT_LISTBOX ||
1884                     dis->CtlType == ODT_COMBOBOX ||
1885                     dis->CtlType == ODT_MENU)
1886                     di.u.item.item_id = dis->itemID;
1887                 di.u.item.action = dis->itemAction;
1888                 di.u.item.state = dis->itemState;
1889
1890                 seq->lParam = di.u.lp;
1891                 break;
1892             }
1893             default:
1894                 if (msg->message >= 0xc000) return;  /* ignore registered messages */
1895                 sprintf( seq->output, "%s: %p %04x wp %08lx lp %08lx",
1896                          msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1897             }
1898             if (msg->flags & (sent|posted|parent|defwinproc|beginpaint))
1899                 sprintf( seq->output + strlen(seq->output), " (flags %x)", msg->flags );
1900         }
1901     }
1902
1903     sequence_cnt++;
1904 }
1905
1906 /* try to make sure pending X events have been processed before continuing */
1907 static void flush_events(void)
1908 {
1909     MSG msg;
1910     int diff = 200;
1911     int min_timeout = 100;
1912     DWORD time = GetTickCount() + diff;
1913
1914     while (diff > 0)
1915     {
1916         if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1917         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1918         diff = time - GetTickCount();
1919     }
1920 }
1921
1922 static void flush_sequence(void)
1923 {
1924     HeapFree(GetProcessHeap(), 0, sequence);
1925     sequence = 0;
1926     sequence_cnt = sequence_size = 0;
1927 }
1928
1929 static void dump_sequence(const struct message *expected, const char *context, const char *file, int line)
1930 {
1931     const struct recvd_message *actual = sequence;
1932     unsigned int count = 0;
1933
1934     trace_(file, line)("Failed sequence %s:\n", context );
1935     while (expected->message && actual->message)
1936     {
1937         if (actual->output[0])
1938         {
1939             if (expected->flags & hook)
1940             {
1941                 trace_(file, line)( "  %u: expected: hook %04x - actual: %s\n",
1942                                     count, expected->message, actual->output );
1943             }
1944             else if (expected->flags & winevent_hook)
1945             {
1946                 trace_(file, line)( "  %u: expected: winevent %04x - actual: %s\n",
1947                                     count, expected->message, actual->output );
1948             }
1949             else if (expected->flags & kbd_hook)
1950             {
1951                 trace_(file, line)( "  %u: expected: kbd %04x - actual: %s\n",
1952                                     count, expected->message, actual->output );
1953             }
1954             else
1955             {
1956                 trace_(file, line)( "  %u: expected: msg %04x - actual: %s\n",
1957                                     count, expected->message, actual->output );
1958             }
1959         }
1960
1961         if (expected->message == actual->message)
1962         {
1963             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) &&
1964                 (expected->flags & optional))
1965             {
1966                 /* don't match messages if their defwinproc status differs */
1967                 expected++;
1968             }
1969             else
1970             {
1971                 expected++;
1972                 actual++;
1973             }
1974         }
1975         /* silently drop winevent messages if there is no support for them */
1976         else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1977             expected++;
1978         else
1979         {
1980             expected++;
1981             actual++;
1982         }
1983         count++;
1984     }
1985
1986     /* optional trailing messages */
1987     while (expected->message && ((expected->flags & optional) ||
1988             ((expected->flags & winevent_hook) && !hEvent_hook)))
1989     {
1990         trace_(file, line)( "  %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1991         expected++;
1992         count++;
1993     }
1994
1995     if (expected->message)
1996     {
1997         trace_(file, line)( "  %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1998         return;
1999     }
2000
2001     while (actual->message && actual->output[0])
2002     {
2003         trace_(file, line)( "  %u: expected: nothing - actual: %s\n", count, actual->output );
2004         actual++;
2005         count++;
2006     }
2007 }
2008
2009 #define ok_sequence( exp, contx, todo) \
2010         ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
2011
2012
2013 static void ok_sequence_(const struct message *expected_list, const char *context, int todo,
2014                          const char *file, int line)
2015 {
2016     static const struct recvd_message end_of_sequence;
2017     const struct message *expected = expected_list;
2018     const struct recvd_message *actual;
2019     int failcount = 0, dump = 0;
2020     unsigned int count = 0;
2021
2022     add_message(&end_of_sequence);
2023
2024     actual = sequence;
2025
2026     while (expected->message && actual->message)
2027     {
2028         if (expected->message == actual->message &&
2029             !((expected->flags ^ actual->flags) & (hook|winevent_hook|kbd_hook)))
2030         {
2031             if (expected->flags & wparam)
2032             {
2033                 if (((expected->wParam ^ actual->wParam) & ~expected->wp_mask) && todo)
2034                 {
2035                     todo_wine {
2036                         failcount ++;
2037                         if (strcmp(winetest_platform, "wine")) dump++;
2038                         ok_( file, line) (FALSE,
2039                             "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2040                             context, count, expected->message, expected->wParam, actual->wParam);
2041                     }
2042                 }
2043                 else
2044                 {
2045                     ok_( file, line)( ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) == 0,
2046                                      "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2047                                      context, count, expected->message, expected->wParam, actual->wParam);
2048                     if ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) dump++;
2049                 }
2050
2051             }
2052             if (expected->flags & lparam)
2053             {
2054                 if (((expected->lParam ^ actual->lParam) & ~expected->lp_mask) && todo)
2055                 {
2056                     todo_wine {
2057                         failcount ++;
2058                         if (strcmp(winetest_platform, "wine")) dump++;
2059                         ok_( file, line) (FALSE,
2060                             "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2061                             context, count, expected->message, expected->lParam, actual->lParam);
2062                     }
2063                 }
2064                 else
2065                 {
2066                     ok_( file, line)(((expected->lParam ^ actual->lParam) & ~expected->lp_mask) == 0,
2067                                      "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2068                                      context, count, expected->message, expected->lParam, actual->lParam);
2069                     if ((expected->lParam ^ actual->lParam) & ~expected->lp_mask) dump++;
2070                 }
2071             }
2072             if ((expected->flags & optional) &&
2073                 ((expected->flags ^ actual->flags) & (defwinproc|parent)))
2074             {
2075                 /* don't match optional messages if their defwinproc or parent status differs */
2076                 expected++;
2077                 count++;
2078                 continue;
2079             }
2080             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
2081             {
2082                     todo_wine {
2083                         failcount ++;
2084                         if (strcmp(winetest_platform, "wine")) dump++;
2085                         ok_( file, line) (FALSE,
2086                             "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2087                             context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2088                     }
2089             }
2090             else
2091             {
2092                 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
2093                     "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2094                     context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2095                 if ((expected->flags & defwinproc) != (actual->flags & defwinproc)) dump++;
2096             }
2097
2098             ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
2099                 "%s: %u: the msg 0x%04x should %shave been sent by BeginPaint\n",
2100                 context, count, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
2101             if ((expected->flags & beginpaint) != (actual->flags & beginpaint)) dump++;
2102
2103             ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
2104                 "%s: %u: the msg 0x%04x should have been %s\n",
2105                 context, count, expected->message, (expected->flags & posted) ? "posted" : "sent");
2106             if ((expected->flags & (sent|posted)) != (actual->flags & (sent|posted))) dump++;
2107
2108             ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
2109                 "%s: %u: the msg 0x%04x was expected in %s\n",
2110                 context, count, expected->message, (expected->flags & parent) ? "parent" : "child");
2111             if ((expected->flags & parent) != (actual->flags & parent)) dump++;
2112
2113             ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
2114                 "%s: %u: the msg 0x%04x should have been sent by a hook\n",
2115                 context, count, expected->message);
2116             if ((expected->flags & hook) != (actual->flags & hook)) dump++;
2117
2118             ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
2119                 "%s: %u: the msg 0x%04x should have been sent by a winevent hook\n",
2120                 context, count, expected->message);
2121             if ((expected->flags & winevent_hook) != (actual->flags & winevent_hook)) dump++;
2122
2123             ok_( file, line) ((expected->flags & kbd_hook) == (actual->flags & kbd_hook),
2124                 "%s: %u: the msg 0x%04x should have been sent by a keyboard hook\n",
2125                 context, count, expected->message);
2126             if ((expected->flags & kbd_hook) != (actual->flags & kbd_hook)) dump++;
2127
2128             expected++;
2129             actual++;
2130         }
2131         /* silently drop hook messages if there is no support for them */
2132         else if ((expected->flags & optional) ||
2133                  ((expected->flags & hook) && !hCBT_hook) ||
2134                  ((expected->flags & winevent_hook) && !hEvent_hook) ||
2135                  ((expected->flags & kbd_hook) && !hKBD_hook))
2136             expected++;
2137         else if (todo)
2138         {
2139             failcount++;
2140             todo_wine {
2141                 if (strcmp(winetest_platform, "wine")) dump++;
2142                 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2143                                   context, count, expected->message, actual->message);
2144             }
2145             goto done;
2146         }
2147         else
2148         {
2149             ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2150                               context, count, expected->message, actual->message);
2151             dump++;
2152             expected++;
2153             actual++;
2154         }
2155         count++;
2156     }
2157
2158     /* skip all optional trailing messages */
2159     while (expected->message && ((expected->flags & optional) ||
2160                                  ((expected->flags & hook) && !hCBT_hook) ||
2161                                  ((expected->flags & winevent_hook) && !hEvent_hook)))
2162         expected++;
2163
2164     if (todo)
2165     {
2166         todo_wine {
2167             if (expected->message || actual->message) {
2168                 failcount++;
2169                 if (strcmp(winetest_platform, "wine")) dump++;
2170                 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2171                                   context, count, expected->message, actual->message);
2172             }
2173         }
2174     }
2175     else
2176     {
2177         if (expected->message || actual->message)
2178         {
2179             dump++;
2180             ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2181                               context, count, expected->message, actual->message);
2182         }
2183     }
2184     if( todo && !failcount) /* succeeded yet marked todo */
2185         todo_wine {
2186             if (!strcmp(winetest_platform, "wine")) dump++;
2187             ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
2188         }
2189
2190 done:
2191     if (dump) dump_sequence(expected_list, context, file, line);
2192     flush_sequence();
2193 }
2194
2195 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
2196
2197 /******************************** MDI test **********************************/
2198
2199 /* CreateWindow for MDI frame window, initially visible */
2200 static const struct message WmCreateMDIframeSeq[] = {
2201     { HCBT_CREATEWND, hook },
2202     { WM_GETMINMAXINFO, sent },
2203     { WM_NCCREATE, sent },
2204     { WM_NCCALCSIZE, sent|wparam, 0 },
2205     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2206     { WM_CREATE, sent },
2207     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2208     { WM_NOTIFYFORMAT, sent|optional },
2209     { WM_QUERYUISTATE, sent|optional },
2210     { WM_WINDOWPOSCHANGING, sent|optional },
2211     { WM_GETMINMAXINFO, sent|optional },
2212     { WM_NCCALCSIZE, sent|optional },
2213     { WM_WINDOWPOSCHANGED, sent|optional },
2214     { WM_SHOWWINDOW, sent|wparam, 1 },
2215     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2216     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2217     { HCBT_ACTIVATE, hook },
2218     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
2219     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
2220     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
2221     { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
2222     { WM_NCACTIVATE, sent },
2223     { WM_GETTEXT, sent|defwinproc|optional },
2224     { WM_ACTIVATE, sent|wparam, 1 },
2225     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
2226     { HCBT_SETFOCUS, hook },
2227     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2228     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2229     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2230     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
2231     /* Win9x adds SWP_NOZORDER below */
2232     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2233     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2234     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2235     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2236     { WM_MOVE, sent },
2237     { 0 }
2238 };
2239 /* DestroyWindow for MDI frame window, initially visible */
2240 static const struct message WmDestroyMDIframeSeq[] = {
2241     { HCBT_DESTROYWND, hook },
2242     { 0x0090, sent|optional },
2243     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2244     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2245     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2246     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2247     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
2248     { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2249     { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
2250     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
2251     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2252     { WM_DESTROY, sent },
2253     { WM_NCDESTROY, sent },
2254     { 0 }
2255 };
2256 /* CreateWindow for MDI client window, initially visible */
2257 static const struct message WmCreateMDIclientSeq[] = {
2258     { HCBT_CREATEWND, hook },
2259     { WM_NCCREATE, sent },
2260     { WM_NCCALCSIZE, sent|wparam, 0 },
2261     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2262     { WM_CREATE, sent },
2263     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2264     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2265     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2266     { WM_MOVE, sent },
2267     { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
2268     { WM_SHOWWINDOW, sent|wparam, 1 },
2269     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2270     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2271     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2272     { 0 }
2273 };
2274 /* ShowWindow(SW_SHOW) for MDI client window */
2275 static const struct message WmShowMDIclientSeq[] = {
2276     { WM_SHOWWINDOW, sent|wparam, 1 },
2277     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2278     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2279     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2280     { 0 }
2281 };
2282 /* ShowWindow(SW_HIDE) for MDI client window */
2283 static const struct message WmHideMDIclientSeq[] = {
2284     { WM_SHOWWINDOW, sent|wparam, 0 },
2285     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2286     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
2287     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
2288     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2289     { 0 }
2290 };
2291 /* DestroyWindow for MDI client window, initially visible */
2292 static const struct message WmDestroyMDIclientSeq[] = {
2293     { HCBT_DESTROYWND, hook },
2294     { 0x0090, sent|optional },
2295     { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
2296     { WM_SHOWWINDOW, sent|wparam, 0 },
2297     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2298     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2299     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2300     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2301     { WM_DESTROY, sent },
2302     { WM_NCDESTROY, sent },
2303     { 0 }
2304 };
2305 /* CreateWindow for MDI child window, initially visible */
2306 static const struct message WmCreateMDIchildVisibleSeq[] = {
2307     { HCBT_CREATEWND, hook },
2308     { WM_NCCREATE, sent }, 
2309     { WM_NCCALCSIZE, sent|wparam, 0 },
2310     { WM_CREATE, sent },
2311     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2312     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2313     { WM_MOVE, sent },
2314     /* Win2k sends wparam set to
2315      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2316      * while Win9x doesn't bother to set child window id according to
2317      * CLIENTCREATESTRUCT.idFirstChild
2318      */
2319     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2320     { WM_SHOWWINDOW, sent|wparam, 1 },
2321     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2322     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2323     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2324     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2325     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2326     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2327     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2328
2329     /* Win9x: message sequence terminates here. */
2330
2331     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2332     { HCBT_SETFOCUS, hook }, /* in MDI client */
2333     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2334     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2335     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2336     { WM_SETFOCUS, sent }, /* in MDI client */
2337     { HCBT_SETFOCUS, hook },
2338     { WM_KILLFOCUS, sent }, /* in MDI client */
2339     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2340     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2341     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2342     { WM_SETFOCUS, sent|defwinproc },
2343     { WM_MDIACTIVATE, sent|defwinproc },
2344     { 0 }
2345 };
2346 /* CreateWindow for MDI child window with invisible parent */
2347 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
2348     { HCBT_CREATEWND, hook },
2349     { WM_GETMINMAXINFO, sent },
2350     { WM_NCCREATE, sent }, 
2351     { WM_NCCALCSIZE, sent|wparam, 0 },
2352     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2353     { WM_CREATE, sent },
2354     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2355     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2356     { WM_MOVE, sent },
2357     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2358     { WM_SHOWWINDOW, sent|wparam, 1 },
2359     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2360     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2361     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2362     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2363
2364     /* Win9x: message sequence terminates here. */
2365
2366     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2367     { HCBT_SETFOCUS, hook }, /* in MDI client */
2368     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2369     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2370     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2371     { WM_SETFOCUS, sent }, /* in MDI client */
2372     { HCBT_SETFOCUS, hook },
2373     { WM_KILLFOCUS, sent }, /* in MDI client */
2374     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2375     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2376     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2377     { WM_SETFOCUS, sent|defwinproc },
2378     { WM_MDIACTIVATE, sent|defwinproc },
2379     { 0 }
2380 };
2381 /* DestroyWindow for MDI child window, initially visible */
2382 static const struct message WmDestroyMDIchildVisibleSeq[] = {
2383     { HCBT_DESTROYWND, hook },
2384     /* Win2k sends wparam set to
2385      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2386      * while Win9x doesn't bother to set child window id according to
2387      * CLIENTCREATESTRUCT.idFirstChild
2388      */
2389     { 0x0090, sent|optional },
2390     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2391     { WM_SHOWWINDOW, sent|wparam, 0 },
2392     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2393     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2394     { WM_ERASEBKGND, sent|parent|optional },
2395     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2396
2397     /* { WM_DESTROY, sent }
2398      * Win9x: message sequence terminates here.
2399      */
2400
2401     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2402     { WM_KILLFOCUS, sent },
2403     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2404     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2405     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2406     { WM_SETFOCUS, sent }, /* in MDI client */
2407
2408     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2409     { WM_KILLFOCUS, sent }, /* in MDI client */
2410     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2411     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2412     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2413     { WM_SETFOCUS, sent }, /* in MDI client */
2414
2415     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2416
2417     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2418     { WM_KILLFOCUS, sent },
2419     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2420     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2421     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2422     { WM_SETFOCUS, sent }, /* in MDI client */
2423
2424     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2425     { WM_KILLFOCUS, sent }, /* in MDI client */
2426     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2427     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2428     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2429     { WM_SETFOCUS, sent }, /* in MDI client */
2430
2431     { WM_DESTROY, sent },
2432
2433     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2434     { WM_KILLFOCUS, sent },
2435     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2436     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2437     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2438     { WM_SETFOCUS, sent }, /* in MDI client */
2439
2440     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2441     { WM_KILLFOCUS, sent }, /* in MDI client */
2442     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2443     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2444     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2445     { WM_SETFOCUS, sent }, /* in MDI client */
2446
2447     { WM_NCDESTROY, sent },
2448     { 0 }
2449 };
2450 /* CreateWindow for MDI child window, initially invisible */
2451 static const struct message WmCreateMDIchildInvisibleSeq[] = {
2452     { HCBT_CREATEWND, hook },
2453     { WM_NCCREATE, sent }, 
2454     { WM_NCCALCSIZE, sent|wparam, 0 },
2455     { WM_CREATE, sent },
2456     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2457     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2458     { WM_MOVE, sent },
2459     /* Win2k sends wparam set to
2460      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2461      * while Win9x doesn't bother to set child window id according to
2462      * CLIENTCREATESTRUCT.idFirstChild
2463      */
2464     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2465     { 0 }
2466 };
2467 /* DestroyWindow for MDI child window, initially invisible */
2468 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
2469     { HCBT_DESTROYWND, hook },
2470     /* Win2k sends wparam set to
2471      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2472      * while Win9x doesn't bother to set child window id according to
2473      * CLIENTCREATESTRUCT.idFirstChild
2474      */
2475     { 0x0090, sent|optional },
2476     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2477     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2478     { WM_DESTROY, sent },
2479     { WM_NCDESTROY, sent },
2480     /* FIXME: Wine destroys an icon/title window while Windows doesn't */
2481     { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
2482     { 0 }
2483 };
2484 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
2485 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
2486     { HCBT_CREATEWND, hook },
2487     { WM_NCCREATE, sent }, 
2488     { WM_NCCALCSIZE, sent|wparam, 0 },
2489     { WM_CREATE, sent },
2490     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2491     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2492     { WM_MOVE, sent },
2493     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2494     { WM_GETMINMAXINFO, sent },
2495     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED  },
2496     { WM_NCCALCSIZE, sent|wparam, 1 },
2497     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2498     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2499      /* in MDI frame */
2500     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2501     { WM_NCCALCSIZE, sent|wparam, 1 },
2502     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2503     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2504     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2505     /* Win2k sends wparam set to
2506      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2507      * while Win9x doesn't bother to set child window id according to
2508      * CLIENTCREATESTRUCT.idFirstChild
2509      */
2510     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2511     { WM_SHOWWINDOW, sent|wparam, 1 },
2512     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2513     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2514     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2515     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2516     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2517     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2518     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_FRAMECHANGED },
2519
2520     /* Win9x: message sequence terminates here. */
2521
2522     { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2523     { HCBT_SETFOCUS, hook|optional }, /* in MDI client */
2524     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2525     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2526     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2527     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2528     { HCBT_SETFOCUS, hook|optional },
2529     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2530     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2531     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2532     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2533     { WM_SETFOCUS, sent|defwinproc|optional },
2534     { WM_MDIACTIVATE, sent|defwinproc|optional },
2535      /* in MDI frame */
2536     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2537     { WM_NCCALCSIZE, sent|wparam, 1 },
2538     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2539     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2540     { 0 }
2541 };
2542 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2543 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2544     /* restore the 1st MDI child */
2545     { WM_SETREDRAW, sent|wparam, 0 },
2546     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2547     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2548     { WM_NCCALCSIZE, sent|wparam, 1 },
2549     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2550     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2551     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2552      /* in MDI frame */
2553     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2554     { WM_NCCALCSIZE, sent|wparam, 1 },
2555     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2556     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2557     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2558     { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2559     /* create the 2nd MDI child */
2560     { HCBT_CREATEWND, hook },
2561     { WM_NCCREATE, sent }, 
2562     { WM_NCCALCSIZE, sent|wparam, 0 },
2563     { WM_CREATE, sent },
2564     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2565     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2566     { WM_MOVE, sent },
2567     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2568     { WM_GETMINMAXINFO, sent },
2569     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2570     { WM_NCCALCSIZE, sent|wparam, 1 },
2571     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2572     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2573     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2574      /* in MDI frame */
2575     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2576     { WM_NCCALCSIZE, sent|wparam, 1 },
2577     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2578     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2579     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2580     /* Win2k sends wparam set to
2581      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2582      * while Win9x doesn't bother to set child window id according to
2583      * CLIENTCREATESTRUCT.idFirstChild
2584      */
2585     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2586     { WM_SHOWWINDOW, sent|wparam, 1 },
2587     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2588     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2589     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2590     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2591     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2592     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2593
2594     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2595     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2596
2597     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2598
2599     /* Win9x: message sequence terminates here. */
2600
2601     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2602     { HCBT_SETFOCUS, hook },
2603     { WM_KILLFOCUS, sent|defwinproc|optional }, /* in the 1st MDI child */
2604     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2605     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2606     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2607     { WM_SETFOCUS, sent }, /* in MDI client */
2608     { HCBT_SETFOCUS, hook },
2609     { WM_KILLFOCUS, sent }, /* in MDI client */
2610     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2611     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2612     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2613     { WM_SETFOCUS, sent|defwinproc },
2614
2615     { WM_MDIACTIVATE, sent|defwinproc },
2616      /* in MDI frame */
2617     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2618     { WM_NCCALCSIZE, sent|wparam, 1 },
2619     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2620     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2621     { 0 }
2622 };
2623 /* WM_MDICREATE MDI child window, initially visible and maximized */
2624 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2625     { WM_MDICREATE, sent },
2626     { HCBT_CREATEWND, hook },
2627     { WM_NCCREATE, sent }, 
2628     { WM_NCCALCSIZE, sent|wparam, 0 },
2629     { WM_CREATE, sent },
2630     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2631     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2632     { WM_MOVE, sent },
2633     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2634     { WM_GETMINMAXINFO, sent },
2635     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2636     { WM_NCCALCSIZE, sent|wparam, 1 },
2637     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2638     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2639
2640      /* in MDI frame */
2641     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2642     { WM_NCCALCSIZE, sent|wparam, 1 },
2643     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2644     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2645     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2646
2647     /* Win2k sends wparam set to
2648      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2649      * while Win9x doesn't bother to set child window id according to
2650      * CLIENTCREATESTRUCT.idFirstChild
2651      */
2652     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2653     { WM_SHOWWINDOW, sent|wparam, 1 },
2654     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2655
2656     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2657
2658     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2659     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2660     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2661
2662     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2663     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2664
2665     /* Win9x: message sequence terminates here. */
2666
2667     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2668     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2669     { HCBT_SETFOCUS, hook }, /* in MDI client */
2670     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2671     { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2672     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2673     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2674     { HCBT_SETFOCUS, hook|optional },
2675     { WM_KILLFOCUS, sent }, /* in MDI client */
2676     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2677     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2678     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2679     { WM_SETFOCUS, sent|defwinproc },
2680
2681     { WM_MDIACTIVATE, sent|defwinproc },
2682
2683      /* in MDI child */
2684     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2685     { WM_NCCALCSIZE, sent|wparam, 1 },
2686     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2687     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2688
2689      /* in MDI frame */
2690     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2691     { WM_NCCALCSIZE, sent|wparam, 1 },
2692     { 0x0093, sent|defwinproc|optional },
2693     { 0x0093, sent|defwinproc|optional },
2694     { 0x0093, sent|defwinproc|optional },
2695     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2696     { WM_MOVE, sent|defwinproc },
2697     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2698
2699      /* in MDI client */
2700     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2701     { WM_NCCALCSIZE, sent|wparam, 1 },
2702     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2703     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2704
2705      /* in MDI child */
2706     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2707     { WM_NCCALCSIZE, sent|wparam, 1 },
2708     { 0x0093, sent|optional },
2709     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2710     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2711
2712     { 0x0093, sent|optional },
2713     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2714     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2715     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2716     { 0x0093, sent|defwinproc|optional },
2717     { 0x0093, sent|defwinproc|optional },
2718     { 0x0093, sent|defwinproc|optional },
2719     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2720     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2721
2722     { 0 }
2723 };
2724 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2725 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2726     { HCBT_CREATEWND, hook },
2727     { WM_GETMINMAXINFO, sent },
2728     { WM_NCCREATE, sent }, 
2729     { WM_NCCALCSIZE, sent|wparam, 0 },
2730     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2731     { WM_CREATE, sent },
2732     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2733     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2734     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2735     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI frame */
2736     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2737     { WM_MOVE, sent },
2738     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2739     { WM_GETMINMAXINFO, sent },
2740     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2741     { WM_GETMINMAXINFO, sent|defwinproc },
2742     { WM_NCCALCSIZE, sent|wparam, 1 },
2743     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_STATECHANGED },
2744     { WM_MOVE, sent|defwinproc },
2745     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2746      /* in MDI frame */
2747     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2748     { WM_NCCALCSIZE, sent|wparam, 1 },
2749     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2750     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2751     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2752     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2753     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2754     /* Win2k sends wparam set to
2755      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2756      * while Win9x doesn't bother to set child window id according to
2757      * CLIENTCREATESTRUCT.idFirstChild
2758      */
2759     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2760     { 0 }
2761 };
2762 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2763 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2764     { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2765     { HCBT_SYSCOMMAND, hook },
2766     { WM_CLOSE, sent|defwinproc },
2767     { WM_MDIDESTROY, sent }, /* in MDI client */
2768
2769     /* bring the 1st MDI child to top */
2770     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2771     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2772
2773     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2774
2775     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2776     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2777     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2778
2779     /* maximize the 1st MDI child */
2780     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2781     { WM_GETMINMAXINFO, sent|defwinproc },
2782     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED },
2783     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2784     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2785     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2786     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2787
2788     /* restore the 2nd MDI child */
2789     { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2790     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2791     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2792     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2793
2794     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2795
2796     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2797     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2798
2799     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2800
2801     { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2802      /* in MDI frame */
2803     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2804     { WM_NCCALCSIZE, sent|wparam, 1 },
2805     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2806     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2807     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2808
2809     /* bring the 1st MDI child to top */
2810     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2811     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2812     { HCBT_SETFOCUS, hook },
2813     { WM_KILLFOCUS, sent|defwinproc },
2814     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2815     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2816     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2817     { WM_SETFOCUS, sent }, /* in MDI client */
2818     { HCBT_SETFOCUS, hook },
2819     { WM_KILLFOCUS, sent }, /* in MDI client */
2820     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2821     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2822     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2823     { WM_SETFOCUS, sent|defwinproc },
2824     { WM_MDIACTIVATE, sent|defwinproc },
2825     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2826
2827     /* apparently ShowWindow(SW_SHOW) on an MDI client */
2828     { WM_SHOWWINDOW, sent|wparam, 1 },
2829     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2830     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2831     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2832     { WM_MDIREFRESHMENU, sent },
2833
2834     { HCBT_DESTROYWND, hook },
2835     /* Win2k sends wparam set to
2836      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2837      * while Win9x doesn't bother to set child window id according to
2838      * CLIENTCREATESTRUCT.idFirstChild
2839      */
2840     { 0x0090, sent|defwinproc|optional },
2841     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2842     { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2843     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2844     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2845     { WM_ERASEBKGND, sent|parent|optional },
2846     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2847
2848     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2849     { WM_DESTROY, sent|defwinproc },
2850     { WM_NCDESTROY, sent|defwinproc },
2851     { 0 }
2852 };
2853 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2854 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2855     { WM_MDIDESTROY, sent }, /* in MDI client */
2856     { WM_SHOWWINDOW, sent|wparam, 0 },
2857     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2858     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2859     { WM_ERASEBKGND, sent|parent|optional },
2860     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2861
2862     { HCBT_SETFOCUS, hook },
2863     { WM_KILLFOCUS, sent },
2864     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2865     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2866     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2867     { WM_SETFOCUS, sent }, /* in MDI client */
2868     { HCBT_SETFOCUS, hook },
2869     { WM_KILLFOCUS, sent }, /* in MDI client */
2870     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2871     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2872     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2873     { WM_SETFOCUS, sent },
2874
2875      /* in MDI child */
2876     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2877     { WM_NCCALCSIZE, sent|wparam, 1 },
2878     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2879     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2880
2881      /* in MDI frame */
2882     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2883     { WM_NCCALCSIZE, sent|wparam, 1 },
2884     { 0x0093, sent|defwinproc|optional },
2885     { 0x0093, sent|defwinproc|optional },
2886     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2887     { WM_MOVE, sent|defwinproc },
2888     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2889
2890      /* in MDI client */
2891     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2892     { WM_NCCALCSIZE, sent|wparam, 1 },
2893     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2894     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2895
2896      /* in MDI child */
2897     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2898     { WM_NCCALCSIZE, sent|wparam, 1 },
2899     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2900     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2901
2902      /* in MDI child */
2903     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2904     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2905     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2906     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2907
2908      /* in MDI frame */
2909     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2910     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2911     { 0x0093, sent|defwinproc|optional },
2912     { 0x0093, sent|defwinproc|optional },
2913     { 0x0093, sent|defwinproc|optional },
2914     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2915     { WM_MOVE, sent|defwinproc },
2916     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2917
2918      /* in MDI client */
2919     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2920     { WM_NCCALCSIZE, sent|wparam, 1 },
2921     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2922     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2923
2924      /* in MDI child */
2925     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2926     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2927     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2928     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2929     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2930     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2931
2932     { 0x0093, sent|defwinproc|optional },
2933     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2934     { 0x0093, sent|defwinproc|optional },
2935     { 0x0093, sent|defwinproc|optional },
2936     { 0x0093, sent|defwinproc|optional },
2937     { 0x0093, sent|optional },
2938
2939     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2940     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2941     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2942     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2943     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2944
2945      /* in MDI frame */
2946     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2947     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2948     { 0x0093, sent|defwinproc|optional },
2949     { 0x0093, sent|defwinproc|optional },
2950     { 0x0093, sent|defwinproc|optional },
2951     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2952     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2953     { 0x0093, sent|optional },
2954
2955     { WM_NCACTIVATE, sent|wparam, 0 },
2956     { WM_MDIACTIVATE, sent },
2957
2958     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2959     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2960     { WM_NCCALCSIZE, sent|wparam, 1 },
2961
2962     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2963
2964     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2965     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2966     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2967
2968      /* in MDI child */
2969     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2970     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2971     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2972     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2973
2974      /* in MDI frame */
2975     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2976     { WM_NCCALCSIZE, sent|wparam, 1 },
2977     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2978     { WM_MOVE, sent|defwinproc },
2979     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2980
2981      /* in MDI client */
2982     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2983     { WM_NCCALCSIZE, sent|wparam, 1 },
2984     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2985     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2986     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2987     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2988     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2989     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2990     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2991
2992     { HCBT_SETFOCUS, hook },
2993     { WM_KILLFOCUS, sent },
2994     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2995     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2996     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2997     { WM_SETFOCUS, sent }, /* in MDI client */
2998
2999     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
3000
3001     { HCBT_DESTROYWND, hook },
3002     /* Win2k sends wparam set to
3003      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
3004      * while Win9x doesn't bother to set child window id according to
3005      * CLIENTCREATESTRUCT.idFirstChild
3006      */
3007     { 0x0090, sent|optional },
3008     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
3009
3010     { WM_SHOWWINDOW, sent|wparam, 0 },
3011     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3012     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
3013     { WM_ERASEBKGND, sent|parent|optional },
3014     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3015
3016     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
3017     { WM_DESTROY, sent },
3018     { WM_NCDESTROY, sent },
3019     { 0 }
3020 };
3021 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
3022 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
3023     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3024     { WM_GETMINMAXINFO, sent },
3025     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
3026     { WM_NCCALCSIZE, sent|wparam, 1 },
3027     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3028     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3029
3030     { WM_WINDOWPOSCHANGING, sent|wparam|optional|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3031     { WM_NCACTIVATE, sent|wparam|optional|defwinproc, 1 },
3032     { HCBT_SETFOCUS, hook|optional },
3033     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3034     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3035     { WM_SETFOCUS, sent|optional }, /* in MDI client */
3036     { HCBT_SETFOCUS, hook|optional },
3037     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3038     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3039     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3040     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3041     { WM_SETFOCUS, sent|optional|defwinproc },
3042     { WM_MDIACTIVATE, sent|optional|defwinproc },
3043     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3044     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3045      /* in MDI frame */
3046     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3047     { WM_NCCALCSIZE, sent|wparam, 1 },
3048     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3049     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3050     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3051     { 0 }
3052 };
3053 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
3054 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
3055     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3056     { WM_GETMINMAXINFO, sent },
3057     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
3058     { WM_GETMINMAXINFO, sent|defwinproc },
3059     { WM_NCCALCSIZE, sent|wparam, 1 },
3060     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3061     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3062
3063     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3064     { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
3065     { HCBT_SETFOCUS, hook|optional },
3066     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3067     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3068     { WM_SETFOCUS, sent|optional }, /* in MDI client */
3069     { HCBT_SETFOCUS, hook|optional },
3070     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3071     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3072     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3073     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3074     { WM_SETFOCUS, sent|defwinproc|optional },
3075     { WM_MDIACTIVATE, sent|defwinproc|optional },
3076     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3077     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3078     { 0 }
3079 };
3080 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
3081 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
3082     { WM_MDIMAXIMIZE, sent }, /* in MDI client */
3083     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3084     { WM_GETMINMAXINFO, sent },
3085     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3086     { WM_GETMINMAXINFO, sent|defwinproc },
3087     { WM_NCCALCSIZE, sent|wparam, 1 },
3088     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
3089     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3090     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
3091     { WM_MOVE, sent|defwinproc },
3092     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3093
3094     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3095     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3096     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3097     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3098     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3099     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3100      /* in MDI frame */
3101     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3102     { WM_NCCALCSIZE, sent|wparam, 1 },
3103     { 0x0093, sent|defwinproc|optional },
3104     { 0x0094, sent|defwinproc|optional },
3105     { 0x0094, sent|defwinproc|optional },
3106     { 0x0094, sent|defwinproc|optional },
3107     { 0x0094, sent|defwinproc|optional },
3108     { 0x0093, sent|defwinproc|optional },
3109     { 0x0093, sent|defwinproc|optional },
3110     { 0x0091, sent|defwinproc|optional },
3111     { 0x0092, sent|defwinproc|optional },
3112     { 0x0092, sent|defwinproc|optional },
3113     { 0x0092, sent|defwinproc|optional },
3114     { 0x0092, sent|defwinproc|optional },
3115     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3116     { WM_MOVE, sent|defwinproc },
3117     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3118     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
3119      /* in MDI client */
3120     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
3121     { WM_NCCALCSIZE, sent|wparam, 1 },
3122     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3123     { WM_SIZE, sent|wparam, SIZE_RESTORED },
3124      /* in MDI child */
3125     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
3126     { WM_GETMINMAXINFO, sent|defwinproc },
3127     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3128     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3129     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3130     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
3131     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3132     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3133     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3134     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3135      /* in MDI frame */
3136     { 0x0093, sent|optional },
3137     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
3138     { 0x0093, sent|defwinproc|optional },
3139     { 0x0093, sent|defwinproc|optional },
3140     { 0x0093, sent|defwinproc|optional },
3141     { 0x0091, sent|defwinproc|optional },
3142     { 0x0092, sent|defwinproc|optional },
3143     { 0x0092, sent|defwinproc|optional },
3144     { 0x0092, sent|defwinproc|optional },
3145     { 0x0092, sent|defwinproc|optional },
3146     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3147     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3148     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3149     { 0 }
3150 };
3151 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
3152 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
3153     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3154     { WM_GETMINMAXINFO, sent },
3155     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3156     { WM_NCCALCSIZE, sent|wparam, 1 },
3157     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3158     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3159     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3160      /* in MDI frame */
3161     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3162     { WM_NCCALCSIZE, sent|wparam, 1 },
3163     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3164     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3165     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3166     { 0 }
3167 };
3168 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
3169 static const struct message WmRestoreMDIchildVisibleSeq[] = {
3170     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3171     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3172     { WM_NCCALCSIZE, sent|wparam, 1 },
3173     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3174     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3175     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3176      /* in MDI frame */
3177     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3178     { WM_NCCALCSIZE, sent|wparam, 1 },
3179     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3180     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3181     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3182     { 0 }
3183 };
3184 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
3185 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
3186     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3187     { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
3188     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3189     { WM_NCCALCSIZE, sent|wparam, 1 },
3190     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3191     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3192     { WM_MOVE, sent|defwinproc },
3193     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3194     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3195     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3196     { HCBT_SETFOCUS, hook },
3197     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3198     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
3199     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3200     { WM_SETFOCUS, sent },
3201     { 0 }
3202 };
3203 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
3204 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
3205     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
3206     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3207     { WM_NCCALCSIZE, sent|wparam, 1 },
3208     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3209     { WM_MOVE, sent|defwinproc },
3210     { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
3211     { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
3212     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3213     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3214     /* FIXME: Wine creates an icon/title window while Windows doesn't */
3215     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
3216     { 0 }
3217 };
3218 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
3219 static const struct message WmRestoreMDIchildInisibleSeq[] = {
3220     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3221     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED  },
3222     { WM_NCCALCSIZE, sent|wparam, 1 },
3223     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3224     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3225     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3226     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3227      /* in MDI frame */
3228     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3229     { WM_NCCALCSIZE, sent|wparam, 1 },
3230     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3231     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3232     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3233     { 0 }
3234 };
3235
3236 static HWND mdi_client;
3237 static WNDPROC old_mdi_client_proc;
3238
3239 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3240 {
3241     struct recvd_message msg;
3242
3243     /* do not log painting messages */
3244     if (message != WM_PAINT &&
3245         message != WM_NCPAINT &&
3246         message != WM_SYNCPAINT &&
3247         message != WM_ERASEBKGND &&
3248         message != WM_NCHITTEST &&
3249         message != WM_GETTEXT &&
3250         message != WM_MDIGETACTIVE &&
3251         !ignore_message( message ))
3252     {
3253         msg.hwnd = hwnd;
3254         msg.message = message;
3255         msg.flags = sent|wparam|lparam;
3256         msg.wParam = wParam;
3257         msg.lParam = lParam;
3258         msg.descr = "mdi client";
3259         add_message(&msg);
3260     }
3261
3262     return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
3263 }
3264
3265 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3266 {
3267     static LONG defwndproc_counter = 0;
3268     LRESULT ret;
3269     struct recvd_message msg;
3270
3271     /* do not log painting messages */
3272     if (message != WM_PAINT &&
3273         message != WM_NCPAINT &&
3274         message != WM_SYNCPAINT &&
3275         message != WM_ERASEBKGND &&
3276         message != WM_NCHITTEST &&
3277         message != WM_GETTEXT &&
3278         !ignore_message( message ))
3279     {
3280         switch (message)
3281         {
3282             case WM_MDIACTIVATE:
3283             {
3284                 HWND active, client = GetParent(hwnd);
3285
3286                 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
3287
3288                 if (hwnd == (HWND)lParam) /* if we are being activated */
3289                     ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
3290                 else
3291                     ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
3292                 break;
3293             }
3294         }
3295
3296         msg.hwnd = hwnd;
3297         msg.message = message;
3298         msg.flags = sent|wparam|lparam;
3299         if (defwndproc_counter) msg.flags |= defwinproc;
3300         msg.wParam = wParam;
3301         msg.lParam = lParam;
3302         msg.descr = "mdi child";
3303         add_message(&msg);
3304     }
3305
3306     defwndproc_counter++;
3307     ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
3308     defwndproc_counter--;
3309
3310     return ret;
3311 }
3312
3313 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3314 {
3315     static LONG defwndproc_counter = 0;
3316     LRESULT ret;
3317     struct recvd_message msg;
3318
3319     /* do not log painting messages */
3320     if (message != WM_PAINT &&
3321         message != WM_NCPAINT &&
3322         message != WM_SYNCPAINT &&
3323         message != WM_ERASEBKGND &&
3324         message != WM_NCHITTEST &&
3325         message != WM_GETTEXT &&
3326         !ignore_message( message ))
3327     {
3328         msg.hwnd = hwnd;
3329         msg.message = message;
3330         msg.flags = sent|wparam|lparam;
3331         if (defwndproc_counter) msg.flags |= defwinproc;
3332         msg.wParam = wParam;
3333         msg.lParam = lParam;
3334         msg.descr = "mdi frame";
3335         add_message(&msg);
3336     }
3337
3338     defwndproc_counter++;
3339     ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
3340     defwndproc_counter--;
3341
3342     return ret;
3343 }
3344
3345 static BOOL mdi_RegisterWindowClasses(void)
3346 {
3347     WNDCLASSA cls;
3348
3349     cls.style = 0;
3350     cls.lpfnWndProc = mdi_frame_wnd_proc;
3351     cls.cbClsExtra = 0;
3352     cls.cbWndExtra = 0;
3353     cls.hInstance = GetModuleHandleA(0);
3354     cls.hIcon = 0;
3355     cls.hCursor = LoadCursorA(0, IDC_ARROW);
3356     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3357     cls.lpszMenuName = NULL;
3358     cls.lpszClassName = "MDI_frame_class";
3359     if (!RegisterClassA(&cls)) return FALSE;
3360
3361     cls.lpfnWndProc = mdi_child_wnd_proc;
3362     cls.lpszClassName = "MDI_child_class";
3363     if (!RegisterClassA(&cls)) return FALSE;
3364
3365     if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
3366     old_mdi_client_proc = cls.lpfnWndProc;
3367     cls.hInstance = GetModuleHandleA(0);
3368     cls.lpfnWndProc = mdi_client_hook_proc;
3369     cls.lpszClassName = "MDI_client_class";
3370     if (!RegisterClassA(&cls)) assert(0);
3371
3372     return TRUE;
3373 }
3374
3375 static void test_mdi_messages(void)
3376 {
3377     MDICREATESTRUCTA mdi_cs;
3378     CLIENTCREATESTRUCT client_cs;
3379     HWND mdi_frame, mdi_child, mdi_child2, active_child;
3380     BOOL zoomed;
3381     RECT rc;
3382     HMENU hMenu = CreateMenu();
3383
3384     if (!mdi_RegisterWindowClasses()) assert(0);
3385
3386     flush_sequence();
3387
3388     trace("creating MDI frame window\n");
3389     mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
3390                                 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3391                                 WS_MAXIMIZEBOX | WS_VISIBLE,
3392                                 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
3393                                 GetDesktopWindow(), hMenu,
3394                                 GetModuleHandleA(0), NULL);
3395     assert(mdi_frame);
3396     ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
3397
3398     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3399     ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
3400
3401     trace("creating MDI client window\n");
3402     GetClientRect(mdi_frame, &rc);
3403     client_cs.hWindowMenu = 0;
3404     client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
3405     mdi_client = CreateWindowExA(0, "MDI_client_class",
3406                                  NULL,
3407                                  WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
3408                                  rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
3409                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3410     assert(mdi_client);
3411     ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
3412
3413     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3414     ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
3415
3416     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3417     ok(!active_child, "wrong active MDI child %p\n", active_child);
3418     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3419
3420     SetFocus(0);
3421     flush_sequence();
3422
3423     trace("creating invisible MDI child window\n");
3424     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3425                                 WS_CHILD,
3426                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3427                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3428     assert(mdi_child);
3429
3430     flush_sequence();
3431     ShowWindow(mdi_child, SW_SHOWNORMAL);
3432     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
3433
3434     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3435     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3436
3437     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3438     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3439
3440     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3441     ok(!active_child, "wrong active MDI child %p\n", active_child);
3442     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3443
3444     ShowWindow(mdi_child, SW_HIDE);
3445     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
3446     flush_sequence();
3447
3448     ShowWindow(mdi_child, SW_SHOW);
3449     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) 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() == 0, "wrong focus window %p\n", GetFocus());
3456
3457     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3458     ok(!active_child, "wrong active MDI child %p\n", active_child);
3459     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3460
3461     DestroyWindow(mdi_child);
3462     flush_sequence();
3463
3464     trace("creating visible MDI child window\n");
3465     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3466                                 WS_CHILD | WS_VISIBLE,
3467                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3468                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3469     assert(mdi_child);
3470     ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
3471
3472     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3473     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3474
3475     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3476     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3477
3478     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3479     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3480     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3481     flush_sequence();
3482
3483     DestroyWindow(mdi_child);
3484     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3485
3486     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3487     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3488
3489     /* Win2k: MDI client still returns a just destroyed child as active
3490      * Win9x: MDI client returns 0
3491      */
3492     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3493     ok(active_child == mdi_child || /* win2k */
3494        !active_child, /* win9x */
3495        "wrong active MDI child %p\n", active_child);
3496     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3497
3498     flush_sequence();
3499
3500     trace("creating invisible MDI child window\n");
3501     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3502                                 WS_CHILD,
3503                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3504                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3505     assert(mdi_child2);
3506     ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
3507
3508     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
3509     ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
3510
3511     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3512     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3513
3514     /* Win2k: MDI client still returns a just destroyed child as active
3515      * Win9x: MDI client returns mdi_child2
3516      */
3517     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3518     ok(active_child == mdi_child || /* win2k */
3519        active_child == mdi_child2, /* win9x */
3520        "wrong active MDI child %p\n", active_child);
3521     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3522     flush_sequence();
3523
3524     ShowWindow(mdi_child2, SW_MAXIMIZE);
3525     ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3526
3527     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3528     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3529
3530     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3531     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3532     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3533     flush_sequence();
3534
3535     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3536     ok(GetFocus() == mdi_child2 || /* win2k */
3537        GetFocus() == 0, /* win9x */
3538        "wrong focus window %p\n", GetFocus());
3539
3540     SetFocus(0);
3541     flush_sequence();
3542
3543     ShowWindow(mdi_child2, SW_HIDE);
3544     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3545
3546     ShowWindow(mdi_child2, SW_RESTORE);
3547     ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3548     flush_sequence();
3549
3550     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3551     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3552
3553     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3554     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3555     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3556     flush_sequence();
3557
3558     SetFocus(0);
3559     flush_sequence();
3560
3561     ShowWindow(mdi_child2, SW_HIDE);
3562     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3563
3564     ShowWindow(mdi_child2, SW_SHOW);
3565     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3566
3567     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3568     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3569
3570     ShowWindow(mdi_child2, SW_MAXIMIZE);
3571     ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3572
3573     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3574     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3575
3576     ShowWindow(mdi_child2, SW_RESTORE);
3577     ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3578
3579     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3580     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3581
3582     ShowWindow(mdi_child2, SW_MINIMIZE);
3583     ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3584
3585     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3586     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3587
3588     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3589     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3590     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3591     flush_sequence();
3592
3593     ShowWindow(mdi_child2, SW_RESTORE);
3594     ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", FALSE);
3595
3596     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3597     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3598
3599     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3600     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3601     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3602     flush_sequence();
3603
3604     SetFocus(0);
3605     flush_sequence();
3606
3607     ShowWindow(mdi_child2, SW_HIDE);
3608     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3609
3610     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3611     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3612
3613     DestroyWindow(mdi_child2);
3614     ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3615
3616     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3617     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3618
3619     /* test for maximized MDI children */
3620     trace("creating maximized visible MDI child window 1\n");
3621     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3622                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3623                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3624                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3625     assert(mdi_child);
3626     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3627     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3628
3629     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3630     ok(GetFocus() == mdi_child || /* win2k */
3631        GetFocus() == 0, /* win9x */
3632        "wrong focus window %p\n", GetFocus());
3633
3634     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3635     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3636     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3637     flush_sequence();
3638
3639     trace("creating maximized visible MDI child window 2\n");
3640     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3641                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3642                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3643                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3644     assert(mdi_child2);
3645     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3646     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3647     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3648
3649     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3650     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3651
3652     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3653     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3654     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3655     flush_sequence();
3656
3657     trace("destroying maximized visible MDI child window 2\n");
3658     DestroyWindow(mdi_child2);
3659     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3660
3661     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3662
3663     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3664     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3665
3666     /* Win2k: MDI client still returns a just destroyed child as active
3667      * Win9x: MDI client returns 0
3668      */
3669     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3670     ok(active_child == mdi_child2 || /* win2k */
3671        !active_child, /* win9x */
3672        "wrong active MDI child %p\n", active_child);
3673     flush_sequence();
3674
3675     ShowWindow(mdi_child, SW_MAXIMIZE);
3676     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3677     flush_sequence();
3678
3679     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3680     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3681
3682     trace("re-creating maximized visible MDI child window 2\n");
3683     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3684                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3685                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3686                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3687     assert(mdi_child2);
3688     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3689     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3690     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3691
3692     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3693     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3694
3695     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3696     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3697     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3698     flush_sequence();
3699
3700     SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3701     ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3702     ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3703
3704     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3705     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3706     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3707
3708     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3709     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3710     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3711     flush_sequence();
3712
3713     DestroyWindow(mdi_child);
3714     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3715
3716     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3717     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3718
3719     /* Win2k: MDI client still returns a just destroyed child as active
3720      * Win9x: MDI client returns 0
3721      */
3722     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3723     ok(active_child == mdi_child || /* win2k */
3724        !active_child, /* win9x */
3725        "wrong active MDI child %p\n", active_child);
3726     flush_sequence();
3727
3728     trace("creating maximized invisible MDI child window\n");
3729     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3730                                 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3731                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3732                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3733     assert(mdi_child2);
3734     ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", FALSE);
3735     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3736     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3737     ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3738
3739     /* Win2k: MDI client still returns a just destroyed child as active
3740      * Win9x: MDI client returns 0
3741      */
3742     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3743     ok(active_child == mdi_child || /* win2k */
3744        !active_child || active_child == mdi_child2, /* win9x */
3745        "wrong active MDI child %p\n", active_child);
3746     flush_sequence();
3747
3748     trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3749     ShowWindow(mdi_child2, SW_MAXIMIZE);
3750     ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3751     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3752     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3753     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3754
3755     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3756     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3757     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3758     flush_sequence();
3759
3760     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3761     flush_sequence();
3762
3763     /* end of test for maximized MDI children */
3764     SetFocus(0);
3765     flush_sequence();
3766     trace("creating maximized visible MDI child window 1(Switch test)\n");
3767     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3768                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3769                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3770                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3771     assert(mdi_child);
3772     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3773     ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3774
3775     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3776     ok(GetFocus() == mdi_child || /* win2k */
3777        GetFocus() == 0, /* win9x */
3778        "wrong focus window %p(Switch test)\n", GetFocus());
3779
3780     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3781     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3782     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3783     flush_sequence();
3784
3785     trace("creating maximized visible MDI child window 2(Switch test)\n");
3786     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3787                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3788                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3789                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3790     assert(mdi_child2);
3791     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3792
3793     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3794     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3795
3796     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3797     ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3798
3799     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3800     ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3801     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3802     flush_sequence();
3803
3804     trace("Switch child window.\n");
3805     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3806     ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3807     trace("end of test for switch maximized MDI children\n");
3808     flush_sequence();
3809
3810     /* Prepare for switching test of not maximized MDI children  */
3811     ShowWindow( mdi_child, SW_NORMAL );
3812     ok(!IsZoomed(mdi_child), "wrong zoomed state for %p(Switch test)\n", mdi_child);
3813     ok(!IsZoomed(mdi_child2), "wrong zoomed state for %p(Switch test)\n", mdi_child2);
3814     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
3815     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3816     flush_sequence();
3817
3818     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child2, 0);
3819     ok_sequence(WmSwitchNotMaximizedChild, "Not maximized child did not switch correctly", FALSE);
3820     trace("end of test for switch not maximized MDI children\n");
3821     flush_sequence();
3822
3823     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3824     flush_sequence();
3825
3826     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3827     flush_sequence();
3828
3829     SetFocus(0);
3830     flush_sequence();
3831     /* end of tests for switch maximized/not maximized MDI children */
3832
3833     mdi_cs.szClass = "MDI_child_Class";
3834     mdi_cs.szTitle = "MDI child";
3835     mdi_cs.hOwner = GetModuleHandleA(0);
3836     mdi_cs.x = 0;
3837     mdi_cs.y = 0;
3838     mdi_cs.cx = CW_USEDEFAULT;
3839     mdi_cs.cy = CW_USEDEFAULT;
3840     mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3841     mdi_cs.lParam = 0;
3842     mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3843     ok(mdi_child != 0, "MDI child creation failed\n");
3844     ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3845
3846     ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3847
3848     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3849     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3850
3851     ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3852     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3853     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3854
3855     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3856     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3857     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3858     flush_sequence();
3859
3860     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3861     ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3862
3863     ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3864     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3865     ok(!active_child, "wrong active MDI child %p\n", active_child);
3866
3867     SetFocus(0);
3868     flush_sequence();
3869
3870     DestroyWindow(mdi_client);
3871     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3872
3873     /* test maximization of MDI child with invisible parent */
3874     client_cs.hWindowMenu = 0;
3875     mdi_client = CreateWindow("MDI_client_class",
3876                                  NULL,
3877                                  WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3878                                  0, 0, 660, 430,
3879                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3880     ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3881
3882     ShowWindow(mdi_client, SW_HIDE);
3883     ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3884
3885     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3886                                 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3887                                 0, 0, 650, 440,
3888                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3889     ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3890
3891     SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3892     ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3893     zoomed = IsZoomed(mdi_child);
3894     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3895     
3896     ShowWindow(mdi_client, SW_SHOW);
3897     ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3898
3899     DestroyWindow(mdi_child);
3900     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3901
3902     /* end of test for maximization of MDI child with invisible parent */
3903
3904     DestroyWindow(mdi_client);
3905     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3906
3907     DestroyWindow(mdi_frame);
3908     ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3909 }
3910 /************************* End of MDI test **********************************/
3911
3912 static void test_WM_SETREDRAW(HWND hwnd)
3913 {
3914     DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3915
3916     flush_events();
3917     flush_sequence();
3918
3919     SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3920     ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3921
3922     ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3923     ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3924
3925     flush_sequence();
3926     SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3927     ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3928
3929     ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3930     ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3931
3932     /* restore original WS_VISIBLE state */
3933     SetWindowLongA(hwnd, GWL_STYLE, style);
3934
3935     flush_events();
3936     flush_sequence();
3937 }
3938
3939 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3940 {
3941     struct recvd_message msg;
3942
3943     if (ignore_message( message )) return 0;
3944
3945     switch (message)
3946     {
3947         /* ignore */
3948         case WM_MOUSEMOVE:
3949         case WM_NCMOUSEMOVE:
3950         case WM_NCMOUSELEAVE:
3951         case WM_SETCURSOR:
3952             return 0;
3953         case WM_NCHITTEST:
3954             return HTCLIENT;
3955     }
3956
3957     msg.hwnd = hwnd;
3958     msg.message = message;
3959     msg.flags = sent|wparam|lparam;
3960     msg.wParam = wParam;
3961     msg.lParam = lParam;
3962     msg.descr = "dialog";
3963     add_message(&msg);
3964
3965     if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3966     if (message == WM_TIMER) EndDialog( hwnd, 0 );
3967     return 0;
3968 }
3969
3970 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3971 {
3972     DWORD style, exstyle;
3973     INT xmin, xmax;
3974     BOOL ret;
3975
3976     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3977     style = GetWindowLongA(hwnd, GWL_STYLE);
3978     /* do not be confused by WS_DLGFRAME set */
3979     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3980
3981     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3982     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3983
3984     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3985     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3986     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3987         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3988     else
3989         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3990
3991     style = GetWindowLongA(hwnd, GWL_STYLE);
3992     if (set) ok(style & set, "style %08x should be set\n", set);
3993     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3994
3995     /* a subsequent call should do nothing */
3996     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3997     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3998     ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3999
4000     xmin = 0xdeadbeef;
4001     xmax = 0xdeadbeef;
4002     ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
4003     ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
4004     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
4005     ok(xmin == min, "unexpected min scroll value %d\n", xmin);
4006     ok(xmax == max, "unexpected max scroll value %d\n", xmax);
4007 }
4008
4009 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
4010 {
4011     DWORD style, exstyle;
4012     SCROLLINFO si;
4013     BOOL ret;
4014
4015     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
4016     style = GetWindowLongA(hwnd, GWL_STYLE);
4017     /* do not be confused by WS_DLGFRAME set */
4018     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
4019
4020     if (clear) ok(style & clear, "style %08x should be set\n", clear);
4021     if (set) ok(!(style & set), "style %08x should not be set\n", set);
4022
4023     si.cbSize = sizeof(si);
4024     si.fMask = SIF_RANGE;
4025     si.nMin = min;
4026     si.nMax = max;
4027     SetScrollInfo(hwnd, ctl, &si, TRUE);
4028     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
4029         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
4030     else
4031         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
4032
4033     style = GetWindowLongA(hwnd, GWL_STYLE);
4034     if (set) ok(style & set, "style %08x should be set\n", set);
4035     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
4036
4037     /* a subsequent call should do nothing */
4038     SetScrollInfo(hwnd, ctl, &si, TRUE);
4039     if (style & WS_HSCROLL)
4040         ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4041     else if (style & WS_VSCROLL)
4042         ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4043     else
4044         ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4045
4046     si.fMask = SIF_PAGE;
4047     si.nPage = 5;
4048     SetScrollInfo(hwnd, ctl, &si, FALSE);
4049     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4050
4051     si.fMask = SIF_POS;
4052     si.nPos = max - 1;
4053     SetScrollInfo(hwnd, ctl, &si, FALSE);
4054     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4055
4056     si.fMask = SIF_RANGE;
4057     si.nMin = 0xdeadbeef;
4058     si.nMax = 0xdeadbeef;
4059     ret = GetScrollInfo(hwnd, ctl, &si);
4060     ok( ret, "GetScrollInfo error %d\n", GetLastError());
4061     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
4062     ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
4063     ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
4064 }
4065
4066 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
4067 static void test_scroll_messages(HWND hwnd)
4068 {
4069     SCROLLINFO si;
4070     INT min, max;
4071     BOOL ret;
4072
4073     flush_events();
4074     flush_sequence();
4075
4076     min = 0xdeadbeef;
4077     max = 0xdeadbeef;
4078     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4079     ok( ret, "GetScrollRange error %d\n", GetLastError());
4080     if (sequence->message != WmGetScrollRangeSeq[0].message)
4081         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4082     /* values of min and max are undefined */
4083     flush_sequence();
4084
4085     ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
4086     ok( ret, "SetScrollRange error %d\n", GetLastError());
4087     if (sequence->message != WmSetScrollRangeSeq[0].message)
4088         trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4089     flush_sequence();
4090
4091     min = 0xdeadbeef;
4092     max = 0xdeadbeef;
4093     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4094     ok( ret, "GetScrollRange error %d\n", GetLastError());
4095     if (sequence->message != WmGetScrollRangeSeq[0].message)
4096         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4097     /* values of min and max are undefined */
4098     flush_sequence();
4099
4100     si.cbSize = sizeof(si);
4101     si.fMask = SIF_RANGE;
4102     si.nMin = 20;
4103     si.nMax = 160;
4104     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4105     if (sequence->message != WmSetScrollRangeSeq[0].message)
4106         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4107     flush_sequence();
4108
4109     si.fMask = SIF_PAGE;
4110     si.nPage = 10;
4111     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4112     if (sequence->message != WmSetScrollRangeSeq[0].message)
4113         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4114     flush_sequence();
4115
4116     si.fMask = SIF_POS;
4117     si.nPos = 20;
4118     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4119     if (sequence->message != WmSetScrollRangeSeq[0].message)
4120         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4121     flush_sequence();
4122
4123     si.fMask = SIF_RANGE;
4124     si.nMin = 0xdeadbeef;
4125     si.nMax = 0xdeadbeef;
4126     ret = GetScrollInfo(hwnd, SB_CTL, &si);
4127     ok( ret, "GetScrollInfo error %d\n", GetLastError());
4128     if (sequence->message != WmGetScrollInfoSeq[0].message)
4129         trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4130     /* values of min and max are undefined */
4131     flush_sequence();
4132
4133     /* set WS_HSCROLL */
4134     test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4135     /* clear WS_HSCROLL */
4136     test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4137
4138     /* set WS_HSCROLL */
4139     test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4140     /* clear WS_HSCROLL */
4141     test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4142
4143     /* set WS_VSCROLL */
4144     test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4145     /* clear WS_VSCROLL */
4146     test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4147
4148     /* set WS_VSCROLL */
4149     test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4150     /* clear WS_VSCROLL */
4151     test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4152 }
4153
4154 static void test_showwindow(void)
4155 {
4156     HWND hwnd, hchild;
4157     RECT rc;
4158
4159     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4160                            100, 100, 200, 200, 0, 0, 0, NULL);
4161     ok (hwnd != 0, "Failed to create overlapped window\n");
4162     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4163                              0, 0, 10, 10, hwnd, 0, 0, NULL);
4164     ok (hchild != 0, "Failed to create child\n");
4165     flush_sequence();
4166
4167     /* ShowWindow( SW_SHOWNA) for invisible top level window */
4168     trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
4169     ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4170     ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", FALSE);
4171
4172     /* ShowWindow( SW_SHOWNA) for now visible top level window */
4173     trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
4174     ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4175     ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
4176     /* back to invisible */
4177     ShowWindow(hchild, SW_HIDE);
4178     ShowWindow(hwnd, SW_HIDE);
4179     flush_sequence();
4180     /* ShowWindow(SW_SHOWNA) with child and parent invisible */ 
4181     trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
4182     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4183     ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
4184     /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */ 
4185     ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
4186     flush_sequence();
4187     trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
4188     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4189     ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
4190     /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
4191     ShowWindow( hwnd, SW_SHOW);
4192     flush_sequence();
4193     trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
4194     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4195     ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
4196
4197     /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
4198     ShowWindow( hchild, SW_HIDE);
4199     flush_sequence();
4200     trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
4201     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4202     ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
4203
4204     SetCapture(hchild);
4205     ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
4206     DestroyWindow(hchild);
4207     ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
4208
4209     DestroyWindow(hwnd);
4210     flush_sequence();
4211
4212     /* Popup windows */
4213     /* Test 1:
4214      * 1. Create invisible maximized popup window.
4215      * 2. Move and resize it.
4216      * 3. Show it maximized.
4217      */
4218     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4219     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4220                            100, 100, 200, 200, 0, 0, 0, NULL);
4221     ok (hwnd != 0, "Failed to create popup window\n");
4222     ok(IsZoomed(hwnd), "window should be maximized\n");
4223     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4224
4225     GetWindowRect(hwnd, &rc);
4226     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4227         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4228         "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
4229         rc.left, rc.top, rc.right, rc.bottom);
4230     /* Reset window's size & position */
4231     SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
4232     ok(IsZoomed(hwnd), "window should be maximized\n");
4233     flush_sequence();
4234
4235     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4236     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4237     ok(IsZoomed(hwnd), "window should be maximized\n");
4238     ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
4239
4240     GetWindowRect(hwnd, &rc);
4241     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4242         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4243         "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
4244         rc.left, rc.top, rc.right, rc.bottom);
4245     DestroyWindow(hwnd);
4246     flush_sequence();
4247
4248     /* Test 2:
4249      * 1. Create invisible maximized popup window.
4250      * 2. Show it maximized.
4251      */
4252     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4253     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4254                            100, 100, 200, 200, 0, 0, 0, NULL);
4255     ok (hwnd != 0, "Failed to create popup window\n");
4256     ok(IsZoomed(hwnd), "window should be maximized\n");
4257     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4258
4259     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4260     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4261     ok(IsZoomed(hwnd), "window should be maximized\n");
4262     ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
4263     DestroyWindow(hwnd);
4264     flush_sequence();
4265
4266     /* Test 3:
4267      * 1. Create visible maximized popup window.
4268      */
4269     trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
4270     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4271                            100, 100, 200, 200, 0, 0, 0, NULL);
4272     ok (hwnd != 0, "Failed to create popup window\n");
4273     ok(IsZoomed(hwnd), "window should be maximized\n");
4274     ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4275     DestroyWindow(hwnd);
4276     flush_sequence();
4277
4278     /* Test 4:
4279      * 1. Create visible popup window.
4280      * 2. Maximize it.
4281      */
4282     trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
4283     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
4284                            100, 100, 200, 200, 0, 0, 0, NULL);
4285     ok (hwnd != 0, "Failed to create popup window\n");
4286     ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
4287     ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
4288
4289     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
4290     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4291     ok(IsZoomed(hwnd), "window should be maximized\n");
4292     ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
4293     DestroyWindow(hwnd);
4294     flush_sequence();
4295 }
4296
4297 static void test_sys_menu(void)
4298 {
4299     HWND hwnd;
4300     HMENU hmenu;
4301     UINT state;
4302
4303     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4304                            100, 100, 200, 200, 0, 0, 0, NULL);
4305     ok (hwnd != 0, "Failed to create overlapped window\n");
4306
4307     flush_sequence();
4308
4309     /* test existing window without CS_NOCLOSE style */
4310     hmenu = GetSystemMenu(hwnd, FALSE);
4311     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4312
4313     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4314     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4315     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4316
4317     EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
4318     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4319
4320     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4321     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4322     ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
4323
4324     EnableMenuItem(hmenu, SC_CLOSE, 0);
4325     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4326
4327     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4328     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4329     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4330
4331     /* test whether removing WS_SYSMENU destroys a system menu */
4332     SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
4333     SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4334     flush_sequence();
4335     hmenu = GetSystemMenu(hwnd, FALSE);
4336     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4337
4338     DestroyWindow(hwnd);
4339
4340     /* test new window with CS_NOCLOSE style */
4341     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4342                            100, 100, 200, 200, 0, 0, 0, NULL);
4343     ok (hwnd != 0, "Failed to create overlapped window\n");
4344
4345     hmenu = GetSystemMenu(hwnd, FALSE);
4346     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4347
4348     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4349     ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4350
4351     DestroyWindow(hwnd);
4352
4353     /* test new window without WS_SYSMENU style */
4354     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
4355                            100, 100, 200, 200, 0, 0, 0, NULL);
4356     ok(hwnd != 0, "Failed to create overlapped window\n");
4357
4358     hmenu = GetSystemMenu(hwnd, FALSE);
4359     ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
4360
4361     DestroyWindow(hwnd);
4362 }
4363
4364 /* For shown WS_OVERLAPPEDWINDOW */
4365 static const struct message WmSetIcon_1[] = {
4366     { WM_SETICON, sent },
4367     { 0x00AE, sent|defwinproc|optional }, /* XP */
4368     { WM_GETTEXT, sent|defwinproc|optional },
4369     { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
4370     { 0 }
4371 };
4372
4373 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
4374 static const struct message WmSetIcon_2[] = {
4375     { WM_SETICON, sent },
4376     { 0 }
4377 };
4378
4379 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4380 static const struct message WmInitEndSession[] = {
4381     { 0x003B, sent },
4382     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4383     { 0 }
4384 };
4385
4386 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4387 static const struct message WmInitEndSession_2[] = {
4388     { 0x003B, sent },
4389     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4390     { 0 }
4391 };
4392
4393 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4394 static const struct message WmInitEndSession_3[] = {
4395     { 0x003B, sent },
4396     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4397     { 0 }
4398 };
4399
4400 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4401 static const struct message WmInitEndSession_4[] = {
4402     { 0x003B, sent },
4403     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4404     { 0 }
4405 };
4406
4407 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4408 static const struct message WmInitEndSession_5[] = {
4409     { 0x003B, sent },
4410     { WM_ENDSESSION, sent|defwinproc/*|wparam*/|lparam, 1, ENDSESSION_LOGOFF },
4411     { 0 }
4412 };
4413
4414 static const struct message WmOptionalPaint[] = {
4415     { WM_PAINT, sent|optional },
4416     { WM_NCPAINT, sent|beginpaint|optional },
4417     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4418     { WM_ERASEBKGND, sent|beginpaint|optional },
4419     { 0 }
4420 };
4421
4422 static const struct message WmZOrder[] = {
4423     { WM_WINDOWPOSCHANGING, sent|wparam, 0, 0 },
4424     { WM_GETMINMAXINFO, sent|defwinproc|wparam, 0, 0 },
4425     { HCBT_ACTIVATE, hook },
4426     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
4427     { WM_WINDOWPOSCHANGING, sent|wparam, 3, 0 },
4428     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0 },
4429     { WM_GETTEXT, sent|optional },
4430     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
4431     { WM_ACTIVATEAPP, sent|wparam, 1, 0 },
4432     { WM_NCACTIVATE, sent|lparam, 1, 0 },
4433     { WM_GETTEXT, sent|defwinproc|optional },
4434     { WM_GETTEXT, sent|defwinproc|optional },
4435     { WM_ACTIVATE, sent|wparam|lparam, 1, 0 },
4436     { HCBT_SETFOCUS, hook },
4437     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4438     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4439     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4440     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
4441     { WM_GETTEXT, sent|optional },
4442     { WM_NCCALCSIZE, sent|optional },
4443     { 0 }
4444 };
4445
4446 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4447 {
4448     DWORD ret;
4449     MSG msg;
4450
4451     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4452     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4453
4454     PostMessageA(hwnd, WM_USER, 0, 0);
4455
4456     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4457     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4458
4459     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4460     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4461
4462     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4463     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4464
4465     PostMessageA(hwnd, WM_USER, 0, 0);
4466
4467     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4468     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4469
4470     ok(PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4471     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4472
4473     /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4474     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4475     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4476
4477     PostMessageA(hwnd, WM_USER, 0, 0);
4478
4479     /* new incoming message causes it to become signaled again */
4480     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4481     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4482
4483     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4484     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4485     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4486     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4487 }
4488
4489 /* test if we receive the right sequence of messages */
4490 static void test_messages(void)
4491 {
4492     HWND hwnd, hparent, hchild;
4493     HWND hchild2, hbutton;
4494     HMENU hmenu;
4495     MSG msg;
4496     LRESULT res;
4497
4498     flush_sequence();
4499
4500     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4501                            100, 100, 200, 200, 0, 0, 0, NULL);
4502     ok (hwnd != 0, "Failed to create overlapped window\n");
4503     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4504
4505     /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4506     ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4507     ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4508
4509     /* test WM_SETREDRAW on a not visible top level window */
4510     test_WM_SETREDRAW(hwnd);
4511
4512     SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4513     flush_events();
4514     ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4515     ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4516
4517     ok(GetActiveWindow() == hwnd, "window should be active\n");
4518     ok(GetFocus() == hwnd, "window should have input focus\n");
4519     ShowWindow(hwnd, SW_HIDE);
4520     flush_events();
4521     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4522
4523     ShowWindow(hwnd, SW_SHOW);
4524     flush_events();
4525     ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4526
4527     ShowWindow(hwnd, SW_HIDE);
4528     flush_events();
4529     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4530
4531     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4532     flush_events();
4533     ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4534     flush_sequence();
4535
4536     if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MAXIMIZE)
4537     {
4538         ShowWindow(hwnd, SW_RESTORE);
4539         flush_events();
4540         ok_sequence(WmShowRestoreMaxOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4541         flush_sequence();
4542     }
4543
4544     ShowWindow(hwnd, SW_MINIMIZE);
4545     flush_events();
4546     ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4547     flush_sequence();
4548
4549     if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MINIMIZE)
4550     {
4551         ShowWindow(hwnd, SW_RESTORE);
4552         flush_events();
4553         ok_sequence(WmShowRestoreMinOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4554         flush_sequence();
4555     }
4556
4557     ShowWindow(hwnd, SW_SHOW);
4558     flush_events();
4559     ok_sequence(WmOptionalPaint, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4560
4561     SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4562     ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4563     ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4564     ok(GetActiveWindow() == hwnd, "window should still be active\n");
4565
4566     /* test WM_SETREDRAW on a visible top level window */
4567     ShowWindow(hwnd, SW_SHOW);
4568     flush_events();
4569     test_WM_SETREDRAW(hwnd);
4570
4571     trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4572     test_scroll_messages(hwnd);
4573
4574     /* test resizing and moving */
4575     SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4576     ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4577     flush_events();
4578     flush_sequence();
4579     SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4580     ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4581     flush_events();
4582     flush_sequence();
4583     SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER|SWP_NOACTIVATE );
4584     ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4585     flush_events();
4586     flush_sequence();
4587
4588     /* popups don't get WM_GETMINMAXINFO */
4589     SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4590     SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4591     flush_sequence();
4592     SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4593     ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4594
4595     DestroyWindow(hwnd);
4596     ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4597
4598     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4599                               100, 100, 200, 200, 0, 0, 0, NULL);
4600     ok (hparent != 0, "Failed to create parent window\n");
4601     flush_sequence();
4602
4603     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4604                              0, 0, 10, 10, hparent, 0, 0, NULL);
4605     ok (hchild != 0, "Failed to create child window\n");
4606     ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4607     DestroyWindow(hchild);
4608     flush_sequence();
4609
4610     /* visible child window with a caption */
4611     hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4612                              WS_CHILD | WS_VISIBLE | WS_CAPTION,
4613                              0, 0, 10, 10, hparent, 0, 0, NULL);
4614     ok (hchild != 0, "Failed to create child window\n");
4615     ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4616
4617     trace("testing scroll APIs on a visible child window %p\n", hchild);
4618     test_scroll_messages(hchild);
4619
4620     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4621     ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4622
4623     DestroyWindow(hchild);
4624     flush_sequence();
4625
4626     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4627                              0, 0, 10, 10, hparent, 0, 0, NULL);
4628     ok (hchild != 0, "Failed to create child window\n");
4629     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4630     
4631     hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4632                                100, 100, 50, 50, hparent, 0, 0, NULL);
4633     ok (hchild2 != 0, "Failed to create child2 window\n");
4634     flush_sequence();
4635
4636     hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4637                               0, 100, 50, 50, hchild, 0, 0, NULL);
4638     ok (hbutton != 0, "Failed to create button window\n");
4639
4640     /* test WM_SETREDRAW on a not visible child window */
4641     test_WM_SETREDRAW(hchild);
4642
4643     ShowWindow(hchild, SW_SHOW);
4644     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4645
4646     /* check parent messages too */
4647     log_all_parent_messages++;
4648     ShowWindow(hchild, SW_HIDE);
4649     ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4650     log_all_parent_messages--;
4651
4652     ShowWindow(hchild, SW_SHOW);
4653     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4654
4655     ShowWindow(hchild, SW_HIDE);
4656     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4657
4658     ShowWindow(hchild, SW_SHOW);
4659     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4660
4661     /* test WM_SETREDRAW on a visible child window */
4662     test_WM_SETREDRAW(hchild);
4663
4664     log_all_parent_messages++;
4665     MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4666     ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4667     log_all_parent_messages--;
4668
4669     ShowWindow(hchild, SW_HIDE);
4670     flush_sequence();
4671     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4672     ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4673
4674     ShowWindow(hchild, SW_HIDE);
4675     flush_sequence();
4676     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4677     ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4678
4679     /* DestroyWindow sequence below expects that a child has focus */
4680     SetFocus(hchild);
4681     flush_sequence();
4682
4683     DestroyWindow(hchild);
4684     ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4685     DestroyWindow(hchild2);
4686     DestroyWindow(hbutton);
4687
4688     flush_sequence();
4689     hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4690                              0, 0, 100, 100, hparent, 0, 0, NULL);
4691     ok (hchild != 0, "Failed to create child popup window\n");
4692     ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4693     DestroyWindow(hchild);
4694
4695     /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4696     flush_sequence();
4697     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
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     flush_sequence();
4710     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4711     ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
4712     DestroyWindow(hchild);
4713
4714     /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4715      * changes nothing in message sequences.
4716      */
4717     flush_sequence();
4718     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4719                              0, 0, 100, 100, hparent, 0, 0, NULL);
4720     ok (hchild != 0, "Failed to create popup window\n");
4721     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4722     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4723     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4724     flush_sequence();
4725     ShowWindow(hchild, SW_SHOW);
4726     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4727     flush_sequence();
4728     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4729     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4730     DestroyWindow(hchild);
4731
4732     flush_sequence();
4733     hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4734                            0, 0, 100, 100, hparent, 0, 0, NULL);
4735     ok(hwnd != 0, "Failed to create custom dialog window\n");
4736     ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4737
4738     if(0) {
4739     trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4740     test_scroll_messages(hwnd);
4741     }
4742
4743     flush_sequence();
4744
4745     test_def_id = 1;
4746     SendMessage(hwnd, WM_NULL, 0, 0);
4747
4748     flush_sequence();
4749     after_end_dialog = 1;
4750     EndDialog( hwnd, 0 );
4751     ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4752
4753     DestroyWindow(hwnd);
4754     after_end_dialog = 0;
4755     test_def_id = 0;
4756
4757     hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4758                            0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4759     ok(hwnd != 0, "Failed to create custom dialog window\n");
4760     flush_sequence();
4761     trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4762     ShowWindow(hwnd, SW_SHOW);
4763     ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4764     DestroyWindow(hwnd);
4765
4766     flush_sequence();
4767     DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4768     ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4769
4770     DestroyWindow(hparent);
4771     flush_sequence();
4772
4773     /* Message sequence for SetMenu */
4774     ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4775     ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4776
4777     hmenu = CreateMenu();
4778     ok (hmenu != 0, "Failed to create menu\n");
4779     ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4780     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4781                            100, 100, 200, 200, 0, hmenu, 0, NULL);
4782     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4783     ok (SetMenu(hwnd, 0), "SetMenu\n");
4784     ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4785     ok (SetMenu(hwnd, 0), "SetMenu\n");
4786     ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4787     ShowWindow(hwnd, SW_SHOW);
4788     UpdateWindow( hwnd );
4789     flush_events();
4790     flush_sequence();
4791     ok (SetMenu(hwnd, 0), "SetMenu\n");
4792     ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4793     ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4794     ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4795
4796     UpdateWindow( hwnd );
4797     flush_events();
4798     flush_sequence();
4799     ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4800     flush_events();
4801     ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4802
4803     DestroyWindow(hwnd);
4804     flush_sequence();
4805
4806     /* Message sequence for EnableWindow */
4807     hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4808                               100, 100, 200, 200, 0, 0, 0, NULL);
4809     ok (hparent != 0, "Failed to create parent window\n");
4810     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4811                              0, 0, 10, 10, hparent, 0, 0, NULL);
4812     ok (hchild != 0, "Failed to create child window\n");
4813
4814     SetFocus(hchild);
4815     flush_events();
4816     flush_sequence();
4817
4818     EnableWindow(hparent, FALSE);
4819     ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4820
4821     EnableWindow(hparent, TRUE);
4822     ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4823
4824     flush_events();
4825     flush_sequence();
4826
4827     test_MsgWaitForMultipleObjects(hparent);
4828
4829     /* the following test causes an exception in user.exe under win9x */
4830     if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4831     {
4832         DestroyWindow(hparent);
4833         flush_sequence();
4834         return;
4835     }
4836     PostMessageW( hparent, WM_USER+1, 0, 0 );
4837     /* PeekMessage(NULL) fails, but still removes the message */
4838     SetLastError(0xdeadbeef);
4839     ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4840     ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4841         GetLastError() == 0xdeadbeef, /* NT4 */
4842         "last error is %d\n", GetLastError() );
4843     ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4844     ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4845
4846     DestroyWindow(hchild);
4847     DestroyWindow(hparent);
4848     flush_sequence();
4849
4850     /* Message sequences for WM_SETICON */
4851     trace("testing WM_SETICON\n");
4852     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4853                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4854                            NULL, NULL, 0);
4855     ShowWindow(hwnd, SW_SHOW);
4856     UpdateWindow(hwnd);
4857     flush_events();
4858     flush_sequence();
4859     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4860     ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4861
4862     ShowWindow(hwnd, SW_HIDE);
4863     flush_events();
4864     flush_sequence();
4865     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4866     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4867     DestroyWindow(hwnd);
4868     flush_sequence();
4869
4870     hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4871                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4872                            NULL, NULL, 0);
4873     ShowWindow(hwnd, SW_SHOW);
4874     UpdateWindow(hwnd);
4875     flush_events();
4876     flush_sequence();
4877     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4878     ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4879
4880     ShowWindow(hwnd, SW_HIDE);
4881     flush_events();
4882     flush_sequence();
4883     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4884     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4885
4886     flush_sequence();
4887     res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4888     if (!res)
4889     {
4890         todo_wine win_skip( "Message 0x3b not supported\n" );
4891         goto done;
4892     }
4893     ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4894     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4895     res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4896     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4897     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4898     res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4899     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4900     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4901
4902     flush_sequence();
4903     res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4904     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4905     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4906     res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4907     ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4908     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4909
4910     res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4911     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4912     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4913
4914     res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4915     ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4916     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4917
4918 done:
4919     DestroyWindow(hwnd);
4920     flush_sequence();
4921 }
4922
4923 static void test_setwindowpos(void)
4924 {
4925     HWND hwnd;
4926     RECT rc;
4927     LRESULT res;
4928     const INT winX = 100;
4929     const INT winY = 100;
4930     const INT sysX = GetSystemMetrics(SM_CXMINTRACK);
4931
4932     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
4933                            0, 0, winX, winY, 0,
4934                            NULL, NULL, 0);
4935
4936     GetWindowRect(hwnd, &rc);
4937     expect(sysX, rc.right);
4938     expect(winY, rc.bottom);
4939
4940     flush_events();
4941     flush_sequence();
4942     res = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, winX, winY, 0);
4943     ok_sequence(WmZOrder, "Z-Order", TRUE);
4944     ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
4945
4946     GetWindowRect(hwnd, &rc);
4947     expect(sysX, rc.right);
4948     expect(winY, rc.bottom);
4949     DestroyWindow(hwnd);
4950 }
4951
4952 static void invisible_parent_tests(void)
4953 {
4954     HWND hparent, hchild;
4955
4956     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4957                               100, 100, 200, 200, 0, 0, 0, NULL);
4958     ok (hparent != 0, "Failed to create parent window\n");
4959     flush_sequence();
4960
4961     /* test showing child with hidden parent */
4962
4963     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4964                              0, 0, 10, 10, hparent, 0, 0, NULL);
4965     ok (hchild != 0, "Failed to create child window\n");
4966     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4967
4968     ShowWindow( hchild, SW_MINIMIZE );
4969     ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4970     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4971     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4972
4973     /* repeat */
4974     flush_events();
4975     flush_sequence();
4976     ShowWindow( hchild, SW_MINIMIZE );
4977     ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4978
4979     DestroyWindow(hchild);
4980     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4981                              0, 0, 10, 10, hparent, 0, 0, NULL);
4982     flush_sequence();
4983
4984     ShowWindow( hchild, SW_MAXIMIZE );
4985     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4986     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4987     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4988
4989     /* repeat */
4990     flush_events();
4991     flush_sequence();
4992     ShowWindow( hchild, SW_MAXIMIZE );
4993     ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4994
4995     DestroyWindow(hchild);
4996     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4997                              0, 0, 10, 10, hparent, 0, 0, NULL);
4998     flush_sequence();
4999
5000     ShowWindow( hchild, SW_RESTORE );
5001     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
5002     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5003     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5004
5005     DestroyWindow(hchild);
5006     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5007                              0, 0, 10, 10, hparent, 0, 0, NULL);
5008     flush_sequence();
5009
5010     ShowWindow( hchild, SW_SHOWMINIMIZED );
5011     ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
5012     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5013     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5014
5015     /* repeat */
5016     flush_events();
5017     flush_sequence();
5018     ShowWindow( hchild, SW_SHOWMINIMIZED );
5019     ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
5020
5021     DestroyWindow(hchild);
5022     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5023                              0, 0, 10, 10, hparent, 0, 0, NULL);
5024     flush_sequence();
5025
5026     /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
5027     ShowWindow( hchild, SW_SHOWMAXIMIZED );
5028     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
5029     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5030     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5031
5032     DestroyWindow(hchild);
5033     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5034                              0, 0, 10, 10, hparent, 0, 0, NULL);
5035     flush_sequence();
5036
5037     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5038     ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5039     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5040     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5041
5042     /* repeat */
5043     flush_events();
5044     flush_sequence();
5045     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5046     ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5047
5048     DestroyWindow(hchild);
5049     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5050                              0, 0, 10, 10, hparent, 0, 0, NULL);
5051     flush_sequence();
5052
5053     /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
5054     ShowWindow( hchild, SW_FORCEMINIMIZE );
5055     ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
5056 todo_wine {
5057     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5058 }
5059     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5060
5061     DestroyWindow(hchild);
5062     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5063                              0, 0, 10, 10, hparent, 0, 0, NULL);
5064     flush_sequence();
5065
5066     ShowWindow( hchild, SW_SHOWNA );
5067     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5068     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5069     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5070
5071     /* repeat */
5072     flush_events();
5073     flush_sequence();
5074     ShowWindow( hchild, SW_SHOWNA );
5075     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5076
5077     DestroyWindow(hchild);
5078     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5079                              0, 0, 10, 10, hparent, 0, 0, NULL);
5080     flush_sequence();
5081
5082     ShowWindow( hchild, SW_SHOW );
5083     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5084     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5085     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5086
5087     /* repeat */
5088     flush_events();
5089     flush_sequence();
5090     ShowWindow( hchild, SW_SHOW );
5091     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5092
5093     ShowWindow( hchild, SW_HIDE );
5094     ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
5095     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5096     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5097
5098     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5099     ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
5100     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5101     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5102
5103     SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5104     ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
5105     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
5106     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5107
5108     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5109     flush_sequence();
5110     DestroyWindow(hchild);
5111     ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
5112
5113     DestroyWindow(hparent);
5114     flush_sequence();
5115 }
5116
5117 /****************** button message test *************************/
5118 #define ID_BUTTON 0x000e
5119
5120 static const struct message WmSetFocusButtonSeq[] =
5121 {
5122     { HCBT_SETFOCUS, hook },
5123     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5124     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5125     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5126     { WM_SETFOCUS, sent|wparam, 0 },
5127     { WM_CTLCOLORBTN, sent|parent },
5128     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5129     { WM_APP, sent|wparam|lparam, 0, 0 },
5130     { 0 }
5131 };
5132 static const struct message WmKillFocusButtonSeq[] =
5133 {
5134     { HCBT_SETFOCUS, hook },
5135     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5136     { WM_KILLFOCUS, sent|wparam, 0 },
5137     { WM_CTLCOLORBTN, sent|parent },
5138     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5139     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5140     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5141     { WM_APP, sent|wparam|lparam, 0, 0 },
5142     { WM_PAINT, sent },
5143     { WM_CTLCOLORBTN, sent|parent },
5144     { 0 }
5145 };
5146 static const struct message WmSetFocusStaticSeq[] =
5147 {
5148     { HCBT_SETFOCUS, hook },
5149     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5150     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5151     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5152     { WM_SETFOCUS, sent|wparam, 0 },
5153     { WM_CTLCOLORSTATIC, sent|parent },
5154     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5155     { WM_COMMAND, sent|wparam|parent|optional, MAKEWPARAM(ID_BUTTON, BN_CLICKED) }, /* radio button */
5156     { WM_APP, sent|wparam|lparam, 0, 0 },
5157     { 0 }
5158 };
5159 static const struct message WmKillFocusStaticSeq[] =
5160 {
5161     { HCBT_SETFOCUS, hook },
5162     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5163     { WM_KILLFOCUS, sent|wparam, 0 },
5164     { WM_CTLCOLORSTATIC, sent|parent },
5165     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5166     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5167     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5168     { WM_APP, sent|wparam|lparam, 0, 0 },
5169     { WM_PAINT, sent },
5170     { WM_CTLCOLORSTATIC, sent|parent },
5171     { 0 }
5172 };
5173 static const struct message WmSetFocusOwnerdrawSeq[] =
5174 {
5175     { HCBT_SETFOCUS, hook },
5176     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5177     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5178     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5179     { WM_SETFOCUS, sent|wparam, 0 },
5180     { WM_CTLCOLORBTN, sent|parent },
5181     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x001040e4 },
5182     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5183     { WM_APP, sent|wparam|lparam, 0, 0 },
5184     { 0 }
5185 };
5186 static const struct message WmKillFocusOwnerdrawSeq[] =
5187 {
5188     { HCBT_SETFOCUS, hook },
5189     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5190     { WM_KILLFOCUS, sent|wparam, 0 },
5191     { WM_CTLCOLORBTN, sent|parent },
5192     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000040e4 },
5193     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5194     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5195     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5196     { WM_APP, sent|wparam|lparam, 0, 0 },
5197     { WM_PAINT, sent },
5198     { WM_CTLCOLORBTN, sent|parent },
5199     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 },
5200     { 0 }
5201 };
5202 static const struct message WmLButtonDownSeq[] =
5203 {
5204     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
5205     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5206     { HCBT_SETFOCUS, hook },
5207     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
5208     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5209     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5210     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
5211     { WM_CTLCOLORBTN, sent|defwinproc },
5212     { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
5213     { WM_CTLCOLORBTN, sent|defwinproc },
5214     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5215     { 0 }
5216 };
5217 static const struct message WmLButtonUpSeq[] =
5218 {
5219     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
5220     { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
5221     { WM_CTLCOLORBTN, sent|defwinproc },
5222     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5223     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5224     { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
5225     { 0 }
5226 };
5227 static const struct message WmSetFontButtonSeq[] =
5228 {
5229     { WM_SETFONT, sent },
5230     { WM_PAINT, sent },
5231     { WM_ERASEBKGND, sent|defwinproc|optional },
5232     { WM_CTLCOLORBTN, sent|defwinproc },
5233     { 0 }
5234 };
5235 static const struct message WmSetStyleButtonSeq[] =
5236 {
5237     { BM_SETSTYLE, sent },
5238     { WM_APP, sent|wparam|lparam, 0, 0 },
5239     { WM_PAINT, sent },
5240     { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5241     { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5242     { WM_CTLCOLORBTN, sent|parent },
5243     { 0 }
5244 };
5245 static const struct message WmSetStyleStaticSeq[] =
5246 {
5247     { BM_SETSTYLE, sent },
5248     { WM_APP, sent|wparam|lparam, 0, 0 },
5249     { WM_PAINT, sent },
5250     { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5251     { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5252     { WM_CTLCOLORSTATIC, sent|parent },
5253     { 0 }
5254 };
5255 static const struct message WmSetStyleUserSeq[] =
5256 {
5257     { BM_SETSTYLE, sent },
5258     { WM_APP, sent|wparam|lparam, 0, 0 },
5259     { WM_PAINT, sent },
5260     { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5261     { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5262     { WM_CTLCOLORBTN, sent|parent },
5263     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_PAINT) },
5264     { 0 }
5265 };
5266 static const struct message WmSetStyleOwnerdrawSeq[] =
5267 {
5268     { BM_SETSTYLE, sent },
5269     { WM_APP, sent|wparam|lparam, 0, 0 },
5270     { WM_PAINT, sent },
5271     { WM_NCPAINT, sent|optional }, /* FIXME: Wine sends it */
5272     { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5273     { WM_CTLCOLORBTN, sent|parent },
5274     { WM_CTLCOLORBTN, sent|parent|optional }, /* Win9x doesn't send it */
5275     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 },
5276     { 0 }
5277 };
5278 static const struct message WmSetStateButtonSeq[] =
5279 {
5280     { BM_SETSTATE, sent },
5281     { WM_CTLCOLORBTN, sent|parent },
5282     { WM_APP, sent|wparam|lparam, 0, 0 },
5283     { 0 }
5284 };
5285 static const struct message WmSetStateStaticSeq[] =
5286 {
5287     { BM_SETSTATE, sent },
5288     { WM_CTLCOLORSTATIC, sent|parent },
5289     { WM_APP, sent|wparam|lparam, 0, 0 },
5290     { 0 }
5291 };
5292 static const struct message WmSetStateUserSeq[] =
5293 {
5294     { BM_SETSTATE, sent },
5295     { WM_CTLCOLORBTN, sent|parent },
5296     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_HILITE) },
5297     { WM_APP, sent|wparam|lparam, 0, 0 },
5298     { 0 }
5299 };
5300 static const struct message WmSetStateOwnerdrawSeq[] =
5301 {
5302     { BM_SETSTATE, sent },
5303     { WM_CTLCOLORBTN, sent|parent },
5304     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000120e4 },
5305     { WM_APP, sent|wparam|lparam, 0, 0 },
5306     { 0 }
5307 };
5308 static const struct message WmClearStateButtonSeq[] =
5309 {
5310     { BM_SETSTATE, sent },
5311     { WM_CTLCOLORBTN, sent|parent },
5312     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_UNHILITE) },
5313     { WM_APP, sent|wparam|lparam, 0, 0 },
5314     { 0 }
5315 };
5316 static const struct message WmClearStateOwnerdrawSeq[] =
5317 {
5318     { BM_SETSTATE, sent },
5319     { WM_CTLCOLORBTN, sent|parent },
5320     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000020e4 },
5321     { WM_APP, sent|wparam|lparam, 0, 0 },
5322     { 0 }
5323 };
5324 static const struct message WmSetCheckIgnoredSeq[] =
5325 {
5326     { BM_SETCHECK, sent },
5327     { WM_APP, sent|wparam|lparam, 0, 0 },
5328     { 0 }
5329 };
5330 static const struct message WmSetCheckStaticSeq[] =
5331 {
5332     { BM_SETCHECK, sent },
5333     { WM_CTLCOLORSTATIC, sent|parent },
5334     { WM_APP, sent|wparam|lparam, 0, 0 },
5335     { 0 }
5336 };
5337
5338 static WNDPROC old_button_proc;
5339
5340 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5341 {
5342     static LONG defwndproc_counter = 0;
5343     LRESULT ret;
5344     struct recvd_message msg;
5345
5346     if (ignore_message( message )) return 0;
5347
5348     switch (message)
5349     {
5350     case WM_SYNCPAINT:
5351         break;
5352     case BM_SETSTATE:
5353         if (GetCapture())
5354             ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
5355         /* fall through */
5356     default:
5357         msg.hwnd = hwnd;
5358         msg.message = message;
5359         msg.flags = sent|wparam|lparam;
5360         if (defwndproc_counter) msg.flags |= defwinproc;
5361         msg.wParam = wParam;
5362         msg.lParam = lParam;
5363         msg.descr = "button";
5364         add_message(&msg);
5365     }
5366
5367     defwndproc_counter++;
5368     ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
5369     defwndproc_counter--;
5370
5371     return ret;
5372 }
5373
5374 static void subclass_button(void)
5375 {
5376     WNDCLASSA cls;
5377
5378     if (!GetClassInfoA(0, "button", &cls)) assert(0);
5379
5380     old_button_proc = cls.lpfnWndProc;
5381
5382     cls.hInstance = GetModuleHandle(0);
5383     cls.lpfnWndProc = button_hook_proc;
5384     cls.lpszClassName = "my_button_class";
5385     UnregisterClass(cls.lpszClassName, cls.hInstance);
5386     if (!RegisterClassA(&cls)) assert(0);
5387 }
5388
5389 static void test_button_messages(void)
5390 {
5391     static const struct
5392     {
5393         DWORD style;
5394         DWORD dlg_code;
5395         const struct message *setfocus;
5396         const struct message *killfocus;
5397         const struct message *setstyle;
5398         const struct message *setstate;
5399         const struct message *clearstate;
5400         const struct message *setcheck;
5401     } button[] = {
5402         { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5403           WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq,
5404           WmSetStateButtonSeq, WmSetStateButtonSeq, WmSetCheckIgnoredSeq },
5405         { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
5406           WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq,
5407           WmSetStateButtonSeq, WmSetStateButtonSeq, WmSetCheckIgnoredSeq },
5408         { BS_CHECKBOX, DLGC_BUTTON,
5409           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5410           WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5411         { BS_AUTOCHECKBOX, DLGC_BUTTON,
5412           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5413           WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5414         { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5415           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5416           WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5417         { BS_3STATE, DLGC_BUTTON,
5418           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5419           WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5420         { BS_AUTO3STATE, DLGC_BUTTON,
5421           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5422           WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5423         { BS_GROUPBOX, DLGC_STATIC,
5424           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5425           WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckIgnoredSeq },
5426         { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5427           WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleUserSeq,
5428           WmSetStateUserSeq, WmClearStateButtonSeq, WmSetCheckIgnoredSeq },
5429         { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5430           WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5431           WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5432         { BS_OWNERDRAW, DLGC_BUTTON,
5433           WmSetFocusOwnerdrawSeq, WmKillFocusOwnerdrawSeq, WmSetStyleOwnerdrawSeq,
5434           WmSetStateOwnerdrawSeq, WmClearStateOwnerdrawSeq, WmSetCheckIgnoredSeq },
5435     };
5436     unsigned int i;
5437     HWND hwnd, parent;
5438     DWORD dlg_code;
5439     HFONT zfont;
5440
5441     /* selection with VK_SPACE should capture button window */
5442     hwnd = CreateWindowExA(0, "button", "test", BS_CHECKBOX | WS_VISIBLE | WS_POPUP,
5443                            0, 0, 50, 14, 0, 0, 0, NULL);
5444     ok(hwnd != 0, "Failed to create button window\n");
5445     ReleaseCapture();
5446     SetFocus(hwnd);
5447     SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
5448     ok(GetCapture() == hwnd, "Should be captured on VK_SPACE WM_KEYDOWN\n");
5449     SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
5450     DestroyWindow(hwnd);
5451
5452     subclass_button();
5453
5454     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5455                              100, 100, 200, 200, 0, 0, 0, NULL);
5456     ok(parent != 0, "Failed to create parent window\n");
5457
5458     for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
5459     {
5460         MSG msg;
5461         DWORD style, state;
5462
5463         trace("button style %08x\n", button[i].style);
5464
5465         hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_CHILD | BS_NOTIFY,
5466                                0, 0, 50, 14, parent, (HMENU)ID_BUTTON, 0, NULL);
5467         ok(hwnd != 0, "Failed to create button window\n");
5468
5469         style = GetWindowLongA(hwnd, GWL_STYLE);
5470         style &= ~(WS_CHILD | BS_NOTIFY);
5471         /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
5472         if (button[i].style == BS_USERBUTTON)
5473             ok(style == BS_PUSHBUTTON, "expected style BS_PUSHBUTTON got %x\n", style);
5474         else
5475             ok(style == button[i].style, "expected style %x got %x\n", button[i].style, style);
5476
5477         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5478         ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5479
5480         ShowWindow(hwnd, SW_SHOW);
5481         UpdateWindow(hwnd);
5482         SetFocus(0);
5483         flush_events();
5484         SetFocus(0);
5485         flush_sequence();
5486
5487         log_all_parent_messages++;
5488
5489         ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
5490         SetFocus(hwnd);
5491         SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5492         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5493         ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
5494
5495         SetFocus(0);
5496         SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5497         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5498         ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
5499
5500         ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
5501
5502         SendMessage(hwnd, BM_SETSTYLE, button[i].style | BS_BOTTOM, TRUE);
5503         SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5504         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5505         ok_sequence(button[i].setstyle, "BM_SETSTYLE on a button", FALSE);
5506
5507         style = GetWindowLongA(hwnd, GWL_STYLE);
5508         style &= ~(WS_VISIBLE | WS_CHILD | BS_NOTIFY);
5509         /* XP doesn't turn a BS_USERBUTTON into BS_PUSHBUTTON here! */
5510         ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5511
5512         state = SendMessage(hwnd, BM_GETSTATE, 0, 0);
5513         ok(state == 0, "expected state 0, got %04x\n", state);
5514
5515         flush_sequence();
5516
5517         SendMessage(hwnd, BM_SETSTATE, TRUE, 0);
5518         SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5519         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5520         ok_sequence(button[i].setstate, "BM_SETSTATE/TRUE on a button", FALSE);
5521
5522         state = SendMessage(hwnd, BM_GETSTATE, 0, 0);
5523         ok(state == 0x0004, "expected state 0x0004, got %04x\n", state);
5524
5525         style = GetWindowLongA(hwnd, GWL_STYLE);
5526         style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5527         ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5528
5529         flush_sequence();
5530
5531         SendMessage(hwnd, BM_SETSTATE, FALSE, 0);
5532         SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5533         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5534         ok_sequence(button[i].clearstate, "BM_SETSTATE/FALSE on a button", FALSE);
5535
5536         state = SendMessage(hwnd, BM_GETSTATE, 0, 0);
5537         ok(state == 0, "expected state 0, got %04x\n", state);
5538
5539         style = GetWindowLongA(hwnd, GWL_STYLE);
5540         style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5541         ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5542
5543         state = SendMessage(hwnd, BM_GETCHECK, 0, 0);
5544         ok(state == BST_UNCHECKED, "expected BST_UNCHECKED, got %04x\n", state);
5545
5546         flush_sequence();
5547
5548         SendMessage(hwnd, BM_SETCHECK, BST_UNCHECKED, 0);
5549         SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5550         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5551         ok_sequence(WmSetCheckIgnoredSeq, "BM_SETCHECK on a button", FALSE);
5552
5553         state = SendMessage(hwnd, BM_GETCHECK, 0, 0);
5554         ok(state == BST_UNCHECKED, "expected BST_UNCHECKED, got %04x\n", state);
5555
5556         style = GetWindowLongA(hwnd, GWL_STYLE);
5557         style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5558         ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5559
5560         flush_sequence();
5561
5562         SendMessage(hwnd, BM_SETCHECK, BST_CHECKED, 0);
5563         SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5564         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5565         ok_sequence(button[i].setcheck, "BM_SETCHECK on a button", FALSE);
5566
5567         state = SendMessage(hwnd, BM_GETCHECK, 0, 0);
5568         if (button[i].style == BS_PUSHBUTTON ||
5569             button[i].style == BS_DEFPUSHBUTTON ||
5570             button[i].style == BS_GROUPBOX ||
5571             button[i].style == BS_USERBUTTON ||
5572             button[i].style == BS_OWNERDRAW)
5573             ok(state == BST_UNCHECKED, "expected check 0, got %04x\n", state);
5574         else
5575             ok(state == BST_CHECKED, "expected check 1, got %04x\n", state);
5576
5577         style = GetWindowLongA(hwnd, GWL_STYLE);
5578         style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5579         if (button[i].style == BS_RADIOBUTTON ||
5580             button[i].style == BS_AUTORADIOBUTTON)
5581             ok(style == (button[i].style | WS_TABSTOP), "expected style %04x | WS_TABSTOP got %04x\n", button[i].style, style);
5582         else
5583             ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5584
5585         log_all_parent_messages--;
5586
5587         DestroyWindow(hwnd);
5588     }
5589
5590     DestroyWindow(parent);
5591
5592     hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
5593                            0, 0, 50, 14, 0, 0, 0, NULL);
5594     ok(hwnd != 0, "Failed to create button window\n");
5595
5596     SetForegroundWindow(hwnd);
5597     flush_events();
5598
5599     SetActiveWindow(hwnd);
5600     SetFocus(0);
5601     flush_sequence();
5602
5603     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
5604     ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
5605
5606     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
5607     ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
5608
5609     flush_sequence();
5610     zfont = GetStockObject(SYSTEM_FONT);
5611     SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
5612     UpdateWindow(hwnd);
5613     ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
5614
5615     DestroyWindow(hwnd);
5616 }
5617
5618 /****************** static message test *************************/
5619 static const struct message WmSetFontStaticSeq[] =
5620 {
5621     { WM_SETFONT, sent },
5622     { WM_PAINT, sent|defwinproc|optional },
5623     { WM_ERASEBKGND, sent|defwinproc|optional },
5624     { WM_CTLCOLORSTATIC, sent|defwinproc|optional },
5625     { 0 }
5626 };
5627
5628 static WNDPROC old_static_proc;
5629
5630 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5631 {
5632     static LONG defwndproc_counter = 0;
5633     LRESULT ret;
5634     struct recvd_message msg;
5635
5636     if (ignore_message( message )) return 0;
5637
5638     msg.hwnd = hwnd;
5639     msg.message = message;
5640     msg.flags = sent|wparam|lparam;
5641     if (defwndproc_counter) msg.flags |= defwinproc;
5642     msg.wParam = wParam;
5643     msg.lParam = lParam;
5644     msg.descr = "static";
5645     add_message(&msg);
5646
5647     defwndproc_counter++;
5648     ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
5649     defwndproc_counter--;
5650
5651     return ret;
5652 }
5653
5654 static void subclass_static(void)
5655 {
5656     WNDCLASSA cls;
5657
5658     if (!GetClassInfoA(0, "static", &cls)) assert(0);
5659
5660     old_static_proc = cls.lpfnWndProc;
5661
5662     cls.hInstance = GetModuleHandle(0);
5663     cls.lpfnWndProc = static_hook_proc;
5664     cls.lpszClassName = "my_static_class";
5665     UnregisterClass(cls.lpszClassName, cls.hInstance);
5666     if (!RegisterClassA(&cls)) assert(0);
5667 }
5668
5669 static void test_static_messages(void)
5670 {
5671     /* FIXME: make as comprehensive as the button message test */
5672     static const struct
5673     {
5674         DWORD style;
5675         DWORD dlg_code;
5676         const struct message *setfont;
5677     } static_ctrl[] = {
5678         { SS_LEFT, DLGC_STATIC,
5679           WmSetFontStaticSeq }
5680     };
5681     unsigned int i;
5682     HWND hwnd;
5683     DWORD dlg_code;
5684
5685     subclass_static();
5686
5687     for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
5688     {
5689         hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
5690                                0, 0, 50, 14, 0, 0, 0, NULL);
5691         ok(hwnd != 0, "Failed to create static window\n");
5692
5693         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5694         ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5695
5696         ShowWindow(hwnd, SW_SHOW);
5697         UpdateWindow(hwnd);
5698         SetFocus(0);
5699         flush_sequence();
5700
5701         trace("static style %08x\n", static_ctrl[i].style);
5702         SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
5703         ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
5704
5705         DestroyWindow(hwnd);
5706     }
5707 }
5708
5709 /****************** ComboBox message test *************************/
5710 #define ID_COMBOBOX 0x000f
5711
5712 static const struct message WmKeyDownComboSeq[] =
5713 {
5714     { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
5715     { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
5716     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
5717     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
5718     { WM_CTLCOLOREDIT, sent|parent },
5719     { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
5720     { 0 }
5721 };
5722
5723 static WNDPROC old_combobox_proc;
5724
5725 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5726 {
5727     static LONG defwndproc_counter = 0;
5728     LRESULT ret;
5729     struct recvd_message msg;
5730
5731     /* do not log painting messages */
5732     if (message != WM_PAINT &&
5733         message != WM_NCPAINT &&
5734         message != WM_SYNCPAINT &&
5735         message != WM_ERASEBKGND &&
5736         message != WM_NCHITTEST &&
5737         message != WM_GETTEXT &&
5738         !ignore_message( message ))
5739     {
5740         msg.hwnd = hwnd;
5741         msg.message = message;
5742         msg.flags = sent|wparam|lparam;
5743         if (defwndproc_counter) msg.flags |= defwinproc;
5744         msg.wParam = wParam;
5745         msg.lParam = lParam;
5746         msg.descr = "combo";
5747         add_message(&msg);
5748     }
5749
5750     defwndproc_counter++;
5751     ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5752     defwndproc_counter--;
5753
5754     return ret;
5755 }
5756
5757 static void subclass_combobox(void)
5758 {
5759     WNDCLASSA cls;
5760
5761     if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5762
5763     old_combobox_proc = cls.lpfnWndProc;
5764
5765     cls.hInstance = GetModuleHandle(0);
5766     cls.lpfnWndProc = combobox_hook_proc;
5767     cls.lpszClassName = "my_combobox_class";
5768     UnregisterClass(cls.lpszClassName, cls.hInstance);
5769     if (!RegisterClassA(&cls)) assert(0);
5770 }
5771
5772 static void test_combobox_messages(void)
5773 {
5774     HWND parent, combo;
5775     LRESULT ret;
5776
5777     subclass_combobox();
5778
5779     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5780                              100, 100, 200, 200, 0, 0, 0, NULL);
5781     ok(parent != 0, "Failed to create parent window\n");
5782     flush_sequence();
5783
5784     combo = CreateWindowEx(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5785                            0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5786     ok(combo != 0, "Failed to create combobox window\n");
5787
5788     UpdateWindow(combo);
5789
5790     ret = SendMessage(combo, WM_GETDLGCODE, 0, 0);
5791     ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5792
5793     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5794     ok(ret == 0, "expected 0, got %ld\n", ret);
5795     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5796     ok(ret == 1, "expected 1, got %ld\n", ret);
5797     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5798     ok(ret == 2, "expected 2, got %ld\n", ret);
5799
5800     SendMessage(combo, CB_SETCURSEL, 0, 0);
5801     SetFocus(combo);
5802     flush_sequence();
5803
5804     log_all_parent_messages++;
5805     SendMessage(combo, WM_KEYDOWN, VK_DOWN, 0);
5806     SendMessage(combo, WM_KEYUP, VK_DOWN, 0);
5807     log_all_parent_messages--;
5808     ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5809
5810     DestroyWindow(combo);
5811     DestroyWindow(parent);
5812 }
5813
5814 /****************** WM_IME_KEYDOWN message test *******************/
5815
5816 static const struct message WmImeKeydownMsgSeq_0[] =
5817 {
5818     { WM_IME_KEYDOWN, wparam, VK_RETURN },
5819     { WM_CHAR, wparam, 'A' },
5820     { 0 }
5821 };
5822
5823 static const struct message WmImeKeydownMsgSeq_1[] =
5824 {
5825     { WM_KEYDOWN, optional|wparam, VK_RETURN },
5826     { WM_CHAR,    optional|wparam, VK_RETURN },
5827     { 0 }
5828 };
5829
5830 static LRESULT WINAPI wmime_keydown_procA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5831 {
5832     struct recvd_message msg;
5833
5834     msg.hwnd = hwnd;
5835     msg.message = message;
5836     msg.flags = wparam|lparam;
5837     msg.wParam = wParam;
5838     msg.lParam = lParam;
5839     msg.descr = "wmime_keydown";
5840     add_message(&msg);
5841
5842     return DefWindowProcA(hwnd, message, wParam, lParam);
5843 }
5844
5845 static void register_wmime_keydown_class(void)
5846 {
5847     WNDCLASSA cls;
5848
5849     ZeroMemory(&cls, sizeof(WNDCLASSA));
5850     cls.lpfnWndProc = wmime_keydown_procA;
5851     cls.hInstance = GetModuleHandleA(0);
5852     cls.lpszClassName = "wmime_keydown_class";
5853     if (!RegisterClassA(&cls)) assert(0);
5854 }
5855
5856 static void test_wmime_keydown_message(void)
5857 {
5858     HWND hwnd;
5859     MSG msg;
5860
5861     trace("Message sequences by WM_IME_KEYDOWN\n");
5862
5863     register_wmime_keydown_class();
5864     hwnd = CreateWindowExA(0, "wmime_keydown_class", NULL, WS_OVERLAPPEDWINDOW,
5865                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5866                            NULL, NULL, 0);
5867     flush_events();
5868     flush_sequence();
5869
5870     SendMessage(hwnd, WM_IME_KEYDOWN, VK_RETURN, 0x1c0001);
5871     SendMessage(hwnd, WM_CHAR, 'A', 1);
5872     ok_sequence(WmImeKeydownMsgSeq_0, "WM_IME_KEYDOWN 0", FALSE);
5873
5874     while ( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
5875     {
5876         TranslateMessage(&msg);
5877         DispatchMessage(&msg);
5878     }
5879     ok_sequence(WmImeKeydownMsgSeq_1, "WM_IME_KEYDOWN 1", FALSE);
5880
5881     DestroyWindow(hwnd);
5882 }
5883
5884 /************* painting message test ********************/
5885
5886 void dump_region(HRGN hrgn)
5887 {
5888     DWORD i, size;
5889     RGNDATA *data = NULL;
5890     RECT *rect;
5891
5892     if (!hrgn)
5893     {
5894         printf( "null region\n" );
5895         return;
5896     }
5897     if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5898     if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5899     GetRegionData( hrgn, size, data );
5900     printf("%d rects:", data->rdh.nCount );
5901     for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5902         printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
5903     printf("\n");
5904     HeapFree( GetProcessHeap(), 0, data );
5905 }
5906
5907 static void check_update_rgn( HWND hwnd, HRGN hrgn )
5908 {
5909     INT ret;
5910     RECT r1, r2;
5911     HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
5912     HRGN update = CreateRectRgn( 0, 0, 0, 0 );
5913
5914     ret = GetUpdateRgn( hwnd, update, FALSE );
5915     ok( ret != ERROR, "GetUpdateRgn failed\n" );
5916     if (ret == NULLREGION)
5917     {
5918         ok( !hrgn, "Update region shouldn't be empty\n" );
5919     }
5920     else
5921     {
5922         if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
5923         {
5924             ok( 0, "Regions are different\n" );
5925             if (winetest_debug > 0)
5926             {
5927                 printf( "Update region: " );
5928                 dump_region( update );
5929                 printf( "Wanted region: " );
5930                 dump_region( hrgn );
5931             }
5932         }
5933     }
5934     GetRgnBox( update, &r1 );
5935     GetUpdateRect( hwnd, &r2, FALSE );
5936     ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
5937         "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
5938         r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
5939
5940     DeleteObject( tmp );
5941     DeleteObject( update );
5942 }
5943
5944 static const struct message WmInvalidateRgn[] = {
5945     { WM_NCPAINT, sent },
5946     { WM_GETTEXT, sent|defwinproc|optional },
5947     { 0 }
5948 };
5949
5950 static const struct message WmGetUpdateRect[] = {
5951     { WM_NCPAINT, sent },
5952     { WM_GETTEXT, sent|defwinproc|optional },
5953     { WM_PAINT, sent },
5954     { 0 }
5955 };
5956
5957 static const struct message WmInvalidateFull[] = {
5958     { WM_NCPAINT, sent|wparam, 1 },
5959     { WM_GETTEXT, sent|defwinproc|optional },
5960     { 0 }
5961 };
5962
5963 static const struct message WmInvalidateErase[] = {
5964     { WM_NCPAINT, sent|wparam, 1 },
5965     { WM_GETTEXT, sent|defwinproc|optional },
5966     { WM_ERASEBKGND, sent },
5967     { 0 }
5968 };
5969
5970 static const struct message WmInvalidatePaint[] = {
5971     { WM_PAINT, sent },
5972     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5973     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5974     { 0 }
5975 };
5976
5977 static const struct message WmInvalidateErasePaint[] = {
5978     { WM_PAINT, sent },
5979     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5980     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5981     { WM_ERASEBKGND, sent|beginpaint|optional },
5982     { 0 }
5983 };
5984
5985 static const struct message WmInvalidateErasePaint2[] = {
5986     { WM_PAINT, sent },
5987     { WM_NCPAINT, sent|beginpaint },
5988     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5989     { WM_ERASEBKGND, sent|beginpaint|optional },
5990     { 0 }
5991 };
5992
5993 static const struct message WmErase[] = {
5994     { WM_ERASEBKGND, sent },
5995     { 0 }
5996 };
5997
5998 static const struct message WmPaint[] = {
5999     { WM_PAINT, sent },
6000     { 0 }
6001 };
6002
6003 static const struct message WmParentOnlyPaint[] = {
6004     { WM_PAINT, sent|parent },
6005     { 0 }
6006 };
6007
6008 static const struct message WmInvalidateParent[] = {
6009     { WM_NCPAINT, sent|parent },
6010     { WM_GETTEXT, sent|defwinproc|parent|optional },
6011     { WM_ERASEBKGND, sent|parent },
6012     { 0 }
6013 };
6014
6015 static const struct message WmInvalidateParentChild[] = {
6016     { WM_NCPAINT, sent|parent },
6017     { WM_GETTEXT, sent|defwinproc|parent|optional },
6018     { WM_ERASEBKGND, sent|parent },
6019     { WM_NCPAINT, sent },
6020     { WM_GETTEXT, sent|defwinproc|optional },
6021     { WM_ERASEBKGND, sent },
6022     { 0 }
6023 };
6024
6025 static const struct message WmInvalidateParentChild2[] = {
6026     { WM_ERASEBKGND, sent|parent },
6027     { WM_NCPAINT, sent },
6028     { WM_GETTEXT, sent|defwinproc|optional },
6029     { WM_ERASEBKGND, sent },
6030     { 0 }
6031 };
6032
6033 static const struct message WmParentPaint[] = {
6034     { WM_PAINT, sent|parent },
6035     { WM_PAINT, sent },
6036     { 0 }
6037 };
6038
6039 static const struct message WmParentPaintNc[] = {
6040     { WM_PAINT, sent|parent },
6041     { WM_PAINT, sent },
6042     { WM_NCPAINT, sent|beginpaint },
6043     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6044     { WM_ERASEBKGND, sent|beginpaint|optional },
6045     { 0 }
6046 };
6047
6048 static const struct message WmChildPaintNc[] = {
6049     { WM_PAINT, sent },
6050     { WM_NCPAINT, sent|beginpaint },
6051     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6052     { WM_ERASEBKGND, sent|beginpaint|optional },
6053     { 0 }
6054 };
6055
6056 static const struct message WmParentErasePaint[] = {
6057     { WM_PAINT, sent|parent },
6058     { WM_NCPAINT, sent|parent|beginpaint },
6059     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
6060     { WM_ERASEBKGND, sent|parent|beginpaint|optional },
6061     { WM_PAINT, sent },
6062     { WM_NCPAINT, sent|beginpaint },
6063     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6064     { WM_ERASEBKGND, sent|beginpaint|optional },
6065     { 0 }
6066 };
6067
6068 static const struct message WmParentOnlyNcPaint[] = {
6069     { WM_PAINT, sent|parent },
6070     { WM_NCPAINT, sent|parent|beginpaint },
6071     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
6072     { 0 }
6073 };
6074
6075 static const struct message WmSetParentStyle[] = {
6076     { WM_STYLECHANGING, sent|parent },
6077     { WM_STYLECHANGED, sent|parent },
6078     { 0 }
6079 };
6080
6081 static void test_paint_messages(void)
6082 {
6083     BOOL ret;
6084     RECT rect;
6085     POINT pt;
6086     MSG msg;
6087     HWND hparent, hchild;
6088     HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
6089     HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
6090     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
6091                                 100, 100, 200, 200, 0, 0, 0, NULL);
6092     ok (hwnd != 0, "Failed to create overlapped window\n");
6093
6094     ShowWindow( hwnd, SW_SHOW );
6095     UpdateWindow( hwnd );
6096     flush_events();
6097     flush_sequence();
6098
6099     check_update_rgn( hwnd, 0 );
6100     SetRectRgn( hrgn, 10, 10, 20, 20 );
6101     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6102     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6103     check_update_rgn( hwnd, hrgn );
6104     SetRectRgn( hrgn2, 20, 20, 30, 30 );
6105     ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
6106     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6107     CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
6108     check_update_rgn( hwnd, hrgn );
6109     /* validate everything */
6110     ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6111     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6112     check_update_rgn( hwnd, 0 );
6113
6114     /* test empty region */
6115     SetRectRgn( hrgn, 10, 10, 10, 15 );
6116     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6117     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6118     check_update_rgn( hwnd, 0 );
6119     /* test empty rect */
6120     SetRect( &rect, 10, 10, 10, 15 );
6121     ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
6122     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6123     check_update_rgn( hwnd, 0 );
6124
6125     /* flush pending messages */
6126     flush_events();
6127     flush_sequence();
6128
6129     GetClientRect( hwnd, &rect );
6130     SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
6131     /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
6132      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
6133      */
6134     trace("testing InvalidateRect(0, NULL, FALSE)\n");
6135     SetRectEmpty( &rect );
6136     ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
6137     check_update_rgn( hwnd, hrgn );
6138     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6139     flush_events();
6140     ok_sequence( WmPaint, "Paint", FALSE );
6141     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6142     check_update_rgn( hwnd, 0 );
6143
6144     /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
6145      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
6146      */
6147     trace("testing ValidateRect(0, NULL)\n");
6148     SetRectEmpty( &rect );
6149     if (ValidateRect(0, &rect))  /* not supported on Win9x */
6150     {
6151         check_update_rgn( hwnd, hrgn );
6152         ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6153         flush_events();
6154         ok_sequence( WmPaint, "Paint", FALSE );
6155         RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6156         check_update_rgn( hwnd, 0 );
6157     }
6158
6159     trace("testing InvalidateRgn(0, NULL, FALSE)\n");
6160     SetLastError(0xdeadbeef);
6161     ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
6162     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
6163        "wrong error code %d\n", GetLastError());
6164     check_update_rgn( hwnd, 0 );
6165     flush_events();
6166     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6167
6168     trace("testing ValidateRgn(0, NULL)\n");
6169     SetLastError(0xdeadbeef);
6170     ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
6171     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
6172        broken( GetLastError() == 0xdeadbeef ) /* win9x */,
6173        "wrong error code %d\n", GetLastError());
6174     check_update_rgn( hwnd, 0 );
6175     flush_events();
6176     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6177
6178     trace("testing UpdateWindow(NULL)\n");
6179     SetLastError(0xdeadbeef);
6180     ok(!UpdateWindow(NULL), "UpdateWindow(NULL) should fail\n");
6181     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
6182        broken( GetLastError() == 0xdeadbeef ) /* win9x */,
6183        "wrong error code %d\n", GetLastError());
6184     check_update_rgn( hwnd, 0 );
6185     flush_events();
6186     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6187
6188     /* now with frame */
6189     SetRectRgn( hrgn, -5, -5, 20, 20 );
6190
6191     /* flush pending messages */
6192     flush_events();
6193     flush_sequence();
6194     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6195     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
6196
6197     SetRectRgn( hrgn, 0, 0, 20, 20 );  /* GetUpdateRgn clips to client area */
6198     check_update_rgn( hwnd, hrgn );
6199
6200     flush_sequence();
6201     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
6202     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
6203
6204     flush_sequence();
6205     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
6206     ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
6207
6208     GetClientRect( hwnd, &rect );
6209     SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
6210     check_update_rgn( hwnd, hrgn );
6211
6212     flush_sequence();
6213     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
6214     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6215
6216     flush_sequence();
6217     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
6218     ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
6219     check_update_rgn( hwnd, 0 );
6220
6221     flush_sequence();
6222     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
6223     ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
6224     check_update_rgn( hwnd, 0 );
6225
6226     flush_sequence();
6227     SetRectRgn( hrgn, 0, 0, 100, 100 );
6228     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6229     SetRectRgn( hrgn, 0, 0, 50, 100 );
6230     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
6231     SetRectRgn( hrgn, 50, 0, 100, 100 );
6232     check_update_rgn( hwnd, hrgn );
6233     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
6234     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );  /* must not generate messages, everything is valid */
6235     check_update_rgn( hwnd, 0 );
6236
6237     flush_sequence();
6238     SetRectRgn( hrgn, 0, 0, 100, 100 );
6239     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
6240     SetRectRgn( hrgn, 0, 0, 100, 50 );
6241     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
6242     ok_sequence( WmErase, "Erase", FALSE );
6243     SetRectRgn( hrgn, 0, 50, 100, 100 );
6244     check_update_rgn( hwnd, hrgn );
6245
6246     flush_sequence();
6247     SetRectRgn( hrgn, 0, 0, 100, 100 );
6248     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
6249     SetRectRgn( hrgn, 0, 0, 50, 50 );
6250     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
6251     ok_sequence( WmPaint, "Paint", FALSE );
6252
6253     flush_sequence();
6254     SetRectRgn( hrgn, -4, -4, -2, -2 );
6255     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6256     SetRectRgn( hrgn, -200, -200, -198, -198 );
6257     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
6258     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
6259
6260     flush_sequence();
6261     SetRectRgn( hrgn, -4, -4, -2, -2 );
6262     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6263     SetRectRgn( hrgn, -4, -4, -3, -3 );
6264     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
6265     SetRectRgn( hrgn, 0, 0, 1, 1 );
6266     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
6267     ok_sequence( WmPaint, "Paint", FALSE );
6268
6269     flush_sequence();
6270     SetRectRgn( hrgn, -4, -4, -1, -1 );
6271     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6272     RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
6273     /* make sure no WM_PAINT was generated */
6274     flush_events();
6275     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
6276
6277     flush_sequence();
6278     SetRectRgn( hrgn, -4, -4, -1, -1 );
6279     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6280     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
6281     {
6282         if (msg.hwnd == hwnd && msg.message == WM_PAINT)
6283         {
6284             /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
6285             INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
6286             ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
6287             ret = GetUpdateRect( hwnd, &rect, FALSE );
6288             ok( ret, "Invalid GetUpdateRect result %d\n", ret );
6289             /* this will send WM_NCPAINT and validate the non client area */
6290             ret = GetUpdateRect( hwnd, &rect, TRUE );
6291             ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
6292         }
6293         DispatchMessage( &msg );
6294     }
6295     ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
6296
6297     DestroyWindow( hwnd );
6298
6299     /* now test with a child window */
6300
6301     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
6302                               100, 100, 200, 200, 0, 0, 0, NULL);
6303     ok (hparent != 0, "Failed to create parent window\n");
6304
6305     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
6306                            10, 10, 100, 100, hparent, 0, 0, NULL);
6307     ok (hchild != 0, "Failed to create child window\n");
6308
6309     ShowWindow( hparent, SW_SHOW );
6310     UpdateWindow( hparent );
6311     UpdateWindow( hchild );
6312     flush_events();
6313     flush_sequence();
6314     log_all_parent_messages++;
6315
6316     SetRect( &rect, 0, 0, 50, 50 );
6317     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6318     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6319     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
6320
6321     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6322     pt.x = pt.y = 0;
6323     MapWindowPoints( hchild, hparent, &pt, 1 );
6324     SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
6325     check_update_rgn( hchild, hrgn );
6326     SetRectRgn( hrgn, 0, 0, 50, 50 );
6327     check_update_rgn( hparent, hrgn );
6328     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6329     ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
6330     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6331     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6332
6333     flush_events();
6334     ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
6335
6336     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6337     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6338     ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
6339     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6340     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6341
6342     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6343     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6344     ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
6345
6346     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6347     flush_sequence();
6348     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6349     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6350     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
6351
6352     /* flush all paint messages */
6353     flush_events();
6354     flush_sequence();
6355
6356     /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
6357     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6358     SetRectRgn( hrgn, 0, 0, 50, 50 );
6359     check_update_rgn( hparent, hrgn );
6360     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6361     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6362     SetRectRgn( hrgn, 0, 0, 50, 50 );
6363     check_update_rgn( hparent, hrgn );
6364
6365     /* flush all paint messages */
6366     flush_events();
6367     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6368     flush_sequence();
6369
6370     /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
6371     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6372     SetRectRgn( hrgn, 0, 0, 50, 50 );
6373     check_update_rgn( hparent, hrgn );
6374     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6375     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6376     SetRectRgn( hrgn2, 10, 10, 50, 50 );
6377     CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
6378     check_update_rgn( hparent, hrgn );
6379     /* flush all paint messages */
6380     flush_events();
6381     flush_sequence();
6382
6383     /* same as above but parent gets completely validated */
6384     SetRect( &rect, 20, 20, 30, 30 );
6385     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6386     SetRectRgn( hrgn, 20, 20, 30, 30 );
6387     check_update_rgn( hparent, hrgn );
6388     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6389     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6390     check_update_rgn( hparent, 0 );  /* no update region */
6391     flush_events();
6392     ok_sequence( WmEmptySeq, "WmEmpty", FALSE );  /* and no paint messages */
6393
6394     /* make sure RDW_VALIDATE on child doesn't have the same effect */
6395     flush_sequence();
6396     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6397     SetRectRgn( hrgn, 20, 20, 30, 30 );
6398     check_update_rgn( hparent, hrgn );
6399     RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
6400     SetRectRgn( hrgn, 20, 20, 30, 30 );
6401     check_update_rgn( hparent, hrgn );
6402
6403     /* same as above but normal WM_PAINT doesn't validate parent */
6404     flush_sequence();
6405     SetRect( &rect, 20, 20, 30, 30 );
6406     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6407     SetRectRgn( hrgn, 20, 20, 30, 30 );
6408     check_update_rgn( hparent, hrgn );
6409     /* no WM_PAINT in child while parent still pending */
6410     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6411     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6412     while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6413     ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
6414
6415     flush_sequence();
6416     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6417     /* no WM_PAINT in child while parent still pending */
6418     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6419     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6420     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
6421     /* now that parent is valid child should get WM_PAINT */
6422     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6423     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6424     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6425     ok_sequence( WmEmptySeq, "No other message", FALSE );
6426
6427     /* same thing with WS_CLIPCHILDREN in parent */
6428     flush_sequence();
6429     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6430     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6431     /* changing style invalidates non client area, but we need to invalidate something else to see it */
6432     RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
6433     ok_sequence( WmEmptySeq, "No message", FALSE );
6434     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
6435     ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
6436
6437     flush_sequence();
6438     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
6439     SetRectRgn( hrgn, 20, 20, 30, 30 );
6440     check_update_rgn( hparent, hrgn );
6441     /* no WM_PAINT in child while parent still pending */
6442     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6443     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6444     /* WM_PAINT in parent first */
6445     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6446     ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
6447
6448     /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
6449     flush_sequence();
6450     SetRect( &rect, 0, 0, 30, 30 );
6451     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
6452     SetRectRgn( hrgn, 0, 0, 30, 30 );
6453     check_update_rgn( hparent, hrgn );
6454     flush_events();
6455     ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
6456
6457     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6458     flush_sequence();
6459     SetRect( &rect, -10, 0, 30, 30 );
6460     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6461     SetRect( &rect, 0, 0, 20, 20 );
6462     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6463     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6464     ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
6465
6466     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6467     flush_sequence();
6468     SetRect( &rect, -10, 0, 30, 30 );
6469     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6470     SetRect( &rect, 0, 0, 100, 100 );
6471     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6472     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6473     ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
6474     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6475     ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
6476
6477     /* test RDW_INTERNALPAINT behavior */
6478
6479     flush_sequence();
6480     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
6481     flush_events();
6482     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6483
6484     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
6485     flush_events();
6486     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6487
6488     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6489     flush_events();
6490     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6491
6492     assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
6493     UpdateWindow( hparent );
6494     flush_events();
6495     flush_sequence();
6496     trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
6497     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6498     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6499                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6500     flush_events();
6501     ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
6502
6503     UpdateWindow( hparent );
6504     flush_events();
6505     flush_sequence();
6506     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
6507     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6508     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6509                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6510     flush_events();
6511     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6512
6513     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6514     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6515     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6516     flush_events();
6517     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6518
6519     assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
6520     UpdateWindow( hparent );
6521     flush_events();
6522     flush_sequence();
6523     trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
6524     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6525     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6526                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6527     flush_events();
6528     ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
6529
6530     UpdateWindow( hparent );
6531     flush_events();
6532     flush_sequence();
6533     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
6534     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6535     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6536                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6537     flush_events();
6538     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6539
6540     ok(GetWindowLong( hparent, GWL_STYLE ) & WS_VISIBLE, "parent should be visible\n");
6541     ok(GetWindowLong( hchild, GWL_STYLE ) & WS_VISIBLE, "child should be visible\n");
6542
6543     UpdateWindow( hparent );
6544     flush_events();
6545     flush_sequence();
6546     trace("testing SetWindowPos(-10000, -10000) on child\n");
6547     SetWindowPos( hchild, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6548     check_update_rgn( hchild, 0 );
6549     flush_events();
6550
6551 #if 0 /* this one doesn't pass under Wine yet */
6552     UpdateWindow( hparent );
6553     flush_events();
6554     flush_sequence();
6555     trace("testing ShowWindow(SW_MINIMIZE) on child\n");
6556     ShowWindow( hchild, SW_MINIMIZE );
6557     check_update_rgn( hchild, 0 );
6558     flush_events();
6559 #endif
6560
6561     UpdateWindow( hparent );
6562     flush_events();
6563     flush_sequence();
6564     trace("testing SetWindowPos(-10000, -10000) on parent\n");
6565     SetWindowPos( hparent, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6566     check_update_rgn( hparent, 0 );
6567     flush_events();
6568
6569     log_all_parent_messages--;
6570     DestroyWindow( hparent );
6571     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6572
6573     /* tests for moving windows off-screen (needs simple WS_POPUP windows) */
6574
6575     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_POPUP | WS_VISIBLE,
6576                               100, 100, 200, 200, 0, 0, 0, NULL);
6577     ok (hparent != 0, "Failed to create parent window\n");
6578
6579     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
6580                            10, 10, 100, 100, hparent, 0, 0, NULL);
6581     ok (hchild != 0, "Failed to create child window\n");
6582
6583     ShowWindow( hparent, SW_SHOW );
6584     UpdateWindow( hparent );
6585     UpdateWindow( hchild );
6586     flush_events();
6587     flush_sequence();
6588
6589     /* moving child outside of parent boundaries changes update region */
6590     SetRect( &rect, 0, 0, 40, 40 );
6591     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6592     SetRectRgn( hrgn, 0, 0, 40, 40 );
6593     check_update_rgn( hchild, hrgn );
6594     MoveWindow( hchild, -10, 10, 100, 100, FALSE );
6595     SetRectRgn( hrgn, 10, 0, 40, 40 );
6596     check_update_rgn( hchild, hrgn );
6597     MoveWindow( hchild, -10, -10, 100, 100, FALSE );
6598     SetRectRgn( hrgn, 10, 10, 40, 40 );
6599     check_update_rgn( hchild, hrgn );
6600
6601     /* moving parent off-screen does too */
6602     SetRect( &rect, 0, 0, 100, 100 );
6603     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
6604     SetRectRgn( hrgn, 0, 0, 100, 100 );
6605     check_update_rgn( hparent, hrgn );
6606     SetRectRgn( hrgn, 10, 10, 40, 40 );
6607     check_update_rgn( hchild, hrgn );
6608     MoveWindow( hparent, -20, -20, 200, 200, FALSE );
6609     SetRectRgn( hrgn, 20, 20, 100, 100 );
6610     check_update_rgn( hparent, hrgn );
6611     SetRectRgn( hrgn, 30, 30, 40, 40 );
6612     check_update_rgn( hchild, hrgn );
6613
6614     /* invalidated region is cropped by the parent rects */
6615     SetRect( &rect, 0, 0, 50, 50 );
6616     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6617     SetRectRgn( hrgn, 30, 30, 50, 50 );
6618     check_update_rgn( hchild, hrgn );
6619
6620     DestroyWindow( hparent );
6621     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6622     flush_sequence();
6623
6624     DeleteObject( hrgn );
6625     DeleteObject( hrgn2 );
6626 }
6627
6628 struct wnd_event
6629 {
6630     HWND hwnd;
6631     HANDLE grand_child;
6632     HANDLE start_event;
6633     HANDLE stop_event;
6634 };
6635
6636 static DWORD WINAPI thread_proc(void *param)
6637 {
6638     MSG msg;
6639     struct wnd_event *wnd_event = param;
6640
6641     wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
6642                                       100, 100, 200, 200, 0, 0, 0, NULL);
6643     ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
6644
6645     SetEvent(wnd_event->start_event);
6646
6647     while (GetMessage(&msg, 0, 0, 0))
6648     {
6649         TranslateMessage(&msg);
6650         DispatchMessage(&msg);
6651     }
6652
6653     ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
6654
6655     return 0;
6656 }
6657
6658 static DWORD CALLBACK create_grand_child_thread( void *param )
6659 {
6660     struct wnd_event *wnd_event = param;
6661     HWND hchild;
6662     MSG msg;
6663
6664     hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
6665                              WS_CHILD | WS_VISIBLE, 0, 0, 10, 10, wnd_event->hwnd, 0, 0, NULL);
6666     ok (hchild != 0, "Failed to create child window\n");
6667     flush_events();
6668     flush_sequence();
6669     SetEvent( wnd_event->start_event );
6670
6671     for (;;)
6672     {
6673         MsgWaitForMultipleObjects(0, NULL, FALSE, 1000, QS_ALLINPUT);
6674         if (!IsWindow( hchild )) break;  /* will be destroyed when parent thread exits */
6675         while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6676     }
6677     return 0;
6678 }
6679
6680 static DWORD CALLBACK create_child_thread( void *param )
6681 {
6682     struct wnd_event *wnd_event = param;
6683     struct wnd_event child_event;
6684     DWORD ret, tid;
6685     MSG msg;
6686
6687     child_event.hwnd = CreateWindowExA(0, "TestWindowClass", "Test child",
6688                              WS_CHILD | WS_VISIBLE, 0, 0, 10, 10, wnd_event->hwnd, 0, 0, NULL);
6689     ok (child_event.hwnd != 0, "Failed to create child window\n");
6690     SetFocus( child_event.hwnd );
6691     flush_events();
6692     flush_sequence();
6693     child_event.start_event = wnd_event->start_event;
6694     wnd_event->grand_child = CreateThread(NULL, 0, create_grand_child_thread, &child_event, 0, &tid);
6695     for (;;)
6696     {
6697         DWORD ret = MsgWaitForMultipleObjects(1, &child_event.start_event, FALSE, 1000, QS_SENDMESSAGE);
6698         if (ret != 1) break;
6699         while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6700     }
6701     ret = WaitForSingleObject( wnd_event->stop_event, 5000 );
6702     ok( !ret, "WaitForSingleObject failed %x\n", ret );
6703     return 0;
6704 }
6705
6706 static void test_interthread_messages(void)
6707 {
6708     HANDLE hThread;
6709     DWORD tid;
6710     WNDPROC proc;
6711     MSG msg;
6712     char buf[256];
6713     int len, expected_len;
6714     struct wnd_event wnd_event;
6715     BOOL ret;
6716
6717     wnd_event.start_event = CreateEventW(NULL, 0, 0, NULL);
6718     if (!wnd_event.start_event)
6719     {
6720         win_skip("skipping interthread message test under win9x\n");
6721         return;
6722     }
6723
6724     hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
6725     ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
6726
6727     ok(WaitForSingleObject(wnd_event.start_event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6728
6729     CloseHandle(wnd_event.start_event);
6730
6731     SetLastError(0xdeadbeef);
6732     ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
6733     ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
6734        "wrong error code %d\n", GetLastError());
6735
6736     proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6737     ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
6738
6739     expected_len = lstrlenA("window caption text");
6740     memset(buf, 0, sizeof(buf));
6741     SetLastError(0xdeadbeef);
6742     len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
6743     ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
6744     ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
6745
6746     msg.hwnd = wnd_event.hwnd;
6747     msg.message = WM_GETTEXT;
6748     msg.wParam = sizeof(buf);
6749     msg.lParam = (LPARAM)buf;
6750     memset(buf, 0, sizeof(buf));
6751     SetLastError(0xdeadbeef);
6752     len = DispatchMessageA(&msg);
6753     ok((!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY) || broken(len), /* nt4 */
6754        "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
6755
6756     /* the following test causes an exception in user.exe under win9x */
6757     msg.hwnd = wnd_event.hwnd;
6758     msg.message = WM_TIMER;
6759     msg.wParam = 0;
6760     msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6761     SetLastError(0xdeadbeef);
6762     len = DispatchMessageA(&msg);
6763     ok(!len && GetLastError() == 0xdeadbeef,
6764        "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
6765
6766     ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
6767     ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
6768
6769     ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6770     CloseHandle(hThread);
6771
6772     ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
6773
6774     wnd_event.hwnd = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6775                               100, 100, 200, 200, 0, 0, 0, NULL);
6776     ok (wnd_event.hwnd != 0, "Failed to create parent window\n");
6777     flush_sequence();
6778     log_all_parent_messages++;
6779     wnd_event.start_event = CreateEventA( NULL, TRUE, FALSE, NULL );
6780     wnd_event.stop_event = CreateEventA( NULL, TRUE, FALSE, NULL );
6781     hThread = CreateThread( NULL, 0, create_child_thread, &wnd_event, 0, &tid );
6782     for (;;)
6783     {
6784         ret = MsgWaitForMultipleObjects(1, &wnd_event.start_event, FALSE, 1000, QS_SENDMESSAGE);
6785         if (ret != 1) break;
6786         while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6787     }
6788     ok( !ret, "MsgWaitForMultipleObjects failed %x\n", ret );
6789     /* now wait for the thread without processing messages; this shouldn't deadlock */
6790     SetEvent( wnd_event.stop_event );
6791     ret = WaitForSingleObject( hThread, 5000 );
6792     ok( !ret, "WaitForSingleObject failed %x\n", ret );
6793     CloseHandle( hThread );
6794
6795     ret = WaitForSingleObject( wnd_event.grand_child, 5000 );
6796     ok( !ret, "WaitForSingleObject failed %x\n", ret );
6797     CloseHandle( wnd_event.grand_child );
6798
6799     CloseHandle( wnd_event.start_event );
6800     CloseHandle( wnd_event.stop_event );
6801     flush_events();
6802     ok_sequence(WmExitThreadSeq, "destroy child on thread exit", FALSE);
6803     log_all_parent_messages--;
6804     DestroyWindow( wnd_event.hwnd );
6805 }
6806
6807
6808 static const struct message WmVkN[] = {
6809     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6810     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6811     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6812     { WM_CHAR, wparam|lparam, 'n', 1 },
6813     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
6814     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6815     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6816     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6817     { 0 }
6818 };
6819 static const struct message WmShiftVkN[] = {
6820     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6821     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6822     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6823     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6824     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6825     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6826     { WM_CHAR, wparam|lparam, 'N', 1 },
6827     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
6828     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6829     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6830     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6831     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6832     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6833     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6834     { 0 }
6835 };
6836 static const struct message WmCtrlVkN[] = {
6837     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6838     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6839     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6840     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6841     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6842     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6843     { WM_CHAR, wparam|lparam, 0x000e, 1 },
6844     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6845     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6846     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6847     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6848     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6849     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6850     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6851     { 0 }
6852 };
6853 static const struct message WmCtrlVkN_2[] = {
6854     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6855     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6856     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6857     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6858     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6859     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6860     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6861     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6862     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6863     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6864     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6865     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6866     { 0 }
6867 };
6868 static const struct message WmAltVkN[] = {
6869     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6870     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6871     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6872     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6873     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6874     { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6875     { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
6876     { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
6877     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
6878     { HCBT_SYSCOMMAND, hook },
6879     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6880     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6881     { 0x00AE, sent|defwinproc|optional }, /* XP */
6882     { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
6883     { WM_INITMENU, sent|defwinproc },
6884     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6885     { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
6886     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
6887     { WM_CAPTURECHANGED, sent|defwinproc },
6888     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
6889     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6890     { WM_EXITMENULOOP, sent|defwinproc },
6891     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
6892     { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
6893     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6894     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6895     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6896     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6897     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6898     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6899     { 0 }
6900 };
6901 static const struct message WmAltVkN_2[] = {
6902     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6903     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6904     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6905     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6906     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6907     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
6908     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6909     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6910     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6911     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6912     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6913     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6914     { 0 }
6915 };
6916 static const struct message WmCtrlAltVkN[] = {
6917     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6918     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6919     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6920     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6921     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6922     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6923     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6924     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6925     { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6926     { WM_CHAR, optional },
6927     { WM_CHAR, sent|optional },
6928     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6929     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6930     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6931     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6932     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6933     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6934     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6935     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6936     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6937     { 0 }
6938 };
6939 static const struct message WmCtrlShiftVkN[] = {
6940     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6941     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6942     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6943     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6944     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6945     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6946     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6947     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6948     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
6949     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6950     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6951     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6952     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6953     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6954     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6955     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6956     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6957     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6958     { 0 }
6959 };
6960 static const struct message WmCtrlAltShiftVkN[] = {
6961     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6962     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6963     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6964     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6965     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6966     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6967     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
6968     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
6969     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
6970     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6971     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6972     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
6973     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6974     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6975     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6976     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
6977     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
6978     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
6979     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6980     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6981     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6982     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6983     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6984     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6985     { 0 }
6986 };
6987 static const struct message WmAltPressRelease[] = {
6988     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6989     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6990     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6991     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6992     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6993     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6994     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
6995     { HCBT_SYSCOMMAND, hook },
6996     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6997     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6998     { WM_INITMENU, sent|defwinproc },
6999     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7000     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
7001     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7002
7003     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
7004
7005     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7006     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
7007     { WM_CAPTURECHANGED, sent|defwinproc },
7008     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
7009     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7010     { WM_EXITMENULOOP, sent|defwinproc },
7011     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
7012     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
7013     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
7014     { 0 }
7015 };
7016 static const struct message WmShiftMouseButton[] = {
7017     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
7018     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
7019     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
7020     { WM_MOUSEMOVE, wparam|optional, 0, 0 },
7021     { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
7022     { WM_LBUTTONDOWN, wparam, MK_LBUTTON|MK_SHIFT, 0 },
7023     { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON|MK_SHIFT, 0 },
7024     { WM_LBUTTONUP, wparam, MK_SHIFT, 0 },
7025     { WM_LBUTTONUP, sent|wparam, MK_SHIFT, 0 },
7026     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
7027     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
7028     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
7029     { 0 }
7030 };
7031 static const struct message WmF1Seq[] = {
7032     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
7033     { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
7034     { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
7035     { WM_KEYF1, wparam|lparam, 0, 0 },
7036     { WM_KEYF1, sent|wparam|lparam, 0, 0 },
7037     { WM_HELP, sent|defwinproc },
7038     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
7039     { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
7040     { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
7041     { 0 }
7042 };
7043 static const struct message WmVkAppsSeq[] = {
7044     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
7045     { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
7046     { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
7047     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
7048     { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
7049     { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
7050     { WM_CONTEXTMENU, lparam, /*hwnd*/0, -1 },
7051     { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, -1 },
7052     { 0 }
7053 };
7054 static const struct message WmVkF10Seq[] = {
7055     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7056     { WM_SYSKEYDOWN, wparam|lparam, VK_F10, 1 },
7057     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_F10, 0x00000001 },
7058     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7059     { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7060     { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7061     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_KEYMENU },
7062     { HCBT_SYSCOMMAND, hook },
7063     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7064     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7065     { WM_INITMENU, sent|defwinproc },
7066     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7067     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
7068     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7069
7070     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0x10000001 }, /* XP */
7071
7072     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7073     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7074     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
7075     { WM_CAPTURECHANGED, sent|defwinproc },
7076     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
7077     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7078     { WM_EXITMENULOOP, sent|defwinproc },
7079     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7080     { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7081     { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7082     { 0 }
7083 };
7084 static const struct message WmShiftF10Seq[] = {
7085     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
7086     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
7087     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x00000001 },
7088     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7089     { WM_SYSKEYDOWN, wparam|lparam, VK_F10, 1 },
7090     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_F10, 0x00000001 },
7091     { WM_CONTEXTMENU, sent|defwinproc|lparam, /*hwnd*/0, -1 },
7092     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7093     { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7094     { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7095     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_KEYMENU },
7096     { HCBT_SYSCOMMAND, hook },
7097     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7098     { WM_INITMENU, sent|defwinproc },
7099     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
7100     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xd0000001 }, /* XP */
7101     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0x10000001 }, /* XP */
7102     { WM_CAPTURECHANGED, sent|defwinproc|wparam|lparam, 0, 0 },
7103     { WM_MENUSELECT, sent|defwinproc|wparam|lparam, 0xffff0000, 0 },
7104     { WM_EXITMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7105     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0xc0000001 }, /* XP */
7106     { WM_KEYUP, wparam|lparam, VK_ESCAPE, 0xc0000001 },
7107     { WM_KEYUP, sent|wparam|lparam, VK_ESCAPE, 0xc0000001 },
7108     { 0 }
7109 };
7110
7111 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
7112 {
7113     MSG msg;
7114
7115     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
7116     {
7117         struct recvd_message log_msg;
7118
7119         /* ignore some unwanted messages */
7120         if (msg.message == WM_MOUSEMOVE ||
7121             msg.message == WM_TIMER ||
7122             ignore_message( msg.message ))
7123             continue;
7124
7125         log_msg.hwnd = msg.hwnd;
7126         log_msg.message = msg.message;
7127         log_msg.flags = wparam|lparam;
7128         log_msg.wParam = msg.wParam;
7129         log_msg.lParam = msg.lParam;
7130         log_msg.descr = "accel";
7131         add_message(&log_msg);
7132
7133         if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
7134         {
7135             TranslateMessage(&msg);
7136             DispatchMessage(&msg);
7137         }
7138     }
7139 }
7140
7141 static void test_accelerators(void)
7142 {
7143     RECT rc;
7144     POINT pt;
7145     SHORT state;
7146     HACCEL hAccel;
7147     HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7148                                 100, 100, 200, 200, 0, 0, 0, NULL);
7149     BOOL ret;
7150
7151     assert(hwnd != 0);
7152     UpdateWindow(hwnd);
7153     flush_events();
7154     flush_sequence();
7155
7156     SetFocus(hwnd);
7157     ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
7158
7159     state = GetKeyState(VK_SHIFT);
7160     ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
7161     state = GetKeyState(VK_CAPITAL);
7162     ok(state == 0, "wrong CapsLock state %04x\n", state);
7163
7164     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
7165     assert(hAccel != 0);
7166
7167     flush_events();
7168     pump_msg_loop(hwnd, 0);
7169     flush_sequence();
7170
7171     trace("testing VK_N press/release\n");
7172     flush_sequence();
7173     keybd_event('N', 0, 0, 0);
7174     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7175     pump_msg_loop(hwnd, hAccel);
7176     if (!sequence_cnt)  /* we didn't get any message */
7177     {
7178         skip( "queuing key events not supported\n" );
7179         goto done;
7180     }
7181     ok_sequence(WmVkN, "VK_N press/release", FALSE);
7182
7183     trace("testing Shift+VK_N press/release\n");
7184     flush_sequence();
7185     keybd_event(VK_SHIFT, 0, 0, 0);
7186     keybd_event('N', 0, 0, 0);
7187     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7188     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7189     pump_msg_loop(hwnd, hAccel);
7190     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
7191
7192     trace("testing Ctrl+VK_N press/release\n");
7193     flush_sequence();
7194     keybd_event(VK_CONTROL, 0, 0, 0);
7195     keybd_event('N', 0, 0, 0);
7196     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7197     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7198     pump_msg_loop(hwnd, hAccel);
7199     ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
7200
7201     trace("testing Alt+VK_N press/release\n");
7202     flush_sequence();
7203     keybd_event(VK_MENU, 0, 0, 0);
7204     keybd_event('N', 0, 0, 0);
7205     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7206     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7207     pump_msg_loop(hwnd, hAccel);
7208     ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
7209
7210     trace("testing Ctrl+Alt+VK_N press/release 1\n");
7211     flush_sequence();
7212     keybd_event(VK_CONTROL, 0, 0, 0);
7213     keybd_event(VK_MENU, 0, 0, 0);
7214     keybd_event('N', 0, 0, 0);
7215     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7216     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7217     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7218     pump_msg_loop(hwnd, hAccel);
7219     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
7220
7221     ret = DestroyAcceleratorTable(hAccel);
7222     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7223
7224     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
7225     assert(hAccel != 0);
7226
7227     trace("testing VK_N press/release\n");
7228     flush_sequence();
7229     keybd_event('N', 0, 0, 0);
7230     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7231     pump_msg_loop(hwnd, hAccel);
7232     ok_sequence(WmVkN, "VK_N press/release", FALSE);
7233
7234     trace("testing Shift+VK_N press/release\n");
7235     flush_sequence();
7236     keybd_event(VK_SHIFT, 0, 0, 0);
7237     keybd_event('N', 0, 0, 0);
7238     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7239     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7240     pump_msg_loop(hwnd, hAccel);
7241     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
7242
7243     trace("testing Ctrl+VK_N press/release 2\n");
7244     flush_sequence();
7245     keybd_event(VK_CONTROL, 0, 0, 0);
7246     keybd_event('N', 0, 0, 0);
7247     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7248     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7249     pump_msg_loop(hwnd, hAccel);
7250     ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
7251
7252     trace("testing Alt+VK_N press/release 2\n");
7253     flush_sequence();
7254     keybd_event(VK_MENU, 0, 0, 0);
7255     keybd_event('N', 0, 0, 0);
7256     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7257     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7258     pump_msg_loop(hwnd, hAccel);
7259     ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
7260
7261     trace("testing Ctrl+Alt+VK_N press/release 2\n");
7262     flush_sequence();
7263     keybd_event(VK_CONTROL, 0, 0, 0);
7264     keybd_event(VK_MENU, 0, 0, 0);
7265     keybd_event('N', 0, 0, 0);
7266     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7267     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7268     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7269     pump_msg_loop(hwnd, hAccel);
7270     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
7271
7272     trace("testing Ctrl+Shift+VK_N press/release\n");
7273     flush_sequence();
7274     keybd_event(VK_CONTROL, 0, 0, 0);
7275     keybd_event(VK_SHIFT, 0, 0, 0);
7276     keybd_event('N', 0, 0, 0);
7277     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7278     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7279     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7280     pump_msg_loop(hwnd, hAccel);
7281     ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
7282
7283     trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
7284     flush_sequence();
7285     keybd_event(VK_CONTROL, 0, 0, 0);
7286     keybd_event(VK_MENU, 0, 0, 0);
7287     keybd_event(VK_SHIFT, 0, 0, 0);
7288     keybd_event('N', 0, 0, 0);
7289     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7290     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7291     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7292     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7293     pump_msg_loop(hwnd, hAccel);
7294     ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
7295
7296     ret = DestroyAcceleratorTable(hAccel);
7297     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7298     hAccel = 0;
7299
7300     trace("testing Alt press/release\n");
7301     flush_sequence();
7302     keybd_event(VK_MENU, 0, 0, 0);
7303     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7304     keybd_event(VK_MENU, 0, 0, 0);
7305     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7306     pump_msg_loop(hwnd, 0);
7307     /* this test doesn't pass in Wine for managed windows */
7308     ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
7309
7310     trace("testing VK_F1 press/release\n");
7311     keybd_event(VK_F1, 0, 0, 0);
7312     keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
7313     pump_msg_loop(hwnd, 0);
7314     ok_sequence(WmF1Seq, "F1 press/release", FALSE);
7315
7316     trace("testing VK_APPS press/release\n");
7317     keybd_event(VK_APPS, 0, 0, 0);
7318     keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
7319     pump_msg_loop(hwnd, 0);
7320     ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
7321
7322     trace("testing VK_F10 press/release\n");
7323     keybd_event(VK_F10, 0, 0, 0);
7324     keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7325     keybd_event(VK_F10, 0, 0, 0);
7326     keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7327     pump_msg_loop(hwnd, 0);
7328     ok_sequence(WmVkF10Seq, "VK_F10 press/release", TRUE);
7329
7330     trace("testing SHIFT+F10 press/release\n");
7331     keybd_event(VK_SHIFT, 0, 0, 0);
7332     keybd_event(VK_F10, 0, 0, 0);
7333     keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7334     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7335     keybd_event(VK_ESCAPE, 0, 0, 0);
7336     keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0);
7337     pump_msg_loop(hwnd, 0);
7338     ok_sequence(WmShiftF10Seq, "SHIFT+F10 press/release", TRUE);
7339
7340     trace("testing Shift+MouseButton press/release\n");
7341     /* first, move mouse pointer inside of the window client area */
7342     GetClientRect(hwnd, &rc);
7343     MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
7344     rc.left += (rc.right - rc.left)/2;
7345     rc.top += (rc.bottom - rc.top)/2;
7346     SetCursorPos(rc.left, rc.top);
7347     SetActiveWindow(hwnd);
7348
7349     flush_events();
7350     flush_sequence();
7351     GetCursorPos(&pt);
7352     if (pt.x == rc.left && pt.y == rc.top)
7353     {
7354         int i;
7355         keybd_event(VK_SHIFT, 0, 0, 0);
7356         mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
7357         mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7358         keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7359         pump_msg_loop(hwnd, 0);
7360         for (i = 0; i < sequence_cnt; i++) if (sequence[i].message == WM_LBUTTONDOWN) break;
7361         if (i < sequence_cnt)
7362             ok_sequence(WmShiftMouseButton, "Shift+MouseButton press/release", FALSE);
7363         else
7364             skip( "Shift+MouseButton event didn't get to the window\n" );
7365     }
7366
7367 done:
7368     if (hAccel) DestroyAcceleratorTable(hAccel);
7369     DestroyWindow(hwnd);
7370 }
7371
7372 /************* window procedures ********************/
7373
7374 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message, 
7375                              WPARAM wParam, LPARAM lParam)
7376 {
7377     static LONG defwndproc_counter = 0;
7378     static LONG beginpaint_counter = 0;
7379     LRESULT ret;
7380     struct recvd_message msg;
7381
7382     if (ignore_message( message )) return 0;
7383
7384     switch (message)
7385     {
7386         case WM_ENABLE:
7387         {
7388             LONG style = GetWindowLongA(hwnd, GWL_STYLE);
7389             ok((BOOL)wParam == !(style & WS_DISABLED),
7390                 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
7391             break;
7392         }
7393
7394         case WM_CAPTURECHANGED:
7395             if (test_DestroyWindow_flag)
7396             {
7397                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7398                 if (style & WS_CHILD)
7399                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7400                 else if (style & WS_POPUP)
7401                     lParam = WND_POPUP_ID;
7402                 else
7403                     lParam = WND_PARENT_ID;
7404             }
7405             break;
7406
7407         case WM_NCDESTROY:
7408         {
7409             HWND capture;
7410
7411             ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
7412             capture = GetCapture();
7413             if (capture)
7414             {
7415                 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
7416                 trace("current capture %p, releasing...\n", capture);
7417                 ReleaseCapture();
7418             }
7419         }
7420         /* fall through */
7421         case WM_DESTROY:
7422             if (pGetAncestor)
7423                 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
7424             if (test_DestroyWindow_flag)
7425             {
7426                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7427                 if (style & WS_CHILD)
7428                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7429                 else if (style & WS_POPUP)
7430                     lParam = WND_POPUP_ID;
7431                 else
7432                     lParam = WND_PARENT_ID;
7433             }
7434             break;
7435
7436         /* test_accelerators() depends on this */
7437         case WM_NCHITTEST:
7438             return HTCLIENT;
7439
7440         /* ignore */
7441         case WM_MOUSEMOVE:
7442         case WM_MOUSEACTIVATE:
7443         case WM_NCMOUSEMOVE:
7444         case WM_SETCURSOR:
7445         case WM_IME_SELECT:
7446             return 0;
7447     }
7448
7449     msg.hwnd = hwnd;
7450     msg.message = message;
7451     msg.flags = sent|wparam|lparam;
7452     if (defwndproc_counter) msg.flags |= defwinproc;
7453     if (beginpaint_counter) msg.flags |= beginpaint;
7454     msg.wParam = wParam;
7455     msg.lParam = lParam;
7456     msg.descr = "MsgCheckProc";
7457     add_message(&msg);
7458
7459     if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
7460     {
7461         HWND parent = GetParent(hwnd);
7462         RECT rc;
7463         MINMAXINFO *minmax = (MINMAXINFO *)lParam;
7464
7465         GetClientRect(parent, &rc);
7466         trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
7467         trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
7468               minmax->ptReserved.x, minmax->ptReserved.y,
7469               minmax->ptMaxSize.x, minmax->ptMaxSize.y,
7470               minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
7471               minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
7472               minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
7473
7474         ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
7475            minmax->ptMaxSize.x, rc.right);
7476         ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
7477            minmax->ptMaxSize.y, rc.bottom);
7478     }
7479
7480     if (message == WM_PAINT)
7481     {
7482         PAINTSTRUCT ps;
7483         beginpaint_counter++;
7484         BeginPaint( hwnd, &ps );
7485         beginpaint_counter--;
7486         EndPaint( hwnd, &ps );
7487         return 0;
7488     }
7489
7490     defwndproc_counter++;
7491     ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam) 
7492                   : DefWindowProcA(hwnd, message, wParam, lParam);
7493     defwndproc_counter--;
7494
7495     return ret;
7496 }
7497
7498 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7499 {
7500     return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
7501 }
7502
7503 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7504 {
7505     return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
7506 }
7507
7508 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7509 {
7510     static LONG defwndproc_counter = 0;
7511     LRESULT ret;
7512     struct recvd_message msg;
7513
7514     if (ignore_message( message )) return 0;
7515
7516     switch (message)
7517     {
7518     case WM_QUERYENDSESSION:
7519     case WM_ENDSESSION:
7520         lParam &= ~0x01;  /* Vista adds a 0x01 flag */
7521         break;
7522     }
7523
7524     msg.hwnd = hwnd;
7525     msg.message = message;
7526     msg.flags = sent|wparam|lparam;
7527     if (defwndproc_counter) msg.flags |= defwinproc;
7528     msg.wParam = wParam;
7529     msg.lParam = lParam;
7530     msg.descr = "popup";
7531     add_message(&msg);
7532
7533     if (message == WM_CREATE)
7534     {
7535         DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
7536         SetWindowLongA(hwnd, GWL_STYLE, style);
7537     }
7538
7539     defwndproc_counter++;
7540     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7541     defwndproc_counter--;
7542
7543     return ret;
7544 }
7545
7546 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7547 {
7548     static LONG defwndproc_counter = 0;
7549     static LONG beginpaint_counter = 0;
7550     LRESULT ret;
7551     struct recvd_message msg;
7552
7553     if (ignore_message( message )) return 0;
7554
7555     if (log_all_parent_messages ||
7556         message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
7557         message == WM_SETFOCUS || message == WM_KILLFOCUS ||
7558         message == WM_ENABLE || message == WM_ENTERIDLE ||
7559         message == WM_DRAWITEM || message == WM_COMMAND ||
7560         message == WM_IME_SETCONTEXT)
7561     {
7562         switch (message)
7563         {
7564             /* ignore */
7565             case WM_NCHITTEST:
7566                 return HTCLIENT;
7567             case WM_SETCURSOR:
7568             case WM_MOUSEMOVE:
7569             case WM_NCMOUSEMOVE:
7570                 return 0;
7571
7572             case WM_ERASEBKGND:
7573             {
7574                 RECT rc;
7575                 INT ret = GetClipBox((HDC)wParam, &rc);
7576
7577                 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
7578                        ret, rc.left, rc.top, rc.right, rc.bottom);
7579                 break;
7580             }
7581         }
7582
7583         msg.hwnd = hwnd;
7584         msg.message = message;
7585         msg.flags = sent|parent|wparam|lparam;
7586         if (defwndproc_counter) msg.flags |= defwinproc;
7587         if (beginpaint_counter) msg.flags |= beginpaint;
7588         msg.wParam = wParam;
7589         msg.lParam = lParam;
7590         msg.descr = "parent";
7591         add_message(&msg);
7592     }
7593
7594     if (message == WM_PAINT)
7595     {
7596         PAINTSTRUCT ps;
7597         beginpaint_counter++;
7598         BeginPaint( hwnd, &ps );
7599         beginpaint_counter--;
7600         EndPaint( hwnd, &ps );
7601         return 0;
7602     }
7603
7604     defwndproc_counter++;
7605     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7606     defwndproc_counter--;
7607
7608     return ret;
7609 }
7610
7611 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7612 {
7613     static LONG defwndproc_counter = 0;
7614     LRESULT ret;
7615     struct recvd_message msg;
7616
7617     if (ignore_message( message )) return 0;
7618
7619     if (test_def_id)
7620     {
7621         DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
7622         ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
7623         if (after_end_dialog)
7624             ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
7625         else
7626             ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
7627     }
7628
7629     msg.hwnd = hwnd;
7630     msg.message = message;
7631     msg.flags = sent|wparam|lparam;
7632     if (defwndproc_counter) msg.flags |= defwinproc;
7633     msg.wParam = wParam;
7634     msg.lParam = lParam;
7635     msg.descr = "dialog";
7636     add_message(&msg);
7637
7638     defwndproc_counter++;
7639     ret = DefDlgProcA(hwnd, message, wParam, lParam);
7640     defwndproc_counter--;
7641
7642     return ret;
7643 }
7644
7645 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7646 {
7647     static LONG defwndproc_counter = 0;
7648     LRESULT ret;
7649     struct recvd_message msg;
7650
7651     /* log only specific messages we are interested in */
7652     switch (message)
7653     {
7654 #if 0 /* probably log these as well */
7655     case WM_ACTIVATE:
7656     case WM_SETFOCUS:
7657     case WM_KILLFOCUS:
7658 #endif
7659     case WM_SHOWWINDOW:
7660     case WM_SIZE:
7661     case WM_MOVE:
7662     case WM_GETMINMAXINFO:
7663     case WM_WINDOWPOSCHANGING:
7664     case WM_WINDOWPOSCHANGED:
7665         break;
7666
7667     default: /* ignore */
7668         /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
7669         return DefWindowProcA(hwnd, message, wParam, lParam);
7670     }
7671
7672     msg.hwnd = hwnd;
7673     msg.message = message;
7674     msg.flags = sent|wparam|lparam;
7675     if (defwndproc_counter) msg.flags |= defwinproc;
7676     msg.wParam = wParam;
7677     msg.lParam = lParam;
7678     msg.descr = "show";
7679     add_message(&msg);
7680
7681     defwndproc_counter++;
7682     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7683     defwndproc_counter--;
7684
7685     return ret;
7686 }
7687
7688 static LRESULT WINAPI PaintLoopProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
7689 {
7690     switch (msg)
7691     {
7692         case WM_CREATE: return 0;
7693         case WM_PAINT:
7694         {
7695             MSG msg2;
7696             static int i = 0;
7697
7698             if (i < 256)
7699             {
7700                 i++;
7701                 if (PeekMessageA(&msg2, 0, 0, 0, 1))
7702                 {
7703                     TranslateMessage(&msg2);
7704                     DispatchMessage(&msg2);
7705                 }
7706                 i--;
7707             }
7708             else ok(broken(1), "infinite loop\n");
7709             if ( i == 0)
7710                 paint_loop_done = 1;
7711             return DefWindowProcA(hWnd,msg,wParam,lParam);
7712         }
7713     }
7714     return DefWindowProcA(hWnd,msg,wParam,lParam);
7715 }
7716
7717 static LRESULT WINAPI HotkeyMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7718 {
7719     static LONG defwndproc_counter = 0;
7720     LRESULT ret;
7721     struct recvd_message msg;
7722     DWORD queue_status;
7723
7724     if (ignore_message( message )) return 0;
7725
7726     if ((message >= WM_KEYFIRST && message <= WM_KEYLAST) ||
7727         message == WM_HOTKEY || message >= WM_APP)
7728     {
7729         msg.hwnd = hwnd;
7730         msg.message = message;
7731         msg.flags = sent|wparam|lparam;
7732         if (defwndproc_counter) msg.flags |= defwinproc;
7733         msg.wParam = wParam;
7734         msg.lParam = lParam;
7735         msg.descr = "HotkeyMsgCheckProcA";
7736         add_message(&msg);
7737     }
7738
7739     defwndproc_counter++;
7740     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7741     defwndproc_counter--;
7742
7743     if (message == WM_APP)
7744     {
7745         queue_status = GetQueueStatus(QS_HOTKEY);
7746         ok((queue_status & (QS_HOTKEY << 16)) == QS_HOTKEY << 16, "expected QS_HOTKEY << 16 set, got %x\n", queue_status);
7747         queue_status = GetQueueStatus(QS_POSTMESSAGE);
7748         ok((queue_status & (QS_POSTMESSAGE << 16)) == QS_POSTMESSAGE << 16, "expected QS_POSTMESSAGE << 16 set, got %x\n", queue_status);
7749         PostMessageA(hwnd, WM_APP+1, 0, 0);
7750     }
7751     else if (message == WM_APP+1)
7752     {
7753         queue_status = GetQueueStatus(QS_HOTKEY);
7754         ok((queue_status & (QS_HOTKEY << 16)) == 0, "expected QS_HOTKEY << 16 cleared, got %x\n", queue_status);
7755     }
7756
7757     return ret;
7758 }
7759
7760 static BOOL RegisterWindowClasses(void)
7761 {
7762     WNDCLASSA cls;
7763     WNDCLASSW clsW;
7764
7765     cls.style = 0;
7766     cls.lpfnWndProc = MsgCheckProcA;
7767     cls.cbClsExtra = 0;
7768     cls.cbWndExtra = 0;
7769     cls.hInstance = GetModuleHandleA(0);
7770     cls.hIcon = 0;
7771     cls.hCursor = LoadCursorA(0, IDC_ARROW);
7772     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7773     cls.lpszMenuName = NULL;
7774     cls.lpszClassName = "TestWindowClass";
7775     if(!RegisterClassA(&cls)) return FALSE;
7776
7777     cls.lpfnWndProc = HotkeyMsgCheckProcA;
7778     cls.lpszClassName = "HotkeyWindowClass";
7779     if(!RegisterClassA(&cls)) return FALSE;
7780
7781     cls.lpfnWndProc = ShowWindowProcA;
7782     cls.lpszClassName = "ShowWindowClass";
7783     if(!RegisterClassA(&cls)) return FALSE;
7784
7785     cls.lpfnWndProc = PopupMsgCheckProcA;
7786     cls.lpszClassName = "TestPopupClass";
7787     if(!RegisterClassA(&cls)) return FALSE;
7788
7789     cls.lpfnWndProc = ParentMsgCheckProcA;
7790     cls.lpszClassName = "TestParentClass";
7791     if(!RegisterClassA(&cls)) return FALSE;
7792
7793     cls.lpfnWndProc = DefWindowProcA;
7794     cls.lpszClassName = "SimpleWindowClass";
7795     if(!RegisterClassA(&cls)) return FALSE;
7796
7797     cls.lpfnWndProc = PaintLoopProcA;
7798     cls.lpszClassName = "PaintLoopWindowClass";
7799     if(!RegisterClassA(&cls)) return FALSE;
7800
7801     cls.style = CS_NOCLOSE;
7802     cls.lpszClassName = "NoCloseWindowClass";
7803     if(!RegisterClassA(&cls)) return FALSE;
7804
7805     ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
7806     cls.style = 0;
7807     cls.hInstance = GetModuleHandleA(0);
7808     cls.hbrBackground = 0;
7809     cls.lpfnWndProc = TestDlgProcA;
7810     cls.lpszClassName = "TestDialogClass";
7811     if(!RegisterClassA(&cls)) return FALSE;
7812
7813     clsW.style = 0;
7814     clsW.lpfnWndProc = MsgCheckProcW;
7815     clsW.cbClsExtra = 0;
7816     clsW.cbWndExtra = 0;
7817     clsW.hInstance = GetModuleHandleW(0);
7818     clsW.hIcon = 0;
7819     clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
7820     clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
7821     clsW.lpszMenuName = NULL;
7822     clsW.lpszClassName = testWindowClassW;
7823     RegisterClassW(&clsW);  /* ignore error, this fails on Win9x */
7824
7825     return TRUE;
7826 }
7827
7828 static BOOL is_our_logged_class(HWND hwnd)
7829 {
7830     char buf[256];
7831
7832     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7833     {
7834         if (!lstrcmpiA(buf, "TestWindowClass") ||
7835             !lstrcmpiA(buf, "ShowWindowClass") ||
7836             !lstrcmpiA(buf, "TestParentClass") ||
7837             !lstrcmpiA(buf, "TestPopupClass") ||
7838             !lstrcmpiA(buf, "SimpleWindowClass") ||
7839             !lstrcmpiA(buf, "TestDialogClass") ||
7840             !lstrcmpiA(buf, "MDI_frame_class") ||
7841             !lstrcmpiA(buf, "MDI_client_class") ||
7842             !lstrcmpiA(buf, "MDI_child_class") ||
7843             !lstrcmpiA(buf, "my_button_class") ||
7844             !lstrcmpiA(buf, "my_edit_class") ||
7845             !lstrcmpiA(buf, "static") ||
7846             !lstrcmpiA(buf, "ListBox") ||
7847             !lstrcmpiA(buf, "ComboBox") ||
7848             !lstrcmpiA(buf, "MyDialogClass") ||
7849             !lstrcmpiA(buf, "#32770") ||
7850             !lstrcmpiA(buf, "#32768"))
7851         return TRUE;
7852     }
7853     return FALSE;
7854 }
7855
7856 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7857
7858     HWND hwnd;
7859
7860     ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7861
7862     if (nCode == HCBT_CLICKSKIPPED)
7863     {
7864         /* ignore this event, XP sends it a lot when switching focus between windows */
7865         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7866     }
7867
7868     if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
7869     {
7870         struct recvd_message msg;
7871
7872         msg.hwnd = 0;
7873         msg.message = nCode;
7874         msg.flags = hook|wparam|lparam;
7875         msg.wParam = wParam;
7876         msg.lParam = lParam;
7877         msg.descr = "CBT";
7878         add_message(&msg);
7879
7880         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7881     }
7882
7883     if (nCode == HCBT_DESTROYWND)
7884     {
7885         if (test_DestroyWindow_flag)
7886         {
7887             DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
7888             if (style & WS_CHILD)
7889                 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
7890             else if (style & WS_POPUP)
7891                 lParam = WND_POPUP_ID;
7892             else
7893                 lParam = WND_PARENT_ID;
7894         }
7895     }
7896
7897     /* Log also SetFocus(0) calls */
7898     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7899
7900     if (is_our_logged_class(hwnd))
7901     {
7902         struct recvd_message msg;
7903
7904         msg.hwnd = hwnd;
7905         msg.message = nCode;
7906         msg.flags = hook|wparam|lparam;
7907         msg.wParam = wParam;
7908         msg.lParam = lParam;
7909         msg.descr = "CBT";
7910         add_message(&msg);
7911     }
7912     return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7913 }
7914
7915 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
7916                                     DWORD event,
7917                                     HWND hwnd,
7918                                     LONG object_id,
7919                                     LONG child_id,
7920                                     DWORD thread_id,
7921                                     DWORD event_time)
7922 {
7923     ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7924
7925     /* ignore mouse cursor events */
7926     if (object_id == OBJID_CURSOR) return;
7927
7928     if (!hwnd || is_our_logged_class(hwnd))
7929     {
7930         struct recvd_message msg;
7931
7932         msg.hwnd = hwnd;
7933         msg.message = event;
7934         msg.flags = winevent_hook|wparam|lparam;
7935         msg.wParam = object_id;
7936         msg.lParam = child_id;
7937         msg.descr = "WEH";
7938         add_message(&msg);
7939     }
7940 }
7941
7942 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
7943 static const WCHAR wszAnsi[] = {'U',0};
7944
7945 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
7946 {
7947     switch (uMsg)
7948     {
7949     case CB_FINDSTRINGEXACT:
7950         trace("String: %p\n", (LPCWSTR)lParam);
7951         if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
7952             return 1;
7953         if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
7954             return 0;
7955         return -1;
7956     }
7957     return DefWindowProcW(hwnd, uMsg, wParam, lParam);
7958 }
7959
7960 static const struct message WmGetTextLengthAfromW[] = {
7961     { WM_GETTEXTLENGTH, sent },
7962     { WM_GETTEXT, sent|optional },
7963     { 0 }
7964 };
7965
7966 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
7967
7968 /* dummy window proc for WM_GETTEXTLENGTH test */
7969 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
7970 {
7971     switch(msg)
7972     {
7973     case WM_GETTEXTLENGTH:
7974         return lstrlenW(dummy_window_text) + 37;  /* some random length */
7975     case WM_GETTEXT:
7976         lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
7977         return lstrlenW( (LPWSTR)lp );
7978     default:
7979         return DefWindowProcW( hwnd, msg, wp, lp );
7980     }
7981 }
7982
7983 static void test_message_conversion(void)
7984 {
7985     static const WCHAR wszMsgConversionClass[] =
7986         {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
7987     WNDCLASSW cls;
7988     LRESULT lRes;
7989     HWND hwnd;
7990     WNDPROC wndproc, newproc;
7991     BOOL ret;
7992
7993     cls.style = 0;
7994     cls.lpfnWndProc = MsgConversionProcW;
7995     cls.cbClsExtra = 0;
7996     cls.cbWndExtra = 0;
7997     cls.hInstance = GetModuleHandleW(NULL);
7998     cls.hIcon = NULL;
7999     cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
8000     cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
8001     cls.lpszMenuName = NULL;
8002     cls.lpszClassName = wszMsgConversionClass;
8003     /* this call will fail on Win9x, but that doesn't matter as this test is
8004      * meaningless on those platforms */
8005     if(!RegisterClassW(&cls)) return;
8006
8007     hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
8008                            100, 100, 200, 200, 0, 0, 0, NULL);
8009     ok(hwnd != NULL, "Window creation failed\n");
8010
8011     /* {W, A} -> A */
8012
8013     wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
8014     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8015     ok(lRes == 0, "String should have been converted\n");
8016     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8017     ok(lRes == 1, "String shouldn't have been converted\n");
8018
8019     /* {W, A} -> W */
8020
8021     wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
8022     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8023     ok(lRes == 1, "String shouldn't have been converted\n");
8024     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8025     ok(lRes == 1, "String shouldn't have been converted\n");
8026
8027     /* Synchronous messages */
8028
8029     lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8030     ok(lRes == 0, "String should have been converted\n");
8031     lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8032     ok(lRes == 1, "String shouldn't have been converted\n");
8033
8034     /* Asynchronous messages */
8035
8036     SetLastError(0);
8037     lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8038     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8039         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8040     SetLastError(0);
8041     lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8042     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8043         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8044     SetLastError(0);
8045     lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8046     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8047         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8048     SetLastError(0);
8049     lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8050     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8051         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8052     SetLastError(0);
8053     lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8054     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8055         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8056     SetLastError(0);
8057     lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8058     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8059         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8060     SetLastError(0);
8061     lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
8062     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8063         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8064     SetLastError(0);
8065     lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
8066     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8067         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8068
8069     /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
8070
8071     hwnd = CreateWindowW (testWindowClassW, wszUnicode,
8072                           WS_OVERLAPPEDWINDOW,
8073                           100, 100, 200, 200, 0, 0, 0, NULL);
8074     assert(hwnd);
8075     flush_sequence();
8076     lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
8077     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
8078     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
8079         "got bad length %ld\n", lRes );
8080
8081     flush_sequence();
8082     lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
8083                             hwnd, WM_GETTEXTLENGTH, 0, 0);
8084     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
8085     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
8086         "got bad length %ld\n", lRes );
8087
8088     wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
8089     newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
8090     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
8091     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
8092                                      NULL, 0, NULL, NULL ) ||
8093         broken(lRes == lstrlenW(dummy_window_text) + 37),
8094         "got bad length %ld\n", lRes );
8095
8096     SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc );  /* restore old wnd proc */
8097     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
8098     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
8099                                      NULL, 0, NULL, NULL ) ||
8100         broken(lRes == lstrlenW(dummy_window_text) + 37),
8101         "got bad length %ld\n", lRes );
8102
8103     ret = DestroyWindow(hwnd);
8104     ok( ret, "DestroyWindow() error %d\n", GetLastError());
8105 }
8106
8107 struct timer_info
8108 {
8109     HWND hWnd;
8110     HANDLE handles[2];
8111     DWORD id;
8112 };
8113
8114 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
8115 {
8116 }
8117
8118 static VOID CALLBACK tfunc_crash(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
8119 {
8120     /* Crash on purpose */
8121     *(volatile int *)0 = 2;
8122 }
8123
8124 #define TIMER_ID  0x19
8125
8126 static DWORD WINAPI timer_thread_proc(LPVOID x)
8127 {
8128     struct timer_info *info = x;
8129     DWORD r;
8130
8131     r = KillTimer(info->hWnd, 0x19);
8132     ok(r,"KillTimer failed in thread\n");
8133     r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
8134     ok(r,"SetTimer failed in thread\n");
8135     ok(r==TIMER_ID,"SetTimer id different\n");
8136     r = SetEvent(info->handles[0]);
8137     ok(r,"SetEvent failed in thread\n");
8138     return 0;
8139 }
8140
8141 static void test_timers(void)
8142 {
8143     struct timer_info info;
8144     DWORD id;
8145     MSG msg;
8146
8147     info.hWnd = CreateWindow ("TestWindowClass", NULL,
8148        WS_OVERLAPPEDWINDOW ,
8149        CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8150        NULL, NULL, 0);
8151
8152     info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
8153     ok(info.id, "SetTimer failed\n");
8154     ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
8155     info.handles[0] = CreateEvent(NULL,0,0,NULL);
8156     info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
8157
8158     WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
8159
8160     WaitForSingleObject(info.handles[1], INFINITE);
8161
8162     CloseHandle(info.handles[0]);
8163     CloseHandle(info.handles[1]);
8164
8165     ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
8166
8167     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
8168
8169     /* Test timer callback with crash */
8170     SetLastError(0xdeadbeef);
8171     info.hWnd = CreateWindowW(testWindowClassW, NULL,
8172                               WS_OVERLAPPEDWINDOW ,
8173                               CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8174                               NULL, NULL, 0);
8175     if ((!info.hWnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) || /* Win9x/Me */
8176         (!pGetMenuInfo)) /* Win95/NT4 */
8177     {
8178         win_skip("Test would crash on Win9x/WinMe/NT4\n");
8179         DestroyWindow(info.hWnd);
8180         return;
8181     }
8182     info.id = SetTimer(info.hWnd, TIMER_ID, 0, tfunc_crash);
8183     ok(info.id, "SetTimer failed\n");
8184     Sleep(150);
8185     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8186
8187     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
8188 }
8189
8190 static int count = 0;
8191 static VOID CALLBACK callback_count(
8192     HWND hwnd,
8193     UINT uMsg,
8194     UINT_PTR idEvent,
8195     DWORD dwTime
8196 )
8197 {
8198     count++;
8199 }
8200
8201 static void test_timers_no_wnd(void)
8202 {
8203     UINT_PTR id, id2;
8204     MSG msg;
8205
8206     count = 0;
8207     id = SetTimer(NULL, 0, 100, callback_count);
8208     ok(id != 0, "did not get id from SetTimer.\n");
8209     id2 = SetTimer(NULL, id, 200, callback_count);
8210     ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
8211     Sleep(150);
8212     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8213     ok(count == 0, "did not get zero count as expected (%i).\n", count);
8214     Sleep(150);
8215     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8216     ok(count == 1, "did not get one count as expected (%i).\n", count);
8217     KillTimer(NULL, id);
8218     Sleep(250);
8219     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8220     ok(count == 1, "killing replaced timer did not work (%i).\n", count);
8221 }
8222
8223 /* Various win events with arbitrary parameters */
8224 static const struct message WmWinEventsSeq[] = {
8225     { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
8226     { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
8227     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
8228     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
8229     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
8230     { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
8231     { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
8232     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
8233     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
8234     /* our win event hook ignores OBJID_CURSOR events */
8235     /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
8236     { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
8237     { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
8238     { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
8239     { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
8240     { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
8241     { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
8242     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
8243     { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
8244     { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
8245     { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
8246     { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
8247     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
8248     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
8249     { 0 }
8250 };
8251 static const struct message WmWinEventCaretSeq[] = {
8252     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8253     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8254     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
8255     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8256     { 0 }
8257 };
8258 static const struct message WmWinEventCaretSeq_2[] = {
8259     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8260     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8261     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8262     { 0 }
8263 };
8264 static const struct message WmWinEventAlertSeq[] = {
8265     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
8266     { 0 }
8267 };
8268 static const struct message WmWinEventAlertSeq_2[] = {
8269     /* create window in the thread proc */
8270     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
8271     /* our test event */
8272     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
8273     { 0 }
8274 };
8275 static const struct message WmGlobalHookSeq_1[] = {
8276     /* create window in the thread proc */
8277     { HCBT_CREATEWND, hook|lparam, 0, 2 },
8278     /* our test events */
8279     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
8280     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
8281     { 0 }
8282 };
8283 static const struct message WmGlobalHookSeq_2[] = {
8284     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
8285     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
8286     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
8287     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
8288     { 0 }
8289 };
8290
8291 static const struct message WmMouseLLHookSeq[] = {
8292     { WM_MOUSEMOVE, hook },
8293     { WM_LBUTTONUP, hook },
8294     { WM_MOUSEMOVE, hook },
8295     { 0 }
8296 };
8297
8298 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
8299                                          DWORD event,
8300                                          HWND hwnd,
8301                                          LONG object_id,
8302                                          LONG child_id,
8303                                          DWORD thread_id,
8304                                          DWORD event_time)
8305 {
8306     char buf[256];
8307
8308     if (GetClassNameA(hwnd, buf, sizeof(buf)))
8309     {
8310         if (!lstrcmpiA(buf, "TestWindowClass") ||
8311             !lstrcmpiA(buf, "static"))
8312         {
8313             struct recvd_message msg;
8314
8315             msg.hwnd = hwnd;
8316             msg.message = event;
8317             msg.flags = winevent_hook|wparam|lparam;
8318             msg.wParam = object_id;
8319             msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
8320             msg.descr = "WEH_2";
8321             add_message(&msg);
8322         }
8323     }
8324 }
8325
8326 static HHOOK hCBT_global_hook;
8327 static DWORD cbt_global_hook_thread_id;
8328
8329 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
8330
8331     HWND hwnd;
8332     char buf[256];
8333
8334     if (nCode == HCBT_SYSCOMMAND)
8335     {
8336         struct recvd_message msg;
8337
8338         msg.hwnd = 0;
8339         msg.message = nCode;
8340         msg.flags = hook|wparam|lparam;
8341         msg.wParam = wParam;
8342         msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8343         msg.descr = "CBT_2";
8344         add_message(&msg);
8345
8346         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8347     }
8348     /* WH_MOUSE_LL hook */
8349     if (nCode == HC_ACTION)
8350     {
8351         MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
8352
8353         /* we can't test for real mouse events */
8354         if (mhll->flags & LLMHF_INJECTED)
8355         {
8356             struct recvd_message msg;
8357
8358             memset (&msg, 0, sizeof (msg));
8359             msg.message = wParam;
8360             msg.flags = hook;
8361             msg.descr = "CBT_2";
8362             add_message(&msg);
8363         }
8364         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8365     }
8366
8367     /* Log also SetFocus(0) calls */
8368     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
8369
8370     if (GetClassNameA(hwnd, buf, sizeof(buf)))
8371     {
8372         if (!lstrcmpiA(buf, "TestWindowClass") ||
8373             !lstrcmpiA(buf, "static"))
8374         {
8375             struct recvd_message msg;
8376
8377             msg.hwnd = hwnd;
8378             msg.message = nCode;
8379             msg.flags = hook|wparam|lparam;
8380             msg.wParam = wParam;
8381             msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8382             msg.descr = "CBT_2";
8383             add_message(&msg);
8384         }
8385     }
8386     return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8387 }
8388
8389 static DWORD WINAPI win_event_global_thread_proc(void *param)
8390 {
8391     HWND hwnd;
8392     MSG msg;
8393     HANDLE hevent = *(HANDLE *)param;
8394
8395     assert(pNotifyWinEvent);
8396
8397     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8398     assert(hwnd);
8399     trace("created thread window %p\n", hwnd);
8400
8401     *(HWND *)param = hwnd;
8402
8403     flush_sequence();
8404     /* this event should be received only by our new hook proc,
8405      * an old one does not expect an event from another thread.
8406      */
8407     pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
8408     SetEvent(hevent);
8409
8410     while (GetMessage(&msg, 0, 0, 0))
8411     {
8412         TranslateMessage(&msg);
8413         DispatchMessage(&msg);
8414     }
8415     return 0;
8416 }
8417
8418 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
8419 {
8420     HWND hwnd;
8421     MSG msg;
8422     HANDLE hevent = *(HANDLE *)param;
8423
8424     flush_sequence();
8425     /* these events should be received only by our new hook proc,
8426      * an old one does not expect an event from another thread.
8427      */
8428
8429     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8430     assert(hwnd);
8431     trace("created thread window %p\n", hwnd);
8432
8433     *(HWND *)param = hwnd;
8434
8435     /* Windows doesn't like when a thread plays games with the focus,
8436        that leads to all kinds of misbehaviours and failures to activate
8437        a window. So, better keep next lines commented out.
8438     SetFocus(0);
8439     SetFocus(hwnd);*/
8440
8441     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8442     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8443
8444     SetEvent(hevent);
8445
8446     while (GetMessage(&msg, 0, 0, 0))
8447     {
8448         TranslateMessage(&msg);
8449         DispatchMessage(&msg);
8450     }
8451     return 0;
8452 }
8453
8454 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
8455 {
8456     HWND hwnd;
8457     MSG msg;
8458     HANDLE hevent = *(HANDLE *)param;
8459
8460     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8461     assert(hwnd);
8462     trace("created thread window %p\n", hwnd);
8463
8464     *(HWND *)param = hwnd;
8465
8466     flush_sequence();
8467
8468     /* Windows doesn't like when a thread plays games with the focus,
8469      * that leads to all kinds of misbehaviours and failures to activate
8470      * a window. So, better don't generate a mouse click message below.
8471      */
8472     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8473     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8474     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8475
8476     SetEvent(hevent);
8477     while (GetMessage(&msg, 0, 0, 0))
8478     {
8479         TranslateMessage(&msg);
8480         DispatchMessage(&msg);
8481     }
8482     return 0;
8483 }
8484
8485 static void test_winevents(void)
8486 {
8487     BOOL ret;
8488     MSG msg;
8489     HWND hwnd, hwnd2;
8490     UINT i;
8491     HANDLE hthread, hevent;
8492     DWORD tid;
8493     HWINEVENTHOOK hhook;
8494     const struct message *events = WmWinEventsSeq;
8495
8496     hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
8497                            WS_OVERLAPPEDWINDOW,
8498                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8499                            NULL, NULL, 0);
8500     assert(hwnd);
8501
8502     /****** start of global hook test *************/
8503     hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8504     if (!hCBT_global_hook)
8505     {
8506         ok(DestroyWindow(hwnd), "failed to destroy window\n");
8507         skip( "cannot set global hook\n" );
8508         return;
8509     }
8510
8511     hevent = CreateEventA(NULL, 0, 0, NULL);
8512     assert(hevent);
8513     hwnd2 = hevent;
8514
8515     hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
8516     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8517
8518     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8519
8520     ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
8521
8522     flush_sequence();
8523     /* this one should be received only by old hook proc */
8524     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8525     /* this one should be received only by old hook proc */
8526     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8527
8528     ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
8529
8530     ret = UnhookWindowsHookEx(hCBT_global_hook);
8531     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8532
8533     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8534     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8535     CloseHandle(hthread);
8536     CloseHandle(hevent);
8537     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8538     /****** end of global hook test *************/
8539
8540     if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
8541     {
8542         ok(DestroyWindow(hwnd), "failed to destroy window\n");
8543         return;
8544     }
8545
8546     flush_sequence();
8547
8548     if (0)
8549     {
8550     /* this test doesn't pass under Win9x */
8551     /* win2k ignores events with hwnd == 0 */
8552     SetLastError(0xdeadbeef);
8553     pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
8554     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
8555        GetLastError() == 0xdeadbeef, /* Win9x */
8556        "unexpected error %d\n", GetLastError());
8557     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8558     }
8559
8560     for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
8561         pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
8562
8563     ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
8564
8565     /****** start of event filtering test *************/
8566     hhook = pSetWinEventHook(
8567         EVENT_OBJECT_SHOW, /* 0x8002 */
8568         EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
8569         GetModuleHandleA(0), win_event_global_hook_proc,
8570         GetCurrentProcessId(), 0,
8571         WINEVENT_INCONTEXT);
8572     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8573
8574     hevent = CreateEventA(NULL, 0, 0, NULL);
8575     assert(hevent);
8576     hwnd2 = hevent;
8577
8578     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8579     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8580
8581     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8582
8583     ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
8584
8585     flush_sequence();
8586     /* this one should be received only by old hook proc */
8587     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8588     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8589     /* this one should be received only by old hook proc */
8590     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8591
8592     ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
8593
8594     ret = pUnhookWinEvent(hhook);
8595     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8596
8597     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8598     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8599     CloseHandle(hthread);
8600     CloseHandle(hevent);
8601     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8602     /****** end of event filtering test *************/
8603
8604     /****** start of out of context event test *************/
8605     hhook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0,
8606         win_event_global_hook_proc, GetCurrentProcessId(), 0,
8607         WINEVENT_OUTOFCONTEXT);
8608     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8609
8610     hevent = CreateEventA(NULL, 0, 0, NULL);
8611     assert(hevent);
8612     hwnd2 = hevent;
8613
8614     flush_sequence();
8615
8616     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8617     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8618
8619     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8620
8621     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8622     /* process pending winevent messages */
8623     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8624     ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
8625
8626     flush_sequence();
8627     /* this one should be received only by old hook proc */
8628     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8629     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8630     /* this one should be received only by old hook proc */
8631     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8632
8633     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
8634     /* process pending winevent messages */
8635     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8636     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
8637
8638     ret = pUnhookWinEvent(hhook);
8639     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8640
8641     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8642     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8643     CloseHandle(hthread);
8644     CloseHandle(hevent);
8645     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8646     /****** end of out of context event test *************/
8647
8648     /****** start of MOUSE_LL hook test *************/
8649     hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8650     /* WH_MOUSE_LL is not supported on Win9x platforms */
8651     if (!hCBT_global_hook)
8652     {
8653         win_skip("Skipping WH_MOUSE_LL test on this platform\n");
8654         goto skip_mouse_ll_hook_test;
8655     }
8656
8657     hevent = CreateEventA(NULL, 0, 0, NULL);
8658     assert(hevent);
8659     hwnd2 = hevent;
8660
8661     hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
8662     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8663
8664     while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
8665         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
8666
8667     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
8668     flush_sequence();
8669
8670     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8671     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8672     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8673
8674     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
8675
8676     ret = UnhookWindowsHookEx(hCBT_global_hook);
8677     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8678
8679     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8680     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8681     CloseHandle(hthread);
8682     CloseHandle(hevent);
8683     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8684     /****** end of MOUSE_LL hook test *************/
8685 skip_mouse_ll_hook_test:
8686
8687     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8688 }
8689
8690 static void test_set_hook(void)
8691 {
8692     BOOL ret;
8693     HHOOK hhook;
8694     HWINEVENTHOOK hwinevent_hook;
8695
8696     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
8697     ok(hhook != 0, "local hook does not require hModule set to 0\n");
8698     UnhookWindowsHookEx(hhook);
8699
8700     if (0)
8701     {
8702     /* this test doesn't pass under Win9x: BUG! */
8703     SetLastError(0xdeadbeef);
8704     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
8705     ok(!hhook, "global hook requires hModule != 0\n");
8706     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
8707     }
8708
8709     SetLastError(0xdeadbeef);
8710     hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
8711     ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
8712     ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
8713        GetLastError() == 0xdeadbeef, /* Win9x */
8714        "unexpected error %d\n", GetLastError());
8715
8716     SetLastError(0xdeadbeef);
8717     ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
8718     ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
8719        GetLastError() == 0xdeadbeef, /* Win9x */
8720        "unexpected error %d\n", GetLastError());
8721
8722     if (!pSetWinEventHook || !pUnhookWinEvent) return;
8723
8724     /* even process local incontext hooks require hmodule */
8725     SetLastError(0xdeadbeef);
8726     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8727         GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
8728     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8729     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8730        GetLastError() == 0xdeadbeef, /* Win9x */
8731        "unexpected error %d\n", GetLastError());
8732
8733     /* even thread local incontext hooks require hmodule */
8734     SetLastError(0xdeadbeef);
8735     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8736         GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
8737     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8738     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8739        GetLastError() == 0xdeadbeef, /* Win9x */
8740        "unexpected error %d\n", GetLastError());
8741
8742     if (0)
8743     {
8744     /* these 3 tests don't pass under Win9x */
8745     SetLastError(0xdeadbeef);
8746     hwinevent_hook = pSetWinEventHook(1, 0, 0, win_event_proc,
8747         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8748     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8749     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8750
8751     SetLastError(0xdeadbeef);
8752     hwinevent_hook = pSetWinEventHook(-1, 1, 0, win_event_proc,
8753         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8754     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8755     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8756
8757     SetLastError(0xdeadbeef);
8758     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8759         0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
8760     ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
8761     ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
8762     }
8763
8764     SetLastError(0xdeadbeef);
8765     hwinevent_hook = pSetWinEventHook(0, 0, 0, win_event_proc,
8766         GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8767     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8768     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8769     ret = pUnhookWinEvent(hwinevent_hook);
8770     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8771
8772 todo_wine {
8773     /* This call succeeds under win2k SP4, but fails under Wine.
8774        Does win2k test/use passed process id? */
8775     SetLastError(0xdeadbeef);
8776     hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8777         0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
8778     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8779     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8780     ret = pUnhookWinEvent(hwinevent_hook);
8781     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8782 }
8783
8784     SetLastError(0xdeadbeef);
8785     ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
8786     ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
8787         GetLastError() == 0xdeadbeef, /* Win9x */
8788         "unexpected error %d\n", GetLastError());
8789 }
8790
8791 static const struct message ScrollWindowPaint1[] = {
8792     { WM_PAINT, sent },
8793     { WM_ERASEBKGND, sent|beginpaint },
8794     { WM_GETTEXTLENGTH, sent|optional },
8795     { WM_PAINT, sent|optional },
8796     { WM_NCPAINT, sent|beginpaint|optional },
8797     { WM_GETTEXT, sent|beginpaint|optional },
8798     { WM_GETTEXT, sent|beginpaint|optional },
8799     { WM_GETTEXT, sent|beginpaint|optional },
8800     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
8801     { WM_ERASEBKGND, sent|beginpaint|optional },
8802     { 0 }
8803 };
8804
8805 static const struct message ScrollWindowPaint2[] = {
8806     { WM_PAINT, sent },
8807     { 0 }
8808 };
8809
8810 static void test_scrollwindowex(void)
8811 {
8812     HWND hwnd, hchild;
8813     RECT rect={0,0,130,130};
8814
8815     hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
8816             WS_VISIBLE|WS_OVERLAPPEDWINDOW,
8817             100, 100, 200, 200, 0, 0, 0, NULL);
8818     ok (hwnd != 0, "Failed to create overlapped window\n");
8819     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", 
8820             WS_VISIBLE|WS_CAPTION|WS_CHILD,
8821             10, 10, 150, 150, hwnd, 0, 0, NULL);
8822     ok (hchild != 0, "Failed to create child\n");
8823     UpdateWindow(hwnd);
8824     flush_events();
8825     flush_sequence();
8826
8827     /* scroll without the child window */
8828     trace("start scroll\n");
8829     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8830             SW_ERASE|SW_INVALIDATE);
8831     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8832     trace("end scroll\n");
8833     flush_sequence();
8834     flush_events();
8835     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8836     flush_events();
8837     flush_sequence();
8838
8839     /* Now without the SW_ERASE flag */
8840     trace("start scroll\n");
8841     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
8842     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8843     trace("end scroll\n");
8844     flush_sequence();
8845     flush_events();
8846     ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
8847     flush_events();
8848     flush_sequence();
8849
8850     /* now scroll the child window as well */
8851     trace("start scroll\n");
8852     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8853             SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
8854     /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
8855     /* windows sometimes a WM_MOVE */
8856     ok_sequence(WmEmptySeq, "ScrollWindowEx", TRUE);
8857     trace("end scroll\n");
8858     flush_sequence();
8859     flush_events();
8860     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8861     flush_events();
8862     flush_sequence();
8863
8864     /* now scroll with ScrollWindow() */
8865     trace("start scroll with ScrollWindow\n");
8866     ScrollWindow( hwnd, 5, 5, NULL, NULL);
8867     trace("end scroll\n");
8868     flush_sequence();
8869     flush_events();
8870     ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
8871
8872     ok(DestroyWindow(hchild), "failed to destroy window\n");
8873     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8874     flush_sequence();
8875 }
8876
8877 static const struct message destroy_window_with_children[] = {
8878     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8879     { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
8880     { 0x0090, sent|optional },
8881     { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
8882     { 0x0090, sent|optional },
8883     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8884     { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8885     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8886     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8887     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
8888     { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8889     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8890     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8891     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8892     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8893     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8894     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8895     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8896     { 0 }
8897 };
8898
8899 static void test_DestroyWindow(void)
8900 {
8901     BOOL ret;
8902     HWND parent, child1, child2, child3, child4, test;
8903     UINT_PTR child_id = WND_CHILD_ID + 1;
8904
8905     parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8906                              100, 100, 200, 200, 0, 0, 0, NULL);
8907     assert(parent != 0);
8908     child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8909                              0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
8910     assert(child1 != 0);
8911     child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8912                              0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
8913     assert(child2 != 0);
8914     child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8915                              0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
8916     assert(child3 != 0);
8917     child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
8918                              0, 0, 50, 50, parent, 0, 0, NULL);
8919     assert(child4 != 0);
8920
8921     /* test owner/parent of child2 */
8922     test = GetParent(child2);
8923     ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8924     ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8925     if(pGetAncestor) {
8926         test = pGetAncestor(child2, GA_PARENT);
8927         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8928     }
8929     test = GetWindow(child2, GW_OWNER);
8930     ok(!test, "wrong owner %p\n", test);
8931
8932     test = SetParent(child2, parent);
8933     ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
8934
8935     /* test owner/parent of the parent */
8936     test = GetParent(parent);
8937     ok(!test, "wrong parent %p\n", test);
8938     ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
8939     if(pGetAncestor) {
8940         test = pGetAncestor(parent, GA_PARENT);
8941         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8942     }
8943     test = GetWindow(parent, GW_OWNER);
8944     ok(!test, "wrong owner %p\n", test);
8945
8946     /* test owner/parent of child1 */
8947     test = GetParent(child1);
8948     ok(test == parent, "wrong parent %p\n", test);
8949     ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
8950     if(pGetAncestor) {
8951         test = pGetAncestor(child1, GA_PARENT);
8952         ok(test == parent, "wrong parent %p\n", test);
8953     }
8954     test = GetWindow(child1, GW_OWNER);
8955     ok(!test, "wrong owner %p\n", test);
8956
8957     /* test owner/parent of child2 */
8958     test = GetParent(child2);
8959     ok(test == parent, "wrong parent %p\n", test);
8960     ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8961     if(pGetAncestor) {
8962         test = pGetAncestor(child2, GA_PARENT);
8963         ok(test == parent, "wrong parent %p\n", test);
8964     }
8965     test = GetWindow(child2, GW_OWNER);
8966     ok(!test, "wrong owner %p\n", test);
8967
8968     /* test owner/parent of child3 */
8969     test = GetParent(child3);
8970     ok(test == child1, "wrong parent %p\n", test);
8971     ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
8972     if(pGetAncestor) {
8973         test = pGetAncestor(child3, GA_PARENT);
8974         ok(test == child1, "wrong parent %p\n", test);
8975     }
8976     test = GetWindow(child3, GW_OWNER);
8977     ok(!test, "wrong owner %p\n", test);
8978
8979     /* test owner/parent of child4 */
8980     test = GetParent(child4);
8981     ok(test == parent, "wrong parent %p\n", test);
8982     ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
8983     if(pGetAncestor) {
8984         test = pGetAncestor(child4, GA_PARENT);
8985         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8986     }
8987     test = GetWindow(child4, GW_OWNER);
8988     ok(test == parent, "wrong owner %p\n", test);
8989
8990     flush_sequence();
8991
8992     trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
8993            parent, child1, child2, child3, child4);
8994
8995     SetCapture(child4);
8996     test = GetCapture();
8997     ok(test == child4, "wrong capture window %p\n", test);
8998
8999     test_DestroyWindow_flag = TRUE;
9000     ret = DestroyWindow(parent);
9001     ok( ret, "DestroyWindow() error %d\n", GetLastError());
9002     test_DestroyWindow_flag = FALSE;
9003     ok_sequence(destroy_window_with_children, "destroy window with children", 0);
9004
9005     ok(!IsWindow(parent), "parent still exists\n");
9006     ok(!IsWindow(child1), "child1 still exists\n");
9007     ok(!IsWindow(child2), "child2 still exists\n");
9008     ok(!IsWindow(child3), "child3 still exists\n");
9009     ok(!IsWindow(child4), "child4 still exists\n");
9010
9011     test = GetCapture();
9012     ok(!test, "wrong capture window %p\n", test);
9013 }
9014
9015
9016 static const struct message WmDispatchPaint[] = {
9017     { WM_NCPAINT, sent },
9018     { WM_GETTEXT, sent|defwinproc|optional },
9019     { WM_GETTEXT, sent|defwinproc|optional },
9020     { WM_ERASEBKGND, sent },
9021     { 0 }
9022 };
9023
9024 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9025 {
9026     if (message == WM_PAINT) return 0;
9027     return MsgCheckProcA( hwnd, message, wParam, lParam );
9028 }
9029
9030 static void test_DispatchMessage(void)
9031 {
9032     RECT rect;
9033     MSG msg;
9034     int count;
9035     HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9036                                100, 100, 200, 200, 0, 0, 0, NULL);
9037     ShowWindow( hwnd, SW_SHOW );
9038     UpdateWindow( hwnd );
9039     flush_events();
9040     flush_sequence();
9041     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
9042
9043     SetRect( &rect, -5, -5, 5, 5 );
9044     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
9045     count = 0;
9046     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
9047     {
9048         if (msg.message != WM_PAINT) DispatchMessage( &msg );
9049         else
9050         {
9051             flush_sequence();
9052             DispatchMessage( &msg );
9053             /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
9054             if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
9055             else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
9056             if (++count > 10) break;
9057         }
9058     }
9059     ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
9060
9061     trace("now without DispatchMessage\n");
9062     flush_sequence();
9063     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
9064     count = 0;
9065     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
9066     {
9067         if (msg.message != WM_PAINT) DispatchMessage( &msg );
9068         else
9069         {
9070             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
9071             flush_sequence();
9072             /* this will send WM_NCCPAINT just like DispatchMessage does */
9073             GetUpdateRgn( hwnd, hrgn, TRUE );
9074             ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
9075             DeleteObject( hrgn );
9076             GetClientRect( hwnd, &rect );
9077             ValidateRect( hwnd, &rect );  /* this will stop WM_PAINTs */
9078             ok( !count, "Got multiple WM_PAINTs\n" );
9079             if (++count > 10) break;
9080         }
9081     }
9082     DestroyWindow(hwnd);
9083 }
9084
9085
9086 static const struct message WmUser[] = {
9087     { WM_USER, sent },
9088     { 0 }
9089 };
9090
9091 struct sendmsg_info
9092 {
9093     HWND  hwnd;
9094     DWORD timeout;
9095     DWORD ret;
9096 };
9097
9098 static DWORD CALLBACK send_msg_thread( LPVOID arg )
9099 {
9100     struct sendmsg_info *info = arg;
9101     SetLastError( 0xdeadbeef );
9102     info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
9103     if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT ||
9104                         broken(GetLastError() == 0),  /* win9x */
9105                         "unexpected error %d\n", GetLastError());
9106     return 0;
9107 }
9108
9109 static void wait_for_thread( HANDLE thread )
9110 {
9111     while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
9112     {
9113         MSG msg;
9114         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
9115     }
9116 }
9117
9118 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9119 {
9120     if (message == WM_USER) Sleep(200);
9121     return MsgCheckProcA( hwnd, message, wParam, lParam );
9122 }
9123
9124 static void test_SendMessageTimeout(void)
9125 {
9126     HANDLE thread;
9127     struct sendmsg_info info;
9128     DWORD tid;
9129     BOOL is_win9x;
9130
9131     info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9132                                100, 100, 200, 200, 0, 0, 0, NULL);
9133     flush_events();
9134     flush_sequence();
9135
9136     info.timeout = 1000;
9137     info.ret = 0xdeadbeef;
9138     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9139     wait_for_thread( thread );
9140     CloseHandle( thread );
9141     ok( info.ret == 1, "SendMessageTimeout failed\n" );
9142     ok_sequence( WmUser, "WmUser", FALSE );
9143
9144     info.timeout = 1;
9145     info.ret = 0xdeadbeef;
9146     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9147     Sleep(100);  /* SendMessageTimeout should time out here */
9148     wait_for_thread( thread );
9149     CloseHandle( thread );
9150     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
9151     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9152
9153     /* 0 means infinite timeout (but not on win9x) */
9154     info.timeout = 0;
9155     info.ret = 0xdeadbeef;
9156     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9157     Sleep(100);
9158     wait_for_thread( thread );
9159     CloseHandle( thread );
9160     is_win9x = !info.ret;
9161     if (is_win9x) ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9162     else ok_sequence( WmUser, "WmUser", FALSE );
9163
9164     /* timeout is treated as signed despite the prototype (but not on win9x) */
9165     info.timeout = 0x7fffffff;
9166     info.ret = 0xdeadbeef;
9167     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9168     Sleep(100);
9169     wait_for_thread( thread );
9170     CloseHandle( thread );
9171     ok( info.ret == 1, "SendMessageTimeout failed\n" );
9172     ok_sequence( WmUser, "WmUser", FALSE );
9173
9174     info.timeout = 0x80000000;
9175     info.ret = 0xdeadbeef;
9176     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9177     Sleep(100);
9178     wait_for_thread( thread );
9179     CloseHandle( thread );
9180     if (is_win9x)
9181     {
9182         ok( info.ret == 1, "SendMessageTimeout failed\n" );
9183         ok_sequence( WmUser, "WmUser", FALSE );
9184     }
9185     else
9186     {
9187         ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
9188         ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9189     }
9190
9191     /* now check for timeout during message processing */
9192     SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
9193     info.timeout = 100;
9194     info.ret = 0xdeadbeef;
9195     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9196     wait_for_thread( thread );
9197     CloseHandle( thread );
9198     /* we should time out but still get the message */
9199     ok( info.ret == 0, "SendMessageTimeout failed\n" );
9200     ok_sequence( WmUser, "WmUser", FALSE );
9201
9202     DestroyWindow( info.hwnd );
9203 }
9204
9205
9206 /****************** edit message test *************************/
9207 #define ID_EDIT 0x1234
9208 static const struct message sl_edit_setfocus[] =
9209 {
9210     { HCBT_SETFOCUS, hook },
9211     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9212     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9213     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9214     { WM_SETFOCUS, sent|wparam, 0 },
9215     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9216     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
9217     { WM_CTLCOLOREDIT, sent|parent },
9218     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9219     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9220     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9221     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9222     { 0 }
9223 };
9224 static const struct message ml_edit_setfocus[] =
9225 {
9226     { HCBT_SETFOCUS, hook },
9227     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9228     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9229     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9230     { WM_SETFOCUS, sent|wparam, 0 },
9231     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9232     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9233     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9234     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9235     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9236     { 0 }
9237 };
9238 static const struct message sl_edit_killfocus[] =
9239 {
9240     { HCBT_SETFOCUS, hook },
9241     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9242     { WM_KILLFOCUS, sent|wparam, 0 },
9243     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9244     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9245     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
9246     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
9247     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
9248     { 0 }
9249 };
9250 static const struct message sl_edit_lbutton_dblclk[] =
9251 {
9252     { WM_LBUTTONDBLCLK, sent },
9253     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9254     { 0 }
9255 };
9256 static const struct message sl_edit_lbutton_down[] =
9257 {
9258     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
9259     { HCBT_SETFOCUS, hook },
9260     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9261     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9262     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9263     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9264     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9265     { WM_CTLCOLOREDIT, sent|parent },
9266     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9267     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9268     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9269     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9270     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9271     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9272     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9273     { WM_CTLCOLOREDIT, sent|parent|optional },
9274     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9275     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9276     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9277     { 0 }
9278 };
9279 static const struct message ml_edit_lbutton_down[] =
9280 {
9281     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
9282     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9283     { HCBT_SETFOCUS, hook },
9284     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9285     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9286     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9287     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9288     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9289     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9290     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9291     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9292     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9293     { 0 }
9294 };
9295 static const struct message sl_edit_lbutton_up[] =
9296 {
9297     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9298     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9299     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9300     { WM_CAPTURECHANGED, sent|defwinproc },
9301     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9302     { 0 }
9303 };
9304 static const struct message ml_edit_lbutton_up[] =
9305 {
9306     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9307     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9308     { WM_CAPTURECHANGED, sent|defwinproc },
9309     { 0 }
9310 };
9311
9312 static WNDPROC old_edit_proc;
9313
9314 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9315 {
9316     static LONG defwndproc_counter = 0;
9317     LRESULT ret;
9318     struct recvd_message msg;
9319
9320     if (ignore_message( message )) return 0;
9321
9322     msg.hwnd = hwnd;
9323     msg.message = message;
9324     msg.flags = sent|wparam|lparam;
9325     if (defwndproc_counter) msg.flags |= defwinproc;
9326     msg.wParam = wParam;
9327     msg.lParam = lParam;
9328     msg.descr = "edit";
9329     add_message(&msg);
9330
9331     defwndproc_counter++;
9332     ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
9333     defwndproc_counter--;
9334
9335     return ret;
9336 }
9337
9338 static void subclass_edit(void)
9339 {
9340     WNDCLASSA cls;
9341
9342     if (!GetClassInfoA(0, "edit", &cls)) assert(0);
9343
9344     old_edit_proc = cls.lpfnWndProc;
9345
9346     cls.hInstance = GetModuleHandle(0);
9347     cls.lpfnWndProc = edit_hook_proc;
9348     cls.lpszClassName = "my_edit_class";
9349     UnregisterClass(cls.lpszClassName, cls.hInstance);
9350     if (!RegisterClassA(&cls)) assert(0);
9351 }
9352
9353 static void test_edit_messages(void)
9354 {
9355     HWND hwnd, parent;
9356     DWORD dlg_code;
9357
9358     subclass_edit();
9359     log_all_parent_messages++;
9360
9361     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9362                              100, 100, 200, 200, 0, 0, 0, NULL);
9363     ok (parent != 0, "Failed to create parent window\n");
9364
9365     /* test single line edit */
9366     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
9367                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9368     ok(hwnd != 0, "Failed to create edit window\n");
9369
9370     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9371     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
9372
9373     ShowWindow(hwnd, SW_SHOW);
9374     UpdateWindow(hwnd);
9375     SetFocus(0);
9376     flush_sequence();
9377
9378     SetFocus(hwnd);
9379     ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
9380
9381     SetFocus(0);
9382     ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
9383
9384     SetFocus(0);
9385     ReleaseCapture();
9386     flush_sequence();
9387
9388     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9389     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
9390
9391     SetFocus(0);
9392     ReleaseCapture();
9393     flush_sequence();
9394
9395     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9396     ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
9397
9398     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9399     ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
9400
9401     DestroyWindow(hwnd);
9402
9403     /* test multiline edit */
9404     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
9405                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9406     ok(hwnd != 0, "Failed to create edit window\n");
9407
9408     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9409     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
9410        "wrong dlg_code %08x\n", dlg_code);
9411
9412     ShowWindow(hwnd, SW_SHOW);
9413     UpdateWindow(hwnd);
9414     SetFocus(0);
9415     flush_sequence();
9416
9417     SetFocus(hwnd);
9418     ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
9419
9420     SetFocus(0);
9421     ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
9422
9423     SetFocus(0);
9424     ReleaseCapture();
9425     flush_sequence();
9426
9427     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9428     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
9429
9430     SetFocus(0);
9431     ReleaseCapture();
9432     flush_sequence();
9433
9434     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9435     ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
9436
9437     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9438     ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
9439
9440     DestroyWindow(hwnd);
9441     DestroyWindow(parent);
9442
9443     log_all_parent_messages--;
9444 }
9445
9446 /**************************** End of Edit test ******************************/
9447
9448 static const struct message WmKeyDownSkippedSeq[] =
9449 {
9450     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
9451     { 0 }
9452 };
9453 static const struct message WmKeyDownWasDownSkippedSeq[] =
9454 {
9455     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x40000001 }, /* XP */
9456     { 0 }
9457 };
9458 static const struct message WmKeyUpSkippedSeq[] =
9459 {
9460     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9461     { 0 }
9462 };
9463 static const struct message WmUserKeyUpSkippedSeq[] =
9464 {
9465     { WM_USER, sent },
9466     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9467     { 0 }
9468 };
9469
9470 #define EV_STOP 0
9471 #define EV_SENDMSG 1
9472 #define EV_ACK 2
9473
9474 struct peekmsg_info
9475 {
9476     HWND  hwnd;
9477     HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
9478 };
9479
9480 static DWORD CALLBACK send_msg_thread_2(void *param)
9481 {
9482     DWORD ret;
9483     struct peekmsg_info *info = param;
9484
9485     trace("thread: looping\n");
9486     SetEvent(info->hevent[EV_ACK]);
9487
9488     while (1)
9489     {
9490         ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
9491
9492         switch (ret)
9493         {
9494         case WAIT_OBJECT_0 + EV_STOP:
9495             trace("thread: exiting\n");
9496             return 0;
9497
9498         case WAIT_OBJECT_0 + EV_SENDMSG:
9499             trace("thread: sending message\n");
9500             ok( SendNotifyMessageA(info->hwnd, WM_USER, 0, 0),
9501                 "SendNotifyMessageA failed error %u\n", GetLastError());
9502             SetEvent(info->hevent[EV_ACK]);
9503             break;
9504
9505         default:
9506             trace("unexpected return: %04x\n", ret);
9507             assert(0);
9508             break;
9509         }
9510     }
9511     return 0;
9512 }
9513
9514 static void test_PeekMessage(void)
9515 {
9516     MSG msg;
9517     HANDLE hthread;
9518     DWORD tid, qstatus;
9519     UINT qs_all_input = QS_ALLINPUT;
9520     UINT qs_input = QS_INPUT;
9521     BOOL ret;
9522     struct peekmsg_info info;
9523
9524     info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9525                               100, 100, 200, 200, 0, 0, 0, NULL);
9526     assert(info.hwnd);
9527     ShowWindow(info.hwnd, SW_SHOW);
9528     UpdateWindow(info.hwnd);
9529     SetFocus(info.hwnd);
9530
9531     info.hevent[EV_STOP] = CreateEventA(NULL, 0, 0, NULL);
9532     info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
9533     info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
9534
9535     hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
9536     WaitForSingleObject(info.hevent[EV_ACK], 10000);
9537
9538     flush_events();
9539     flush_sequence();
9540
9541     SetLastError(0xdeadbeef);
9542     qstatus = GetQueueStatus(qs_all_input);
9543     if (GetLastError() == ERROR_INVALID_FLAGS)
9544     {
9545         trace("QS_RAWINPUT not supported on this platform\n");
9546         qs_all_input &= ~QS_RAWINPUT;
9547         qs_input &= ~QS_RAWINPUT;
9548     }
9549     if (qstatus & QS_POSTMESSAGE)
9550     {
9551         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) /* nothing */ ;
9552         qstatus = GetQueueStatus(qs_all_input);
9553     }
9554     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9555
9556     trace("signalling to send message\n");
9557     SetEvent(info.hevent[EV_SENDMSG]);
9558     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9559
9560     /* pass invalid QS_xxxx flags */
9561     SetLastError(0xdeadbeef);
9562     qstatus = GetQueueStatus(0xffffffff);
9563     ok(qstatus == 0 || broken(qstatus)  /* win9x */, "GetQueueStatus should fail: %08x\n", qstatus);
9564     if (!qstatus)
9565     {
9566         ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
9567         qstatus = GetQueueStatus(qs_all_input);
9568     }
9569     qstatus &= ~MAKELONG( 0x4000, 0x4000 );  /* sometimes set on Win95 */
9570     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
9571        "wrong qstatus %08x\n", qstatus);
9572
9573     msg.message = 0;
9574     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9575     ok(!ret,
9576        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9577         msg.message);
9578     ok_sequence(WmUser, "WmUser", FALSE);
9579
9580     qstatus = GetQueueStatus(qs_all_input);
9581     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9582
9583     keybd_event('N', 0, 0, 0);
9584     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9585     qstatus = GetQueueStatus(qs_all_input);
9586     if (!(qstatus & MAKELONG(QS_KEY, QS_KEY)))
9587     {
9588         skip( "queuing key events not supported\n" );
9589         goto done;
9590     }
9591     ok(qstatus == MAKELONG(QS_KEY, QS_KEY) ||
9592        /* keybd_event seems to trigger a sent message on NT4 */
9593        qstatus == MAKELONG(QS_KEY|QS_SENDMESSAGE, QS_KEY|QS_SENDMESSAGE),
9594        "wrong qstatus %08x\n", qstatus);
9595
9596     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9597     qstatus = GetQueueStatus(qs_all_input);
9598     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY) ||
9599        qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY|QS_SENDMESSAGE),
9600        "wrong qstatus %08x\n", qstatus);
9601
9602     InvalidateRect(info.hwnd, NULL, FALSE);
9603     qstatus = GetQueueStatus(qs_all_input);
9604     ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY) ||
9605        qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY|QS_SENDMESSAGE),
9606        "wrong qstatus %08x\n", qstatus);
9607
9608     trace("signalling to send message\n");
9609     SetEvent(info.hevent[EV_SENDMSG]);
9610     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9611
9612     qstatus = GetQueueStatus(qs_all_input);
9613     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9614        "wrong qstatus %08x\n", qstatus);
9615
9616     msg.message = 0;
9617     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
9618     if (ret && msg.message == WM_CHAR)
9619     {
9620         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9621         goto done;
9622     }
9623     ok(!ret,
9624        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9625         msg.message);
9626     if (!sequence_cnt)  /* nt4 doesn't fetch anything with PM_QS_* flags */
9627     {
9628         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9629         goto done;
9630     }
9631     ok_sequence(WmUser, "WmUser", FALSE);
9632
9633     qstatus = GetQueueStatus(qs_all_input);
9634     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9635        "wrong qstatus %08x\n", qstatus);
9636
9637     trace("signalling to send message\n");
9638     SetEvent(info.hevent[EV_SENDMSG]);
9639     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9640
9641     qstatus = GetQueueStatus(qs_all_input);
9642     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9643        "wrong qstatus %08x\n", qstatus);
9644
9645     msg.message = 0;
9646     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE );
9647     ok(!ret,
9648        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9649         msg.message);
9650     ok_sequence(WmUser, "WmUser", FALSE);
9651
9652     qstatus = GetQueueStatus(qs_all_input);
9653     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9654        "wrong qstatus %08x\n", qstatus);
9655
9656     msg.message = 0;
9657     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9658     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9659        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9660        ret, msg.message, msg.wParam);
9661     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9662
9663     qstatus = GetQueueStatus(qs_all_input);
9664     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9665        "wrong qstatus %08x\n", qstatus);
9666
9667     msg.message = 0;
9668     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9669     ok(!ret,
9670        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9671         msg.message);
9672     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9673
9674     qstatus = GetQueueStatus(qs_all_input);
9675     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9676        "wrong qstatus %08x\n", qstatus);
9677
9678     msg.message = 0;
9679     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9680     ok(ret && msg.message == WM_PAINT,
9681        "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
9682     DispatchMessageA(&msg);
9683     ok_sequence(WmPaint, "WmPaint", FALSE);
9684
9685     qstatus = GetQueueStatus(qs_all_input);
9686     ok(qstatus == MAKELONG(0, QS_KEY),
9687        "wrong qstatus %08x\n", qstatus);
9688
9689     msg.message = 0;
9690     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9691     ok(!ret,
9692        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9693         msg.message);
9694     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9695
9696     qstatus = GetQueueStatus(qs_all_input);
9697     ok(qstatus == MAKELONG(0, QS_KEY),
9698        "wrong qstatus %08x\n", qstatus);
9699
9700     trace("signalling to send message\n");
9701     SetEvent(info.hevent[EV_SENDMSG]);
9702     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9703
9704     qstatus = GetQueueStatus(qs_all_input);
9705     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
9706        "wrong qstatus %08x\n", qstatus);
9707
9708     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9709
9710     qstatus = GetQueueStatus(qs_all_input);
9711     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9712        "wrong qstatus %08x\n", qstatus);
9713
9714     msg.message = 0;
9715     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9716     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9717        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9718        ret, msg.message, msg.wParam);
9719     ok_sequence(WmUser, "WmUser", FALSE);
9720
9721     qstatus = GetQueueStatus(qs_all_input);
9722     ok(qstatus == MAKELONG(0, QS_KEY),
9723        "wrong qstatus %08x\n", qstatus);
9724
9725     msg.message = 0;
9726     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9727     ok(!ret,
9728        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9729         msg.message);
9730     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9731
9732     qstatus = GetQueueStatus(qs_all_input);
9733     ok(qstatus == MAKELONG(0, QS_KEY),
9734        "wrong qstatus %08x\n", qstatus);
9735
9736     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9737
9738     qstatus = GetQueueStatus(qs_all_input);
9739     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9740        "wrong qstatus %08x\n", qstatus);
9741
9742     trace("signalling to send message\n");
9743     SetEvent(info.hevent[EV_SENDMSG]);
9744     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9745
9746     qstatus = GetQueueStatus(qs_all_input);
9747     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9748        "wrong qstatus %08x\n", qstatus);
9749
9750     msg.message = 0;
9751     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
9752     ok(!ret,
9753        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9754         msg.message);
9755     ok_sequence(WmUser, "WmUser", FALSE);
9756
9757     qstatus = GetQueueStatus(qs_all_input);
9758     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9759        "wrong qstatus %08x\n", qstatus);
9760
9761     msg.message = 0;
9762     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9763         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9764     else /* workaround for a missing QS_RAWINPUT support */
9765         ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
9766     ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9767        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9768        ret, msg.message, msg.wParam);
9769     ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9770
9771     qstatus = GetQueueStatus(qs_all_input);
9772     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9773        "wrong qstatus %08x\n", qstatus);
9774
9775     msg.message = 0;
9776     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9777         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9778     else /* workaround for a missing QS_RAWINPUT support */
9779         ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
9780     ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9781        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
9782        ret, msg.message, msg.wParam);
9783     ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
9784
9785     qstatus = GetQueueStatus(qs_all_input);
9786     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9787        "wrong qstatus %08x\n", qstatus);
9788
9789     msg.message = 0;
9790     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
9791     ok(!ret,
9792        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9793         msg.message);
9794     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9795
9796     qstatus = GetQueueStatus(qs_all_input);
9797     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9798        "wrong qstatus %08x\n", qstatus);
9799
9800     msg.message = 0;
9801     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9802     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9803        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9804        ret, msg.message, msg.wParam);
9805     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9806
9807     qstatus = GetQueueStatus(qs_all_input);
9808     ok(qstatus == 0,
9809        "wrong qstatus %08x\n", qstatus);
9810
9811     msg.message = 0;
9812     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9813     ok(!ret,
9814        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9815         msg.message);
9816     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9817
9818     qstatus = GetQueueStatus(qs_all_input);
9819     ok(qstatus == 0,
9820        "wrong qstatus %08x\n", qstatus);
9821
9822     /* test whether presence of the quit flag in the queue affects
9823      * the queue state
9824      */
9825     PostQuitMessage(0x1234abcd);
9826
9827     qstatus = GetQueueStatus(qs_all_input);
9828     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9829        "wrong qstatus %08x\n", qstatus);
9830
9831     PostMessageA(info.hwnd, WM_USER, 0, 0);
9832
9833     qstatus = GetQueueStatus(qs_all_input);
9834     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9835        "wrong qstatus %08x\n", qstatus);
9836
9837     msg.message = 0;
9838     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9839     ok(ret && msg.message == WM_USER,
9840        "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
9841     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9842
9843     qstatus = GetQueueStatus(qs_all_input);
9844     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9845        "wrong qstatus %08x\n", qstatus);
9846
9847     msg.message = 0;
9848     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9849     ok(ret && msg.message == WM_QUIT,
9850        "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
9851     ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
9852     ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
9853     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9854
9855     qstatus = GetQueueStatus(qs_all_input);
9856 todo_wine {
9857     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9858        "wrong qstatus %08x\n", qstatus);
9859 }
9860
9861     msg.message = 0;
9862     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9863     ok(!ret,
9864        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9865         msg.message);
9866     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9867
9868     qstatus = GetQueueStatus(qs_all_input);
9869     ok(qstatus == 0,
9870        "wrong qstatus %08x\n", qstatus);
9871
9872     /* some GetMessage tests */
9873
9874     keybd_event('N', 0, 0, 0);
9875     qstatus = GetQueueStatus(qs_all_input);
9876     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9877
9878     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9879     qstatus = GetQueueStatus(qs_all_input);
9880     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9881
9882     if (qstatus)
9883     {
9884         ret = GetMessageA( &msg, 0, 0, 0 );
9885         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9886            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9887            ret, msg.message, msg.wParam);
9888         qstatus = GetQueueStatus(qs_all_input);
9889         ok(qstatus == MAKELONG(0, QS_KEY), "wrong qstatus %08x\n", qstatus);
9890     }
9891
9892     if (qstatus)
9893     {
9894         ret = GetMessageA( &msg, 0, 0, 0 );
9895         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9896            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9897            ret, msg.message, msg.wParam);
9898         ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9899         qstatus = GetQueueStatus(qs_all_input);
9900         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9901     }
9902
9903     keybd_event('N', 0, 0, 0);
9904     qstatus = GetQueueStatus(qs_all_input);
9905     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9906
9907     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9908     qstatus = GetQueueStatus(qs_all_input);
9909     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9910
9911     if (qstatus & (QS_KEY << 16))
9912     {
9913         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9914         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9915            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9916            ret, msg.message, msg.wParam);
9917         ok_sequence(WmKeyDownWasDownSkippedSeq, "WmKeyDownWasDownSkippedSeq", FALSE);
9918         qstatus = GetQueueStatus(qs_all_input);
9919         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9920     }
9921
9922     if (qstatus)
9923     {
9924         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9925         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9926            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9927            ret, msg.message, msg.wParam);
9928         qstatus = GetQueueStatus(qs_all_input);
9929         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9930     }
9931
9932     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9933     qstatus = GetQueueStatus(qs_all_input);
9934     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9935
9936     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9937     qstatus = GetQueueStatus(qs_all_input);
9938     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9939
9940     trace("signalling to send message\n");
9941     SetEvent(info.hevent[EV_SENDMSG]);
9942     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9943     qstatus = GetQueueStatus(qs_all_input);
9944     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9945        "wrong qstatus %08x\n", qstatus);
9946
9947     if (qstatus & (QS_KEY << 16))
9948     {
9949         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9950         ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9951            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9952            ret, msg.message, msg.wParam);
9953         ok_sequence(WmUserKeyUpSkippedSeq, "WmUserKeyUpSkippedSeq", FALSE);
9954         qstatus = GetQueueStatus(qs_all_input);
9955         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9956     }
9957
9958     if (qstatus)
9959     {
9960         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9961         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9962            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9963            ret, msg.message, msg.wParam);
9964         qstatus = GetQueueStatus(qs_all_input);
9965         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9966     }
9967 done:
9968     trace("signalling to exit\n");
9969     SetEvent(info.hevent[EV_STOP]);
9970
9971     WaitForSingleObject(hthread, INFINITE);
9972
9973     CloseHandle(hthread);
9974     CloseHandle(info.hevent[0]);
9975     CloseHandle(info.hevent[1]);
9976     CloseHandle(info.hevent[2]);
9977
9978     DestroyWindow(info.hwnd);
9979 }
9980
9981 static void wait_move_event(HWND hwnd, int x, int y)
9982 {
9983     MSG msg;
9984     DWORD time;
9985     BOOL  ret;
9986     int go = 0;
9987
9988     time = GetTickCount();
9989     while (GetTickCount() - time < 200 && !go) {
9990         ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9991         go  = ret && msg.pt.x > x && msg.pt.y > y;
9992         if (!ret) MsgWaitForMultipleObjects( 0, NULL, FALSE, GetTickCount() - time, QS_ALLINPUT );
9993     }
9994 }
9995
9996 #define STEP 5
9997 static void test_PeekMessage2(void)
9998 {
9999     HWND hwnd;
10000     BOOL ret;
10001     MSG msg;
10002     UINT message;
10003     DWORD time1, time2, time3;
10004     int x1, y1, x2, y2, x3, y3;
10005     POINT pos;
10006
10007     time1 = time2 = time3 = 0;
10008     x1 = y1 = x2 = y2 = x3 = y3 = 0;
10009
10010     /* Initialise window and make sure it is ready for events */
10011     hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
10012                         10, 10, 800, 800, NULL, NULL, NULL, NULL);
10013     assert(hwnd);
10014     trace("Window for test_PeekMessage2 %p\n", hwnd);
10015     ShowWindow(hwnd, SW_SHOW);
10016     UpdateWindow(hwnd);
10017     SetFocus(hwnd);
10018     GetCursorPos(&pos);
10019     SetCursorPos(100, 100);
10020     mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
10021     flush_events();
10022
10023     /* Do initial mousemove, wait until we can see it
10024        and then do our test peek with PM_NOREMOVE. */
10025     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
10026     wait_move_event(hwnd, 100-STEP, 100-STEP);
10027
10028     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
10029     if (!ret)
10030     {
10031         skip( "queuing mouse events not supported\n" );
10032         goto done;
10033     }
10034     else
10035     {
10036         trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
10037         message = msg.message;
10038         time1 = msg.time;
10039         x1 = msg.pt.x;
10040         y1 = msg.pt.y;
10041         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
10042     }
10043
10044     /* Allow time to advance a bit, and then simulate the user moving their
10045      * mouse around. After that we peek again with PM_NOREMOVE.
10046      * Although the previous mousemove message was never removed, the
10047      * mousemove we now peek should reflect the recent mouse movements
10048      * because the input queue will merge the move events. */
10049     Sleep(100);
10050     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
10051     wait_move_event(hwnd, x1, y1);
10052
10053     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
10054     ok(ret, "no message available\n");
10055     if (ret) {
10056         trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
10057         message = msg.message;
10058         time2 = msg.time;
10059         x2 = msg.pt.x;
10060         y2 = msg.pt.y;
10061         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
10062         ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
10063         ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
10064     }
10065
10066     /* Have another go, to drive the point home */
10067     Sleep(100);
10068     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
10069     wait_move_event(hwnd, x2, y2);
10070
10071     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
10072     ok(ret, "no message available\n");
10073     if (ret) {
10074         trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
10075         message = msg.message;
10076         time3 = msg.time;
10077         x3 = msg.pt.x;
10078         y3 = msg.pt.y;
10079         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
10080         ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
10081         ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
10082     }
10083
10084 done:
10085     DestroyWindow(hwnd);
10086     SetCursorPos(pos.x, pos.y);
10087     flush_events();
10088 }
10089
10090 static INT_PTR CALLBACK wm_quit_dlg_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
10091 {
10092     struct recvd_message msg;
10093
10094     if (ignore_message( message )) return 0;
10095
10096     msg.hwnd = hwnd;
10097     msg.message = message;
10098     msg.flags = sent|wparam|lparam;
10099     msg.wParam = wp;
10100     msg.lParam = lp;
10101     msg.descr = "dialog";
10102     add_message(&msg);
10103
10104     switch (message)
10105     {
10106     case WM_INITDIALOG:
10107         PostMessage(hwnd, WM_QUIT, 0x1234, 0x5678);
10108         PostMessage(hwnd, WM_USER, 0xdead, 0xbeef);
10109         return 0;
10110
10111     case WM_GETDLGCODE:
10112         return 0;
10113
10114     case WM_USER:
10115         EndDialog(hwnd, 0);
10116         break;
10117     }
10118
10119     return 1;
10120 }
10121
10122 static const struct message WmQuitDialogSeq[] = {
10123     { HCBT_CREATEWND, hook },
10124     { WM_SETFONT, sent },
10125     { WM_INITDIALOG, sent },
10126     { WM_CHANGEUISTATE, sent|optional },
10127     { HCBT_DESTROYWND, hook },
10128     { 0x0090, sent|optional }, /* Vista */
10129     { WM_DESTROY, sent },
10130     { WM_NCDESTROY, sent },
10131     { 0 }
10132 };
10133
10134 static void test_quit_message(void)
10135 {
10136     MSG msg;
10137     BOOL ret;
10138
10139     /* test using PostQuitMessage */
10140     flush_events();
10141     PostQuitMessage(0xbeef);
10142
10143     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
10144     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
10145     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10146     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
10147
10148     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
10149     ok(ret, "PostMessage failed with error %d\n", GetLastError());
10150
10151     ret = GetMessage(&msg, NULL, 0, 0);
10152     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
10153     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
10154
10155     /* note: WM_QUIT message received after WM_USER message */
10156     ret = GetMessage(&msg, NULL, 0, 0);
10157     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
10158     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10159     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
10160
10161     ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
10162     ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
10163
10164     /* now test with PostThreadMessage - different behaviour! */
10165     PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
10166
10167     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
10168     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
10169     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10170     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
10171
10172     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
10173     ok(ret, "PostMessage failed with error %d\n", GetLastError());
10174
10175     /* note: we receive the WM_QUIT message first this time */
10176     ret = GetMessage(&msg, NULL, 0, 0);
10177     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
10178     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10179     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
10180
10181     ret = GetMessage(&msg, NULL, 0, 0);
10182     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
10183     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
10184
10185     flush_events();
10186     flush_sequence();
10187     ret = DialogBoxParam(GetModuleHandle(0), "TEST_EMPTY_DIALOG", 0, wm_quit_dlg_proc, 0);
10188     ok(ret == 1, "expected 1, got %d\n", ret);
10189     ok_sequence(WmQuitDialogSeq, "WmQuitDialogSeq", FALSE);
10190     memset(&msg, 0xab, sizeof(msg));
10191     ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
10192     ok(ret, "PeekMessage failed\n");
10193     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10194     ok(msg.wParam == 0x1234, "wParam was 0x%lx instead of 0x1234\n", msg.wParam);
10195     ok(msg.lParam == 0, "lParam was 0x%lx instead of 0\n", msg.lParam);
10196 }
10197
10198 static const struct message WmMouseHoverSeq[] = {
10199     { WM_MOUSEACTIVATE, sent|optional },  /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
10200     { WM_MOUSEACTIVATE, sent|optional },
10201     { WM_TIMER, sent|optional }, /* XP sends it */
10202     { WM_SYSTIMER, sent },
10203     { WM_MOUSEHOVER, sent|wparam, 0 },
10204     { 0 }
10205 };
10206
10207 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
10208 {
10209     MSG msg;
10210     DWORD start_ticks, end_ticks;
10211
10212     start_ticks = GetTickCount();
10213     /* add some deviation (50%) to cover not expected delays */
10214     start_ticks += timeout / 2;
10215
10216     do
10217     {
10218         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
10219         {
10220             /* Timer proc messages are not dispatched to the window proc,
10221              * and therefore not logged.
10222              */
10223             if ((msg.message == WM_TIMER || msg.message == WM_SYSTIMER) && msg.hwnd)
10224             {
10225                 struct recvd_message s_msg;
10226
10227                 s_msg.hwnd = msg.hwnd;
10228                 s_msg.message = msg.message;
10229                 s_msg.flags = sent|wparam|lparam;
10230                 s_msg.wParam = msg.wParam;
10231                 s_msg.lParam = msg.lParam;
10232                 s_msg.descr = "msg_loop";
10233                 add_message(&s_msg);
10234             }
10235             DispatchMessage(&msg);
10236         }
10237
10238         end_ticks = GetTickCount();
10239
10240         /* inject WM_MOUSEMOVE to see how it changes tracking */
10241         if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
10242         {
10243             mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
10244             mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
10245
10246             inject_mouse_move = FALSE;
10247         }
10248     } while (start_ticks + timeout >= end_ticks);
10249 }
10250
10251 static void test_TrackMouseEvent(void)
10252 {
10253     TRACKMOUSEEVENT tme;
10254     BOOL ret;
10255     HWND hwnd, hchild;
10256     RECT rc_parent, rc_child;
10257     UINT default_hover_time, hover_width = 0, hover_height = 0;
10258
10259 #define track_hover(track_hwnd, track_hover_time) \
10260     tme.cbSize = sizeof(tme); \
10261     tme.dwFlags = TME_HOVER; \
10262     tme.hwndTrack = track_hwnd; \
10263     tme.dwHoverTime = track_hover_time; \
10264     SetLastError(0xdeadbeef); \
10265     ret = pTrackMouseEvent(&tme); \
10266     ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
10267
10268 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
10269     tme.cbSize = sizeof(tme); \
10270     tme.dwFlags = TME_QUERY; \
10271     tme.hwndTrack = (HWND)0xdeadbeef; \
10272     tme.dwHoverTime = 0xdeadbeef; \
10273     SetLastError(0xdeadbeef); \
10274     ret = pTrackMouseEvent(&tme); \
10275     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
10276     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
10277     ok(tme.dwFlags == (expected_track_flags), \
10278        "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
10279     ok(tme.hwndTrack == (expected_track_hwnd), \
10280        "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
10281     ok(tme.dwHoverTime == (expected_hover_time), \
10282        "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
10283
10284 #define track_hover_cancel(track_hwnd) \
10285     tme.cbSize = sizeof(tme); \
10286     tme.dwFlags = TME_HOVER | TME_CANCEL; \
10287     tme.hwndTrack = track_hwnd; \
10288     tme.dwHoverTime = 0xdeadbeef; \
10289     SetLastError(0xdeadbeef); \
10290     ret = pTrackMouseEvent(&tme); \
10291     ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
10292
10293     default_hover_time = 0xdeadbeef;
10294     SetLastError(0xdeadbeef);
10295     ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
10296     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
10297        "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
10298     if (!ret) default_hover_time = 400;
10299     trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
10300
10301     SetLastError(0xdeadbeef);
10302     ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
10303     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
10304        "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
10305     if (!ret) hover_width = 4;
10306     SetLastError(0xdeadbeef);
10307     ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
10308     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
10309        "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
10310     if (!ret) hover_height = 4;
10311     trace("hover rect is %u x %d\n", hover_width, hover_height);
10312
10313     hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
10314                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10315                           CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
10316                           NULL, NULL, 0);
10317     assert(hwnd);
10318
10319     hchild = CreateWindowEx(0, "TestWindowClass", NULL,
10320                           WS_CHILD | WS_BORDER | WS_VISIBLE,
10321                           50, 50, 200, 200, hwnd,
10322                           NULL, NULL, 0);
10323     assert(hchild);
10324
10325     SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
10326     flush_events();
10327     flush_sequence();
10328
10329     tme.cbSize = 0;
10330     tme.dwFlags = TME_QUERY;
10331     tme.hwndTrack = (HWND)0xdeadbeef;
10332     tme.dwHoverTime = 0xdeadbeef;
10333     SetLastError(0xdeadbeef);
10334     ret = pTrackMouseEvent(&tme);
10335     ok(!ret, "TrackMouseEvent should fail\n");
10336     ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef),
10337        "not expected error %u\n", GetLastError());
10338
10339     tme.cbSize = sizeof(tme);
10340     tme.dwFlags = TME_HOVER;
10341     tme.hwndTrack = (HWND)0xdeadbeef;
10342     tme.dwHoverTime = 0xdeadbeef;
10343     SetLastError(0xdeadbeef);
10344     ret = pTrackMouseEvent(&tme);
10345     ok(!ret, "TrackMouseEvent should fail\n");
10346     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10347        "not expected error %u\n", GetLastError());
10348
10349     tme.cbSize = sizeof(tme);
10350     tme.dwFlags = TME_HOVER | TME_CANCEL;
10351     tme.hwndTrack = (HWND)0xdeadbeef;
10352     tme.dwHoverTime = 0xdeadbeef;
10353     SetLastError(0xdeadbeef);
10354     ret = pTrackMouseEvent(&tme);
10355     ok(!ret, "TrackMouseEvent should fail\n");
10356     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10357        "not expected error %u\n", GetLastError());
10358
10359     GetWindowRect(hwnd, &rc_parent);
10360     GetWindowRect(hchild, &rc_child);
10361     SetCursorPos(rc_child.left - 10, rc_child.top - 10);
10362
10363     /* Process messages so that the system updates its internal current
10364      * window and hittest, otherwise TrackMouseEvent calls don't have any
10365      * effect.
10366      */
10367     flush_events();
10368     flush_sequence();
10369
10370     track_query(0, NULL, 0);
10371     track_hover(hchild, 0);
10372     track_query(0, NULL, 0);
10373
10374     flush_events();
10375     flush_sequence();
10376
10377     track_hover(hwnd, 0);
10378     tme.cbSize = sizeof(tme);
10379     tme.dwFlags = TME_QUERY;
10380     tme.hwndTrack = (HWND)0xdeadbeef;
10381     tme.dwHoverTime = 0xdeadbeef;
10382     SetLastError(0xdeadbeef);
10383     ret = pTrackMouseEvent(&tme);
10384     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());
10385     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize);
10386     if (!tme.dwFlags)
10387     {
10388         skip( "Cursor not inside window, skipping TrackMouseEvent tests\n" );
10389         DestroyWindow( hwnd );
10390         return;
10391     }
10392     ok(tme.dwFlags == TME_HOVER, "wrong tme.dwFlags %08x, expected TME_HOVER\n", tme.dwFlags);
10393     ok(tme.hwndTrack == hwnd, "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, hwnd);
10394     ok(tme.dwHoverTime == default_hover_time, "wrong tme.dwHoverTime %u, expected %u\n",
10395        tme.dwHoverTime, default_hover_time);
10396
10397     pump_msg_loop_timeout(default_hover_time, FALSE);
10398     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10399
10400     track_query(0, NULL, 0);
10401
10402     track_hover(hwnd, HOVER_DEFAULT);
10403     track_query(TME_HOVER, hwnd, default_hover_time);
10404
10405     Sleep(default_hover_time / 2);
10406     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
10407     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
10408
10409     track_query(TME_HOVER, hwnd, default_hover_time);
10410
10411     pump_msg_loop_timeout(default_hover_time, FALSE);
10412     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10413
10414     track_query(0, NULL, 0);
10415
10416     track_hover(hwnd, HOVER_DEFAULT);
10417     track_query(TME_HOVER, hwnd, default_hover_time);
10418
10419     pump_msg_loop_timeout(default_hover_time, TRUE);
10420     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10421
10422     track_query(0, NULL, 0);
10423
10424     track_hover(hwnd, HOVER_DEFAULT);
10425     track_query(TME_HOVER, hwnd, default_hover_time);
10426     track_hover_cancel(hwnd);
10427
10428     DestroyWindow(hwnd);
10429
10430 #undef track_hover
10431 #undef track_query
10432 #undef track_hover_cancel
10433 }
10434
10435
10436 static const struct message WmSetWindowRgn[] = {
10437     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10438     { WM_NCCALCSIZE, sent|wparam, 1 },
10439     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
10440     { WM_GETTEXT, sent|defwinproc|optional },
10441     { WM_ERASEBKGND, sent|optional },
10442     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10443     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10444     { 0 }
10445 };
10446
10447 static const struct message WmSetWindowRgn_no_redraw[] = {
10448     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10449     { WM_NCCALCSIZE, sent|wparam, 1 },
10450     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10451     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10452     { 0 }
10453 };
10454
10455 static const struct message WmSetWindowRgn_clear[] = {
10456     { WM_WINDOWPOSCHANGING, sent/*|wparam*/, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE/*|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE only on some Windows versions */ },
10457     { WM_NCCALCSIZE, sent|wparam, 1 },
10458     { WM_NCPAINT, sent|optional },
10459     { WM_GETTEXT, sent|defwinproc|optional },
10460     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
10461     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10462     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
10463     { WM_NCPAINT, sent|optional },
10464     { WM_GETTEXT, sent|defwinproc|optional },
10465     { WM_ERASEBKGND, sent|optional },
10466     { WM_WINDOWPOSCHANGING, sent|optional },
10467     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10468     { WM_NCPAINT, sent|optional },
10469     { WM_GETTEXT, sent|defwinproc|optional },
10470     { WM_ERASEBKGND, sent|optional },
10471     { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10472     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10473     { WM_NCPAINT, sent|optional },
10474     { WM_GETTEXT, sent|defwinproc|optional },
10475     { WM_ERASEBKGND, sent|optional },
10476     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10477     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10478     { 0 }
10479 };
10480
10481 static void test_SetWindowRgn(void)
10482 {
10483     HRGN hrgn;
10484     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10485                                 100, 100, 200, 200, 0, 0, 0, NULL);
10486     ok( hwnd != 0, "Failed to create overlapped window\n" );
10487
10488     ShowWindow( hwnd, SW_SHOW );
10489     UpdateWindow( hwnd );
10490     flush_events();
10491     flush_sequence();
10492
10493     trace("testing SetWindowRgn\n");
10494     hrgn = CreateRectRgn( 0, 0, 150, 150 );
10495     SetWindowRgn( hwnd, hrgn, TRUE );
10496     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
10497
10498     hrgn = CreateRectRgn( 30, 30, 160, 160 );
10499     SetWindowRgn( hwnd, hrgn, FALSE );
10500     ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
10501
10502     hrgn = CreateRectRgn( 0, 0, 180, 180 );
10503     SetWindowRgn( hwnd, hrgn, TRUE );
10504     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
10505
10506     SetWindowRgn( hwnd, 0, TRUE );
10507     ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
10508
10509     DestroyWindow( hwnd );
10510 }
10511
10512 /*************************** ShowWindow() test ******************************/
10513 static const struct message WmShowNormal[] = {
10514     { WM_SHOWWINDOW, sent|wparam, 1 },
10515     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10516     { HCBT_ACTIVATE, hook },
10517     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10518     { HCBT_SETFOCUS, hook },
10519     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10520     { 0 }
10521 };
10522 static const struct message WmShow[] = {
10523     { WM_SHOWWINDOW, sent|wparam, 1 },
10524     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10525     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10526     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10527     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10528     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10529     { 0 }
10530 };
10531 static const struct message WmShowNoActivate_1[] = {
10532     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10533     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10534     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10535     { WM_MOVE, sent|defwinproc|optional },
10536     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10537     { 0 }
10538 };
10539 static const struct message WmShowNoActivate_2[] = {
10540     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10541     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10542     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10543     { WM_MOVE, sent|defwinproc },
10544     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10545     { HCBT_SETFOCUS, hook|optional },
10546     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10547     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10548     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10549     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10550     { 0 }
10551 };
10552 static const struct message WmShowNA_1[] = {
10553     { WM_SHOWWINDOW, sent|wparam, 1 },
10554     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10555     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10556     { 0 }
10557 };
10558 static const struct message WmShowNA_2[] = {
10559     { WM_SHOWWINDOW, sent|wparam, 1 },
10560     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10561     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10562     { 0 }
10563 };
10564 static const struct message WmRestore_1[] = {
10565     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10566     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10567     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10568     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10569     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10570     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10571     { WM_MOVE, sent|defwinproc },
10572     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10573     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10574     { 0 }
10575 };
10576 static const struct message WmRestore_2[] = {
10577     { WM_SHOWWINDOW, sent|wparam, 1 },
10578     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10579     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10580     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10581     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10582     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10583     { 0 }
10584 };
10585 static const struct message WmRestore_3[] = {
10586     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10587     { WM_GETMINMAXINFO, sent },
10588     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10589     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10590     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10591     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10592     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10593     { WM_MOVE, sent|defwinproc },
10594     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10595     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10596     { 0 }
10597 };
10598 static const struct message WmRestore_4[] = {
10599     { HCBT_MINMAX, hook|lparam|optional, 0, SW_RESTORE },
10600     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10601     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10602     { WM_MOVE, sent|defwinproc|optional },
10603     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10604     { 0 }
10605 };
10606 static const struct message WmRestore_5[] = {
10607     { HCBT_MINMAX, hook|lparam|optional, 0, SW_SHOWNORMAL },
10608     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10609     { HCBT_ACTIVATE, hook|optional },
10610     { HCBT_SETFOCUS, hook|optional },
10611     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10612     { WM_MOVE, sent|defwinproc|optional },
10613     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10614     { 0 }
10615 };
10616 static const struct message WmHide_1[] = {
10617     { WM_SHOWWINDOW, sent|wparam, 0 },
10618     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOACTIVATE },
10619     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOACTIVATE },
10620     { HCBT_ACTIVATE, hook|optional },
10621     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10622     { 0 }
10623 };
10624 static const struct message WmHide_2[] = {
10625     { WM_SHOWWINDOW, sent|wparam, 0 },
10626     { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10627     { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10628     { HCBT_ACTIVATE, hook|optional },
10629     { 0 }
10630 };
10631 static const struct message WmHide_3[] = {
10632     { WM_SHOWWINDOW, sent|wparam, 0 },
10633     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10634     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10635     { HCBT_SETFOCUS, hook|optional },
10636     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10637     { 0 }
10638 };
10639 static const struct message WmShowMinimized_1[] = {
10640     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10641     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10642     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10643     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10644     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10645     { WM_MOVE, sent|defwinproc },
10646     { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10647     { 0 }
10648 };
10649 static const struct message WmMinimize_1[] = {
10650     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10651     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10652     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10653     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10654     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10655     { WM_MOVE, sent|defwinproc },
10656     { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10657     { 0 }
10658 };
10659 static const struct message WmMinimize_2[] = {
10660     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10661     { HCBT_SETFOCUS, hook|optional },
10662     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10663     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10664     { WM_MOVE, sent|defwinproc },
10665     { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10666     { 0 }
10667 };
10668 static const struct message WmMinimize_3[] = {
10669     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10670     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10671     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10672     { WM_MOVE, sent|defwinproc },
10673     { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10674     { 0 }
10675 };
10676 static const struct message WmShowMinNoActivate[] = {
10677     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10678     { WM_WINDOWPOSCHANGING, sent },
10679     { WM_WINDOWPOSCHANGED, sent },
10680     { WM_MOVE, sent|defwinproc|optional },
10681     { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
10682     { 0 }
10683 };
10684 static const struct message WmMinMax_1[] = {
10685     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10686     { 0 }
10687 };
10688 static const struct message WmMinMax_2[] = {
10689     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10690     { WM_GETMINMAXINFO, sent|optional },
10691     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED },
10692     { HCBT_ACTIVATE, hook|optional },
10693     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10694     { HCBT_SETFOCUS, hook|optional },
10695     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10696     { WM_MOVE, sent|defwinproc|optional },
10697     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MAXIMIZED },
10698     { HCBT_SETFOCUS, hook|optional },
10699     { 0 }
10700 };
10701 static const struct message WmMinMax_3[] = {
10702     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10703     { HCBT_SETFOCUS, hook|optional },
10704     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10705     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10706     { WM_MOVE, sent|defwinproc|optional },
10707     { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
10708     { 0 }
10709 };
10710 static const struct message WmMinMax_4[] = {
10711     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10712     { 0 }
10713 };
10714 static const struct message WmShowMaximized_1[] = {
10715     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10716     { WM_GETMINMAXINFO, sent },
10717     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10718     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10719     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10720     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10721     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10722     { WM_MOVE, sent|defwinproc },
10723     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10724     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10725     { 0 }
10726 };
10727 static const struct message WmShowMaximized_2[] = {
10728     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10729     { WM_GETMINMAXINFO, sent },
10730     { WM_WINDOWPOSCHANGING, sent|optional },
10731     { HCBT_ACTIVATE, hook|optional },
10732     { WM_WINDOWPOSCHANGED, sent|optional },
10733     { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
10734     { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
10735     { WM_WINDOWPOSCHANGING, sent|optional },
10736     { HCBT_SETFOCUS, hook|optional },
10737     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10738     { WM_MOVE, sent|defwinproc },
10739     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10740     { HCBT_SETFOCUS, hook|optional },
10741     { 0 }
10742 };
10743 static const struct message WmShowMaximized_3[] = {
10744     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10745     { WM_GETMINMAXINFO, sent|optional },
10746     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10747     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10748     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10749     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10750     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10751     { WM_MOVE, sent|defwinproc|optional },
10752     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10753     { 0 }
10754 };
10755
10756 static void test_ShowWindow(void)
10757 {
10758     /* ShowWindow commands in random order */
10759     static const struct
10760     {
10761         INT cmd; /* ShowWindow command */
10762         LPARAM ret; /* ShowWindow return value */
10763         DWORD style; /* window style after the command */
10764         const struct message *msg; /* message sequence the command produces */
10765         INT wp_cmd, wp_flags; /* window placement after the command */
10766         POINT wp_min, wp_max; /* window placement after the command */
10767         BOOL todo_msg; /* message sequence doesn't match what Wine does */
10768     } sw[] =
10769     {
10770 /*  1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal,
10771            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10772 /*  2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq,
10773            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10774 /*  3 */ { SW_HIDE, TRUE, 0, WmHide_1,
10775            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10776 /*  4 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10777            SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10778 /*  5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1,
10779            SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10780 /*  6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1,
10781            SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10782 /*  7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1,
10783            SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10784 /*  8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq,
10785            SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10786 /*  9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1,
10787            SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10788 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2,
10789            SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10790 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1,
10791            SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10792 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq,
10793            SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10794 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1,
10795            SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10796 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq,
10797            SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10798 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2,
10799            SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10800 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10801            SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10802 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow,
10803            SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10804 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq,
10805            SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10806 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1,
10807            SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10808 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3,
10809            SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10810 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
10811            SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10812 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate,
10813            SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, TRUE },
10814 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4,
10815            SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10816 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
10817            SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10818 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq,
10819            SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10820 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1,
10821            SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10822 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2,
10823            SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10824 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
10825            SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10826 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq,
10827            SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10828 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1,
10829            SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10830 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq,
10831            SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10832 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3,
10833            SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10834 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10835            SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10836 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, /* what does this mean?! */
10837            SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10838 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq,
10839            SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10840 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10841            SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10842 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2,
10843            SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10844 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq,
10845            SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10846 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq,
10847            SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10848 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2,
10849            SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10850 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3,
10851            SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10852 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2,
10853            SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10854 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2,
10855            SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10856 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1,
10857            SW_SHOWMINIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10858 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3,
10859            SW_SHOWMINIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10860 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3,
10861            SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10862 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4,
10863            SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10864 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3,
10865            SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10866 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq,
10867            SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10868 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5,
10869            SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10870 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5,
10871            SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10872 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1,
10873            SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10874 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10875            SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10876 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3,
10877            SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10878 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
10879            SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10880 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2,
10881            SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10882 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq,
10883            SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE }
10884     };
10885     HWND hwnd;
10886     DWORD style;
10887     LPARAM ret;
10888     INT i;
10889     WINDOWPLACEMENT wp;
10890     RECT win_rc, work_rc = {0, 0, 0, 0};
10891
10892 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
10893     hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
10894                           120, 120, 90, 90,
10895                           0, 0, 0, NULL);
10896     assert(hwnd);
10897
10898     style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10899     ok(style == 0, "expected style 0, got %08x\n", style);
10900
10901     flush_events();
10902     flush_sequence();
10903
10904     if (pGetMonitorInfoA && pMonitorFromPoint)
10905     {
10906         HMONITOR hmon;
10907         MONITORINFO mi;
10908         POINT pt = {0, 0};
10909
10910         SetLastError(0xdeadbeef);
10911         hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
10912         ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
10913
10914         mi.cbSize = sizeof(mi);
10915         SetLastError(0xdeadbeef);
10916         ret = pGetMonitorInfoA(hmon, &mi);
10917         ok(ret, "GetMonitorInfo error %u\n", GetLastError());
10918         trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
10919             mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
10920             mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
10921         work_rc = mi.rcWork;
10922     }
10923
10924     GetWindowRect(hwnd, &win_rc);
10925     OffsetRect(&win_rc, -work_rc.left, -work_rc.top);
10926
10927     wp.length = sizeof(wp);
10928     SetLastError(0xdeadbeaf);
10929     ret = GetWindowPlacement(hwnd, &wp);
10930     ok(ret, "GetWindowPlacement error %u\n", GetLastError());
10931     ok(wp.flags == 0, "expected 0, got %#x\n", wp.flags);
10932     ok(wp.showCmd == SW_SHOWNORMAL, "expected SW_SHOWNORMAL, got %d\n", wp.showCmd);
10933     ok(wp.ptMinPosition.x == -1 && wp.ptMinPosition.y == -1,
10934        "expected -1,-1 got %d,%d\n", wp.ptMinPosition.x, wp.ptMinPosition.y);
10935     ok(wp.ptMaxPosition.x == -1 && wp.ptMaxPosition.y == -1,
10936        "expected -1,-1 got %d,%d\n", wp.ptMaxPosition.x, wp.ptMaxPosition.y);
10937     if (work_rc.left || work_rc.top) todo_wine /* FIXME: remove once Wine is fixed */
10938     ok(EqualRect(&win_rc, &wp.rcNormalPosition),
10939        "expected %d,%d-%d,%d got %d,%d-%d,%d\n",
10940         win_rc.left, win_rc.top, win_rc.right, win_rc.bottom,
10941         wp.rcNormalPosition.left, wp.rcNormalPosition.top,
10942         wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
10943     else
10944     ok(EqualRect(&win_rc, &wp.rcNormalPosition),
10945        "expected %d,%d-%d,%d got %d,%d-%d,%d\n",
10946         win_rc.left, win_rc.top, win_rc.right, win_rc.bottom,
10947         wp.rcNormalPosition.left, wp.rcNormalPosition.top,
10948         wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
10949
10950     for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
10951     {
10952         static const char * const sw_cmd_name[13] =
10953         {
10954             "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
10955             "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
10956             "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
10957             "SW_NORMALNA" /* 0xCC */
10958         };
10959         char comment[64];
10960         INT idx; /* index into the above array of names */
10961
10962         idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
10963
10964         style = GetWindowLong(hwnd, GWL_STYLE);
10965         trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
10966         ret = ShowWindow(hwnd, sw[i].cmd);
10967         ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
10968         style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10969         ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
10970
10971         sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
10972         ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
10973
10974         wp.length = sizeof(wp);
10975         SetLastError(0xdeadbeaf);
10976         ret = GetWindowPlacement(hwnd, &wp);
10977         ok(ret, "GetWindowPlacement error %u\n", GetLastError());
10978         ok(wp.flags == sw[i].wp_flags, "expected %#x, got %#x\n", sw[i].wp_flags, wp.flags);
10979         ok(wp.showCmd == sw[i].wp_cmd, "expected %d, got %d\n", sw[i].wp_cmd, wp.showCmd);
10980
10981         /* NT moves the minimized window to -32000,-32000, win9x to 3000,3000 */
10982         if ((wp.ptMinPosition.x + work_rc.left == -32000 && wp.ptMinPosition.y + work_rc.top == -32000) ||
10983             (wp.ptMinPosition.x + work_rc.left == 3000 && wp.ptMinPosition.y + work_rc.top == 3000))
10984         {
10985             ok((wp.ptMinPosition.x + work_rc.left == sw[i].wp_min.x && wp.ptMinPosition.y + work_rc.top == sw[i].wp_min.y) ||
10986                (wp.ptMinPosition.x + work_rc.left == 3000 && wp.ptMinPosition.y + work_rc.top == 3000),
10987                "expected %d,%d got %d,%d\n", sw[i].wp_min.x, sw[i].wp_min.y, wp.ptMinPosition.x, wp.ptMinPosition.y);
10988         }
10989         else
10990         {
10991             if (wp.ptMinPosition.x != sw[i].wp_min.x || wp.ptMinPosition.y != sw[i].wp_min.y)
10992             todo_wine
10993             ok(wp.ptMinPosition.x == sw[i].wp_min.x && wp.ptMinPosition.y == sw[i].wp_min.y,
10994                "expected %d,%d got %d,%d\n", sw[i].wp_min.x, sw[i].wp_min.y, wp.ptMinPosition.x, wp.ptMinPosition.y);
10995             else
10996             ok(wp.ptMinPosition.x == sw[i].wp_min.x && wp.ptMinPosition.y == sw[i].wp_min.y,
10997                "expected %d,%d got %d,%d\n", sw[i].wp_min.x, sw[i].wp_min.y, wp.ptMinPosition.x, wp.ptMinPosition.y);
10998         }
10999
11000         if (wp.ptMaxPosition.x != sw[i].wp_max.x || wp.ptMaxPosition.y != sw[i].wp_max.y)
11001         todo_wine
11002         ok(wp.ptMaxPosition.x == sw[i].wp_max.x && wp.ptMaxPosition.y == sw[i].wp_max.y,
11003            "expected %d,%d got %d,%d\n", sw[i].wp_max.x, sw[i].wp_max.y, wp.ptMaxPosition.x, wp.ptMaxPosition.y);
11004         else
11005         ok(wp.ptMaxPosition.x == sw[i].wp_max.x && wp.ptMaxPosition.y == sw[i].wp_max.y,
11006            "expected %d,%d got %d,%d\n", sw[i].wp_max.x, sw[i].wp_max.y, wp.ptMaxPosition.x, wp.ptMaxPosition.y);
11007
11008 if (0) /* FIXME: Wine behaves completely different here */
11009         ok(EqualRect(&win_rc, &wp.rcNormalPosition),
11010            "expected %d,%d-%d,%d got %d,%d-%d,%d\n",
11011             win_rc.left, win_rc.top, win_rc.right, win_rc.bottom,
11012             wp.rcNormalPosition.left, wp.rcNormalPosition.top,
11013             wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
11014
11015         flush_events();
11016         flush_sequence();
11017     }
11018
11019     DestroyWindow(hwnd);
11020 }
11021
11022 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
11023 {
11024     struct recvd_message msg;
11025
11026     if (ignore_message( message )) return 0;
11027
11028     msg.hwnd = hwnd;
11029     msg.message = message;
11030     msg.flags = sent|wparam|lparam;
11031     msg.wParam = wParam;
11032     msg.lParam = lParam;
11033     msg.descr = "dialog";
11034     add_message(&msg);
11035
11036     /* calling DefDlgProc leads to a recursion under XP */
11037
11038     switch (message)
11039     {
11040     case WM_INITDIALOG:
11041     case WM_GETDLGCODE:
11042         return 0;
11043     }
11044     return 1;
11045 }
11046
11047 static const struct message WmDefDlgSetFocus_1[] = {
11048     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
11049     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
11050     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
11051     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
11052     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
11053     { HCBT_SETFOCUS, hook },
11054     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
11055     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11056     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
11057     { WM_SETFOCUS, sent|wparam, 0 },
11058     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
11059     { WM_CTLCOLOREDIT, sent },
11060     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
11061     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11062     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11063     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11064     { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
11065     { 0 }
11066 };
11067 static const struct message WmDefDlgSetFocus_2[] = {
11068     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
11069     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
11070     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
11071     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
11072     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
11073     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11074     { WM_CTLCOLOREDIT, sent|optional }, /* XP */
11075     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11076     { 0 }
11077 };
11078 /* Creation of a dialog */
11079 static const struct message WmCreateDialogParamSeq_1[] = {
11080     { HCBT_CREATEWND, hook },
11081     { WM_NCCREATE, sent },
11082     { WM_NCCALCSIZE, sent|wparam, 0 },
11083     { WM_CREATE, sent },
11084     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
11085     { WM_SIZE, sent|wparam, SIZE_RESTORED },
11086     { WM_MOVE, sent },
11087     { WM_SETFONT, sent },
11088     { WM_INITDIALOG, sent },
11089     { WM_CHANGEUISTATE, sent|optional },
11090     { 0 }
11091 };
11092 /* Creation of a dialog */
11093 static const struct message WmCreateDialogParamSeq_2[] = {
11094     { HCBT_CREATEWND, hook },
11095     { WM_NCCREATE, sent },
11096     { WM_NCCALCSIZE, sent|wparam, 0 },
11097     { WM_CREATE, sent },
11098     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
11099     { WM_SIZE, sent|wparam, SIZE_RESTORED },
11100     { WM_MOVE, sent },
11101     { WM_CHANGEUISTATE, sent|optional },
11102     { 0 }
11103 };
11104
11105 static void test_dialog_messages(void)
11106 {
11107     WNDCLASS cls;
11108     HWND hdlg, hedit1, hedit2, hfocus;
11109     LRESULT ret;
11110
11111 #define set_selection(hctl, start, end) \
11112     ret = SendMessage(hctl, EM_SETSEL, start, end); \
11113     ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
11114
11115 #define check_selection(hctl, start, end) \
11116     ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
11117     ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
11118
11119     subclass_edit();
11120
11121     hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
11122                           WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
11123                           0, 0, 100, 100, 0, 0, 0, NULL);
11124     ok(hdlg != 0, "Failed to create custom dialog window\n");
11125
11126     hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
11127                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
11128                            0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
11129     ok(hedit1 != 0, "Failed to create edit control\n");
11130     hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
11131                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
11132                            0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
11133     ok(hedit2 != 0, "Failed to create edit control\n");
11134
11135     SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
11136     SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
11137
11138     hfocus = GetFocus();
11139     ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
11140
11141     SetFocus(hedit2);
11142     hfocus = GetFocus();
11143     ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
11144
11145     check_selection(hedit1, 0, 0);
11146     check_selection(hedit2, 0, 0);
11147
11148     set_selection(hedit2, 0, -1);
11149     check_selection(hedit2, 0, 3);
11150
11151     SetFocus(0);
11152     hfocus = GetFocus();
11153     ok(hfocus == 0, "wrong focus %p\n", hfocus);
11154
11155     flush_sequence();
11156     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
11157     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
11158     ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
11159
11160     hfocus = GetFocus();
11161     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
11162
11163     check_selection(hedit1, 0, 5);
11164     check_selection(hedit2, 0, 3);
11165
11166     flush_sequence();
11167     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
11168     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
11169     ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
11170
11171     hfocus = GetFocus();
11172     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
11173
11174     check_selection(hedit1, 0, 5);
11175     check_selection(hedit2, 0, 3);
11176
11177     EndDialog(hdlg, 0);
11178     DestroyWindow(hedit1);
11179     DestroyWindow(hedit2);
11180     DestroyWindow(hdlg);
11181     flush_sequence();
11182
11183 #undef set_selection
11184 #undef check_selection
11185
11186     ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
11187     cls.lpszClassName = "MyDialogClass";
11188     cls.hInstance = GetModuleHandle(0);
11189     /* need a cast since a dlgproc is used as a wndproc */
11190     cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
11191     if (!RegisterClass(&cls)) assert(0);
11192
11193     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
11194     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
11195     ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
11196     EndDialog(hdlg, 0);
11197     DestroyWindow(hdlg);
11198     flush_sequence();
11199
11200     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
11201     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
11202     ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
11203     EndDialog(hdlg, 0);
11204     DestroyWindow(hdlg);
11205     flush_sequence();
11206
11207     UnregisterClass(cls.lpszClassName, cls.hInstance);
11208 }
11209
11210 static void test_nullCallback(void)
11211 {
11212     HWND hwnd;
11213
11214     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
11215                            100, 100, 200, 200, 0, 0, 0, NULL);
11216     ok (hwnd != 0, "Failed to create overlapped window\n");
11217
11218     SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
11219     flush_events();
11220     DestroyWindow(hwnd);
11221 }
11222
11223 /* SetActiveWindow( 0 ) hwnd visible */
11224 static const struct message SetActiveWindowSeq0[] =
11225 {
11226     { HCBT_ACTIVATE, hook|optional },
11227     { WM_NCACTIVATE, sent|wparam, 0 },
11228     { WM_GETTEXT, sent|defwinproc|optional },
11229     { WM_ACTIVATE, sent|wparam, 0 },
11230     { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
11231     { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
11232     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11233     { WM_KILLFOCUS, sent|optional },
11234     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11235     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
11236     { WM_NCACTIVATE, sent|wparam|optional, 1 },
11237     { WM_GETTEXT, sent|defwinproc|optional },
11238     { WM_ACTIVATE, sent|wparam|optional, 1 },
11239     { HCBT_SETFOCUS, hook|optional },
11240     { WM_KILLFOCUS, sent|defwinproc|optional },
11241     { WM_IME_SETCONTEXT, sent|defwinproc|optional },
11242     { WM_IME_SETCONTEXT, sent|defwinproc|optional },
11243     { WM_IME_SETCONTEXT, sent|optional },
11244     { WM_IME_SETCONTEXT, sent|optional },
11245     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
11246     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11247     { WM_SETFOCUS, sent|defwinproc|optional },
11248     { WM_GETTEXT, sent|optional },
11249     { 0 }
11250 };
11251 /* SetActiveWindow( hwnd ) hwnd visible */
11252 static const struct message SetActiveWindowSeq1[] =
11253 {
11254     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11255     { 0 }
11256 };
11257 /* SetActiveWindow( popup ) hwnd visible, popup visible */
11258 static const struct message SetActiveWindowSeq2[] =
11259 {
11260     { HCBT_ACTIVATE, hook },
11261     { WM_NCACTIVATE, sent|wparam, 0 },
11262     { WM_GETTEXT, sent|defwinproc|optional },
11263     { WM_ACTIVATE, sent|wparam, 0 },
11264     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11265     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
11266     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11267     { WM_NCPAINT, sent|optional },
11268     { WM_GETTEXT, sent|defwinproc|optional },
11269     { WM_ERASEBKGND, sent|optional },
11270     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11271     { WM_NCACTIVATE, sent|wparam, 1 },
11272     { WM_GETTEXT, sent|defwinproc|optional },
11273     { WM_ACTIVATE, sent|wparam, 1 },
11274     { HCBT_SETFOCUS, hook },
11275     { WM_KILLFOCUS, sent|defwinproc },
11276     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
11277     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11278     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
11279     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11280     { WM_SETFOCUS, sent|defwinproc },
11281     { WM_GETTEXT, sent|optional },
11282     { 0 }
11283 };
11284
11285 /* SetActiveWindow( hwnd ) hwnd not visible */
11286 static const struct message SetActiveWindowSeq3[] =
11287 {
11288     { HCBT_ACTIVATE, hook },
11289     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11290     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11291     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
11292     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11293     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11294     { WM_ACTIVATEAPP, sent|wparam, 1 },
11295     { WM_ACTIVATEAPP, sent|wparam, 1 },
11296     { WM_NCACTIVATE, sent|wparam, 1 },
11297     { WM_ACTIVATE, sent|wparam, 1 },
11298     { HCBT_SETFOCUS, hook },
11299     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11300     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11301     { WM_SETFOCUS, sent|defwinproc },
11302     { 0 }
11303 };
11304 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
11305 static const struct message SetActiveWindowSeq4[] =
11306 {
11307     { HCBT_ACTIVATE, hook },
11308     { WM_NCACTIVATE, sent|wparam, 0 },
11309     { WM_GETTEXT, sent|defwinproc|optional },
11310     { WM_ACTIVATE, sent|wparam, 0 },
11311     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11312     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
11313     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11314     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11315     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11316     { WM_NCACTIVATE, sent|wparam, 1 },
11317     { WM_GETTEXT, sent|defwinproc|optional },
11318     { WM_ACTIVATE, sent|wparam, 1 },
11319     { HCBT_SETFOCUS, hook },
11320     { WM_KILLFOCUS, sent|defwinproc },
11321     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
11322     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11323     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
11324     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11325     { WM_SETFOCUS, sent|defwinproc },
11326     { 0 }
11327 };
11328
11329
11330 static void test_SetActiveWindow(void)
11331 {
11332     HWND hwnd, popup, ret;
11333
11334     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
11335                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11336                            100, 100, 200, 200, 0, 0, 0, NULL);
11337
11338     popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
11339                            WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
11340                            100, 100, 200, 200, hwnd, 0, 0, NULL);
11341
11342     ok(hwnd != 0, "Failed to create overlapped window\n");
11343     ok(popup != 0, "Failed to create popup window\n");
11344     SetForegroundWindow( popup );
11345     flush_sequence();
11346
11347     trace("SetActiveWindow(0)\n");
11348     ret = SetActiveWindow(0);
11349     ok( ret == popup, "Failed to SetActiveWindow(0)\n");
11350     ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", FALSE);
11351     flush_sequence();
11352
11353     trace("SetActiveWindow(hwnd), hwnd visible\n");
11354     ret = SetActiveWindow(hwnd);
11355     if (ret == hwnd) ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
11356     flush_sequence();
11357
11358     trace("SetActiveWindow(popup), hwnd visible, popup visible\n");
11359     ret = SetActiveWindow(popup);
11360     ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visible\n");
11361     ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visible", FALSE);
11362     flush_sequence();
11363
11364     ShowWindow(hwnd, SW_HIDE);
11365     ShowWindow(popup, SW_HIDE);
11366     flush_sequence();
11367
11368     trace("SetActiveWindow(hwnd), hwnd not visible\n");
11369     ret = SetActiveWindow(hwnd);
11370     ok( ret == NULL, "SetActiveWindow(hwnd), hwnd not visible, previous is %p\n", ret );
11371     ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
11372     flush_sequence();
11373
11374     trace("SetActiveWindow(popup), hwnd not visible, popup not visible\n");
11375     ret = SetActiveWindow(popup);
11376     ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
11377     ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visible", TRUE);
11378     flush_sequence();
11379
11380     trace("done\n");
11381
11382     DestroyWindow(hwnd);
11383 }
11384
11385 static const struct message SetForegroundWindowSeq[] =
11386 {
11387     { WM_NCACTIVATE, sent|wparam, 0 },
11388     { WM_GETTEXT, sent|defwinproc|optional },
11389     { WM_ACTIVATE, sent|wparam, 0 },
11390     { WM_ACTIVATEAPP, sent|wparam, 0 },
11391     { WM_KILLFOCUS, sent },
11392     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
11393     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
11394     { 0 }
11395 };
11396
11397 static void test_SetForegroundWindow(void)
11398 {
11399     HWND hwnd;
11400
11401     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
11402                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11403                            100, 100, 200, 200, 0, 0, 0, NULL);
11404     ok (hwnd != 0, "Failed to create overlapped window\n");
11405     SetForegroundWindow( hwnd );
11406     flush_sequence();
11407
11408     trace("SetForegroundWindow( 0 )\n");
11409     SetForegroundWindow( 0 );
11410     ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
11411     trace("SetForegroundWindow( GetDesktopWindow() )\n");
11412     SetForegroundWindow( GetDesktopWindow() );
11413     ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
11414                                         "foreground top level window", FALSE);
11415     trace("done\n");
11416
11417     DestroyWindow(hwnd);
11418 }
11419
11420 static void test_dbcs_wm_char(void)
11421 {
11422     BYTE dbch[2];
11423     WCHAR wch, bad_wch;
11424     HWND hwnd, hwnd2;
11425     MSG msg;
11426     DWORD time;
11427     POINT pt;
11428     DWORD_PTR res;
11429     CPINFOEXA cpinfo;
11430     UINT i, j, k;
11431     struct message wmCharSeq[2];
11432
11433     if (!pGetCPInfoExA)
11434     {
11435         win_skip("GetCPInfoExA is not available\n");
11436         return;
11437     }
11438
11439     pGetCPInfoExA( CP_ACP, 0, &cpinfo );
11440     if (cpinfo.MaxCharSize != 2)
11441     {
11442         skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
11443         return;
11444     }
11445
11446     dbch[0] = dbch[1] = 0;
11447     wch = 0;
11448     bad_wch = cpinfo.UnicodeDefaultChar;
11449     for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
11450         for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
11451             for (k = 128; k <= 255; k++)
11452             {
11453                 char str[2];
11454                 WCHAR wstr[2];
11455                 str[0] = j;
11456                 str[1] = k;
11457                 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
11458                     WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
11459                     (BYTE)str[0] == j && (BYTE)str[1] == k &&
11460                     HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
11461                 {
11462                     dbch[0] = j;
11463                     dbch[1] = k;
11464                     wch = wstr[0];
11465                     break;
11466                 }
11467             }
11468
11469     if (!wch)
11470     {
11471         skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
11472         return;
11473     }
11474     trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
11475            dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
11476
11477     hwnd = CreateWindowExW(0, testWindowClassW, NULL,
11478                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11479     hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
11480                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11481     ok (hwnd != 0, "Failed to create overlapped window\n");
11482     ok (hwnd2 != 0, "Failed to create overlapped window\n");
11483     flush_sequence();
11484
11485     memset( wmCharSeq, 0, sizeof(wmCharSeq) );
11486     wmCharSeq[0].message = WM_CHAR;
11487     wmCharSeq[0].flags = sent|wparam;
11488     wmCharSeq[0].wParam = wch;
11489
11490     /* posted message */
11491     PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11492     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11493     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11494     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11495     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11496     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11497     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11498
11499     /* posted thread message */
11500     PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
11501     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11502     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11503     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11504     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11505     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11506     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11507
11508     /* sent message */
11509     flush_sequence();
11510     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11511     ok_sequence( WmEmptySeq, "no messages", FALSE );
11512     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11513     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11514     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11515
11516     /* sent message with timeout */
11517     flush_sequence();
11518     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11519     ok_sequence( WmEmptySeq, "no messages", FALSE );
11520     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11521     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11522     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11523
11524     /* sent message with timeout and callback */
11525     flush_sequence();
11526     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11527     ok_sequence( WmEmptySeq, "no messages", FALSE );
11528     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11529     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11530     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11531
11532     /* sent message with callback */
11533     flush_sequence();
11534     SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11535     ok_sequence( WmEmptySeq, "no messages", FALSE );
11536     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11537     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11538     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11539
11540     /* direct window proc call */
11541     flush_sequence();
11542     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11543     ok_sequence( WmEmptySeq, "no messages", FALSE );
11544     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11545     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11546
11547     /* dispatch message */
11548     msg.hwnd = hwnd;
11549     msg.message = WM_CHAR;
11550     msg.wParam = dbch[0];
11551     msg.lParam = 0;
11552     DispatchMessageA( &msg );
11553     ok_sequence( WmEmptySeq, "no messages", FALSE );
11554     msg.wParam = dbch[1];
11555     DispatchMessageA( &msg );
11556     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11557
11558     /* window handle is irrelevant */
11559     flush_sequence();
11560     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11561     ok_sequence( WmEmptySeq, "no messages", FALSE );
11562     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11563     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11564     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11565
11566     /* interleaved post and send */
11567     flush_sequence();
11568     PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11569     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11570     ok_sequence( WmEmptySeq, "no messages", FALSE );
11571     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11572     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11573     ok_sequence( WmEmptySeq, "no messages", FALSE );
11574     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11575     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11576     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11577     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11578     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11579     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11580     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11581
11582     /* interleaved sent message and winproc */
11583     flush_sequence();
11584     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11585     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11586     ok_sequence( WmEmptySeq, "no messages", FALSE );
11587     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11588     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11589     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11590     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11591
11592     /* interleaved winproc and dispatch */
11593     msg.hwnd = hwnd;
11594     msg.message = WM_CHAR;
11595     msg.wParam = dbch[0];
11596     msg.lParam = 0;
11597     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11598     DispatchMessageA( &msg );
11599     ok_sequence( WmEmptySeq, "no messages", FALSE );
11600     msg.wParam = dbch[1];
11601     DispatchMessageA( &msg );
11602     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11603     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11604     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11605
11606     /* interleaved sends */
11607     flush_sequence();
11608     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11609     SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
11610     ok_sequence( WmEmptySeq, "no messages", FALSE );
11611     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11612     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11613     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11614     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11615
11616     /* dbcs WM_CHAR */
11617     flush_sequence();
11618     SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
11619     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11620     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11621
11622     /* other char messages are not magic */
11623     PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
11624     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11625     ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
11626     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
11627     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11628     PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
11629     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11630     ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
11631     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
11632     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11633
11634     /* test retrieving messages */
11635
11636     PostMessageW( hwnd, WM_CHAR, wch, 0 );
11637     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11638     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11639     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11640     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11641     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11642     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11643     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11644     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11645     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11646
11647     /* message filters */
11648     PostMessageW( hwnd, WM_CHAR, wch, 0 );
11649     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11650     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11651     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11652     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11653     /* message id is filtered, hwnd is not */
11654     ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
11655     ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
11656     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11657     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11658     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11659     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11660
11661     /* mixing GetMessage and PostMessage */
11662     PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
11663     ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
11664     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11665     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11666     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11667     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
11668     time = msg.time;
11669     pt = msg.pt;
11670     ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
11671     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11672     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11673     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11674     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11675     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
11676     ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
11677     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 );
11678     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11679
11680     /* without PM_REMOVE */
11681     PostMessageW( hwnd, WM_CHAR, wch, 0 );
11682     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
11683     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11684     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11685     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11686     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11687     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11688     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11689     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11690     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
11691     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11692     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11693     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11694     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11695     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11696     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11697     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11698     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11699
11700     DestroyWindow(hwnd);
11701     DestroyWindow(hwnd2);
11702 }
11703
11704 #define ID_LISTBOX 0x000f
11705
11706 static const struct message wm_lb_setcursel_0[] =
11707 {
11708     { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
11709     { WM_CTLCOLORLISTBOX, sent|parent },
11710     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
11711     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11712     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11713     { 0 }
11714 };
11715 static const struct message wm_lb_setcursel_1[] =
11716 {
11717     { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
11718     { WM_CTLCOLORLISTBOX, sent|parent },
11719     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
11720     { WM_CTLCOLORLISTBOX, sent|parent },
11721     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
11722     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
11723     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
11724     { 0 }
11725 };
11726 static const struct message wm_lb_setcursel_2[] =
11727 {
11728     { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
11729     { WM_CTLCOLORLISTBOX, sent|parent },
11730     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
11731     { WM_CTLCOLORLISTBOX, sent|parent },
11732     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
11733     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11734     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11735     { 0 }
11736 };
11737 static const struct message wm_lb_click_0[] =
11738 {
11739     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
11740     { HCBT_SETFOCUS, hook },
11741     { WM_KILLFOCUS, sent|parent },
11742     { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
11743     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11744     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
11745     { WM_SETFOCUS, sent|defwinproc },
11746
11747     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
11748     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
11749     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11750     { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
11751     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
11752
11753     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
11754     { WM_CTLCOLORLISTBOX, sent|parent },
11755     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
11756     { WM_CTLCOLORLISTBOX, sent|parent },
11757     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
11758     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
11759
11760     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11761     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11762
11763     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
11764     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
11765     { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
11766     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
11767     { 0 }
11768 };
11769 static const struct message wm_lb_deletestring[] =
11770 {
11771     { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
11772     { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
11773     { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11774     { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11775     { 0 }
11776 };
11777 static const struct message wm_lb_deletestring_reset[] =
11778 {
11779     { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
11780     { LB_RESETCONTENT, sent|wparam|lparam|defwinproc|optional, 0, 0 },
11781     { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
11782     { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11783     { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11784     { 0 }
11785 };
11786
11787 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
11788
11789 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
11790
11791 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11792 {
11793     static LONG defwndproc_counter = 0;
11794     LRESULT ret;
11795     struct recvd_message msg;
11796
11797     /* do not log painting messages */
11798     if (message != WM_PAINT &&
11799         message != WM_NCPAINT &&
11800         message != WM_SYNCPAINT &&
11801         message != WM_ERASEBKGND &&
11802         message != WM_NCHITTEST &&
11803         message != WM_GETTEXT &&
11804         !ignore_message( message ))
11805     {
11806         msg.hwnd = hwnd;
11807         msg.message = message;
11808         msg.flags = sent|wparam|lparam;
11809         if (defwndproc_counter) msg.flags |= defwinproc;
11810         msg.wParam = wp;
11811         msg.lParam = lp;
11812         msg.descr = "listbox";
11813         add_message(&msg);
11814     }
11815
11816     defwndproc_counter++;
11817     ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
11818     defwndproc_counter--;
11819
11820     return ret;
11821 }
11822
11823 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
11824                                int caret_index, int top_index, int line)
11825 {
11826     LRESULT ret;
11827
11828     /* calling an orig proc helps to avoid unnecessary message logging */
11829     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
11830     ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
11831     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
11832     ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
11833     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
11834     ok_(__FILE__, line)(ret == caret_index ||
11835                         broken(cur_sel == -1 && caret_index == 0 && ret == -1),  /* nt4 */
11836                         "expected caret index %d, got %ld\n", caret_index, ret);
11837     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
11838     ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
11839 }
11840
11841 static void test_listbox_messages(void)
11842 {
11843     HWND parent, listbox;
11844     LRESULT ret;
11845
11846     parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW  | WS_VISIBLE,
11847                              100, 100, 200, 200, 0, 0, 0, NULL);
11848     listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
11849                               WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
11850                               10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
11851     listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
11852
11853     check_lb_state(listbox, 0, LB_ERR, 0, 0);
11854
11855     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
11856     ok(ret == 0, "expected 0, got %ld\n", ret);
11857     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
11858     ok(ret == 1, "expected 1, got %ld\n", ret);
11859     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
11860     ok(ret == 2, "expected 2, got %ld\n", ret);
11861
11862     check_lb_state(listbox, 3, LB_ERR, 0, 0);
11863
11864     flush_sequence();
11865
11866     log_all_parent_messages++;
11867
11868     trace("selecting item 0\n");
11869     ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
11870     ok(ret == 0, "expected 0, got %ld\n", ret);
11871     ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
11872     check_lb_state(listbox, 3, 0, 0, 0);
11873     flush_sequence();
11874
11875     trace("selecting item 1\n");
11876     ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
11877     ok(ret == 1, "expected 1, got %ld\n", ret);
11878     ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
11879     check_lb_state(listbox, 3, 1, 1, 0);
11880
11881     trace("selecting item 2\n");
11882     ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
11883     ok(ret == 2, "expected 2, got %ld\n", ret);
11884     ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
11885     check_lb_state(listbox, 3, 2, 2, 0);
11886
11887     trace("clicking on item 0\n");
11888     ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
11889     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11890     ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
11891     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11892     ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
11893     check_lb_state(listbox, 3, 0, 0, 0);
11894     flush_sequence();
11895
11896     trace("deleting item 0\n");
11897     ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11898     ok(ret == 2, "expected 2, got %ld\n", ret);
11899     ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
11900     check_lb_state(listbox, 2, -1, 0, 0);
11901     flush_sequence();
11902
11903     trace("deleting item 0\n");
11904     ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11905     ok(ret == 1, "expected 1, got %ld\n", ret);
11906     ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
11907     check_lb_state(listbox, 1, -1, 0, 0);
11908     flush_sequence();
11909
11910     trace("deleting item 0\n");
11911     ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11912     ok(ret == 0, "expected 0, got %ld\n", ret);
11913     ok_sequence(wm_lb_deletestring_reset, "LB_DELETESTRING 0", FALSE );
11914     check_lb_state(listbox, 0, -1, 0, 0);
11915     flush_sequence();
11916
11917     trace("deleting item 0\n");
11918     ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11919     ok(ret == LB_ERR, "expected LB_ERR, got %ld\n", ret);
11920     check_lb_state(listbox, 0, -1, 0, 0);
11921     flush_sequence();
11922
11923     log_all_parent_messages--;
11924
11925     DestroyWindow(listbox);
11926     DestroyWindow(parent);
11927 }
11928
11929 /*************************** Menu test ******************************/
11930 static const struct message wm_popup_menu_1[] =
11931 {
11932     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11933     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11934     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
11935     { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
11936     { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
11937     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
11938     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11939     { WM_INITMENU, sent|lparam, 0, 0 },
11940     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
11941     { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
11942     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
11943     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
11944     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
11945     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11946     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001, 0, 0x40000000 },
11947     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
11948     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11949     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11950     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11951     { WM_MENUCOMMAND, sent }, /* |wparam, 200 - Win9x */
11952     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11953     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11954     { 0 }
11955 };
11956 static const struct message wm_popup_menu_2[] =
11957 {
11958     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11959     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11960     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11961     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11962     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11963     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11964     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11965     { WM_INITMENU, sent|lparam, 0, 0 },
11966     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11967     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11968     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11969     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11970     { HCBT_CREATEWND, hook },
11971     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11972                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11973     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11974     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11975     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11976     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11977     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11978     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11979     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11980     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11981     { HCBT_DESTROYWND, hook },
11982     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11983     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11984     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11985     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11986     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11987     { WM_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
11988     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11989     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11990     { 0 }
11991 };
11992 static const struct message wm_popup_menu_3[] =
11993 {
11994     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11995     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11996     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11997     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11998     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11999     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
12000     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
12001     { WM_INITMENU, sent|lparam, 0, 0 },
12002     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
12003     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
12004     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
12005     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
12006     { HCBT_CREATEWND, hook },
12007     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
12008                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
12009     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
12010     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
12011     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
12012     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
12013     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
12014     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
12015     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
12016     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
12017     { HCBT_DESTROYWND, hook },
12018     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
12019     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
12020     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
12021     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
12022     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
12023     { WM_COMMAND, sent|wparam|lparam, 100, 0 },
12024     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
12025     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
12026     { 0 }
12027 };
12028
12029 static const struct message wm_single_menu_item[] =
12030 {
12031     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
12032     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
12033     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'Q', 0x20000001 },
12034     { WM_SYSKEYDOWN, sent|wparam|lparam, 'Q', 0x20000001 },
12035     { WM_SYSCHAR, sent|wparam|lparam, 'q', 0x20000001 },
12036     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'q' },
12037     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
12038     { WM_INITMENU, sent|lparam, 0, 0 },
12039     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(300,MF_HILITE) },
12040     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
12041     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
12042     { WM_MENUCOMMAND, sent },
12043     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'Q', 0xe0000001 },
12044     { WM_SYSKEYUP, sent|wparam|lparam, 'Q', 0xe0000001 },
12045     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 },
12046     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
12047
12048     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 1 },
12049     { WM_KEYDOWN, sent|wparam|lparam, VK_ESCAPE, 1 },
12050     { WM_CHAR,  sent|wparam|lparam, VK_ESCAPE, 0x00000001 },
12051     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0xc0000001 },
12052     { WM_KEYUP, sent|wparam|lparam, VK_ESCAPE, 0xc0000001 },
12053     { 0 }
12054 };
12055
12056 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
12057 {
12058     if (message == WM_ENTERIDLE ||
12059         message == WM_INITMENU ||
12060         message == WM_INITMENUPOPUP ||
12061         message == WM_MENUSELECT ||
12062         message == WM_PARENTNOTIFY ||
12063         message == WM_ENTERMENULOOP ||
12064         message == WM_EXITMENULOOP ||
12065         message == WM_UNINITMENUPOPUP ||
12066         message == WM_KEYDOWN ||
12067         message == WM_KEYUP ||
12068         message == WM_CHAR ||
12069         message == WM_SYSKEYDOWN ||
12070         message == WM_SYSKEYUP ||
12071         message == WM_SYSCHAR ||
12072         message == WM_COMMAND ||
12073         message == WM_MENUCOMMAND)
12074     {
12075         struct recvd_message msg;
12076
12077         msg.hwnd = hwnd;
12078         msg.message = message;
12079         msg.flags = sent|wparam|lparam;
12080         msg.wParam = wp;
12081         msg.lParam = lp;
12082         msg.descr = "parent_menu_proc";
12083         add_message(&msg);
12084     }
12085
12086     return DefWindowProcA(hwnd, message, wp, lp);
12087 }
12088
12089 static void set_menu_style(HMENU hmenu, DWORD style)
12090 {
12091     MENUINFO mi;
12092     BOOL ret;
12093
12094     mi.cbSize = sizeof(mi);
12095     mi.fMask = MIM_STYLE;
12096     mi.dwStyle = style;
12097     SetLastError(0xdeadbeef);
12098     ret = pSetMenuInfo(hmenu, &mi);
12099     ok(ret, "SetMenuInfo error %u\n", GetLastError());
12100 }
12101
12102 static DWORD get_menu_style(HMENU hmenu)
12103 {
12104     MENUINFO mi;
12105     BOOL ret;
12106
12107     mi.cbSize = sizeof(mi);
12108     mi.fMask = MIM_STYLE;
12109     mi.dwStyle = 0;
12110     SetLastError(0xdeadbeef);
12111     ret = pGetMenuInfo(hmenu, &mi);
12112     ok(ret, "GetMenuInfo error %u\n", GetLastError());
12113
12114     return mi.dwStyle;
12115 }
12116
12117 static void test_menu_messages(void)
12118 {
12119     MSG msg;
12120     WNDCLASSA cls;
12121     HMENU hmenu, hmenu_popup;
12122     HWND hwnd;
12123     DWORD style;
12124
12125     if (!pGetMenuInfo || !pSetMenuInfo)
12126     {
12127         win_skip("GetMenuInfo and/or SetMenuInfo are not available\n");
12128         return;
12129     }
12130     cls.style = 0;
12131     cls.lpfnWndProc = parent_menu_proc;
12132     cls.cbClsExtra = 0;
12133     cls.cbWndExtra = 0;
12134     cls.hInstance = GetModuleHandleA(0);
12135     cls.hIcon = 0;
12136     cls.hCursor = LoadCursorA(0, IDC_ARROW);
12137     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
12138     cls.lpszMenuName = NULL;
12139     cls.lpszClassName = "TestMenuClass";
12140     UnregisterClass(cls.lpszClassName, cls.hInstance);
12141     if (!RegisterClassA(&cls)) assert(0);
12142
12143     SetLastError(0xdeadbeef);
12144     hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
12145                            100, 100, 200, 200, 0, 0, 0, NULL);
12146     ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
12147
12148     SetLastError(0xdeadbeef);
12149     hmenu = LoadMenuA(GetModuleHandle(0), MAKEINTRESOURCE(1));
12150     ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
12151
12152     SetMenu(hwnd, hmenu);
12153     SetForegroundWindow( hwnd );
12154
12155     set_menu_style(hmenu, MNS_NOTIFYBYPOS);
12156     style = get_menu_style(hmenu);
12157     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
12158
12159     hmenu_popup = GetSubMenu(hmenu, 0);
12160     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12161     style = get_menu_style(hmenu_popup);
12162     ok(style == 0, "expected 0, got %u\n", style);
12163
12164     hmenu_popup = GetSubMenu(hmenu_popup, 0);
12165     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12166     style = get_menu_style(hmenu_popup);
12167     ok(style == 0, "expected 0, got %u\n", style);
12168
12169     /* Alt+E, Enter */
12170     trace("testing a popup menu command\n");
12171     flush_sequence();
12172     keybd_event(VK_MENU, 0, 0, 0);
12173     keybd_event('E', 0, 0, 0);
12174     keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
12175     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12176     keybd_event(VK_RETURN, 0, 0, 0);
12177     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
12178     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
12179     {
12180         TranslateMessage(&msg);
12181         DispatchMessage(&msg);
12182     }
12183     if (!sequence_cnt)  /* we didn't get any message */
12184     {
12185         skip( "queuing key events not supported\n" );
12186         goto done;
12187     }
12188     /* win98 queues only a WM_KEYUP and doesn't start menu tracking */
12189     if (sequence[0].message == WM_KEYUP && sequence[0].wParam == VK_MENU)
12190     {
12191         win_skip( "menu tracking through VK_MENU not supported\n" );
12192         goto done;
12193     }
12194     ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
12195
12196     /* Alt+F, Right, Enter */
12197     trace("testing submenu of a popup menu command\n");
12198     flush_sequence();
12199     keybd_event(VK_MENU, 0, 0, 0);
12200     keybd_event('F', 0, 0, 0);
12201     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
12202     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12203     keybd_event(VK_RIGHT, 0, 0, 0);
12204     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
12205     keybd_event(VK_RETURN, 0, 0, 0);
12206     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
12207     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
12208     {
12209         TranslateMessage(&msg);
12210         DispatchMessage(&msg);
12211     }
12212     ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
12213
12214     trace("testing single menu item command\n");
12215     flush_sequence();
12216     keybd_event(VK_MENU, 0, 0, 0);
12217     keybd_event('Q', 0, 0, 0);
12218     keybd_event('Q', 0, KEYEVENTF_KEYUP, 0);
12219     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12220     keybd_event(VK_ESCAPE, 0, 0, 0);
12221     keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0);
12222     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
12223     {
12224         TranslateMessage(&msg);
12225         DispatchMessage(&msg);
12226     }
12227     ok_sequence(wm_single_menu_item, "single menu item command", FALSE);
12228
12229     set_menu_style(hmenu, 0);
12230     style = get_menu_style(hmenu);
12231     ok(style == 0, "expected 0, got %u\n", style);
12232
12233     hmenu_popup = GetSubMenu(hmenu, 0);
12234     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12235     set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
12236     style = get_menu_style(hmenu_popup);
12237     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
12238
12239     hmenu_popup = GetSubMenu(hmenu_popup, 0);
12240     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12241     style = get_menu_style(hmenu_popup);
12242     ok(style == 0, "expected 0, got %u\n", style);
12243
12244     /* Alt+F, Right, Enter */
12245     trace("testing submenu of a popup menu command\n");
12246     flush_sequence();
12247     keybd_event(VK_MENU, 0, 0, 0);
12248     keybd_event('F', 0, 0, 0);
12249     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
12250     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12251     keybd_event(VK_RIGHT, 0, 0, 0);
12252     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
12253     keybd_event(VK_RETURN, 0, 0, 0);
12254     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
12255     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
12256     {
12257         TranslateMessage(&msg);
12258         DispatchMessage(&msg);
12259     }
12260     ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
12261
12262 done:
12263     DestroyWindow(hwnd);
12264     DestroyMenu(hmenu);
12265 }
12266
12267
12268 static void test_paintingloop(void)
12269 {
12270     HWND hwnd;
12271
12272     paint_loop_done = 0;
12273     hwnd = CreateWindowExA(0x0,"PaintLoopWindowClass",
12274                                "PaintLoopWindowClass",WS_OVERLAPPEDWINDOW,
12275                                 100, 100, 100, 100, 0, 0, 0, NULL );
12276     ok(hwnd != 0, "PaintLoop window error %u\n", GetLastError());
12277     ShowWindow(hwnd,SW_NORMAL);
12278     SetFocus(hwnd);
12279
12280     while (!paint_loop_done)
12281     {
12282         MSG msg;
12283         if (PeekMessageA(&msg, 0, 0, 0, 1))
12284         {
12285             TranslateMessage(&msg);
12286             DispatchMessage(&msg);
12287         }
12288     }
12289     DestroyWindow(hwnd);
12290 }
12291
12292 static void test_defwinproc(void)
12293 {
12294     HWND hwnd;
12295     MSG msg;
12296     int gotwmquit = FALSE;
12297     hwnd = CreateWindowExA(0, "static", "test_defwndproc", WS_POPUP, 0,0,0,0,0,0,0, NULL);
12298     assert(hwnd);
12299     DefWindowProcA( hwnd, WM_ENDSESSION, 1, 0);
12300     while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) {
12301         if( msg.message == WM_QUIT) gotwmquit = TRUE;
12302         DispatchMessageA( &msg );
12303     }
12304     ok( gotwmquit == FALSE, "Unexpected WM_QUIT message!\n");
12305     DestroyWindow( hwnd);
12306 }
12307
12308 #define clear_clipboard(hwnd)  clear_clipboard_(__LINE__, (hwnd))
12309 static void clear_clipboard_(int line, HWND hWnd)
12310 {
12311     BOOL succ;
12312     succ = OpenClipboard(hWnd);
12313     ok_(__FILE__, line)(succ, "OpenClipboard failed, err=%u\n", GetLastError());
12314     succ = EmptyClipboard();
12315     ok_(__FILE__, line)(succ, "EmptyClipboard failed, err=%u\n", GetLastError());
12316     succ = CloseClipboard();
12317     ok_(__FILE__, line)(succ, "CloseClipboard failed, err=%u\n", GetLastError());
12318 }
12319
12320 #define expect_HWND(expected, got) expect_HWND_(__LINE__, (expected), (got))
12321 static void expect_HWND_(int line, HWND expected, HWND got)
12322 {
12323     ok_(__FILE__, line)(got==expected, "Expected %p, got %p\n", expected, got);
12324 }
12325
12326 static WNDPROC pOldViewerProc;
12327
12328 static LRESULT CALLBACK recursive_viewer_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
12329 {
12330     static BOOL recursion_guard;
12331
12332     if (message == WM_DRAWCLIPBOARD && !recursion_guard)
12333     {
12334         recursion_guard = TRUE;
12335         clear_clipboard(hWnd);
12336         recursion_guard = FALSE;
12337     }
12338     return CallWindowProcA(pOldViewerProc, hWnd, message, wParam, lParam);
12339 }
12340
12341 static void test_clipboard_viewers(void)
12342 {
12343     static struct message wm_change_cb_chain[] =
12344     {
12345         { WM_CHANGECBCHAIN, sent|wparam|lparam, 0, 0 },
12346         { 0 }
12347     };
12348     static const struct message wm_clipboard_destroyed[] =
12349     {
12350         { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
12351         { 0 }
12352     };
12353     static struct message wm_clipboard_changed[] =
12354     {
12355         { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
12356         { 0 }
12357     };
12358     static struct message wm_clipboard_changed_and_owned[] =
12359     {
12360         { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
12361         { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
12362         { 0 }
12363     };
12364
12365     HINSTANCE hInst = GetModuleHandleA(NULL);
12366     HWND hWnd1, hWnd2, hWnd3;
12367     HWND hOrigViewer;
12368     HWND hRet;
12369
12370     hWnd1 = CreateWindowExA(0, "TestWindowClass", "Clipboard viewer test wnd 1",
12371         WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12372         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12373         GetDesktopWindow(), NULL, hInst, NULL);
12374     hWnd2 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 2",
12375         WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12376         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12377         GetDesktopWindow(), NULL, hInst, NULL);
12378     hWnd3 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 3",
12379         WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12380         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12381         GetDesktopWindow(), NULL, hInst, NULL);
12382     trace("clipbd viewers: hWnd1=%p, hWnd2=%p, hWnd3=%p\n", hWnd1, hWnd2, hWnd3);
12383     assert(hWnd1 && hWnd2 && hWnd3);
12384
12385     flush_sequence();
12386
12387     /* Test getting the clipboard viewer and setting the viewer to NULL. */
12388     hOrigViewer = GetClipboardViewer();
12389     hRet = SetClipboardViewer(NULL);
12390     ok_sequence(WmEmptySeq, "set viewer to NULL", FALSE);
12391     expect_HWND(hOrigViewer, hRet);
12392     expect_HWND(NULL, GetClipboardViewer());
12393
12394     /* Test registering hWnd1 as a viewer. */
12395     hRet = SetClipboardViewer(hWnd1);
12396     wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12397     ok_sequence(wm_clipboard_changed, "set viewer NULL->1", FALSE);
12398     expect_HWND(NULL, hRet);
12399     expect_HWND(hWnd1, GetClipboardViewer());
12400
12401     /* Test that changing the clipboard actually refreshes the registered viewer. */
12402     clear_clipboard(hWnd1);
12403     wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12404     ok_sequence(wm_clipboard_changed, "clear clipbd (viewer=owner=1)", FALSE);
12405
12406     /* Again, but with different owner. */
12407     clear_clipboard(hWnd2);
12408     wm_clipboard_changed_and_owned[1].wParam = (WPARAM) GetClipboardOwner();
12409     ok_sequence(wm_clipboard_changed_and_owned, "clear clipbd (viewer=1, owner=2)", FALSE);
12410
12411     /* Test re-registering same window. */
12412     hRet = SetClipboardViewer(hWnd1);
12413     wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12414     ok_sequence(wm_clipboard_changed, "set viewer 1->1", FALSE);
12415     expect_HWND(hWnd1, hRet);
12416     expect_HWND(hWnd1, GetClipboardViewer());
12417
12418     /* Test ChangeClipboardChain. */
12419     ChangeClipboardChain(hWnd2, hWnd3);
12420     wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
12421     wm_change_cb_chain[0].lParam = (LPARAM) hWnd3;
12422     ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=3)", FALSE);
12423     expect_HWND(hWnd1, GetClipboardViewer());
12424
12425     ChangeClipboardChain(hWnd2, NULL);
12426     wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
12427     wm_change_cb_chain[0].lParam = 0;
12428     ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=NULL)", FALSE);
12429     expect_HWND(hWnd1, GetClipboardViewer());
12430
12431     ChangeClipboardChain(NULL, hWnd2);
12432     ok_sequence(WmEmptySeq, "change chain (viewer=1, remove=NULL, next=2)", TRUE);
12433     expect_HWND(hWnd1, GetClipboardViewer());
12434
12435     /* Actually change clipboard viewer with ChangeClipboardChain. */
12436     ChangeClipboardChain(hWnd1, hWnd2);
12437     ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=2)", FALSE);
12438     expect_HWND(hWnd2, GetClipboardViewer());
12439
12440     /* Test that no refresh messages are sent when viewer has unregistered. */
12441     clear_clipboard(hWnd2);
12442     ok_sequence(WmEmptySeq, "clear clipd (viewer=2, owner=1)", FALSE);
12443
12444     /* Register hWnd1 again. */
12445     ChangeClipboardChain(hWnd2, hWnd1);
12446     ok_sequence(WmEmptySeq, "change chain (viewer=remove=2, next=1)", FALSE);
12447     expect_HWND(hWnd1, GetClipboardViewer());
12448
12449     /* Subclass hWnd1 so that when it receives a WM_DRAWCLIPBOARD message, it
12450      * changes the clipboard. When this happens, the system shouldn't send
12451      * another WM_DRAWCLIPBOARD (as this could cause an infinite loop).
12452      */
12453     pOldViewerProc = (WNDPROC) SetWindowLongPtrA(hWnd1, GWLP_WNDPROC, (LONG_PTR) recursive_viewer_proc);
12454     clear_clipboard(hWnd2);
12455     /* The clipboard owner is changed in recursive_viewer_proc: */
12456     wm_clipboard_changed[0].wParam = (WPARAM) hWnd2;
12457     ok_sequence(wm_clipboard_changed, "recursive clear clipbd (viewer=1, owner=2)", TRUE);
12458
12459     /* Test unregistering. */
12460     ChangeClipboardChain(hWnd1, NULL);
12461     ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=NULL)", FALSE);
12462     expect_HWND(NULL, GetClipboardViewer());
12463
12464     clear_clipboard(hWnd1);
12465     ok_sequence(wm_clipboard_destroyed, "clear clipbd (no viewer, owner=1)", FALSE);
12466
12467     DestroyWindow(hWnd1);
12468     DestroyWindow(hWnd2);
12469     DestroyWindow(hWnd3);
12470     SetClipboardViewer(hOrigViewer);
12471 }
12472
12473 static void test_PostMessage(void)
12474 {
12475     static const struct
12476     {
12477         HWND hwnd;
12478         BOOL ret;
12479     } data[] =
12480     {
12481         { HWND_TOP /* 0 */, TRUE },
12482         { HWND_BROADCAST, TRUE },
12483         { HWND_BOTTOM, TRUE },
12484         { HWND_TOPMOST, TRUE },
12485         { HWND_NOTOPMOST, FALSE },
12486         { HWND_MESSAGE, FALSE },
12487         { (HWND)0xdeadbeef, FALSE }
12488     };
12489     int i;
12490     HWND hwnd;
12491     BOOL ret;
12492     MSG msg;
12493     static const WCHAR staticW[] = {'s','t','a','t','i','c',0};
12494
12495     SetLastError(0xdeadbeef);
12496     hwnd = CreateWindowExW(0, staticW, NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
12497     if (!hwnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
12498     {
12499         win_skip("Skipping some PostMessage tests on Win9x/WinMe\n");
12500         return;
12501     }
12502     assert(hwnd);
12503
12504     flush_events();
12505
12506     PostMessage(hwnd, WM_USER+1, 0x1234, 0x5678);
12507     PostMessage(0, WM_USER+2, 0x5678, 0x1234);
12508
12509     for (i = 0; i < sizeof(data)/sizeof(data[0]); i++)
12510     {
12511         memset(&msg, 0xab, sizeof(msg));
12512         ret = PeekMessageA(&msg, data[i].hwnd, 0, 0, PM_NOREMOVE);
12513         ok(ret == data[i].ret, "%d: hwnd %p expected %d, got %d\n", i, data[i].hwnd, data[i].ret, ret);
12514         if (data[i].ret)
12515         {
12516             if (data[i].hwnd)
12517                 ok(ret && msg.hwnd == 0 && msg.message == WM_USER+2 &&
12518                    msg.wParam == 0x5678 && msg.lParam == 0x1234,
12519                    "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/0/WM_USER+2/0x5678/0x1234\n",
12520                    i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam);
12521             else
12522                 ok(ret && msg.hwnd == hwnd && msg.message == WM_USER+1 &&
12523                    msg.wParam == 0x1234 && msg.lParam == 0x5678,
12524                    "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/%p/WM_USER+1/0x1234/0x5678\n",
12525                    i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam, msg.hwnd);
12526         }
12527     }
12528
12529     DestroyWindow(hwnd);
12530     flush_events();
12531 }
12532
12533 static const struct
12534 {
12535     DWORD exp, broken;
12536     BOOL todo;
12537 } wait_idle_expect[] =
12538 {
12539 /* 0 */  { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12540          { WAIT_TIMEOUT, 0,            FALSE },
12541          { WAIT_TIMEOUT, 0,            FALSE },
12542          { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12543          { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12544 /* 5 */  { WAIT_TIMEOUT, 0,            FALSE },
12545          { WAIT_TIMEOUT, 0,            FALSE },
12546          { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12547          { 0,            0,            FALSE },
12548          { 0,            0,            FALSE },
12549 /* 10 */ { 0,            0,            FALSE },
12550          { 0,            0,            FALSE },
12551          { 0,            WAIT_TIMEOUT, FALSE },
12552          { 0,            0,            FALSE },
12553          { 0,            0,            FALSE },
12554 /* 15 */ { 0,            0,            FALSE },
12555          { WAIT_TIMEOUT, 0,            FALSE },
12556          { WAIT_TIMEOUT, 0,            FALSE },
12557          { WAIT_TIMEOUT, 0,            FALSE },
12558          { WAIT_TIMEOUT, 0,            FALSE },
12559 /* 20 */ { WAIT_TIMEOUT, 0,            FALSE },
12560 };
12561
12562 static DWORD CALLBACK do_wait_idle_child_thread( void *arg )
12563 {
12564     MSG msg;
12565
12566     PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12567     Sleep( 200 );
12568     MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12569     return 0;
12570 }
12571
12572 static void do_wait_idle_child( int arg )
12573 {
12574     WNDCLASS cls;
12575     MSG msg;
12576     HWND hwnd = 0;
12577     HANDLE thread;
12578     DWORD id;
12579     HANDLE start_event = OpenEventA( EVENT_ALL_ACCESS, FALSE, "test_WaitForInputIdle_start" );
12580     HANDLE end_event = OpenEventA( EVENT_ALL_ACCESS, FALSE, "test_WaitForInputIdle_end" );
12581
12582     memset( &cls, 0, sizeof(cls) );
12583     cls.lpfnWndProc   = DefWindowProc;
12584     cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
12585     cls.hCursor       = LoadCursor(0, IDC_ARROW);
12586     cls.lpszClassName = "TestClass";
12587     RegisterClass( &cls );
12588
12589     PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );  /* create the msg queue */
12590
12591     ok( start_event != 0, "failed to create start event, error %u\n", GetLastError() );
12592     ok( end_event != 0, "failed to create end event, error %u\n", GetLastError() );
12593
12594     switch (arg)
12595     {
12596     case 0:
12597         SetEvent( start_event );
12598         break;
12599     case 1:
12600         SetEvent( start_event );
12601         Sleep( 200 );
12602         PeekMessage( &msg, 0, 0, 0, PM_REMOVE );
12603         break;
12604     case 2:
12605         SetEvent( start_event );
12606         Sleep( 200 );
12607         PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12608         PostThreadMessage( GetCurrentThreadId(), WM_COMMAND, 0x1234, 0xabcd );
12609         PeekMessage( &msg, 0, 0, 0, PM_REMOVE );
12610         break;
12611     case 3:
12612         SetEvent( start_event );
12613         Sleep( 200 );
12614         SendMessage( HWND_BROADCAST, WM_WININICHANGE, 0, 0 );
12615         break;
12616     case 4:
12617         SetEvent( start_event );
12618         Sleep( 200 );
12619         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12620         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessage( &msg );
12621         break;
12622     case 5:
12623         SetEvent( start_event );
12624         Sleep( 200 );
12625         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12626         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12627         break;
12628     case 6:
12629         SetEvent( start_event );
12630         Sleep( 200 );
12631         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12632         while (PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ))
12633         {
12634             GetMessage( &msg, 0, 0, 0 );
12635             DispatchMessage( &msg );
12636         }
12637         break;
12638     case 7:
12639         SetEvent( start_event );
12640         Sleep( 200 );
12641         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12642         SetTimer( hwnd, 3, 1, NULL );
12643         Sleep( 200 );
12644         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessage( &msg );
12645         break;
12646     case 8:
12647         SetEvent( start_event );
12648         Sleep( 200 );
12649         PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12650         MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12651         break;
12652     case 9:
12653         SetEvent( start_event );
12654         Sleep( 200 );
12655         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12656         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12657         for (;;) GetMessage( &msg, 0, 0, 0 );
12658         break;
12659     case 10:
12660         SetEvent( start_event );
12661         Sleep( 200 );
12662         hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12663         SetTimer( hwnd, 3, 1, NULL );
12664         Sleep( 200 );
12665         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12666         break;
12667     case 11:
12668         SetEvent( start_event );
12669         Sleep( 200 );
12670         return;  /* exiting the process makes WaitForInputIdle return success too */
12671     case 12:
12672         PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12673         Sleep( 200 );
12674         MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12675         SetEvent( start_event );
12676         break;
12677     case 13:
12678         SetEvent( start_event );
12679         PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12680         Sleep( 200 );
12681         thread = CreateThread( NULL, 0, do_wait_idle_child_thread, NULL, 0, &id );
12682         WaitForSingleObject( thread, 10000 );
12683         CloseHandle( thread );
12684         break;
12685     case 14:
12686         SetEvent( start_event );
12687         Sleep( 200 );
12688         PeekMessage( &msg, HWND_TOPMOST, 0, 0, PM_NOREMOVE );
12689         break;
12690     case 15:
12691         SetEvent( start_event );
12692         Sleep( 200 );
12693         PeekMessage( &msg, HWND_BROADCAST, 0, 0, PM_NOREMOVE );
12694         break;
12695     case 16:
12696         SetEvent( start_event );
12697         Sleep( 200 );
12698         PeekMessage( &msg, HWND_BOTTOM, 0, 0, PM_NOREMOVE );
12699         break;
12700     case 17:
12701         SetEvent( start_event );
12702         Sleep( 200 );
12703         PeekMessage( &msg, (HWND)0xdeadbeef, 0, 0, PM_NOREMOVE );
12704         break;
12705     case 18:
12706         SetEvent( start_event );
12707         Sleep( 200 );
12708         PeekMessage( &msg, HWND_NOTOPMOST, 0, 0, PM_NOREMOVE );
12709         break;
12710     case 19:
12711         SetEvent( start_event );
12712         Sleep( 200 );
12713         PeekMessage( &msg, HWND_MESSAGE, 0, 0, PM_NOREMOVE );
12714         break;
12715     case 20:
12716         SetEvent( start_event );
12717         Sleep( 200 );
12718         PeekMessage( &msg, GetDesktopWindow(), 0, 0, PM_NOREMOVE );
12719         break;
12720     }
12721     WaitForSingleObject( end_event, 2000 );
12722     CloseHandle( start_event );
12723     CloseHandle( end_event );
12724     if (hwnd) DestroyWindow( hwnd );
12725 }
12726
12727 static LRESULT CALLBACK wait_idle_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
12728 {
12729     if (msg == WM_WININICHANGE) Sleep( 200 );  /* make sure the child waits */
12730     return DefWindowProcA( hwnd, msg, wp, lp );
12731 }
12732
12733 static DWORD CALLBACK wait_idle_thread( void *arg )
12734 {
12735     WNDCLASS cls;
12736     MSG msg;
12737     HWND hwnd;
12738
12739     memset( &cls, 0, sizeof(cls) );
12740     cls.lpfnWndProc   = wait_idle_proc;
12741     cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
12742     cls.hCursor       = LoadCursor(0, IDC_ARROW);
12743     cls.lpszClassName = "TestClass";
12744     RegisterClass( &cls );
12745
12746     hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
12747     while (GetMessage( &msg, 0, 0, 0 )) DispatchMessage( &msg );
12748     DestroyWindow(hwnd);
12749     return 0;
12750 }
12751
12752 static void test_WaitForInputIdle( char *argv0 )
12753 {
12754     char path[MAX_PATH];
12755     PROCESS_INFORMATION pi;
12756     STARTUPINFOA startup;
12757     BOOL ret;
12758     HANDLE start_event, end_event, thread;
12759     unsigned int i;
12760     DWORD id;
12761     const IMAGE_DOS_HEADER *dos = (const IMAGE_DOS_HEADER *)GetModuleHandleA(0);
12762     const IMAGE_NT_HEADERS *nt = (const IMAGE_NT_HEADERS *)((const char *)dos + dos->e_lfanew);
12763     BOOL console_app = (nt->OptionalHeader.Subsystem != IMAGE_SUBSYSTEM_WINDOWS_GUI);
12764
12765     if (console_app)  /* build the test with -mwindows for better coverage */
12766         trace( "not built as a GUI app, WaitForInputIdle may not be fully tested\n" );
12767
12768     start_event = CreateEventA(NULL, 0, 0, "test_WaitForInputIdle_start");
12769     end_event = CreateEventA(NULL, 0, 0, "test_WaitForInputIdle_end");
12770     ok(start_event != 0, "failed to create start event, error %u\n", GetLastError());
12771     ok(end_event != 0, "failed to create end event, error %u\n", GetLastError());
12772
12773     memset( &startup, 0, sizeof(startup) );
12774     startup.cb = sizeof(startup);
12775     startup.dwFlags = STARTF_USESHOWWINDOW;
12776     startup.wShowWindow = SW_SHOWNORMAL;
12777
12778     thread = CreateThread( NULL, 0, wait_idle_thread, NULL, 0, &id );
12779
12780     for (i = 0; i < sizeof(wait_idle_expect)/sizeof(wait_idle_expect[0]); i++)
12781     {
12782         ResetEvent( start_event );
12783         ResetEvent( end_event );
12784         sprintf( path, "%s msg %u", argv0, i );
12785         ret = CreateProcessA( NULL, path, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &pi );
12786         ok( ret, "CreateProcess '%s' failed err %u.\n", path, GetLastError() );
12787         if (ret)
12788         {
12789             ret = WaitForSingleObject( start_event, 5000 );
12790             ok( ret == WAIT_OBJECT_0, "%u: WaitForSingleObject failed\n", i );
12791             if (ret == WAIT_OBJECT_0)
12792             {
12793                 ret = WaitForInputIdle( pi.hProcess, 1000 );
12794                 if (ret == WAIT_FAILED)
12795                     ok( console_app ||
12796                         ret == wait_idle_expect[i].exp ||
12797                         broken(ret == wait_idle_expect[i].broken),
12798                         "%u: WaitForInputIdle error %08x expected %08x\n",
12799                         i, ret, wait_idle_expect[i].exp );
12800                 else if (wait_idle_expect[i].todo)
12801                     todo_wine
12802                     ok( ret == wait_idle_expect[i].exp || broken(ret == wait_idle_expect[i].broken),
12803                         "%u: WaitForInputIdle error %08x expected %08x\n",
12804                         i, ret, wait_idle_expect[i].exp );
12805                 else
12806                     ok( ret == wait_idle_expect[i].exp || broken(ret == wait_idle_expect[i].broken),
12807                         "%u: WaitForInputIdle error %08x expected %08x\n",
12808                         i, ret, wait_idle_expect[i].exp );
12809                 SetEvent( end_event );
12810                 WaitForSingleObject( pi.hProcess, 1000 );  /* give it a chance to exit on its own */
12811             }
12812             TerminateProcess( pi.hProcess, 0 );  /* just in case */
12813             winetest_wait_child_process( pi.hProcess );
12814             ret = WaitForInputIdle( pi.hProcess, 100 );
12815             ok( ret == WAIT_FAILED, "%u: WaitForInputIdle after exit error %08x\n", i, ret );
12816             CloseHandle( pi.hProcess );
12817             CloseHandle( pi.hThread );
12818         }
12819     }
12820     CloseHandle( start_event );
12821     PostThreadMessage( id, WM_QUIT, 0, 0 );
12822     WaitForSingleObject( thread, 10000 );
12823     CloseHandle( thread );
12824 }
12825
12826 static const struct message WmSetParentSeq_1[] = {
12827     { WM_SHOWWINDOW, sent|wparam, 0 },
12828     { EVENT_OBJECT_PARENTCHANGE, winevent_hook|wparam|lparam, 0, 0 },
12829     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
12830     { WM_CHILDACTIVATE, sent },
12831     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW|SWP_NOCLIENTSIZE },
12832     { WM_MOVE, sent|defwinproc|wparam, 0 },
12833     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
12834     { WM_SHOWWINDOW, sent|wparam, 1 },
12835     { 0 }
12836 };
12837
12838 static const struct message WmSetParentSeq_2[] = {
12839     { WM_SHOWWINDOW, sent|wparam, 0 },
12840     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
12841     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
12842     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
12843     { HCBT_SETFOCUS, hook|optional },
12844     { WM_NCACTIVATE, sent|wparam|optional, 0 },
12845     { WM_ACTIVATE, sent|wparam|optional, 0 },
12846     { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
12847     { WM_KILLFOCUS, sent|wparam, 0 },
12848     { EVENT_OBJECT_PARENTCHANGE, winevent_hook|wparam|lparam, 0, 0 },
12849     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
12850     { HCBT_ACTIVATE, hook },
12851     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
12852     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
12853     { WM_NCACTIVATE, sent|wparam|optional, 1 },
12854     { WM_ACTIVATE, sent|wparam|optional, 1 },
12855     { HCBT_SETFOCUS, hook },
12856     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
12857     { WM_SETFOCUS, sent|optional|defwinproc },
12858     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOREDRAW|SWP_NOSIZE|SWP_NOCLIENTSIZE },
12859     { WM_MOVE, sent|defwinproc|wparam, 0 },
12860     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
12861     { WM_SHOWWINDOW, sent|wparam, 1 },
12862     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
12863     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
12864     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
12865     { 0 }
12866 };
12867
12868
12869 static void test_SetParent(void)
12870 {
12871     HWND parent1, parent2, child, popup;
12872     RECT rc, rc_old;
12873
12874     parent1 = CreateWindowEx(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW,
12875                             100, 100, 200, 200, 0, 0, 0, NULL);
12876     ok(parent1 != 0, "Failed to create parent1 window\n");
12877
12878     parent2 = CreateWindowEx(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW,
12879                             400, 100, 200, 200, 0, 0, 0, NULL);
12880     ok(parent2 != 0, "Failed to create parent2 window\n");
12881
12882     /* WS_CHILD window */
12883     child = CreateWindowEx(0, "TestWindowClass", NULL, WS_CHILD | WS_VISIBLE,
12884                            10, 10, 150, 150, parent1, 0, 0, NULL);
12885     ok(child != 0, "Failed to create child window\n");
12886
12887     GetWindowRect(parent1, &rc);
12888     trace("parent1 (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
12889     GetWindowRect(child, &rc_old);
12890     MapWindowPoints(0, parent1, (POINT *)&rc_old, 2);
12891     trace("child (%d,%d)-(%d,%d)\n", rc_old.left, rc_old.top, rc_old.right, rc_old.bottom);
12892
12893     flush_sequence();
12894
12895     SetParent(child, parent2);
12896     flush_events();
12897     ok_sequence(WmSetParentSeq_1, "SetParent() visible WS_CHILD", TRUE);
12898
12899     ok(GetWindowLongA(child, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
12900     ok(!IsWindowVisible(child), "IsWindowVisible() should return FALSE\n");
12901
12902     GetWindowRect(parent2, &rc);
12903     trace("parent2 (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
12904     GetWindowRect(child, &rc);
12905     MapWindowPoints(0, parent2, (POINT *)&rc, 2);
12906     trace("child (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
12907
12908     ok(EqualRect(&rc_old, &rc), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
12909        rc_old.left, rc_old.top, rc_old.right, rc_old.bottom,
12910        rc.left, rc.top, rc.right, rc.bottom );
12911
12912     /* WS_POPUP window */
12913     popup = CreateWindowEx(0, "TestWindowClass", NULL, WS_POPUP | WS_VISIBLE,
12914                            20, 20, 100, 100, 0, 0, 0, NULL);
12915     ok(popup != 0, "Failed to create popup window\n");
12916
12917     GetWindowRect(popup, &rc_old);
12918     trace("popup (%d,%d)-(%d,%d)\n", rc_old.left, rc_old.top, rc_old.right, rc_old.bottom);
12919
12920     flush_sequence();
12921
12922     SetParent(popup, child);
12923     flush_events();
12924     ok_sequence(WmSetParentSeq_2, "SetParent() visible WS_POPUP", TRUE);
12925
12926     ok(GetWindowLongA(popup, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
12927     ok(!IsWindowVisible(popup), "IsWindowVisible() should return FALSE\n");
12928
12929     GetWindowRect(child, &rc);
12930     trace("parent2 (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
12931     GetWindowRect(popup, &rc);
12932     MapWindowPoints(0, child, (POINT *)&rc, 2);
12933     trace("popup (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
12934
12935     ok(EqualRect(&rc_old, &rc), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
12936        rc_old.left, rc_old.top, rc_old.right, rc_old.bottom,
12937        rc.left, rc.top, rc.right, rc.bottom );
12938
12939     DestroyWindow(popup);
12940     DestroyWindow(child);
12941     DestroyWindow(parent1);
12942     DestroyWindow(parent2);
12943
12944     flush_sequence();
12945 }
12946
12947 static const struct message WmKeyReleaseOnly[] = {
12948     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 0x41, 0x80000001 },
12949     { WM_KEYUP, sent|wparam|lparam, 0x41, 0x80000001 },
12950     { 0 }
12951 };
12952 static const struct message WmKeyPressNormal[] = {
12953     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 0x41, 0x1 },
12954     { WM_KEYDOWN, sent|wparam|lparam, 0x41, 0x1 },
12955     { 0 }
12956 };
12957 static const struct message WmKeyPressRepeat[] = {
12958     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 0x41, 0x40000001 },
12959     { WM_KEYDOWN, sent|wparam|lparam, 0x41, 0x40000001 },
12960     { 0 }
12961 };
12962 static const struct message WmKeyReleaseNormal[] = {
12963     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 0x41, 0xc0000001 },
12964     { WM_KEYUP, sent|wparam|lparam, 0x41, 0xc0000001 },
12965     { 0 }
12966 };
12967
12968 static void test_keyflags(void)
12969 {
12970     HWND test_window;
12971     SHORT key_state;
12972     BYTE keyboard_state[256];
12973     MSG msg;
12974
12975     test_window = CreateWindowEx(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
12976                            100, 100, 200, 200, 0, 0, 0, NULL);
12977
12978     flush_sequence();
12979
12980     /* keyup without a keydown */
12981     keybd_event(0x41, 0, KEYEVENTF_KEYUP, 0);
12982     while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
12983         DispatchMessage(&msg);
12984     ok_sequence(WmKeyReleaseOnly, "key release only", TRUE);
12985
12986     key_state = GetAsyncKeyState(0x41);
12987     ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
12988
12989     key_state = GetKeyState(0x41);
12990     ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
12991
12992     /* keydown */
12993     keybd_event(0x41, 0, 0, 0);
12994     while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
12995         DispatchMessage(&msg);
12996     ok_sequence(WmKeyPressNormal, "key press only", FALSE);
12997
12998     key_state = GetAsyncKeyState(0x41);
12999     ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13000
13001     key_state = GetKeyState(0x41);
13002     ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13003
13004     /* keydown repeat */
13005     keybd_event(0x41, 0, 0, 0);
13006     while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13007         DispatchMessage(&msg);
13008     ok_sequence(WmKeyPressRepeat, "key press repeat", FALSE);
13009
13010     key_state = GetAsyncKeyState(0x41);
13011     ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13012
13013     key_state = GetKeyState(0x41);
13014     ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13015
13016     /* keyup */
13017     keybd_event(0x41, 0, KEYEVENTF_KEYUP, 0);
13018     while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13019         DispatchMessage(&msg);
13020     ok_sequence(WmKeyReleaseNormal, "key release repeat", FALSE);
13021
13022     key_state = GetAsyncKeyState(0x41);
13023     ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13024
13025     key_state = GetKeyState(0x41);
13026     ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13027
13028     /* set the key state in this thread */
13029     GetKeyboardState(keyboard_state);
13030     keyboard_state[0x41] = 0x80;
13031     SetKeyboardState(keyboard_state);
13032
13033     key_state = GetAsyncKeyState(0x41);
13034     ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13035
13036     /* keydown */
13037     keybd_event(0x41, 0, 0, 0);
13038     while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13039         DispatchMessage(&msg);
13040     ok_sequence(WmKeyPressRepeat, "key press after setkeyboardstate", TRUE);
13041
13042     key_state = GetAsyncKeyState(0x41);
13043     ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13044
13045     key_state = GetKeyState(0x41);
13046     ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13047
13048     /* clear the key state in this thread */
13049     GetKeyboardState(keyboard_state);
13050     keyboard_state[0x41] = 0;
13051     SetKeyboardState(keyboard_state);
13052
13053     key_state = GetAsyncKeyState(0x41);
13054     ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13055
13056     /* keyup */
13057     keybd_event(0x41, 0, KEYEVENTF_KEYUP, 0);
13058     while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13059         DispatchMessage(&msg);
13060     ok_sequence(WmKeyReleaseOnly, "key release after setkeyboardstate", TRUE);
13061
13062     key_state = GetAsyncKeyState(0x41);
13063     ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13064
13065     key_state = GetKeyState(0x41);
13066     ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13067
13068     DestroyWindow(test_window);
13069     flush_sequence();
13070 }
13071
13072 static const struct message WmHotkeyPressLWIN[] = {
13073     { WM_KEYDOWN, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED },
13074     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 1 },
13075     { WM_KEYDOWN, sent|wparam|lparam, VK_LWIN, 1 },
13076     { 0 }
13077 };
13078 static const struct message WmHotkeyPress[] = {
13079     { WM_KEYDOWN, kbd_hook|lparam, 0, LLKHF_INJECTED },
13080     { WM_HOTKEY, sent|wparam, 5 },
13081     { 0 }
13082 };
13083 static const struct message WmHotkeyRelease[] = {
13084     { WM_KEYUP, kbd_hook|lparam, 0, LLKHF_INJECTED|LLKHF_UP },
13085     { HCBT_KEYSKIPPED, hook|lparam|optional, 0, 0x80000001 },
13086     { WM_KEYUP, sent|lparam, 0, 0x80000001 },
13087     { 0 }
13088 };
13089 static const struct message WmHotkeyReleaseLWIN[] = {
13090     { WM_KEYUP, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED|LLKHF_UP },
13091     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 0xc0000001 },
13092     { WM_KEYUP, sent|wparam|lparam, VK_LWIN, 0xc0000001 },
13093     { 0 }
13094 };
13095 static const struct message WmHotkeyCombined[] = {
13096     { WM_KEYDOWN, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED },
13097     { WM_KEYDOWN, kbd_hook|lparam, 0, LLKHF_INJECTED },
13098     { WM_KEYUP, kbd_hook|lparam, 0, LLKHF_INJECTED|LLKHF_UP },
13099     { WM_KEYUP, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED|LLKHF_UP },
13100     { WM_APP, sent, 0, 0 },
13101     { WM_HOTKEY, sent|wparam, 5 },
13102     { WM_APP+1, sent, 0, 0 },
13103     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 1 },
13104     { WM_KEYDOWN, sent|wparam|lparam, VK_LWIN, 1 },
13105     { HCBT_KEYSKIPPED, hook|optional, 0, 0x80000001 },
13106     { WM_KEYUP, sent, 0, 0x80000001 }, /* lparam not checked so the sequence isn't a todo */
13107     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 0xc0000001 },
13108     { WM_KEYUP, sent|wparam|lparam, VK_LWIN, 0xc0000001 },
13109     { 0 }
13110 };
13111 static const struct message WmHotkeyPrevious[] = {
13112     { WM_KEYDOWN, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED },
13113     { WM_KEYDOWN, kbd_hook|lparam, 0, LLKHF_INJECTED },
13114     { WM_KEYUP, kbd_hook|lparam, 0, LLKHF_INJECTED|LLKHF_UP },
13115     { WM_KEYUP, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED|LLKHF_UP },
13116     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 1 },
13117     { WM_KEYDOWN, sent|wparam|lparam, VK_LWIN, 1 },
13118     { HCBT_KEYSKIPPED, hook|lparam|optional, 0, 1 },
13119     { WM_KEYDOWN, sent|lparam, 0, 1 },
13120     { HCBT_KEYSKIPPED, hook|optional|lparam, 0, 0xc0000001 },
13121     { WM_KEYUP, sent|lparam, 0, 0xc0000001 },
13122     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 0xc0000001 },
13123     { WM_KEYUP, sent|wparam|lparam, VK_LWIN, 0xc0000001 },
13124     { 0 }
13125 };
13126 static const struct message WmHotkeyNew[] = {
13127     { WM_KEYDOWN, kbd_hook|lparam, 0, LLKHF_INJECTED },
13128     { WM_KEYUP, kbd_hook|lparam, 0, LLKHF_INJECTED|LLKHF_UP },
13129     { WM_HOTKEY, sent|wparam, 5 },
13130     { HCBT_KEYSKIPPED, hook|optional, 0, 0x80000001 },
13131     { WM_KEYUP, sent, 0, 0x80000001 }, /* lparam not checked so the sequence isn't a todo */
13132     { 0 }
13133 };
13134
13135 static int hotkey_letter;
13136
13137 static LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
13138 {
13139     struct recvd_message msg;
13140
13141     if (nCode == HC_ACTION)
13142     {
13143         KBDLLHOOKSTRUCT *kdbhookstruct = (KBDLLHOOKSTRUCT*)lParam;
13144
13145         msg.hwnd = 0;
13146         msg.message = wParam;
13147         msg.flags = kbd_hook|wparam|lparam;
13148         msg.wParam = kdbhookstruct->vkCode;
13149         msg.lParam = kdbhookstruct->flags;
13150         msg.descr = "KeyboardHookProc";
13151         add_message(&msg);
13152
13153         if (wParam == WM_KEYUP || wParam == WM_KEYDOWN)
13154         {
13155             ok(kdbhookstruct->vkCode == VK_LWIN || kdbhookstruct->vkCode == hotkey_letter,
13156                "unexpected keycode %x\n", kdbhookstruct->vkCode);
13157        }
13158     }
13159
13160     return CallNextHookEx(hKBD_hook, nCode, wParam, lParam);
13161 }
13162
13163 static void test_hotkey(void)
13164 {
13165     HWND test_window, taskbar_window;
13166     BOOL ret;
13167     MSG msg;
13168     DWORD queue_status;
13169     SHORT key_state;
13170
13171     SetLastError(0xdeadbeef);
13172     ret = UnregisterHotKey(NULL, 0);
13173     ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13174     ok(GetLastError() == ERROR_HOTKEY_NOT_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13175        "unexpected error %d\n", GetLastError());
13176
13177     if (ret == TRUE)
13178     {
13179         skip("hotkeys not supported\n");
13180         return;
13181     }
13182
13183     test_window = CreateWindowEx(0, "HotkeyWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
13184                            100, 100, 200, 200, 0, 0, 0, NULL);
13185
13186     flush_sequence();
13187
13188     SetLastError(0xdeadbeef);
13189     ret = UnregisterHotKey(test_window, 0);
13190     ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13191     ok(GetLastError() == ERROR_HOTKEY_NOT_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13192        "unexpected error %d\n", GetLastError());
13193
13194     /* Search for a Windows Key + letter combination that hasn't been registered */
13195     for (hotkey_letter = 0x41; hotkey_letter <= 0x51; hotkey_letter ++)
13196     {
13197         SetLastError(0xdeadbeef);
13198         ret = RegisterHotKey(test_window, 5, MOD_WIN, hotkey_letter);
13199
13200         if (ret == TRUE)
13201         {
13202             break;
13203         }
13204         else
13205         {
13206             ok(GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13207                "unexpected error %d\n", GetLastError());
13208         }
13209     }
13210
13211     if (hotkey_letter == 0x52)
13212     {
13213         ok(0, "Couldn't find any free Windows Key + letter combination\n");
13214         goto end;
13215     }
13216
13217     hKBD_hook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProc, GetModuleHandle(NULL), 0);
13218     if (!hKBD_hook) win_skip("WH_KEYBOARD_LL is not supported\n");
13219
13220     /* Same key combination, different id */
13221     SetLastError(0xdeadbeef);
13222     ret = RegisterHotKey(test_window, 4, MOD_WIN, hotkey_letter);
13223     ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13224     ok(GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13225        "unexpected error %d\n", GetLastError());
13226
13227     /* Same key combination, different window */
13228     SetLastError(0xdeadbeef);
13229     ret = RegisterHotKey(NULL, 5, MOD_WIN, hotkey_letter);
13230     ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13231     ok(GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13232        "unexpected error %d\n", GetLastError());
13233
13234     /* Register the same hotkey twice */
13235     SetLastError(0xdeadbeef);
13236     ret = RegisterHotKey(test_window, 5, MOD_WIN, hotkey_letter);
13237     ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13238     ok(GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13239        "unexpected error %d\n", GetLastError());
13240
13241     /* Window on another thread */
13242     taskbar_window = FindWindowA("Shell_TrayWnd", NULL);
13243     if (!taskbar_window)
13244     {
13245         skip("no taskbar?\n");
13246     }
13247     else
13248     {
13249         SetLastError(0xdeadbeef);
13250         ret = RegisterHotKey(taskbar_window, 5, 0, hotkey_letter);
13251         ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13252         ok(GetLastError() == ERROR_WINDOW_OF_OTHER_THREAD || broken(GetLastError() == 0xdeadbeef),
13253            "unexpected error %d\n", GetLastError());
13254     }
13255
13256     /* Inject the appropriate key sequence */
13257     keybd_event(VK_LWIN, 0, 0, 0);
13258     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13259         DispatchMessage(&msg);
13260     ok_sequence(WmHotkeyPressLWIN, "window hotkey press LWIN", FALSE);
13261
13262     keybd_event(hotkey_letter, 0, 0, 0);
13263     queue_status = GetQueueStatus(QS_HOTKEY);
13264     ok((queue_status & (QS_HOTKEY << 16)) == QS_HOTKEY << 16, "expected QS_HOTKEY << 16 set, got %x\n", queue_status);
13265     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13266     {
13267         if (msg.message == WM_HOTKEY)
13268         {
13269             ok(msg.hwnd == test_window, "unexpected hwnd %p\n", msg.hwnd);
13270             ok(msg.lParam == MAKELPARAM(MOD_WIN, hotkey_letter), "unexpected WM_HOTKEY lparam %lx\n", msg.lParam);
13271         }
13272         DispatchMessage(&msg);
13273     }
13274     ok_sequence(WmHotkeyPress, "window hotkey press", FALSE);
13275
13276     queue_status = GetQueueStatus(QS_HOTKEY);
13277     ok((queue_status & (QS_HOTKEY << 16)) == 0, "expected QS_HOTKEY << 16 cleared, got %x\n", queue_status);
13278
13279     key_state = GetAsyncKeyState(hotkey_letter);
13280     ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13281
13282     keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13283     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13284         DispatchMessage(&msg);
13285     ok_sequence(WmHotkeyRelease, "window hotkey release", TRUE);
13286
13287     keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
13288     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13289         DispatchMessage(&msg);
13290     ok_sequence(WmHotkeyReleaseLWIN, "window hotkey release LWIN", FALSE);
13291
13292     /* normal posted WM_HOTKEY messages set QS_HOTKEY */
13293     PostMessage(test_window, WM_HOTKEY, 0, 0);
13294     queue_status = GetQueueStatus(QS_HOTKEY);
13295     ok((queue_status & (QS_HOTKEY << 16)) == QS_HOTKEY << 16, "expected QS_HOTKEY << 16 set, got %x\n", queue_status);
13296     queue_status = GetQueueStatus(QS_POSTMESSAGE);
13297     ok((queue_status & (QS_POSTMESSAGE << 16)) == QS_POSTMESSAGE << 16, "expected QS_POSTMESSAGE << 16 set, got %x\n", queue_status);
13298     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13299         DispatchMessage(&msg);
13300     flush_sequence();
13301
13302     /* Send and process all messages at once */
13303     PostMessage(test_window, WM_APP, 0, 0);
13304     keybd_event(VK_LWIN, 0, 0, 0);
13305     keybd_event(hotkey_letter, 0, 0, 0);
13306     keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13307     keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
13308
13309     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13310     {
13311         if (msg.message == WM_HOTKEY)
13312         {
13313             ok(msg.hwnd == test_window, "unexpected hwnd %p\n", msg.hwnd);
13314             ok(msg.lParam == MAKELPARAM(MOD_WIN, hotkey_letter), "unexpected WM_HOTKEY lparam %lx\n", msg.lParam);
13315         }
13316         DispatchMessage(&msg);
13317     }
13318     ok_sequence(WmHotkeyCombined, "window hotkey combined", FALSE);
13319
13320     /* Register same hwnd/id with different key combination */
13321     ret = RegisterHotKey(test_window, 5, 0, hotkey_letter);
13322     ok(ret == TRUE, "expected TRUE, got %i, err=%d\n", ret, GetLastError());
13323
13324     /* Previous key combination does not work */
13325     keybd_event(VK_LWIN, 0, 0, 0);
13326     keybd_event(hotkey_letter, 0, 0, 0);
13327     keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13328     keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
13329
13330     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13331         DispatchMessage(&msg);
13332     ok_sequence(WmHotkeyPrevious, "window hotkey previous", FALSE);
13333
13334     /* New key combination works */
13335     keybd_event(hotkey_letter, 0, 0, 0);
13336     keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13337
13338     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13339     {
13340         if (msg.message == WM_HOTKEY)
13341         {
13342             ok(msg.hwnd == test_window, "unexpected hwnd %p\n", msg.hwnd);
13343             ok(msg.lParam == MAKELPARAM(0, hotkey_letter), "unexpected WM_HOTKEY lparam %lx\n", msg.lParam);
13344         }
13345         DispatchMessage(&msg);
13346     }
13347     ok_sequence(WmHotkeyNew, "window hotkey new", FALSE);
13348
13349     /* Unregister hotkey properly */
13350     ret = UnregisterHotKey(test_window, 5);
13351     ok(ret == TRUE, "expected TRUE, got %i, err=%d\n", ret, GetLastError());
13352
13353     /* Unregister hotkey again */
13354     SetLastError(0xdeadbeef);
13355     ret = UnregisterHotKey(test_window, 5);
13356     ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13357     ok(GetLastError() == ERROR_HOTKEY_NOT_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13358        "unexpected error %d\n", GetLastError());
13359
13360     /* Register thread hotkey */
13361     ret = RegisterHotKey(NULL, 5, MOD_WIN, hotkey_letter);
13362     ok(ret == TRUE, "expected TRUE, got %i, err=%d\n", ret, GetLastError());
13363
13364     /* Inject the appropriate key sequence */
13365     keybd_event(VK_LWIN, 0, 0, 0);
13366     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13367     {
13368         ok(msg.hwnd != NULL, "unexpected thread message %x\n", msg.message);
13369         DispatchMessage(&msg);
13370     }
13371     ok_sequence(WmHotkeyPressLWIN, "thread hotkey press LWIN", FALSE);
13372
13373     keybd_event(hotkey_letter, 0, 0, 0);
13374     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13375     {
13376         if (msg.message == WM_HOTKEY)
13377         {
13378             struct recvd_message message;
13379             ok(msg.hwnd == NULL, "unexpected hwnd %p\n", msg.hwnd);
13380             ok(msg.lParam == MAKELPARAM(MOD_WIN, hotkey_letter), "unexpected WM_HOTKEY lparam %lx\n", msg.lParam);
13381             message.message = msg.message;
13382             message.flags = sent|wparam|lparam;
13383             message.wParam = msg.wParam;
13384             message.lParam = msg.lParam;
13385             message.descr = "test_hotkey thread message";
13386             add_message(&message);
13387         }
13388         else
13389             ok(msg.hwnd != NULL, "unexpected thread message %x\n", msg.message);
13390         DispatchMessage(&msg);
13391     }
13392     ok_sequence(WmHotkeyPress, "thread hotkey press", FALSE);
13393
13394     keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13395     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13396     {
13397         ok(msg.hwnd != NULL, "unexpected thread message %x\n", msg.message);
13398         DispatchMessage(&msg);
13399     }
13400     ok_sequence(WmHotkeyRelease, "thread hotkey release", TRUE);
13401
13402     keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
13403     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13404     {
13405         ok(msg.hwnd != NULL, "unexpected thread message %x\n", msg.message);
13406         DispatchMessage(&msg);
13407     }
13408     ok_sequence(WmHotkeyReleaseLWIN, "thread hotkey release LWIN", FALSE);
13409
13410     /* Unregister thread hotkey */
13411     ret = UnregisterHotKey(NULL, 5);
13412     ok(ret == TRUE, "expected TRUE, got %i, err=%d\n", ret, GetLastError());
13413
13414     if (hKBD_hook) UnhookWindowsHookEx(hKBD_hook);
13415     hKBD_hook = NULL;
13416
13417 end:
13418     UnregisterHotKey(NULL, 5);
13419     UnregisterHotKey(test_window, 5);
13420     DestroyWindow(test_window);
13421     flush_sequence();
13422 }
13423
13424 START_TEST(msg)
13425 {
13426     char **test_argv;
13427     BOOL ret;
13428     BOOL (WINAPI *pIsWinEventHookInstalled)(DWORD)= 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
13429     HMODULE hModuleImm32;
13430     BOOL (WINAPI *pImmDisableIME)(DWORD);
13431
13432     int argc = winetest_get_mainargs( &test_argv );
13433     if (argc >= 3)
13434     {
13435         unsigned int arg;
13436         /* Child process. */
13437         sscanf (test_argv[2], "%d", (unsigned int *) &arg);
13438         do_wait_idle_child( arg );
13439         return;
13440     }
13441
13442     init_procs();
13443
13444     hModuleImm32 = LoadLibrary("imm32.dll");
13445     if (hModuleImm32) {
13446         pImmDisableIME = (void *)GetProcAddress(hModuleImm32, "ImmDisableIME");
13447         if (pImmDisableIME)
13448             pImmDisableIME(0);
13449     }
13450     pImmDisableIME = NULL;
13451     FreeLibrary(hModuleImm32);
13452
13453     if (!RegisterWindowClasses()) assert(0);
13454
13455     if (pSetWinEventHook)
13456     {
13457         hEvent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX,
13458                                        GetModuleHandleA(0), win_event_proc,
13459                                        0, GetCurrentThreadId(),
13460                                        WINEVENT_INCONTEXT);
13461         if (pIsWinEventHookInstalled && hEvent_hook)
13462         {
13463             UINT event;
13464             for (event = EVENT_MIN; event <= EVENT_MAX; event++)
13465                 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
13466         }
13467     }
13468     if (!hEvent_hook) win_skip( "no win event hook support\n" );
13469
13470     cbt_hook_thread_id = GetCurrentThreadId();
13471     hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
13472     if (!hCBT_hook) win_skip( "cannot set global hook, will skip hook tests\n" );
13473
13474     test_winevents();
13475
13476     /* Fix message sequences before removing 4 lines below */
13477 #if 1
13478     if (pUnhookWinEvent && hEvent_hook)
13479     {
13480         ret = pUnhookWinEvent(hEvent_hook);
13481         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
13482         pUnhookWinEvent = 0;
13483     }
13484     hEvent_hook = 0;
13485 #endif
13486
13487     test_SetParent();
13488     test_PostMessage();
13489     test_ShowWindow();
13490     test_PeekMessage();
13491     test_PeekMessage2();
13492     test_WaitForInputIdle( test_argv[0] );
13493     test_scrollwindowex();
13494     test_messages();
13495     test_setwindowpos();
13496     test_showwindow();
13497     invisible_parent_tests();
13498     test_mdi_messages();
13499     test_button_messages();
13500     test_static_messages();
13501     test_listbox_messages();
13502     test_combobox_messages();
13503     test_wmime_keydown_message();
13504     test_paint_messages();
13505     test_interthread_messages();
13506     test_message_conversion();
13507     test_accelerators();
13508     test_timers();
13509     test_timers_no_wnd();
13510     if (hCBT_hook) test_set_hook();
13511     test_DestroyWindow();
13512     test_DispatchMessage();
13513     test_SendMessageTimeout();
13514     test_edit_messages();
13515     test_quit_message();
13516     test_SetActiveWindow();
13517
13518     if (!pTrackMouseEvent)
13519         win_skip("TrackMouseEvent is not available\n");
13520     else
13521         test_TrackMouseEvent();
13522
13523     test_SetWindowRgn();
13524     test_sys_menu();
13525     test_dialog_messages();
13526     test_nullCallback();
13527     test_dbcs_wm_char();
13528     test_menu_messages();
13529     test_paintingloop();
13530     test_defwinproc();
13531     test_clipboard_viewers();
13532     test_keyflags();
13533     test_hotkey();
13534     /* keep it the last test, under Windows it tends to break the tests
13535      * which rely on active/foreground windows being correct.
13536      */
13537     test_SetForegroundWindow();
13538
13539     UnhookWindowsHookEx(hCBT_hook);
13540     if (pUnhookWinEvent && hEvent_hook)
13541     {
13542         ret = pUnhookWinEvent(hEvent_hook);
13543         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
13544         SetLastError(0xdeadbeef);
13545         ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
13546         ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
13547            GetLastError() == 0xdeadbeef, /* Win9x */
13548            "unexpected error %d\n", GetLastError());
13549     }
13550 }