wined3d: Default to GLSL. This is safe because we now have proper ps2.0/vs2.0 detection.
[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 #include <assert.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26
27 #define _WIN32_WINNT 0x0501 /* For WM_CHANGEUISTATE,QS_RAWINPUT */
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winnls.h"
34
35 #include "wine/test.h"
36
37 #define MDI_FIRST_CHILD_ID 2004
38
39 /* undocumented SWP flags - from SDK 3.1 */
40 #define SWP_NOCLIENTSIZE        0x0800
41 #define SWP_NOCLIENTMOVE        0x1000
42 #define SWP_STATECHANGED        0x8000
43
44 #define SW_NORMALNA             0xCC    /* undoc. flag in MinMaximize */
45
46 #ifndef WM_SYSTIMER
47 #define WM_SYSTIMER         0x0118
48 #endif
49
50 #define WND_PARENT_ID           1
51 #define WND_POPUP_ID            2
52 #define WND_CHILD_ID            3
53
54 #ifndef WM_LBTRACKPOINT
55 #define WM_LBTRACKPOINT  0x0131
56 #endif
57
58 /* encoded DRAWITEMSTRUCT into an LPARAM */
59 typedef struct
60 {
61     union
62     {
63         struct
64         {
65             UINT type    : 4;  /* ODT_* flags */
66             UINT ctl_id  : 4;  /* Control ID */
67             UINT item_id : 4;  /* Menu item ID */
68             UINT action  : 4;  /* ODA_* flags */
69             UINT state   : 16; /* ODS_* flags */
70         } item;
71         LPARAM lp;
72     } u;
73 } DRAW_ITEM_STRUCT;
74
75 static BOOL test_DestroyWindow_flag;
76 static HWINEVENTHOOK hEvent_hook;
77
78 static void dump_winpos_flags(UINT flags);
79
80 static const WCHAR testWindowClassW[] =
81 { 'T','e','s','t','W','i','n','d','o','w','C','l','a','s','s','W',0 };
82
83 /*
84 FIXME: add tests for these
85 Window Edge Styles (Win31/Win95/98 look), in order of precedence:
86  WS_EX_DLGMODALFRAME: double border, WS_CAPTION allowed
87  WS_THICKFRAME: thick border
88  WS_DLGFRAME: double border, WS_CAPTION not allowed (but possibly shown anyway)
89  WS_BORDER (default for overlapped windows): single black border
90  none (default for child (and popup?) windows): no border
91 */
92
93 typedef enum {
94     sent=0x1,
95     posted=0x2,
96     parent=0x4,
97     wparam=0x8,
98     lparam=0x10,
99     defwinproc=0x20,
100     beginpaint=0x40,
101     optional=0x80,
102     hook=0x100,
103     winevent_hook=0x200
104 } msg_flags_t;
105
106 struct message {
107     UINT message;          /* the WM_* code */
108     msg_flags_t flags;     /* message props */
109     WPARAM wParam;         /* expected value of wParam */
110     LPARAM lParam;         /* expected value of lParam */
111 };
112
113 /* Empty message sequence */
114 static const struct message WmEmptySeq[] =
115 {
116     { 0 }
117 };
118 /* CreateWindow (for overlapped window, not initially visible) (16/32) */
119 static const struct message WmCreateOverlappedSeq[] = {
120     { HCBT_CREATEWND, hook },
121     { WM_GETMINMAXINFO, sent },
122     { WM_NCCREATE, sent },
123     { WM_NCCALCSIZE, sent|wparam, 0 },
124     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
125     { WM_CREATE, sent },
126     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
127     { 0 }
128 };
129 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
130  * for a not visible overlapped window.
131  */
132 static const struct message WmSWP_ShowOverlappedSeq[] = {
133     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
134     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
135     { WM_NCPAINT, sent|wparam|optional, 1 },
136     { WM_GETTEXT, sent|defwinproc|optional },
137     { WM_ERASEBKGND, sent|optional },
138     { HCBT_ACTIVATE, hook },
139     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
140     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
141     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x: SWP_NOSENDCHANGING */
142     { WM_ACTIVATEAPP, sent|wparam, 1 },
143     { WM_NCACTIVATE, sent|wparam, 1 },
144     { WM_GETTEXT, sent|defwinproc|optional },
145     { WM_ACTIVATE, sent|wparam, 1 },
146     { HCBT_SETFOCUS, hook },
147     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
148     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
149     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
150     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
151     { WM_NCPAINT, sent|wparam|optional, 1 },
152     { WM_GETTEXT, sent|defwinproc|optional },
153     { WM_ERASEBKGND, sent|optional },
154     /* Win9x adds SWP_NOZORDER below */
155     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
156     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
157     { WM_NCPAINT, sent|wparam|optional, 1 },
158     { WM_ERASEBKGND, sent|optional },
159     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
160     { 0 }
161 };
162 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
163  * for a visible overlapped window.
164  */
165 static const struct message WmSWP_HideOverlappedSeq[] = {
166     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
167     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
168     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
169     { 0 }
170 };
171
172 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
173  * for a visible overlapped window.
174  */
175 static const struct message WmSWP_ResizeSeq[] = {
176     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
177     { WM_GETMINMAXINFO, sent|defwinproc },
178     { WM_NCCALCSIZE, sent|wparam, TRUE },
179     { WM_NCPAINT, sent|optional },
180     { WM_GETTEXT, sent|defwinproc|optional },
181     { WM_ERASEBKGND, sent|optional },
182     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
183     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
184     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
185     { WM_NCPAINT, sent|optional },
186     { WM_GETTEXT, sent|defwinproc|optional },
187     { WM_ERASEBKGND, sent|optional },
188     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
189     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
190     { 0 }
191 };
192
193 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
194  * for a visible popup window.
195  */
196 static const struct message WmSWP_ResizePopupSeq[] = {
197     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
198     { WM_GETMINMAXINFO, sent|defwinproc|optional }, /* Win9x */
199     { WM_NCCALCSIZE, sent|wparam, TRUE },
200     { WM_NCPAINT, sent|optional },
201     { WM_GETTEXT, sent|defwinproc|optional },
202     { WM_ERASEBKGND, sent|optional },
203     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
204     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
205     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
206     { WM_NCPAINT, sent|optional },
207     { WM_GETTEXT, sent|defwinproc|optional },
208     { WM_ERASEBKGND, sent|optional },
209     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
210     { 0 }
211 };
212
213 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
214  * for a visible overlapped window.
215  */
216 static const struct message WmSWP_MoveSeq[] = {
217     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE },
218     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
219     { WM_MOVE, sent|defwinproc|wparam, 0 },
220     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
221     { 0 }
222 };
223 /* Resize with SetWindowPos(SWP_NOZORDER)
224  * for a visible overlapped window
225  * SWP_NOZORDER is stripped by the logging code
226  */
227 static const struct message WmSWP_ResizeNoZOrder[] = {
228     { WM_WINDOWPOSCHANGING, sent|wparam, 0/*SWP_NOZORDER*/ },
229     { WM_GETMINMAXINFO, sent|defwinproc },
230     { WM_NCCALCSIZE, sent|wparam, 1 },
231     { WM_NCPAINT, sent },
232     { WM_GETTEXT, sent|defwinproc|optional },
233     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
234     { WM_WINDOWPOSCHANGED, sent|wparam, /*SWP_NOZORDER|*/SWP_NOMOVE|SWP_NOCLIENTMOVE },
235     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
236     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
237     { WM_NCPAINT, sent|optional }, /* Win9x doesn't send it */
238     { WM_GETTEXT, sent|defwinproc|optional }, /* Win9x doesn't send it */
239     { WM_ERASEBKGND, sent|optional }, /* Win9x doesn't send it */
240     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
241     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
242     { 0 }
243 };
244
245 /* Switch visible mdi children */
246 static const struct message WmSwitchChild[] = {
247     /* Switch MDI child */
248     { WM_MDIACTIVATE, sent },/* in the MDI client */
249     { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 1st MDI child */
250     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
251     { WM_CHILDACTIVATE, sent },/* in the 1st MDI child */
252     /* Deactivate 2nd MDI child */
253     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
254     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
255     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
256     /* Preparing for maximize and maximaze the 1st MDI child */
257     { WM_GETMINMAXINFO, sent|defwinproc }, /* in the 1st MDI child */
258     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED }, /* in the 1st MDI child */
259     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
260     { WM_CHILDACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
261     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 }, /* in the 1st MDI child */
262     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED }, /* in the 1st MDI child */
263     /* Lock redraw 2nd MDI child */
264     { WM_SETREDRAW, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
265     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
266     /* Restore 2nd MDI child */
267     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|0x8000 },/* in the 2nd MDI child */
268     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
269     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
270     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 }, /* in the 2nd MDI child */
271     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED }, /* in the 2nd MDI child */
272     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
273     /* Redraw 2nd MDI child */
274     { WM_SETREDRAW, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
275     /* Redraw MDI frame */
276     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },/* in MDI frame */
277     { WM_NCCALCSIZE, sent|wparam, 1 },/* in MDI frame */
278     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in MDI frame */
279     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in MDI frame */
280     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
281     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
282     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
283     { HCBT_SETFOCUS, hook },
284     { WM_KILLFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
285     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },/* in the 1st MDI child */
286     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
287     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
288     { WM_SETFOCUS, sent },/* in the MDI client */
289     { HCBT_SETFOCUS, hook },
290     { WM_KILLFOCUS, sent },/* in the MDI client */
291     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
292     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 }, /* in the 1st MDI child */
293     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
294     { WM_SETFOCUS, sent|defwinproc }, /* in the 1st MDI child */
295     { WM_MDIACTIVATE, sent|defwinproc },/* in the 1st MDI child */
296     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* in the 1st MDI child */
297     { 0 }
298 };
299
300 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
301                 SWP_NOZORDER|SWP_FRAMECHANGED)
302  * for a visible overlapped window with WS_CLIPCHILDREN style set.
303  */
304 static const struct message WmSWP_FrameChanged_clip[] = {
305     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
306     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
307     { WM_NCPAINT, sent|parent }, /* wparam != 1 */
308     { WM_GETTEXT, sent|parent|defwinproc|optional },
309     { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
310     { WM_NCPAINT, sent }, /* wparam != 1 */
311     { WM_ERASEBKGND, sent },
312     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
313     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
314     { WM_PAINT, sent },
315     { 0 }
316 };
317 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|
318                 SWP_NOZORDER|SWP_FRAMECHANGED)
319  * for a visible overlapped window.
320  */
321 static const struct message WmSWP_FrameChangedDeferErase[] = {
322     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
323     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
324     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
325     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
326     { WM_PAINT, sent|parent },
327     { WM_NCPAINT, sent|beginpaint|parent }, /* wparam != 1 */
328     { WM_GETTEXT, sent|beginpaint|parent|defwinproc|optional },
329     { WM_PAINT, sent },
330     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
331     { WM_ERASEBKGND, sent|beginpaint },
332     { 0 }
333 };
334
335 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
336                 SWP_NOZORDER|SWP_FRAMECHANGED)
337  * for a visible overlapped window without WS_CLIPCHILDREN style set.
338  */
339 static const struct message WmSWP_FrameChanged_noclip[] = {
340     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
341     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
342     { WM_NCPAINT, sent|parent }, /* wparam != 1 */
343     { WM_GETTEXT, sent|parent|defwinproc|optional },
344     { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
345     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
346     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
347     { WM_PAINT, sent },
348     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
349     { WM_ERASEBKGND, sent|beginpaint },
350     { 0 }
351 };
352
353 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
354 static const struct message WmShowOverlappedSeq[] = {
355     { WM_SHOWWINDOW, sent|wparam, 1 },
356     { WM_NCPAINT, sent|wparam|optional, 1 },
357     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
358     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
359     { WM_NCPAINT, sent|wparam|optional, 1 },
360     { WM_GETTEXT, sent|defwinproc|optional },
361     { WM_ERASEBKGND, sent|optional },
362     { HCBT_ACTIVATE, hook },
363     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
364     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
365     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
366     { WM_NCPAINT, sent|wparam|optional, 1 },
367     { WM_ACTIVATEAPP, sent|wparam, 1 },
368     { WM_NCACTIVATE, sent|wparam, 1 },
369     { WM_GETTEXT, sent|defwinproc|optional },
370     { WM_ACTIVATE, sent|wparam, 1 },
371     { HCBT_SETFOCUS, hook },
372     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
373     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
374     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
375     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
376     { WM_NCPAINT, sent|wparam|optional, 1 },
377     { WM_GETTEXT, sent|defwinproc|optional },
378     { WM_ERASEBKGND, sent|optional },
379     /* Win9x adds SWP_NOZORDER below */
380     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
381     { WM_NCCALCSIZE, sent|optional },
382     { WM_NCPAINT, sent|optional },
383     { WM_ERASEBKGND, sent|optional },
384 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
385        * messages. Does that mean that CreateWindow doesn't set initial
386        * window dimensions for overlapped windows?
387        */
388     { WM_SIZE, sent },
389     { WM_MOVE, sent },
390 #endif
391     { 0 }
392 };
393 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible overlapped window */
394 static const struct message WmShowMaxOverlappedSeq[] = {
395     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
396     { WM_GETMINMAXINFO, sent },
397     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
398     { WM_GETMINMAXINFO, sent|defwinproc },
399     { WM_NCCALCSIZE, sent|wparam, TRUE },
400     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
401     { HCBT_ACTIVATE, hook },
402     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
403     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
404     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
405     { WM_ACTIVATEAPP, sent|wparam, 1 },
406     { WM_NCACTIVATE, sent|wparam, 1 },
407     { WM_GETTEXT, sent|defwinproc|optional },
408     { WM_ACTIVATE, sent|wparam, 1 },
409     { HCBT_SETFOCUS, hook },
410     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
411     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
412     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
413     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
414     { WM_NCPAINT, sent|wparam|optional, 1 },
415     { WM_GETTEXT, sent|defwinproc|optional },
416     { WM_ERASEBKGND, sent|optional },
417     /* Win9x adds SWP_NOZORDER below */
418     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
419     { WM_MOVE, sent|defwinproc },
420     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
421     { WM_NCCALCSIZE, sent|optional },
422     { WM_NCPAINT, sent|optional },
423     { WM_ERASEBKGND, sent|optional },
424     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
425     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
426     { 0 }
427 };
428 /* ShowWindow(SW_SHOWMINIMIZED) for a not visible overlapped window */
429 static const struct message WmShowMinOverlappedSeq[] = {
430     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
431     { HCBT_SETFOCUS, hook },
432     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
433     { WM_KILLFOCUS, sent },
434     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
435     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
436     { WM_GETTEXT, sent|optional },
437     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCOPYBITS|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
438     { WM_GETMINMAXINFO, sent|defwinproc },
439     { WM_NCCALCSIZE, sent|wparam, TRUE },
440     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
441     { WM_NCPAINT, sent },
442     { WM_GETTEXT, sent|defwinproc|optional },
443     { WM_WINDOWPOSCHANGED, sent },
444     { WM_MOVE, sent|defwinproc },
445     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
446     { WM_NCCALCSIZE, sent|optional },
447     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
448     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
449     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
450     { WM_NCACTIVATE, sent|wparam, 0 },
451     { WM_GETTEXT, sent|defwinproc|optional },
452     { WM_ACTIVATE, sent },
453     { WM_ACTIVATEAPP, sent|wparam, 0 },
454     { 0 }
455 };
456 /* ShowWindow(SW_HIDE) for a visible overlapped window */
457 static const struct message WmHideOverlappedSeq[] = {
458     { WM_SHOWWINDOW, sent|wparam, 0 },
459     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
460     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
461     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
462     { WM_SIZE, sent|optional }, /* XP doesn't send it */
463     { WM_MOVE, sent|optional }, /* XP doesn't send it */
464     { WM_NCACTIVATE, sent|wparam, 0 },
465     { WM_ACTIVATE, sent|wparam, 0 },
466     { WM_ACTIVATEAPP, sent|wparam, 0 },
467     { WM_KILLFOCUS, sent|wparam, 0 },
468     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
469     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
470     { 0 }
471 };
472 /* DestroyWindow for a visible overlapped window */
473 static const struct message WmDestroyOverlappedSeq[] = {
474     { HCBT_DESTROYWND, hook },
475     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
476     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
477     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
478     { WM_NCACTIVATE, sent|wparam, 0 },
479     { WM_ACTIVATE, sent|wparam, 0 },
480     { WM_ACTIVATEAPP, sent|wparam, 0 },
481     { WM_KILLFOCUS, sent|wparam, 0 },
482     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
483     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
484     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
485     { WM_DESTROY, sent },
486     { WM_NCDESTROY, sent },
487     { 0 }
488 };
489 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
490 static const struct message WmCreateMaxPopupSeq[] = {
491     { HCBT_CREATEWND, hook },
492     { WM_NCCREATE, sent },
493     { WM_NCCALCSIZE, sent|wparam, 0 },
494     { WM_CREATE, sent },
495     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
496     { WM_SIZE, sent|wparam, SIZE_RESTORED },
497     { WM_MOVE, sent },
498     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
499     { WM_GETMINMAXINFO, sent },
500     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|0x8000 },
501     { WM_NCCALCSIZE, sent|wparam, TRUE },
502     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|0x8000 },
503     { WM_MOVE, sent|defwinproc },
504     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
505     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
506     { WM_SHOWWINDOW, sent|wparam, 1 },
507     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
508     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
509     { HCBT_ACTIVATE, hook },
510     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
511     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
512     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
513     { WM_ACTIVATEAPP, sent|wparam, 1 },
514     { WM_NCACTIVATE, sent|wparam, 1 },
515     { WM_ACTIVATE, sent|wparam, 1 },
516     { HCBT_SETFOCUS, hook },
517     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
518     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
519     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
520     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
521     { WM_SYNCPAINT, sent|wparam|optional, 4 },
522     { WM_NCPAINT, sent|wparam|optional, 1 },
523     { WM_ERASEBKGND, sent|optional },
524     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
525     { 0 }
526 };
527 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
528 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
529     { HCBT_CREATEWND, hook },
530     { WM_NCCREATE, sent },
531     { WM_NCCALCSIZE, sent|wparam, 0 },
532     { WM_CREATE, sent },
533     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
534     { WM_SIZE, sent|wparam, SIZE_RESTORED },
535     { WM_MOVE, sent },
536     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
537     { WM_GETMINMAXINFO, sent },
538     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|0x8000 },
539     { WM_NCCALCSIZE, sent|wparam, TRUE },
540     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|0x8000 },
541     { WM_MOVE, sent|defwinproc },
542     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
543     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
544     { 0 }
545 };
546 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
547 static const struct message WmShowMaxPopupResizedSeq[] = {
548     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
549     { WM_GETMINMAXINFO, sent },
550     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
551     { WM_NCCALCSIZE, sent|wparam, TRUE },
552     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
553     { HCBT_ACTIVATE, hook },
554     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
555     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
556     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
557     { WM_ACTIVATEAPP, sent|wparam, 1 },
558     { WM_NCACTIVATE, sent|wparam, 1 },
559     { WM_ACTIVATE, sent|wparam, 1 },
560     { HCBT_SETFOCUS, hook },
561     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
562     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
563     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
564     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
565     { WM_NCPAINT, sent|wparam|optional, 1 },
566     { WM_ERASEBKGND, sent|optional },
567     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE },
568     /* WinNT4.0 sends WM_MOVE */
569     { WM_MOVE, sent|defwinproc|optional },
570     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
571     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
572     { 0 }
573 };
574 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
575 static const struct message WmShowMaxPopupSeq[] = {
576     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
577     { WM_GETMINMAXINFO, sent },
578     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
579     { WM_NCCALCSIZE, sent|wparam, TRUE },
580     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
581     { HCBT_ACTIVATE, hook },
582     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
583     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
584     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
585     { WM_ACTIVATEAPP, sent|wparam, 1 },
586     { WM_NCACTIVATE, sent|wparam, 1 },
587     { WM_ACTIVATE, sent|wparam, 1 },
588     { HCBT_SETFOCUS, hook },
589     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
590     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
591     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
592     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
593     { WM_SYNCPAINT, sent|wparam|optional, 4 },
594     { WM_NCPAINT, sent|wparam|optional, 1 },
595     { WM_ERASEBKGND, sent|optional },
596     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
597     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
598     { 0 }
599 };
600 /* CreateWindow(WS_VISIBLE) for popup window */
601 static const struct message WmCreatePopupSeq[] = {
602     { HCBT_CREATEWND, hook },
603     { WM_NCCREATE, sent },
604     { WM_NCCALCSIZE, sent|wparam, 0 },
605     { WM_CREATE, sent },
606     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
607     { WM_SIZE, sent|wparam, SIZE_RESTORED },
608     { WM_MOVE, sent },
609     { WM_SHOWWINDOW, sent|wparam, 1 },
610     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
611     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
612     { HCBT_ACTIVATE, hook },
613     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
614     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
615     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
616     { WM_NCPAINT, sent|wparam|optional, 1 },
617     { WM_ERASEBKGND, sent|optional },
618     { WM_ACTIVATEAPP, sent|wparam, 1 },
619     { WM_NCACTIVATE, sent|wparam, 1 },
620     { WM_ACTIVATE, sent|wparam, 1 },
621     { HCBT_SETFOCUS, hook },
622     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
623     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
624     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
625     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
626     { WM_SYNCPAINT, sent|wparam|optional, 4 },
627     { WM_NCPAINT, sent|wparam|optional, 1 },
628     { WM_ERASEBKGND, sent|optional },
629     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
630     { 0 }
631 };
632 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
633 static const struct message WmShowVisMaxPopupSeq[] = {
634     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
635     { WM_GETMINMAXINFO, sent },
636     { WM_GETTEXT, sent|optional },
637     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
638     { WM_NCCALCSIZE, sent|wparam, TRUE },
639     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
640     { WM_NCPAINT, sent|wparam|optional, 1 },
641     { WM_ERASEBKGND, sent|optional },
642     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|0x8000 },
643     { WM_MOVE, sent|defwinproc },
644     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
645     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
646     { 0 }
647 };
648 /* CreateWindow (for a child popup window, not initially visible) */
649 static const struct message WmCreateChildPopupSeq[] = {
650     { HCBT_CREATEWND, hook },
651     { WM_NCCREATE, sent }, 
652     { WM_NCCALCSIZE, sent|wparam, 0 },
653     { WM_CREATE, sent },
654     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
655     { WM_SIZE, sent|wparam, SIZE_RESTORED },
656     { WM_MOVE, sent },
657     { 0 }
658 };
659 /* CreateWindow (for a popup window, not initially visible,
660  * which sets WS_VISIBLE in WM_CREATE handler)
661  */
662 static const struct message WmCreateInvisiblePopupSeq[] = {
663     { HCBT_CREATEWND, hook },
664     { WM_NCCREATE, sent }, 
665     { WM_NCCALCSIZE, sent|wparam, 0 },
666     { WM_CREATE, sent },
667     { WM_STYLECHANGING, sent },
668     { WM_STYLECHANGED, sent },
669     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
670     { WM_SIZE, sent|wparam, SIZE_RESTORED },
671     { WM_MOVE, sent },
672     { 0 }
673 };
674 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
675  * for a popup window with WS_VISIBLE style set
676  */
677 static const struct message WmShowVisiblePopupSeq_2[] = {
678     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
679     { 0 }
680 };
681 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
682  * for a popup window with WS_VISIBLE style set
683  */
684 static const struct message WmShowVisiblePopupSeq_3[] = {
685     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
686     { HCBT_ACTIVATE, hook },
687     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
688     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
689     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
690     { WM_NCACTIVATE, sent|wparam, 1 },
691     { WM_ACTIVATE, sent|wparam, 1 },
692     { HCBT_SETFOCUS, hook },
693     { WM_KILLFOCUS, sent|parent },
694     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
695     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
696     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
697     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
698     { WM_SETFOCUS, sent|defwinproc },
699     { 0 }
700 };
701 /* CreateWindow (for child window, not initially visible) */
702 static const struct message WmCreateChildSeq[] = {
703     { HCBT_CREATEWND, hook },
704     { WM_NCCREATE, sent }, 
705     /* child is inserted into parent's child list after WM_NCCREATE returns */
706     { WM_NCCALCSIZE, sent|wparam, 0 },
707     { WM_CREATE, sent },
708     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
709     { WM_SIZE, sent|wparam, SIZE_RESTORED },
710     { WM_MOVE, sent },
711     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
712     { 0 }
713 };
714 /* CreateWindow (for maximized child window, not initially visible) */
715 static const struct message WmCreateMaximizedChildSeq[] = {
716     { HCBT_CREATEWND, hook },
717     { WM_NCCREATE, sent }, 
718     { WM_NCCALCSIZE, sent|wparam, 0 },
719     { WM_CREATE, sent },
720     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
721     { WM_SIZE, sent|wparam, SIZE_RESTORED },
722     { WM_MOVE, sent },
723     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
724     { WM_GETMINMAXINFO, sent },
725     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
726     { WM_NCCALCSIZE, sent|wparam, 1 },
727     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|0x8000 },
728     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
729     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
730     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
731     { 0 }
732 };
733 /* CreateWindow (for a child window, initially visible) */
734 static const struct message WmCreateVisibleChildSeq[] = {
735     { HCBT_CREATEWND, hook },
736     { WM_NCCREATE, sent }, 
737     /* child is inserted into parent's child list after WM_NCCREATE returns */
738     { WM_NCCALCSIZE, sent|wparam, 0 },
739     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
740     { WM_CREATE, sent },
741     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
742     { WM_SIZE, sent|wparam, SIZE_RESTORED },
743     { WM_MOVE, sent },
744     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
745     { WM_SHOWWINDOW, sent|wparam, 1 },
746     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
747     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
748     { WM_ERASEBKGND, sent|parent|optional },
749     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
750     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
751     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
752     { 0 }
753 };
754 /* ShowWindow(SW_SHOW) for a not visible child window */
755 static const struct message WmShowChildSeq[] = {
756     { WM_SHOWWINDOW, sent|wparam, 1 },
757     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
758     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
759     { WM_ERASEBKGND, sent|parent|optional },
760     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
761     { 0 }
762 };
763 /* ShowWindow(SW_HIDE) for a visible child window */
764 static const struct message WmHideChildSeq[] = {
765     { WM_SHOWWINDOW, sent|wparam, 0 },
766     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
767     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
768     { WM_ERASEBKGND, sent|parent|optional },
769     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
770     { 0 }
771 };
772 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
773 static const struct message WmHideChildSeq2[] = {
774     { WM_SHOWWINDOW, sent|wparam, 0 },
775     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
776     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
777     { WM_ERASEBKGND, sent|parent },
778     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
779     { 0 }
780 };
781 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
782  * for a not visible child window
783  */
784 static const struct message WmShowChildSeq_2[] = {
785     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
786     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
787     { WM_CHILDACTIVATE, sent },
788     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
789     { 0 }
790 };
791 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
792  * for a not visible child window
793  */
794 static const struct message WmShowChildSeq_3[] = {
795     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
796     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
797     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
798     { 0 }
799 };
800 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
801  * for a visible child window with a caption
802  */
803 static const struct message WmShowChildSeq_4[] = {
804     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
805     { WM_CHILDACTIVATE, sent },
806     { 0 }
807 };
808 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
809 static const struct message WmShowChildInvisibleParentSeq_1[] = {
810     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
811     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|0x8000 },
812     { WM_NCCALCSIZE, sent|wparam, 1 },
813     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
814     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|0x8000 },
815     { WM_MOVE, sent|defwinproc },
816     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
817     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
818     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
819     /* FIXME: Wine creates an icon/title window while Windows doesn't */
820     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
821     { WM_GETTEXT, sent|optional },
822     { 0 }
823 };
824 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
825 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
826     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
827     { 0 }
828 };
829 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
830 static const struct message WmShowChildInvisibleParentSeq_2[] = {
831     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
832     { WM_GETMINMAXINFO, sent },
833     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
834     { WM_NCCALCSIZE, sent|wparam, 1 },
835     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
836     { WM_CHILDACTIVATE, sent },
837     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|0x8000 },
838     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
839     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
840     { 0 }
841 };
842 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
843 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
844     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
845     { 0 }
846 };
847 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
848 static const struct message WmShowChildInvisibleParentSeq_3[] = {
849     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
850     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
851     { WM_NCCALCSIZE, sent|wparam, 1 },
852     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
853     { WM_CHILDACTIVATE, sent },
854     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|0x8000 },
855     { WM_MOVE, sent|defwinproc },
856     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
857     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
858     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
859     /* FIXME: Wine creates an icon/title window while Windows doesn't */
860     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
861     { WM_GETTEXT, sent|optional },
862     { 0 }
863 };
864 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
865 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
866     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
867     { 0 }
868 };
869 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
870 static const struct message WmShowChildInvisibleParentSeq_4[] = {
871     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
872     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|0x8000 },
873     { WM_NCCALCSIZE, sent|wparam, 1 },
874     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
875     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|0x8000 },
876     { WM_MOVE, sent|defwinproc },
877     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
878     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
879     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
880     /* FIXME: Wine creates an icon/title window while Windows doesn't */
881     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
882     { WM_GETTEXT, sent|optional },
883     { 0 }
884 };
885 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
886 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
887     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
888     { 0 }
889 };
890 /* ShowWindow(SW_SHOW) for child with invisible parent */
891 static const struct message WmShowChildInvisibleParentSeq_5[] = {
892     { WM_SHOWWINDOW, sent|wparam, 1 },
893     { 0 }
894 };
895 /* ShowWindow(SW_HIDE) for child with invisible parent */
896 static const struct message WmHideChildInvisibleParentSeq[] = {
897     { WM_SHOWWINDOW, sent|wparam, 0 },
898     { 0 }
899 };
900 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
901 static const struct message WmShowChildInvisibleParentSeq_6[] = {
902     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
903     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
904     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
905     { 0 }
906 };
907 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
908 static const struct message WmHideChildInvisibleParentSeq_2[] = {
909     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
910     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
911     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
912     { 0 }
913 };
914 /* DestroyWindow for a visible child window */
915 static const struct message WmDestroyChildSeq[] = {
916     { HCBT_DESTROYWND, hook },
917     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
918     { WM_SHOWWINDOW, sent|wparam, 0 },
919     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
920     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
921     { WM_ERASEBKGND, sent|parent|optional },
922     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
923     { HCBT_SETFOCUS, hook }, /* set focus to a parent */
924     { WM_KILLFOCUS, sent },
925     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
926     { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
927     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
928     { WM_SETFOCUS, sent|parent },
929     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
930     { WM_DESTROY, sent },
931     { WM_DESTROY, sent|optional }, /* some other (IME?) window */
932     { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
933     { WM_NCDESTROY, sent },
934     { 0 }
935 };
936 /* DestroyWindow for a visible child window with invisible parent */
937 static const struct message WmDestroyInvisibleChildSeq[] = {
938     { HCBT_DESTROYWND, hook },
939     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
940     { WM_SHOWWINDOW, sent|wparam, 0 },
941     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
942     { WM_DESTROY, sent },
943     { WM_NCDESTROY, sent },
944     { 0 }
945 };
946 /* Moving the mouse in nonclient area */
947 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
948     { WM_NCHITTEST, sent },
949     { WM_SETCURSOR, sent },
950     { WM_NCMOUSEMOVE, posted },
951     { 0 }
952 };
953 /* Moving the mouse in client area */
954 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
955     { WM_NCHITTEST, sent },
956     { WM_SETCURSOR, sent },
957     { WM_MOUSEMOVE, posted },
958     { 0 }
959 };
960 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
961 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
962     { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
963     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
964     { WM_GETMINMAXINFO, sent|defwinproc },
965     { WM_ENTERSIZEMOVE, sent|defwinproc },
966     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
967     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
968     { WM_MOVE, sent|defwinproc },
969     { WM_EXITSIZEMOVE, sent|defwinproc },
970     { 0 }
971 };
972 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
973 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
974     { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
975     { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
976     { WM_GETMINMAXINFO, sent|defwinproc },
977     { WM_ENTERSIZEMOVE, sent|defwinproc },
978     { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
979     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
980     { WM_GETMINMAXINFO, sent|defwinproc },
981     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
982     { WM_NCPAINT, sent|defwinproc|wparam, 1 },
983     { WM_GETTEXT, sent|defwinproc },
984     { WM_ERASEBKGND, sent|defwinproc },
985     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
986     { WM_MOVE, sent|defwinproc },
987     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
988     { WM_EXITSIZEMOVE, sent|defwinproc },
989     { 0 }
990 };
991 /* Resizing child window with MoveWindow (32) */
992 static const struct message WmResizingChildWithMoveWindowSeq[] = {
993     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
994     { WM_NCCALCSIZE, sent|wparam, 1 },
995     { WM_ERASEBKGND, sent|parent|optional },
996     { WM_ERASEBKGND, sent|optional },
997     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
998     { WM_MOVE, sent|defwinproc },
999     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1000     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1001     { 0 }
1002 };
1003 /* Clicking on inactive button */
1004 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
1005     { WM_NCHITTEST, sent },
1006     { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
1007     { WM_MOUSEACTIVATE, sent },
1008     { WM_MOUSEACTIVATE, sent|parent|defwinproc },
1009     { WM_SETCURSOR, sent },
1010     { WM_SETCURSOR, sent|parent|defwinproc },
1011     { WM_LBUTTONDOWN, posted },
1012     { WM_KILLFOCUS, posted|parent },
1013     { WM_SETFOCUS, posted },
1014     { WM_CTLCOLORBTN, posted|parent },
1015     { BM_SETSTATE, posted },
1016     { WM_CTLCOLORBTN, posted|parent },
1017     { WM_LBUTTONUP, posted },
1018     { BM_SETSTATE, posted },
1019     { WM_CTLCOLORBTN, posted|parent },
1020     { WM_COMMAND, posted|parent },
1021     { 0 }
1022 };
1023 /* Reparenting a button (16/32) */
1024 /* The last child (button) reparented gets topmost for its new parent. */
1025 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
1026     { WM_SHOWWINDOW, sent|wparam, 0 },
1027     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1028     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1029     { WM_ERASEBKGND, sent|parent },
1030     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1031     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
1032     { WM_CHILDACTIVATE, sent },
1033     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
1034     { WM_MOVE, sent|defwinproc },
1035     { WM_SHOWWINDOW, sent|wparam, 1 },
1036     { 0 }
1037 };
1038 /* Creation of a custom dialog (32) */
1039 static const struct message WmCreateCustomDialogSeq[] = {
1040     { HCBT_CREATEWND, hook },
1041     { WM_GETMINMAXINFO, sent },
1042     { WM_NCCREATE, sent },
1043     { WM_NCCALCSIZE, sent|wparam, 0 },
1044     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1045     { WM_CREATE, sent },
1046     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1047     { WM_SHOWWINDOW, sent|wparam, 1 },
1048     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1049     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1050     { HCBT_ACTIVATE, hook },
1051     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1052
1053
1054     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1055
1056     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1057
1058     { WM_NCACTIVATE, sent|wparam, 1 },
1059     { WM_GETTEXT, sent|optional|defwinproc },
1060     { WM_GETTEXT, sent|optional|defwinproc },
1061     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1062     { WM_ACTIVATE, sent|wparam, 1 },
1063     { WM_KILLFOCUS, sent|parent },
1064     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1065     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1066     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1067     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1068     { WM_SETFOCUS, sent },
1069     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1070     { WM_NCPAINT, sent|wparam, 1 },
1071     { WM_GETTEXT, sent|optional|defwinproc },
1072     { WM_GETTEXT, sent|optional|defwinproc },
1073     { WM_ERASEBKGND, sent },
1074     { WM_CTLCOLORDLG, sent|defwinproc },
1075     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1076     { WM_GETTEXT, sent|optional },
1077     { WM_GETTEXT, sent|optional },
1078     { WM_NCCALCSIZE, sent|optional },
1079     { WM_NCPAINT, sent|optional },
1080     { WM_GETTEXT, sent|optional|defwinproc },
1081     { WM_GETTEXT, sent|optional|defwinproc },
1082     { WM_ERASEBKGND, sent|optional },
1083     { WM_CTLCOLORDLG, sent|optional|defwinproc },
1084     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1085     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1086     { WM_MOVE, sent },
1087     { 0 }
1088 };
1089 /* Calling EndDialog for a custom dialog (32) */
1090 static const struct message WmEndCustomDialogSeq[] = {
1091     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1092     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1093     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1094     { WM_GETTEXT, sent|optional },
1095     { HCBT_ACTIVATE, hook },
1096     { WM_NCACTIVATE, sent|wparam, 0 },
1097     { WM_GETTEXT, sent|optional|defwinproc },
1098     { WM_GETTEXT, sent|optional|defwinproc },
1099     { WM_ACTIVATE, sent|wparam, 0 },
1100     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1101     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1102     { HCBT_SETFOCUS, hook },
1103     { WM_KILLFOCUS, sent },
1104     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1105     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1106     { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1107     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1108     { WM_SETFOCUS, sent|parent|defwinproc },
1109     { 0 }
1110 };
1111 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1112 static const struct message WmShowCustomDialogSeq[] = {
1113     { WM_SHOWWINDOW, sent|wparam, 1 },
1114     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1115     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1116     { HCBT_ACTIVATE, hook },
1117     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1118
1119     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1120
1121     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1122     { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1123     { WM_NCACTIVATE, sent|wparam, 1 },
1124     { WM_ACTIVATE, sent|wparam, 1 },
1125
1126     { WM_KILLFOCUS, sent|parent },
1127     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1128     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1129     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1130     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1131     { WM_SETFOCUS, sent },
1132     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1133     { WM_NCPAINT, sent|wparam, 1 },
1134     { WM_ERASEBKGND, sent },
1135     { WM_CTLCOLORDLG, sent|defwinproc },
1136     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1137     { 0 }
1138 };
1139 /* Creation and destruction of a modal dialog (32) */
1140 static const struct message WmModalDialogSeq[] = {
1141     { WM_CANCELMODE, sent|parent },
1142     { HCBT_SETFOCUS, hook },
1143     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1144     { WM_KILLFOCUS, sent|parent },
1145     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1146     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1147     { WM_ENABLE, sent|parent|wparam, 0 },
1148     { HCBT_CREATEWND, hook },
1149     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1150     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1151     { WM_SETFONT, sent },
1152     { WM_INITDIALOG, sent },
1153     { WM_CHANGEUISTATE, sent|optional },
1154     { WM_UPDATEUISTATE, sent|optional },
1155     { WM_SHOWWINDOW, sent },
1156     { HCBT_ACTIVATE, hook },
1157     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1158     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1159     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1160     { WM_NCACTIVATE, sent|wparam, 1 },
1161     { WM_GETTEXT, sent|optional },
1162     { WM_ACTIVATE, sent|wparam, 1 },
1163     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1164     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1165     { WM_NCPAINT, sent },
1166     { WM_GETTEXT, sent|optional },
1167     { WM_ERASEBKGND, sent },
1168     { WM_CTLCOLORDLG, sent },
1169     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1170     { WM_GETTEXT, sent|optional },
1171     { WM_NCCALCSIZE, sent|optional },
1172     { WM_NCPAINT, sent|optional },
1173     { WM_GETTEXT, sent|optional },
1174     { WM_ERASEBKGND, sent|optional },
1175     { WM_CTLCOLORDLG, sent|optional },
1176     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1177     { WM_PAINT, sent|optional },
1178     { WM_CTLCOLORBTN, sent },
1179     { WM_ENTERIDLE, sent|parent|optional },
1180     { WM_ENTERIDLE, sent|parent|optional },
1181     { WM_ENTERIDLE, sent|parent|optional },
1182     { WM_ENTERIDLE, sent|parent|optional },
1183     { WM_ENTERIDLE, sent|parent|optional },
1184     { WM_ENTERIDLE, sent|parent|optional },
1185     { WM_ENTERIDLE, sent|parent|optional },
1186     { WM_ENTERIDLE, sent|parent|optional },
1187     { WM_ENTERIDLE, sent|parent|optional },
1188     { WM_ENTERIDLE, sent|parent|optional },
1189     { WM_ENTERIDLE, sent|parent|optional },
1190     { WM_ENTERIDLE, sent|parent|optional },
1191     { WM_ENTERIDLE, sent|parent|optional },
1192     { WM_ENTERIDLE, sent|parent|optional },
1193     { WM_ENTERIDLE, sent|parent|optional },
1194     { WM_ENTERIDLE, sent|parent|optional },
1195     { WM_ENTERIDLE, sent|parent|optional },
1196     { WM_ENTERIDLE, sent|parent|optional },
1197     { WM_ENTERIDLE, sent|parent|optional },
1198     { WM_ENTERIDLE, sent|parent|optional },
1199     { WM_TIMER, sent },
1200     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1201     { WM_ENABLE, sent|parent|wparam, 1 },
1202     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1203     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1204     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1205     { WM_GETTEXT, sent|optional },
1206     { HCBT_ACTIVATE, hook },
1207     { WM_NCACTIVATE, sent|wparam, 0 },
1208     { WM_GETTEXT, sent|optional },
1209     { WM_ACTIVATE, sent|wparam, 0 },
1210     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1211     { WM_WINDOWPOSCHANGING, sent|optional },
1212     { HCBT_SETFOCUS, hook },
1213     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1214     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1215     { WM_SETFOCUS, sent|parent|defwinproc },
1216     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1217     { HCBT_DESTROYWND, hook },
1218     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1219     { WM_DESTROY, sent },
1220     { WM_NCDESTROY, sent },
1221     { 0 }
1222 };
1223 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1224 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1225     /* (inside dialog proc, handling WM_INITDIALOG) */
1226     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1227     { WM_NCCALCSIZE, sent },
1228     { WM_NCACTIVATE, sent|parent|wparam, 0 },
1229     { WM_GETTEXT, sent|defwinproc },
1230     { WM_ACTIVATE, sent|parent|wparam, 0 },
1231     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1232     { WM_WINDOWPOSCHANGING, sent|parent },
1233     { WM_NCACTIVATE, sent|wparam, 1 },
1234     { WM_ACTIVATE, sent|wparam, 1 },
1235     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1236     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1237     /* (setting focus) */
1238     { WM_SHOWWINDOW, sent|wparam, 1 },
1239     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1240     { WM_NCPAINT, sent },
1241     { WM_GETTEXT, sent|defwinproc },
1242     { WM_ERASEBKGND, sent },
1243     { WM_CTLCOLORDLG, sent|defwinproc },
1244     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1245     { WM_PAINT, sent },
1246     /* (bunch of WM_CTLCOLOR* for each control) */
1247     { WM_PAINT, sent|parent },
1248     { WM_ENTERIDLE, sent|parent|wparam, 0 },
1249     { WM_SETCURSOR, sent|parent },
1250     { 0 }
1251 };
1252 /* SetMenu for NonVisible windows with size change*/
1253 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1254     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1255     { WM_NCCALCSIZE, sent|wparam, 1 },
1256     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1257     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1258     { WM_MOVE, sent|defwinproc },
1259     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1260     { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1261     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1262     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1263     { WM_GETTEXT, sent|optional },
1264     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1265     { 0 }
1266 };
1267 /* SetMenu for NonVisible windows with no size change */
1268 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1269     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1270     { WM_NCCALCSIZE, sent|wparam, 1 },
1271     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1272     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1273     { 0 }
1274 };
1275 /* SetMenu for Visible windows with size change */
1276 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1277     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1278     { WM_NCCALCSIZE, sent|wparam, 1 },
1279     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1280     { WM_NCPAINT, sent }, /* wparam != 1 */
1281     { WM_GETTEXT, sent|defwinproc|optional },
1282     { WM_ERASEBKGND, sent|optional },
1283     { WM_ACTIVATE, sent|optional },
1284     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1285     { WM_MOVE, sent|defwinproc },
1286     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1287     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1288     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1289     { WM_ERASEBKGND, sent|optional },
1290     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1291     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1292     { 0 }
1293 };
1294 /* SetMenu for Visible windows with no size change */
1295 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1296     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1297     { WM_NCCALCSIZE, sent|wparam, 1 },
1298     { WM_NCPAINT, sent }, /* wparam != 1 */
1299     { WM_GETTEXT, sent|defwinproc|optional },
1300     { WM_ERASEBKGND, sent|optional },
1301     { WM_ACTIVATE, sent|optional },
1302     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1303     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1304     { 0 }
1305 };
1306 /* DrawMenuBar for a visible window */
1307 static const struct message WmDrawMenuBarSeq[] =
1308 {
1309     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1310     { WM_NCCALCSIZE, sent|wparam, 1 },
1311     { WM_NCPAINT, sent }, /* wparam != 1 */
1312     { WM_GETTEXT, sent|defwinproc|optional },
1313     { WM_ERASEBKGND, sent|optional },
1314     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1315     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1316     { 0 }
1317 };
1318
1319 static const struct message WmSetRedrawFalseSeq[] =
1320 {
1321     { WM_SETREDRAW, sent|wparam, 0 },
1322     { 0 }
1323 };
1324
1325 static const struct message WmSetRedrawTrueSeq[] =
1326 {
1327     { WM_SETREDRAW, sent|wparam, 1 },
1328     { 0 }
1329 };
1330
1331 static const struct message WmEnableWindowSeq_1[] =
1332 {
1333     { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1334     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1335     { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1336     { 0 }
1337 };
1338
1339 static const struct message WmEnableWindowSeq_2[] =
1340 {
1341     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1342     { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1343     { 0 }
1344 };
1345
1346 static const struct message WmGetScrollRangeSeq[] =
1347 {
1348     { SBM_GETRANGE, sent },
1349     { 0 }
1350 };
1351 static const struct message WmGetScrollInfoSeq[] =
1352 {
1353     { SBM_GETSCROLLINFO, sent },
1354     { 0 }
1355 };
1356 static const struct message WmSetScrollRangeSeq[] =
1357 {
1358     /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1359        sends SBM_SETSCROLLINFO.
1360      */
1361     { SBM_SETSCROLLINFO, sent },
1362     { 0 }
1363 };
1364 /* SetScrollRange for a window without a non-client area */
1365 static const struct message WmSetScrollRangeHSeq_empty[] =
1366 {
1367     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1368     { 0 }
1369 };
1370 static const struct message WmSetScrollRangeVSeq_empty[] =
1371 {
1372     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1373     { 0 }
1374 };
1375 static const struct message WmSetScrollRangeHVSeq[] =
1376 {
1377     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1378     { WM_NCCALCSIZE, sent|wparam, 1 },
1379     { WM_GETTEXT, sent|defwinproc|optional },
1380     { WM_ERASEBKGND, sent|optional },
1381     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1382     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1383     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1384     { 0 }
1385 };
1386 /* SetScrollRange for a window with a non-client area */
1387 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1388 {
1389     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1390     { WM_NCCALCSIZE, sent|wparam, 1 },
1391     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1392     { WM_NCPAINT, sent|optional },
1393     { WM_GETTEXT, sent|defwinproc|optional },
1394     { WM_GETTEXT, sent|defwinproc|optional },
1395     { WM_ERASEBKGND, sent|optional },
1396     { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1397     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE },
1398     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1399     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1400     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1401     { WM_GETTEXT, sent|optional },
1402     { WM_GETTEXT, sent|optional },
1403     { WM_GETTEXT, sent|optional },
1404     { WM_GETTEXT, sent|optional },
1405     { 0 }
1406 };
1407 /* test if we receive the right sequence of messages */
1408 /* after calling ShowWindow( SW_SHOWNA) */
1409 static const struct message WmSHOWNAChildInvisParInvis[] = {
1410     { WM_SHOWWINDOW, sent|wparam, 1 },
1411     { 0 }
1412 };
1413 static const struct message WmSHOWNAChildVisParInvis[] = {
1414     { WM_SHOWWINDOW, sent|wparam, 1 },
1415     { 0 }
1416 };
1417 static const struct message WmSHOWNAChildVisParVis[] = {
1418     { WM_SHOWWINDOW, sent|wparam, 1 },
1419     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1420     { 0 }
1421 };
1422 static const struct message WmSHOWNAChildInvisParVis[] = {
1423     { WM_SHOWWINDOW, sent|wparam, 1 },
1424     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1425     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1426     { WM_ERASEBKGND, sent|optional },
1427     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1428     { 0 }
1429 };
1430 static const struct message WmSHOWNATopVisible[] = {
1431     { WM_SHOWWINDOW, sent|wparam, 1 },
1432     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1433     { 0 }
1434 };
1435 static const struct message WmSHOWNATopInvisible[] = {
1436     { WM_SHOWWINDOW, sent|wparam, 1 },
1437     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1438     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1439     { WM_NCPAINT, sent|wparam, 1 },
1440     { WM_GETTEXT, sent|defwinproc|optional },
1441     { WM_ERASEBKGND, sent|optional },
1442     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1443     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1444     { WM_NCPAINT, sent|wparam|optional, 1 },
1445     { WM_ERASEBKGND, sent|optional },
1446     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1447     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1448     { WM_MOVE, sent },
1449     { 0 }
1450 };
1451
1452 static int after_end_dialog, test_def_id;
1453 static int sequence_cnt, sequence_size;
1454 static struct message* sequence;
1455 static int log_all_parent_messages;
1456
1457 /* user32 functions */
1458 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1459 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1460 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1461 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1462 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1463 /* kernel32 functions */
1464 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1465
1466 static void init_procs(void)
1467 {
1468     HMODULE user32 = GetModuleHandleA("user32.dll");
1469     HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1470
1471 #define GET_PROC(dll, func) \
1472     p ## func = (void*)GetProcAddress(dll, #func); \
1473     if(!p ## func) { \
1474       trace("GetProcAddress(%s) failed\n", #func); \
1475     }
1476
1477     GET_PROC(user32, GetAncestor)
1478     GET_PROC(user32, NotifyWinEvent)
1479     GET_PROC(user32, SetWinEventHook)
1480     GET_PROC(user32, TrackMouseEvent)
1481     GET_PROC(user32, UnhookWinEvent)
1482
1483     GET_PROC(kernel32, GetCPInfoExA)
1484
1485 #undef GET_PROC
1486 }
1487
1488 static void add_message(const struct message *msg)
1489 {
1490     if (!sequence) 
1491     {
1492         sequence_size = 10;
1493         sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof (struct message) );
1494     }
1495     if (sequence_cnt == sequence_size) 
1496     {
1497         sequence_size *= 2;
1498         sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof (struct message) );
1499     }
1500     assert(sequence);
1501
1502     sequence[sequence_cnt].message = msg->message;
1503     sequence[sequence_cnt].flags = msg->flags;
1504     sequence[sequence_cnt].wParam = msg->wParam;
1505     sequence[sequence_cnt].lParam = msg->lParam;
1506
1507     sequence_cnt++;
1508 }
1509
1510 /* try to make sure pending X events have been processed before continuing */
1511 static void flush_events(void)
1512 {
1513     MSG msg;
1514     int diff = 100;
1515     DWORD time = GetTickCount() + diff;
1516
1517     while (diff > 0)
1518     {
1519         if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min(10,diff), QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1520         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1521         diff = time - GetTickCount();
1522     }
1523 }
1524
1525 static void flush_sequence(void)
1526 {
1527     HeapFree(GetProcessHeap(), 0, sequence);
1528     sequence = 0;
1529     sequence_cnt = sequence_size = 0;
1530 }
1531
1532 #define ok_sequence( exp, contx, todo) \
1533         ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
1534
1535
1536 static void ok_sequence_(const struct message *expected, const char *context, int todo,
1537         const char *file, int line)
1538 {
1539     static const struct message end_of_sequence = { 0, 0, 0, 0 };
1540     const struct message *actual;
1541     int failcount = 0;
1542     
1543     add_message(&end_of_sequence);
1544
1545     actual = sequence;
1546
1547     while (expected->message && actual->message)
1548     {
1549         trace_( file, line)("expected %04x - actual %04x\n", expected->message, actual->message);
1550
1551         if (expected->message == actual->message)
1552         {
1553             if (expected->flags & wparam)
1554             {
1555                 if (expected->wParam != actual->wParam && todo)
1556                 {
1557                     todo_wine {
1558                         failcount ++;
1559                         ok_( file, line) (FALSE,
1560                             "%s: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1561                             context, expected->message, expected->wParam, actual->wParam);
1562                     }
1563                 }
1564                 else
1565                 ok_( file, line) (expected->wParam == actual->wParam,
1566                      "%s: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1567                      context, expected->message, expected->wParam, actual->wParam);
1568             }
1569             if (expected->flags & lparam)
1570             {
1571                 if (expected->lParam != actual->lParam && todo)
1572                 {
1573                     todo_wine {
1574                         failcount ++;
1575                         ok_( file, line) (FALSE,
1576                             "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1577                             context, expected->message, expected->lParam, actual->lParam);
1578                     }
1579                 }
1580                 else
1581                  ok_( file, line) (expected->lParam == actual->lParam,
1582                      "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1583                      context, expected->message, expected->lParam, actual->lParam);
1584             }
1585             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
1586             {
1587                     todo_wine {
1588                         failcount ++;
1589                         ok_( file, line) (FALSE,
1590                             "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1591                             context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1592                     }
1593             }
1594             else
1595                 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
1596                     "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1597                     context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1598             ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
1599                 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
1600                 context, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
1601             ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
1602                 "%s: the msg 0x%04x should have been %s\n",
1603                 context, expected->message, (expected->flags & posted) ? "posted" : "sent");
1604             ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
1605                 "%s: the msg 0x%04x was expected in %s\n",
1606                 context, expected->message, (expected->flags & parent) ? "parent" : "child");
1607             ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
1608                 "%s: the msg 0x%04x should have been sent by a hook\n",
1609                 context, expected->message);
1610             ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
1611                 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
1612                 context, expected->message);
1613             expected++;
1614             actual++;
1615         }
1616         /* silently drop winevent messages if there is no support for them */
1617         else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1618             expected++;
1619         else if (todo)
1620         {
1621             failcount++;
1622             todo_wine {
1623                 ok_( file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
1624                     context, expected->message, actual->message);
1625             }
1626             flush_sequence();
1627             return;
1628         }
1629         else
1630         {
1631             ok_( file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
1632                 context, expected->message, actual->message);
1633             expected++;
1634             actual++;
1635         }
1636     }
1637
1638     /* skip all optional trailing messages */
1639     while (expected->message && ((expected->flags & optional) ||
1640             ((expected->flags & winevent_hook) && !hEvent_hook)))
1641         expected++;
1642
1643     if (todo)
1644     {
1645         todo_wine {
1646             if (expected->message || actual->message) {
1647                 failcount++;
1648                 ok_( file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
1649                     context, expected->message, actual->message);
1650             }
1651         }
1652     }
1653     else
1654     {
1655         if (expected->message || actual->message)
1656             ok_( file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
1657                 context, expected->message, actual->message);
1658     }
1659     if( todo && !failcount) /* succeeded yet marked todo */
1660         todo_wine {
1661             ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
1662         }
1663
1664     flush_sequence();
1665 }
1666
1667 /******************************** MDI test **********************************/
1668
1669 /* CreateWindow for MDI frame window, initially visible */
1670 static const struct message WmCreateMDIframeSeq[] = {
1671     { HCBT_CREATEWND, hook },
1672     { WM_GETMINMAXINFO, sent },
1673     { WM_NCCREATE, sent },
1674     { WM_NCCALCSIZE, sent|wparam, 0 },
1675     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1676     { WM_CREATE, sent },
1677     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1678     { WM_SHOWWINDOW, sent|wparam, 1 },
1679     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1680     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1681     { HCBT_ACTIVATE, hook },
1682     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1683     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1684     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
1685     { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
1686     { WM_NCACTIVATE, sent|wparam, 1 },
1687     { WM_GETTEXT, sent|defwinproc|optional },
1688     { WM_ACTIVATE, sent|wparam, 1 },
1689     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
1690     { HCBT_SETFOCUS, hook },
1691     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1692     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1693     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1694     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
1695     /* Win9x adds SWP_NOZORDER below */
1696     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1697     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
1698     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1699     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1700     { WM_MOVE, sent },
1701     { 0 }
1702 };
1703 /* DestroyWindow for MDI frame window, initially visible */
1704 static const struct message WmDestroyMDIframeSeq[] = {
1705     { HCBT_DESTROYWND, hook },
1706     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1707     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1708     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
1709     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1710     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
1711     { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
1712     { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
1713     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
1714     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1715     { WM_DESTROY, sent },
1716     { WM_NCDESTROY, sent },
1717     { 0 }
1718 };
1719 /* CreateWindow for MDI client window, initially visible */
1720 static const struct message WmCreateMDIclientSeq[] = {
1721     { HCBT_CREATEWND, hook },
1722     { WM_NCCREATE, sent },
1723     { WM_NCCALCSIZE, sent|wparam, 0 },
1724     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
1725     { WM_CREATE, sent },
1726     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
1727     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1728     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1729     { WM_MOVE, sent },
1730     { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
1731     { WM_SHOWWINDOW, sent|wparam, 1 },
1732     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1733     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1734     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1735     { 0 }
1736 };
1737 /* ShowWindow(SW_SHOW) for MDI client window */
1738 static const struct message WmShowMDIclientSeq[] = {
1739     { WM_SHOWWINDOW, sent|wparam, 1 },
1740     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1741     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1742     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1743     { 0 }
1744 };
1745 /* ShowWindow(SW_HIDE) for MDI client window */
1746 static const struct message WmHideMDIclientSeq[] = {
1747     { WM_SHOWWINDOW, sent|wparam, 0 },
1748     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1749     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
1750     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
1751     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1752     { 0 }
1753 };
1754 /* DestroyWindow for MDI client window, initially visible */
1755 static const struct message WmDestroyMDIclientSeq[] = {
1756     { HCBT_DESTROYWND, hook },
1757     { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
1758     { WM_SHOWWINDOW, sent|wparam, 0 },
1759     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1760     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1761     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1762     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1763     { WM_DESTROY, sent },
1764     { WM_NCDESTROY, sent },
1765     { 0 }
1766 };
1767 /* CreateWindow for MDI child window, initially visible */
1768 static const struct message WmCreateMDIchildVisibleSeq[] = {
1769     { HCBT_CREATEWND, hook },
1770     { WM_NCCREATE, sent }, 
1771     { WM_NCCALCSIZE, sent|wparam, 0 },
1772     { WM_CREATE, sent },
1773     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1774     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1775     { WM_MOVE, sent },
1776     /* Win2k sends wparam set to
1777      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1778      * while Win9x doesn't bother to set child window id according to
1779      * CLIENTCREATESTRUCT.idFirstChild
1780      */
1781     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1782     { WM_SHOWWINDOW, sent|wparam, 1 },
1783     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1784     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1785     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1786     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1787     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1788     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1789     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1790
1791     /* Win9x: message sequence terminates here. */
1792
1793     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1794     { HCBT_SETFOCUS, hook }, /* in MDI client */
1795     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1796     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
1797     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1798     { WM_SETFOCUS, sent }, /* in MDI client */
1799     { HCBT_SETFOCUS, hook },
1800     { WM_KILLFOCUS, sent }, /* in MDI client */
1801     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1802     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1803     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1804     { WM_SETFOCUS, sent|defwinproc },
1805     { WM_MDIACTIVATE, sent|defwinproc },
1806     { 0 }
1807 };
1808 /* CreateWindow for MDI child window with invisible parent */
1809 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
1810     { HCBT_CREATEWND, hook },
1811     { WM_GETMINMAXINFO, sent },
1812     { WM_NCCREATE, sent }, 
1813     { WM_NCCALCSIZE, sent|wparam, 0 },
1814     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
1815     { WM_CREATE, sent },
1816     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1817     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1818     { WM_MOVE, sent },
1819     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1820     { WM_SHOWWINDOW, sent|wparam, 1 },
1821     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
1822     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1823     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1824     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1825
1826     /* Win9x: message sequence terminates here. */
1827
1828     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1829     { HCBT_SETFOCUS, hook }, /* in MDI client */
1830     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1831     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
1832     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1833     { WM_SETFOCUS, sent }, /* in MDI client */
1834     { HCBT_SETFOCUS, hook },
1835     { WM_KILLFOCUS, sent }, /* in MDI client */
1836     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1837     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1838     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1839     { WM_SETFOCUS, sent|defwinproc },
1840     { WM_MDIACTIVATE, sent|defwinproc },
1841     { 0 }
1842 };
1843 /* DestroyWindow for MDI child window, initially visible */
1844 static const struct message WmDestroyMDIchildVisibleSeq[] = {
1845     { HCBT_DESTROYWND, hook },
1846     /* Win2k sends wparam set to
1847      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1848      * while Win9x doesn't bother to set child window id according to
1849      * CLIENTCREATESTRUCT.idFirstChild
1850      */
1851     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1852     { WM_SHOWWINDOW, sent|wparam, 0 },
1853     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1854     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1855     { WM_ERASEBKGND, sent|parent|optional },
1856     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1857
1858     /* { WM_DESTROY, sent }
1859      * Win9x: message sequence terminates here.
1860      */
1861
1862     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1863     { WM_KILLFOCUS, sent },
1864     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1865     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1866     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1867     { WM_SETFOCUS, sent }, /* in MDI client */
1868
1869     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1870     { WM_KILLFOCUS, sent }, /* in MDI client */
1871     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1872     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1873     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1874     { WM_SETFOCUS, sent }, /* in MDI client */
1875
1876     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1877
1878     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1879     { WM_KILLFOCUS, sent },
1880     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1881     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1882     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1883     { WM_SETFOCUS, sent }, /* in MDI client */
1884
1885     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1886     { WM_KILLFOCUS, sent }, /* in MDI client */
1887     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1888     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1889     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1890     { WM_SETFOCUS, sent }, /* in MDI client */
1891
1892     { WM_DESTROY, sent },
1893
1894     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1895     { WM_KILLFOCUS, sent },
1896     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1897     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1898     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1899     { WM_SETFOCUS, sent }, /* in MDI client */
1900
1901     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1902     { WM_KILLFOCUS, sent }, /* in MDI client */
1903     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1904     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1905     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1906     { WM_SETFOCUS, sent }, /* in MDI client */
1907
1908     { WM_NCDESTROY, sent },
1909     { 0 }
1910 };
1911 /* CreateWindow for MDI child window, initially invisible */
1912 static const struct message WmCreateMDIchildInvisibleSeq[] = {
1913     { HCBT_CREATEWND, hook },
1914     { WM_NCCREATE, sent }, 
1915     { WM_NCCALCSIZE, sent|wparam, 0 },
1916     { WM_CREATE, sent },
1917     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1918     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1919     { WM_MOVE, sent },
1920     /* Win2k sends wparam set to
1921      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1922      * while Win9x doesn't bother to set child window id according to
1923      * CLIENTCREATESTRUCT.idFirstChild
1924      */
1925     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1926     { 0 }
1927 };
1928 /* DestroyWindow for MDI child window, initially invisible */
1929 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
1930     { HCBT_DESTROYWND, hook },
1931     /* Win2k sends wparam set to
1932      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1933      * while Win9x doesn't bother to set child window id according to
1934      * CLIENTCREATESTRUCT.idFirstChild
1935      */
1936     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1937     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1938     { WM_DESTROY, sent },
1939     { WM_NCDESTROY, sent },
1940     /* FIXME: Wine destroys an icon/title window while Windows doesn't */
1941     { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
1942     { 0 }
1943 };
1944 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
1945 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
1946     { HCBT_CREATEWND, hook },
1947     { WM_NCCREATE, sent }, 
1948     { WM_NCCALCSIZE, sent|wparam, 0 },
1949     { WM_CREATE, sent },
1950     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1951     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1952     { WM_MOVE, sent },
1953     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1954     { WM_GETMINMAXINFO, sent },
1955     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
1956     { WM_NCCALCSIZE, sent|wparam, 1 },
1957     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1958     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
1959      /* in MDI frame */
1960     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1961     { WM_NCCALCSIZE, sent|wparam, 1 },
1962     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1963     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1964     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1965     /* Win2k sends wparam set to
1966      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1967      * while Win9x doesn't bother to set child window id according to
1968      * CLIENTCREATESTRUCT.idFirstChild
1969      */
1970     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1971     { WM_SHOWWINDOW, sent|wparam, 1 },
1972     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1973     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1974     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1975     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1976     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1977     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1978     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1979
1980     /* Win9x: message sequence terminates here. */
1981
1982     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1983     { HCBT_SETFOCUS, hook }, /* in MDI client */
1984     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1985     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
1986     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1987     { WM_SETFOCUS, sent }, /* in MDI client */
1988     { HCBT_SETFOCUS, hook },
1989     { WM_KILLFOCUS, sent }, /* in MDI client */
1990     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1991     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1992     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1993     { WM_SETFOCUS, sent|defwinproc },
1994     { WM_MDIACTIVATE, sent|defwinproc },
1995      /* in MDI frame */
1996     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1997     { WM_NCCALCSIZE, sent|wparam, 1 },
1998     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1999     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2000     { 0 }
2001 };
2002 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2003 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2004     /* restore the 1st MDI child */
2005     { WM_SETREDRAW, sent|wparam, 0 },
2006     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2007     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
2008     { WM_NCCALCSIZE, sent|wparam, 1 },
2009     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2010     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2011     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2012      /* in MDI frame */
2013     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2014     { WM_NCCALCSIZE, sent|wparam, 1 },
2015     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2016     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2017     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2018     { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2019     /* create the 2nd MDI child */
2020     { HCBT_CREATEWND, hook },
2021     { WM_NCCREATE, sent }, 
2022     { WM_NCCALCSIZE, sent|wparam, 0 },
2023     { WM_CREATE, sent },
2024     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2025     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2026     { WM_MOVE, sent },
2027     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2028     { WM_GETMINMAXINFO, sent },
2029     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
2030     { WM_NCCALCSIZE, sent|wparam, 1 },
2031     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2032     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2033     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2034      /* in MDI frame */
2035     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2036     { WM_NCCALCSIZE, sent|wparam, 1 },
2037     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2038     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2039     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2040     /* Win2k sends wparam set to
2041      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2042      * while Win9x doesn't bother to set child window id according to
2043      * CLIENTCREATESTRUCT.idFirstChild
2044      */
2045     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2046     { WM_SHOWWINDOW, sent|wparam, 1 },
2047     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2048     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2049     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2050     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2051     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2052     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2053
2054     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2055     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2056
2057     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2058
2059     /* Win9x: message sequence terminates here. */
2060
2061     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2062     { HCBT_SETFOCUS, hook },
2063     { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
2064     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2065     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2066     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2067     { WM_SETFOCUS, sent }, /* in MDI client */
2068     { HCBT_SETFOCUS, hook },
2069     { WM_KILLFOCUS, sent }, /* in MDI client */
2070     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2071     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2072     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2073     { WM_SETFOCUS, sent|defwinproc },
2074
2075     { WM_MDIACTIVATE, sent|defwinproc },
2076      /* in MDI frame */
2077     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2078     { WM_NCCALCSIZE, sent|wparam, 1 },
2079     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2080     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2081     { 0 }
2082 };
2083 /* WM_MDICREATE MDI child window, initially visible and maximized */
2084 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2085     { WM_MDICREATE, sent },
2086     { HCBT_CREATEWND, hook },
2087     { WM_NCCREATE, sent }, 
2088     { WM_NCCALCSIZE, sent|wparam, 0 },
2089     { WM_CREATE, sent },
2090     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2091     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2092     { WM_MOVE, sent },
2093     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2094     { WM_GETMINMAXINFO, sent },
2095     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
2096     { WM_NCCALCSIZE, sent|wparam, 1 },
2097     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2098     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2099
2100      /* in MDI frame */
2101     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2102     { WM_NCCALCSIZE, sent|wparam, 1 },
2103     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2104     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2105     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2106
2107     /* Win2k sends wparam set to
2108      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2109      * while Win9x doesn't bother to set child window id according to
2110      * CLIENTCREATESTRUCT.idFirstChild
2111      */
2112     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2113     { WM_SHOWWINDOW, sent|wparam, 1 },
2114     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2115
2116     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2117
2118     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2119     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2120     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2121
2122     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2123     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2124
2125     /* Win9x: message sequence terminates here. */
2126
2127     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2128     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2129     { HCBT_SETFOCUS, hook }, /* in MDI client */
2130     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2131     { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2132     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2133     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2134     { HCBT_SETFOCUS, hook|optional },
2135     { WM_KILLFOCUS, sent }, /* in MDI client */
2136     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2137     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2138     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2139     { WM_SETFOCUS, sent|defwinproc },
2140
2141     { WM_MDIACTIVATE, sent|defwinproc },
2142
2143      /* in MDI child */
2144     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2145     { WM_NCCALCSIZE, sent|wparam, 1 },
2146     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2147     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2148
2149      /* in MDI frame */
2150     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2151     { WM_NCCALCSIZE, sent|wparam, 1 },
2152     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2153     { WM_MOVE, sent|defwinproc },
2154     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2155
2156      /* in MDI client */
2157     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2158     { WM_NCCALCSIZE, sent|wparam, 1 },
2159     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2160     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2161
2162      /* in MDI child */
2163     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2164     { WM_NCCALCSIZE, sent|wparam, 1 },
2165     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2166     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2167
2168     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2169     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2170     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2171     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2172     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2173
2174     { 0 }
2175 };
2176 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2177 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2178     { HCBT_CREATEWND, hook },
2179     { WM_GETMINMAXINFO, sent },
2180     { WM_NCCREATE, sent }, 
2181     { WM_NCCALCSIZE, sent|wparam, 0 },
2182     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2183     { WM_CREATE, sent },
2184     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2185     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2186     { WM_MOVE, sent },
2187     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2188     { WM_GETMINMAXINFO, sent },
2189     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
2190     { WM_GETMINMAXINFO, sent|defwinproc },
2191     { WM_NCCALCSIZE, sent|wparam, 1 },
2192     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|0x8000 },
2193     { WM_MOVE, sent|defwinproc },
2194     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2195      /* in MDI frame */
2196     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2197     { WM_NCCALCSIZE, sent|wparam, 1 },
2198     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2199     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2200     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2201     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2202     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2203     /* Win2k sends wparam set to
2204      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2205      * while Win9x doesn't bother to set child window id according to
2206      * CLIENTCREATESTRUCT.idFirstChild
2207      */
2208     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2209     { 0 }
2210 };
2211 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2212 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2213     { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2214     { HCBT_SYSCOMMAND, hook },
2215     { WM_CLOSE, sent|defwinproc },
2216     { WM_MDIDESTROY, sent }, /* in MDI client */
2217
2218     /* bring the 1st MDI child to top */
2219     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2220     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2221
2222     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2223
2224     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2225     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2226     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2227
2228     /* maximize the 1st MDI child */
2229     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2230     { WM_GETMINMAXINFO, sent|defwinproc },
2231     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|0x8000 },
2232     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2233     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2234     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2235     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2236
2237     /* restore the 2nd MDI child */
2238     { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2239     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2240     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|0x8000 },
2241     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2242
2243     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2244
2245     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2246     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2247
2248     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2249
2250     { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2251      /* in MDI frame */
2252     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2253     { WM_NCCALCSIZE, sent|wparam, 1 },
2254     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2255     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2256     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2257
2258     /* bring the 1st MDI child to top */
2259     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2260     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2261     { HCBT_SETFOCUS, hook },
2262     { WM_KILLFOCUS, sent|defwinproc },
2263     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2264     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2265     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2266     { WM_SETFOCUS, sent }, /* in MDI client */
2267     { HCBT_SETFOCUS, hook },
2268     { WM_KILLFOCUS, sent }, /* in MDI client */
2269     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2270     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2271     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2272     { WM_SETFOCUS, sent|defwinproc },
2273     { WM_MDIACTIVATE, sent|defwinproc },
2274     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2275
2276     /* apparently ShowWindow(SW_SHOW) on an MDI client */
2277     { WM_SHOWWINDOW, sent|wparam, 1 },
2278     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2279     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2280     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2281     { WM_MDIREFRESHMENU, sent },
2282
2283     { HCBT_DESTROYWND, hook },
2284     /* Win2k sends wparam set to
2285      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2286      * while Win9x doesn't bother to set child window id according to
2287      * CLIENTCREATESTRUCT.idFirstChild
2288      */
2289     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2290     { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2291     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2292     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2293     { WM_ERASEBKGND, sent|parent|optional },
2294     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2295
2296     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2297     { WM_DESTROY, sent|defwinproc },
2298     { WM_NCDESTROY, sent|defwinproc },
2299     { 0 }
2300 };
2301 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2302 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2303     { WM_MDIDESTROY, sent }, /* in MDI client */
2304     { WM_SHOWWINDOW, sent|wparam, 0 },
2305     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2306     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2307     { WM_ERASEBKGND, sent|parent|optional },
2308     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2309
2310     { HCBT_SETFOCUS, hook },
2311     { WM_KILLFOCUS, sent },
2312     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2313     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2314     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2315     { WM_SETFOCUS, sent }, /* in MDI client */
2316     { HCBT_SETFOCUS, hook },
2317     { WM_KILLFOCUS, sent }, /* in MDI client */
2318     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2319     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2320     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2321     { WM_SETFOCUS, sent },
2322
2323      /* in MDI child */
2324     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2325     { WM_NCCALCSIZE, sent|wparam, 1 },
2326     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2327     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2328
2329      /* in MDI frame */
2330     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2331     { WM_NCCALCSIZE, sent|wparam, 1 },
2332     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2333     { WM_MOVE, sent|defwinproc },
2334     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2335
2336      /* in MDI client */
2337     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2338     { WM_NCCALCSIZE, sent|wparam, 1 },
2339     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2340     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2341
2342      /* in MDI child */
2343     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2344     { WM_NCCALCSIZE, sent|wparam, 1 },
2345     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2346     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2347
2348      /* in MDI child */
2349     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2350     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2351     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2352     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2353
2354      /* in MDI frame */
2355     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2356     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2357     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2358     { WM_MOVE, sent|defwinproc },
2359     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2360
2361      /* in MDI client */
2362     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2363     { WM_NCCALCSIZE, sent|wparam, 1 },
2364     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2365     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2366
2367      /* in MDI child */
2368     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2369     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2370     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2371     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2372     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2373     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2374
2375     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2376
2377     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2378     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2379     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2380     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2381     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2382
2383      /* in MDI frame */
2384     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2385     { WM_NCCALCSIZE, sent|wparam, 1 },
2386     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2387     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2388
2389     { WM_NCACTIVATE, sent|wparam, 0 },
2390     { WM_MDIACTIVATE, sent },
2391
2392     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2393     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|0x8000 },
2394     { WM_NCCALCSIZE, sent|wparam, 1 },
2395
2396     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2397
2398     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2399     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|0x8000 },
2400     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2401
2402      /* in MDI child */
2403     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2404     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2405     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2406     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2407
2408      /* in MDI frame */
2409     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2410     { WM_NCCALCSIZE, sent|wparam, 1 },
2411     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2412     { WM_MOVE, sent|defwinproc },
2413     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2414
2415      /* in MDI client */
2416     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2417     { WM_NCCALCSIZE, sent|wparam, 1 },
2418     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2419     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2420     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2421     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2422     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2423     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2424     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2425
2426     { HCBT_SETFOCUS, hook },
2427     { WM_KILLFOCUS, sent },
2428     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2429     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2430     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2431     { WM_SETFOCUS, sent }, /* in MDI client */
2432
2433     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2434
2435     { HCBT_DESTROYWND, hook },
2436     /* Win2k sends wparam set to
2437      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2438      * while Win9x doesn't bother to set child window id according to
2439      * CLIENTCREATESTRUCT.idFirstChild
2440      */
2441     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2442
2443     { WM_SHOWWINDOW, sent|wparam, 0 },
2444     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2445     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2446     { WM_ERASEBKGND, sent|parent|optional },
2447     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2448
2449     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2450     { WM_DESTROY, sent },
2451     { WM_NCDESTROY, sent },
2452     { 0 }
2453 };
2454 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
2455 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
2456     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2457     { WM_GETMINMAXINFO, sent },
2458     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
2459     { WM_NCCALCSIZE, sent|wparam, 1 },
2460     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2461     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2462
2463     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2464     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2465     { HCBT_SETFOCUS, hook },
2466     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2467     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2468     { WM_SETFOCUS, sent }, /* in MDI client */
2469     { HCBT_SETFOCUS, hook },
2470     { WM_KILLFOCUS, sent }, /* in MDI client */
2471     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2472     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2473     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2474     { WM_SETFOCUS, sent|defwinproc },
2475     { WM_MDIACTIVATE, sent|defwinproc },
2476     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2477     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2478      /* in MDI frame */
2479     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2480     { WM_NCCALCSIZE, sent|wparam, 1 },
2481     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2482     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2483     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2484     { 0 }
2485 };
2486 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
2487 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
2488     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2489     { WM_GETMINMAXINFO, sent },
2490     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
2491     { WM_GETMINMAXINFO, sent|defwinproc },
2492     { WM_NCCALCSIZE, sent|wparam, 1 },
2493     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2494     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2495
2496     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2497     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2498     { HCBT_SETFOCUS, hook },
2499     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2500     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2501     { WM_SETFOCUS, sent }, /* in MDI client */
2502     { HCBT_SETFOCUS, hook },
2503     { WM_KILLFOCUS, sent }, /* in MDI client */
2504     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2505     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2506     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2507     { WM_SETFOCUS, sent|defwinproc },
2508     { WM_MDIACTIVATE, sent|defwinproc },
2509     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2510     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2511     { 0 }
2512 };
2513 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
2514 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
2515     { WM_MDIMAXIMIZE, sent }, /* in MDI client */
2516     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2517     { WM_GETMINMAXINFO, sent },
2518     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
2519     { WM_GETMINMAXINFO, sent|defwinproc },
2520     { WM_NCCALCSIZE, sent|wparam, 1 },
2521     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
2522     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2523     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|0x8000 },
2524     { WM_MOVE, sent|defwinproc },
2525     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2526
2527     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2528     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2529     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2530     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
2531     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2532     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
2533      /* in MDI frame */
2534     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2535     { WM_NCCALCSIZE, sent|wparam, 1 },
2536     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2537     { WM_MOVE, sent|defwinproc },
2538     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2539     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
2540      /* in MDI client */
2541     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2542     { WM_NCCALCSIZE, sent|wparam, 1 },
2543     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2544     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2545      /* in MDI child */
2546     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2547     { WM_GETMINMAXINFO, sent|defwinproc },
2548     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2549     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2550     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2551     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
2552     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
2553     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2554     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2555     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
2556      /* in MDI frame */
2557     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2558     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
2559     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
2560     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2561     { 0 }
2562 };
2563 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
2564 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
2565     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2566     { WM_GETMINMAXINFO, sent },
2567     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
2568     { WM_NCCALCSIZE, sent|wparam, 1 },
2569     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2570     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2571     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2572      /* in MDI frame */
2573     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2574     { WM_NCCALCSIZE, sent|wparam, 1 },
2575     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2576     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2577     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2578     { 0 }
2579 };
2580 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
2581 static const struct message WmRestoreMDIchildVisibleSeq[] = {
2582     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2583     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
2584     { WM_NCCALCSIZE, sent|wparam, 1 },
2585     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2586     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2587     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2588      /* in MDI frame */
2589     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2590     { WM_NCCALCSIZE, sent|wparam, 1 },
2591     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2592     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2593     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2594     { 0 }
2595 };
2596 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
2597 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
2598     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2599     { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
2600     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
2601     { WM_NCCALCSIZE, sent|wparam, 1 },
2602     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2603     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|0x8000 },
2604     { WM_MOVE, sent|defwinproc },
2605     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2606     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2607     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2608     { HCBT_SETFOCUS, hook },
2609     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2610     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2611     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2612     { WM_SETFOCUS, sent },
2613     { 0 }
2614 };
2615 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
2616 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
2617     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
2618     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|0x8000 },
2619     { WM_NCCALCSIZE, sent|wparam, 1 },
2620     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|0x8000 },
2621     { WM_MOVE, sent|defwinproc },
2622     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
2623     { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
2624     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2625     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2626     /* FIXME: Wine creates an icon/title window while Windows doesn't */
2627     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
2628     { 0 }
2629 };
2630 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
2631 static const struct message WmRestoreMDIchildInisibleSeq[] = {
2632     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2633     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
2634     { WM_NCCALCSIZE, sent|wparam, 1 },
2635     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2636     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2637     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2638     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2639      /* in MDI frame */
2640     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2641     { WM_NCCALCSIZE, sent|wparam, 1 },
2642     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2643     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2644     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2645     { 0 }
2646 };
2647
2648 static HWND mdi_client;
2649 static WNDPROC old_mdi_client_proc;
2650
2651 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2652 {
2653     struct message msg;
2654
2655     /* do not log painting messages */
2656     if (message != WM_PAINT &&
2657         message != WM_NCPAINT &&
2658         message != WM_SYNCPAINT &&
2659         message != WM_ERASEBKGND &&
2660         message != WM_NCPAINT &&
2661         message != WM_NCHITTEST &&
2662         message != WM_GETTEXT &&
2663         message != WM_MDIGETACTIVE &&
2664         message != WM_GETICON &&
2665         message != WM_DEVICECHANGE)
2666     {
2667         trace("mdi client: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
2668
2669         switch (message)
2670         {
2671             case WM_WINDOWPOSCHANGING:
2672             case WM_WINDOWPOSCHANGED:
2673             {
2674                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2675
2676                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2677                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2678                       winpos->hwnd, winpos->hwndInsertAfter,
2679                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2680                 dump_winpos_flags(winpos->flags);
2681
2682                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2683                  * in the high word for internal purposes
2684                  */
2685                 wParam = winpos->flags & 0xffff;
2686                 /* We are not interested in the flags that don't match under XP and Win9x */
2687                 wParam &= ~(SWP_NOZORDER);
2688                 break;
2689             }
2690         }
2691
2692         msg.message = message;
2693         msg.flags = sent|wparam|lparam;
2694         msg.wParam = wParam;
2695         msg.lParam = lParam;
2696         add_message(&msg);
2697     }
2698
2699     return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
2700 }
2701
2702 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2703 {
2704     static long defwndproc_counter = 0;
2705     LRESULT ret;
2706     struct message msg;
2707
2708     /* do not log painting messages */
2709     if (message != WM_PAINT &&
2710         message != WM_NCPAINT &&
2711         message != WM_SYNCPAINT &&
2712         message != WM_ERASEBKGND &&
2713         message != WM_NCPAINT &&
2714         message != WM_NCHITTEST &&
2715         message != WM_GETTEXT &&
2716         message != WM_GETICON &&
2717         message != WM_DEVICECHANGE)
2718     {
2719         trace("mdi child: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
2720
2721         switch (message)
2722         {
2723             case WM_WINDOWPOSCHANGING:
2724             case WM_WINDOWPOSCHANGED:
2725             {
2726                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2727
2728                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2729                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2730                       winpos->hwnd, winpos->hwndInsertAfter,
2731                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2732                 dump_winpos_flags(winpos->flags);
2733
2734                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2735                  * in the high word for internal purposes
2736                  */
2737                 wParam = winpos->flags & 0xffff;
2738                 /* We are not interested in the flags that don't match under XP and Win9x */
2739                 wParam &= ~(SWP_NOZORDER);
2740                 break;
2741             }
2742
2743             case WM_MDIACTIVATE:
2744             {
2745                 HWND active, client = GetParent(hwnd);
2746
2747                 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
2748
2749                 if (hwnd == (HWND)lParam) /* if we are being activated */
2750                     ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
2751                 else
2752                     ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
2753                 break;
2754             }
2755         }
2756
2757         msg.message = message;
2758         msg.flags = sent|wparam|lparam;
2759         if (defwndproc_counter) msg.flags |= defwinproc;
2760         msg.wParam = wParam;
2761         msg.lParam = lParam;
2762         add_message(&msg);
2763     }
2764
2765     defwndproc_counter++;
2766     ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
2767     defwndproc_counter--;
2768
2769     return ret;
2770 }
2771
2772 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2773 {
2774     static long defwndproc_counter = 0;
2775     LRESULT ret;
2776     struct message msg;
2777
2778     /* do not log painting messages */
2779     if (message != WM_PAINT &&
2780         message != WM_NCPAINT &&
2781         message != WM_SYNCPAINT &&
2782         message != WM_ERASEBKGND &&
2783         message != WM_NCPAINT &&
2784         message != WM_NCHITTEST &&
2785         message != WM_GETTEXT &&
2786         message != WM_GETICON &&
2787         message != WM_DEVICECHANGE)
2788     {
2789         trace("mdi frame: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
2790
2791         switch (message)
2792         {
2793             case WM_WINDOWPOSCHANGING:
2794             case WM_WINDOWPOSCHANGED:
2795             {
2796                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2797
2798                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2799                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2800                       winpos->hwnd, winpos->hwndInsertAfter,
2801                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2802                 dump_winpos_flags(winpos->flags);
2803
2804                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2805                  * in the high word for internal purposes
2806                  */
2807                 wParam = winpos->flags & 0xffff;
2808                 /* We are not interested in the flags that don't match under XP and Win9x */
2809                 wParam &= ~(SWP_NOZORDER);
2810                 break;
2811             }
2812         }
2813
2814         msg.message = message;
2815         msg.flags = sent|wparam|lparam;
2816         if (defwndproc_counter) msg.flags |= defwinproc;
2817         msg.wParam = wParam;
2818         msg.lParam = lParam;
2819         add_message(&msg);
2820     }
2821
2822     defwndproc_counter++;
2823     ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
2824     defwndproc_counter--;
2825
2826     return ret;
2827 }
2828
2829 static BOOL mdi_RegisterWindowClasses(void)
2830 {
2831     WNDCLASSA cls;
2832
2833     cls.style = 0;
2834     cls.lpfnWndProc = mdi_frame_wnd_proc;
2835     cls.cbClsExtra = 0;
2836     cls.cbWndExtra = 0;
2837     cls.hInstance = GetModuleHandleA(0);
2838     cls.hIcon = 0;
2839     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
2840     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
2841     cls.lpszMenuName = NULL;
2842     cls.lpszClassName = "MDI_frame_class";
2843     if (!RegisterClassA(&cls)) return FALSE;
2844
2845     cls.lpfnWndProc = mdi_child_wnd_proc;
2846     cls.lpszClassName = "MDI_child_class";
2847     if (!RegisterClassA(&cls)) return FALSE;
2848
2849     if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
2850     old_mdi_client_proc = cls.lpfnWndProc;
2851     cls.hInstance = GetModuleHandleA(0);
2852     cls.lpfnWndProc = mdi_client_hook_proc;
2853     cls.lpszClassName = "MDI_client_class";
2854     if (!RegisterClassA(&cls)) assert(0);
2855
2856     return TRUE;
2857 }
2858
2859 static void test_mdi_messages(void)
2860 {
2861     MDICREATESTRUCTA mdi_cs;
2862     CLIENTCREATESTRUCT client_cs;
2863     HWND mdi_frame, mdi_child, mdi_child2, active_child;
2864     BOOL zoomed;
2865     HMENU hMenu = CreateMenu();
2866
2867     assert(mdi_RegisterWindowClasses());
2868
2869     flush_sequence();
2870
2871     trace("creating MDI frame window\n");
2872     mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
2873                                 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2874                                 WS_MAXIMIZEBOX | WS_VISIBLE,
2875                                 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
2876                                 GetDesktopWindow(), hMenu,
2877                                 GetModuleHandleA(0), NULL);
2878     assert(mdi_frame);
2879     ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
2880
2881     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2882     ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
2883
2884     trace("creating MDI client window\n");
2885     client_cs.hWindowMenu = 0;
2886     client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
2887     mdi_client = CreateWindowExA(0, "MDI_client_class",
2888                                  NULL,
2889                                  WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
2890                                  0, 0, 0, 0,
2891                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
2892     assert(mdi_client);
2893     ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
2894
2895     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2896     ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
2897
2898     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2899     ok(!active_child, "wrong active MDI child %p\n", active_child);
2900     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2901
2902     SetFocus(0);
2903     flush_sequence();
2904
2905     trace("creating invisible MDI child window\n");
2906     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2907                                 WS_CHILD,
2908                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2909                                 mdi_client, 0, GetModuleHandleA(0), NULL);
2910     assert(mdi_child);
2911
2912     flush_sequence();
2913     ShowWindow(mdi_child, SW_SHOWNORMAL);
2914     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
2915
2916     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2917     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
2918
2919     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2920     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2921
2922     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2923     ok(!active_child, "wrong active MDI child %p\n", active_child);
2924     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2925
2926     ShowWindow(mdi_child, SW_HIDE);
2927     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
2928     flush_sequence();
2929
2930     ShowWindow(mdi_child, SW_SHOW);
2931     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
2932
2933     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2934     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
2935
2936     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2937     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2938
2939     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2940     ok(!active_child, "wrong active MDI child %p\n", active_child);
2941     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2942
2943     DestroyWindow(mdi_child);
2944     flush_sequence();
2945
2946     trace("creating visible MDI child window\n");
2947     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2948                                 WS_CHILD | WS_VISIBLE,
2949                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2950                                 mdi_client, 0, GetModuleHandleA(0), NULL);
2951     assert(mdi_child);
2952     ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
2953
2954     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2955     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
2956
2957     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2958     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
2959
2960     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2961     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
2962     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2963     flush_sequence();
2964
2965     DestroyWindow(mdi_child);
2966     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
2967
2968     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2969     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2970
2971     /* Win2k: MDI client still returns a just destroyed child as active
2972      * Win9x: MDI client returns 0
2973      */
2974     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2975     ok(active_child == mdi_child || /* win2k */
2976        !active_child, /* win9x */
2977        "wrong active MDI child %p\n", active_child);
2978     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2979
2980     flush_sequence();
2981
2982     trace("creating invisible MDI child window\n");
2983     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2984                                 WS_CHILD,
2985                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2986                                 mdi_client, 0, GetModuleHandleA(0), NULL);
2987     assert(mdi_child2);
2988     ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
2989
2990     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
2991     ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
2992
2993     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2994     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2995
2996     /* Win2k: MDI client still returns a just destroyed child as active
2997      * Win9x: MDI client returns mdi_child2
2998      */
2999     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3000     ok(active_child == mdi_child || /* win2k */
3001        active_child == mdi_child2, /* win9x */
3002        "wrong active MDI child %p\n", active_child);
3003     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3004     flush_sequence();
3005
3006     ShowWindow(mdi_child2, SW_MAXIMIZE);
3007     ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3008
3009     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3010     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3011
3012     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3013     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3014     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3015     flush_sequence();
3016
3017     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3018     ok(GetFocus() == mdi_child2 || /* win2k */
3019        GetFocus() == 0, /* win9x */
3020        "wrong focus window %p\n", GetFocus());
3021
3022     SetFocus(0);
3023     flush_sequence();
3024
3025     ShowWindow(mdi_child2, SW_HIDE);
3026     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3027
3028     ShowWindow(mdi_child2, SW_RESTORE);
3029     ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3030     flush_sequence();
3031
3032     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3033     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3034
3035     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3036     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3037     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3038     flush_sequence();
3039
3040     SetFocus(0);
3041     flush_sequence();
3042
3043     ShowWindow(mdi_child2, SW_HIDE);
3044     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3045
3046     ShowWindow(mdi_child2, SW_SHOW);
3047     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3048
3049     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3050     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3051
3052     ShowWindow(mdi_child2, SW_MAXIMIZE);
3053     ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3054
3055     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3056     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3057
3058     ShowWindow(mdi_child2, SW_RESTORE);
3059     ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3060
3061     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3062     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3063
3064     ShowWindow(mdi_child2, SW_MINIMIZE);
3065     ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3066
3067     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3068     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3069
3070     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3071     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3072     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3073     flush_sequence();
3074
3075     ShowWindow(mdi_child2, SW_RESTORE);
3076     ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", TRUE);
3077
3078     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3079     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3080
3081     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3082     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3083     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3084     flush_sequence();
3085
3086     SetFocus(0);
3087     flush_sequence();
3088
3089     ShowWindow(mdi_child2, SW_HIDE);
3090     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3091
3092     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3093     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3094
3095     DestroyWindow(mdi_child2);
3096     ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3097
3098     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3099     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3100
3101     /* test for maximized MDI children */
3102     trace("creating maximized visible MDI child window 1\n");
3103     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3104                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3105                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3106                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3107     assert(mdi_child);
3108     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3109     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3110
3111     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3112     ok(GetFocus() == mdi_child || /* win2k */
3113        GetFocus() == 0, /* win9x */
3114        "wrong focus window %p\n", GetFocus());
3115
3116     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3117     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3118     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3119     flush_sequence();
3120
3121     trace("creating maximized visible MDI child window 2\n");
3122     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3123                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3124                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3125                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3126     assert(mdi_child2);
3127     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3128     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3129     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3130
3131     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3132     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3133
3134     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3135     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3136     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3137     flush_sequence();
3138
3139     trace("destroying maximized visible MDI child window 2\n");
3140     DestroyWindow(mdi_child2);
3141     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3142
3143     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3144
3145     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3146     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3147
3148     /* Win2k: MDI client still returns a just destroyed child as active
3149      * Win9x: MDI client returns 0
3150      */
3151     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3152     ok(active_child == mdi_child2 || /* win2k */
3153        !active_child, /* win9x */
3154        "wrong active MDI child %p\n", active_child);
3155     flush_sequence();
3156
3157     ShowWindow(mdi_child, SW_MAXIMIZE);
3158     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3159     flush_sequence();
3160
3161     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3162     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3163
3164     trace("re-creating maximized visible MDI child window 2\n");
3165     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3166                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3167                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3168                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3169     assert(mdi_child2);
3170     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3171     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3172     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3173
3174     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3175     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3176
3177     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3178     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3179     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3180     flush_sequence();
3181
3182     SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3183     ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3184     ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3185
3186     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3187     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3188     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3189
3190     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3191     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3192     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3193     flush_sequence();
3194
3195     DestroyWindow(mdi_child);
3196     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3197
3198     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3199     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3200
3201     /* Win2k: MDI client still returns a just destroyed child as active
3202      * Win9x: MDI client returns 0
3203      */
3204     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3205     ok(active_child == mdi_child || /* win2k */
3206        !active_child, /* win9x */
3207        "wrong active MDI child %p\n", active_child);
3208     flush_sequence();
3209
3210     trace("creating maximized invisible MDI child window\n");
3211     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3212                                 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3213                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3214                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3215     assert(mdi_child2);
3216     ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", TRUE);
3217     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3218     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3219     ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3220
3221     /* Win2k: MDI client still returns a just destroyed child as active
3222      * Win9x: MDI client returns 0
3223      */
3224     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3225     ok(active_child == mdi_child || /* win2k */
3226        !active_child, /* win9x */
3227        "wrong active MDI child %p\n", active_child);
3228     flush_sequence();
3229
3230     trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3231     ShowWindow(mdi_child2, SW_MAXIMIZE);
3232     ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3233     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3234     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3235     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3236
3237     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3238     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3239     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3240     flush_sequence();
3241
3242     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3243     flush_sequence();
3244
3245     /* end of test for maximized MDI children */
3246     SetFocus(0);
3247     flush_sequence();
3248     trace("creating maximized visible MDI child window 1(Switch test)\n");
3249     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3250                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3251                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3252                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3253     assert(mdi_child);
3254     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3255     ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3256
3257     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3258     ok(GetFocus() == mdi_child || /* win2k */
3259        GetFocus() == 0, /* win9x */
3260        "wrong focus window %p(Switch test)\n", GetFocus());
3261
3262     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3263     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3264     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3265     flush_sequence();
3266
3267     trace("creating maximized visible MDI child window 2(Switch test)\n");
3268     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3269                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3270                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3271                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3272     assert(mdi_child2);
3273     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3274
3275     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3276     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3277
3278     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3279     ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3280
3281     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3282     ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3283     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3284     flush_sequence();
3285
3286     trace("Switch child window.\n");
3287     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3288     ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3289     trace("end of test for switch maximized MDI children\n");
3290
3291     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3292     flush_sequence();
3293
3294     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3295     flush_sequence();
3296
3297     SetFocus(0);
3298     flush_sequence();
3299     /* end of test for switch maximized MDI children */
3300
3301     mdi_cs.szClass = "MDI_child_Class";
3302     mdi_cs.szTitle = "MDI child";
3303     mdi_cs.hOwner = GetModuleHandleA(0);
3304     mdi_cs.x = 0;
3305     mdi_cs.y = 0;
3306     mdi_cs.cx = CW_USEDEFAULT;
3307     mdi_cs.cy = CW_USEDEFAULT;
3308     mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3309     mdi_cs.lParam = 0;
3310     mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3311     ok(mdi_child != 0, "MDI child creation failed\n");
3312     ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3313
3314     ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3315
3316     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3317     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3318
3319     ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3320     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3321     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3322
3323     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3324     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3325     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3326     flush_sequence();
3327
3328     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3329     ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3330
3331     ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3332     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3333     ok(!active_child, "wrong active MDI child %p\n", active_child);
3334
3335     SetFocus(0);
3336     flush_sequence();
3337
3338     DestroyWindow(mdi_client);
3339     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3340
3341     /* test maximization of MDI child with invisible parent */
3342     client_cs.hWindowMenu = 0;
3343     mdi_client = CreateWindow("MDI_client_class",
3344                                  NULL,
3345                                  WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3346                                  0, 0, 660, 430,
3347                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3348     ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3349
3350     ShowWindow(mdi_client, SW_HIDE);
3351     ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3352
3353     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3354                                 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3355                                 0, 0, 650, 440,
3356                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3357     ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3358
3359     SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3360     ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3361     zoomed = IsZoomed(mdi_child);
3362     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3363     
3364     ShowWindow(mdi_client, SW_SHOW);
3365     ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3366
3367     DestroyWindow(mdi_child);
3368     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3369
3370     /* end of test for maximization of MDI child with invisible parent */
3371
3372     DestroyWindow(mdi_client);
3373     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3374
3375     DestroyWindow(mdi_frame);
3376     ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3377 }
3378 /************************* End of MDI test **********************************/
3379
3380 static void test_WM_SETREDRAW(HWND hwnd)
3381 {
3382     DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3383
3384     flush_sequence();
3385
3386     SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3387     ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3388
3389     ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3390     ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3391
3392     flush_sequence();
3393     SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3394     ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3395
3396     ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3397     ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3398
3399     /* restore original WS_VISIBLE state */
3400     SetWindowLongA(hwnd, GWL_STYLE, style);
3401
3402     flush_sequence();
3403 }
3404
3405 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3406 {
3407     struct message msg;
3408
3409     trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
3410
3411     /* explicitly ignore WM_GETICON message */
3412     if (message == WM_GETICON) return 0;
3413
3414     switch (message)
3415     {
3416         /* ignore */
3417         case WM_MOUSEMOVE:
3418         case WM_SETCURSOR:
3419         case WM_DEVICECHANGE:
3420             return 0;
3421         case WM_NCHITTEST:
3422             return HTCLIENT;
3423
3424         case WM_WINDOWPOSCHANGING:
3425         case WM_WINDOWPOSCHANGED:
3426         {
3427             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
3428
3429             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
3430             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
3431                   winpos->hwnd, winpos->hwndInsertAfter,
3432                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
3433             dump_winpos_flags(winpos->flags);
3434
3435             /* Log only documented flags, win2k uses 0x1000 and 0x2000
3436              * in the high word for internal purposes
3437              */
3438             wParam = winpos->flags & 0xffff;
3439             /* We are not interested in the flags that don't match under XP and Win9x */
3440             wParam &= ~(SWP_NOZORDER);
3441             break;
3442         }
3443     }
3444
3445     msg.message = message;
3446     msg.flags = sent|wparam|lparam;
3447     msg.wParam = wParam;
3448     msg.lParam = lParam;
3449     add_message(&msg);
3450
3451     if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3452     if (message == WM_TIMER) EndDialog( hwnd, 0 );
3453     return 0;
3454 }
3455
3456 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3457 {
3458     DWORD style, exstyle;
3459     INT xmin, xmax;
3460     BOOL ret;
3461
3462     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3463     style = GetWindowLongA(hwnd, GWL_STYLE);
3464     /* do not be confused by WS_DLGFRAME set */
3465     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3466
3467     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3468     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3469
3470     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3471     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3472     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3473         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3474     else
3475         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3476
3477     style = GetWindowLongA(hwnd, GWL_STYLE);
3478     if (set) ok(style & set, "style %08x should be set\n", set);
3479     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3480
3481     /* a subsequent call should do nothing */
3482     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3483     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3484     ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3485
3486     xmin = 0xdeadbeef;
3487     xmax = 0xdeadbeef;
3488     trace("Ignore GetScrollRange error below if you are on Win9x\n");
3489     ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
3490     ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
3491     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3492     ok(xmin == min, "unexpected min scroll value %d\n", xmin);
3493     ok(xmax == max, "unexpected max scroll value %d\n", xmax);
3494 }
3495
3496 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3497 {
3498     DWORD style, exstyle;
3499     SCROLLINFO si;
3500     BOOL ret;
3501
3502     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3503     style = GetWindowLongA(hwnd, GWL_STYLE);
3504     /* do not be confused by WS_DLGFRAME set */
3505     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3506
3507     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3508     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3509
3510     si.cbSize = sizeof(si);
3511     si.fMask = SIF_RANGE;
3512     si.nMin = min;
3513     si.nMax = max;
3514     SetScrollInfo(hwnd, ctl, &si, TRUE);
3515     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3516         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
3517     else
3518         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
3519
3520     style = GetWindowLongA(hwnd, GWL_STYLE);
3521     if (set) ok(style & set, "style %08x should be set\n", set);
3522     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3523
3524     /* a subsequent call should do nothing */
3525     SetScrollInfo(hwnd, ctl, &si, TRUE);
3526     if (style & WS_HSCROLL)
3527         ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3528     else if (style & WS_VSCROLL)
3529         ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3530     else
3531         ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3532
3533     si.fMask = SIF_PAGE;
3534     si.nPage = 5;
3535     SetScrollInfo(hwnd, ctl, &si, FALSE);
3536     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3537
3538     si.fMask = SIF_POS;
3539     si.nPos = max - 1;
3540     SetScrollInfo(hwnd, ctl, &si, FALSE);
3541     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3542
3543     si.fMask = SIF_RANGE;
3544     si.nMin = 0xdeadbeef;
3545     si.nMax = 0xdeadbeef;
3546     ret = GetScrollInfo(hwnd, ctl, &si);
3547     ok( ret, "GetScrollInfo error %d\n", GetLastError());
3548     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3549     ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
3550     ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
3551 }
3552
3553 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
3554 static void test_scroll_messages(HWND hwnd)
3555 {
3556     SCROLLINFO si;
3557     INT min, max;
3558     BOOL ret;
3559
3560     min = 0xdeadbeef;
3561     max = 0xdeadbeef;
3562     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3563     ok( ret, "GetScrollRange error %d\n", GetLastError());
3564     if (sequence->message != WmGetScrollRangeSeq[0].message)
3565         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3566     /* values of min and max are undefined */
3567     flush_sequence();
3568
3569     ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
3570     ok( ret, "SetScrollRange error %d\n", GetLastError());
3571     if (sequence->message != WmSetScrollRangeSeq[0].message)
3572         trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3573     flush_sequence();
3574
3575     min = 0xdeadbeef;
3576     max = 0xdeadbeef;
3577     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3578     ok( ret, "GetScrollRange error %d\n", GetLastError());
3579     if (sequence->message != WmGetScrollRangeSeq[0].message)
3580         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3581     /* values of min and max are undefined */
3582     flush_sequence();
3583
3584     si.cbSize = sizeof(si);
3585     si.fMask = SIF_RANGE;
3586     si.nMin = 20;
3587     si.nMax = 160;
3588     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3589     if (sequence->message != WmSetScrollRangeSeq[0].message)
3590         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3591     flush_sequence();
3592
3593     si.fMask = SIF_PAGE;
3594     si.nPage = 10;
3595     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3596     if (sequence->message != WmSetScrollRangeSeq[0].message)
3597         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3598     flush_sequence();
3599
3600     si.fMask = SIF_POS;
3601     si.nPos = 20;
3602     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3603     if (sequence->message != WmSetScrollRangeSeq[0].message)
3604         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3605     flush_sequence();
3606
3607     si.fMask = SIF_RANGE;
3608     si.nMin = 0xdeadbeef;
3609     si.nMax = 0xdeadbeef;
3610     ret = GetScrollInfo(hwnd, SB_CTL, &si);
3611     ok( ret, "GetScrollInfo error %d\n", GetLastError());
3612     if (sequence->message != WmGetScrollInfoSeq[0].message)
3613         trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3614     /* values of min and max are undefined */
3615     flush_sequence();
3616
3617     /* set WS_HSCROLL */
3618     test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
3619     /* clear WS_HSCROLL */
3620     test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
3621
3622     /* set WS_HSCROLL */
3623     test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
3624     /* clear WS_HSCROLL */
3625     test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
3626
3627     /* set WS_VSCROLL */
3628     test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
3629     /* clear WS_VSCROLL */
3630     test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
3631
3632     /* set WS_VSCROLL */
3633     test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
3634     /* clear WS_VSCROLL */
3635     test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
3636 }
3637
3638 static void test_showwindow(void)
3639 {
3640     HWND hwnd, hchild;
3641     RECT rc;
3642
3643     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
3644                            100, 100, 200, 200, 0, 0, 0, NULL);
3645     ok (hwnd != 0, "Failed to create overlapped window\n");
3646     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
3647                              0, 0, 10, 10, hwnd, 0, 0, NULL);
3648     ok (hchild != 0, "Failed to create child\n");
3649     flush_sequence();
3650
3651     /* ShowWindow( SW_SHOWNA) for invisible top level window */
3652     trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
3653     ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3654     ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", TRUE);
3655     trace("done\n");
3656
3657     /* ShowWindow( SW_SHOWNA) for now visible top level window */
3658     trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
3659     ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3660     ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
3661     trace("done\n");
3662     /* back to invisible */
3663     ShowWindow(hchild, SW_HIDE);
3664     ShowWindow(hwnd, SW_HIDE);
3665     flush_sequence();
3666     /* ShowWindow(SW_SHOWNA) with child and parent invisible */ 
3667     trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
3668     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3669     ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
3670     trace("done\n");
3671     /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */ 
3672     ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
3673     flush_sequence();
3674     trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
3675     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3676     ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
3677     trace("done\n");
3678     /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
3679     ShowWindow( hwnd, SW_SHOW);
3680     flush_sequence();
3681     trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
3682     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3683     ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
3684     trace("done\n");
3685
3686     /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
3687     ShowWindow( hchild, SW_HIDE);
3688     flush_sequence();
3689     trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
3690     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3691     ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
3692     trace("done\n");
3693
3694     SetCapture(hchild);
3695     ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
3696     DestroyWindow(hchild);
3697     ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
3698
3699     DestroyWindow(hwnd);
3700     flush_sequence();
3701
3702     /* Popup windows */
3703     /* Test 1:
3704      * 1. Create invisible maximized popup window.
3705      * 2. Move and resize it.
3706      * 3. Show it maximized.
3707      */
3708     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
3709     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
3710                            100, 100, 200, 200, 0, 0, 0, NULL);
3711     ok (hwnd != 0, "Failed to create popup window\n");
3712     ok(IsZoomed(hwnd), "window should be maximized\n");
3713     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
3714     trace("done\n");
3715
3716     GetWindowRect(hwnd, &rc);
3717     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
3718         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
3719         "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
3720         rc.left, rc.top, rc.right, rc.bottom);
3721     /* Reset window's size & position */
3722     SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
3723     ok(IsZoomed(hwnd), "window should be maximized\n");
3724     flush_sequence();
3725
3726     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
3727     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3728     ok(IsZoomed(hwnd), "window should be maximized\n");
3729     ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
3730     trace("done\n");
3731
3732     GetWindowRect(hwnd, &rc);
3733     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
3734         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
3735         "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
3736         rc.left, rc.top, rc.right, rc.bottom);
3737     DestroyWindow(hwnd);
3738     flush_sequence();
3739
3740     /* Test 2:
3741      * 1. Create invisible maximized popup window.
3742      * 2. Show it maximized.
3743      */
3744     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
3745     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
3746                            100, 100, 200, 200, 0, 0, 0, NULL);
3747     ok (hwnd != 0, "Failed to create popup window\n");
3748     ok(IsZoomed(hwnd), "window should be maximized\n");
3749     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
3750     trace("done\n");
3751
3752     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
3753     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3754     ok(IsZoomed(hwnd), "window should be maximized\n");
3755     ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
3756     trace("done\n");
3757     DestroyWindow(hwnd);
3758     flush_sequence();
3759
3760     /* Test 3:
3761      * 1. Create visible maximized popup window.
3762      */
3763     trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
3764     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
3765                            100, 100, 200, 200, 0, 0, 0, NULL);
3766     ok (hwnd != 0, "Failed to create popup window\n");
3767     ok(IsZoomed(hwnd), "window should be maximized\n");
3768     ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
3769     trace("done\n");
3770     DestroyWindow(hwnd);
3771     flush_sequence();
3772
3773     /* Test 4:
3774      * 1. Create visible popup window.
3775      * 2. Maximize it.
3776      */
3777     trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
3778     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
3779                            100, 100, 200, 200, 0, 0, 0, NULL);
3780     ok (hwnd != 0, "Failed to create popup window\n");
3781     ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
3782     ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
3783     trace("done\n");
3784
3785     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
3786     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3787     ok(IsZoomed(hwnd), "window should be maximized\n");
3788     ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
3789     trace("done\n");
3790     DestroyWindow(hwnd);
3791     flush_sequence();
3792 }
3793
3794 static void test_sys_menu(void)
3795 {
3796     HWND hwnd;
3797     HMENU hmenu;
3798     UINT state;
3799
3800     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
3801                            100, 100, 200, 200, 0, 0, 0, NULL);
3802     ok (hwnd != 0, "Failed to create overlapped window\n");
3803
3804     flush_sequence();
3805
3806     /* test existing window without CS_NOCLOSE style */
3807     hmenu = GetSystemMenu(hwnd, FALSE);
3808     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
3809
3810     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3811     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3812     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
3813
3814     EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
3815     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
3816
3817     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3818     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3819     ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
3820
3821     EnableMenuItem(hmenu, SC_CLOSE, 0);
3822     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
3823
3824     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3825     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3826     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
3827
3828     /* test whether removing WS_SYSMENU destroys a system menu */
3829     SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
3830     SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
3831     flush_sequence();
3832     hmenu = GetSystemMenu(hwnd, FALSE);
3833     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
3834
3835     DestroyWindow(hwnd);
3836
3837     /* test new window with CS_NOCLOSE style */
3838     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
3839                            100, 100, 200, 200, 0, 0, 0, NULL);
3840     ok (hwnd != 0, "Failed to create overlapped window\n");
3841
3842     hmenu = GetSystemMenu(hwnd, FALSE);
3843     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
3844
3845     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3846     ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3847
3848     DestroyWindow(hwnd);
3849
3850     /* test new window without WS_SYSMENU style */
3851     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
3852                            100, 100, 200, 200, 0, 0, 0, NULL);
3853     ok(hwnd != 0, "Failed to create overlapped window\n");
3854
3855     hmenu = GetSystemMenu(hwnd, FALSE);
3856     ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
3857
3858     DestroyWindow(hwnd);
3859 }
3860
3861 /* For shown WS_OVERLAPPEDWINDOW */
3862 static const struct message WmSetIcon_1[] = {
3863     { WM_SETICON, sent },
3864     { 0x00AE, sent|defwinproc|optional }, /* XP */
3865     { WM_GETTEXT, sent|defwinproc|optional },
3866     { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
3867     { 0 }
3868 };
3869
3870 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
3871 static const struct message WmSetIcon_2[] = {
3872     { WM_SETICON, sent },
3873     { 0 }
3874 };
3875
3876 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
3877 static const struct message WmInitEndSession[] = {
3878     { 0x003B, sent },
3879     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
3880     { 0 }
3881 };
3882
3883 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
3884 static const struct message WmInitEndSession_2[] = {
3885     { 0x003B, sent },
3886     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
3887     { 0 }
3888 };
3889
3890 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
3891 static const struct message WmInitEndSession_3[] = {
3892     { 0x003B, sent },
3893     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
3894     { 0 }
3895 };
3896
3897 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
3898 static const struct message WmInitEndSession_4[] = {
3899     { 0x003B, sent },
3900     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
3901     { 0 }
3902 };
3903
3904 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
3905 static const struct message WmInitEndSession_5[] = {
3906     { 0x003B, sent },
3907     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 1, ENDSESSION_LOGOFF },
3908     { 0 }
3909 };
3910
3911 static void test_MsgWaitForMultipleObjects(HWND hwnd)
3912 {
3913     DWORD ret;
3914     MSG msg;
3915
3916     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3917     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
3918
3919     PostMessageA(hwnd, WM_USER, 0, 0);
3920
3921     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3922     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
3923
3924     ok(PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
3925     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
3926
3927     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3928     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
3929
3930     PostMessageA(hwnd, WM_USER, 0, 0);
3931
3932     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3933     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
3934
3935     ok(PeekMessageW( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
3936     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
3937
3938     /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
3939     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3940     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
3941
3942     PostMessageA(hwnd, WM_USER, 0, 0);
3943
3944     /* new incoming message causes it to become signaled again */
3945     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3946     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
3947
3948     ok(PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
3949     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
3950     ok(PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
3951     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
3952 }
3953
3954 /* test if we receive the right sequence of messages */
3955 static void test_messages(void)
3956 {
3957     HWND hwnd, hparent, hchild;
3958     HWND hchild2, hbutton;
3959     HMENU hmenu;
3960     MSG msg;
3961     LRESULT res;
3962
3963     flush_sequence();
3964
3965     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
3966                            100, 100, 200, 200, 0, 0, 0, NULL);
3967     ok (hwnd != 0, "Failed to create overlapped window\n");
3968     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
3969
3970     /* test ShowWindow(SW_HIDE) on a newly created invisible window */
3971     ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
3972     ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
3973
3974     /* test WM_SETREDRAW on a not visible top level window */
3975     test_WM_SETREDRAW(hwnd);
3976
3977     SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
3978     ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
3979     ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
3980
3981     ok(GetActiveWindow() == hwnd, "window should be active\n");
3982     ok(GetFocus() == hwnd, "window should have input focus\n");
3983     ShowWindow(hwnd, SW_HIDE);
3984     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", TRUE);
3985
3986     ShowWindow(hwnd, SW_SHOW);
3987     ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
3988
3989     ShowWindow(hwnd, SW_HIDE);
3990     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
3991
3992     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3993     ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
3994
3995     ShowWindow(hwnd, SW_RESTORE);
3996     /* FIXME: add ok_sequence() here */
3997     flush_sequence();
3998
3999     ShowWindow(hwnd, SW_MINIMIZE);
4000     ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4001     flush_sequence();
4002
4003     ShowWindow(hwnd, SW_RESTORE);
4004     /* FIXME: add ok_sequence() here */
4005     flush_sequence();
4006
4007     ShowWindow(hwnd, SW_SHOW);
4008     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4009
4010     ok(GetActiveWindow() == hwnd, "window should be active\n");
4011     ok(GetFocus() == hwnd, "window should have input focus\n");
4012     SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4013     ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4014     ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4015     ok(GetActiveWindow() == hwnd, "window should still be active\n");
4016
4017     /* test WM_SETREDRAW on a visible top level window */
4018     ShowWindow(hwnd, SW_SHOW);
4019     test_WM_SETREDRAW(hwnd);
4020
4021     trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4022     test_scroll_messages(hwnd);
4023
4024     /* test resizing and moving */
4025     SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4026     ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4027     flush_events();
4028     flush_sequence();
4029     SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4030     ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4031     flush_events();
4032     flush_sequence();
4033     SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER );
4034     ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4035     flush_events();
4036     flush_sequence();
4037
4038     /* popups don't get WM_GETMINMAXINFO */
4039     SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4040     SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4041     flush_sequence();
4042     SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4043     ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4044
4045     DestroyWindow(hwnd);
4046     ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4047
4048     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4049                               100, 100, 200, 200, 0, 0, 0, NULL);
4050     ok (hparent != 0, "Failed to create parent window\n");
4051     flush_sequence();
4052
4053     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4054                              0, 0, 10, 10, hparent, 0, 0, NULL);
4055     ok (hchild != 0, "Failed to create child window\n");
4056     ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4057     DestroyWindow(hchild);
4058     flush_sequence();
4059
4060     /* visible child window with a caption */
4061     hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4062                              WS_CHILD | WS_VISIBLE | WS_CAPTION,
4063                              0, 0, 10, 10, hparent, 0, 0, NULL);
4064     ok (hchild != 0, "Failed to create child window\n");
4065     ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4066
4067     trace("testing scroll APIs on a visible child window %p\n", hchild);
4068     test_scroll_messages(hchild);
4069
4070     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4071     ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4072
4073     DestroyWindow(hchild);
4074     flush_sequence();
4075
4076     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4077                              0, 0, 10, 10, hparent, 0, 0, NULL);
4078     ok (hchild != 0, "Failed to create child window\n");
4079     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4080     
4081     hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4082                                100, 100, 50, 50, hparent, 0, 0, NULL);
4083     ok (hchild2 != 0, "Failed to create child2 window\n");
4084     flush_sequence();
4085
4086     hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4087                               0, 100, 50, 50, hchild, 0, 0, NULL);
4088     ok (hbutton != 0, "Failed to create button window\n");
4089
4090     /* test WM_SETREDRAW on a not visible child window */
4091     test_WM_SETREDRAW(hchild);
4092
4093     ShowWindow(hchild, SW_SHOW);
4094     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4095
4096     /* check parent messages too */
4097     log_all_parent_messages++;
4098     ShowWindow(hchild, SW_HIDE);
4099     ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4100     log_all_parent_messages--;
4101
4102     ShowWindow(hchild, SW_SHOW);
4103     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4104
4105     ShowWindow(hchild, SW_HIDE);
4106     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4107
4108     ShowWindow(hchild, SW_SHOW);
4109     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4110
4111     /* test WM_SETREDRAW on a visible child window */
4112     test_WM_SETREDRAW(hchild);
4113
4114     log_all_parent_messages++;
4115     MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4116     ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4117     log_all_parent_messages--;
4118
4119     ShowWindow(hchild, SW_HIDE);
4120     flush_sequence();
4121     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4122     ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4123
4124     ShowWindow(hchild, SW_HIDE);
4125     flush_sequence();
4126     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4127     ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4128
4129     /* DestroyWindow sequence below expects that a child has focus */
4130     SetFocus(hchild);
4131     flush_sequence();
4132
4133     DestroyWindow(hchild);
4134     ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4135     DestroyWindow(hchild2);
4136     DestroyWindow(hbutton);
4137
4138     flush_sequence();
4139     hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4140                              0, 0, 100, 100, hparent, 0, 0, NULL);
4141     ok (hchild != 0, "Failed to create child popup window\n");
4142     ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4143     DestroyWindow(hchild);
4144
4145     /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4146     flush_sequence();
4147     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4148                              0, 0, 100, 100, hparent, 0, 0, NULL);
4149     ok (hchild != 0, "Failed to create popup window\n");
4150     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4151     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4152     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4153     flush_sequence();
4154     ShowWindow(hchild, SW_SHOW);
4155     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4156     flush_sequence();
4157     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4158     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4159     flush_sequence();
4160     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4161     ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", TRUE);
4162     DestroyWindow(hchild);
4163
4164     /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4165      * changes nothing in message sequences.
4166      */
4167     flush_sequence();
4168     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4169                              0, 0, 100, 100, hparent, 0, 0, NULL);
4170     ok (hchild != 0, "Failed to create popup window\n");
4171     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4172     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4173     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4174     flush_sequence();
4175     ShowWindow(hchild, SW_SHOW);
4176     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4177     flush_sequence();
4178     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4179     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4180     DestroyWindow(hchild);
4181
4182     flush_sequence();
4183     hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4184                            0, 0, 100, 100, hparent, 0, 0, NULL);
4185     ok(hwnd != 0, "Failed to create custom dialog window\n");
4186     ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4187
4188     /*
4189     trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4190     test_scroll_messages(hwnd);
4191     */
4192
4193     flush_sequence();
4194
4195     test_def_id = 1;
4196     SendMessage(hwnd, WM_NULL, 0, 0);
4197
4198     flush_sequence();
4199     after_end_dialog = 1;
4200     EndDialog( hwnd, 0 );
4201     ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4202
4203     DestroyWindow(hwnd);
4204     after_end_dialog = 0;
4205     test_def_id = 0;
4206
4207     hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4208                            0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4209     ok(hwnd != 0, "Failed to create custom dialog window\n");
4210     flush_sequence();
4211     trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4212     ShowWindow(hwnd, SW_SHOW);
4213     ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4214     DestroyWindow(hwnd);
4215
4216     flush_sequence();
4217     DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4218     ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4219
4220     DestroyWindow(hparent);
4221     flush_sequence();
4222
4223     /* Message sequence for SetMenu */
4224     ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4225     ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4226
4227     hmenu = CreateMenu();
4228     ok (hmenu != 0, "Failed to create menu\n");
4229     ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4230     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4231                            100, 100, 200, 200, 0, hmenu, 0, NULL);
4232     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4233     ok (SetMenu(hwnd, 0), "SetMenu\n");
4234     ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4235     ok (SetMenu(hwnd, 0), "SetMenu\n");
4236     ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4237     ShowWindow(hwnd, SW_SHOW);
4238     UpdateWindow( hwnd );
4239     flush_events();
4240     flush_sequence();
4241     ok (SetMenu(hwnd, 0), "SetMenu\n");
4242     ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4243     ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4244     ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4245
4246     UpdateWindow( hwnd );
4247     flush_events();
4248     flush_sequence();
4249     ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4250     flush_events();
4251     ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4252
4253     DestroyWindow(hwnd);
4254     flush_sequence();
4255
4256     /* Message sequence for EnableWindow */
4257     hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4258                               100, 100, 200, 200, 0, 0, 0, NULL);
4259     ok (hparent != 0, "Failed to create parent window\n");
4260     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4261                              0, 0, 10, 10, hparent, 0, 0, NULL);
4262     ok (hchild != 0, "Failed to create child window\n");
4263
4264     SetFocus(hchild);
4265     flush_events();
4266     flush_sequence();
4267
4268     EnableWindow(hparent, FALSE);
4269     ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4270
4271     EnableWindow(hparent, TRUE);
4272     ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4273
4274     flush_events();
4275     flush_sequence();
4276
4277     test_MsgWaitForMultipleObjects(hparent);
4278
4279     /* the following test causes an exception in user.exe under win9x */
4280     if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4281     {
4282         DestroyWindow(hparent);
4283         flush_sequence();
4284         return;
4285     }
4286     PostMessageW( hparent, WM_USER+1, 0, 0 );
4287     /* PeekMessage(NULL) fails, but still removes the message */
4288     SetLastError(0xdeadbeef);
4289     ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4290     ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4291         GetLastError() == 0xdeadbeef, /* NT4 */
4292         "last error is %d\n", GetLastError() );
4293     ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4294     ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4295
4296     DestroyWindow(hchild);
4297     DestroyWindow(hparent);
4298     flush_sequence();
4299
4300     /* Message sequences for WM_SETICON */
4301     trace("testing WM_SETICON\n");
4302     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4303                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4304                            NULL, NULL, 0);
4305     ShowWindow(hwnd, SW_SHOW);
4306     UpdateWindow(hwnd);
4307     flush_events();
4308     flush_sequence();
4309     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4310     ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4311
4312     ShowWindow(hwnd, SW_HIDE);
4313     flush_events();
4314     flush_sequence();
4315     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4316     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4317     DestroyWindow(hwnd);
4318     flush_sequence();
4319
4320     hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4321                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4322                            NULL, NULL, 0);
4323     ShowWindow(hwnd, SW_SHOW);
4324     UpdateWindow(hwnd);
4325     flush_events();
4326     flush_sequence();
4327     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4328     ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4329
4330     ShowWindow(hwnd, SW_HIDE);
4331     flush_events();
4332     flush_sequence();
4333     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4334     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4335
4336     flush_sequence();
4337     res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4338     ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4339     todo_wine
4340     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4341     res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4342     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4343     todo_wine
4344     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4345     res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4346     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4347     todo_wine
4348     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4349
4350     flush_sequence();
4351     res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4352     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4353     todo_wine
4354     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4355     res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4356     ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4357     todo_wine
4358     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4359
4360     res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4361     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4362     todo_wine
4363     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4364
4365     res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4366     ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4367     todo_wine
4368     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4369
4370     DestroyWindow(hwnd);
4371     flush_sequence();
4372 }
4373
4374 static void invisible_parent_tests(void)
4375 {
4376     HWND hparent, hchild;
4377
4378     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4379                               100, 100, 200, 200, 0, 0, 0, NULL);
4380     ok (hparent != 0, "Failed to create parent window\n");
4381     flush_sequence();
4382
4383     /* test showing child with hidden parent */
4384
4385     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4386                              0, 0, 10, 10, hparent, 0, 0, NULL);
4387     ok (hchild != 0, "Failed to create child window\n");
4388     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4389
4390     ShowWindow( hchild, SW_MINIMIZE );
4391     ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4392     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4393     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4394
4395     /* repeat */
4396     flush_events();
4397     flush_sequence();
4398     ShowWindow( hchild, SW_MINIMIZE );
4399     ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4400
4401     DestroyWindow(hchild);
4402     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4403                              0, 0, 10, 10, hparent, 0, 0, NULL);
4404     flush_sequence();
4405
4406     ShowWindow( hchild, SW_MAXIMIZE );
4407     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4408     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4409     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4410
4411     /* repeat */
4412     flush_events();
4413     flush_sequence();
4414     ShowWindow( hchild, SW_MAXIMIZE );
4415     ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4416
4417     DestroyWindow(hchild);
4418     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4419                              0, 0, 10, 10, hparent, 0, 0, NULL);
4420     flush_sequence();
4421
4422     ShowWindow( hchild, SW_RESTORE );
4423     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
4424     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4425     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4426
4427     DestroyWindow(hchild);
4428     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4429                              0, 0, 10, 10, hparent, 0, 0, NULL);
4430     flush_sequence();
4431
4432     ShowWindow( hchild, SW_SHOWMINIMIZED );
4433     ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4434     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4435     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4436
4437     /* repeat */
4438     flush_events();
4439     flush_sequence();
4440     ShowWindow( hchild, SW_SHOWMINIMIZED );
4441     ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4442
4443     DestroyWindow(hchild);
4444     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4445                              0, 0, 10, 10, hparent, 0, 0, NULL);
4446     flush_sequence();
4447
4448     /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
4449     ShowWindow( hchild, SW_SHOWMAXIMIZED );
4450     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
4451     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4452     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4453
4454     DestroyWindow(hchild);
4455     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4456                              0, 0, 10, 10, hparent, 0, 0, NULL);
4457     flush_sequence();
4458
4459     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4460     ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4461     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4462     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4463
4464     /* repeat */
4465     flush_events();
4466     flush_sequence();
4467     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4468     ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4469
4470     DestroyWindow(hchild);
4471     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4472                              0, 0, 10, 10, hparent, 0, 0, NULL);
4473     flush_sequence();
4474
4475     /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
4476     ShowWindow( hchild, SW_FORCEMINIMIZE );
4477     ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
4478 todo_wine {
4479     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4480 }
4481     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4482
4483     DestroyWindow(hchild);
4484     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4485                              0, 0, 10, 10, hparent, 0, 0, NULL);
4486     flush_sequence();
4487
4488     ShowWindow( hchild, SW_SHOWNA );
4489     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4490     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4491     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4492
4493     /* repeat */
4494     flush_events();
4495     flush_sequence();
4496     ShowWindow( hchild, SW_SHOWNA );
4497     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4498
4499     DestroyWindow(hchild);
4500     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4501                              0, 0, 10, 10, hparent, 0, 0, NULL);
4502     flush_sequence();
4503
4504     ShowWindow( hchild, SW_SHOW );
4505     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4506     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4507     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4508
4509     /* repeat */
4510     flush_events();
4511     flush_sequence();
4512     ShowWindow( hchild, SW_SHOW );
4513     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4514
4515     ShowWindow( hchild, SW_HIDE );
4516     ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
4517     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4518     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4519
4520     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4521     ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
4522     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4523     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4524
4525     SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4526     ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
4527     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
4528     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4529
4530     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4531     flush_sequence();
4532     DestroyWindow(hchild);
4533     ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
4534
4535     DestroyWindow(hparent);
4536     flush_sequence();
4537 }
4538
4539 /****************** button message test *************************/
4540 static const struct message WmSetFocusButtonSeq[] =
4541 {
4542     { HCBT_SETFOCUS, hook },
4543     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
4544     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4545     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4546     { WM_SETFOCUS, sent|wparam, 0 },
4547     { WM_CTLCOLORBTN, sent|defwinproc },
4548     { 0 }
4549 };
4550 static const struct message WmKillFocusButtonSeq[] =
4551 {
4552     { HCBT_SETFOCUS, hook },
4553     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4554     { WM_KILLFOCUS, sent|wparam, 0 },
4555     { WM_CTLCOLORBTN, sent|defwinproc },
4556     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
4557     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
4558     { 0 }
4559 };
4560 static const struct message WmSetFocusStaticSeq[] =
4561 {
4562     { HCBT_SETFOCUS, hook },
4563     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
4564     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4565     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4566     { WM_SETFOCUS, sent|wparam, 0 },
4567     { WM_CTLCOLORSTATIC, sent|defwinproc },
4568     { 0 }
4569 };
4570 static const struct message WmKillFocusStaticSeq[] =
4571 {
4572     { HCBT_SETFOCUS, hook },
4573     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4574     { WM_KILLFOCUS, sent|wparam, 0 },
4575     { WM_CTLCOLORSTATIC, sent|defwinproc },
4576     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
4577     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
4578     { 0 }
4579 };
4580 static const struct message WmLButtonDownSeq[] =
4581 {
4582     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
4583     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
4584     { HCBT_SETFOCUS, hook },
4585     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4586     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4587     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4588     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4589     { WM_CTLCOLORBTN, sent|defwinproc },
4590     { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
4591     { WM_CTLCOLORBTN, sent|defwinproc },
4592     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4593     { 0 }
4594 };
4595 static const struct message WmLButtonUpSeq[] =
4596 {
4597     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
4598     { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
4599     { WM_CTLCOLORBTN, sent|defwinproc },
4600     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4601     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
4602     { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
4603     { 0 }
4604 };
4605 static const struct message WmSetFontButtonSeq[] =
4606 {
4607     { WM_SETFONT, sent },
4608     { WM_PAINT, sent },
4609     { WM_ERASEBKGND, sent|defwinproc|optional },
4610     { WM_CTLCOLORBTN, sent|defwinproc },
4611     { 0 }
4612 };
4613
4614 static WNDPROC old_button_proc;
4615
4616 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4617 {
4618     static long defwndproc_counter = 0;
4619     LRESULT ret;
4620     struct message msg;
4621
4622     trace("button: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
4623
4624     /* explicitly ignore WM_GETICON message */
4625     if (message == WM_GETICON) return 0;
4626
4627     msg.message = message;
4628     msg.flags = sent|wparam|lparam;
4629     if (defwndproc_counter) msg.flags |= defwinproc;
4630     msg.wParam = wParam;
4631     msg.lParam = lParam;
4632     add_message(&msg);
4633
4634     if (message == BM_SETSTATE)
4635         ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
4636
4637     defwndproc_counter++;
4638     ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
4639     defwndproc_counter--;
4640
4641     return ret;
4642 }
4643
4644 static void subclass_button(void)
4645 {
4646     WNDCLASSA cls;
4647
4648     if (!GetClassInfoA(0, "button", &cls)) assert(0);
4649
4650     old_button_proc = cls.lpfnWndProc;
4651
4652     cls.hInstance = GetModuleHandle(0);
4653     cls.lpfnWndProc = button_hook_proc;
4654     cls.lpszClassName = "my_button_class";
4655     UnregisterClass(cls.lpszClassName, cls.hInstance);
4656     if (!RegisterClassA(&cls)) assert(0);
4657 }
4658
4659 static void test_button_messages(void)
4660 {
4661     static const struct
4662     {
4663         DWORD style;
4664         DWORD dlg_code;
4665         const struct message *setfocus;
4666         const struct message *killfocus;
4667     } button[] = {
4668         { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
4669           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
4670         { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
4671           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
4672         { BS_CHECKBOX, DLGC_BUTTON,
4673           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4674         { BS_AUTOCHECKBOX, DLGC_BUTTON,
4675           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4676         { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
4677           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4678         { BS_3STATE, DLGC_BUTTON,
4679           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4680         { BS_AUTO3STATE, DLGC_BUTTON,
4681           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4682         { BS_GROUPBOX, DLGC_STATIC,
4683           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4684         { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
4685           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
4686         { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
4687           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4688         { BS_OWNERDRAW, DLGC_BUTTON,
4689           WmSetFocusButtonSeq, WmKillFocusButtonSeq }
4690     };
4691     unsigned int i;
4692     HWND hwnd;
4693     DWORD dlg_code;
4694     HFONT zfont;
4695
4696     subclass_button();
4697
4698     for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
4699     {
4700         hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_POPUP,
4701                                0, 0, 50, 14, 0, 0, 0, NULL);
4702         ok(hwnd != 0, "Failed to create button window\n");
4703
4704         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
4705         ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
4706
4707         ShowWindow(hwnd, SW_SHOW);
4708         UpdateWindow(hwnd);
4709         SetFocus(0);
4710         flush_sequence();
4711
4712         trace("button style %08x\n", button[i].style);
4713         SetFocus(hwnd);
4714         ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
4715
4716         SetFocus(0);
4717         ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
4718
4719         DestroyWindow(hwnd);
4720     }
4721
4722     hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
4723                            0, 0, 50, 14, 0, 0, 0, NULL);
4724     ok(hwnd != 0, "Failed to create button window\n");
4725
4726     SetFocus(0);
4727     flush_events();
4728     flush_sequence();
4729
4730     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
4731     ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
4732
4733     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
4734     ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
4735
4736     flush_sequence();
4737     zfont = (HFONT)GetStockObject(SYSTEM_FONT);
4738     SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
4739     UpdateWindow(hwnd);
4740     ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
4741
4742     DestroyWindow(hwnd);
4743 }
4744
4745 /****************** static message test *************************/
4746 static const struct message WmSetFontStaticSeq[] =
4747 {
4748     { WM_SETFONT, sent },
4749     { WM_PAINT, sent|defwinproc },
4750     { WM_ERASEBKGND, sent|defwinproc|optional },
4751     { WM_CTLCOLORSTATIC, sent|defwinproc },
4752     { 0 }
4753 };
4754
4755 static WNDPROC old_static_proc;
4756
4757 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4758 {
4759     static long defwndproc_counter = 0;
4760     LRESULT ret;
4761     struct message msg;
4762
4763     trace("static: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
4764
4765     /* explicitly ignore WM_GETICON message */
4766     if (message == WM_GETICON) return 0;
4767
4768     msg.message = message;
4769     msg.flags = sent|wparam|lparam;
4770     if (defwndproc_counter) msg.flags |= defwinproc;
4771     msg.wParam = wParam;
4772     msg.lParam = lParam;
4773     add_message(&msg);
4774
4775
4776     defwndproc_counter++;
4777     ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
4778     defwndproc_counter--;
4779
4780     return ret;
4781 }
4782
4783 static void subclass_static(void)
4784 {
4785     WNDCLASSA cls;
4786
4787     if (!GetClassInfoA(0, "static", &cls)) assert(0);
4788
4789     old_static_proc = cls.lpfnWndProc;
4790
4791     cls.hInstance = GetModuleHandle(0);
4792     cls.lpfnWndProc = static_hook_proc;
4793     cls.lpszClassName = "my_static_class";
4794     UnregisterClass(cls.lpszClassName, cls.hInstance);
4795     if (!RegisterClassA(&cls)) assert(0);
4796 }
4797
4798 static void test_static_messages(void)
4799 {
4800     /* FIXME: make as comprehensive as the button message test */
4801     static const struct
4802     {
4803         DWORD style;
4804         DWORD dlg_code;
4805         const struct message *setfont;
4806     } static_ctrl[] = {
4807         { SS_LEFT, DLGC_STATIC,
4808           WmSetFontStaticSeq }
4809     };
4810     unsigned int i;
4811     HWND hwnd;
4812     DWORD dlg_code;
4813
4814     subclass_static();
4815
4816     for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
4817     {
4818         hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
4819                                0, 0, 50, 14, 0, 0, 0, NULL);
4820         ok(hwnd != 0, "Failed to create static window\n");
4821
4822         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
4823         ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
4824
4825         ShowWindow(hwnd, SW_SHOW);
4826         UpdateWindow(hwnd);
4827         SetFocus(0);
4828         flush_sequence();
4829
4830         trace("static style %08x\n", static_ctrl[i].style);
4831         SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
4832         ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
4833
4834         DestroyWindow(hwnd);
4835     }
4836 }
4837
4838 /************* painting message test ********************/
4839
4840 void dump_region(HRGN hrgn)
4841 {
4842     DWORD i, size;
4843     RGNDATA *data = NULL;
4844     RECT *rect;
4845
4846     if (!hrgn)
4847     {
4848         printf( "null region\n" );
4849         return;
4850     }
4851     if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
4852     if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
4853     GetRegionData( hrgn, size, data );
4854     printf("%d rects:", data->rdh.nCount );
4855     for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
4856         printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
4857     printf("\n");
4858     HeapFree( GetProcessHeap(), 0, data );
4859 }
4860
4861 static void check_update_rgn( HWND hwnd, HRGN hrgn )
4862 {
4863     INT ret;
4864     RECT r1, r2;
4865     HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
4866     HRGN update = CreateRectRgn( 0, 0, 0, 0 );
4867
4868     ret = GetUpdateRgn( hwnd, update, FALSE );
4869     ok( ret != ERROR, "GetUpdateRgn failed\n" );
4870     if (ret == NULLREGION)
4871     {
4872         ok( !hrgn, "Update region shouldn't be empty\n" );
4873     }
4874     else
4875     {
4876         if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
4877         {
4878             ok( 0, "Regions are different\n" );
4879             if (winetest_debug > 0)
4880             {
4881                 printf( "Update region: " );
4882                 dump_region( update );
4883                 printf( "Wanted region: " );
4884                 dump_region( hrgn );
4885             }
4886         }
4887     }
4888     GetRgnBox( update, &r1 );
4889     GetUpdateRect( hwnd, &r2, FALSE );
4890     ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
4891         "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
4892         r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
4893
4894     DeleteObject( tmp );
4895     DeleteObject( update );
4896 }
4897
4898 static const struct message WmInvalidateRgn[] = {
4899     { WM_NCPAINT, sent },
4900     { WM_GETTEXT, sent|defwinproc|optional },
4901     { 0 }
4902 };
4903
4904 static const struct message WmGetUpdateRect[] = {
4905     { WM_NCPAINT, sent },
4906     { WM_GETTEXT, sent|defwinproc|optional },
4907     { WM_PAINT, sent },
4908     { 0 }
4909 };
4910
4911 static const struct message WmInvalidateFull[] = {
4912     { WM_NCPAINT, sent|wparam, 1 },
4913     { WM_GETTEXT, sent|defwinproc|optional },
4914     { 0 }
4915 };
4916
4917 static const struct message WmInvalidateErase[] = {
4918     { WM_NCPAINT, sent|wparam, 1 },
4919     { WM_GETTEXT, sent|defwinproc|optional },
4920     { WM_ERASEBKGND, sent },
4921     { 0 }
4922 };
4923
4924 static const struct message WmInvalidatePaint[] = {
4925     { WM_PAINT, sent },
4926     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
4927     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4928     { 0 }
4929 };
4930
4931 static const struct message WmInvalidateErasePaint[] = {
4932     { WM_PAINT, sent },
4933     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
4934     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4935     { WM_ERASEBKGND, sent|beginpaint },
4936     { 0 }
4937 };
4938
4939 static const struct message WmInvalidateErasePaint2[] = {
4940     { WM_PAINT, sent },
4941     { WM_NCPAINT, sent|beginpaint },
4942     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4943     { WM_ERASEBKGND, sent|beginpaint },
4944     { 0 }
4945 };
4946
4947 static const struct message WmErase[] = {
4948     { WM_ERASEBKGND, sent },
4949     { 0 }
4950 };
4951
4952 static const struct message WmPaint[] = {
4953     { WM_PAINT, sent },
4954     { 0 }
4955 };
4956
4957 static const struct message WmParentOnlyPaint[] = {
4958     { WM_PAINT, sent|parent },
4959     { 0 }
4960 };
4961
4962 static const struct message WmInvalidateParent[] = {
4963     { WM_NCPAINT, sent|parent },
4964     { WM_GETTEXT, sent|defwinproc|parent|optional },
4965     { WM_ERASEBKGND, sent|parent },
4966     { 0 }
4967 };
4968
4969 static const struct message WmInvalidateParentChild[] = {
4970     { WM_NCPAINT, sent|parent },
4971     { WM_GETTEXT, sent|defwinproc|parent|optional },
4972     { WM_ERASEBKGND, sent|parent },
4973     { WM_NCPAINT, sent },
4974     { WM_GETTEXT, sent|defwinproc|optional },
4975     { WM_ERASEBKGND, sent },
4976     { 0 }
4977 };
4978
4979 static const struct message WmInvalidateParentChild2[] = {
4980     { WM_ERASEBKGND, sent|parent },
4981     { WM_NCPAINT, sent },
4982     { WM_GETTEXT, sent|defwinproc|optional },
4983     { WM_ERASEBKGND, sent },
4984     { 0 }
4985 };
4986
4987 static const struct message WmParentPaint[] = {
4988     { WM_PAINT, sent|parent },
4989     { WM_PAINT, sent },
4990     { 0 }
4991 };
4992
4993 static const struct message WmParentPaintNc[] = {
4994     { WM_PAINT, sent|parent },
4995     { WM_PAINT, sent },
4996     { WM_NCPAINT, sent|beginpaint },
4997     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4998     { WM_ERASEBKGND, sent|beginpaint },
4999     { 0 }
5000 };
5001
5002 static const struct message WmChildPaintNc[] = {
5003     { WM_PAINT, sent },
5004     { WM_NCPAINT, sent|beginpaint },
5005     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5006     { WM_ERASEBKGND, sent|beginpaint },
5007     { 0 }
5008 };
5009
5010 static const struct message WmParentErasePaint[] = {
5011     { WM_PAINT, sent|parent },
5012     { WM_NCPAINT, sent|parent|beginpaint },
5013     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5014     { WM_ERASEBKGND, sent|parent|beginpaint },
5015     { WM_PAINT, sent },
5016     { WM_NCPAINT, sent|beginpaint },
5017     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5018     { WM_ERASEBKGND, sent|beginpaint },
5019     { 0 }
5020 };
5021
5022 static const struct message WmParentOnlyNcPaint[] = {
5023     { WM_PAINT, sent|parent },
5024     { WM_NCPAINT, sent|parent|beginpaint },
5025     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5026     { 0 }
5027 };
5028
5029 static const struct message WmSetParentStyle[] = {
5030     { WM_STYLECHANGING, sent|parent },
5031     { WM_STYLECHANGED, sent|parent },
5032     { 0 }
5033 };
5034
5035 static void test_paint_messages(void)
5036 {
5037     BOOL ret;
5038     RECT rect;
5039     POINT pt;
5040     MSG msg;
5041     HWND hparent, hchild;
5042     HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
5043     HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
5044     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
5045                                 100, 100, 200, 200, 0, 0, 0, NULL);
5046     ok (hwnd != 0, "Failed to create overlapped window\n");
5047
5048     ShowWindow( hwnd, SW_SHOW );
5049     UpdateWindow( hwnd );
5050     flush_events();
5051     flush_sequence();
5052
5053     check_update_rgn( hwnd, 0 );
5054     SetRectRgn( hrgn, 10, 10, 20, 20 );
5055     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5056     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5057     check_update_rgn( hwnd, hrgn );
5058     SetRectRgn( hrgn2, 20, 20, 30, 30 );
5059     ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
5060     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5061     CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
5062     check_update_rgn( hwnd, hrgn );
5063     /* validate everything */
5064     ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5065     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5066     check_update_rgn( hwnd, 0 );
5067
5068     /* test empty region */
5069     SetRectRgn( hrgn, 10, 10, 10, 15 );
5070     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5071     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5072     check_update_rgn( hwnd, 0 );
5073     /* test empty rect */
5074     SetRect( &rect, 10, 10, 10, 15 );
5075     ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
5076     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5077     check_update_rgn( hwnd, 0 );
5078
5079     /* flush pending messages */
5080     flush_events();
5081     flush_sequence();
5082
5083     GetClientRect( hwnd, &rect );
5084     SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
5085     /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
5086      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5087      */
5088     trace("testing InvalidateRect(0, NULL, FALSE)\n");
5089     SetRectEmpty( &rect );
5090     ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
5091     check_update_rgn( hwnd, hrgn );
5092     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5093     flush_events();
5094     ok_sequence( WmPaint, "Paint", FALSE );
5095     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5096     check_update_rgn( hwnd, 0 );
5097
5098     /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
5099      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5100      */
5101     trace("testing ValidateRect(0, NULL)\n");
5102     SetRectEmpty( &rect );
5103     ok(ValidateRect(0, &rect), "ValidateRect(0, &rc) should not fail\n");
5104     check_update_rgn( hwnd, hrgn );
5105     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5106     flush_events();
5107     ok_sequence( WmPaint, "Paint", FALSE );
5108     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5109     check_update_rgn( hwnd, 0 );
5110
5111     trace("testing InvalidateRgn(0, NULL, FALSE)\n");
5112     SetLastError(0xdeadbeef);
5113     ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
5114     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error code %d\n", GetLastError());
5115     check_update_rgn( hwnd, 0 );
5116     flush_events();
5117     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5118
5119     trace("testing ValidateRgn(0, NULL)\n");
5120     SetLastError(0xdeadbeef);
5121     ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
5122     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error code %d\n", GetLastError());
5123     check_update_rgn( hwnd, 0 );
5124     flush_events();
5125     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5126
5127     /* now with frame */
5128     SetRectRgn( hrgn, -5, -5, 20, 20 );
5129
5130     /* flush pending messages */
5131     flush_events();
5132     flush_sequence();
5133     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5134     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5135
5136     SetRectRgn( hrgn, 0, 0, 20, 20 );  /* GetUpdateRgn clips to client area */
5137     check_update_rgn( hwnd, hrgn );
5138
5139     flush_sequence();
5140     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5141     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5142
5143     flush_sequence();
5144     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5145     ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
5146
5147     GetClientRect( hwnd, &rect );
5148     SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
5149     check_update_rgn( hwnd, hrgn );
5150
5151     flush_sequence();
5152     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
5153     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5154
5155     flush_sequence();
5156     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
5157     ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
5158     check_update_rgn( hwnd, 0 );
5159
5160     flush_sequence();
5161     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
5162     ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
5163     check_update_rgn( hwnd, 0 );
5164
5165     flush_sequence();
5166     SetRectRgn( hrgn, 0, 0, 100, 100 );
5167     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5168     SetRectRgn( hrgn, 0, 0, 50, 100 );
5169     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
5170     SetRectRgn( hrgn, 50, 0, 100, 100 );
5171     check_update_rgn( hwnd, hrgn );
5172     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5173     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );  /* must not generate messages, everything is valid */
5174     check_update_rgn( hwnd, 0 );
5175
5176     flush_sequence();
5177     SetRectRgn( hrgn, 0, 0, 100, 100 );
5178     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5179     SetRectRgn( hrgn, 0, 0, 100, 50 );
5180     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5181     ok_sequence( WmErase, "Erase", FALSE );
5182     SetRectRgn( hrgn, 0, 50, 100, 100 );
5183     check_update_rgn( hwnd, hrgn );
5184
5185     flush_sequence();
5186     SetRectRgn( hrgn, 0, 0, 100, 100 );
5187     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5188     SetRectRgn( hrgn, 0, 0, 50, 50 );
5189     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
5190     ok_sequence( WmPaint, "Paint", FALSE );
5191
5192     flush_sequence();
5193     SetRectRgn( hrgn, -4, -4, -2, -2 );
5194     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5195     SetRectRgn( hrgn, -200, -200, -198, -198 );
5196     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
5197     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5198
5199     flush_sequence();
5200     SetRectRgn( hrgn, -4, -4, -2, -2 );
5201     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5202     SetRectRgn( hrgn, -4, -4, -3, -3 );
5203     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
5204     SetRectRgn( hrgn, 0, 0, 1, 1 );
5205     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
5206     ok_sequence( WmPaint, "Paint", FALSE );
5207
5208     flush_sequence();
5209     SetRectRgn( hrgn, -4, -4, -1, -1 );
5210     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5211     RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
5212     /* make sure no WM_PAINT was generated */
5213     flush_events();
5214     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5215
5216     flush_sequence();
5217     SetRectRgn( hrgn, -4, -4, -1, -1 );
5218     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5219     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
5220     {
5221         if (msg.hwnd == hwnd && msg.message == WM_PAINT)
5222         {
5223             /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
5224             INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
5225             ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
5226             ret = GetUpdateRect( hwnd, &rect, FALSE );
5227             ok( ret, "Invalid GetUpdateRect result %d\n", ret );
5228             /* this will send WM_NCPAINT and validate the non client area */
5229             ret = GetUpdateRect( hwnd, &rect, TRUE );
5230             ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
5231         }
5232         DispatchMessage( &msg );
5233     }
5234     ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
5235
5236     DestroyWindow( hwnd );
5237
5238     /* now test with a child window */
5239
5240     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
5241                               100, 100, 200, 200, 0, 0, 0, NULL);
5242     ok (hparent != 0, "Failed to create parent window\n");
5243
5244     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
5245                            10, 10, 100, 100, hparent, 0, 0, NULL);
5246     ok (hchild != 0, "Failed to create child window\n");
5247
5248     ShowWindow( hparent, SW_SHOW );
5249     UpdateWindow( hparent );
5250     UpdateWindow( hchild );
5251     flush_events();
5252     flush_sequence();
5253     log_all_parent_messages++;
5254
5255     SetRect( &rect, 0, 0, 50, 50 );
5256     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5257     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5258     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
5259
5260     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5261     pt.x = pt.y = 0;
5262     MapWindowPoints( hchild, hparent, &pt, 1 );
5263     SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
5264     check_update_rgn( hchild, hrgn );
5265     SetRectRgn( hrgn, 0, 0, 50, 50 );
5266     check_update_rgn( hparent, hrgn );
5267     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5268     ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
5269     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5270     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5271
5272     flush_events();
5273     ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
5274
5275     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5276     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5277     ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
5278     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5279     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5280
5281     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
5282     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5283     ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
5284
5285     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
5286     flush_sequence();
5287     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5288     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5289     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
5290
5291     /* flush all paint messages */
5292     flush_events();
5293     flush_sequence();
5294
5295     /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
5296     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5297     SetRectRgn( hrgn, 0, 0, 50, 50 );
5298     check_update_rgn( hparent, hrgn );
5299     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5300     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5301     SetRectRgn( hrgn, 0, 0, 50, 50 );
5302     check_update_rgn( hparent, hrgn );
5303
5304     /* flush all paint messages */
5305     flush_events();
5306     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
5307     flush_sequence();
5308
5309     /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
5310     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5311     SetRectRgn( hrgn, 0, 0, 50, 50 );
5312     check_update_rgn( hparent, hrgn );
5313     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5314     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5315     SetRectRgn( hrgn2, 10, 10, 50, 50 );
5316     CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
5317     check_update_rgn( hparent, hrgn );
5318     /* flush all paint messages */
5319     flush_events();
5320     flush_sequence();
5321
5322     /* same as above but parent gets completely validated */
5323     SetRect( &rect, 20, 20, 30, 30 );
5324     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5325     SetRectRgn( hrgn, 20, 20, 30, 30 );
5326     check_update_rgn( hparent, hrgn );
5327     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5328     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5329     check_update_rgn( hparent, 0 );  /* no update region */
5330     flush_events();
5331     ok_sequence( WmEmptySeq, "WmEmpty", FALSE );  /* and no paint messages */
5332
5333     /* make sure RDW_VALIDATE on child doesn't have the same effect */
5334     flush_sequence();
5335     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5336     SetRectRgn( hrgn, 20, 20, 30, 30 );
5337     check_update_rgn( hparent, hrgn );
5338     RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
5339     SetRectRgn( hrgn, 20, 20, 30, 30 );
5340     check_update_rgn( hparent, hrgn );
5341
5342     /* same as above but normal WM_PAINT doesn't validate parent */
5343     flush_sequence();
5344     SetRect( &rect, 20, 20, 30, 30 );
5345     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5346     SetRectRgn( hrgn, 20, 20, 30, 30 );
5347     check_update_rgn( hparent, hrgn );
5348     /* no WM_PAINT in child while parent still pending */
5349     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5350     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
5351     while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5352     ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
5353
5354     flush_sequence();
5355     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5356     /* no WM_PAINT in child while parent still pending */
5357     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5358     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
5359     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
5360     /* now that parent is valid child should get WM_PAINT */
5361     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5362     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5363     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5364     ok_sequence( WmEmptySeq, "No other message", FALSE );
5365
5366     /* same thing with WS_CLIPCHILDREN in parent */
5367     flush_sequence();
5368     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
5369     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
5370     /* changing style invalidates non client area, but we need to invalidate something else to see it */
5371     RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
5372     ok_sequence( WmEmptySeq, "No message", FALSE );
5373     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
5374     ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
5375
5376     flush_sequence();
5377     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
5378     SetRectRgn( hrgn, 20, 20, 30, 30 );
5379     check_update_rgn( hparent, hrgn );
5380     /* no WM_PAINT in child while parent still pending */
5381     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5382     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
5383     /* WM_PAINT in parent first */
5384     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5385     ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
5386
5387     /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
5388     flush_sequence();
5389     SetRect( &rect, 0, 0, 30, 30 );
5390     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
5391     SetRectRgn( hrgn, 0, 0, 30, 30 );
5392     check_update_rgn( hparent, hrgn );
5393     flush_events();
5394     ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
5395
5396     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
5397     flush_sequence();
5398     SetRect( &rect, -10, 0, 30, 30 );
5399     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
5400     SetRect( &rect, 0, 0, 20, 20 );
5401     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
5402     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
5403     ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
5404
5405     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
5406     flush_sequence();
5407     SetRect( &rect, -10, 0, 30, 30 );
5408     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
5409     SetRect( &rect, 0, 0, 100, 100 );
5410     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
5411     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
5412     ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
5413     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5414     ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
5415
5416     /* test RDW_INTERNALPAINT behavior */
5417
5418     flush_sequence();
5419     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
5420     flush_events();
5421     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
5422
5423     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
5424     flush_events();
5425     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
5426
5427     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
5428     flush_events();
5429     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
5430
5431     assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
5432     UpdateWindow( hparent );
5433     flush_events();
5434     flush_sequence();
5435     trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
5436     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5437     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
5438                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5439     flush_events();
5440     ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
5441
5442     UpdateWindow( hparent );
5443     flush_events();
5444     flush_sequence();
5445     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
5446     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5447     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
5448                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5449     flush_events();
5450     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
5451
5452     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
5453     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
5454     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
5455     flush_events();
5456     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
5457
5458     assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
5459     UpdateWindow( hparent );
5460     flush_events();
5461     flush_sequence();
5462     trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
5463     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5464     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
5465                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5466     flush_events();
5467     ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
5468
5469     UpdateWindow( hparent );
5470     flush_events();
5471     flush_sequence();
5472     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
5473     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5474     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
5475                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5476     flush_events();
5477     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
5478
5479     log_all_parent_messages--;
5480     DestroyWindow( hparent );
5481     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
5482
5483     DeleteObject( hrgn );
5484     DeleteObject( hrgn2 );
5485 }
5486
5487 struct wnd_event
5488 {
5489     HWND hwnd;
5490     HANDLE event;
5491 };
5492
5493 static DWORD WINAPI thread_proc(void *param)
5494 {
5495     MSG msg;
5496     struct wnd_event *wnd_event = (struct wnd_event *)param;
5497
5498     wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
5499                                       100, 100, 200, 200, 0, 0, 0, NULL);
5500     ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
5501
5502     SetEvent(wnd_event->event);
5503
5504     while (GetMessage(&msg, 0, 0, 0))
5505     {
5506         TranslateMessage(&msg);
5507         DispatchMessage(&msg);
5508     }
5509
5510     ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
5511
5512     return 0;
5513 }
5514
5515 static void test_interthread_messages(void)
5516 {
5517     HANDLE hThread;
5518     DWORD tid;
5519     WNDPROC proc;
5520     MSG msg;
5521     char buf[256];
5522     int len, expected_len;
5523     struct wnd_event wnd_event;
5524     BOOL ret;
5525
5526     wnd_event.event = CreateEventW(NULL, 0, 0, NULL);
5527     if (!wnd_event.event)
5528     {
5529         trace("skipping interthread message test under win9x\n");
5530         return;
5531     }
5532
5533     hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
5534     ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
5535
5536     ok(WaitForSingleObject(wnd_event.event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5537
5538     CloseHandle(wnd_event.event);
5539
5540     SetLastError(0xdeadbeef);
5541     ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
5542     ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error code %d\n", GetLastError());
5543
5544     proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
5545     ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
5546
5547     expected_len = lstrlenA("window caption text");
5548     memset(buf, 0, sizeof(buf));
5549     SetLastError(0xdeadbeef);
5550     len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
5551     ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
5552     ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
5553
5554     msg.hwnd = wnd_event.hwnd;
5555     msg.message = WM_GETTEXT;
5556     msg.wParam = sizeof(buf);
5557     msg.lParam = (LPARAM)buf;
5558     memset(buf, 0, sizeof(buf));
5559     SetLastError(0xdeadbeef);
5560     len = DispatchMessageA(&msg);
5561     ok(!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY,
5562        "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
5563
5564     /* the following test causes an exception in user.exe under win9x */
5565     msg.hwnd = wnd_event.hwnd;
5566     msg.message = WM_TIMER;
5567     msg.wParam = 0;
5568     msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
5569     SetLastError(0xdeadbeef);
5570     len = DispatchMessageA(&msg);
5571     ok(!len && GetLastError() == 0xdeadbeef,
5572        "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
5573
5574     ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
5575     ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
5576
5577     ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5578     CloseHandle(hThread);
5579
5580     ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
5581 }
5582
5583
5584 static const struct message WmVkN[] = {
5585     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5586     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5587     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
5588     { WM_CHAR, wparam|lparam, 'n', 1 },
5589     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
5590     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5591     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5592     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5593     { 0 }
5594 };
5595 static const struct message WmShiftVkN[] = {
5596     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
5597     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
5598     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
5599     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5600     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5601     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
5602     { WM_CHAR, wparam|lparam, 'N', 1 },
5603     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
5604     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5605     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5606     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5607     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
5608     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
5609     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
5610     { 0 }
5611 };
5612 static const struct message WmCtrlVkN[] = {
5613     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5614     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5615     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5616     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5617     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5618     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
5619     { WM_CHAR, wparam|lparam, 0x000e, 1 },
5620     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
5621     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5622     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5623     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5624     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5625     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5626     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5627     { 0 }
5628 };
5629 static const struct message WmCtrlVkN_2[] = {
5630     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5631     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5632     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5633     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5634     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5635     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
5636     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5637     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5638     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5639     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5640     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5641     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5642     { 0 }
5643 };
5644 static const struct message WmAltVkN[] = {
5645     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5646     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5647     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5648     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
5649     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
5650     { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
5651     { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
5652     { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
5653     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
5654     { HCBT_SYSCOMMAND, hook },
5655     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
5656     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5657     { 0x00AE, sent|defwinproc|optional }, /* XP */
5658     { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
5659     { WM_INITMENU, sent|defwinproc },
5660     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
5661     { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
5662     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5663     { WM_CAPTURECHANGED, sent|defwinproc },
5664     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
5665     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
5666     { WM_EXITMENULOOP, sent|defwinproc },
5667     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
5668     { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
5669     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
5670     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
5671     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
5672     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5673     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5674     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5675     { 0 }
5676 };
5677 static const struct message WmAltVkN_2[] = {
5678     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5679     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5680     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5681     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
5682     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
5683     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
5684     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
5685     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
5686     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
5687     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5688     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5689     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5690     { 0 }
5691 };
5692 static const struct message WmCtrlAltVkN[] = {
5693     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5694     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5695     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5696     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5697     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5698     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5699     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
5700     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
5701     { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
5702     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
5703     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
5704     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
5705     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5706     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5707     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5708     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5709     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5710     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5711     { 0 }
5712 };
5713 static const struct message WmCtrlShiftVkN[] = {
5714     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5715     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5716     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5717     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
5718     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
5719     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
5720     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5721     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5722     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
5723     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5724     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5725     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5726     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
5727     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
5728     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
5729     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5730     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5731     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5732     { 0 }
5733 };
5734 static const struct message WmCtrlAltShiftVkN[] = {
5735     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5736     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5737     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5738     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5739     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5740     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5741     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
5742     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
5743     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
5744     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
5745     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
5746     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
5747     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
5748     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
5749     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
5750     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
5751     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
5752     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
5753     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5754     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5755     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5756     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5757     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5758     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5759     { 0 }
5760 };
5761 static const struct message WmAltPressRelease[] = {
5762     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5763     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5764     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5765     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5766     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5767     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5768     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
5769     { HCBT_SYSCOMMAND, hook },
5770     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
5771     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5772     { WM_INITMENU, sent|defwinproc },
5773     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
5774     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
5775     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
5776
5777     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
5778
5779     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
5780     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
5781     { WM_CAPTURECHANGED, sent|defwinproc },
5782     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
5783     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
5784     { WM_EXITMENULOOP, sent|defwinproc },
5785     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5786     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5787     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5788     { 0 }
5789 };
5790 static const struct message WmAltMouseButton[] = {
5791     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5792     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5793     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5794     { WM_MOUSEMOVE, wparam|optional, 0, 0 },
5795     { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
5796     { WM_LBUTTONDOWN, wparam, MK_LBUTTON, 0 },
5797     { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON, 0 },
5798     { WM_LBUTTONUP, wparam, 0, 0 },
5799     { WM_LBUTTONUP, sent|wparam, 0, 0 },
5800     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5801     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5802     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5803     { 0 }
5804 };
5805 static const struct message WmF1Seq[] = {
5806     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
5807     { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
5808     { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
5809     { 0x4d, wparam|lparam, 0, 0 },
5810     { 0x4d, sent|wparam|lparam, 0, 0 },
5811     { WM_HELP, sent|defwinproc },
5812     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
5813     { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
5814     { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
5815     { 0 }
5816 };
5817 static const struct message WmVkAppsSeq[] = {
5818     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
5819     { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
5820     { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
5821     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
5822     { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
5823     { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
5824     { WM_CONTEXTMENU, lparam, /*hwnd*/0, (LPARAM)-1 },
5825     { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, (LPARAM)-1 },
5826     { 0 }
5827 };
5828
5829 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
5830 {
5831     MSG msg;
5832
5833     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
5834     {
5835         struct message log_msg;
5836
5837         trace("accel: %p, %04x, %08lx, %08lx\n", msg.hwnd, msg.message, msg.wParam, msg.lParam);
5838
5839         /* ignore some unwanted messages */
5840         if (msg.message == WM_MOUSEMOVE ||
5841             msg.message == WM_GETICON ||
5842             msg.message == WM_DEVICECHANGE)
5843             continue;
5844
5845         log_msg.message = msg.message;
5846         log_msg.flags = wparam|lparam;
5847         log_msg.wParam = msg.wParam;
5848         log_msg.lParam = msg.lParam;
5849         add_message(&log_msg);
5850
5851         if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
5852         {
5853             TranslateMessage(&msg);
5854             DispatchMessage(&msg);
5855         }
5856     }
5857 }
5858
5859 static void test_accelerators(void)
5860 {
5861     RECT rc;
5862     SHORT state;
5863     HACCEL hAccel;
5864     HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5865                                 100, 100, 200, 200, 0, 0, 0, NULL);
5866     BOOL ret;
5867
5868     assert(hwnd != 0);
5869     UpdateWindow(hwnd);
5870     flush_events();
5871     flush_sequence();
5872
5873     SetFocus(hwnd);
5874     ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
5875
5876     state = GetKeyState(VK_SHIFT);
5877     ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
5878     state = GetKeyState(VK_CAPITAL);
5879     ok(state == 0, "wrong CapsLock state %04x\n", state);
5880
5881     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
5882     assert(hAccel != 0);
5883
5884     pump_msg_loop(hwnd, 0);
5885     flush_sequence();
5886
5887     trace("testing VK_N press/release\n");
5888     flush_sequence();
5889     keybd_event('N', 0, 0, 0);
5890     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5891     pump_msg_loop(hwnd, hAccel);
5892     ok_sequence(WmVkN, "VK_N press/release", FALSE);
5893
5894     trace("testing Shift+VK_N press/release\n");
5895     flush_sequence();
5896     keybd_event(VK_SHIFT, 0, 0, 0);
5897     keybd_event('N', 0, 0, 0);
5898     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5899     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
5900     pump_msg_loop(hwnd, hAccel);
5901     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
5902
5903     trace("testing Ctrl+VK_N press/release\n");
5904     flush_sequence();
5905     keybd_event(VK_CONTROL, 0, 0, 0);
5906     keybd_event('N', 0, 0, 0);
5907     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5908     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
5909     pump_msg_loop(hwnd, hAccel);
5910     ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
5911
5912     trace("testing Alt+VK_N press/release\n");
5913     flush_sequence();
5914     keybd_event(VK_MENU, 0, 0, 0);
5915     keybd_event('N', 0, 0, 0);
5916     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5917     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
5918     pump_msg_loop(hwnd, hAccel);
5919     ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
5920
5921     trace("testing Ctrl+Alt+VK_N press/release 1\n");
5922     flush_sequence();
5923     keybd_event(VK_CONTROL, 0, 0, 0);
5924     keybd_event(VK_MENU, 0, 0, 0);
5925     keybd_event('N', 0, 0, 0);
5926     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5927     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
5928     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
5929     pump_msg_loop(hwnd, hAccel);
5930     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
5931
5932     ret = DestroyAcceleratorTable(hAccel);
5933     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
5934
5935     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
5936     assert(hAccel != 0);
5937
5938     trace("testing VK_N press/release\n");
5939     flush_sequence();
5940     keybd_event('N', 0, 0, 0);
5941     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5942     pump_msg_loop(hwnd, hAccel);
5943     ok_sequence(WmVkN, "VK_N press/release", FALSE);
5944
5945     trace("testing Shift+VK_N press/release\n");
5946     flush_sequence();
5947     keybd_event(VK_SHIFT, 0, 0, 0);
5948     keybd_event('N', 0, 0, 0);
5949     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5950     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
5951     pump_msg_loop(hwnd, hAccel);
5952     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
5953
5954     trace("testing Ctrl+VK_N press/release 2\n");
5955     flush_sequence();
5956     keybd_event(VK_CONTROL, 0, 0, 0);
5957     keybd_event('N', 0, 0, 0);
5958     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5959     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
5960     pump_msg_loop(hwnd, hAccel);
5961     ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
5962
5963     trace("testing Alt+VK_N press/release 2\n");
5964     flush_sequence();
5965     keybd_event(VK_MENU, 0, 0, 0);
5966     keybd_event('N', 0, 0, 0);
5967     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5968     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
5969     pump_msg_loop(hwnd, hAccel);
5970     ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
5971
5972     trace("testing Ctrl+Alt+VK_N press/release 2\n");
5973     flush_sequence();
5974     keybd_event(VK_CONTROL, 0, 0, 0);
5975     keybd_event(VK_MENU, 0, 0, 0);
5976     keybd_event('N', 0, 0, 0);
5977     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5978     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
5979     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
5980     pump_msg_loop(hwnd, hAccel);
5981     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
5982
5983     trace("testing Ctrl+Shift+VK_N press/release\n");
5984     flush_sequence();
5985     keybd_event(VK_CONTROL, 0, 0, 0);
5986     keybd_event(VK_SHIFT, 0, 0, 0);
5987     keybd_event('N', 0, 0, 0);
5988     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5989     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
5990     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
5991     pump_msg_loop(hwnd, hAccel);
5992     ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
5993
5994     trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
5995     flush_sequence();
5996     keybd_event(VK_CONTROL, 0, 0, 0);
5997     keybd_event(VK_MENU, 0, 0, 0);
5998     keybd_event(VK_SHIFT, 0, 0, 0);
5999     keybd_event('N', 0, 0, 0);
6000     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6001     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6002     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6003     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6004     pump_msg_loop(hwnd, hAccel);
6005     ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
6006
6007     ret = DestroyAcceleratorTable(hAccel);
6008     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6009
6010     trace("testing Alt press/release\n");
6011     flush_sequence();
6012     keybd_event(VK_MENU, 0, 0, 0);
6013     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6014     keybd_event(VK_MENU, 0, 0, 0);
6015     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6016     pump_msg_loop(hwnd, 0);
6017     /* this test doesn't pass in Wine for managed windows */
6018     ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
6019
6020     trace("testing Alt+MouseButton press/release\n");
6021     /* first, move mouse pointer inside of the window client area */
6022     GetClientRect(hwnd, &rc);
6023     MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
6024     rc.left += (rc.right - rc.left)/2;
6025     rc.top += (rc.bottom - rc.top)/2;
6026     SetCursorPos(rc.left, rc.top);
6027
6028     flush_events();
6029     flush_sequence();
6030     keybd_event(VK_MENU, 0, 0, 0);
6031     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
6032     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
6033     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6034     pump_msg_loop(hwnd, 0);
6035     ok_sequence(WmAltMouseButton, "Alt+MouseButton press/release", FALSE);
6036
6037     trace("testing VK_F1 press/release\n");
6038     keybd_event(VK_F1, 0, 0, 0);
6039     keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
6040     pump_msg_loop(hwnd, 0);
6041     ok_sequence(WmF1Seq, "F1 press/release", TRUE);
6042
6043     trace("testing VK_APPS press/release\n");
6044     keybd_event(VK_APPS, 0, 0, 0);
6045     keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
6046     pump_msg_loop(hwnd, 0);
6047     ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
6048
6049     DestroyWindow(hwnd);
6050 }
6051
6052 /************* window procedures ********************/
6053
6054 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message, 
6055                              WPARAM wParam, LPARAM lParam)
6056 {
6057     static long defwndproc_counter = 0;
6058     static long beginpaint_counter = 0;
6059     LRESULT ret;
6060     struct message msg;
6061
6062     trace("%p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6063
6064     /* explicitly ignore WM_GETICON message */
6065     if (message == WM_GETICON) return 0;
6066
6067     switch (message)
6068     {
6069         case WM_ENABLE:
6070         {
6071             LONG style = GetWindowLongA(hwnd, GWL_STYLE);
6072             ok((BOOL)wParam == !(style & WS_DISABLED),
6073                 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
6074             break;
6075         }
6076
6077         case WM_CAPTURECHANGED:
6078             if (test_DestroyWindow_flag)
6079             {
6080                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6081                 if (style & WS_CHILD)
6082                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6083                 else if (style & WS_POPUP)
6084                     lParam = WND_POPUP_ID;
6085                 else
6086                     lParam = WND_PARENT_ID;
6087             }
6088             break;
6089
6090         case WM_NCDESTROY:
6091         {
6092             HWND capture;
6093
6094             ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
6095             capture = GetCapture();
6096             if (capture)
6097             {
6098                 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
6099                 trace("current capture %p, releasing...\n", capture);
6100                 ReleaseCapture();
6101             }
6102         }
6103         /* fall through */
6104         case WM_DESTROY:
6105             if (pGetAncestor)
6106                 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
6107             if (test_DestroyWindow_flag)
6108             {
6109                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6110                 if (style & WS_CHILD)
6111                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6112                 else if (style & WS_POPUP)
6113                     lParam = WND_POPUP_ID;
6114                 else
6115                     lParam = WND_PARENT_ID;
6116             }
6117             break;
6118
6119         /* test_accelerators() depends on this */
6120         case WM_NCHITTEST:
6121             return HTCLIENT;
6122     
6123         /* ignore */
6124         case WM_MOUSEMOVE:
6125         case WM_SETCURSOR:
6126         case WM_DEVICECHANGE:
6127             return 0;
6128
6129         case WM_WINDOWPOSCHANGING:
6130         case WM_WINDOWPOSCHANGED:
6131         {
6132             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6133
6134             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6135             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6136                   winpos->hwnd, winpos->hwndInsertAfter,
6137                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6138             dump_winpos_flags(winpos->flags);
6139
6140             /* Log only documented flags, win2k uses 0x1000 and 0x2000
6141              * in the high word for internal purposes
6142              */
6143             wParam = winpos->flags & 0xffff;
6144             /* We are not interested in the flags that don't match under XP and Win9x */
6145             wParam &= ~(SWP_NOZORDER);
6146             break;
6147         }
6148     }
6149
6150     msg.message = message;
6151     msg.flags = sent|wparam|lparam;
6152     if (defwndproc_counter) msg.flags |= defwinproc;
6153     if (beginpaint_counter) msg.flags |= beginpaint;
6154     msg.wParam = wParam;
6155     msg.lParam = lParam;
6156     add_message(&msg);
6157
6158     if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
6159     {
6160         HWND parent = GetParent(hwnd);
6161         RECT rc;
6162         MINMAXINFO *minmax = (MINMAXINFO *)lParam;
6163
6164         GetClientRect(parent, &rc);
6165         trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
6166
6167         trace("ptReserved = (%d,%d)\n"
6168               "ptMaxSize = (%d,%d)\n"
6169               "ptMaxPosition = (%d,%d)\n"
6170               "ptMinTrackSize = (%d,%d)\n"
6171               "ptMaxTrackSize = (%d,%d)\n",
6172               minmax->ptReserved.x, minmax->ptReserved.y,
6173               minmax->ptMaxSize.x, minmax->ptMaxSize.y,
6174               minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
6175               minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
6176               minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
6177
6178         ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
6179            minmax->ptMaxSize.x, rc.right);
6180         ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
6181            minmax->ptMaxSize.y, rc.bottom);
6182     }
6183
6184     if (message == WM_PAINT)
6185     {
6186         PAINTSTRUCT ps;
6187         beginpaint_counter++;
6188         BeginPaint( hwnd, &ps );
6189         beginpaint_counter--;
6190         EndPaint( hwnd, &ps );
6191         return 0;
6192     }
6193
6194     defwndproc_counter++;
6195     ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam) 
6196                   : DefWindowProcA(hwnd, message, wParam, lParam);
6197     defwndproc_counter--;
6198
6199     return ret;
6200 }
6201
6202 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6203 {
6204     return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
6205 }
6206
6207 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6208 {
6209     return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
6210 }
6211
6212 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6213 {
6214     static long defwndproc_counter = 0;
6215     LRESULT ret;
6216     struct message msg;
6217
6218     trace("popup: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6219
6220     /* explicitly ignore WM_GETICON message */
6221     if (message == WM_GETICON) return 0;
6222
6223     msg.message = message;
6224     msg.flags = sent|wparam|lparam;
6225     if (defwndproc_counter) msg.flags |= defwinproc;
6226     msg.wParam = wParam;
6227     msg.lParam = lParam;
6228     add_message(&msg);
6229
6230     if (message == WM_CREATE)
6231     {
6232         DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
6233         SetWindowLongA(hwnd, GWL_STYLE, style);
6234     }
6235
6236     defwndproc_counter++;
6237     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6238     defwndproc_counter--;
6239
6240     return ret;
6241 }
6242
6243 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6244 {
6245     static long defwndproc_counter = 0;
6246     static long beginpaint_counter = 0;
6247     LRESULT ret;
6248     struct message msg;
6249
6250     trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6251
6252     /* explicitly ignore WM_GETICON message */
6253     if (message == WM_GETICON) return 0;
6254
6255     if (log_all_parent_messages ||
6256         message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
6257         message == WM_SETFOCUS || message == WM_KILLFOCUS ||
6258         message == WM_ENABLE || message == WM_ENTERIDLE ||
6259         message == WM_DRAWITEM ||
6260         message == WM_IME_SETCONTEXT)
6261     {
6262         switch (message)
6263         {
6264             /* ignore */
6265             case WM_NCHITTEST:
6266                 return HTCLIENT;
6267             case WM_SETCURSOR:
6268             case WM_MOUSEMOVE:
6269                 return 0;
6270
6271             case WM_ERASEBKGND:
6272             {
6273                 RECT rc;
6274                 INT ret = GetClipBox((HDC)wParam, &rc);
6275
6276                 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
6277                        ret, rc.left, rc.top, rc.right, rc.bottom);
6278                 break;
6279             }
6280
6281             case WM_WINDOWPOSCHANGING:
6282             case WM_WINDOWPOSCHANGED:
6283             {
6284                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6285
6286                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6287                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6288                       winpos->hwnd, winpos->hwndInsertAfter,
6289                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6290                 dump_winpos_flags(winpos->flags);
6291
6292                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
6293                  * in the high word for internal purposes
6294                  */
6295                 wParam = winpos->flags & 0xffff;
6296                 /* We are not interested in the flags that don't match under XP and Win9x */
6297                 wParam &= ~(SWP_NOZORDER);
6298                 break;
6299             }
6300
6301             case WM_DRAWITEM:
6302             {
6303                 /* encode DRAWITEMSTRUCT into an LPARAM */
6304                 DRAW_ITEM_STRUCT di;
6305                 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam;
6306
6307                 trace("WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x\n",
6308                       dis->CtlType, dis->CtlID, dis->itemID, dis->itemAction, dis->itemState);
6309
6310                 di.u.item.type = dis->CtlType;
6311                 di.u.item.ctl_id = dis->CtlID;
6312                 di.u.item.item_id = dis->itemID;
6313                 di.u.item.action = dis->itemAction;
6314                 di.u.item.state = dis->itemState;
6315
6316                 lParam = di.u.lp;
6317                 break;
6318             }
6319         }
6320
6321         msg.message = message;
6322         msg.flags = sent|parent|wparam|lparam;
6323         if (defwndproc_counter) msg.flags |= defwinproc;
6324         if (beginpaint_counter) msg.flags |= beginpaint;
6325         msg.wParam = wParam;
6326         msg.lParam = lParam;
6327         add_message(&msg);
6328     }
6329
6330     if (message == WM_PAINT)
6331     {
6332         PAINTSTRUCT ps;
6333         beginpaint_counter++;
6334         BeginPaint( hwnd, &ps );
6335         beginpaint_counter--;
6336         EndPaint( hwnd, &ps );
6337         return 0;
6338     }
6339
6340     defwndproc_counter++;
6341     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6342     defwndproc_counter--;
6343
6344     return ret;
6345 }
6346
6347 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6348 {
6349     static long defwndproc_counter = 0;
6350     LRESULT ret;
6351     struct message msg;
6352
6353     trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6354
6355     /* explicitly ignore WM_GETICON message */
6356     if (message == WM_GETICON) return 0;
6357
6358     if (test_def_id)
6359     {
6360         DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
6361         ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
6362         if (after_end_dialog)
6363             ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
6364         else
6365             ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
6366     }
6367
6368     switch (message)
6369     {
6370         case WM_WINDOWPOSCHANGING:
6371         case WM_WINDOWPOSCHANGED:
6372         {
6373             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6374
6375             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6376             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6377                   winpos->hwnd, winpos->hwndInsertAfter,
6378                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6379             dump_winpos_flags(winpos->flags);
6380
6381             /* Log only documented flags, win2k uses 0x1000 and 0x2000
6382              * in the high word for internal purposes
6383              */
6384             wParam = winpos->flags & 0xffff;
6385             /* We are not interested in the flags that don't match under XP and Win9x */
6386             wParam &= ~(SWP_NOZORDER);
6387             break;
6388         }
6389     }
6390
6391     msg.message = message;
6392     msg.flags = sent|wparam|lparam;
6393     if (defwndproc_counter) msg.flags |= defwinproc;
6394     msg.wParam = wParam;
6395     msg.lParam = lParam;
6396     add_message(&msg);
6397
6398     defwndproc_counter++;
6399     ret = DefDlgProcA(hwnd, message, wParam, lParam);
6400     defwndproc_counter--;
6401
6402     return ret;
6403 }
6404
6405 static void dump_winpos_flags(UINT flags)
6406 {
6407     if (!winetest_debug) return;
6408
6409     if (flags & SWP_SHOWWINDOW) printf("|SWP_SHOWWINDOW");
6410     if (flags & SWP_HIDEWINDOW) printf("|SWP_HIDEWINDOW");
6411     if (flags & SWP_NOACTIVATE) printf("|SWP_NOACTIVATE");
6412     if (flags & SWP_FRAMECHANGED) printf("|SWP_FRAMECHANGED");
6413     if (flags & SWP_NOCOPYBITS) printf("|SWP_NOCOPYBITS");
6414     if (flags & SWP_NOOWNERZORDER) printf("|SWP_NOOWNERZORDER");
6415     if (flags & SWP_NOSENDCHANGING) printf("|SWP_NOSENDCHANGING");
6416     if (flags & SWP_DEFERERASE) printf("|SWP_DEFERERASE");
6417     if (flags & SWP_ASYNCWINDOWPOS) printf("|SWP_ASYNCWINDOWPOS");
6418     if (flags & SWP_NOZORDER) printf("|SWP_NOZORDER");
6419     if (flags & SWP_NOREDRAW) printf("|SWP_NOREDRAW");
6420     if (flags & SWP_NOSIZE) printf("|SWP_NOSIZE");
6421     if (flags & SWP_NOMOVE) printf("|SWP_NOMOVE");
6422     if (flags & SWP_NOCLIENTSIZE) printf("|SWP_NOCLIENTSIZE");
6423     if (flags & SWP_NOCLIENTMOVE) printf("|SWP_NOCLIENTMOVE");
6424
6425 #define DUMPED_FLAGS \
6426     (SWP_NOSIZE | \
6427     SWP_NOMOVE | \
6428     SWP_NOZORDER | \
6429     SWP_NOREDRAW | \
6430     SWP_NOACTIVATE | \
6431     SWP_FRAMECHANGED | \
6432     SWP_SHOWWINDOW | \
6433     SWP_HIDEWINDOW | \
6434     SWP_NOCOPYBITS | \
6435     SWP_NOOWNERZORDER | \
6436     SWP_NOSENDCHANGING | \
6437     SWP_DEFERERASE | \
6438     SWP_ASYNCWINDOWPOS | \
6439     SWP_NOCLIENTSIZE | \
6440     SWP_NOCLIENTMOVE)
6441
6442     if(flags & ~DUMPED_FLAGS) printf("|0x%04x", flags & ~DUMPED_FLAGS);
6443     printf("\n");
6444 #undef DUMPED_FLAGS
6445 }
6446
6447 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6448 {
6449     static long defwndproc_counter = 0;
6450     LRESULT ret;
6451     struct message msg;
6452
6453     /* log only specific messages we are interested in */
6454     switch (message)
6455     {
6456 #if 0 /* probably log these as well */
6457     case WM_ACTIVATE:
6458     case WM_SETFOCUS:
6459     case WM_KILLFOCUS:
6460 #endif
6461     case WM_SHOWWINDOW:
6462         trace("WM_SHOWWINDOW %ld\n", wParam);
6463         break;
6464     case WM_SIZE:
6465         trace("WM_SIZE %ld\n", wParam);
6466         break;
6467     case WM_MOVE:
6468         trace("WM_MOVE\n");
6469         break;
6470     case WM_GETMINMAXINFO:
6471         trace("WM_GETMINMAXINFO\n");
6472         break;
6473
6474     case WM_WINDOWPOSCHANGING:
6475     case WM_WINDOWPOSCHANGED:
6476     {
6477         WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6478
6479         trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6480         trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6481               winpos->hwnd, winpos->hwndInsertAfter,
6482               winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6483         trace("flags: ");
6484         dump_winpos_flags(winpos->flags);
6485
6486         /* Log only documented flags, win2k uses 0x1000 and 0x2000
6487          * in the high word for internal purposes
6488          */
6489         wParam = winpos->flags & 0xffff;
6490         /* We are not interested in the flags that don't match under XP and Win9x */
6491         wParam &= ~(SWP_NOZORDER);
6492         break;
6493     }
6494
6495     default: /* ignore */
6496         /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
6497         return DefWindowProcA(hwnd, message, wParam, lParam);
6498     }
6499
6500     msg.message = message;
6501     msg.flags = sent|wparam|lparam;
6502     if (defwndproc_counter) msg.flags |= defwinproc;
6503     msg.wParam = wParam;
6504     msg.lParam = lParam;
6505     add_message(&msg);
6506
6507     defwndproc_counter++;
6508     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6509     defwndproc_counter--;
6510
6511     return ret;
6512 }
6513
6514 static BOOL RegisterWindowClasses(void)
6515 {
6516     WNDCLASSA cls;
6517     WNDCLASSW clsW;
6518
6519     cls.style = 0;
6520     cls.lpfnWndProc = MsgCheckProcA;
6521     cls.cbClsExtra = 0;
6522     cls.cbWndExtra = 0;
6523     cls.hInstance = GetModuleHandleA(0);
6524     cls.hIcon = 0;
6525     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
6526     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6527     cls.lpszMenuName = NULL;
6528     cls.lpszClassName = "TestWindowClass";
6529     if(!RegisterClassA(&cls)) return FALSE;
6530
6531     cls.lpfnWndProc = ShowWindowProcA;
6532     cls.lpszClassName = "ShowWindowClass";
6533     if(!RegisterClassA(&cls)) return FALSE;
6534
6535     cls.lpfnWndProc = PopupMsgCheckProcA;
6536     cls.lpszClassName = "TestPopupClass";
6537     if(!RegisterClassA(&cls)) return FALSE;
6538
6539     cls.lpfnWndProc = ParentMsgCheckProcA;
6540     cls.lpszClassName = "TestParentClass";
6541     if(!RegisterClassA(&cls)) return FALSE;
6542
6543     cls.lpfnWndProc = DefWindowProcA;
6544     cls.lpszClassName = "SimpleWindowClass";
6545     if(!RegisterClassA(&cls)) return FALSE;
6546
6547     cls.style = CS_NOCLOSE;
6548     cls.lpszClassName = "NoCloseWindowClass";
6549     if(!RegisterClassA(&cls)) return FALSE;
6550
6551     ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
6552     cls.style = 0;
6553     cls.hInstance = GetModuleHandleA(0);
6554     cls.hbrBackground = 0;
6555     cls.lpfnWndProc = TestDlgProcA;
6556     cls.lpszClassName = "TestDialogClass";
6557     if(!RegisterClassA(&cls)) return FALSE;
6558
6559     clsW.style = 0;
6560     clsW.lpfnWndProc = MsgCheckProcW;
6561     clsW.cbClsExtra = 0;
6562     clsW.cbWndExtra = 0;
6563     clsW.hInstance = GetModuleHandleW(0);
6564     clsW.hIcon = 0;
6565     clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
6566     clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
6567     clsW.lpszMenuName = NULL;
6568     clsW.lpszClassName = testWindowClassW;
6569     RegisterClassW(&clsW);  /* ignore error, this fails on Win9x */
6570
6571     return TRUE;
6572 }
6573
6574 static HHOOK hCBT_hook;
6575 static DWORD cbt_hook_thread_id;
6576
6577 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
6578
6579     static const char * const CBT_code_name[10] = {
6580         "HCBT_MOVESIZE",
6581         "HCBT_MINMAX",
6582         "HCBT_QS",
6583         "HCBT_CREATEWND",
6584         "HCBT_DESTROYWND",
6585         "HCBT_ACTIVATE",
6586         "HCBT_CLICKSKIPPED",
6587         "HCBT_KEYSKIPPED",
6588         "HCBT_SYSCOMMAND",
6589         "HCBT_SETFOCUS" };
6590     const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
6591     HWND hwnd;
6592     char buf[256];
6593
6594     trace("CBT: %d (%s), %08lx, %08lx\n", nCode, code_name, wParam, lParam);
6595
6596     ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
6597
6598     if (nCode == HCBT_CLICKSKIPPED)
6599     {
6600         /* ignore this event, XP sends it a lot when switching focus between windows */
6601         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
6602     }
6603
6604     if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
6605     {
6606         struct message msg;
6607
6608         msg.message = nCode;
6609         msg.flags = hook|wparam|lparam;
6610         msg.wParam = wParam;
6611         msg.lParam = lParam;
6612         add_message(&msg);
6613
6614         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
6615     }
6616
6617     if (nCode == HCBT_DESTROYWND)
6618     {
6619         if (test_DestroyWindow_flag)
6620         {
6621             DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
6622             if (style & WS_CHILD)
6623                 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
6624             else if (style & WS_POPUP)
6625                 lParam = WND_POPUP_ID;
6626             else
6627                 lParam = WND_PARENT_ID;
6628         }
6629     }
6630
6631     /* Log also SetFocus(0) calls */
6632     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
6633
6634     if (GetClassNameA(hwnd, buf, sizeof(buf)))
6635     {
6636         if (!lstrcmpiA(buf, "TestWindowClass") ||
6637             !lstrcmpiA(buf, "ShowWindowClass") ||
6638             !lstrcmpiA(buf, "TestParentClass") ||
6639             !lstrcmpiA(buf, "TestPopupClass") ||
6640             !lstrcmpiA(buf, "SimpleWindowClass") ||
6641             !lstrcmpiA(buf, "TestDialogClass") ||
6642             !lstrcmpiA(buf, "MDI_frame_class") ||
6643             !lstrcmpiA(buf, "MDI_client_class") ||
6644             !lstrcmpiA(buf, "MDI_child_class") ||
6645             !lstrcmpiA(buf, "my_button_class") ||
6646             !lstrcmpiA(buf, "my_edit_class") ||
6647             !lstrcmpiA(buf, "static") ||
6648             !lstrcmpiA(buf, "ListBox") ||
6649             !lstrcmpiA(buf, "MyDialogClass") ||
6650             !lstrcmpiA(buf, "#32770"))
6651         {
6652             struct message msg;
6653
6654             msg.message = nCode;
6655             msg.flags = hook|wparam|lparam;
6656             msg.wParam = wParam;
6657             msg.lParam = lParam;
6658             add_message(&msg);
6659         }
6660     }
6661     return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
6662 }
6663
6664 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
6665                                     DWORD event,
6666                                     HWND hwnd,
6667                                     LONG object_id,
6668                                     LONG child_id,
6669                                     DWORD thread_id,
6670                                     DWORD event_time)
6671 {
6672     char buf[256];
6673
6674     trace("WEH:%p,event %08x,hwnd %p,obj %08x,id %08x,thread %08x,time %08x\n",
6675            hevent, event, hwnd, object_id, child_id, thread_id, event_time);
6676
6677     ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
6678
6679     /* ignore mouse cursor events */
6680     if (object_id == OBJID_CURSOR) return;
6681
6682     if (!hwnd || GetClassNameA(hwnd, buf, sizeof(buf)))
6683     {
6684         if (!hwnd ||
6685             !lstrcmpiA(buf, "TestWindowClass") ||
6686             !lstrcmpiA(buf, "TestParentClass") ||
6687             !lstrcmpiA(buf, "TestPopupClass") ||
6688             !lstrcmpiA(buf, "SimpleWindowClass") ||
6689             !lstrcmpiA(buf, "TestDialogClass") ||
6690             !lstrcmpiA(buf, "MDI_frame_class") ||
6691             !lstrcmpiA(buf, "MDI_client_class") ||
6692             !lstrcmpiA(buf, "MDI_child_class") ||
6693             !lstrcmpiA(buf, "my_button_class") ||
6694             !lstrcmpiA(buf, "my_edit_class") ||
6695             !lstrcmpiA(buf, "static") ||
6696             !lstrcmpiA(buf, "ListBox") ||
6697             !lstrcmpiA(buf, "MyDialogClass") ||
6698             !lstrcmpiA(buf, "#32770"))
6699         {
6700             struct message msg;
6701
6702             msg.message = event;
6703             msg.flags = winevent_hook|wparam|lparam;
6704             msg.wParam = object_id;
6705             msg.lParam = child_id;
6706             add_message(&msg);
6707         }
6708     }
6709 }
6710
6711 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
6712 static const WCHAR wszAnsi[] = {'U',0};
6713
6714 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6715 {
6716     switch (uMsg)
6717     {
6718     case CB_FINDSTRINGEXACT:
6719         trace("String: %p\n", (LPCWSTR)lParam);
6720         if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
6721             return 1;
6722         if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
6723             return 0;
6724         return -1;
6725     }
6726     return DefWindowProcW(hwnd, uMsg, wParam, lParam);
6727 }
6728
6729 static const struct message WmGetTextLengthAfromW[] = {
6730     { WM_GETTEXTLENGTH, sent },
6731     { WM_GETTEXT, sent },
6732     { 0 }
6733 };
6734
6735 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
6736
6737 /* dummy window proc for WM_GETTEXTLENGTH test */
6738 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
6739 {
6740     switch(msg)
6741     {
6742     case WM_GETTEXTLENGTH:
6743         return lstrlenW(dummy_window_text) + 37;  /* some random length */
6744     case WM_GETTEXT:
6745         lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
6746         return lstrlenW( (LPWSTR)lp );
6747     default:
6748         return DefWindowProcW( hwnd, msg, wp, lp );
6749     }
6750 }
6751
6752 static void test_message_conversion(void)
6753 {
6754     static const WCHAR wszMsgConversionClass[] =
6755         {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
6756     WNDCLASSW cls;
6757     LRESULT lRes;
6758     HWND hwnd;
6759     WNDPROC wndproc, newproc;
6760     BOOL ret;
6761
6762     cls.style = 0;
6763     cls.lpfnWndProc = MsgConversionProcW;
6764     cls.cbClsExtra = 0;
6765     cls.cbWndExtra = 0;
6766     cls.hInstance = GetModuleHandleW(NULL);
6767     cls.hIcon = NULL;
6768     cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
6769     cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
6770     cls.lpszMenuName = NULL;
6771     cls.lpszClassName = wszMsgConversionClass;
6772     /* this call will fail on Win9x, but that doesn't matter as this test is
6773      * meaningless on those platforms */
6774     if(!RegisterClassW(&cls)) return;
6775
6776     hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
6777                            100, 100, 200, 200, 0, 0, 0, NULL);
6778     ok(hwnd != NULL, "Window creation failed\n");
6779
6780     /* {W, A} -> A */
6781
6782     wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
6783     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6784     ok(lRes == 0, "String should have been converted\n");
6785     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6786     ok(lRes == 1, "String shouldn't have been converted\n");
6787
6788     /* {W, A} -> W */
6789
6790     wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
6791     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6792     ok(lRes == 1, "String shouldn't have been converted\n");
6793     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6794     ok(lRes == 1, "String shouldn't have been converted\n");
6795
6796     /* Synchronous messages */
6797
6798     lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6799     ok(lRes == 0, "String should have been converted\n");
6800     lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6801     ok(lRes == 1, "String shouldn't have been converted\n");
6802
6803     /* Asynchronous messages */
6804
6805     SetLastError(0);
6806     lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6807     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6808         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6809     SetLastError(0);
6810     lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6811     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6812         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6813     SetLastError(0);
6814     lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6815     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6816         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6817     SetLastError(0);
6818     lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6819     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6820         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6821     SetLastError(0);
6822     lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6823     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6824         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6825     SetLastError(0);
6826     lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6827     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6828         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6829     SetLastError(0);
6830     lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
6831     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6832         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6833     SetLastError(0);
6834     lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
6835     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6836         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6837
6838     /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
6839
6840     hwnd = CreateWindowW (testWindowClassW, wszUnicode,
6841                           WS_OVERLAPPEDWINDOW,
6842                           100, 100, 200, 200, 0, 0, 0, NULL);
6843     assert(hwnd);
6844     flush_sequence();
6845     lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
6846     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
6847     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
6848         "got bad length %ld\n", lRes );
6849
6850     flush_sequence();
6851     lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
6852                             hwnd, WM_GETTEXTLENGTH, 0, 0);
6853     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
6854     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
6855         "got bad length %ld\n", lRes );
6856
6857     wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
6858     newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
6859     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
6860     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
6861                                      NULL, 0, NULL, NULL ),
6862         "got bad length %ld\n", lRes );
6863
6864     SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc );  /* restore old wnd proc */
6865     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
6866     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
6867                                      NULL, 0, NULL, NULL ),
6868         "got bad length %ld\n", lRes );
6869
6870     ret = DestroyWindow(hwnd);
6871     ok( ret, "DestroyWindow() error %d\n", GetLastError());
6872 }
6873
6874 struct timer_info
6875 {
6876     HWND hWnd;
6877     HANDLE handles[2];
6878     DWORD id;
6879 };
6880
6881 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
6882 {
6883 }
6884
6885 #define TIMER_ID  0x19
6886
6887 static DWORD WINAPI timer_thread_proc(LPVOID x)
6888 {
6889     struct timer_info *info = x;
6890     DWORD r;
6891
6892     r = KillTimer(info->hWnd, 0x19);
6893     ok(r,"KillTimer failed in thread\n");
6894     r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
6895     ok(r,"SetTimer failed in thread\n");
6896     ok(r==TIMER_ID,"SetTimer id different\n");
6897     r = SetEvent(info->handles[0]);
6898     ok(r,"SetEvent failed in thread\n");
6899     return 0;
6900 }
6901
6902 static void test_timers(void)
6903 {
6904     struct timer_info info;
6905     DWORD id;
6906
6907     info.hWnd = CreateWindow ("TestWindowClass", NULL,
6908        WS_OVERLAPPEDWINDOW ,
6909        CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
6910        NULL, NULL, 0);
6911
6912     info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
6913     ok(info.id, "SetTimer failed\n");
6914     ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
6915     info.handles[0] = CreateEvent(NULL,0,0,NULL);
6916     info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
6917
6918     WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
6919
6920     WaitForSingleObject(info.handles[1], INFINITE);
6921
6922     CloseHandle(info.handles[0]);
6923     CloseHandle(info.handles[1]);
6924
6925     ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
6926
6927     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
6928 }
6929
6930 static int count = 0;
6931 static VOID CALLBACK callback_count(
6932     HWND hwnd,
6933     UINT uMsg,
6934     UINT_PTR idEvent,
6935     DWORD dwTime
6936 )
6937 {
6938     count++;
6939 }
6940
6941 static void test_timers_no_wnd(void)
6942 {
6943     UINT_PTR id, id2;
6944     MSG msg;
6945
6946     count = 0;
6947     id = SetTimer(NULL, 0, 100, callback_count);
6948     ok(id != 0, "did not get id from SetTimer.\n");
6949     id2 = SetTimer(NULL, id, 200, callback_count);
6950     ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
6951     Sleep(150);
6952     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6953     ok(count == 0, "did not get zero count as expected (%i).\n", count);
6954     Sleep(150);
6955     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6956     ok(count == 1, "did not get one count as expected (%i).\n", count);
6957     KillTimer(NULL, id);
6958     Sleep(250);
6959     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6960     ok(count == 1, "killing replaced timer did not work (%i).\n", count);
6961 }
6962
6963 /* Various win events with arbitrary parameters */
6964 static const struct message WmWinEventsSeq[] = {
6965     { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
6966     { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6967     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
6968     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
6969     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
6970     { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
6971     { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
6972     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
6973     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
6974     /* our win event hook ignores OBJID_CURSOR events */
6975     /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
6976     { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
6977     { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
6978     { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
6979     { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
6980     { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
6981     { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6982     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
6983     { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
6984     { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
6985     { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
6986     { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
6987     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
6988     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
6989     { 0 }
6990 };
6991 static const struct message WmWinEventCaretSeq[] = {
6992     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
6993     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
6994     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
6995     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
6996     { 0 }
6997 };
6998 static const struct message WmWinEventCaretSeq_2[] = {
6999     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7000     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7001     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7002     { 0 }
7003 };
7004 static const struct message WmWinEventAlertSeq[] = {
7005     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
7006     { 0 }
7007 };
7008 static const struct message WmWinEventAlertSeq_2[] = {
7009     /* create window in the thread proc */
7010     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
7011     /* our test event */
7012     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
7013     { 0 }
7014 };
7015 static const struct message WmGlobalHookSeq_1[] = {
7016     /* create window in the thread proc */
7017     { HCBT_CREATEWND, hook|lparam, 0, 2 },
7018     /* our test events */
7019     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
7020     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
7021     { 0 }
7022 };
7023 static const struct message WmGlobalHookSeq_2[] = {
7024     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
7025     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
7026     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
7027     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
7028     { 0 }
7029 };
7030
7031 static const struct message WmMouseLLHookSeq[] = {
7032     { WM_MOUSEMOVE, hook },
7033     { WM_LBUTTONUP, hook },
7034     { WM_MOUSEMOVE, hook },
7035     { 0 }
7036 };
7037
7038 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
7039                                          DWORD event,
7040                                          HWND hwnd,
7041                                          LONG object_id,
7042                                          LONG child_id,
7043                                          DWORD thread_id,
7044                                          DWORD event_time)
7045 {
7046     char buf[256];
7047
7048     trace("WEH_2:%p,event %08x,hwnd %p,obj %08x,id %08x,thread %08x,time %08x\n",
7049            hevent, event, hwnd, object_id, child_id, thread_id, event_time);
7050
7051     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7052     {
7053         if (!lstrcmpiA(buf, "TestWindowClass") ||
7054             !lstrcmpiA(buf, "static"))
7055         {
7056             struct message msg;
7057
7058             msg.message = event;
7059             msg.flags = winevent_hook|wparam|lparam;
7060             msg.wParam = object_id;
7061             msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
7062             add_message(&msg);
7063         }
7064     }
7065 }
7066
7067 static HHOOK hCBT_global_hook;
7068 static DWORD cbt_global_hook_thread_id;
7069
7070 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7071
7072     HWND hwnd;
7073     char buf[256];
7074
7075     trace("CBT_2: %d, %08lx, %08lx\n", nCode, wParam, lParam);
7076
7077     if (nCode == HCBT_SYSCOMMAND)
7078     {
7079         struct message msg;
7080
7081         msg.message = nCode;
7082         msg.flags = hook|wparam|lparam;
7083         msg.wParam = wParam;
7084         msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7085         add_message(&msg);
7086
7087         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7088     }
7089     /* WH_MOUSE_LL hook */
7090     if (nCode == HC_ACTION)
7091     {
7092         struct message msg;
7093         MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
7094
7095         /* we can't test for real mouse events */
7096         if (mhll->flags & LLMHF_INJECTED)
7097         {
7098             msg.message = wParam;
7099             msg.flags = hook;
7100             add_message(&msg);
7101         }
7102         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7103     }
7104
7105     /* Log also SetFocus(0) calls */
7106     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7107
7108     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7109     {
7110         if (!lstrcmpiA(buf, "TestWindowClass") ||
7111             !lstrcmpiA(buf, "static"))
7112         {
7113             struct message msg;
7114
7115             msg.message = nCode;
7116             msg.flags = hook|wparam|lparam;
7117             msg.wParam = wParam;
7118             msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7119             add_message(&msg);
7120         }
7121     }
7122     return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7123 }
7124
7125 static DWORD WINAPI win_event_global_thread_proc(void *param)
7126 {
7127     HWND hwnd;
7128     MSG msg;
7129     HANDLE hevent = *(HANDLE *)param;
7130
7131     assert(pNotifyWinEvent);
7132
7133     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7134     assert(hwnd);
7135     trace("created thread window %p\n", hwnd);
7136
7137     *(HWND *)param = hwnd;
7138
7139     flush_sequence();
7140     /* this event should be received only by our new hook proc,
7141      * an old one does not expect an event from another thread.
7142      */
7143     pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
7144     SetEvent(hevent);
7145
7146     while (GetMessage(&msg, 0, 0, 0))
7147     {
7148         TranslateMessage(&msg);
7149         DispatchMessage(&msg);
7150     }
7151     return 0;
7152 }
7153
7154 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
7155 {
7156     HWND hwnd;
7157     MSG msg;
7158     HANDLE hevent = *(HANDLE *)param;
7159
7160     flush_sequence();
7161     /* these events should be received only by our new hook proc,
7162      * an old one does not expect an event from another thread.
7163      */
7164
7165     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7166     assert(hwnd);
7167     trace("created thread window %p\n", hwnd);
7168
7169     *(HWND *)param = hwnd;
7170
7171     /* Windows doesn't like when a thread plays games with the focus,
7172        that leads to all kinds of misbehaviours and failures to activate
7173        a window. So, better keep next lines commented out.
7174     SetFocus(0);
7175     SetFocus(hwnd);*/
7176
7177     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7178     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7179
7180     SetEvent(hevent);
7181
7182     while (GetMessage(&msg, 0, 0, 0))
7183     {
7184         TranslateMessage(&msg);
7185         DispatchMessage(&msg);
7186     }
7187     return 0;
7188 }
7189
7190 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
7191 {
7192     HWND hwnd;
7193     MSG msg;
7194     HANDLE hevent = *(HANDLE *)param;
7195
7196     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7197     assert(hwnd);
7198     trace("created thread window %p\n", hwnd);
7199
7200     *(HWND *)param = hwnd;
7201
7202     flush_sequence();
7203
7204     /* Windows doesn't like when a thread plays games with the focus,
7205      * that leads to all kinds of misbehaviours and failures to activate
7206      * a window. So, better don't generate a mouse click message below.
7207      */
7208     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7209     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7210     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7211
7212     SetEvent(hevent);
7213     while (GetMessage(&msg, 0, 0, 0))
7214     {
7215         TranslateMessage(&msg);
7216         DispatchMessage(&msg);
7217     }
7218     return 0;
7219 }
7220
7221 static void test_winevents(void)
7222 {
7223     BOOL ret;
7224     MSG msg;
7225     HWND hwnd, hwnd2;
7226     UINT i;
7227     HANDLE hthread, hevent;
7228     DWORD tid;
7229     HWINEVENTHOOK hhook;
7230     const struct message *events = WmWinEventsSeq;
7231
7232     hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
7233                            WS_OVERLAPPEDWINDOW,
7234                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7235                            NULL, NULL, 0);
7236     assert(hwnd);
7237
7238     /****** start of global hook test *************/
7239     hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7240     assert(hCBT_global_hook);
7241
7242     hevent = CreateEventA(NULL, 0, 0, NULL);
7243     assert(hevent);
7244     hwnd2 = (HWND)hevent;
7245
7246     hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
7247     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7248
7249     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7250
7251     ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
7252
7253     flush_sequence();
7254     /* this one should be received only by old hook proc */
7255     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7256     /* this one should be received only by old hook proc */
7257     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7258
7259     ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
7260
7261     ret = UnhookWindowsHookEx(hCBT_global_hook);
7262     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7263
7264     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7265     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7266     CloseHandle(hthread);
7267     CloseHandle(hevent);
7268     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7269     /****** end of global hook test *************/
7270
7271     if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
7272     {
7273         ok(DestroyWindow(hwnd), "failed to destroy window\n");
7274         return;
7275     }
7276
7277     flush_sequence();
7278
7279     if (0)
7280     {
7281     /* this test doesn't pass under Win9x */
7282     /* win2k ignores events with hwnd == 0 */
7283     SetLastError(0xdeadbeef);
7284     pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
7285     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
7286        GetLastError() == 0xdeadbeef, /* Win9x */
7287        "unexpected error %d\n", GetLastError());
7288     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7289     }
7290
7291     for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
7292         pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
7293
7294     ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
7295
7296     /****** start of event filtering test *************/
7297     hhook = (HWINEVENTHOOK)pSetWinEventHook(
7298         EVENT_OBJECT_SHOW, /* 0x8002 */
7299         EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
7300         GetModuleHandleA(0), win_event_global_hook_proc,
7301         GetCurrentProcessId(), 0,
7302         WINEVENT_INCONTEXT);
7303     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7304
7305     hevent = CreateEventA(NULL, 0, 0, NULL);
7306     assert(hevent);
7307     hwnd2 = (HWND)hevent;
7308
7309     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7310     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7311
7312     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7313
7314     ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
7315
7316     flush_sequence();
7317     /* this one should be received only by old hook proc */
7318     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7319     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7320     /* this one should be received only by old hook proc */
7321     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7322
7323     ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
7324
7325     ret = pUnhookWinEvent(hhook);
7326     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7327
7328     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7329     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7330     CloseHandle(hthread);
7331     CloseHandle(hevent);
7332     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7333     /****** end of event filtering test *************/
7334
7335     /****** start of out of context event test *************/
7336     hhook = (HWINEVENTHOOK)pSetWinEventHook(
7337         EVENT_MIN, EVENT_MAX,
7338         0, win_event_global_hook_proc,
7339         GetCurrentProcessId(), 0,
7340         WINEVENT_OUTOFCONTEXT);
7341     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7342
7343     hevent = CreateEventA(NULL, 0, 0, NULL);
7344     assert(hevent);
7345     hwnd2 = (HWND)hevent;
7346
7347     flush_sequence();
7348
7349     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7350     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7351
7352     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7353
7354     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7355     /* process pending winevent messages */
7356     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7357     ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
7358
7359     flush_sequence();
7360     /* this one should be received only by old hook proc */
7361     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7362     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7363     /* this one should be received only by old hook proc */
7364     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7365
7366     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
7367     /* process pending winevent messages */
7368     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7369     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
7370
7371     ret = pUnhookWinEvent(hhook);
7372     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7373
7374     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7375     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7376     CloseHandle(hthread);
7377     CloseHandle(hevent);
7378     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7379     /****** end of out of context event test *************/
7380
7381     /****** start of MOUSE_LL hook test *************/
7382     hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7383     /* WH_MOUSE_LL is not supported on Win9x platforms */
7384     if (!hCBT_global_hook)
7385     {
7386         trace("Skipping WH_MOUSE_LL test on this platform\n");
7387         goto skip_mouse_ll_hook_test;
7388     }
7389
7390     hevent = CreateEventA(NULL, 0, 0, NULL);
7391     assert(hevent);
7392     hwnd2 = (HWND)hevent;
7393
7394     hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
7395     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7396
7397     while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
7398         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
7399
7400     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
7401     flush_sequence();
7402
7403     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7404     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7405     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7406
7407     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
7408
7409     ret = UnhookWindowsHookEx(hCBT_global_hook);
7410     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7411
7412     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7413     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7414     CloseHandle(hthread);
7415     CloseHandle(hevent);
7416     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7417     /****** end of MOUSE_LL hook test *************/
7418 skip_mouse_ll_hook_test:
7419
7420     ok(DestroyWindow(hwnd), "failed to destroy window\n");
7421 }
7422
7423 static void test_set_hook(void)
7424 {
7425     BOOL ret;
7426     HHOOK hhook;
7427     HWINEVENTHOOK hwinevent_hook;
7428
7429     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
7430     ok(hhook != 0, "local hook does not require hModule set to 0\n");
7431     UnhookWindowsHookEx(hhook);
7432
7433     if (0)
7434     {
7435     /* this test doesn't pass under Win9x: BUG! */
7436     SetLastError(0xdeadbeef);
7437     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
7438     ok(!hhook, "global hook requires hModule != 0\n");
7439     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
7440     }
7441
7442     SetLastError(0xdeadbeef);
7443     hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
7444     ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
7445     ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
7446        GetLastError() == 0xdeadbeef, /* Win9x */
7447        "unexpected error %d\n", GetLastError());
7448
7449     SetLastError(0xdeadbeef);
7450     ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
7451     ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
7452        GetLastError() == 0xdeadbeef, /* Win9x */
7453        "unexpected error %d\n", GetLastError());
7454
7455     if (!pSetWinEventHook || !pUnhookWinEvent) return;
7456
7457     /* even process local incontext hooks require hmodule */
7458     SetLastError(0xdeadbeef);
7459     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7460         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
7461     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
7462     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
7463        GetLastError() == 0xdeadbeef, /* Win9x */
7464        "unexpected error %d\n", GetLastError());
7465
7466     /* even thread local incontext hooks require hmodule */
7467     SetLastError(0xdeadbeef);
7468     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7469         0, win_event_proc, GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
7470     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
7471     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
7472        GetLastError() == 0xdeadbeef, /* Win9x */
7473        "unexpected error %d\n", GetLastError());
7474
7475     if (0)
7476     {
7477     /* these 3 tests don't pass under Win9x */
7478     SetLastError(0xdeadbeef);
7479     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(1, 0,
7480         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7481     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
7482     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
7483
7484     SetLastError(0xdeadbeef);
7485     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(-1, 1,
7486         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7487     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
7488     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
7489
7490     SetLastError(0xdeadbeef);
7491     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7492         0, win_event_proc, 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
7493     ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
7494     ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
7495     }
7496
7497     SetLastError(0xdeadbeef);
7498     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(0, 0,
7499         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7500     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
7501     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
7502     ret = pUnhookWinEvent(hwinevent_hook);
7503     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7504
7505 todo_wine {
7506     /* This call succeeds under win2k SP4, but fails under Wine.
7507        Does win2k test/use passed process id? */
7508     SetLastError(0xdeadbeef);
7509     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7510         0, win_event_proc, 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
7511     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
7512     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
7513     ret = pUnhookWinEvent(hwinevent_hook);
7514     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7515 }
7516
7517     SetLastError(0xdeadbeef);
7518     ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
7519     ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
7520         GetLastError() == 0xdeadbeef, /* Win9x */
7521         "unexpected error %d\n", GetLastError());
7522 }
7523
7524 static const struct message ScrollWindowPaint1[] = {
7525     { WM_PAINT, sent },
7526     { WM_ERASEBKGND, sent|beginpaint },
7527     { 0 }
7528 };
7529
7530 static const struct message ScrollWindowPaint2[] = {
7531     { WM_PAINT, sent },
7532     { 0 }
7533 };
7534
7535 static void test_scrollwindowex(void)
7536 {
7537     HWND hwnd, hchild;
7538     RECT rect={0,0,130,130};
7539
7540     hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
7541             WS_VISIBLE|WS_OVERLAPPEDWINDOW,
7542             100, 100, 200, 200, 0, 0, 0, NULL);
7543     ok (hwnd != 0, "Failed to create overlapped window\n");
7544     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", 
7545             WS_VISIBLE|WS_CAPTION|WS_CHILD,
7546             10, 10, 150, 150, hwnd, 0, 0, NULL);
7547     ok (hchild != 0, "Failed to create child\n");
7548     UpdateWindow(hwnd);
7549     flush_events();
7550     flush_sequence();
7551
7552     /* scroll without the child window */
7553     trace("start scroll\n");
7554     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
7555             SW_ERASE|SW_INVALIDATE);
7556     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7557     trace("end scroll\n");
7558     flush_sequence();
7559     flush_events();
7560     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
7561     flush_events();
7562     flush_sequence();
7563
7564     /* Now without the SW_ERASE flag */
7565     trace("start scroll\n");
7566     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
7567     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7568     trace("end scroll\n");
7569     flush_sequence();
7570     flush_events();
7571     ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
7572     flush_events();
7573     flush_sequence();
7574
7575     /* now scroll the child window as well */
7576     trace("start scroll\n");
7577     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
7578             SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
7579     todo_wine { /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
7580                 /* windows sometimes a WM_MOVE */
7581         ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7582     }
7583     trace("end scroll\n");
7584     flush_sequence();
7585     flush_events();
7586     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
7587     flush_events();
7588     flush_sequence();
7589
7590     /* now scroll with ScrollWindow() */
7591     trace("start scroll with ScrollWindow\n");
7592     ScrollWindow( hwnd, 5, 5, NULL, NULL);
7593     trace("end scroll\n");
7594     flush_sequence();
7595     flush_events();
7596     ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
7597
7598     ok(DestroyWindow(hchild), "failed to destroy window\n");
7599     ok(DestroyWindow(hwnd), "failed to destroy window\n");
7600     flush_sequence();
7601 }
7602
7603 static const struct message destroy_window_with_children[] = {
7604     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
7605     { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
7606     { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
7607     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
7608     { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7609     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7610     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7611     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
7612     { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
7613     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
7614     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
7615     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
7616     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
7617     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
7618     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
7619     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
7620     { 0 }
7621 };
7622
7623 static void test_DestroyWindow(void)
7624 {
7625     BOOL ret;
7626     HWND parent, child1, child2, child3, child4, test;
7627     UINT child_id = WND_CHILD_ID + 1;
7628
7629     parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
7630                              100, 100, 200, 200, 0, 0, 0, NULL);
7631     assert(parent != 0);
7632     child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7633                              0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
7634     assert(child1 != 0);
7635     child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7636                              0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
7637     assert(child2 != 0);
7638     child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7639                              0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
7640     assert(child3 != 0);
7641     child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
7642                              0, 0, 50, 50, parent, 0, 0, NULL);
7643     assert(child4 != 0);
7644
7645     /* test owner/parent of child2 */
7646     test = GetParent(child2);
7647     ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7648     ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
7649     if(pGetAncestor) {
7650         test = pGetAncestor(child2, GA_PARENT);
7651         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7652     }
7653     test = GetWindow(child2, GW_OWNER);
7654     ok(!test, "wrong owner %p\n", test);
7655
7656     test = SetParent(child2, parent);
7657     ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
7658
7659     /* test owner/parent of the parent */
7660     test = GetParent(parent);
7661     ok(!test, "wrong parent %p\n", test);
7662     ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
7663     if(pGetAncestor) {
7664         test = pGetAncestor(parent, GA_PARENT);
7665         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7666     }
7667     test = GetWindow(parent, GW_OWNER);
7668     ok(!test, "wrong owner %p\n", test);
7669
7670     /* test owner/parent of child1 */
7671     test = GetParent(child1);
7672     ok(test == parent, "wrong parent %p\n", test);
7673     ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
7674     if(pGetAncestor) {
7675         test = pGetAncestor(child1, GA_PARENT);
7676         ok(test == parent, "wrong parent %p\n", test);
7677     }
7678     test = GetWindow(child1, GW_OWNER);
7679     ok(!test, "wrong owner %p\n", test);
7680
7681     /* test owner/parent of child2 */
7682     test = GetParent(child2);
7683     ok(test == parent, "wrong parent %p\n", test);
7684     ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
7685     if(pGetAncestor) {
7686         test = pGetAncestor(child2, GA_PARENT);
7687         ok(test == parent, "wrong parent %p\n", test);
7688     }
7689     test = GetWindow(child2, GW_OWNER);
7690     ok(!test, "wrong owner %p\n", test);
7691
7692     /* test owner/parent of child3 */
7693     test = GetParent(child3);
7694     ok(test == child1, "wrong parent %p\n", test);
7695     ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
7696     if(pGetAncestor) {
7697         test = pGetAncestor(child3, GA_PARENT);
7698         ok(test == child1, "wrong parent %p\n", test);
7699     }
7700     test = GetWindow(child3, GW_OWNER);
7701     ok(!test, "wrong owner %p\n", test);
7702
7703     /* test owner/parent of child4 */
7704     test = GetParent(child4);
7705     ok(test == parent, "wrong parent %p\n", test);
7706     ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
7707     if(pGetAncestor) {
7708         test = pGetAncestor(child4, GA_PARENT);
7709         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7710     }
7711     test = GetWindow(child4, GW_OWNER);
7712     ok(test == parent, "wrong owner %p\n", test);
7713
7714     flush_sequence();
7715
7716     trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
7717            parent, child1, child2, child3, child4);
7718
7719     SetCapture(child4);
7720     test = GetCapture();
7721     ok(test == child4, "wrong capture window %p\n", test);
7722
7723     test_DestroyWindow_flag = TRUE;
7724     ret = DestroyWindow(parent);
7725     ok( ret, "DestroyWindow() error %d\n", GetLastError());
7726     test_DestroyWindow_flag = FALSE;
7727     ok_sequence(destroy_window_with_children, "destroy window with children", 0);
7728
7729     ok(!IsWindow(parent), "parent still exists\n");
7730     ok(!IsWindow(child1), "child1 still exists\n");
7731     ok(!IsWindow(child2), "child2 still exists\n");
7732     ok(!IsWindow(child3), "child3 still exists\n");
7733     ok(!IsWindow(child4), "child4 still exists\n");
7734
7735     test = GetCapture();
7736     ok(!test, "wrong capture window %p\n", test);
7737 }
7738
7739
7740 static const struct message WmDispatchPaint[] = {
7741     { WM_NCPAINT, sent },
7742     { WM_GETTEXT, sent|defwinproc|optional },
7743     { WM_GETTEXT, sent|defwinproc|optional },
7744     { WM_ERASEBKGND, sent },
7745     { 0 }
7746 };
7747
7748 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7749 {
7750     if (message == WM_PAINT) return 0;
7751     return MsgCheckProcA( hwnd, message, wParam, lParam );
7752 }
7753
7754 static void test_DispatchMessage(void)
7755 {
7756     RECT rect;
7757     MSG msg;
7758     int count;
7759     HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
7760                                100, 100, 200, 200, 0, 0, 0, NULL);
7761     ShowWindow( hwnd, SW_SHOW );
7762     UpdateWindow( hwnd );
7763     flush_events();
7764     flush_sequence();
7765     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
7766
7767     SetRect( &rect, -5, -5, 5, 5 );
7768     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
7769     count = 0;
7770     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
7771     {
7772         if (msg.message != WM_PAINT) DispatchMessage( &msg );
7773         else
7774         {
7775             flush_sequence();
7776             DispatchMessage( &msg );
7777             /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
7778             if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
7779             else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
7780             if (++count > 10) break;
7781         }
7782     }
7783     ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
7784
7785     trace("now without DispatchMessage\n");
7786     flush_sequence();
7787     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
7788     count = 0;
7789     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
7790     {
7791         if (msg.message != WM_PAINT) DispatchMessage( &msg );
7792         else
7793         {
7794             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
7795             flush_sequence();
7796             /* this will send WM_NCCPAINT just like DispatchMessage does */
7797             GetUpdateRgn( hwnd, hrgn, TRUE );
7798             ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
7799             DeleteObject( hrgn );
7800             GetClientRect( hwnd, &rect );
7801             ValidateRect( hwnd, &rect );  /* this will stop WM_PAINTs */
7802             ok( !count, "Got multiple WM_PAINTs\n" );
7803             if (++count > 10) break;
7804         }
7805     }
7806     DestroyWindow(hwnd);
7807 }
7808
7809
7810 static const struct message WmUser[] = {
7811     { WM_USER, sent },
7812     { 0 }
7813 };
7814
7815 struct sendmsg_info
7816 {
7817     HWND  hwnd;
7818     DWORD timeout;
7819     DWORD ret;
7820 };
7821
7822 static DWORD CALLBACK send_msg_thread( LPVOID arg )
7823 {
7824     struct sendmsg_info *info = arg;
7825     info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
7826     if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT, "unexpected error %d\n", GetLastError());
7827     return 0;
7828 }
7829
7830 static void wait_for_thread( HANDLE thread )
7831 {
7832     while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
7833     {
7834         MSG msg;
7835         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
7836     }
7837 }
7838
7839 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7840 {
7841     if (message == WM_USER) Sleep(200);
7842     return MsgCheckProcA( hwnd, message, wParam, lParam );
7843 }
7844
7845 static void test_SendMessageTimeout(void)
7846 {
7847     HANDLE thread;
7848     struct sendmsg_info info;
7849     DWORD tid;
7850
7851     info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
7852                                100, 100, 200, 200, 0, 0, 0, NULL);
7853     flush_events();
7854     flush_sequence();
7855
7856     info.timeout = 1000;
7857     info.ret = 0xdeadbeef;
7858     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7859     wait_for_thread( thread );
7860     CloseHandle( thread );
7861     ok( info.ret == 1, "SendMessageTimeout failed\n" );
7862     ok_sequence( WmUser, "WmUser", FALSE );
7863
7864     info.timeout = 1;
7865     info.ret = 0xdeadbeef;
7866     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7867     Sleep(100);  /* SendMessageTimeout should timeout here */
7868     wait_for_thread( thread );
7869     CloseHandle( thread );
7870     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
7871     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
7872
7873     /* 0 means infinite timeout */
7874     info.timeout = 0;
7875     info.ret = 0xdeadbeef;
7876     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7877     Sleep(100);
7878     wait_for_thread( thread );
7879     CloseHandle( thread );
7880     ok( info.ret == 1, "SendMessageTimeout failed\n" );
7881     ok_sequence( WmUser, "WmUser", FALSE );
7882
7883     /* timeout is treated as signed despite the prototype */
7884     info.timeout = 0x7fffffff;
7885     info.ret = 0xdeadbeef;
7886     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7887     Sleep(100);
7888     wait_for_thread( thread );
7889     CloseHandle( thread );
7890     ok( info.ret == 1, "SendMessageTimeout failed\n" );
7891     ok_sequence( WmUser, "WmUser", FALSE );
7892
7893     info.timeout = 0x80000000;
7894     info.ret = 0xdeadbeef;
7895     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7896     Sleep(100);
7897     wait_for_thread( thread );
7898     CloseHandle( thread );
7899     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
7900     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
7901
7902     /* now check for timeout during message processing */
7903     SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
7904     info.timeout = 100;
7905     info.ret = 0xdeadbeef;
7906     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7907     wait_for_thread( thread );
7908     CloseHandle( thread );
7909     /* we should timeout but still get the message */
7910     ok( info.ret == 0, "SendMessageTimeout failed\n" );
7911     ok_sequence( WmUser, "WmUser", FALSE );
7912
7913     DestroyWindow( info.hwnd );
7914 }
7915
7916
7917 /****************** edit message test *************************/
7918 #define ID_EDIT 0x1234
7919 static const struct message sl_edit_setfocus[] =
7920 {
7921     { HCBT_SETFOCUS, hook },
7922     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
7923     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
7924     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7925     { WM_SETFOCUS, sent|wparam, 0 },
7926     { WM_CTLCOLOREDIT, sent|parent },
7927     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7928     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7929     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
7930     { 0 }
7931 };
7932 static const struct message ml_edit_setfocus[] =
7933 {
7934     { HCBT_SETFOCUS, hook },
7935     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
7936     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
7937     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7938     { WM_SETFOCUS, sent|wparam, 0 },
7939     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7940     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7941     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
7942     { 0 }
7943 };
7944 static const struct message sl_edit_killfocus[] =
7945 {
7946     { HCBT_SETFOCUS, hook },
7947     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7948     { WM_KILLFOCUS, sent|wparam, 0 },
7949     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7950     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7951     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
7952     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
7953     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
7954     { 0 }
7955 };
7956 static const struct message sl_edit_lbutton_dblclk[] =
7957 {
7958     { WM_LBUTTONDBLCLK, sent },
7959     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7960     { 0 }
7961 };
7962 static const struct message sl_edit_lbutton_down[] =
7963 {
7964     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
7965     { HCBT_SETFOCUS, hook },
7966     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
7967     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
7968     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7969     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
7970     { WM_CTLCOLOREDIT, sent|parent },
7971     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7972     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7973     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7974     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
7975     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7976     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7977     { WM_CTLCOLOREDIT, sent|parent|optional },
7978     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7979     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7980     { 0 }
7981 };
7982 static const struct message ml_edit_lbutton_down[] =
7983 {
7984     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
7985     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7986     { HCBT_SETFOCUS, hook },
7987     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
7988     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
7989     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7990     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
7991     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7992     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7993     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
7994     { 0 }
7995 };
7996 static const struct message sl_edit_lbutton_up[] =
7997 {
7998     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
7999     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8000     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8001     { WM_CAPTURECHANGED, sent|defwinproc },
8002     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8003     { 0 }
8004 };
8005 static const struct message ml_edit_lbutton_up[] =
8006 {
8007     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8008     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8009     { WM_CAPTURECHANGED, sent|defwinproc },
8010     { 0 }
8011 };
8012
8013 static WNDPROC old_edit_proc;
8014
8015 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8016 {
8017     static long defwndproc_counter = 0;
8018     LRESULT ret;
8019     struct message msg;
8020
8021     trace("edit: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
8022
8023     /* explicitly ignore WM_GETICON message */
8024     if (message == WM_GETICON) return 0;
8025
8026     msg.message = message;
8027     msg.flags = sent|wparam|lparam;
8028     if (defwndproc_counter) msg.flags |= defwinproc;
8029     msg.wParam = wParam;
8030     msg.lParam = lParam;
8031     add_message(&msg);
8032
8033     defwndproc_counter++;
8034     ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
8035     defwndproc_counter--;
8036
8037     return ret;
8038 }
8039
8040 static void subclass_edit(void)
8041 {
8042     WNDCLASSA cls;
8043
8044     if (!GetClassInfoA(0, "edit", &cls)) assert(0);
8045
8046     old_edit_proc = cls.lpfnWndProc;
8047
8048     cls.hInstance = GetModuleHandle(0);
8049     cls.lpfnWndProc = edit_hook_proc;
8050     cls.lpszClassName = "my_edit_class";
8051     UnregisterClass(cls.lpszClassName, cls.hInstance);
8052     if (!RegisterClassA(&cls)) assert(0);
8053 }
8054
8055 static void test_edit_messages(void)
8056 {
8057     HWND hwnd, parent;
8058     DWORD dlg_code;
8059
8060     subclass_edit();
8061     log_all_parent_messages++;
8062
8063     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8064                              100, 100, 200, 200, 0, 0, 0, NULL);
8065     ok (parent != 0, "Failed to create parent window\n");
8066
8067     /* test single line edit */
8068     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
8069                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8070     ok(hwnd != 0, "Failed to create edit window\n");
8071
8072     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8073     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
8074
8075     ShowWindow(hwnd, SW_SHOW);
8076     UpdateWindow(hwnd);
8077     SetFocus(0);
8078     flush_sequence();
8079
8080     SetFocus(hwnd);
8081     ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
8082
8083     SetFocus(0);
8084     ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
8085
8086     SetFocus(0);
8087     ReleaseCapture();
8088     flush_sequence();
8089
8090     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8091     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
8092
8093     SetFocus(0);
8094     ReleaseCapture();
8095     flush_sequence();
8096
8097     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8098     ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
8099
8100     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8101     ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
8102
8103     DestroyWindow(hwnd);
8104
8105     /* test multiline edit */
8106     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
8107                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8108     ok(hwnd != 0, "Failed to create edit window\n");
8109
8110     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8111     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
8112        "wrong dlg_code %08x\n", dlg_code);
8113
8114     ShowWindow(hwnd, SW_SHOW);
8115     UpdateWindow(hwnd);
8116     SetFocus(0);
8117     flush_sequence();
8118
8119     SetFocus(hwnd);
8120     ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
8121
8122     SetFocus(0);
8123     ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
8124
8125     SetFocus(0);
8126     ReleaseCapture();
8127     flush_sequence();
8128
8129     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8130     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
8131
8132     SetFocus(0);
8133     ReleaseCapture();
8134     flush_sequence();
8135
8136     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8137     ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
8138
8139     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8140     ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
8141
8142     DestroyWindow(hwnd);
8143     DestroyWindow(parent);
8144
8145     log_all_parent_messages--;
8146 }
8147
8148 /**************************** End of Edit test ******************************/
8149
8150 static const struct message WmKeyDownSkippedSeq[] =
8151 {
8152     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
8153     { 0 }
8154 };
8155 static const struct message WmKeyUpSkippedSeq[] =
8156 {
8157     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8158     { 0 }
8159 };
8160
8161 #define EV_START_STOP 0
8162 #define EV_SENDMSG 1
8163 #define EV_ACK 2
8164
8165 struct peekmsg_info
8166 {
8167     HWND  hwnd;
8168     HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
8169 };
8170
8171 static DWORD CALLBACK send_msg_thread_2(void *param)
8172 {
8173     DWORD ret;
8174     struct peekmsg_info *info = param;
8175
8176     trace("thread: waiting for start\n");
8177     WaitForSingleObject(info->hevent[EV_START_STOP], INFINITE);
8178     trace("thread: looping\n");
8179
8180     while (1)
8181     {
8182         ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
8183
8184         switch (ret)
8185         {
8186         case WAIT_OBJECT_0 + EV_START_STOP:
8187             trace("thread: exiting\n");
8188             return 0;
8189
8190         case WAIT_OBJECT_0 + EV_SENDMSG:
8191             trace("thread: sending message\n");
8192             SendNotifyMessageA(info->hwnd, WM_USER, 0, 0);
8193             SetEvent(info->hevent[EV_ACK]);
8194             break;
8195
8196         default:
8197             trace("unexpected return: %04x\n", ret);
8198             assert(0);
8199             break;
8200         }
8201     }
8202     return 0;
8203 }
8204
8205 static void test_PeekMessage(void)
8206 {
8207     MSG msg;
8208     HANDLE hthread;
8209     DWORD tid, qstatus;
8210     UINT qs_all_input = QS_ALLINPUT;
8211     UINT qs_input = QS_INPUT;
8212     BOOL ret;
8213     struct peekmsg_info info;
8214
8215     info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8216                               100, 100, 200, 200, 0, 0, 0, NULL);
8217     assert(info.hwnd);
8218     ShowWindow(info.hwnd, SW_SHOW);
8219     UpdateWindow(info.hwnd);
8220     SetFocus(info.hwnd);
8221
8222     info.hevent[EV_START_STOP] = CreateEventA(NULL, 0, 0, NULL);
8223     info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
8224     info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
8225
8226     hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
8227     Sleep(100);
8228
8229     trace("signalling to start looping\n");
8230     SetEvent(info.hevent[EV_START_STOP]);
8231
8232     flush_events();
8233     flush_sequence();
8234
8235     SetLastError(0xdeadbeef);
8236     qstatus = GetQueueStatus(qs_all_input);
8237     if (GetLastError() == ERROR_INVALID_FLAGS)
8238     {
8239         trace("QS_RAWINPUT not supported on this platform\n");
8240         qs_all_input &= ~QS_RAWINPUT;
8241         qs_input &= ~QS_RAWINPUT;
8242     }
8243     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8244
8245     trace("signalling to send message\n");
8246     SetEvent(info.hevent[EV_SENDMSG]);
8247     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8248
8249     /* pass invalid QS_xxxx flags */
8250     SetLastError(0xdeadbeef);
8251     qstatus = GetQueueStatus(0xffffffff);
8252     ok(qstatus == 0, "GetQueueStatus should fail: %08x\n", qstatus);
8253     ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
8254
8255     qstatus = GetQueueStatus(qs_all_input);
8256     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
8257        "wrong qstatus %08x\n", qstatus);
8258
8259     msg.message = 0;
8260     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8261     ok(!ret,
8262        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8263         msg.message);
8264     ok_sequence(WmUser, "WmUser", FALSE);
8265
8266     qstatus = GetQueueStatus(qs_all_input);
8267     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8268
8269     keybd_event('N', 0, 0, 0);
8270     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
8271     qstatus = GetQueueStatus(qs_all_input);
8272     ok(qstatus == MAKELONG(QS_KEY, QS_KEY),
8273        "wrong qstatus %08x\n", qstatus);
8274
8275     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8276     qstatus = GetQueueStatus(qs_all_input);
8277     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8278        "wrong qstatus %08x\n", qstatus);
8279
8280     InvalidateRect(info.hwnd, NULL, FALSE);
8281     qstatus = GetQueueStatus(qs_all_input);
8282     ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8283        "wrong qstatus %08x\n", qstatus);
8284
8285     trace("signalling to send message\n");
8286     SetEvent(info.hevent[EV_SENDMSG]);
8287     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8288
8289     qstatus = GetQueueStatus(qs_all_input);
8290     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8291        "wrong qstatus %08x\n", qstatus);
8292
8293     msg.message = 0;
8294     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
8295     ok(!ret,
8296        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8297         msg.message);
8298     ok_sequence(WmUser, "WmUser", FALSE);
8299
8300     qstatus = GetQueueStatus(qs_all_input);
8301     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8302        "wrong qstatus %08x\n", qstatus);
8303
8304     trace("signalling to send message\n");
8305     SetEvent(info.hevent[EV_SENDMSG]);
8306     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8307
8308     qstatus = GetQueueStatus(qs_all_input);
8309     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8310        "wrong qstatus %08x\n", qstatus);
8311
8312     msg.message = 0;
8313     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8314     ok(!ret,
8315        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8316         msg.message);
8317     ok_sequence(WmUser, "WmUser", FALSE);
8318
8319     qstatus = GetQueueStatus(qs_all_input);
8320     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8321        "wrong qstatus %08x\n", qstatus);
8322
8323     msg.message = 0;
8324     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8325     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8326        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8327        ret, msg.message, msg.wParam);
8328     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8329
8330     qstatus = GetQueueStatus(qs_all_input);
8331     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
8332        "wrong qstatus %08x\n", qstatus);
8333
8334     msg.message = 0;
8335     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8336     ok(!ret,
8337        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8338         msg.message);
8339     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8340
8341     qstatus = GetQueueStatus(qs_all_input);
8342     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
8343        "wrong qstatus %08x\n", qstatus);
8344
8345     msg.message = 0;
8346     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
8347     ok(ret && msg.message == WM_PAINT,
8348        "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
8349     DispatchMessageA(&msg);
8350     ok_sequence(WmPaint, "WmPaint", FALSE);
8351
8352     qstatus = GetQueueStatus(qs_all_input);
8353     ok(qstatus == MAKELONG(0, QS_KEY),
8354        "wrong qstatus %08x\n", qstatus);
8355
8356     msg.message = 0;
8357     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
8358     ok(!ret,
8359        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8360         msg.message);
8361     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8362
8363     qstatus = GetQueueStatus(qs_all_input);
8364     ok(qstatus == MAKELONG(0, QS_KEY),
8365        "wrong qstatus %08x\n", qstatus);
8366
8367     trace("signalling to send message\n");
8368     SetEvent(info.hevent[EV_SENDMSG]);
8369     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8370
8371     qstatus = GetQueueStatus(qs_all_input);
8372     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
8373        "wrong qstatus %08x\n", qstatus);
8374
8375     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8376
8377     qstatus = GetQueueStatus(qs_all_input);
8378     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
8379        "wrong qstatus %08x\n", qstatus);
8380
8381     msg.message = 0;
8382     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
8383     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8384        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8385        ret, msg.message, msg.wParam);
8386     ok_sequence(WmUser, "WmUser", FALSE);
8387
8388     qstatus = GetQueueStatus(qs_all_input);
8389     ok(qstatus == MAKELONG(0, QS_KEY),
8390        "wrong qstatus %08x\n", qstatus);
8391
8392     msg.message = 0;
8393     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
8394     ok(!ret,
8395        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8396         msg.message);
8397     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8398
8399     qstatus = GetQueueStatus(qs_all_input);
8400     ok(qstatus == MAKELONG(0, QS_KEY),
8401        "wrong qstatus %08x\n", qstatus);
8402
8403     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8404
8405     qstatus = GetQueueStatus(qs_all_input);
8406     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8407        "wrong qstatus %08x\n", qstatus);
8408
8409     trace("signalling to send message\n");
8410     SetEvent(info.hevent[EV_SENDMSG]);
8411     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8412
8413     qstatus = GetQueueStatus(qs_all_input);
8414     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
8415        "wrong qstatus %08x\n", qstatus);
8416
8417     msg.message = 0;
8418     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
8419     ok(!ret,
8420        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8421         msg.message);
8422     ok_sequence(WmUser, "WmUser", FALSE);
8423
8424     qstatus = GetQueueStatus(qs_all_input);
8425     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
8426        "wrong qstatus %08x\n", qstatus);
8427
8428     msg.message = 0;
8429     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
8430         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
8431     else /* workaround for a missing QS_RAWINPUT support */
8432         ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
8433     ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
8434        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
8435        ret, msg.message, msg.wParam);
8436     ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
8437
8438     qstatus = GetQueueStatus(qs_all_input);
8439     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
8440        "wrong qstatus %08x\n", qstatus);
8441
8442     msg.message = 0;
8443     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
8444         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
8445     else /* workaround for a missing QS_RAWINPUT support */
8446         ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
8447     ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
8448        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
8449        ret, msg.message, msg.wParam);
8450     ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
8451
8452     qstatus = GetQueueStatus(qs_all_input);
8453     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8454        "wrong qstatus %08x\n", qstatus);
8455
8456     msg.message = 0;
8457     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
8458     ok(!ret,
8459        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8460         msg.message);
8461     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8462
8463     qstatus = GetQueueStatus(qs_all_input);
8464     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8465        "wrong qstatus %08x\n", qstatus);
8466
8467     msg.message = 0;
8468     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8469     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8470        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8471        ret, msg.message, msg.wParam);
8472     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8473
8474     qstatus = GetQueueStatus(qs_all_input);
8475     ok(qstatus == 0,
8476        "wrong qstatus %08x\n", qstatus);
8477
8478     msg.message = 0;
8479     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8480     ok(!ret,
8481        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8482         msg.message);
8483     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8484
8485     qstatus = GetQueueStatus(qs_all_input);
8486     ok(qstatus == 0,
8487        "wrong qstatus %08x\n", qstatus);
8488
8489     /* test whether presence of the quit flag in the queue affects
8490      * the queue state
8491      */
8492     PostQuitMessage(0x1234abcd);
8493
8494     qstatus = GetQueueStatus(qs_all_input);
8495     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
8496        "wrong qstatus %08x\n", qstatus);
8497
8498     PostMessageA(info.hwnd, WM_USER, 0, 0);
8499
8500     qstatus = GetQueueStatus(qs_all_input);
8501     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
8502        "wrong qstatus %08x\n", qstatus);
8503
8504     msg.message = 0;
8505     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8506     ok(ret && msg.message == WM_USER,
8507        "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
8508     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8509
8510     qstatus = GetQueueStatus(qs_all_input);
8511     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8512        "wrong qstatus %08x\n", qstatus);
8513
8514     msg.message = 0;
8515     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8516     ok(ret && msg.message == WM_QUIT,
8517        "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
8518     ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
8519     ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
8520     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8521
8522     qstatus = GetQueueStatus(qs_all_input);
8523 todo_wine {
8524     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8525        "wrong qstatus %08x\n", qstatus);
8526 }
8527
8528     msg.message = 0;
8529     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8530     ok(!ret,
8531        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8532         msg.message);
8533     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8534
8535     qstatus = GetQueueStatus(qs_all_input);
8536     ok(qstatus == 0,
8537        "wrong qstatus %08x\n", qstatus);
8538
8539     trace("signalling to exit\n");
8540     SetEvent(info.hevent[EV_START_STOP]);
8541
8542     WaitForSingleObject(hthread, INFINITE);
8543
8544     CloseHandle(hthread);
8545     CloseHandle(info.hevent[0]);
8546     CloseHandle(info.hevent[1]);
8547     CloseHandle(info.hevent[2]);
8548
8549     DestroyWindow(info.hwnd);
8550 }
8551
8552 static void wait_move_event(HWND hwnd, int x, int y)
8553 {
8554     MSG msg;
8555     DWORD time;
8556     BOOL  ret;
8557     int go = 0;
8558
8559     time = GetTickCount();
8560     while (GetTickCount() - time < 200 && !go) {
8561         ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
8562         go  = ret && msg.pt.x > x && msg.pt.y > y;
8563     }
8564 }
8565
8566 #define STEP 20
8567 static void test_PeekMessage2(void)
8568 {
8569     HWND hwnd;
8570     BOOL ret;
8571     MSG msg;
8572     UINT message;
8573     DWORD time1, time2, time3;
8574     int x1, y1, x2, y2, x3, y3;
8575     POINT pos;
8576
8577     time1 = time2 = time3 = 0;
8578     x1 = y1 = x2 = y2 = x3 = y3 = 0;
8579
8580     /* Initialise window and make sure it is ready for events */
8581     hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
8582                         10, 10, 800, 800, NULL, NULL, NULL, NULL);
8583     assert(hwnd);
8584     trace("Window for test_PeekMessage2 %p\n", hwnd);
8585     ShowWindow(hwnd, SW_SHOW);
8586     UpdateWindow(hwnd);
8587     SetFocus(hwnd);
8588     GetCursorPos(&pos);
8589     SetCursorPos(100, 100);
8590     mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
8591     flush_events();
8592
8593     /* Do initial mousemove, wait until we can see it
8594        and then do our test peek with PM_NOREMOVE. */
8595     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
8596     wait_move_event(hwnd, 80, 80);
8597
8598     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
8599     ok(ret, "no message available\n");
8600     if (ret) {
8601         trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
8602         message = msg.message;
8603         time1 = msg.time;
8604         x1 = msg.pt.x;
8605         y1 = msg.pt.y;
8606         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
8607     }
8608
8609     /* Allow time to advance a bit, and then simulate the user moving their
8610      * mouse around. After that we peek again with PM_NOREMOVE.
8611      * Although the previous mousemove message was never removed, the
8612      * mousemove we now peek should reflect the recent mouse movements
8613      * because the input queue will merge the move events. */
8614     Sleep(2);
8615     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
8616     wait_move_event(hwnd, x1, y1);
8617
8618     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
8619     ok(ret, "no message available\n");
8620     if (ret) {
8621         trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
8622         message = msg.message;
8623         time2 = msg.time;
8624         x2 = msg.pt.x;
8625         y2 = msg.pt.y;
8626         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
8627         ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
8628         ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
8629     }
8630
8631     /* Have another go, to drive the point home */
8632     Sleep(2);
8633     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
8634     wait_move_event(hwnd, x2, y2);
8635
8636     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
8637     ok(ret, "no message available\n");
8638     if (ret) {
8639         trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
8640         message = msg.message;
8641         time3 = msg.time;
8642         x3 = msg.pt.x;
8643         y3 = msg.pt.y;
8644         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
8645         ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
8646         ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
8647     }
8648
8649     DestroyWindow(hwnd);
8650     SetCursorPos(pos.x, pos.y);
8651     flush_events();
8652 }
8653
8654 static void test_quit_message(void)
8655 {
8656     MSG msg;
8657     BOOL ret;
8658
8659     /* test using PostQuitMessage */
8660     PostQuitMessage(0xbeef);
8661
8662     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
8663     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
8664     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8665     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
8666
8667     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
8668     ok(ret, "PostMessage failed with error %d\n", GetLastError());
8669
8670     ret = GetMessage(&msg, NULL, 0, 0);
8671     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
8672     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
8673
8674     /* note: WM_QUIT message received after WM_USER message */
8675     ret = GetMessage(&msg, NULL, 0, 0);
8676     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
8677     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8678     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
8679
8680     ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
8681     ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
8682
8683     /* now test with PostThreadMessage - different behaviour! */
8684     PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
8685
8686     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
8687     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
8688     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8689     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
8690
8691     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
8692     ok(ret, "PostMessage failed with error %d\n", GetLastError());
8693
8694     /* note: we receive the WM_QUIT message first this time */
8695     ret = GetMessage(&msg, NULL, 0, 0);
8696     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
8697     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8698     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
8699
8700     ret = GetMessage(&msg, NULL, 0, 0);
8701     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
8702     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
8703 }
8704
8705 static const struct message WmMouseHoverSeq[] = {
8706     { WM_MOUSEACTIVATE, sent|optional },  /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
8707     { WM_MOUSEACTIVATE, sent|optional },
8708     { WM_TIMER, sent|optional }, /* XP sends it */
8709     { WM_SYSTIMER, sent },
8710     { WM_MOUSEHOVER, sent|wparam, 0 },
8711     { 0 }
8712 };
8713
8714 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
8715 {
8716     MSG msg;
8717     DWORD start_ticks, end_ticks;
8718
8719     start_ticks = GetTickCount();
8720     /* add some deviation (5%) to cover not expected delays */
8721     start_ticks += timeout / 20;
8722
8723     do
8724     {
8725         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
8726         {
8727             /* Timer proc messages are not dispatched to the window proc,
8728              * and therefore not logged.
8729              */
8730             if (msg.message == WM_TIMER || msg.message == WM_SYSTIMER)
8731             {
8732                 struct message s_msg;
8733
8734                 s_msg.message = msg.message;
8735                 s_msg.flags = sent|wparam|lparam;
8736                 s_msg.wParam = msg.wParam;
8737                 s_msg.lParam = msg.lParam;
8738                 add_message(&s_msg);
8739             }
8740             DispatchMessage(&msg);
8741         }
8742
8743         end_ticks = GetTickCount();
8744
8745         /* inject WM_MOUSEMOVE to see how it changes tracking */
8746         if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
8747         {
8748             mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8749             mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8750
8751             inject_mouse_move = FALSE;
8752         }
8753     } while (start_ticks + timeout >= end_ticks);
8754 }
8755
8756 static void test_TrackMouseEvent(void)
8757 {
8758     TRACKMOUSEEVENT tme;
8759     BOOL ret;
8760     HWND hwnd, hchild;
8761     RECT rc_parent, rc_child;
8762     UINT default_hover_time, hover_width = 0, hover_height = 0;
8763
8764 #define track_hover(track_hwnd, track_hover_time) \
8765     tme.cbSize = sizeof(tme); \
8766     tme.dwFlags = TME_HOVER; \
8767     tme.hwndTrack = track_hwnd; \
8768     tme.dwHoverTime = track_hover_time; \
8769     SetLastError(0xdeadbeef); \
8770     ret = pTrackMouseEvent(&tme); \
8771     ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
8772
8773 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
8774     tme.cbSize = sizeof(tme); \
8775     tme.dwFlags = TME_QUERY; \
8776     tme.hwndTrack = (HWND)0xdeadbeef; \
8777     tme.dwHoverTime = 0xdeadbeef; \
8778     SetLastError(0xdeadbeef); \
8779     ret = pTrackMouseEvent(&tme); \
8780     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
8781     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
8782     ok(tme.dwFlags == (expected_track_flags), \
8783        "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
8784     ok(tme.hwndTrack == (expected_track_hwnd), \
8785        "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
8786     ok(tme.dwHoverTime == (expected_hover_time), \
8787        "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
8788
8789 #define track_hover_cancel(track_hwnd) \
8790     tme.cbSize = sizeof(tme); \
8791     tme.dwFlags = TME_HOVER | TME_CANCEL; \
8792     tme.hwndTrack = track_hwnd; \
8793     tme.dwHoverTime = 0xdeadbeef; \
8794     SetLastError(0xdeadbeef); \
8795     ret = pTrackMouseEvent(&tme); \
8796     ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
8797
8798     default_hover_time = 0xdeadbeef;
8799     SetLastError(0xdeadbeef);
8800     ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
8801     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
8802     if (!ret) default_hover_time = 400;
8803     trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
8804
8805     SetLastError(0xdeadbeef);
8806     ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
8807     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
8808     if (!ret) hover_width = 4;
8809     SetLastError(0xdeadbeef);
8810     ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
8811     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
8812     if (!ret) hover_height = 4;
8813     trace("hover rect is %u x %d\n", hover_width, hover_height);
8814
8815     hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
8816                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8817                           CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8818                           NULL, NULL, 0);
8819     assert(hwnd);
8820
8821     hchild = CreateWindowEx(0, "TestWindowClass", NULL,
8822                           WS_CHILD | WS_BORDER | WS_VISIBLE,
8823                           50, 50, 200, 200, hwnd,
8824                           NULL, NULL, 0);
8825     assert(hchild);
8826
8827     flush_events();
8828     flush_sequence();
8829
8830     tme.cbSize = 0;
8831     tme.dwFlags = TME_QUERY;
8832     tme.hwndTrack = (HWND)0xdeadbeef;
8833     tme.dwHoverTime = 0xdeadbeef;
8834     SetLastError(0xdeadbeef);
8835     ret = pTrackMouseEvent(&tme);
8836     ok(!ret, "TrackMouseEvent should fail\n");
8837     ok(GetLastError() == ERROR_INVALID_PARAMETER, "not expected error %d\n", GetLastError());
8838
8839     tme.cbSize = sizeof(tme);
8840     tme.dwFlags = TME_HOVER;
8841     tme.hwndTrack = (HWND)0xdeadbeef;
8842     tme.dwHoverTime = 0xdeadbeef;
8843     SetLastError(0xdeadbeef);
8844     ret = pTrackMouseEvent(&tme);
8845     ok(!ret, "TrackMouseEvent should fail\n");
8846     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "not expected error %d\n", GetLastError());
8847
8848     tme.cbSize = sizeof(tme);
8849     tme.dwFlags = TME_HOVER | TME_CANCEL;
8850     tme.hwndTrack = (HWND)0xdeadbeef;
8851     tme.dwHoverTime = 0xdeadbeef;
8852     SetLastError(0xdeadbeef);
8853     ret = pTrackMouseEvent(&tme);
8854     ok(!ret, "TrackMouseEvent should fail\n");
8855     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "not expected error %d\n", GetLastError());
8856
8857     GetWindowRect(hwnd, &rc_parent);
8858     GetWindowRect(hchild, &rc_child);
8859     SetCursorPos(rc_child.left - 10, rc_child.top - 10);
8860
8861     /* Process messages so that the system updates its internal current
8862      * window and hittest, otherwise TrackMouseEvent calls don't have any
8863      * effect.
8864      */
8865     flush_events();
8866     flush_sequence();
8867
8868     track_query(0, NULL, 0);
8869     track_hover(hchild, 0);
8870     track_query(0, NULL, 0);
8871
8872     flush_events();
8873     flush_sequence();
8874
8875     track_hover(hwnd, 0);
8876     track_query(TME_HOVER, hwnd, default_hover_time);
8877
8878     pump_msg_loop_timeout(default_hover_time, FALSE);
8879     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
8880
8881     track_query(0, NULL, 0);
8882
8883     track_hover(hwnd, HOVER_DEFAULT);
8884     track_query(TME_HOVER, hwnd, default_hover_time);
8885
8886     Sleep(default_hover_time / 2);
8887     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8888     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8889
8890     track_query(TME_HOVER, hwnd, default_hover_time);
8891
8892     pump_msg_loop_timeout(default_hover_time / 2, FALSE);
8893     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
8894
8895     track_query(0, NULL, 0);
8896
8897     track_hover(hwnd, HOVER_DEFAULT);
8898     track_query(TME_HOVER, hwnd, default_hover_time);
8899
8900     pump_msg_loop_timeout(default_hover_time, TRUE);
8901     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
8902
8903     track_query(0, NULL, 0);
8904
8905     track_hover(hwnd, HOVER_DEFAULT);
8906     track_query(TME_HOVER, hwnd, default_hover_time);
8907     track_hover_cancel(hwnd);
8908
8909     DestroyWindow(hwnd);
8910
8911 #undef track_hover
8912 #undef track_query
8913 #undef track_hover_cancel
8914 }
8915
8916
8917 static const struct message WmSetWindowRgn[] = {
8918     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
8919     { WM_NCCALCSIZE, sent|wparam, 1 },
8920     { WM_NCPAINT, sent }, /* wparam != 1 */
8921     { WM_GETTEXT, sent|defwinproc|optional },
8922     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
8923     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
8924     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
8925     { 0 }
8926 };
8927
8928 static const struct message WmSetWindowRgn_no_redraw[] = {
8929     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
8930     { WM_NCCALCSIZE, sent|wparam, 1 },
8931     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
8932     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
8933     { 0 }
8934 };
8935
8936 static const struct message WmSetWindowRgn_clear[] = {
8937     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE }, /* some versions of 2000/XP also has SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE in wparam */
8938     { WM_NCCALCSIZE, sent|wparam, 1 },
8939     { WM_NCPAINT, sent }, /* wparam != 1 */
8940     { WM_GETTEXT, sent|defwinproc|optional },
8941     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
8942     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
8943     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
8944     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
8945     { WM_GETTEXT, sent|defwinproc|optional },
8946     { WM_ERASEBKGND, sent|optional },
8947     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
8948     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
8949     { 0 }
8950 };
8951
8952 static void test_SetWindowRgn(void)
8953 {
8954     HRGN hrgn;
8955     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
8956                                 100, 100, 200, 200, 0, 0, 0, NULL);
8957     ok( hwnd != 0, "Failed to create overlapped window\n" );
8958
8959     ShowWindow( hwnd, SW_SHOW );
8960     UpdateWindow( hwnd );
8961     flush_events();
8962     flush_sequence();
8963
8964     trace("testing SetWindowRgn\n");
8965     hrgn = CreateRectRgn( 0, 0, 150, 150 );
8966     SetWindowRgn( hwnd, hrgn, TRUE );
8967     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
8968
8969     hrgn = CreateRectRgn( 30, 30, 160, 160 );
8970     SetWindowRgn( hwnd, hrgn, FALSE );
8971     ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
8972
8973     hrgn = CreateRectRgn( 0, 0, 180, 180 );
8974     SetWindowRgn( hwnd, hrgn, TRUE );
8975     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
8976
8977     SetWindowRgn( hwnd, 0, TRUE );
8978     ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
8979
8980     DestroyWindow( hwnd );
8981 }
8982
8983 /*************************** ShowWindow() test ******************************/
8984 static const struct message WmShowNormal[] = {
8985     { WM_SHOWWINDOW, sent|wparam, 1 },
8986     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
8987     { HCBT_ACTIVATE, hook },
8988     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
8989     { HCBT_SETFOCUS, hook },
8990     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8991     { 0 }
8992 };
8993 static const struct message WmShow[] = {
8994     { WM_SHOWWINDOW, sent|wparam, 1 },
8995     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
8996     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
8997     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
8998     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
8999     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9000     { 0 }
9001 };
9002 static const struct message WmShowNoActivate_1[] = {
9003     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9004     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|0x8000 },
9005     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|0x8000 },
9006     { WM_MOVE, sent|defwinproc },
9007     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9008     { 0 }
9009 };
9010 static const struct message WmShowNoActivate_2[] = {
9011     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9012     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9013     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9014     { WM_MOVE, sent|defwinproc },
9015     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9016     { HCBT_SETFOCUS, hook },
9017     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9018     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9019     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9020     { 0 }
9021 };
9022 static const struct message WmShowNA_1[] = {
9023     { WM_SHOWWINDOW, sent|wparam, 1 },
9024     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9025     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9026     { 0 }
9027 };
9028 static const struct message WmShowNA_2[] = {
9029     { WM_SHOWWINDOW, sent|wparam, 1 },
9030     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9031     { 0 }
9032 };
9033 static const struct message WmRestore_1[] = {
9034     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9035     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9036     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9037     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9038     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9039     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9040     { WM_MOVE, sent|defwinproc },
9041     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9042     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9043     { 0 }
9044 };
9045 static const struct message WmRestore_2[] = {
9046     { WM_SHOWWINDOW, sent|wparam, 1 },
9047     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9048     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9049     { 0 }
9050 };
9051 static const struct message WmRestore_3[] = {
9052     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9053     { WM_GETMINMAXINFO, sent },
9054     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9055     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9056     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9057     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9058     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9059     { WM_MOVE, sent|defwinproc },
9060     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9061     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9062     { 0 }
9063 };
9064 static const struct message WmRestore_4[] = {
9065     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9066     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
9067     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|0x8000 },
9068     { WM_MOVE, sent|defwinproc },
9069     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9070     { 0 }
9071 };
9072 static const struct message WmRestore_5[] = {
9073     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
9074     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
9075     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|0x8000 },
9076     { WM_MOVE, sent|defwinproc },
9077     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9078     { 0 }
9079 };
9080 static const struct message WmHide_1[] = {
9081     { WM_SHOWWINDOW, sent|wparam, 0 },
9082     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9083     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9084     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9085     { 0 }
9086 };
9087 static const struct message WmHide_2[] = {
9088     { WM_SHOWWINDOW, sent|wparam, 0 },
9089     { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9090     { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9091     { 0 }
9092 };
9093 static const struct message WmHide_3[] = {
9094     { WM_SHOWWINDOW, sent|wparam, 0 },
9095     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9096     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9097     { HCBT_SETFOCUS, hook },
9098     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9099     { 0 }
9100 };
9101 static const struct message WmShowMinimized_1[] = {
9102     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9103     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9104     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9105     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9106     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9107     { WM_MOVE, sent|defwinproc },
9108     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9109     { 0 }
9110 };
9111 static const struct message WmMinimize_1[] = {
9112     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9113     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9114     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9115     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9116     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9117     { WM_MOVE, sent|defwinproc },
9118     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9119     { 0 }
9120 };
9121 static const struct message WmMinimize_2[] = {
9122     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9123     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9124     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9125     { WM_MOVE, sent|defwinproc },
9126     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9127     { 0 }
9128 };
9129 static const struct message WmMinimize_3[] = {
9130     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9131     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9132     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9133     { WM_MOVE, sent|defwinproc },
9134     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9135     { 0 }
9136 };
9137 static const struct message WmShowMinNoActivate[] = {
9138     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9139     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9140     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9141     { 0 }
9142 };
9143 static const struct message WmMinMax_1[] = {
9144     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9145     { 0 }
9146 };
9147 static const struct message WmMinMax_2[] = {
9148     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9149     { 0 }
9150 };
9151 static const struct message WmMinMax_3[] = {
9152     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9153     { 0 }
9154 };
9155 static const struct message WmMinMax_4[] = {
9156     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9157     { 0 }
9158 };
9159 static const struct message WmShowMaximized_1[] = {
9160     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9161     { WM_GETMINMAXINFO, sent },
9162     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9163     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9164     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9165     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9166     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9167     { WM_MOVE, sent|defwinproc },
9168     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9169     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9170     { 0 }
9171 };
9172 static const struct message WmShowMaximized_2[] = {
9173     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9174     { WM_GETMINMAXINFO, sent },
9175     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
9176     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9177     { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
9178     { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
9179     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9180     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9181     { WM_MOVE, sent|defwinproc },
9182     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9183     { HCBT_SETFOCUS, hook },
9184     { 0 }
9185 };
9186 static const struct message WmShowMaximized_3[] = {
9187     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9188     { WM_GETMINMAXINFO, sent },
9189     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
9190     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|0x8000 },
9191     { WM_MOVE, sent|defwinproc },
9192     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9193     { 0 }
9194 };
9195
9196 static void test_ShowWindow(void)
9197 {
9198     /* ShowWindow commands in random order */
9199     static const struct
9200     {
9201         INT cmd; /* ShowWindow command */
9202         LPARAM ret; /* ShowWindow return value */
9203         DWORD style; /* window style after the command */
9204         const struct message *msg; /* message sequence the command produces */
9205         BOOL todo_msg; /* message sequence doesn't match what Wine does */
9206     } sw[] =
9207     {
9208 /*  1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
9209 /*  2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9210 /*  3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
9211 /*  4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9212 /*  5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
9213 /*  6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
9214 /*  7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
9215 /*  8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
9216 /*  9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
9217 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
9218 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
9219 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
9220 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
9221 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9222 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
9223 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9224 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
9225 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9226 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, TRUE },
9227 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
9228 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9229 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
9230 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
9231 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9232 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
9233 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
9234 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
9235 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9236 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
9237 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
9238 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9239 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, TRUE },
9240 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9241 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, TRUE }, /* what does this mean?! */
9242 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, TRUE },
9243 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9244 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
9245 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9246 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9247 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, TRUE },
9248 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
9249 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, TRUE },
9250 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
9251 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, TRUE },
9252 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
9253 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
9254 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
9255 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
9256 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
9257 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
9258 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9259 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
9260 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9261 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, TRUE },
9262 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9263 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
9264 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
9265     };
9266     HWND hwnd;
9267     DWORD style;
9268     LPARAM ret;
9269     INT i;
9270
9271 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
9272     hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
9273                           120, 120, 90, 90,
9274                           0, 0, 0, NULL);
9275     assert(hwnd);
9276
9277     style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
9278     ok(style == 0, "expected style 0, got %08x\n", style);
9279
9280     flush_events();
9281     flush_sequence();
9282
9283     for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
9284     {
9285         static const char * const sw_cmd_name[13] =
9286         {
9287             "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
9288             "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
9289             "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
9290             "SW_NORMALNA" /* 0xCC */
9291         };
9292         char comment[64];
9293         INT idx; /* index into the above array of names */
9294
9295         idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
9296
9297         style = GetWindowLong(hwnd, GWL_STYLE);
9298         trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
9299         ret = ShowWindow(hwnd, sw[i].cmd);
9300         ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
9301         style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
9302         ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
9303
9304         sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
9305         ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
9306
9307         flush_events();
9308         flush_sequence();
9309     }
9310
9311     DestroyWindow(hwnd);
9312 }
9313
9314 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9315 {
9316     struct message msg;
9317
9318     trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
9319
9320     switch (message)
9321     {
9322     case WM_WINDOWPOSCHANGING:
9323     case WM_WINDOWPOSCHANGED:
9324     {
9325         WINDOWPOS *winpos = (WINDOWPOS *)lParam;
9326
9327         trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
9328         trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
9329               winpos->hwnd, winpos->hwndInsertAfter,
9330               winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
9331         dump_winpos_flags(winpos->flags);
9332
9333         /* Log only documented flags, win2k uses 0x1000 and 0x2000
9334          * in the high word for internal purposes
9335          */
9336         wParam = winpos->flags & 0xffff;
9337         /* We are not interested in the flags that don't match under XP and Win9x */
9338         wParam &= ~(SWP_NOZORDER);
9339         break;
9340     }
9341
9342     /* explicitly ignore WM_GETICON message */
9343     case WM_GETICON:
9344         return 0;
9345     }
9346
9347     msg.message = message;
9348     msg.flags = sent|wparam|lparam;
9349     msg.wParam = wParam;
9350     msg.lParam = lParam;
9351     add_message(&msg);
9352
9353     /* calling DefDlgProc leads to a recursion under XP */
9354
9355     switch (message)
9356     {
9357     case WM_INITDIALOG:
9358     case WM_GETDLGCODE:
9359         return 0;
9360     }
9361     return 1;
9362 }
9363
9364 static const struct message WmDefDlgSetFocus_1[] = {
9365     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
9366     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
9367     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
9368     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
9369     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
9370     { HCBT_SETFOCUS, hook },
9371     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9372     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9373     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9374     { WM_SETFOCUS, sent|wparam, 0 },
9375     { WM_CTLCOLOREDIT, sent },
9376     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9377     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9378     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9379     { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
9380     { 0 }
9381 };
9382 static const struct message WmDefDlgSetFocus_2[] = {
9383     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
9384     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
9385     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
9386     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
9387     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
9388     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9389     { WM_CTLCOLOREDIT, sent|optional }, /* XP */
9390     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9391     { 0 }
9392 };
9393 /* Creation of a dialog */
9394 static const struct message WmCreateDialogParamSeq_1[] = {
9395     { HCBT_CREATEWND, hook },
9396     { WM_NCCREATE, sent },
9397     { WM_NCCALCSIZE, sent|wparam, 0 },
9398     { WM_CREATE, sent },
9399     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
9400     { WM_SIZE, sent|wparam, SIZE_RESTORED },
9401     { WM_MOVE, sent },
9402     { WM_SETFONT, sent },
9403     { WM_INITDIALOG, sent },
9404     { WM_CHANGEUISTATE, sent|optional },
9405     { 0 }
9406 };
9407 /* Creation of a dialog */
9408 static const struct message WmCreateDialogParamSeq_2[] = {
9409     { HCBT_CREATEWND, hook },
9410     { WM_NCCREATE, sent },
9411     { WM_NCCALCSIZE, sent|wparam, 0 },
9412     { WM_CREATE, sent },
9413     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
9414     { WM_SIZE, sent|wparam, SIZE_RESTORED },
9415     { WM_MOVE, sent },
9416     { WM_CHANGEUISTATE, sent|optional },
9417     { 0 }
9418 };
9419
9420 static void test_dialog_messages(void)
9421 {
9422     WNDCLASS cls;
9423     HWND hdlg, hedit1, hedit2, hfocus;
9424     LRESULT ret;
9425
9426 #define set_selection(hctl, start, end) \
9427     ret = SendMessage(hctl, EM_SETSEL, start, end); \
9428     ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
9429
9430 #define check_selection(hctl, start, end) \
9431     ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
9432     ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
9433
9434     subclass_edit();
9435
9436     hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
9437                           WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
9438                           0, 0, 100, 100, 0, 0, 0, NULL);
9439     ok(hdlg != 0, "Failed to create custom dialog window\n");
9440
9441     hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
9442                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
9443                            0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
9444     ok(hedit1 != 0, "Failed to create edit control\n");
9445     hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
9446                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
9447                            0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
9448     ok(hedit2 != 0, "Failed to create edit control\n");
9449
9450     SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
9451     SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
9452
9453     hfocus = GetFocus();
9454     ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
9455
9456     SetFocus(hedit2);
9457     hfocus = GetFocus();
9458     ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
9459
9460     check_selection(hedit1, 0, 0);
9461     check_selection(hedit2, 0, 0);
9462
9463     set_selection(hedit2, 0, -1);
9464     check_selection(hedit2, 0, 3);
9465
9466     SetFocus(0);
9467     hfocus = GetFocus();
9468     ok(hfocus == 0, "wrong focus %p\n", hfocus);
9469
9470     flush_sequence();
9471     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
9472     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
9473     ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
9474
9475     hfocus = GetFocus();
9476     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
9477
9478     check_selection(hedit1, 0, 5);
9479     check_selection(hedit2, 0, 3);
9480
9481     flush_sequence();
9482     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
9483     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
9484     ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
9485
9486     hfocus = GetFocus();
9487     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
9488
9489     check_selection(hedit1, 0, 5);
9490     check_selection(hedit2, 0, 3);
9491
9492     EndDialog(hdlg, 0);
9493     DestroyWindow(hedit1);
9494     DestroyWindow(hedit2);
9495     DestroyWindow(hdlg);
9496     flush_sequence();
9497
9498 #undef set_selection
9499 #undef check_selection
9500
9501     ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
9502     cls.lpszClassName = "MyDialogClass";
9503     cls.hInstance = GetModuleHandle(0);
9504     /* need a cast since a dlgproc is used as a wndproc */
9505     cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
9506     if (!RegisterClass(&cls)) assert(0);
9507
9508     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
9509     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
9510     ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
9511     EndDialog(hdlg, 0);
9512     DestroyWindow(hdlg);
9513     flush_sequence();
9514
9515     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
9516     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
9517     ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
9518     EndDialog(hdlg, 0);
9519     DestroyWindow(hdlg);
9520     flush_sequence();
9521
9522     UnregisterClass(cls.lpszClassName, cls.hInstance);
9523 }
9524
9525 static void test_nullCallback(void)
9526 {
9527     HWND hwnd;
9528
9529     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
9530                            100, 100, 200, 200, 0, 0, 0, NULL);
9531     ok (hwnd != 0, "Failed to create overlapped window\n");
9532
9533     SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
9534     flush_events();
9535     DestroyWindow(hwnd);
9536 }
9537
9538 static const struct message SetForegroundWindowSeq[] =
9539 {
9540     { WM_NCACTIVATE, sent|wparam, 0 },
9541     { WM_GETTEXT, sent|defwinproc|optional },
9542     { WM_ACTIVATE, sent|wparam, 0 },
9543     { WM_ACTIVATEAPP, sent|wparam, 0 },
9544     { WM_KILLFOCUS, sent },
9545     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
9546     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
9547     { 0 }
9548 };
9549
9550 static void test_SetForegroundWindow(void)
9551 {
9552     HWND hwnd;
9553
9554     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
9555                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9556                            100, 100, 200, 200, 0, 0, 0, NULL);
9557     ok (hwnd != 0, "Failed to create overlapped window\n");
9558     flush_sequence();
9559
9560     trace("SetForegroundWindow( 0 )\n");
9561     SetForegroundWindow( 0 );
9562     ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
9563     trace("SetForegroundWindow( GetDesktopWindow() )\n");
9564     SetForegroundWindow( GetDesktopWindow() );
9565     ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
9566                                         "foreground top level window", FALSE);
9567     trace("done\n");
9568
9569     DestroyWindow(hwnd);
9570 }
9571
9572 static void test_dbcs_wm_char(void)
9573 {
9574     BYTE dbch[2];
9575     WCHAR wch, bad_wch;
9576     HWND hwnd, hwnd2;
9577     MSG msg;
9578     DWORD time;
9579     POINT pt;
9580     DWORD_PTR res;
9581     CPINFOEXA cpinfo;
9582     UINT i, j, k;
9583     struct message wmCharSeq[2];
9584
9585     pGetCPInfoExA( CP_ACP, 0, &cpinfo );
9586     if (cpinfo.MaxCharSize != 2)
9587     {
9588         skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
9589         return;
9590     }
9591
9592     dbch[0] = dbch[1] = 0;
9593     wch = 0;
9594     bad_wch = cpinfo.UnicodeDefaultChar;
9595     for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
9596         for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
9597             for (k = 128; k <= 255; k++)
9598             {
9599                 char str[2];
9600                 WCHAR wstr[2];
9601                 str[0] = j;
9602                 str[1] = k;
9603                 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
9604                     WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
9605                     (BYTE)str[0] == j && (BYTE)str[1] == k &&
9606                     HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
9607                 {
9608                     dbch[0] = j;
9609                     dbch[1] = k;
9610                     wch = wstr[0];
9611                     break;
9612                 }
9613             }
9614
9615     if (!wch)
9616     {
9617         skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
9618         return;
9619     }
9620     trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
9621            dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
9622
9623     hwnd = CreateWindowExW(0, testWindowClassW, NULL,
9624                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
9625     hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
9626                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
9627     ok (hwnd != 0, "Failed to create overlapped window\n");
9628     ok (hwnd2 != 0, "Failed to create overlapped window\n");
9629     flush_sequence();
9630
9631     memset( wmCharSeq, 0, sizeof(wmCharSeq) );
9632     wmCharSeq[0].message = WM_CHAR;
9633     wmCharSeq[0].flags = sent|wparam;
9634     wmCharSeq[0].wParam = wch;
9635
9636     /* posted message */
9637     PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9638     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9639     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9640     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9641     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9642     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
9643     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9644
9645     /* posted thread message */
9646     PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
9647     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9648     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9649     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9650     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9651     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
9652     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9653
9654     /* sent message */
9655     flush_sequence();
9656     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9657     ok_sequence( WmEmptySeq, "no messages", FALSE );
9658     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9659     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9660     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9661
9662     /* sent message with timeout */
9663     flush_sequence();
9664     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
9665     ok_sequence( WmEmptySeq, "no messages", FALSE );
9666     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
9667     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9668     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9669
9670     /* sent message with timeout and callback */
9671     flush_sequence();
9672     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
9673     ok_sequence( WmEmptySeq, "no messages", FALSE );
9674     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
9675     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9676     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9677
9678     /* sent message with callback */
9679     flush_sequence();
9680     SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9681     ok_sequence( WmEmptySeq, "no messages", FALSE );
9682     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
9683     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9684     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9685
9686     /* direct window proc call */
9687     flush_sequence();
9688     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
9689     ok_sequence( WmEmptySeq, "no messages", FALSE );
9690     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
9691     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9692
9693     /* dispatch message */
9694     msg.hwnd = hwnd;
9695     msg.message = WM_CHAR;
9696     msg.wParam = dbch[0];
9697     msg.lParam = 0;
9698     DispatchMessageA( &msg );
9699     ok_sequence( WmEmptySeq, "no messages", FALSE );
9700     msg.wParam = dbch[1];
9701     DispatchMessageA( &msg );
9702     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9703
9704     /* window handle is irrelevant */
9705     flush_sequence();
9706     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
9707     ok_sequence( WmEmptySeq, "no messages", FALSE );
9708     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9709     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9710     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9711
9712     /* interleaved post and send */
9713     flush_sequence();
9714     PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
9715     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
9716     ok_sequence( WmEmptySeq, "no messages", FALSE );
9717     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9718     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9719     ok_sequence( WmEmptySeq, "no messages", FALSE );
9720     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9721     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9722     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
9723     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9724     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9725     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9726     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9727
9728     /* interleaved sent message and winproc */
9729     flush_sequence();
9730     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9731     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
9732     ok_sequence( WmEmptySeq, "no messages", FALSE );
9733     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9734     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9735     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
9736     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9737
9738     /* interleaved winproc and dispatch */
9739     msg.hwnd = hwnd;
9740     msg.message = WM_CHAR;
9741     msg.wParam = dbch[0];
9742     msg.lParam = 0;
9743     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
9744     DispatchMessageA( &msg );
9745     ok_sequence( WmEmptySeq, "no messages", FALSE );
9746     msg.wParam = dbch[1];
9747     DispatchMessageA( &msg );
9748     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9749     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
9750     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9751
9752     /* interleaved sends */
9753     flush_sequence();
9754     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9755     SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
9756     ok_sequence( WmEmptySeq, "no messages", FALSE );
9757     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
9758     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9759     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9760     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9761
9762     /* dbcs WM_CHAR */
9763     flush_sequence();
9764     SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
9765     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9766     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9767
9768     /* other char messages are not magic */
9769     PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
9770     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9771     ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
9772     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
9773     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9774     PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
9775     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9776     ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
9777     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
9778     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9779
9780     /* test retrieving messages */
9781
9782     PostMessageW( hwnd, WM_CHAR, wch, 0 );
9783     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9784     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9785     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9786     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9787     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9788     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9789     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9790     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9791     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9792
9793     /* message filters */
9794     PostMessageW( hwnd, WM_CHAR, wch, 0 );
9795     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9796     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9797     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9798     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9799     /* message id is filtered, hwnd is not */
9800     ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
9801     ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
9802     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9803     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9804     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9805     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9806
9807     /* mixing GetMessage and PostMessage */
9808     PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
9809     ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
9810     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9811     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9812     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9813     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
9814     time = msg.time;
9815     pt = msg.pt;
9816     ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
9817     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
9818     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9819     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9820     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9821     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
9822     ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
9823     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 );
9824     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9825
9826     /* without PM_REMOVE */
9827     PostMessageW( hwnd, WM_CHAR, wch, 0 );
9828     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
9829     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9830     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9831     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9832     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
9833     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9834     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9835     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9836     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
9837     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9838     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9839     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9840     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
9841     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9842     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9843     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9844     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9845
9846     DestroyWindow(hwnd);
9847 }
9848
9849 #define ID_LISTBOX 0x000f
9850
9851 static const struct message wm_lb_setcursel_0[] =
9852 {
9853     { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
9854     { WM_CTLCOLORLISTBOX, sent|parent },
9855     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
9856     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
9857     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
9858     { 0 }
9859 };
9860 static const struct message wm_lb_setcursel_1[] =
9861 {
9862     { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
9863     { WM_CTLCOLORLISTBOX, sent|parent },
9864     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
9865     { WM_CTLCOLORLISTBOX, sent|parent },
9866     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
9867     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
9868     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
9869     { 0 }
9870 };
9871 static const struct message wm_lb_setcursel_2[] =
9872 {
9873     { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
9874     { WM_CTLCOLORLISTBOX, sent|parent },
9875     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
9876     { WM_CTLCOLORLISTBOX, sent|parent },
9877     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
9878     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
9879     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
9880     { 0 }
9881 };
9882 static const struct message wm_lb_click_0[] =
9883 {
9884     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
9885     { HCBT_SETFOCUS, hook },
9886     { WM_KILLFOCUS, sent|parent },
9887     { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
9888     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9889     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9890     { WM_SETFOCUS, sent },
9891
9892     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
9893     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
9894     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
9895     { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
9896     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9897
9898     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
9899     { WM_CTLCOLORLISTBOX, sent|parent },
9900     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
9901     { WM_CTLCOLORLISTBOX, sent|parent },
9902     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
9903     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
9904
9905     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
9906     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
9907
9908     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9909     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9910     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, 0 },
9911     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
9912     { 0 }
9913 };
9914
9915 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
9916
9917 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
9918
9919 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
9920 {
9921     struct message msg;
9922
9923     /* do not log painting messages */
9924     if (message != WM_PAINT &&
9925         message != WM_NCPAINT &&
9926         message != WM_SYNCPAINT &&
9927         message != WM_ERASEBKGND &&
9928         message != WM_NCHITTEST &&
9929         message != WM_GETTEXT &&
9930         message != WM_GETICON &&
9931         message != WM_DEVICECHANGE)
9932     {
9933         trace("listbox: %p, %04x, %08lx, %08lx\n", hwnd, message, wp, lp);
9934
9935         msg.message = message;
9936         msg.flags = sent|wparam|lparam;
9937         msg.wParam = wp;
9938         msg.lParam = lp;
9939         add_message(&msg);
9940     }
9941
9942     return CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
9943 }
9944
9945 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
9946                                int caret_index, int top_index, int line)
9947 {
9948     LRESULT ret;
9949
9950     /* calling an orig proc helps to avoid unnecessary message logging */
9951     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
9952     ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
9953     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
9954     ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
9955     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
9956     ok_(__FILE__, line)(ret == caret_index, "expected caret index %d, got %ld\n", caret_index, ret);
9957     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
9958     ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
9959 }
9960
9961 static void test_listbox(void)
9962 {
9963     HWND parent, listbox;
9964     LRESULT ret;
9965
9966     parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW  | WS_VISIBLE,
9967                              100, 100, 200, 200, 0, 0, 0, NULL);
9968     listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
9969                               WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
9970                               10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
9971     listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
9972
9973     check_lb_state(listbox, 0, LB_ERR, 0, 0);
9974
9975     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
9976     ok(ret == 0, "expected 0, got %ld\n", ret);
9977     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
9978     ok(ret == 1, "expected 1, got %ld\n", ret);
9979     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
9980     ok(ret == 2, "expected 2, got %ld\n", ret);
9981
9982     check_lb_state(listbox, 3, LB_ERR, 0, 0);
9983
9984     flush_sequence();
9985
9986     log_all_parent_messages++;
9987
9988     trace("selecting item 0\n");
9989     ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
9990     ok(ret == 0, "expected 0, got %ld\n", ret);
9991     ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
9992     check_lb_state(listbox, 3, 0, 0, 0);
9993     flush_sequence();
9994
9995     trace("selecting item 1\n");
9996     ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
9997     ok(ret == 1, "expected 1, got %ld\n", ret);
9998     ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
9999     check_lb_state(listbox, 3, 1, 1, 0);
10000
10001     trace("selecting item 2\n");
10002     ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
10003     ok(ret == 2, "expected 2, got %ld\n", ret);
10004     ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
10005     check_lb_state(listbox, 3, 2, 2, 0);
10006
10007     trace("clicking on item 0\n");
10008     ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
10009     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
10010     ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
10011     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
10012     ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
10013     check_lb_state(listbox, 3, 0, 0, 0);
10014     flush_sequence();
10015
10016     log_all_parent_messages--;
10017
10018     DestroyWindow(parent);
10019 }
10020
10021 START_TEST(msg)
10022 {
10023     BOOL ret;
10024     FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
10025
10026     init_procs();
10027
10028     if (!RegisterWindowClasses()) assert(0);
10029
10030     if (pSetWinEventHook)
10031     {
10032         hEvent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
10033                                                       GetModuleHandleA(0),
10034                                                       win_event_proc,
10035                                                       0,
10036                                                       GetCurrentThreadId(),
10037                                                       WINEVENT_INCONTEXT);
10038         assert(hEvent_hook);
10039
10040         if (pIsWinEventHookInstalled)
10041         {
10042             UINT event;
10043             for (event = EVENT_MIN; event <= EVENT_MAX; event++)
10044                 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
10045         }
10046     }
10047
10048     cbt_hook_thread_id = GetCurrentThreadId();
10049     hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
10050     assert(hCBT_hook);
10051
10052     test_winevents();
10053
10054     /* Fix message sequences before removing 4 lines below */
10055 #if 1
10056     if (pUnhookWinEvent && hEvent_hook)
10057     {
10058         ret = pUnhookWinEvent(hEvent_hook);
10059         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
10060         pUnhookWinEvent = 0;
10061     }
10062     hEvent_hook = 0;
10063 #endif
10064
10065     test_ShowWindow();
10066     test_PeekMessage();
10067     test_PeekMessage2();
10068     test_scrollwindowex();
10069     test_messages();
10070     test_showwindow();
10071     invisible_parent_tests();
10072     test_mdi_messages();
10073     test_button_messages();
10074     test_static_messages();
10075     test_paint_messages();
10076     test_interthread_messages();
10077     test_message_conversion();
10078     test_accelerators();
10079     test_timers();
10080     test_timers_no_wnd();
10081     test_set_hook();
10082     test_DestroyWindow();
10083     test_DispatchMessage();
10084     test_SendMessageTimeout();
10085     test_edit_messages();
10086     test_quit_message();
10087
10088     if (!pTrackMouseEvent)
10089         skip("TrackMouseEvent is not available\n");
10090     else
10091         test_TrackMouseEvent();
10092
10093     test_SetWindowRgn();
10094     test_sys_menu();
10095     test_dialog_messages();
10096     test_nullCallback();
10097     test_SetForegroundWindow();
10098     test_dbcs_wm_char();
10099     test_listbox();
10100
10101     UnhookWindowsHookEx(hCBT_hook);
10102     if (pUnhookWinEvent)
10103     {
10104         ret = pUnhookWinEvent(hEvent_hook);
10105         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
10106         SetLastError(0xdeadbeef);
10107         ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
10108         ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
10109            GetLastError() == 0xdeadbeef, /* Win9x */
10110            "unexpected error %d\n", GetLastError());
10111     }
10112     else
10113         skip("UnhookWinEvent is not available\n");
10114 }