urlmon: Don't create stgmed_obj for binding to object.
[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     LPARAM logged_lParam;
6250
6251     trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6252
6253     /* explicitly ignore WM_GETICON message */
6254     if (message == WM_GETICON) return 0;
6255
6256     logged_lParam=lParam;
6257     if (log_all_parent_messages ||
6258         message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
6259         message == WM_SETFOCUS || message == WM_KILLFOCUS ||
6260         message == WM_ENABLE || message == WM_ENTERIDLE ||
6261         message == WM_DRAWITEM ||
6262         message == WM_IME_SETCONTEXT)
6263     {
6264         switch (message)
6265         {
6266             /* ignore */
6267             case WM_NCHITTEST:
6268                 return HTCLIENT;
6269             case WM_SETCURSOR:
6270             case WM_MOUSEMOVE:
6271                 return 0;
6272
6273             case WM_ERASEBKGND:
6274             {
6275                 RECT rc;
6276                 INT ret = GetClipBox((HDC)wParam, &rc);
6277
6278                 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
6279                        ret, rc.left, rc.top, rc.right, rc.bottom);
6280                 break;
6281             }
6282
6283             case WM_WINDOWPOSCHANGING:
6284             case WM_WINDOWPOSCHANGED:
6285             {
6286                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6287
6288                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6289                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6290                       winpos->hwnd, winpos->hwndInsertAfter,
6291                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6292                 dump_winpos_flags(winpos->flags);
6293
6294                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
6295                  * in the high word for internal purposes
6296                  */
6297                 wParam = winpos->flags & 0xffff;
6298                 /* We are not interested in the flags that don't match under XP and Win9x */
6299                 wParam &= ~(SWP_NOZORDER);
6300                 break;
6301             }
6302
6303             case WM_DRAWITEM:
6304             {
6305                 /* encode DRAWITEMSTRUCT into an LPARAM */
6306                 DRAW_ITEM_STRUCT di;
6307                 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam;
6308
6309                 trace("WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x\n",
6310                       dis->CtlType, dis->CtlID, dis->itemID, dis->itemAction, dis->itemState);
6311
6312                 di.u.item.type = dis->CtlType;
6313                 di.u.item.ctl_id = dis->CtlID;
6314                 di.u.item.item_id = dis->itemID;
6315                 di.u.item.action = dis->itemAction;
6316                 di.u.item.state = dis->itemState;
6317
6318                 logged_lParam = di.u.lp;
6319                 break;
6320             }
6321         }
6322
6323         msg.message = message;
6324         msg.flags = sent|parent|wparam|lparam;
6325         if (defwndproc_counter) msg.flags |= defwinproc;
6326         if (beginpaint_counter) msg.flags |= beginpaint;
6327         msg.wParam = wParam;
6328         msg.lParam = logged_lParam;
6329         add_message(&msg);
6330     }
6331
6332     if (message == WM_PAINT)
6333     {
6334         PAINTSTRUCT ps;
6335         beginpaint_counter++;
6336         BeginPaint( hwnd, &ps );
6337         beginpaint_counter--;
6338         EndPaint( hwnd, &ps );
6339         return 0;
6340     }
6341
6342     defwndproc_counter++;
6343     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6344     defwndproc_counter--;
6345
6346     return ret;
6347 }
6348
6349 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6350 {
6351     static long defwndproc_counter = 0;
6352     LRESULT ret;
6353     struct message msg;
6354
6355     trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6356
6357     /* explicitly ignore WM_GETICON message */
6358     if (message == WM_GETICON) return 0;
6359
6360     if (test_def_id)
6361     {
6362         DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
6363         ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
6364         if (after_end_dialog)
6365             ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
6366         else
6367             ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
6368     }
6369
6370     switch (message)
6371     {
6372         case WM_WINDOWPOSCHANGING:
6373         case WM_WINDOWPOSCHANGED:
6374         {
6375             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6376
6377             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6378             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6379                   winpos->hwnd, winpos->hwndInsertAfter,
6380                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6381             dump_winpos_flags(winpos->flags);
6382
6383             /* Log only documented flags, win2k uses 0x1000 and 0x2000
6384              * in the high word for internal purposes
6385              */
6386             wParam = winpos->flags & 0xffff;
6387             /* We are not interested in the flags that don't match under XP and Win9x */
6388             wParam &= ~(SWP_NOZORDER);
6389             break;
6390         }
6391     }
6392
6393     msg.message = message;
6394     msg.flags = sent|wparam|lparam;
6395     if (defwndproc_counter) msg.flags |= defwinproc;
6396     msg.wParam = wParam;
6397     msg.lParam = lParam;
6398     add_message(&msg);
6399
6400     defwndproc_counter++;
6401     ret = DefDlgProcA(hwnd, message, wParam, lParam);
6402     defwndproc_counter--;
6403
6404     return ret;
6405 }
6406
6407 static void dump_winpos_flags(UINT flags)
6408 {
6409     if (!winetest_debug) return;
6410
6411     if (flags & SWP_SHOWWINDOW) printf("|SWP_SHOWWINDOW");
6412     if (flags & SWP_HIDEWINDOW) printf("|SWP_HIDEWINDOW");
6413     if (flags & SWP_NOACTIVATE) printf("|SWP_NOACTIVATE");
6414     if (flags & SWP_FRAMECHANGED) printf("|SWP_FRAMECHANGED");
6415     if (flags & SWP_NOCOPYBITS) printf("|SWP_NOCOPYBITS");
6416     if (flags & SWP_NOOWNERZORDER) printf("|SWP_NOOWNERZORDER");
6417     if (flags & SWP_NOSENDCHANGING) printf("|SWP_NOSENDCHANGING");
6418     if (flags & SWP_DEFERERASE) printf("|SWP_DEFERERASE");
6419     if (flags & SWP_ASYNCWINDOWPOS) printf("|SWP_ASYNCWINDOWPOS");
6420     if (flags & SWP_NOZORDER) printf("|SWP_NOZORDER");
6421     if (flags & SWP_NOREDRAW) printf("|SWP_NOREDRAW");
6422     if (flags & SWP_NOSIZE) printf("|SWP_NOSIZE");
6423     if (flags & SWP_NOMOVE) printf("|SWP_NOMOVE");
6424     if (flags & SWP_NOCLIENTSIZE) printf("|SWP_NOCLIENTSIZE");
6425     if (flags & SWP_NOCLIENTMOVE) printf("|SWP_NOCLIENTMOVE");
6426
6427 #define DUMPED_FLAGS \
6428     (SWP_NOSIZE | \
6429     SWP_NOMOVE | \
6430     SWP_NOZORDER | \
6431     SWP_NOREDRAW | \
6432     SWP_NOACTIVATE | \
6433     SWP_FRAMECHANGED | \
6434     SWP_SHOWWINDOW | \
6435     SWP_HIDEWINDOW | \
6436     SWP_NOCOPYBITS | \
6437     SWP_NOOWNERZORDER | \
6438     SWP_NOSENDCHANGING | \
6439     SWP_DEFERERASE | \
6440     SWP_ASYNCWINDOWPOS | \
6441     SWP_NOCLIENTSIZE | \
6442     SWP_NOCLIENTMOVE)
6443
6444     if(flags & ~DUMPED_FLAGS) printf("|0x%04x", flags & ~DUMPED_FLAGS);
6445     printf("\n");
6446 #undef DUMPED_FLAGS
6447 }
6448
6449 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6450 {
6451     static long defwndproc_counter = 0;
6452     LRESULT ret;
6453     struct message msg;
6454
6455     /* log only specific messages we are interested in */
6456     switch (message)
6457     {
6458 #if 0 /* probably log these as well */
6459     case WM_ACTIVATE:
6460     case WM_SETFOCUS:
6461     case WM_KILLFOCUS:
6462 #endif
6463     case WM_SHOWWINDOW:
6464         trace("WM_SHOWWINDOW %ld\n", wParam);
6465         break;
6466     case WM_SIZE:
6467         trace("WM_SIZE %ld\n", wParam);
6468         break;
6469     case WM_MOVE:
6470         trace("WM_MOVE\n");
6471         break;
6472     case WM_GETMINMAXINFO:
6473         trace("WM_GETMINMAXINFO\n");
6474         break;
6475
6476     case WM_WINDOWPOSCHANGING:
6477     case WM_WINDOWPOSCHANGED:
6478     {
6479         WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6480
6481         trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6482         trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6483               winpos->hwnd, winpos->hwndInsertAfter,
6484               winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6485         trace("flags: ");
6486         dump_winpos_flags(winpos->flags);
6487
6488         /* Log only documented flags, win2k uses 0x1000 and 0x2000
6489          * in the high word for internal purposes
6490          */
6491         wParam = winpos->flags & 0xffff;
6492         /* We are not interested in the flags that don't match under XP and Win9x */
6493         wParam &= ~(SWP_NOZORDER);
6494         break;
6495     }
6496
6497     default: /* ignore */
6498         /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
6499         return DefWindowProcA(hwnd, message, wParam, lParam);
6500     }
6501
6502     msg.message = message;
6503     msg.flags = sent|wparam|lparam;
6504     if (defwndproc_counter) msg.flags |= defwinproc;
6505     msg.wParam = wParam;
6506     msg.lParam = lParam;
6507     add_message(&msg);
6508
6509     defwndproc_counter++;
6510     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6511     defwndproc_counter--;
6512
6513     return ret;
6514 }
6515
6516 static BOOL RegisterWindowClasses(void)
6517 {
6518     WNDCLASSA cls;
6519     WNDCLASSW clsW;
6520
6521     cls.style = 0;
6522     cls.lpfnWndProc = MsgCheckProcA;
6523     cls.cbClsExtra = 0;
6524     cls.cbWndExtra = 0;
6525     cls.hInstance = GetModuleHandleA(0);
6526     cls.hIcon = 0;
6527     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
6528     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6529     cls.lpszMenuName = NULL;
6530     cls.lpszClassName = "TestWindowClass";
6531     if(!RegisterClassA(&cls)) return FALSE;
6532
6533     cls.lpfnWndProc = ShowWindowProcA;
6534     cls.lpszClassName = "ShowWindowClass";
6535     if(!RegisterClassA(&cls)) return FALSE;
6536
6537     cls.lpfnWndProc = PopupMsgCheckProcA;
6538     cls.lpszClassName = "TestPopupClass";
6539     if(!RegisterClassA(&cls)) return FALSE;
6540
6541     cls.lpfnWndProc = ParentMsgCheckProcA;
6542     cls.lpszClassName = "TestParentClass";
6543     if(!RegisterClassA(&cls)) return FALSE;
6544
6545     cls.lpfnWndProc = DefWindowProcA;
6546     cls.lpszClassName = "SimpleWindowClass";
6547     if(!RegisterClassA(&cls)) return FALSE;
6548
6549     cls.style = CS_NOCLOSE;
6550     cls.lpszClassName = "NoCloseWindowClass";
6551     if(!RegisterClassA(&cls)) return FALSE;
6552
6553     ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
6554     cls.style = 0;
6555     cls.hInstance = GetModuleHandleA(0);
6556     cls.hbrBackground = 0;
6557     cls.lpfnWndProc = TestDlgProcA;
6558     cls.lpszClassName = "TestDialogClass";
6559     if(!RegisterClassA(&cls)) return FALSE;
6560
6561     clsW.style = 0;
6562     clsW.lpfnWndProc = MsgCheckProcW;
6563     clsW.cbClsExtra = 0;
6564     clsW.cbWndExtra = 0;
6565     clsW.hInstance = GetModuleHandleW(0);
6566     clsW.hIcon = 0;
6567     clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
6568     clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
6569     clsW.lpszMenuName = NULL;
6570     clsW.lpszClassName = testWindowClassW;
6571     RegisterClassW(&clsW);  /* ignore error, this fails on Win9x */
6572
6573     return TRUE;
6574 }
6575
6576 static HHOOK hCBT_hook;
6577 static DWORD cbt_hook_thread_id;
6578
6579 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
6580
6581     static const char * const CBT_code_name[10] = {
6582         "HCBT_MOVESIZE",
6583         "HCBT_MINMAX",
6584         "HCBT_QS",
6585         "HCBT_CREATEWND",
6586         "HCBT_DESTROYWND",
6587         "HCBT_ACTIVATE",
6588         "HCBT_CLICKSKIPPED",
6589         "HCBT_KEYSKIPPED",
6590         "HCBT_SYSCOMMAND",
6591         "HCBT_SETFOCUS" };
6592     const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
6593     HWND hwnd;
6594     char buf[256];
6595
6596     trace("CBT: %d (%s), %08lx, %08lx\n", nCode, code_name, wParam, lParam);
6597
6598     ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
6599
6600     if (nCode == HCBT_CLICKSKIPPED)
6601     {
6602         /* ignore this event, XP sends it a lot when switching focus between windows */
6603         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
6604     }
6605
6606     if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
6607     {
6608         struct message msg;
6609
6610         msg.message = nCode;
6611         msg.flags = hook|wparam|lparam;
6612         msg.wParam = wParam;
6613         msg.lParam = lParam;
6614         add_message(&msg);
6615
6616         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
6617     }
6618
6619     if (nCode == HCBT_DESTROYWND)
6620     {
6621         if (test_DestroyWindow_flag)
6622         {
6623             DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
6624             if (style & WS_CHILD)
6625                 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
6626             else if (style & WS_POPUP)
6627                 lParam = WND_POPUP_ID;
6628             else
6629                 lParam = WND_PARENT_ID;
6630         }
6631     }
6632
6633     /* Log also SetFocus(0) calls */
6634     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
6635
6636     if (GetClassNameA(hwnd, buf, sizeof(buf)))
6637     {
6638         if (!lstrcmpiA(buf, "TestWindowClass") ||
6639             !lstrcmpiA(buf, "ShowWindowClass") ||
6640             !lstrcmpiA(buf, "TestParentClass") ||
6641             !lstrcmpiA(buf, "TestPopupClass") ||
6642             !lstrcmpiA(buf, "SimpleWindowClass") ||
6643             !lstrcmpiA(buf, "TestDialogClass") ||
6644             !lstrcmpiA(buf, "MDI_frame_class") ||
6645             !lstrcmpiA(buf, "MDI_client_class") ||
6646             !lstrcmpiA(buf, "MDI_child_class") ||
6647             !lstrcmpiA(buf, "my_button_class") ||
6648             !lstrcmpiA(buf, "my_edit_class") ||
6649             !lstrcmpiA(buf, "static") ||
6650             !lstrcmpiA(buf, "ListBox") ||
6651             !lstrcmpiA(buf, "MyDialogClass") ||
6652             !lstrcmpiA(buf, "#32770"))
6653         {
6654             struct message msg;
6655
6656             msg.message = nCode;
6657             msg.flags = hook|wparam|lparam;
6658             msg.wParam = wParam;
6659             msg.lParam = lParam;
6660             add_message(&msg);
6661         }
6662     }
6663     return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
6664 }
6665
6666 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
6667                                     DWORD event,
6668                                     HWND hwnd,
6669                                     LONG object_id,
6670                                     LONG child_id,
6671                                     DWORD thread_id,
6672                                     DWORD event_time)
6673 {
6674     char buf[256];
6675
6676     trace("WEH:%p,event %08x,hwnd %p,obj %08x,id %08x,thread %08x,time %08x\n",
6677            hevent, event, hwnd, object_id, child_id, thread_id, event_time);
6678
6679     ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
6680
6681     /* ignore mouse cursor events */
6682     if (object_id == OBJID_CURSOR) return;
6683
6684     if (!hwnd || GetClassNameA(hwnd, buf, sizeof(buf)))
6685     {
6686         if (!hwnd ||
6687             !lstrcmpiA(buf, "TestWindowClass") ||
6688             !lstrcmpiA(buf, "TestParentClass") ||
6689             !lstrcmpiA(buf, "TestPopupClass") ||
6690             !lstrcmpiA(buf, "SimpleWindowClass") ||
6691             !lstrcmpiA(buf, "TestDialogClass") ||
6692             !lstrcmpiA(buf, "MDI_frame_class") ||
6693             !lstrcmpiA(buf, "MDI_client_class") ||
6694             !lstrcmpiA(buf, "MDI_child_class") ||
6695             !lstrcmpiA(buf, "my_button_class") ||
6696             !lstrcmpiA(buf, "my_edit_class") ||
6697             !lstrcmpiA(buf, "static") ||
6698             !lstrcmpiA(buf, "ListBox") ||
6699             !lstrcmpiA(buf, "MyDialogClass") ||
6700             !lstrcmpiA(buf, "#32770"))
6701         {
6702             struct message msg;
6703
6704             msg.message = event;
6705             msg.flags = winevent_hook|wparam|lparam;
6706             msg.wParam = object_id;
6707             msg.lParam = child_id;
6708             add_message(&msg);
6709         }
6710     }
6711 }
6712
6713 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
6714 static const WCHAR wszAnsi[] = {'U',0};
6715
6716 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6717 {
6718     switch (uMsg)
6719     {
6720     case CB_FINDSTRINGEXACT:
6721         trace("String: %p\n", (LPCWSTR)lParam);
6722         if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
6723             return 1;
6724         if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
6725             return 0;
6726         return -1;
6727     }
6728     return DefWindowProcW(hwnd, uMsg, wParam, lParam);
6729 }
6730
6731 static const struct message WmGetTextLengthAfromW[] = {
6732     { WM_GETTEXTLENGTH, sent },
6733     { WM_GETTEXT, sent },
6734     { 0 }
6735 };
6736
6737 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
6738
6739 /* dummy window proc for WM_GETTEXTLENGTH test */
6740 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
6741 {
6742     switch(msg)
6743     {
6744     case WM_GETTEXTLENGTH:
6745         return lstrlenW(dummy_window_text) + 37;  /* some random length */
6746     case WM_GETTEXT:
6747         lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
6748         return lstrlenW( (LPWSTR)lp );
6749     default:
6750         return DefWindowProcW( hwnd, msg, wp, lp );
6751     }
6752 }
6753
6754 static void test_message_conversion(void)
6755 {
6756     static const WCHAR wszMsgConversionClass[] =
6757         {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
6758     WNDCLASSW cls;
6759     LRESULT lRes;
6760     HWND hwnd;
6761     WNDPROC wndproc, newproc;
6762     BOOL ret;
6763
6764     cls.style = 0;
6765     cls.lpfnWndProc = MsgConversionProcW;
6766     cls.cbClsExtra = 0;
6767     cls.cbWndExtra = 0;
6768     cls.hInstance = GetModuleHandleW(NULL);
6769     cls.hIcon = NULL;
6770     cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
6771     cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
6772     cls.lpszMenuName = NULL;
6773     cls.lpszClassName = wszMsgConversionClass;
6774     /* this call will fail on Win9x, but that doesn't matter as this test is
6775      * meaningless on those platforms */
6776     if(!RegisterClassW(&cls)) return;
6777
6778     hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
6779                            100, 100, 200, 200, 0, 0, 0, NULL);
6780     ok(hwnd != NULL, "Window creation failed\n");
6781
6782     /* {W, A} -> A */
6783
6784     wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
6785     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6786     ok(lRes == 0, "String should have been converted\n");
6787     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6788     ok(lRes == 1, "String shouldn't have been converted\n");
6789
6790     /* {W, A} -> W */
6791
6792     wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
6793     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6794     ok(lRes == 1, "String shouldn't have been converted\n");
6795     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6796     ok(lRes == 1, "String shouldn't have been converted\n");
6797
6798     /* Synchronous messages */
6799
6800     lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6801     ok(lRes == 0, "String should have been converted\n");
6802     lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6803     ok(lRes == 1, "String shouldn't have been converted\n");
6804
6805     /* Asynchronous messages */
6806
6807     SetLastError(0);
6808     lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6809     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6810         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6811     SetLastError(0);
6812     lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6813     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6814         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6815     SetLastError(0);
6816     lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6817     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6818         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6819     SetLastError(0);
6820     lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6821     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6822         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6823     SetLastError(0);
6824     lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6825     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6826         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6827     SetLastError(0);
6828     lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6829     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6830         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6831     SetLastError(0);
6832     lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
6833     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6834         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6835     SetLastError(0);
6836     lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
6837     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6838         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6839
6840     /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
6841
6842     hwnd = CreateWindowW (testWindowClassW, wszUnicode,
6843                           WS_OVERLAPPEDWINDOW,
6844                           100, 100, 200, 200, 0, 0, 0, NULL);
6845     assert(hwnd);
6846     flush_sequence();
6847     lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
6848     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
6849     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
6850         "got bad length %ld\n", lRes );
6851
6852     flush_sequence();
6853     lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
6854                             hwnd, WM_GETTEXTLENGTH, 0, 0);
6855     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
6856     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
6857         "got bad length %ld\n", lRes );
6858
6859     wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
6860     newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
6861     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
6862     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
6863                                      NULL, 0, NULL, NULL ),
6864         "got bad length %ld\n", lRes );
6865
6866     SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc );  /* restore old wnd proc */
6867     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
6868     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
6869                                      NULL, 0, NULL, NULL ),
6870         "got bad length %ld\n", lRes );
6871
6872     ret = DestroyWindow(hwnd);
6873     ok( ret, "DestroyWindow() error %d\n", GetLastError());
6874 }
6875
6876 struct timer_info
6877 {
6878     HWND hWnd;
6879     HANDLE handles[2];
6880     DWORD id;
6881 };
6882
6883 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
6884 {
6885 }
6886
6887 #define TIMER_ID  0x19
6888
6889 static DWORD WINAPI timer_thread_proc(LPVOID x)
6890 {
6891     struct timer_info *info = x;
6892     DWORD r;
6893
6894     r = KillTimer(info->hWnd, 0x19);
6895     ok(r,"KillTimer failed in thread\n");
6896     r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
6897     ok(r,"SetTimer failed in thread\n");
6898     ok(r==TIMER_ID,"SetTimer id different\n");
6899     r = SetEvent(info->handles[0]);
6900     ok(r,"SetEvent failed in thread\n");
6901     return 0;
6902 }
6903
6904 static void test_timers(void)
6905 {
6906     struct timer_info info;
6907     DWORD id;
6908
6909     info.hWnd = CreateWindow ("TestWindowClass", NULL,
6910        WS_OVERLAPPEDWINDOW ,
6911        CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
6912        NULL, NULL, 0);
6913
6914     info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
6915     ok(info.id, "SetTimer failed\n");
6916     ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
6917     info.handles[0] = CreateEvent(NULL,0,0,NULL);
6918     info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
6919
6920     WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
6921
6922     WaitForSingleObject(info.handles[1], INFINITE);
6923
6924     CloseHandle(info.handles[0]);
6925     CloseHandle(info.handles[1]);
6926
6927     ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
6928
6929     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
6930 }
6931
6932 static int count = 0;
6933 static VOID CALLBACK callback_count(
6934     HWND hwnd,
6935     UINT uMsg,
6936     UINT_PTR idEvent,
6937     DWORD dwTime
6938 )
6939 {
6940     count++;
6941 }
6942
6943 static void test_timers_no_wnd(void)
6944 {
6945     UINT_PTR id, id2;
6946     MSG msg;
6947
6948     count = 0;
6949     id = SetTimer(NULL, 0, 100, callback_count);
6950     ok(id != 0, "did not get id from SetTimer.\n");
6951     id2 = SetTimer(NULL, id, 200, callback_count);
6952     ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
6953     Sleep(150);
6954     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6955     ok(count == 0, "did not get zero count as expected (%i).\n", count);
6956     Sleep(150);
6957     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6958     ok(count == 1, "did not get one count as expected (%i).\n", count);
6959     KillTimer(NULL, id);
6960     Sleep(250);
6961     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6962     ok(count == 1, "killing replaced timer did not work (%i).\n", count);
6963 }
6964
6965 /* Various win events with arbitrary parameters */
6966 static const struct message WmWinEventsSeq[] = {
6967     { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
6968     { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6969     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
6970     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
6971     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
6972     { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
6973     { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
6974     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
6975     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
6976     /* our win event hook ignores OBJID_CURSOR events */
6977     /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
6978     { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
6979     { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
6980     { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
6981     { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
6982     { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
6983     { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6984     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
6985     { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
6986     { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
6987     { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
6988     { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
6989     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
6990     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
6991     { 0 }
6992 };
6993 static const struct message WmWinEventCaretSeq[] = {
6994     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
6995     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
6996     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
6997     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
6998     { 0 }
6999 };
7000 static const struct message WmWinEventCaretSeq_2[] = {
7001     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7002     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7003     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7004     { 0 }
7005 };
7006 static const struct message WmWinEventAlertSeq[] = {
7007     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
7008     { 0 }
7009 };
7010 static const struct message WmWinEventAlertSeq_2[] = {
7011     /* create window in the thread proc */
7012     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
7013     /* our test event */
7014     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
7015     { 0 }
7016 };
7017 static const struct message WmGlobalHookSeq_1[] = {
7018     /* create window in the thread proc */
7019     { HCBT_CREATEWND, hook|lparam, 0, 2 },
7020     /* our test events */
7021     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
7022     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
7023     { 0 }
7024 };
7025 static const struct message WmGlobalHookSeq_2[] = {
7026     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
7027     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
7028     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
7029     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
7030     { 0 }
7031 };
7032
7033 static const struct message WmMouseLLHookSeq[] = {
7034     { WM_MOUSEMOVE, hook },
7035     { WM_LBUTTONUP, hook },
7036     { WM_MOUSEMOVE, hook },
7037     { 0 }
7038 };
7039
7040 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
7041                                          DWORD event,
7042                                          HWND hwnd,
7043                                          LONG object_id,
7044                                          LONG child_id,
7045                                          DWORD thread_id,
7046                                          DWORD event_time)
7047 {
7048     char buf[256];
7049
7050     trace("WEH_2:%p,event %08x,hwnd %p,obj %08x,id %08x,thread %08x,time %08x\n",
7051            hevent, event, hwnd, object_id, child_id, thread_id, event_time);
7052
7053     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7054     {
7055         if (!lstrcmpiA(buf, "TestWindowClass") ||
7056             !lstrcmpiA(buf, "static"))
7057         {
7058             struct message msg;
7059
7060             msg.message = event;
7061             msg.flags = winevent_hook|wparam|lparam;
7062             msg.wParam = object_id;
7063             msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
7064             add_message(&msg);
7065         }
7066     }
7067 }
7068
7069 static HHOOK hCBT_global_hook;
7070 static DWORD cbt_global_hook_thread_id;
7071
7072 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7073
7074     HWND hwnd;
7075     char buf[256];
7076
7077     trace("CBT_2: %d, %08lx, %08lx\n", nCode, wParam, lParam);
7078
7079     if (nCode == HCBT_SYSCOMMAND)
7080     {
7081         struct message msg;
7082
7083         msg.message = nCode;
7084         msg.flags = hook|wparam|lparam;
7085         msg.wParam = wParam;
7086         msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7087         add_message(&msg);
7088
7089         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7090     }
7091     /* WH_MOUSE_LL hook */
7092     if (nCode == HC_ACTION)
7093     {
7094         struct message msg;
7095         MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
7096
7097         /* we can't test for real mouse events */
7098         if (mhll->flags & LLMHF_INJECTED)
7099         {
7100             msg.message = wParam;
7101             msg.flags = hook;
7102             add_message(&msg);
7103         }
7104         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7105     }
7106
7107     /* Log also SetFocus(0) calls */
7108     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7109
7110     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7111     {
7112         if (!lstrcmpiA(buf, "TestWindowClass") ||
7113             !lstrcmpiA(buf, "static"))
7114         {
7115             struct message msg;
7116
7117             msg.message = nCode;
7118             msg.flags = hook|wparam|lparam;
7119             msg.wParam = wParam;
7120             msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7121             add_message(&msg);
7122         }
7123     }
7124     return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7125 }
7126
7127 static DWORD WINAPI win_event_global_thread_proc(void *param)
7128 {
7129     HWND hwnd;
7130     MSG msg;
7131     HANDLE hevent = *(HANDLE *)param;
7132
7133     assert(pNotifyWinEvent);
7134
7135     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7136     assert(hwnd);
7137     trace("created thread window %p\n", hwnd);
7138
7139     *(HWND *)param = hwnd;
7140
7141     flush_sequence();
7142     /* this event should be received only by our new hook proc,
7143      * an old one does not expect an event from another thread.
7144      */
7145     pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
7146     SetEvent(hevent);
7147
7148     while (GetMessage(&msg, 0, 0, 0))
7149     {
7150         TranslateMessage(&msg);
7151         DispatchMessage(&msg);
7152     }
7153     return 0;
7154 }
7155
7156 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
7157 {
7158     HWND hwnd;
7159     MSG msg;
7160     HANDLE hevent = *(HANDLE *)param;
7161
7162     flush_sequence();
7163     /* these events should be received only by our new hook proc,
7164      * an old one does not expect an event from another thread.
7165      */
7166
7167     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7168     assert(hwnd);
7169     trace("created thread window %p\n", hwnd);
7170
7171     *(HWND *)param = hwnd;
7172
7173     /* Windows doesn't like when a thread plays games with the focus,
7174        that leads to all kinds of misbehaviours and failures to activate
7175        a window. So, better keep next lines commented out.
7176     SetFocus(0);
7177     SetFocus(hwnd);*/
7178
7179     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7180     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7181
7182     SetEvent(hevent);
7183
7184     while (GetMessage(&msg, 0, 0, 0))
7185     {
7186         TranslateMessage(&msg);
7187         DispatchMessage(&msg);
7188     }
7189     return 0;
7190 }
7191
7192 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
7193 {
7194     HWND hwnd;
7195     MSG msg;
7196     HANDLE hevent = *(HANDLE *)param;
7197
7198     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7199     assert(hwnd);
7200     trace("created thread window %p\n", hwnd);
7201
7202     *(HWND *)param = hwnd;
7203
7204     flush_sequence();
7205
7206     /* Windows doesn't like when a thread plays games with the focus,
7207      * that leads to all kinds of misbehaviours and failures to activate
7208      * a window. So, better don't generate a mouse click message below.
7209      */
7210     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7211     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7212     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7213
7214     SetEvent(hevent);
7215     while (GetMessage(&msg, 0, 0, 0))
7216     {
7217         TranslateMessage(&msg);
7218         DispatchMessage(&msg);
7219     }
7220     return 0;
7221 }
7222
7223 static void test_winevents(void)
7224 {
7225     BOOL ret;
7226     MSG msg;
7227     HWND hwnd, hwnd2;
7228     UINT i;
7229     HANDLE hthread, hevent;
7230     DWORD tid;
7231     HWINEVENTHOOK hhook;
7232     const struct message *events = WmWinEventsSeq;
7233
7234     hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
7235                            WS_OVERLAPPEDWINDOW,
7236                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7237                            NULL, NULL, 0);
7238     assert(hwnd);
7239
7240     /****** start of global hook test *************/
7241     hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7242     assert(hCBT_global_hook);
7243
7244     hevent = CreateEventA(NULL, 0, 0, NULL);
7245     assert(hevent);
7246     hwnd2 = (HWND)hevent;
7247
7248     hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
7249     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7250
7251     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7252
7253     ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
7254
7255     flush_sequence();
7256     /* this one should be received only by old hook proc */
7257     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7258     /* this one should be received only by old hook proc */
7259     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7260
7261     ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
7262
7263     ret = UnhookWindowsHookEx(hCBT_global_hook);
7264     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7265
7266     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7267     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7268     CloseHandle(hthread);
7269     CloseHandle(hevent);
7270     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7271     /****** end of global hook test *************/
7272
7273     if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
7274     {
7275         ok(DestroyWindow(hwnd), "failed to destroy window\n");
7276         return;
7277     }
7278
7279     flush_sequence();
7280
7281     if (0)
7282     {
7283     /* this test doesn't pass under Win9x */
7284     /* win2k ignores events with hwnd == 0 */
7285     SetLastError(0xdeadbeef);
7286     pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
7287     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
7288        GetLastError() == 0xdeadbeef, /* Win9x */
7289        "unexpected error %d\n", GetLastError());
7290     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7291     }
7292
7293     for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
7294         pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
7295
7296     ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
7297
7298     /****** start of event filtering test *************/
7299     hhook = (HWINEVENTHOOK)pSetWinEventHook(
7300         EVENT_OBJECT_SHOW, /* 0x8002 */
7301         EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
7302         GetModuleHandleA(0), win_event_global_hook_proc,
7303         GetCurrentProcessId(), 0,
7304         WINEVENT_INCONTEXT);
7305     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7306
7307     hevent = CreateEventA(NULL, 0, 0, NULL);
7308     assert(hevent);
7309     hwnd2 = (HWND)hevent;
7310
7311     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7312     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7313
7314     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7315
7316     ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
7317
7318     flush_sequence();
7319     /* this one should be received only by old hook proc */
7320     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7321     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7322     /* this one should be received only by old hook proc */
7323     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7324
7325     ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
7326
7327     ret = pUnhookWinEvent(hhook);
7328     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7329
7330     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7331     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7332     CloseHandle(hthread);
7333     CloseHandle(hevent);
7334     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7335     /****** end of event filtering test *************/
7336
7337     /****** start of out of context event test *************/
7338     hhook = (HWINEVENTHOOK)pSetWinEventHook(
7339         EVENT_MIN, EVENT_MAX,
7340         0, win_event_global_hook_proc,
7341         GetCurrentProcessId(), 0,
7342         WINEVENT_OUTOFCONTEXT);
7343     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7344
7345     hevent = CreateEventA(NULL, 0, 0, NULL);
7346     assert(hevent);
7347     hwnd2 = (HWND)hevent;
7348
7349     flush_sequence();
7350
7351     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7352     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7353
7354     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7355
7356     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7357     /* process pending winevent messages */
7358     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7359     ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
7360
7361     flush_sequence();
7362     /* this one should be received only by old hook proc */
7363     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7364     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7365     /* this one should be received only by old hook proc */
7366     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7367
7368     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
7369     /* process pending winevent messages */
7370     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7371     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
7372
7373     ret = pUnhookWinEvent(hhook);
7374     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7375
7376     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7377     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7378     CloseHandle(hthread);
7379     CloseHandle(hevent);
7380     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7381     /****** end of out of context event test *************/
7382
7383     /****** start of MOUSE_LL hook test *************/
7384     hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7385     /* WH_MOUSE_LL is not supported on Win9x platforms */
7386     if (!hCBT_global_hook)
7387     {
7388         trace("Skipping WH_MOUSE_LL test on this platform\n");
7389         goto skip_mouse_ll_hook_test;
7390     }
7391
7392     hevent = CreateEventA(NULL, 0, 0, NULL);
7393     assert(hevent);
7394     hwnd2 = (HWND)hevent;
7395
7396     hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
7397     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7398
7399     while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
7400         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
7401
7402     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
7403     flush_sequence();
7404
7405     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7406     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7407     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7408
7409     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
7410
7411     ret = UnhookWindowsHookEx(hCBT_global_hook);
7412     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7413
7414     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7415     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7416     CloseHandle(hthread);
7417     CloseHandle(hevent);
7418     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7419     /****** end of MOUSE_LL hook test *************/
7420 skip_mouse_ll_hook_test:
7421
7422     ok(DestroyWindow(hwnd), "failed to destroy window\n");
7423 }
7424
7425 static void test_set_hook(void)
7426 {
7427     BOOL ret;
7428     HHOOK hhook;
7429     HWINEVENTHOOK hwinevent_hook;
7430
7431     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
7432     ok(hhook != 0, "local hook does not require hModule set to 0\n");
7433     UnhookWindowsHookEx(hhook);
7434
7435     if (0)
7436     {
7437     /* this test doesn't pass under Win9x: BUG! */
7438     SetLastError(0xdeadbeef);
7439     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
7440     ok(!hhook, "global hook requires hModule != 0\n");
7441     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
7442     }
7443
7444     SetLastError(0xdeadbeef);
7445     hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
7446     ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
7447     ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
7448        GetLastError() == 0xdeadbeef, /* Win9x */
7449        "unexpected error %d\n", GetLastError());
7450
7451     SetLastError(0xdeadbeef);
7452     ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
7453     ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
7454        GetLastError() == 0xdeadbeef, /* Win9x */
7455        "unexpected error %d\n", GetLastError());
7456
7457     if (!pSetWinEventHook || !pUnhookWinEvent) return;
7458
7459     /* even process local incontext hooks require hmodule */
7460     SetLastError(0xdeadbeef);
7461     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7462         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
7463     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
7464     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
7465        GetLastError() == 0xdeadbeef, /* Win9x */
7466        "unexpected error %d\n", GetLastError());
7467
7468     /* even thread local incontext hooks require hmodule */
7469     SetLastError(0xdeadbeef);
7470     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7471         0, win_event_proc, GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
7472     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
7473     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
7474        GetLastError() == 0xdeadbeef, /* Win9x */
7475        "unexpected error %d\n", GetLastError());
7476
7477     if (0)
7478     {
7479     /* these 3 tests don't pass under Win9x */
7480     SetLastError(0xdeadbeef);
7481     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(1, 0,
7482         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7483     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
7484     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
7485
7486     SetLastError(0xdeadbeef);
7487     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(-1, 1,
7488         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7489     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
7490     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
7491
7492     SetLastError(0xdeadbeef);
7493     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7494         0, win_event_proc, 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
7495     ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
7496     ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
7497     }
7498
7499     SetLastError(0xdeadbeef);
7500     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(0, 0,
7501         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7502     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
7503     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
7504     ret = pUnhookWinEvent(hwinevent_hook);
7505     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7506
7507 todo_wine {
7508     /* This call succeeds under win2k SP4, but fails under Wine.
7509        Does win2k test/use passed process id? */
7510     SetLastError(0xdeadbeef);
7511     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7512         0, win_event_proc, 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
7513     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
7514     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
7515     ret = pUnhookWinEvent(hwinevent_hook);
7516     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7517 }
7518
7519     SetLastError(0xdeadbeef);
7520     ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
7521     ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
7522         GetLastError() == 0xdeadbeef, /* Win9x */
7523         "unexpected error %d\n", GetLastError());
7524 }
7525
7526 static const struct message ScrollWindowPaint1[] = {
7527     { WM_PAINT, sent },
7528     { WM_ERASEBKGND, sent|beginpaint },
7529     { 0 }
7530 };
7531
7532 static const struct message ScrollWindowPaint2[] = {
7533     { WM_PAINT, sent },
7534     { 0 }
7535 };
7536
7537 static void test_scrollwindowex(void)
7538 {
7539     HWND hwnd, hchild;
7540     RECT rect={0,0,130,130};
7541
7542     hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
7543             WS_VISIBLE|WS_OVERLAPPEDWINDOW,
7544             100, 100, 200, 200, 0, 0, 0, NULL);
7545     ok (hwnd != 0, "Failed to create overlapped window\n");
7546     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", 
7547             WS_VISIBLE|WS_CAPTION|WS_CHILD,
7548             10, 10, 150, 150, hwnd, 0, 0, NULL);
7549     ok (hchild != 0, "Failed to create child\n");
7550     UpdateWindow(hwnd);
7551     flush_events();
7552     flush_sequence();
7553
7554     /* scroll without the child window */
7555     trace("start scroll\n");
7556     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
7557             SW_ERASE|SW_INVALIDATE);
7558     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7559     trace("end scroll\n");
7560     flush_sequence();
7561     flush_events();
7562     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
7563     flush_events();
7564     flush_sequence();
7565
7566     /* Now without the SW_ERASE flag */
7567     trace("start scroll\n");
7568     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
7569     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7570     trace("end scroll\n");
7571     flush_sequence();
7572     flush_events();
7573     ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
7574     flush_events();
7575     flush_sequence();
7576
7577     /* now scroll the child window as well */
7578     trace("start scroll\n");
7579     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
7580             SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
7581     todo_wine { /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
7582                 /* windows sometimes a WM_MOVE */
7583         ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7584     }
7585     trace("end scroll\n");
7586     flush_sequence();
7587     flush_events();
7588     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
7589     flush_events();
7590     flush_sequence();
7591
7592     /* now scroll with ScrollWindow() */
7593     trace("start scroll with ScrollWindow\n");
7594     ScrollWindow( hwnd, 5, 5, NULL, NULL);
7595     trace("end scroll\n");
7596     flush_sequence();
7597     flush_events();
7598     ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
7599
7600     ok(DestroyWindow(hchild), "failed to destroy window\n");
7601     ok(DestroyWindow(hwnd), "failed to destroy window\n");
7602     flush_sequence();
7603 }
7604
7605 static const struct message destroy_window_with_children[] = {
7606     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
7607     { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
7608     { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
7609     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
7610     { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7611     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7612     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7613     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
7614     { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
7615     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
7616     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
7617     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
7618     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
7619     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
7620     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
7621     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
7622     { 0 }
7623 };
7624
7625 static void test_DestroyWindow(void)
7626 {
7627     BOOL ret;
7628     HWND parent, child1, child2, child3, child4, test;
7629     UINT child_id = WND_CHILD_ID + 1;
7630
7631     parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
7632                              100, 100, 200, 200, 0, 0, 0, NULL);
7633     assert(parent != 0);
7634     child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7635                              0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
7636     assert(child1 != 0);
7637     child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7638                              0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
7639     assert(child2 != 0);
7640     child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7641                              0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
7642     assert(child3 != 0);
7643     child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
7644                              0, 0, 50, 50, parent, 0, 0, NULL);
7645     assert(child4 != 0);
7646
7647     /* test owner/parent of child2 */
7648     test = GetParent(child2);
7649     ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7650     ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
7651     if(pGetAncestor) {
7652         test = pGetAncestor(child2, GA_PARENT);
7653         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7654     }
7655     test = GetWindow(child2, GW_OWNER);
7656     ok(!test, "wrong owner %p\n", test);
7657
7658     test = SetParent(child2, parent);
7659     ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
7660
7661     /* test owner/parent of the parent */
7662     test = GetParent(parent);
7663     ok(!test, "wrong parent %p\n", test);
7664     ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
7665     if(pGetAncestor) {
7666         test = pGetAncestor(parent, GA_PARENT);
7667         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7668     }
7669     test = GetWindow(parent, GW_OWNER);
7670     ok(!test, "wrong owner %p\n", test);
7671
7672     /* test owner/parent of child1 */
7673     test = GetParent(child1);
7674     ok(test == parent, "wrong parent %p\n", test);
7675     ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
7676     if(pGetAncestor) {
7677         test = pGetAncestor(child1, GA_PARENT);
7678         ok(test == parent, "wrong parent %p\n", test);
7679     }
7680     test = GetWindow(child1, GW_OWNER);
7681     ok(!test, "wrong owner %p\n", test);
7682
7683     /* test owner/parent of child2 */
7684     test = GetParent(child2);
7685     ok(test == parent, "wrong parent %p\n", test);
7686     ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
7687     if(pGetAncestor) {
7688         test = pGetAncestor(child2, GA_PARENT);
7689         ok(test == parent, "wrong parent %p\n", test);
7690     }
7691     test = GetWindow(child2, GW_OWNER);
7692     ok(!test, "wrong owner %p\n", test);
7693
7694     /* test owner/parent of child3 */
7695     test = GetParent(child3);
7696     ok(test == child1, "wrong parent %p\n", test);
7697     ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
7698     if(pGetAncestor) {
7699         test = pGetAncestor(child3, GA_PARENT);
7700         ok(test == child1, "wrong parent %p\n", test);
7701     }
7702     test = GetWindow(child3, GW_OWNER);
7703     ok(!test, "wrong owner %p\n", test);
7704
7705     /* test owner/parent of child4 */
7706     test = GetParent(child4);
7707     ok(test == parent, "wrong parent %p\n", test);
7708     ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
7709     if(pGetAncestor) {
7710         test = pGetAncestor(child4, GA_PARENT);
7711         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7712     }
7713     test = GetWindow(child4, GW_OWNER);
7714     ok(test == parent, "wrong owner %p\n", test);
7715
7716     flush_sequence();
7717
7718     trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
7719            parent, child1, child2, child3, child4);
7720
7721     SetCapture(child4);
7722     test = GetCapture();
7723     ok(test == child4, "wrong capture window %p\n", test);
7724
7725     test_DestroyWindow_flag = TRUE;
7726     ret = DestroyWindow(parent);
7727     ok( ret, "DestroyWindow() error %d\n", GetLastError());
7728     test_DestroyWindow_flag = FALSE;
7729     ok_sequence(destroy_window_with_children, "destroy window with children", 0);
7730
7731     ok(!IsWindow(parent), "parent still exists\n");
7732     ok(!IsWindow(child1), "child1 still exists\n");
7733     ok(!IsWindow(child2), "child2 still exists\n");
7734     ok(!IsWindow(child3), "child3 still exists\n");
7735     ok(!IsWindow(child4), "child4 still exists\n");
7736
7737     test = GetCapture();
7738     ok(!test, "wrong capture window %p\n", test);
7739 }
7740
7741
7742 static const struct message WmDispatchPaint[] = {
7743     { WM_NCPAINT, sent },
7744     { WM_GETTEXT, sent|defwinproc|optional },
7745     { WM_GETTEXT, sent|defwinproc|optional },
7746     { WM_ERASEBKGND, sent },
7747     { 0 }
7748 };
7749
7750 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7751 {
7752     if (message == WM_PAINT) return 0;
7753     return MsgCheckProcA( hwnd, message, wParam, lParam );
7754 }
7755
7756 static void test_DispatchMessage(void)
7757 {
7758     RECT rect;
7759     MSG msg;
7760     int count;
7761     HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
7762                                100, 100, 200, 200, 0, 0, 0, NULL);
7763     ShowWindow( hwnd, SW_SHOW );
7764     UpdateWindow( hwnd );
7765     flush_events();
7766     flush_sequence();
7767     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
7768
7769     SetRect( &rect, -5, -5, 5, 5 );
7770     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
7771     count = 0;
7772     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
7773     {
7774         if (msg.message != WM_PAINT) DispatchMessage( &msg );
7775         else
7776         {
7777             flush_sequence();
7778             DispatchMessage( &msg );
7779             /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
7780             if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
7781             else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
7782             if (++count > 10) break;
7783         }
7784     }
7785     ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
7786
7787     trace("now without DispatchMessage\n");
7788     flush_sequence();
7789     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
7790     count = 0;
7791     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
7792     {
7793         if (msg.message != WM_PAINT) DispatchMessage( &msg );
7794         else
7795         {
7796             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
7797             flush_sequence();
7798             /* this will send WM_NCCPAINT just like DispatchMessage does */
7799             GetUpdateRgn( hwnd, hrgn, TRUE );
7800             ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
7801             DeleteObject( hrgn );
7802             GetClientRect( hwnd, &rect );
7803             ValidateRect( hwnd, &rect );  /* this will stop WM_PAINTs */
7804             ok( !count, "Got multiple WM_PAINTs\n" );
7805             if (++count > 10) break;
7806         }
7807     }
7808     DestroyWindow(hwnd);
7809 }
7810
7811
7812 static const struct message WmUser[] = {
7813     { WM_USER, sent },
7814     { 0 }
7815 };
7816
7817 struct sendmsg_info
7818 {
7819     HWND  hwnd;
7820     DWORD timeout;
7821     DWORD ret;
7822 };
7823
7824 static DWORD CALLBACK send_msg_thread( LPVOID arg )
7825 {
7826     struct sendmsg_info *info = arg;
7827     info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
7828     if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT, "unexpected error %d\n", GetLastError());
7829     return 0;
7830 }
7831
7832 static void wait_for_thread( HANDLE thread )
7833 {
7834     while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
7835     {
7836         MSG msg;
7837         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
7838     }
7839 }
7840
7841 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7842 {
7843     if (message == WM_USER) Sleep(200);
7844     return MsgCheckProcA( hwnd, message, wParam, lParam );
7845 }
7846
7847 static void test_SendMessageTimeout(void)
7848 {
7849     HANDLE thread;
7850     struct sendmsg_info info;
7851     DWORD tid;
7852
7853     info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
7854                                100, 100, 200, 200, 0, 0, 0, NULL);
7855     flush_events();
7856     flush_sequence();
7857
7858     info.timeout = 1000;
7859     info.ret = 0xdeadbeef;
7860     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7861     wait_for_thread( thread );
7862     CloseHandle( thread );
7863     ok( info.ret == 1, "SendMessageTimeout failed\n" );
7864     ok_sequence( WmUser, "WmUser", FALSE );
7865
7866     info.timeout = 1;
7867     info.ret = 0xdeadbeef;
7868     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7869     Sleep(100);  /* SendMessageTimeout should time out here */
7870     wait_for_thread( thread );
7871     CloseHandle( thread );
7872     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
7873     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
7874
7875     /* 0 means infinite timeout */
7876     info.timeout = 0;
7877     info.ret = 0xdeadbeef;
7878     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7879     Sleep(100);
7880     wait_for_thread( thread );
7881     CloseHandle( thread );
7882     ok( info.ret == 1, "SendMessageTimeout failed\n" );
7883     ok_sequence( WmUser, "WmUser", FALSE );
7884
7885     /* timeout is treated as signed despite the prototype */
7886     info.timeout = 0x7fffffff;
7887     info.ret = 0xdeadbeef;
7888     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7889     Sleep(100);
7890     wait_for_thread( thread );
7891     CloseHandle( thread );
7892     ok( info.ret == 1, "SendMessageTimeout failed\n" );
7893     ok_sequence( WmUser, "WmUser", FALSE );
7894
7895     info.timeout = 0x80000000;
7896     info.ret = 0xdeadbeef;
7897     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7898     Sleep(100);
7899     wait_for_thread( thread );
7900     CloseHandle( thread );
7901     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
7902     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
7903
7904     /* now check for timeout during message processing */
7905     SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
7906     info.timeout = 100;
7907     info.ret = 0xdeadbeef;
7908     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7909     wait_for_thread( thread );
7910     CloseHandle( thread );
7911     /* we should time out but still get the message */
7912     ok( info.ret == 0, "SendMessageTimeout failed\n" );
7913     ok_sequence( WmUser, "WmUser", FALSE );
7914
7915     DestroyWindow( info.hwnd );
7916 }
7917
7918
7919 /****************** edit message test *************************/
7920 #define ID_EDIT 0x1234
7921 static const struct message sl_edit_setfocus[] =
7922 {
7923     { HCBT_SETFOCUS, hook },
7924     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
7925     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
7926     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7927     { WM_SETFOCUS, sent|wparam, 0 },
7928     { WM_CTLCOLOREDIT, sent|parent },
7929     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7930     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7931     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
7932     { 0 }
7933 };
7934 static const struct message ml_edit_setfocus[] =
7935 {
7936     { HCBT_SETFOCUS, hook },
7937     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
7938     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
7939     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7940     { WM_SETFOCUS, sent|wparam, 0 },
7941     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7942     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7943     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
7944     { 0 }
7945 };
7946 static const struct message sl_edit_killfocus[] =
7947 {
7948     { HCBT_SETFOCUS, hook },
7949     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7950     { WM_KILLFOCUS, sent|wparam, 0 },
7951     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7952     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7953     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
7954     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
7955     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
7956     { 0 }
7957 };
7958 static const struct message sl_edit_lbutton_dblclk[] =
7959 {
7960     { WM_LBUTTONDBLCLK, sent },
7961     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7962     { 0 }
7963 };
7964 static const struct message sl_edit_lbutton_down[] =
7965 {
7966     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
7967     { HCBT_SETFOCUS, hook },
7968     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
7969     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
7970     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7971     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
7972     { WM_CTLCOLOREDIT, sent|parent },
7973     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7974     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7975     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7976     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
7977     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7978     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7979     { WM_CTLCOLOREDIT, sent|parent|optional },
7980     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7981     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7982     { 0 }
7983 };
7984 static const struct message ml_edit_lbutton_down[] =
7985 {
7986     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
7987     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7988     { HCBT_SETFOCUS, hook },
7989     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
7990     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
7991     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7992     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
7993     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7994     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7995     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
7996     { 0 }
7997 };
7998 static const struct message sl_edit_lbutton_up[] =
7999 {
8000     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8001     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8002     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8003     { WM_CAPTURECHANGED, sent|defwinproc },
8004     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8005     { 0 }
8006 };
8007 static const struct message ml_edit_lbutton_up[] =
8008 {
8009     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8010     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8011     { WM_CAPTURECHANGED, sent|defwinproc },
8012     { 0 }
8013 };
8014
8015 static WNDPROC old_edit_proc;
8016
8017 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8018 {
8019     static long defwndproc_counter = 0;
8020     LRESULT ret;
8021     struct message msg;
8022
8023     trace("edit: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
8024
8025     /* explicitly ignore WM_GETICON message */
8026     if (message == WM_GETICON) return 0;
8027
8028     msg.message = message;
8029     msg.flags = sent|wparam|lparam;
8030     if (defwndproc_counter) msg.flags |= defwinproc;
8031     msg.wParam = wParam;
8032     msg.lParam = lParam;
8033     add_message(&msg);
8034
8035     defwndproc_counter++;
8036     ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
8037     defwndproc_counter--;
8038
8039     return ret;
8040 }
8041
8042 static void subclass_edit(void)
8043 {
8044     WNDCLASSA cls;
8045
8046     if (!GetClassInfoA(0, "edit", &cls)) assert(0);
8047
8048     old_edit_proc = cls.lpfnWndProc;
8049
8050     cls.hInstance = GetModuleHandle(0);
8051     cls.lpfnWndProc = edit_hook_proc;
8052     cls.lpszClassName = "my_edit_class";
8053     UnregisterClass(cls.lpszClassName, cls.hInstance);
8054     if (!RegisterClassA(&cls)) assert(0);
8055 }
8056
8057 static void test_edit_messages(void)
8058 {
8059     HWND hwnd, parent;
8060     DWORD dlg_code;
8061
8062     subclass_edit();
8063     log_all_parent_messages++;
8064
8065     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8066                              100, 100, 200, 200, 0, 0, 0, NULL);
8067     ok (parent != 0, "Failed to create parent window\n");
8068
8069     /* test single line edit */
8070     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
8071                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8072     ok(hwnd != 0, "Failed to create edit window\n");
8073
8074     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8075     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
8076
8077     ShowWindow(hwnd, SW_SHOW);
8078     UpdateWindow(hwnd);
8079     SetFocus(0);
8080     flush_sequence();
8081
8082     SetFocus(hwnd);
8083     ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
8084
8085     SetFocus(0);
8086     ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
8087
8088     SetFocus(0);
8089     ReleaseCapture();
8090     flush_sequence();
8091
8092     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8093     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
8094
8095     SetFocus(0);
8096     ReleaseCapture();
8097     flush_sequence();
8098
8099     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8100     ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
8101
8102     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8103     ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
8104
8105     DestroyWindow(hwnd);
8106
8107     /* test multiline edit */
8108     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
8109                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8110     ok(hwnd != 0, "Failed to create edit window\n");
8111
8112     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8113     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
8114        "wrong dlg_code %08x\n", dlg_code);
8115
8116     ShowWindow(hwnd, SW_SHOW);
8117     UpdateWindow(hwnd);
8118     SetFocus(0);
8119     flush_sequence();
8120
8121     SetFocus(hwnd);
8122     ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
8123
8124     SetFocus(0);
8125     ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
8126
8127     SetFocus(0);
8128     ReleaseCapture();
8129     flush_sequence();
8130
8131     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8132     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
8133
8134     SetFocus(0);
8135     ReleaseCapture();
8136     flush_sequence();
8137
8138     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8139     ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
8140
8141     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8142     ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
8143
8144     DestroyWindow(hwnd);
8145     DestroyWindow(parent);
8146
8147     log_all_parent_messages--;
8148 }
8149
8150 /**************************** End of Edit test ******************************/
8151
8152 static const struct message WmKeyDownSkippedSeq[] =
8153 {
8154     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
8155     { 0 }
8156 };
8157 static const struct message WmKeyUpSkippedSeq[] =
8158 {
8159     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8160     { 0 }
8161 };
8162
8163 #define EV_START_STOP 0
8164 #define EV_SENDMSG 1
8165 #define EV_ACK 2
8166
8167 struct peekmsg_info
8168 {
8169     HWND  hwnd;
8170     HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
8171 };
8172
8173 static DWORD CALLBACK send_msg_thread_2(void *param)
8174 {
8175     DWORD ret;
8176     struct peekmsg_info *info = param;
8177
8178     trace("thread: waiting for start\n");
8179     WaitForSingleObject(info->hevent[EV_START_STOP], INFINITE);
8180     trace("thread: looping\n");
8181
8182     while (1)
8183     {
8184         ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
8185
8186         switch (ret)
8187         {
8188         case WAIT_OBJECT_0 + EV_START_STOP:
8189             trace("thread: exiting\n");
8190             return 0;
8191
8192         case WAIT_OBJECT_0 + EV_SENDMSG:
8193             trace("thread: sending message\n");
8194             SendNotifyMessageA(info->hwnd, WM_USER, 0, 0);
8195             SetEvent(info->hevent[EV_ACK]);
8196             break;
8197
8198         default:
8199             trace("unexpected return: %04x\n", ret);
8200             assert(0);
8201             break;
8202         }
8203     }
8204     return 0;
8205 }
8206
8207 static void test_PeekMessage(void)
8208 {
8209     MSG msg;
8210     HANDLE hthread;
8211     DWORD tid, qstatus;
8212     UINT qs_all_input = QS_ALLINPUT;
8213     UINT qs_input = QS_INPUT;
8214     BOOL ret;
8215     struct peekmsg_info info;
8216
8217     info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8218                               100, 100, 200, 200, 0, 0, 0, NULL);
8219     assert(info.hwnd);
8220     ShowWindow(info.hwnd, SW_SHOW);
8221     UpdateWindow(info.hwnd);
8222     SetFocus(info.hwnd);
8223
8224     info.hevent[EV_START_STOP] = CreateEventA(NULL, 0, 0, NULL);
8225     info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
8226     info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
8227
8228     hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
8229     Sleep(100);
8230
8231     trace("signalling to start looping\n");
8232     SetEvent(info.hevent[EV_START_STOP]);
8233
8234     flush_events();
8235     flush_sequence();
8236
8237     SetLastError(0xdeadbeef);
8238     qstatus = GetQueueStatus(qs_all_input);
8239     if (GetLastError() == ERROR_INVALID_FLAGS)
8240     {
8241         trace("QS_RAWINPUT not supported on this platform\n");
8242         qs_all_input &= ~QS_RAWINPUT;
8243         qs_input &= ~QS_RAWINPUT;
8244     }
8245     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8246
8247     trace("signalling to send message\n");
8248     SetEvent(info.hevent[EV_SENDMSG]);
8249     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8250
8251     /* pass invalid QS_xxxx flags */
8252     SetLastError(0xdeadbeef);
8253     qstatus = GetQueueStatus(0xffffffff);
8254     ok(qstatus == 0, "GetQueueStatus should fail: %08x\n", qstatus);
8255     ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
8256
8257     qstatus = GetQueueStatus(qs_all_input);
8258     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
8259        "wrong qstatus %08x\n", qstatus);
8260
8261     msg.message = 0;
8262     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8263     ok(!ret,
8264        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8265         msg.message);
8266     ok_sequence(WmUser, "WmUser", FALSE);
8267
8268     qstatus = GetQueueStatus(qs_all_input);
8269     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8270
8271     keybd_event('N', 0, 0, 0);
8272     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
8273     qstatus = GetQueueStatus(qs_all_input);
8274     ok(qstatus == MAKELONG(QS_KEY, QS_KEY),
8275        "wrong qstatus %08x\n", qstatus);
8276
8277     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8278     qstatus = GetQueueStatus(qs_all_input);
8279     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8280        "wrong qstatus %08x\n", qstatus);
8281
8282     InvalidateRect(info.hwnd, NULL, FALSE);
8283     qstatus = GetQueueStatus(qs_all_input);
8284     ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8285        "wrong qstatus %08x\n", qstatus);
8286
8287     trace("signalling to send message\n");
8288     SetEvent(info.hevent[EV_SENDMSG]);
8289     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8290
8291     qstatus = GetQueueStatus(qs_all_input);
8292     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8293        "wrong qstatus %08x\n", qstatus);
8294
8295     msg.message = 0;
8296     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
8297     ok(!ret,
8298        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8299         msg.message);
8300     ok_sequence(WmUser, "WmUser", FALSE);
8301
8302     qstatus = GetQueueStatus(qs_all_input);
8303     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8304        "wrong qstatus %08x\n", qstatus);
8305
8306     trace("signalling to send message\n");
8307     SetEvent(info.hevent[EV_SENDMSG]);
8308     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8309
8310     qstatus = GetQueueStatus(qs_all_input);
8311     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8312        "wrong qstatus %08x\n", qstatus);
8313
8314     msg.message = 0;
8315     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8316     ok(!ret,
8317        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8318         msg.message);
8319     ok_sequence(WmUser, "WmUser", FALSE);
8320
8321     qstatus = GetQueueStatus(qs_all_input);
8322     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8323        "wrong qstatus %08x\n", qstatus);
8324
8325     msg.message = 0;
8326     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8327     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8328        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8329        ret, msg.message, msg.wParam);
8330     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8331
8332     qstatus = GetQueueStatus(qs_all_input);
8333     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
8334        "wrong qstatus %08x\n", qstatus);
8335
8336     msg.message = 0;
8337     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8338     ok(!ret,
8339        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8340         msg.message);
8341     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8342
8343     qstatus = GetQueueStatus(qs_all_input);
8344     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
8345        "wrong qstatus %08x\n", qstatus);
8346
8347     msg.message = 0;
8348     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
8349     ok(ret && msg.message == WM_PAINT,
8350        "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
8351     DispatchMessageA(&msg);
8352     ok_sequence(WmPaint, "WmPaint", FALSE);
8353
8354     qstatus = GetQueueStatus(qs_all_input);
8355     ok(qstatus == MAKELONG(0, QS_KEY),
8356        "wrong qstatus %08x\n", qstatus);
8357
8358     msg.message = 0;
8359     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
8360     ok(!ret,
8361        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8362         msg.message);
8363     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8364
8365     qstatus = GetQueueStatus(qs_all_input);
8366     ok(qstatus == MAKELONG(0, QS_KEY),
8367        "wrong qstatus %08x\n", qstatus);
8368
8369     trace("signalling to send message\n");
8370     SetEvent(info.hevent[EV_SENDMSG]);
8371     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8372
8373     qstatus = GetQueueStatus(qs_all_input);
8374     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
8375        "wrong qstatus %08x\n", qstatus);
8376
8377     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8378
8379     qstatus = GetQueueStatus(qs_all_input);
8380     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
8381        "wrong qstatus %08x\n", qstatus);
8382
8383     msg.message = 0;
8384     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
8385     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8386        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8387        ret, msg.message, msg.wParam);
8388     ok_sequence(WmUser, "WmUser", FALSE);
8389
8390     qstatus = GetQueueStatus(qs_all_input);
8391     ok(qstatus == MAKELONG(0, QS_KEY),
8392        "wrong qstatus %08x\n", qstatus);
8393
8394     msg.message = 0;
8395     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
8396     ok(!ret,
8397        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8398         msg.message);
8399     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8400
8401     qstatus = GetQueueStatus(qs_all_input);
8402     ok(qstatus == MAKELONG(0, QS_KEY),
8403        "wrong qstatus %08x\n", qstatus);
8404
8405     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8406
8407     qstatus = GetQueueStatus(qs_all_input);
8408     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8409        "wrong qstatus %08x\n", qstatus);
8410
8411     trace("signalling to send message\n");
8412     SetEvent(info.hevent[EV_SENDMSG]);
8413     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8414
8415     qstatus = GetQueueStatus(qs_all_input);
8416     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
8417        "wrong qstatus %08x\n", qstatus);
8418
8419     msg.message = 0;
8420     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
8421     ok(!ret,
8422        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8423         msg.message);
8424     ok_sequence(WmUser, "WmUser", FALSE);
8425
8426     qstatus = GetQueueStatus(qs_all_input);
8427     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
8428        "wrong qstatus %08x\n", qstatus);
8429
8430     msg.message = 0;
8431     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
8432         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
8433     else /* workaround for a missing QS_RAWINPUT support */
8434         ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
8435     ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
8436        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
8437        ret, msg.message, msg.wParam);
8438     ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
8439
8440     qstatus = GetQueueStatus(qs_all_input);
8441     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
8442        "wrong qstatus %08x\n", qstatus);
8443
8444     msg.message = 0;
8445     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
8446         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
8447     else /* workaround for a missing QS_RAWINPUT support */
8448         ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
8449     ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
8450        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
8451        ret, msg.message, msg.wParam);
8452     ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
8453
8454     qstatus = GetQueueStatus(qs_all_input);
8455     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8456        "wrong qstatus %08x\n", qstatus);
8457
8458     msg.message = 0;
8459     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
8460     ok(!ret,
8461        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8462         msg.message);
8463     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8464
8465     qstatus = GetQueueStatus(qs_all_input);
8466     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8467        "wrong qstatus %08x\n", qstatus);
8468
8469     msg.message = 0;
8470     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8471     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8472        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8473        ret, msg.message, msg.wParam);
8474     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8475
8476     qstatus = GetQueueStatus(qs_all_input);
8477     ok(qstatus == 0,
8478        "wrong qstatus %08x\n", qstatus);
8479
8480     msg.message = 0;
8481     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8482     ok(!ret,
8483        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8484         msg.message);
8485     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8486
8487     qstatus = GetQueueStatus(qs_all_input);
8488     ok(qstatus == 0,
8489        "wrong qstatus %08x\n", qstatus);
8490
8491     /* test whether presence of the quit flag in the queue affects
8492      * the queue state
8493      */
8494     PostQuitMessage(0x1234abcd);
8495
8496     qstatus = GetQueueStatus(qs_all_input);
8497     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
8498        "wrong qstatus %08x\n", qstatus);
8499
8500     PostMessageA(info.hwnd, WM_USER, 0, 0);
8501
8502     qstatus = GetQueueStatus(qs_all_input);
8503     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
8504        "wrong qstatus %08x\n", qstatus);
8505
8506     msg.message = 0;
8507     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8508     ok(ret && msg.message == WM_USER,
8509        "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
8510     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8511
8512     qstatus = GetQueueStatus(qs_all_input);
8513     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8514        "wrong qstatus %08x\n", qstatus);
8515
8516     msg.message = 0;
8517     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8518     ok(ret && msg.message == WM_QUIT,
8519        "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
8520     ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
8521     ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
8522     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8523
8524     qstatus = GetQueueStatus(qs_all_input);
8525 todo_wine {
8526     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8527        "wrong qstatus %08x\n", qstatus);
8528 }
8529
8530     msg.message = 0;
8531     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8532     ok(!ret,
8533        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8534         msg.message);
8535     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8536
8537     qstatus = GetQueueStatus(qs_all_input);
8538     ok(qstatus == 0,
8539        "wrong qstatus %08x\n", qstatus);
8540
8541     trace("signalling to exit\n");
8542     SetEvent(info.hevent[EV_START_STOP]);
8543
8544     WaitForSingleObject(hthread, INFINITE);
8545
8546     CloseHandle(hthread);
8547     CloseHandle(info.hevent[0]);
8548     CloseHandle(info.hevent[1]);
8549     CloseHandle(info.hevent[2]);
8550
8551     DestroyWindow(info.hwnd);
8552 }
8553
8554 static void wait_move_event(HWND hwnd, int x, int y)
8555 {
8556     MSG msg;
8557     DWORD time;
8558     BOOL  ret;
8559     int go = 0;
8560
8561     time = GetTickCount();
8562     while (GetTickCount() - time < 200 && !go) {
8563         ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
8564         go  = ret && msg.pt.x > x && msg.pt.y > y;
8565     }
8566 }
8567
8568 #define STEP 20
8569 static void test_PeekMessage2(void)
8570 {
8571     HWND hwnd;
8572     BOOL ret;
8573     MSG msg;
8574     UINT message;
8575     DWORD time1, time2, time3;
8576     int x1, y1, x2, y2, x3, y3;
8577     POINT pos;
8578
8579     time1 = time2 = time3 = 0;
8580     x1 = y1 = x2 = y2 = x3 = y3 = 0;
8581
8582     /* Initialise window and make sure it is ready for events */
8583     hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
8584                         10, 10, 800, 800, NULL, NULL, NULL, NULL);
8585     assert(hwnd);
8586     trace("Window for test_PeekMessage2 %p\n", hwnd);
8587     ShowWindow(hwnd, SW_SHOW);
8588     UpdateWindow(hwnd);
8589     SetFocus(hwnd);
8590     GetCursorPos(&pos);
8591     SetCursorPos(100, 100);
8592     mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
8593     flush_events();
8594
8595     /* Do initial mousemove, wait until we can see it
8596        and then do our test peek with PM_NOREMOVE. */
8597     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
8598     wait_move_event(hwnd, 80, 80);
8599
8600     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
8601     ok(ret, "no message available\n");
8602     if (ret) {
8603         trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
8604         message = msg.message;
8605         time1 = msg.time;
8606         x1 = msg.pt.x;
8607         y1 = msg.pt.y;
8608         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
8609     }
8610
8611     /* Allow time to advance a bit, and then simulate the user moving their
8612      * mouse around. After that we peek again with PM_NOREMOVE.
8613      * Although the previous mousemove message was never removed, the
8614      * mousemove we now peek should reflect the recent mouse movements
8615      * because the input queue will merge the move events. */
8616     Sleep(2);
8617     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
8618     wait_move_event(hwnd, x1, y1);
8619
8620     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
8621     ok(ret, "no message available\n");
8622     if (ret) {
8623         trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
8624         message = msg.message;
8625         time2 = msg.time;
8626         x2 = msg.pt.x;
8627         y2 = msg.pt.y;
8628         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
8629         ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
8630         ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
8631     }
8632
8633     /* Have another go, to drive the point home */
8634     Sleep(2);
8635     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
8636     wait_move_event(hwnd, x2, y2);
8637
8638     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
8639     ok(ret, "no message available\n");
8640     if (ret) {
8641         trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
8642         message = msg.message;
8643         time3 = msg.time;
8644         x3 = msg.pt.x;
8645         y3 = msg.pt.y;
8646         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
8647         ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
8648         ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
8649     }
8650
8651     DestroyWindow(hwnd);
8652     SetCursorPos(pos.x, pos.y);
8653     flush_events();
8654 }
8655
8656 static void test_quit_message(void)
8657 {
8658     MSG msg;
8659     BOOL ret;
8660
8661     /* test using PostQuitMessage */
8662     PostQuitMessage(0xbeef);
8663
8664     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
8665     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
8666     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8667     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
8668
8669     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
8670     ok(ret, "PostMessage failed with error %d\n", GetLastError());
8671
8672     ret = GetMessage(&msg, NULL, 0, 0);
8673     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
8674     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
8675
8676     /* note: WM_QUIT message received after WM_USER message */
8677     ret = GetMessage(&msg, NULL, 0, 0);
8678     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
8679     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8680     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
8681
8682     ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
8683     ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
8684
8685     /* now test with PostThreadMessage - different behaviour! */
8686     PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
8687
8688     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
8689     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
8690     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8691     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
8692
8693     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
8694     ok(ret, "PostMessage failed with error %d\n", GetLastError());
8695
8696     /* note: we receive the WM_QUIT message first this time */
8697     ret = GetMessage(&msg, NULL, 0, 0);
8698     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
8699     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8700     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
8701
8702     ret = GetMessage(&msg, NULL, 0, 0);
8703     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
8704     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
8705 }
8706
8707 static const struct message WmMouseHoverSeq[] = {
8708     { WM_MOUSEACTIVATE, sent|optional },  /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
8709     { WM_MOUSEACTIVATE, sent|optional },
8710     { WM_TIMER, sent|optional }, /* XP sends it */
8711     { WM_SYSTIMER, sent },
8712     { WM_MOUSEHOVER, sent|wparam, 0 },
8713     { 0 }
8714 };
8715
8716 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
8717 {
8718     MSG msg;
8719     DWORD start_ticks, end_ticks;
8720
8721     start_ticks = GetTickCount();
8722     /* add some deviation (5%) to cover not expected delays */
8723     start_ticks += timeout / 20;
8724
8725     do
8726     {
8727         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
8728         {
8729             /* Timer proc messages are not dispatched to the window proc,
8730              * and therefore not logged.
8731              */
8732             if (msg.message == WM_TIMER || msg.message == WM_SYSTIMER)
8733             {
8734                 struct message s_msg;
8735
8736                 s_msg.message = msg.message;
8737                 s_msg.flags = sent|wparam|lparam;
8738                 s_msg.wParam = msg.wParam;
8739                 s_msg.lParam = msg.lParam;
8740                 add_message(&s_msg);
8741             }
8742             DispatchMessage(&msg);
8743         }
8744
8745         end_ticks = GetTickCount();
8746
8747         /* inject WM_MOUSEMOVE to see how it changes tracking */
8748         if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
8749         {
8750             mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8751             mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8752
8753             inject_mouse_move = FALSE;
8754         }
8755     } while (start_ticks + timeout >= end_ticks);
8756 }
8757
8758 static void test_TrackMouseEvent(void)
8759 {
8760     TRACKMOUSEEVENT tme;
8761     BOOL ret;
8762     HWND hwnd, hchild;
8763     RECT rc_parent, rc_child;
8764     UINT default_hover_time, hover_width = 0, hover_height = 0;
8765
8766 #define track_hover(track_hwnd, track_hover_time) \
8767     tme.cbSize = sizeof(tme); \
8768     tme.dwFlags = TME_HOVER; \
8769     tme.hwndTrack = track_hwnd; \
8770     tme.dwHoverTime = track_hover_time; \
8771     SetLastError(0xdeadbeef); \
8772     ret = pTrackMouseEvent(&tme); \
8773     ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
8774
8775 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
8776     tme.cbSize = sizeof(tme); \
8777     tme.dwFlags = TME_QUERY; \
8778     tme.hwndTrack = (HWND)0xdeadbeef; \
8779     tme.dwHoverTime = 0xdeadbeef; \
8780     SetLastError(0xdeadbeef); \
8781     ret = pTrackMouseEvent(&tme); \
8782     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
8783     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
8784     ok(tme.dwFlags == (expected_track_flags), \
8785        "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
8786     ok(tme.hwndTrack == (expected_track_hwnd), \
8787        "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
8788     ok(tme.dwHoverTime == (expected_hover_time), \
8789        "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
8790
8791 #define track_hover_cancel(track_hwnd) \
8792     tme.cbSize = sizeof(tme); \
8793     tme.dwFlags = TME_HOVER | TME_CANCEL; \
8794     tme.hwndTrack = track_hwnd; \
8795     tme.dwHoverTime = 0xdeadbeef; \
8796     SetLastError(0xdeadbeef); \
8797     ret = pTrackMouseEvent(&tme); \
8798     ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
8799
8800     default_hover_time = 0xdeadbeef;
8801     SetLastError(0xdeadbeef);
8802     ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
8803     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
8804     if (!ret) default_hover_time = 400;
8805     trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
8806
8807     SetLastError(0xdeadbeef);
8808     ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
8809     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
8810     if (!ret) hover_width = 4;
8811     SetLastError(0xdeadbeef);
8812     ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
8813     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
8814     if (!ret) hover_height = 4;
8815     trace("hover rect is %u x %d\n", hover_width, hover_height);
8816
8817     hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
8818                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8819                           CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8820                           NULL, NULL, 0);
8821     assert(hwnd);
8822
8823     hchild = CreateWindowEx(0, "TestWindowClass", NULL,
8824                           WS_CHILD | WS_BORDER | WS_VISIBLE,
8825                           50, 50, 200, 200, hwnd,
8826                           NULL, NULL, 0);
8827     assert(hchild);
8828
8829     flush_events();
8830     flush_sequence();
8831
8832     tme.cbSize = 0;
8833     tme.dwFlags = TME_QUERY;
8834     tme.hwndTrack = (HWND)0xdeadbeef;
8835     tme.dwHoverTime = 0xdeadbeef;
8836     SetLastError(0xdeadbeef);
8837     ret = pTrackMouseEvent(&tme);
8838     ok(!ret, "TrackMouseEvent should fail\n");
8839     ok(GetLastError() == ERROR_INVALID_PARAMETER, "not expected error %d\n", GetLastError());
8840
8841     tme.cbSize = sizeof(tme);
8842     tme.dwFlags = TME_HOVER;
8843     tme.hwndTrack = (HWND)0xdeadbeef;
8844     tme.dwHoverTime = 0xdeadbeef;
8845     SetLastError(0xdeadbeef);
8846     ret = pTrackMouseEvent(&tme);
8847     ok(!ret, "TrackMouseEvent should fail\n");
8848     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "not expected error %d\n", GetLastError());
8849
8850     tme.cbSize = sizeof(tme);
8851     tme.dwFlags = TME_HOVER | TME_CANCEL;
8852     tme.hwndTrack = (HWND)0xdeadbeef;
8853     tme.dwHoverTime = 0xdeadbeef;
8854     SetLastError(0xdeadbeef);
8855     ret = pTrackMouseEvent(&tme);
8856     ok(!ret, "TrackMouseEvent should fail\n");
8857     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "not expected error %d\n", GetLastError());
8858
8859     GetWindowRect(hwnd, &rc_parent);
8860     GetWindowRect(hchild, &rc_child);
8861     SetCursorPos(rc_child.left - 10, rc_child.top - 10);
8862
8863     /* Process messages so that the system updates its internal current
8864      * window and hittest, otherwise TrackMouseEvent calls don't have any
8865      * effect.
8866      */
8867     flush_events();
8868     flush_sequence();
8869
8870     track_query(0, NULL, 0);
8871     track_hover(hchild, 0);
8872     track_query(0, NULL, 0);
8873
8874     flush_events();
8875     flush_sequence();
8876
8877     track_hover(hwnd, 0);
8878     track_query(TME_HOVER, hwnd, default_hover_time);
8879
8880     pump_msg_loop_timeout(default_hover_time, FALSE);
8881     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
8882
8883     track_query(0, NULL, 0);
8884
8885     track_hover(hwnd, HOVER_DEFAULT);
8886     track_query(TME_HOVER, hwnd, default_hover_time);
8887
8888     Sleep(default_hover_time / 2);
8889     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8890     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8891
8892     track_query(TME_HOVER, hwnd, default_hover_time);
8893
8894     pump_msg_loop_timeout(default_hover_time / 2, FALSE);
8895     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
8896
8897     track_query(0, NULL, 0);
8898
8899     track_hover(hwnd, HOVER_DEFAULT);
8900     track_query(TME_HOVER, hwnd, default_hover_time);
8901
8902     pump_msg_loop_timeout(default_hover_time, TRUE);
8903     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
8904
8905     track_query(0, NULL, 0);
8906
8907     track_hover(hwnd, HOVER_DEFAULT);
8908     track_query(TME_HOVER, hwnd, default_hover_time);
8909     track_hover_cancel(hwnd);
8910
8911     DestroyWindow(hwnd);
8912
8913 #undef track_hover
8914 #undef track_query
8915 #undef track_hover_cancel
8916 }
8917
8918
8919 static const struct message WmSetWindowRgn[] = {
8920     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
8921     { WM_NCCALCSIZE, sent|wparam, 1 },
8922     { WM_NCPAINT, sent }, /* wparam != 1 */
8923     { WM_GETTEXT, sent|defwinproc|optional },
8924     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
8925     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
8926     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
8927     { 0 }
8928 };
8929
8930 static const struct message WmSetWindowRgn_no_redraw[] = {
8931     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
8932     { WM_NCCALCSIZE, sent|wparam, 1 },
8933     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
8934     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
8935     { 0 }
8936 };
8937
8938 static const struct message WmSetWindowRgn_clear[] = {
8939     { 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 */
8940     { WM_NCCALCSIZE, sent|wparam, 1 },
8941     { WM_NCPAINT, sent }, /* wparam != 1 */
8942     { WM_GETTEXT, sent|defwinproc|optional },
8943     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
8944     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
8945     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
8946     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
8947     { WM_GETTEXT, sent|defwinproc|optional },
8948     { WM_ERASEBKGND, sent|optional },
8949     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
8950     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
8951     { 0 }
8952 };
8953
8954 static void test_SetWindowRgn(void)
8955 {
8956     HRGN hrgn;
8957     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
8958                                 100, 100, 200, 200, 0, 0, 0, NULL);
8959     ok( hwnd != 0, "Failed to create overlapped window\n" );
8960
8961     ShowWindow( hwnd, SW_SHOW );
8962     UpdateWindow( hwnd );
8963     flush_events();
8964     flush_sequence();
8965
8966     trace("testing SetWindowRgn\n");
8967     hrgn = CreateRectRgn( 0, 0, 150, 150 );
8968     SetWindowRgn( hwnd, hrgn, TRUE );
8969     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
8970
8971     hrgn = CreateRectRgn( 30, 30, 160, 160 );
8972     SetWindowRgn( hwnd, hrgn, FALSE );
8973     ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
8974
8975     hrgn = CreateRectRgn( 0, 0, 180, 180 );
8976     SetWindowRgn( hwnd, hrgn, TRUE );
8977     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
8978
8979     SetWindowRgn( hwnd, 0, TRUE );
8980     ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
8981
8982     DestroyWindow( hwnd );
8983 }
8984
8985 /*************************** ShowWindow() test ******************************/
8986 static const struct message WmShowNormal[] = {
8987     { WM_SHOWWINDOW, sent|wparam, 1 },
8988     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
8989     { HCBT_ACTIVATE, hook },
8990     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
8991     { HCBT_SETFOCUS, hook },
8992     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8993     { 0 }
8994 };
8995 static const struct message WmShow[] = {
8996     { WM_SHOWWINDOW, sent|wparam, 1 },
8997     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
8998     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
8999     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9000     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9001     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9002     { 0 }
9003 };
9004 static const struct message WmShowNoActivate_1[] = {
9005     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9006     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|0x8000 },
9007     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|0x8000 },
9008     { WM_MOVE, sent|defwinproc },
9009     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9010     { 0 }
9011 };
9012 static const struct message WmShowNoActivate_2[] = {
9013     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9014     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9015     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9016     { WM_MOVE, sent|defwinproc },
9017     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9018     { HCBT_SETFOCUS, hook },
9019     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9020     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9021     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9022     { 0 }
9023 };
9024 static const struct message WmShowNA_1[] = {
9025     { WM_SHOWWINDOW, sent|wparam, 1 },
9026     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9027     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9028     { 0 }
9029 };
9030 static const struct message WmShowNA_2[] = {
9031     { WM_SHOWWINDOW, sent|wparam, 1 },
9032     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9033     { 0 }
9034 };
9035 static const struct message WmRestore_1[] = {
9036     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9037     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9038     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9039     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9040     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9041     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9042     { WM_MOVE, sent|defwinproc },
9043     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9044     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9045     { 0 }
9046 };
9047 static const struct message WmRestore_2[] = {
9048     { WM_SHOWWINDOW, sent|wparam, 1 },
9049     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9050     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9051     { 0 }
9052 };
9053 static const struct message WmRestore_3[] = {
9054     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9055     { WM_GETMINMAXINFO, sent },
9056     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9057     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9058     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9059     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9060     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9061     { WM_MOVE, sent|defwinproc },
9062     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9063     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9064     { 0 }
9065 };
9066 static const struct message WmRestore_4[] = {
9067     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9068     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
9069     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|0x8000 },
9070     { WM_MOVE, sent|defwinproc },
9071     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9072     { 0 }
9073 };
9074 static const struct message WmRestore_5[] = {
9075     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
9076     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
9077     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|0x8000 },
9078     { WM_MOVE, sent|defwinproc },
9079     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9080     { 0 }
9081 };
9082 static const struct message WmHide_1[] = {
9083     { WM_SHOWWINDOW, sent|wparam, 0 },
9084     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9085     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9086     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9087     { 0 }
9088 };
9089 static const struct message WmHide_2[] = {
9090     { WM_SHOWWINDOW, sent|wparam, 0 },
9091     { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9092     { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9093     { 0 }
9094 };
9095 static const struct message WmHide_3[] = {
9096     { WM_SHOWWINDOW, sent|wparam, 0 },
9097     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9098     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9099     { HCBT_SETFOCUS, hook },
9100     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9101     { 0 }
9102 };
9103 static const struct message WmShowMinimized_1[] = {
9104     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9105     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9106     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9107     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9108     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9109     { WM_MOVE, sent|defwinproc },
9110     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9111     { 0 }
9112 };
9113 static const struct message WmMinimize_1[] = {
9114     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9115     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9116     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9117     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9118     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9119     { WM_MOVE, sent|defwinproc },
9120     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9121     { 0 }
9122 };
9123 static const struct message WmMinimize_2[] = {
9124     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9125     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9126     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9127     { WM_MOVE, sent|defwinproc },
9128     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9129     { 0 }
9130 };
9131 static const struct message WmMinimize_3[] = {
9132     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9133     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9134     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9135     { WM_MOVE, sent|defwinproc },
9136     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9137     { 0 }
9138 };
9139 static const struct message WmShowMinNoActivate[] = {
9140     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9141     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9142     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9143     { 0 }
9144 };
9145 static const struct message WmMinMax_1[] = {
9146     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9147     { 0 }
9148 };
9149 static const struct message WmMinMax_2[] = {
9150     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9151     { 0 }
9152 };
9153 static const struct message WmMinMax_3[] = {
9154     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9155     { 0 }
9156 };
9157 static const struct message WmMinMax_4[] = {
9158     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9159     { 0 }
9160 };
9161 static const struct message WmShowMaximized_1[] = {
9162     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9163     { WM_GETMINMAXINFO, sent },
9164     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9165     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9166     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9167     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9168     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9169     { WM_MOVE, sent|defwinproc },
9170     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9171     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9172     { 0 }
9173 };
9174 static const struct message WmShowMaximized_2[] = {
9175     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9176     { WM_GETMINMAXINFO, sent },
9177     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
9178     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9179     { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
9180     { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
9181     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9182     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
9183     { WM_MOVE, sent|defwinproc },
9184     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9185     { HCBT_SETFOCUS, hook },
9186     { 0 }
9187 };
9188 static const struct message WmShowMaximized_3[] = {
9189     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9190     { WM_GETMINMAXINFO, sent },
9191     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
9192     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|0x8000 },
9193     { WM_MOVE, sent|defwinproc },
9194     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9195     { 0 }
9196 };
9197
9198 static void test_ShowWindow(void)
9199 {
9200     /* ShowWindow commands in random order */
9201     static const struct
9202     {
9203         INT cmd; /* ShowWindow command */
9204         LPARAM ret; /* ShowWindow return value */
9205         DWORD style; /* window style after the command */
9206         const struct message *msg; /* message sequence the command produces */
9207         BOOL todo_msg; /* message sequence doesn't match what Wine does */
9208     } sw[] =
9209     {
9210 /*  1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
9211 /*  2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9212 /*  3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
9213 /*  4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9214 /*  5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
9215 /*  6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
9216 /*  7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
9217 /*  8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
9218 /*  9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
9219 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
9220 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
9221 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
9222 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
9223 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9224 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
9225 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9226 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
9227 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9228 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, TRUE },
9229 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
9230 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9231 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
9232 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
9233 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9234 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
9235 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
9236 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
9237 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9238 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
9239 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
9240 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9241 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, TRUE },
9242 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9243 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, TRUE }, /* what does this mean?! */
9244 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, TRUE },
9245 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9246 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
9247 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9248 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9249 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, TRUE },
9250 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
9251 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, TRUE },
9252 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
9253 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, TRUE },
9254 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
9255 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
9256 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
9257 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
9258 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
9259 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
9260 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9261 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
9262 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9263 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, TRUE },
9264 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9265 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
9266 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
9267     };
9268     HWND hwnd;
9269     DWORD style;
9270     LPARAM ret;
9271     INT i;
9272
9273 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
9274     hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
9275                           120, 120, 90, 90,
9276                           0, 0, 0, NULL);
9277     assert(hwnd);
9278
9279     style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
9280     ok(style == 0, "expected style 0, got %08x\n", style);
9281
9282     flush_events();
9283     flush_sequence();
9284
9285     for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
9286     {
9287         static const char * const sw_cmd_name[13] =
9288         {
9289             "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
9290             "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
9291             "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
9292             "SW_NORMALNA" /* 0xCC */
9293         };
9294         char comment[64];
9295         INT idx; /* index into the above array of names */
9296
9297         idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
9298
9299         style = GetWindowLong(hwnd, GWL_STYLE);
9300         trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
9301         ret = ShowWindow(hwnd, sw[i].cmd);
9302         ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
9303         style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
9304         ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
9305
9306         sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
9307         ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
9308
9309         flush_events();
9310         flush_sequence();
9311     }
9312
9313     DestroyWindow(hwnd);
9314 }
9315
9316 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9317 {
9318     struct message msg;
9319
9320     trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
9321
9322     switch (message)
9323     {
9324     case WM_WINDOWPOSCHANGING:
9325     case WM_WINDOWPOSCHANGED:
9326     {
9327         WINDOWPOS *winpos = (WINDOWPOS *)lParam;
9328
9329         trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
9330         trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
9331               winpos->hwnd, winpos->hwndInsertAfter,
9332               winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
9333         dump_winpos_flags(winpos->flags);
9334
9335         /* Log only documented flags, win2k uses 0x1000 and 0x2000
9336          * in the high word for internal purposes
9337          */
9338         wParam = winpos->flags & 0xffff;
9339         /* We are not interested in the flags that don't match under XP and Win9x */
9340         wParam &= ~(SWP_NOZORDER);
9341         break;
9342     }
9343
9344     /* explicitly ignore WM_GETICON message */
9345     case WM_GETICON:
9346         return 0;
9347     }
9348
9349     msg.message = message;
9350     msg.flags = sent|wparam|lparam;
9351     msg.wParam = wParam;
9352     msg.lParam = lParam;
9353     add_message(&msg);
9354
9355     /* calling DefDlgProc leads to a recursion under XP */
9356
9357     switch (message)
9358     {
9359     case WM_INITDIALOG:
9360     case WM_GETDLGCODE:
9361         return 0;
9362     }
9363     return 1;
9364 }
9365
9366 static const struct message WmDefDlgSetFocus_1[] = {
9367     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
9368     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
9369     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
9370     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
9371     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
9372     { HCBT_SETFOCUS, hook },
9373     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9374     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9375     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9376     { WM_SETFOCUS, sent|wparam, 0 },
9377     { WM_CTLCOLOREDIT, sent },
9378     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9379     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9380     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9381     { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
9382     { 0 }
9383 };
9384 static const struct message WmDefDlgSetFocus_2[] = {
9385     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
9386     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
9387     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
9388     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
9389     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
9390     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9391     { WM_CTLCOLOREDIT, sent|optional }, /* XP */
9392     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9393     { 0 }
9394 };
9395 /* Creation of a dialog */
9396 static const struct message WmCreateDialogParamSeq_1[] = {
9397     { HCBT_CREATEWND, hook },
9398     { WM_NCCREATE, sent },
9399     { WM_NCCALCSIZE, sent|wparam, 0 },
9400     { WM_CREATE, sent },
9401     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
9402     { WM_SIZE, sent|wparam, SIZE_RESTORED },
9403     { WM_MOVE, sent },
9404     { WM_SETFONT, sent },
9405     { WM_INITDIALOG, sent },
9406     { WM_CHANGEUISTATE, sent|optional },
9407     { 0 }
9408 };
9409 /* Creation of a dialog */
9410 static const struct message WmCreateDialogParamSeq_2[] = {
9411     { HCBT_CREATEWND, hook },
9412     { WM_NCCREATE, sent },
9413     { WM_NCCALCSIZE, sent|wparam, 0 },
9414     { WM_CREATE, sent },
9415     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
9416     { WM_SIZE, sent|wparam, SIZE_RESTORED },
9417     { WM_MOVE, sent },
9418     { WM_CHANGEUISTATE, sent|optional },
9419     { 0 }
9420 };
9421
9422 static void test_dialog_messages(void)
9423 {
9424     WNDCLASS cls;
9425     HWND hdlg, hedit1, hedit2, hfocus;
9426     LRESULT ret;
9427
9428 #define set_selection(hctl, start, end) \
9429     ret = SendMessage(hctl, EM_SETSEL, start, end); \
9430     ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
9431
9432 #define check_selection(hctl, start, end) \
9433     ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
9434     ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
9435
9436     subclass_edit();
9437
9438     hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
9439                           WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
9440                           0, 0, 100, 100, 0, 0, 0, NULL);
9441     ok(hdlg != 0, "Failed to create custom dialog window\n");
9442
9443     hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
9444                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
9445                            0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
9446     ok(hedit1 != 0, "Failed to create edit control\n");
9447     hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
9448                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
9449                            0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
9450     ok(hedit2 != 0, "Failed to create edit control\n");
9451
9452     SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
9453     SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
9454
9455     hfocus = GetFocus();
9456     ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
9457
9458     SetFocus(hedit2);
9459     hfocus = GetFocus();
9460     ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
9461
9462     check_selection(hedit1, 0, 0);
9463     check_selection(hedit2, 0, 0);
9464
9465     set_selection(hedit2, 0, -1);
9466     check_selection(hedit2, 0, 3);
9467
9468     SetFocus(0);
9469     hfocus = GetFocus();
9470     ok(hfocus == 0, "wrong focus %p\n", hfocus);
9471
9472     flush_sequence();
9473     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
9474     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
9475     ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
9476
9477     hfocus = GetFocus();
9478     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
9479
9480     check_selection(hedit1, 0, 5);
9481     check_selection(hedit2, 0, 3);
9482
9483     flush_sequence();
9484     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
9485     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
9486     ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
9487
9488     hfocus = GetFocus();
9489     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
9490
9491     check_selection(hedit1, 0, 5);
9492     check_selection(hedit2, 0, 3);
9493
9494     EndDialog(hdlg, 0);
9495     DestroyWindow(hedit1);
9496     DestroyWindow(hedit2);
9497     DestroyWindow(hdlg);
9498     flush_sequence();
9499
9500 #undef set_selection
9501 #undef check_selection
9502
9503     ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
9504     cls.lpszClassName = "MyDialogClass";
9505     cls.hInstance = GetModuleHandle(0);
9506     /* need a cast since a dlgproc is used as a wndproc */
9507     cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
9508     if (!RegisterClass(&cls)) assert(0);
9509
9510     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
9511     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
9512     ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
9513     EndDialog(hdlg, 0);
9514     DestroyWindow(hdlg);
9515     flush_sequence();
9516
9517     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
9518     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
9519     ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
9520     EndDialog(hdlg, 0);
9521     DestroyWindow(hdlg);
9522     flush_sequence();
9523
9524     UnregisterClass(cls.lpszClassName, cls.hInstance);
9525 }
9526
9527 static void test_nullCallback(void)
9528 {
9529     HWND hwnd;
9530
9531     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
9532                            100, 100, 200, 200, 0, 0, 0, NULL);
9533     ok (hwnd != 0, "Failed to create overlapped window\n");
9534
9535     SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
9536     flush_events();
9537     DestroyWindow(hwnd);
9538 }
9539
9540 static const struct message SetForegroundWindowSeq[] =
9541 {
9542     { WM_NCACTIVATE, sent|wparam, 0 },
9543     { WM_GETTEXT, sent|defwinproc|optional },
9544     { WM_ACTIVATE, sent|wparam, 0 },
9545     { WM_ACTIVATEAPP, sent|wparam, 0 },
9546     { WM_KILLFOCUS, sent },
9547     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
9548     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
9549     { 0 }
9550 };
9551
9552 static void test_SetForegroundWindow(void)
9553 {
9554     HWND hwnd;
9555
9556     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
9557                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9558                            100, 100, 200, 200, 0, 0, 0, NULL);
9559     ok (hwnd != 0, "Failed to create overlapped window\n");
9560     flush_sequence();
9561
9562     trace("SetForegroundWindow( 0 )\n");
9563     SetForegroundWindow( 0 );
9564     ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
9565     trace("SetForegroundWindow( GetDesktopWindow() )\n");
9566     SetForegroundWindow( GetDesktopWindow() );
9567     ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
9568                                         "foreground top level window", FALSE);
9569     trace("done\n");
9570
9571     DestroyWindow(hwnd);
9572 }
9573
9574 static void test_dbcs_wm_char(void)
9575 {
9576     BYTE dbch[2];
9577     WCHAR wch, bad_wch;
9578     HWND hwnd, hwnd2;
9579     MSG msg;
9580     DWORD time;
9581     POINT pt;
9582     DWORD_PTR res;
9583     CPINFOEXA cpinfo;
9584     UINT i, j, k;
9585     struct message wmCharSeq[2];
9586
9587     if (!pGetCPInfoExA)
9588     {
9589         skip("GetCPInfoExA is not available\n");
9590         return;
9591     }
9592
9593     pGetCPInfoExA( CP_ACP, 0, &cpinfo );
9594     if (cpinfo.MaxCharSize != 2)
9595     {
9596         skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
9597         return;
9598     }
9599
9600     dbch[0] = dbch[1] = 0;
9601     wch = 0;
9602     bad_wch = cpinfo.UnicodeDefaultChar;
9603     for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
9604         for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
9605             for (k = 128; k <= 255; k++)
9606             {
9607                 char str[2];
9608                 WCHAR wstr[2];
9609                 str[0] = j;
9610                 str[1] = k;
9611                 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
9612                     WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
9613                     (BYTE)str[0] == j && (BYTE)str[1] == k &&
9614                     HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
9615                 {
9616                     dbch[0] = j;
9617                     dbch[1] = k;
9618                     wch = wstr[0];
9619                     break;
9620                 }
9621             }
9622
9623     if (!wch)
9624     {
9625         skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
9626         return;
9627     }
9628     trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
9629            dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
9630
9631     hwnd = CreateWindowExW(0, testWindowClassW, NULL,
9632                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
9633     hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
9634                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
9635     ok (hwnd != 0, "Failed to create overlapped window\n");
9636     ok (hwnd2 != 0, "Failed to create overlapped window\n");
9637     flush_sequence();
9638
9639     memset( wmCharSeq, 0, sizeof(wmCharSeq) );
9640     wmCharSeq[0].message = WM_CHAR;
9641     wmCharSeq[0].flags = sent|wparam;
9642     wmCharSeq[0].wParam = wch;
9643
9644     /* posted message */
9645     PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9646     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9647     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9648     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9649     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9650     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
9651     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9652
9653     /* posted thread message */
9654     PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
9655     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9656     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9657     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9658     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9659     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
9660     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9661
9662     /* sent message */
9663     flush_sequence();
9664     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9665     ok_sequence( WmEmptySeq, "no messages", FALSE );
9666     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
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 */
9671     flush_sequence();
9672     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
9673     ok_sequence( WmEmptySeq, "no messages", FALSE );
9674     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
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 timeout and callback */
9679     flush_sequence();
9680     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
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     /* sent message with callback */
9687     flush_sequence();
9688     SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9689     ok_sequence( WmEmptySeq, "no messages", FALSE );
9690     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
9691     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9692     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9693
9694     /* direct window proc call */
9695     flush_sequence();
9696     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
9697     ok_sequence( WmEmptySeq, "no messages", FALSE );
9698     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
9699     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9700
9701     /* dispatch message */
9702     msg.hwnd = hwnd;
9703     msg.message = WM_CHAR;
9704     msg.wParam = dbch[0];
9705     msg.lParam = 0;
9706     DispatchMessageA( &msg );
9707     ok_sequence( WmEmptySeq, "no messages", FALSE );
9708     msg.wParam = dbch[1];
9709     DispatchMessageA( &msg );
9710     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9711
9712     /* window handle is irrelevant */
9713     flush_sequence();
9714     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
9715     ok_sequence( WmEmptySeq, "no messages", FALSE );
9716     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9717     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9718     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9719
9720     /* interleaved post and send */
9721     flush_sequence();
9722     PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
9723     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
9724     ok_sequence( WmEmptySeq, "no messages", FALSE );
9725     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9726     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9727     ok_sequence( WmEmptySeq, "no messages", FALSE );
9728     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9729     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9730     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
9731     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9732     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9733     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9734     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9735
9736     /* interleaved sent message and winproc */
9737     flush_sequence();
9738     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9739     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
9740     ok_sequence( WmEmptySeq, "no messages", FALSE );
9741     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9742     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9743     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
9744     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9745
9746     /* interleaved winproc and dispatch */
9747     msg.hwnd = hwnd;
9748     msg.message = WM_CHAR;
9749     msg.wParam = dbch[0];
9750     msg.lParam = 0;
9751     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
9752     DispatchMessageA( &msg );
9753     ok_sequence( WmEmptySeq, "no messages", FALSE );
9754     msg.wParam = dbch[1];
9755     DispatchMessageA( &msg );
9756     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9757     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
9758     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9759
9760     /* interleaved sends */
9761     flush_sequence();
9762     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9763     SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
9764     ok_sequence( WmEmptySeq, "no messages", FALSE );
9765     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
9766     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9767     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9768     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9769
9770     /* dbcs WM_CHAR */
9771     flush_sequence();
9772     SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
9773     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9774     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9775
9776     /* other char messages are not magic */
9777     PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
9778     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9779     ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
9780     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
9781     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9782     PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
9783     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9784     ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
9785     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
9786     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9787
9788     /* test retrieving messages */
9789
9790     PostMessageW( hwnd, WM_CHAR, wch, 0 );
9791     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9792     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9793     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9794     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[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[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9799     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9800
9801     /* message filters */
9802     PostMessageW( hwnd, WM_CHAR, wch, 0 );
9803     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9804     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9805     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9806     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9807     /* message id is filtered, hwnd is not */
9808     ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
9809     ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "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[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9813     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9814
9815     /* mixing GetMessage and PostMessage */
9816     PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
9817     ok( GetMessageA( &msg, hwnd, 0, 0 ), "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[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9821     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
9822     time = msg.time;
9823     pt = msg.pt;
9824     ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
9825     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
9826     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9827     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9828     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9829     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
9830     ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
9831     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 );
9832     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9833
9834     /* without PM_REMOVE */
9835     PostMessageW( hwnd, WM_CHAR, wch, 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[0], "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[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9844     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
9845     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9846     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9847     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9848     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
9849     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9850     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9851     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9852     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9853
9854     DestroyWindow(hwnd);
9855 }
9856
9857 #define ID_LISTBOX 0x000f
9858
9859 static const struct message wm_lb_setcursel_0[] =
9860 {
9861     { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
9862     { WM_CTLCOLORLISTBOX, sent|parent },
9863     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
9864     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
9865     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
9866     { 0 }
9867 };
9868 static const struct message wm_lb_setcursel_1[] =
9869 {
9870     { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
9871     { WM_CTLCOLORLISTBOX, sent|parent },
9872     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
9873     { WM_CTLCOLORLISTBOX, sent|parent },
9874     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
9875     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
9876     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
9877     { 0 }
9878 };
9879 static const struct message wm_lb_setcursel_2[] =
9880 {
9881     { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
9882     { WM_CTLCOLORLISTBOX, sent|parent },
9883     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
9884     { WM_CTLCOLORLISTBOX, sent|parent },
9885     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
9886     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
9887     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
9888     { 0 }
9889 };
9890 static const struct message wm_lb_click_0[] =
9891 {
9892     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
9893     { HCBT_SETFOCUS, hook },
9894     { WM_KILLFOCUS, sent|parent },
9895     { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
9896     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9897     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9898     { WM_SETFOCUS, sent },
9899
9900     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
9901     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
9902     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
9903     { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
9904     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9905
9906     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
9907     { WM_CTLCOLORLISTBOX, sent|parent },
9908     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
9909     { WM_CTLCOLORLISTBOX, sent|parent },
9910     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
9911     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
9912
9913     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
9914     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
9915
9916     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9917     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9918     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, 0 },
9919     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
9920     { 0 }
9921 };
9922
9923 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
9924
9925 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
9926
9927 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
9928 {
9929     struct message msg;
9930
9931     /* do not log painting messages */
9932     if (message != WM_PAINT &&
9933         message != WM_NCPAINT &&
9934         message != WM_SYNCPAINT &&
9935         message != WM_ERASEBKGND &&
9936         message != WM_NCHITTEST &&
9937         message != WM_GETTEXT &&
9938         message != WM_GETICON &&
9939         message != WM_DEVICECHANGE)
9940     {
9941         trace("listbox: %p, %04x, %08lx, %08lx\n", hwnd, message, wp, lp);
9942
9943         msg.message = message;
9944         msg.flags = sent|wparam|lparam;
9945         msg.wParam = wp;
9946         msg.lParam = lp;
9947         add_message(&msg);
9948     }
9949
9950     return CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
9951 }
9952
9953 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
9954                                int caret_index, int top_index, int line)
9955 {
9956     LRESULT ret;
9957
9958     /* calling an orig proc helps to avoid unnecessary message logging */
9959     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
9960     ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
9961     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
9962     ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
9963     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
9964     ok_(__FILE__, line)(ret == caret_index, "expected caret index %d, got %ld\n", caret_index, ret);
9965     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
9966     ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
9967 }
9968
9969 static void test_listbox(void)
9970 {
9971     HWND parent, listbox;
9972     LRESULT ret;
9973
9974     parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW  | WS_VISIBLE,
9975                              100, 100, 200, 200, 0, 0, 0, NULL);
9976     listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
9977                               WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
9978                               10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
9979     listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
9980
9981     check_lb_state(listbox, 0, LB_ERR, 0, 0);
9982
9983     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
9984     ok(ret == 0, "expected 0, got %ld\n", ret);
9985     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
9986     ok(ret == 1, "expected 1, got %ld\n", ret);
9987     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
9988     ok(ret == 2, "expected 2, got %ld\n", ret);
9989
9990     check_lb_state(listbox, 3, LB_ERR, 0, 0);
9991
9992     flush_sequence();
9993
9994     log_all_parent_messages++;
9995
9996     trace("selecting item 0\n");
9997     ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
9998     ok(ret == 0, "expected 0, got %ld\n", ret);
9999     ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
10000     check_lb_state(listbox, 3, 0, 0, 0);
10001     flush_sequence();
10002
10003     trace("selecting item 1\n");
10004     ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
10005     ok(ret == 1, "expected 1, got %ld\n", ret);
10006     ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
10007     check_lb_state(listbox, 3, 1, 1, 0);
10008
10009     trace("selecting item 2\n");
10010     ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
10011     ok(ret == 2, "expected 2, got %ld\n", ret);
10012     ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
10013     check_lb_state(listbox, 3, 2, 2, 0);
10014
10015     trace("clicking on item 0\n");
10016     ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
10017     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
10018     ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
10019     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
10020     ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
10021     check_lb_state(listbox, 3, 0, 0, 0);
10022     flush_sequence();
10023
10024     log_all_parent_messages--;
10025
10026     DestroyWindow(parent);
10027 }
10028
10029 START_TEST(msg)
10030 {
10031     BOOL ret;
10032     FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
10033
10034     init_procs();
10035
10036     if (!RegisterWindowClasses()) assert(0);
10037
10038     if (pSetWinEventHook)
10039     {
10040         hEvent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
10041                                                       GetModuleHandleA(0),
10042                                                       win_event_proc,
10043                                                       0,
10044                                                       GetCurrentThreadId(),
10045                                                       WINEVENT_INCONTEXT);
10046         assert(hEvent_hook);
10047
10048         if (pIsWinEventHookInstalled)
10049         {
10050             UINT event;
10051             for (event = EVENT_MIN; event <= EVENT_MAX; event++)
10052                 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
10053         }
10054     }
10055
10056     cbt_hook_thread_id = GetCurrentThreadId();
10057     hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
10058     assert(hCBT_hook);
10059
10060     test_winevents();
10061
10062     /* Fix message sequences before removing 4 lines below */
10063 #if 1
10064     if (pUnhookWinEvent && hEvent_hook)
10065     {
10066         ret = pUnhookWinEvent(hEvent_hook);
10067         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
10068         pUnhookWinEvent = 0;
10069     }
10070     hEvent_hook = 0;
10071 #endif
10072
10073     test_ShowWindow();
10074     test_PeekMessage();
10075     test_PeekMessage2();
10076     test_scrollwindowex();
10077     test_messages();
10078     test_showwindow();
10079     invisible_parent_tests();
10080     test_mdi_messages();
10081     test_button_messages();
10082     test_static_messages();
10083     test_paint_messages();
10084     test_interthread_messages();
10085     test_message_conversion();
10086     test_accelerators();
10087     test_timers();
10088     test_timers_no_wnd();
10089     test_set_hook();
10090     test_DestroyWindow();
10091     test_DispatchMessage();
10092     test_SendMessageTimeout();
10093     test_edit_messages();
10094     test_quit_message();
10095
10096     if (!pTrackMouseEvent)
10097         skip("TrackMouseEvent is not available\n");
10098     else
10099         test_TrackMouseEvent();
10100
10101     test_SetWindowRgn();
10102     test_sys_menu();
10103     test_dialog_messages();
10104     test_nullCallback();
10105     test_SetForegroundWindow();
10106     test_dbcs_wm_char();
10107     test_listbox();
10108
10109     UnhookWindowsHookEx(hCBT_hook);
10110     if (pUnhookWinEvent)
10111     {
10112         ret = pUnhookWinEvent(hEvent_hook);
10113         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
10114         SetLastError(0xdeadbeef);
10115         ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
10116         ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
10117            GetLastError() == 0xdeadbeef, /* Win9x */
10118            "unexpected error %d\n", GetLastError());
10119     }
10120     else
10121         skip("UnhookWinEvent is not available\n");
10122 }