comctl32: We can now store binary files in the repository.
[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 static BOOL test_DestroyWindow_flag;
55 static HWINEVENTHOOK hEvent_hook;
56
57 static void dump_winpos_flags(UINT flags);
58
59 static const WCHAR testWindowClassW[] =
60 { 'T','e','s','t','W','i','n','d','o','w','C','l','a','s','s','W',0 };
61
62 /*
63 FIXME: add tests for these
64 Window Edge Styles (Win31/Win95/98 look), in order of precedence:
65  WS_EX_DLGMODALFRAME: double border, WS_CAPTION allowed
66  WS_THICKFRAME: thick border
67  WS_DLGFRAME: double border, WS_CAPTION not allowed (but possibly shown anyway)
68  WS_BORDER (default for overlapped windows): single black border
69  none (default for child (and popup?) windows): no border
70 */
71
72 typedef enum {
73     sent=0x1,
74     posted=0x2,
75     parent=0x4,
76     wparam=0x8,
77     lparam=0x10,
78     defwinproc=0x20,
79     beginpaint=0x40,
80     optional=0x80,
81     hook=0x100,
82     winevent_hook=0x200
83 } msg_flags_t;
84
85 struct message {
86     UINT message;          /* the WM_* code */
87     msg_flags_t flags;     /* message props */
88     WPARAM wParam;         /* expected value of wParam */
89     LPARAM lParam;         /* expected value of lParam */
90 };
91
92 /* Empty message sequence */
93 static const struct message WmEmptySeq[] =
94 {
95     { 0 }
96 };
97 /* CreateWindow (for overlapped window, not initially visible) (16/32) */
98 static const struct message WmCreateOverlappedSeq[] = {
99     { HCBT_CREATEWND, hook },
100     { WM_GETMINMAXINFO, sent },
101     { WM_NCCREATE, sent },
102     { WM_NCCALCSIZE, sent|wparam, 0 },
103     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
104     { WM_CREATE, sent },
105     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
106     { 0 }
107 };
108 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
109  * for a not visible overlapped window.
110  */
111 static const struct message WmSWP_ShowOverlappedSeq[] = {
112     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
113     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
114     { WM_NCPAINT, sent|wparam|optional, 1 },
115     { WM_GETTEXT, sent|defwinproc|optional },
116     { WM_ERASEBKGND, sent|optional },
117     { HCBT_ACTIVATE, hook },
118     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
119     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
120     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x: SWP_NOSENDCHANGING */
121     { WM_ACTIVATEAPP, sent|wparam, 1 },
122     { WM_NCACTIVATE, sent|wparam, 1 },
123     { WM_GETTEXT, sent|defwinproc|optional },
124     { WM_ACTIVATE, sent|wparam, 1 },
125     { HCBT_SETFOCUS, hook },
126     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
127     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
128     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
129     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
130     { WM_NCPAINT, sent|wparam|optional, 1 },
131     { WM_GETTEXT, sent|defwinproc|optional },
132     { WM_ERASEBKGND, sent|optional },
133     /* Win9x adds SWP_NOZORDER below */
134     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
135     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
136     { WM_NCPAINT, sent|wparam|optional, 1 },
137     { WM_ERASEBKGND, sent|optional },
138     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
139     { 0 }
140 };
141 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
142  * for a visible overlapped window.
143  */
144 static const struct message WmSWP_HideOverlappedSeq[] = {
145     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
146     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
147     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
148     { 0 }
149 };
150
151 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
152  * for a visible overlapped window.
153  */
154 static const struct message WmSWP_ResizeSeq[] = {
155     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
156     { WM_GETMINMAXINFO, sent|defwinproc },
157     { WM_NCCALCSIZE, sent|wparam, TRUE },
158     { WM_NCPAINT, sent|optional },
159     { WM_GETTEXT, sent|defwinproc|optional },
160     { WM_ERASEBKGND, sent|optional },
161     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
162     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
163     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
164     { WM_NCPAINT, sent|optional },
165     { WM_GETTEXT, sent|defwinproc|optional },
166     { WM_ERASEBKGND, sent|optional },
167     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
168     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
169     { 0 }
170 };
171
172 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
173  * for a visible popup window.
174  */
175 static const struct message WmSWP_ResizePopupSeq[] = {
176     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
177     { WM_GETMINMAXINFO, sent|defwinproc|optional }, /* Win9x */
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     { 0 }
190 };
191
192 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
193  * for a visible overlapped window.
194  */
195 static const struct message WmSWP_MoveSeq[] = {
196     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE },
197     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
198     { WM_MOVE, sent|defwinproc|wparam, 0 },
199     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
200     { 0 }
201 };
202 /* Resize with SetWindowPos(SWP_NOZORDER)
203  * for a visible overlapped window
204  * SWP_NOZORDER is stripped by the logging code
205  */
206 static const struct message WmSWP_ResizeNoZOrder[] = {
207     { WM_WINDOWPOSCHANGING, sent|wparam, 0/*SWP_NOZORDER*/ },
208     { WM_GETMINMAXINFO, sent|defwinproc },
209     { WM_NCCALCSIZE, sent|wparam, 1 },
210     { WM_NCPAINT, sent },
211     { WM_GETTEXT, sent|defwinproc|optional },
212     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
213     { WM_WINDOWPOSCHANGED, sent|wparam, /*SWP_NOZORDER|*/SWP_NOMOVE|SWP_NOCLIENTMOVE },
214     { WM_SIZE, sent|defwinproc|wparam, 0 },
215     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
216     { WM_NCPAINT, sent|optional }, /* Win9x doesn't send it */
217     { WM_GETTEXT, sent|defwinproc|optional }, /* Win9x doesn't send it */
218     { WM_ERASEBKGND, sent|optional }, /* Win9x doesn't send it */
219     { 0 }
220 };
221
222 /* Switch visible mdi children */
223 static const struct message WmSwitchChild[] = {
224     /* Switch MDI child */
225     { WM_MDIACTIVATE, sent },/* in the MDI client */
226     { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 1st MDI child */
227     { WM_CHILDACTIVATE, sent },/* in the 1st MDI child */
228     /* Deactivate 2nd MDI child */
229     { WM_NCACTIVATE, sent|defwinproc|optional },/* in the 2nd MDI child */
230     { WM_MDIACTIVATE, sent|defwinproc|optional },/* in the 2nd MDI child */
231     { WM_CREATE, hook },
232     /* Preparing for maximize and maximaze the 1st MDI child */
233     { WM_GETMINMAXINFO, sent|defwinproc|optional },/* in the 1st MDI child */
234     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_FRAMECHANGED|SWP_STATECHANGED },/* in the 1st MDI child */
235     { WM_GETMINMAXINFO, sent|defwinproc|optional },/* in the 1st MDI child */
236     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },/* in the 1st MDI child */
237     { WM_CHILDACTIVATE, sent|defwinproc|optional },/* in the 1st MDI child */
238     { WM_WINDOWPOSCHANGED, sent|defwinproc|optional },/* in the 1st MDI child */
239     { WM_MOVE, sent|defwinproc|optional },/* in the 1st MDI child */
240     { WM_SIZE, sent|defwinproc|optional },/* in the 1st MDI child */
241     /* Lock redraw 2nd MDI child */
242     { WM_SETREDRAW, sent|defwinproc|optional },/* in the 2nd MDI child */
243     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },/* in the 2nd MDI child */
244     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },/* in the 2nd MDI child */
245     { WM_WINDOWPOSCHANGED, sent|defwinproc|optional },/* in the 2nd MDI child */
246     { WM_CREATE, hook },
247     /* Restore 2nd MDI child */
248     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED  },/* in the 2nd MDI child */
249     { WM_GETMINMAXINFO, sent|defwinproc|optional },/* in the 2nd MDI child */
250     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },/* in the 2nd MDI child */
251     { WM_WINDOWPOSCHANGED, sent|defwinproc|optional },/* in the 2nd MDI child */
252     { WM_MOVE, sent|defwinproc|optional },/* in the 2nd MDI child */
253     { WM_SIZE, sent|defwinproc|optional },/* in the 2nd MDI child */
254     /* Redraw 2nd MDI child */
255     { WM_SETREDRAW, sent|defwinproc|optional },/* in the 2nd MDI child */
256     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_FRAMECHANGED|SWP_NOMOVE },/* in the 1st MDI child */
257     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },/* in the 1st MDI child */
258     { WM_WINDOWPOSCHANGED, sent|defwinproc|optional},/* in the 1st MDI child */
259     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_FRAMECHANGED|SWP_NOMOVE },/* in the MDI frame */
260     { WM_NCCALCSIZE, sent|wparam, 1 },/* in the MDI frame */
261     { WM_WINDOWPOSCHANGED, sent},/* in the MDI frame */
262     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },/* in the 1st MDI child */
263     { WM_NCACTIVATE, sent|defwinproc|optional },/* in the 1st MDI child */
264     { WM_SETVISIBLE, hook },
265     { WM_KILLFOCUS, sent|defwinproc|optional },/* in the 2nd MDI child */
266     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
267     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
268     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
269     { WM_SETFOCUS, sent },/* in the MDI client */
270     { WM_SETVISIBLE, hook},
271     { WM_KILLFOCUS, sent },/* in the MDI client */
272     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
273     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
274     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
275     { WM_SETFOCUS, sent|defwinproc|optional },/* in the 1st MDI child */
276     { WM_MDIACTIVATE, sent|defwinproc|optional },/* in the 1st MDI child */
277     { WM_WINDOWPOSCHANGED, sent },/* in the 1st MDI child */
278     { 0 }
279 };
280
281 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
282                 SWP_NOZORDER|SWP_FRAMECHANGED)
283  * for a visible overlapped window with WS_CLIPCHILDREN style set.
284  */
285 static const struct message WmSWP_FrameChanged_clip[] = {
286     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
287     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
288     { WM_NCPAINT, sent|parent }, /* wparam != 1 */
289     { WM_GETTEXT, sent|parent|defwinproc|optional },
290     { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
291     { WM_NCPAINT, sent }, /* wparam != 1 */
292     { WM_ERASEBKGND, sent },
293     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
294     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
295     { WM_PAINT, sent },
296     { 0 }
297 };
298 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|
299                 SWP_NOZORDER|SWP_FRAMECHANGED)
300  * for a visible overlapped window.
301  */
302 static const struct message WmSWP_FrameChangedDeferErase[] = {
303     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
304     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
305     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
306     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
307     { WM_PAINT, sent|parent },
308     { WM_NCPAINT, sent|beginpaint|parent }, /* wparam != 1 */
309     { WM_GETTEXT, sent|beginpaint|parent|defwinproc|optional },
310     { WM_PAINT, sent },
311     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
312     { WM_ERASEBKGND, sent|beginpaint },
313     { 0 }
314 };
315
316 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
317                 SWP_NOZORDER|SWP_FRAMECHANGED)
318  * for a visible overlapped window without WS_CLIPCHILDREN style set.
319  */
320 static const struct message WmSWP_FrameChanged_noclip[] = {
321     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
322     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
323     { WM_NCPAINT, sent|parent }, /* wparam != 1 */
324     { WM_GETTEXT, sent|parent|defwinproc|optional },
325     { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
326     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
327     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
328     { WM_PAINT, sent },
329     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
330     { WM_ERASEBKGND, sent|beginpaint },
331     { 0 }
332 };
333
334 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
335 static const struct message WmShowOverlappedSeq[] = {
336     { WM_SHOWWINDOW, sent|wparam, 1 },
337     { WM_NCPAINT, sent|wparam|optional, 1 },
338     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
339     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
340     { WM_NCPAINT, sent|wparam|optional, 1 },
341     { WM_GETTEXT, sent|defwinproc|optional },
342     { WM_ERASEBKGND, sent|optional },
343     { HCBT_ACTIVATE, hook },
344     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
345     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
346     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
347     { WM_NCPAINT, sent|wparam|optional, 1 },
348     { WM_ACTIVATEAPP, sent|wparam, 1 },
349     { WM_NCACTIVATE, sent|wparam, 1 },
350     { WM_GETTEXT, sent|defwinproc|optional },
351     { WM_ACTIVATE, sent|wparam, 1 },
352     { HCBT_SETFOCUS, hook },
353     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
354     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
355     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
356     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
357     { WM_NCPAINT, sent|wparam|optional, 1 },
358     { WM_GETTEXT, sent|defwinproc|optional },
359     { WM_ERASEBKGND, sent|optional },
360     /* Win9x adds SWP_NOZORDER below */
361     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
362     { WM_NCCALCSIZE, sent|optional },
363     { WM_NCPAINT, sent|optional },
364     { WM_ERASEBKGND, sent|optional },
365 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
366        * messages. Does that mean that CreateWindow doesn't set initial
367        * window dimensions for overlapped windows?
368        */
369     { WM_SIZE, sent },
370     { WM_MOVE, sent },
371 #endif
372     { 0 }
373 };
374 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible overlapped window */
375 static const struct message WmShowMaxOverlappedSeq[] = {
376     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
377     { WM_GETMINMAXINFO, sent },
378     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
379     { WM_GETMINMAXINFO, sent|defwinproc },
380     { WM_NCCALCSIZE, sent|wparam, TRUE },
381     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
382     { HCBT_ACTIVATE, hook },
383     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
384     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
385     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
386     { WM_ACTIVATEAPP, sent|wparam, 1 },
387     { WM_NCACTIVATE, sent|wparam, 1 },
388     { WM_GETTEXT, sent|defwinproc|optional },
389     { WM_ACTIVATE, sent|wparam, 1 },
390     { HCBT_SETFOCUS, hook },
391     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
392     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
393     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
394     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
395     { WM_NCPAINT, sent|wparam|optional, 1 },
396     { WM_GETTEXT, sent|defwinproc|optional },
397     { WM_ERASEBKGND, sent|optional },
398     /* Win9x adds SWP_NOZORDER below */
399     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
400     { WM_MOVE, sent|defwinproc },
401     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
402     { WM_NCCALCSIZE, sent|optional },
403     { WM_NCPAINT, sent|optional },
404     { WM_ERASEBKGND, sent|optional },
405     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
406     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
407     { 0 }
408 };
409 /* ShowWindow(SW_SHOWMINIMIZED) for a not visible overlapped window */
410 static const struct message WmShowMinOverlappedSeq[] = {
411     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
412     { HCBT_SETFOCUS, hook },
413     { WM_KILLFOCUS, sent },
414     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
415     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
416     { WM_GETTEXT, sent|optional },
417     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCOPYBITS|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
418     { WM_GETMINMAXINFO, sent|defwinproc },
419     { WM_NCCALCSIZE, sent|wparam, TRUE },
420     { WM_NCPAINT, sent },
421     { WM_GETTEXT, sent|defwinproc|optional },
422     { WM_WINDOWPOSCHANGED, sent },
423     { WM_MOVE, sent|defwinproc },
424     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
425     { WM_NCCALCSIZE, sent|optional },
426     { WM_NCACTIVATE, sent|wparam, 0 },
427     { WM_GETTEXT, sent|defwinproc|optional },
428     { WM_ACTIVATE, sent },
429     { WM_ACTIVATEAPP, sent|wparam, 0 },
430     { 0 }
431 };
432 /* ShowWindow(SW_HIDE) for a visible overlapped window */
433 static const struct message WmHideOverlappedSeq[] = {
434     { WM_SHOWWINDOW, sent|wparam, 0 },
435     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
436     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
437     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
438     { WM_SIZE, sent|optional }, /* XP doesn't send it */
439     { WM_MOVE, sent|optional }, /* XP doesn't send it */
440     { WM_NCACTIVATE, sent|wparam, 0 },
441     { WM_ACTIVATE, sent|wparam, 0 },
442     { WM_ACTIVATEAPP, sent|wparam, 0 },
443     { WM_KILLFOCUS, sent|wparam, 0 },
444     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
445     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
446     { 0 }
447 };
448 /* DestroyWindow for a visible overlapped window */
449 static const struct message WmDestroyOverlappedSeq[] = {
450     { HCBT_DESTROYWND, hook },
451     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
452     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
453     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
454     { WM_NCACTIVATE, sent|wparam, 0 },
455     { WM_ACTIVATE, sent|wparam, 0 },
456     { WM_ACTIVATEAPP, sent|wparam, 0 },
457     { WM_KILLFOCUS, sent|wparam, 0 },
458     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
459     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
460     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
461     { WM_DESTROY, sent },
462     { WM_NCDESTROY, sent },
463     { 0 }
464 };
465 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
466 static const struct message WmCreateMaxPopupSeq[] = {
467     { HCBT_CREATEWND, hook },
468     { WM_NCCREATE, sent },
469     { WM_NCCALCSIZE, sent|wparam, 0 },
470     { WM_CREATE, sent },
471     { WM_SIZE, sent|wparam, SIZE_RESTORED },
472     { WM_MOVE, sent },
473     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
474     { WM_GETMINMAXINFO, sent },
475     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|0x8000 },
476     { WM_NCCALCSIZE, sent|wparam, TRUE },
477     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|0x8000 },
478     { WM_MOVE, sent|defwinproc },
479     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
480     { WM_SHOWWINDOW, sent|wparam, 1 },
481     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
482     { HCBT_ACTIVATE, hook },
483     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
484     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
485     { WM_ACTIVATEAPP, sent|wparam, 1 },
486     { WM_NCACTIVATE, sent|wparam, 1 },
487     { WM_ACTIVATE, sent|wparam, 1 },
488     { HCBT_SETFOCUS, hook },
489     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
490     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
491     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
492     { WM_SYNCPAINT, sent|wparam|optional, 4 },
493     { WM_NCPAINT, sent|wparam|optional, 1 },
494     { WM_ERASEBKGND, sent|optional },
495     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
496     { 0 }
497 };
498 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
499 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
500     { HCBT_CREATEWND, hook },
501     { WM_NCCREATE, sent },
502     { WM_NCCALCSIZE, sent|wparam, 0 },
503     { WM_CREATE, sent },
504     { WM_SIZE, sent|wparam, SIZE_RESTORED },
505     { WM_MOVE, sent },
506     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
507     { WM_GETMINMAXINFO, sent },
508     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|0x8000 },
509     { WM_NCCALCSIZE, sent|wparam, TRUE },
510     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|0x8000 },
511     { WM_MOVE, sent|defwinproc },
512     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
513     { 0 }
514 };
515 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
516 static const struct message WmShowMaxPopupResizedSeq[] = {
517     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
518     { WM_GETMINMAXINFO, sent },
519     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
520     { WM_NCCALCSIZE, sent|wparam, TRUE },
521     { HCBT_ACTIVATE, hook },
522     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
523     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
524     { WM_ACTIVATEAPP, sent|wparam, 1 },
525     { WM_NCACTIVATE, sent|wparam, 1 },
526     { WM_ACTIVATE, sent|wparam, 1 },
527     { HCBT_SETFOCUS, hook },
528     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
529     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
530     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
531     { WM_NCPAINT, sent|wparam|optional, 1 },
532     { WM_ERASEBKGND, sent|optional },
533     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE },
534     /* WinNT4.0 sends WM_MOVE */
535     { WM_MOVE, sent|defwinproc|optional },
536     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
537     { 0 }
538 };
539 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
540 static const struct message WmShowMaxPopupSeq[] = {
541     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
542     { WM_GETMINMAXINFO, sent },
543     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
544     { WM_NCCALCSIZE, sent|wparam, TRUE },
545     { HCBT_ACTIVATE, hook },
546     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
547     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
548     { WM_ACTIVATEAPP, sent|wparam, 1 },
549     { WM_NCACTIVATE, sent|wparam, 1 },
550     { WM_ACTIVATE, sent|wparam, 1 },
551     { HCBT_SETFOCUS, hook },
552     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
553     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
554     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
555     { WM_SYNCPAINT, sent|wparam|optional, 4 },
556     { WM_NCPAINT, sent|wparam|optional, 1 },
557     { WM_ERASEBKGND, sent|optional },
558     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
559     { 0 }
560 };
561 /* CreateWindow(WS_VISIBLE) for popup window */
562 static const struct message WmCreatePopupSeq[] = {
563     { HCBT_CREATEWND, hook },
564     { WM_NCCREATE, sent },
565     { WM_NCCALCSIZE, sent|wparam, 0 },
566     { WM_CREATE, sent },
567     { WM_SIZE, sent|wparam, SIZE_RESTORED },
568     { WM_MOVE, sent },
569     { WM_SHOWWINDOW, sent|wparam, 1 },
570     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
571     { HCBT_ACTIVATE, hook },
572     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
573     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
574     { WM_NCPAINT, sent|wparam|optional, 1 },
575     { WM_ERASEBKGND, sent|optional },
576     { WM_ACTIVATEAPP, sent|wparam, 1 },
577     { WM_NCACTIVATE, sent|wparam, 1 },
578     { WM_ACTIVATE, sent|wparam, 1 },
579     { HCBT_SETFOCUS, hook },
580     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
581     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
582     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
583     { WM_SYNCPAINT, sent|wparam|optional, 4 },
584     { WM_NCPAINT, sent|wparam|optional, 1 },
585     { WM_ERASEBKGND, sent|optional },
586     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
587     { 0 }
588 };
589 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
590 static const struct message WmShowVisMaxPopupSeq[] = {
591     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
592     { WM_GETMINMAXINFO, sent },
593     { WM_GETTEXT, sent|optional },
594     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
595     { WM_NCCALCSIZE, sent|wparam, TRUE },
596     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
597     { WM_NCPAINT, sent|wparam|optional, 1 },
598     { WM_ERASEBKGND, sent|optional },
599     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|0x8000 },
600     { WM_MOVE, sent|defwinproc },
601     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
602     { 0 }
603 };
604 /* CreateWindow (for a child popup window, not initially visible) */
605 static const struct message WmCreateChildPopupSeq[] = {
606     { HCBT_CREATEWND, hook },
607     { WM_NCCREATE, sent }, 
608     { WM_NCCALCSIZE, sent|wparam, 0 },
609     { WM_CREATE, sent },
610     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
611     { WM_SIZE, sent|wparam, SIZE_RESTORED },
612     { WM_MOVE, sent },
613     { 0 }
614 };
615 /* CreateWindow (for a popup window, not initially visible,
616  * which sets WS_VISIBLE in WM_CREATE handler)
617  */
618 static const struct message WmCreateInvisiblePopupSeq[] = {
619     { HCBT_CREATEWND, hook },
620     { WM_NCCREATE, sent }, 
621     { WM_NCCALCSIZE, sent|wparam, 0 },
622     { WM_CREATE, sent },
623     { WM_STYLECHANGING, sent },
624     { WM_STYLECHANGED, sent },
625     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
626     { WM_SIZE, sent|wparam, SIZE_RESTORED },
627     { WM_MOVE, sent },
628     { 0 }
629 };
630 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
631  * for a popup window with WS_VISIBLE style set
632  */
633 static const struct message WmShowVisiblePopupSeq_2[] = {
634     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
635     { 0 }
636 };
637 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
638  * for a popup window with WS_VISIBLE style set
639  */
640 static const struct message WmShowVisiblePopupSeq_3[] = {
641     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
642     { HCBT_ACTIVATE, hook },
643     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
644     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
645     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
646     { WM_NCACTIVATE, sent|wparam, 1 },
647     { WM_ACTIVATE, sent|wparam, 1 },
648     { HCBT_SETFOCUS, hook },
649     { WM_KILLFOCUS, sent|parent },
650     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
651     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
652     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
653     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
654     { WM_SETFOCUS, sent|defwinproc },
655     { 0 }
656 };
657 /* CreateWindow (for child window, not initially visible) */
658 static const struct message WmCreateChildSeq[] = {
659     { HCBT_CREATEWND, hook },
660     { WM_NCCREATE, sent }, 
661     /* child is inserted into parent's child list after WM_NCCREATE returns */
662     { WM_NCCALCSIZE, sent|wparam, 0 },
663     { WM_CREATE, sent },
664     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
665     { WM_SIZE, sent|wparam, SIZE_RESTORED },
666     { WM_MOVE, sent },
667     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
668     { 0 }
669 };
670 /* CreateWindow (for maximized child window, not initially visible) */
671 static const struct message WmCreateMaximizedChildSeq[] = {
672     { HCBT_CREATEWND, hook },
673     { WM_NCCREATE, sent }, 
674     { WM_NCCALCSIZE, sent|wparam, 0 },
675     { WM_CREATE, sent },
676     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
677     { WM_SIZE, sent|wparam, SIZE_RESTORED },
678     { WM_MOVE, sent },
679     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
680     { WM_GETMINMAXINFO, sent },
681     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
682     { WM_NCCALCSIZE, sent|wparam, 1 },
683     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|0x8000 },
684     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
685     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
686     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
687     { 0 }
688 };
689 /* CreateWindow (for a child window, initially visible) */
690 static const struct message WmCreateVisibleChildSeq[] = {
691     { HCBT_CREATEWND, hook },
692     { WM_NCCREATE, sent }, 
693     /* child is inserted into parent's child list after WM_NCCREATE returns */
694     { WM_NCCALCSIZE, sent|wparam, 0 },
695     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
696     { WM_CREATE, sent },
697     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
698     { WM_SIZE, sent|wparam, SIZE_RESTORED },
699     { WM_MOVE, sent },
700     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
701     { WM_SHOWWINDOW, sent|wparam, 1 },
702     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
703     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
704     { WM_ERASEBKGND, sent|parent|optional },
705     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
706     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
707     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
708     { 0 }
709 };
710 /* ShowWindow(SW_SHOW) for a not visible child window */
711 static const struct message WmShowChildSeq[] = {
712     { WM_SHOWWINDOW, sent|wparam, 1 },
713     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
714     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
715     { WM_ERASEBKGND, sent|parent|optional },
716     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
717     { 0 }
718 };
719 /* ShowWindow(SW_HIDE) for a visible child window */
720 static const struct message WmHideChildSeq[] = {
721     { WM_SHOWWINDOW, sent|wparam, 0 },
722     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
723     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
724     { WM_ERASEBKGND, sent|parent|optional },
725     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
726     { 0 }
727 };
728 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
729 static const struct message WmHideChildSeq2[] = {
730     { WM_SHOWWINDOW, sent|wparam, 0 },
731     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
732     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
733     { WM_ERASEBKGND, sent|parent },
734     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
735     { 0 }
736 };
737 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
738  * for a not visible child window
739  */
740 static const struct message WmShowChildSeq_2[] = {
741     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
742     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
743     { WM_CHILDACTIVATE, sent },
744     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
745     { 0 }
746 };
747 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
748  * for a not visible child window
749  */
750 static const struct message WmShowChildSeq_3[] = {
751     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
752     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
753     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
754     { 0 }
755 };
756 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
757  * for a visible child window with a caption
758  */
759 static const struct message WmShowChildSeq_4[] = {
760     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
761     { WM_CHILDACTIVATE, sent },
762     { 0 }
763 };
764 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
765 static const struct message WmShowChildInvisibleParentSeq_1[] = {
766     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
767     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|0x8000 },
768     { WM_NCCALCSIZE, sent|wparam, 1 },
769     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|0x8000 },
770     { WM_MOVE, sent|defwinproc },
771     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
772     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
773     /* FIXME: Wine creates an icon/title window while Windows doesn't */
774     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
775     { WM_GETTEXT, sent|optional },
776     { 0 }
777 };
778 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
779 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
780     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
781     { 0 }
782 };
783 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
784 static const struct message WmShowChildInvisibleParentSeq_2[] = {
785     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
786     { WM_GETMINMAXINFO, sent },
787     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
788     { WM_NCCALCSIZE, sent|wparam, 1 },
789     { WM_CHILDACTIVATE, sent },
790     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|0x8000 },
791     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
792     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
793     { 0 }
794 };
795 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
796 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
797     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
798     { 0 }
799 };
800 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
801 static const struct message WmShowChildInvisibleParentSeq_3[] = {
802     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
803     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
804     { WM_NCCALCSIZE, sent|wparam, 1 },
805     { WM_CHILDACTIVATE, sent },
806     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|0x8000 },
807     { WM_MOVE, sent|defwinproc },
808     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
809     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
810     /* FIXME: Wine creates an icon/title window while Windows doesn't */
811     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
812     { WM_GETTEXT, sent|optional },
813     { 0 }
814 };
815 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
816 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
817     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
818     { 0 }
819 };
820 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
821 static const struct message WmShowChildInvisibleParentSeq_4[] = {
822     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
823     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|0x8000 },
824     { WM_NCCALCSIZE, sent|wparam, 1 },
825     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|0x8000 },
826     { WM_MOVE, sent|defwinproc },
827     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
828     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
829     /* FIXME: Wine creates an icon/title window while Windows doesn't */
830     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
831     { WM_GETTEXT, sent|optional },
832     { 0 }
833 };
834 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
835 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
836     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
837     { 0 }
838 };
839 /* ShowWindow(SW_SHOW) for child with invisible parent */
840 static const struct message WmShowChildInvisibleParentSeq_5[] = {
841     { WM_SHOWWINDOW, sent|wparam, 1 },
842     { 0 }
843 };
844 /* ShowWindow(SW_HIDE) for child with invisible parent */
845 static const struct message WmHideChildInvisibleParentSeq[] = {
846     { WM_SHOWWINDOW, sent|wparam, 0 },
847     { 0 }
848 };
849 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
850 static const struct message WmShowChildInvisibleParentSeq_6[] = {
851     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
852     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
853     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
854     { 0 }
855 };
856 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
857 static const struct message WmHideChildInvisibleParentSeq_2[] = {
858     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
859     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
860     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
861     { 0 }
862 };
863 /* DestroyWindow for a visible child window */
864 static const struct message WmDestroyChildSeq[] = {
865     { HCBT_DESTROYWND, hook },
866     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
867     { WM_SHOWWINDOW, sent|wparam, 0 },
868     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
869     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
870     { WM_ERASEBKGND, sent|parent|optional },
871     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
872     { HCBT_SETFOCUS, hook }, /* set focus to a parent */
873     { WM_KILLFOCUS, sent },
874     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
875     { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
876     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
877     { WM_SETFOCUS, sent|parent },
878     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
879     { WM_DESTROY, sent },
880     { WM_DESTROY, sent|optional }, /* some other (IME?) window */
881     { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
882     { WM_NCDESTROY, sent },
883     { 0 }
884 };
885 /* DestroyWindow for a visible child window with invisible parent */
886 static const struct message WmDestroyInvisibleChildSeq[] = {
887     { HCBT_DESTROYWND, hook },
888     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
889     { WM_SHOWWINDOW, sent|wparam, 0 },
890     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
891     { WM_DESTROY, sent },
892     { WM_NCDESTROY, sent },
893     { 0 }
894 };
895 /* Moving the mouse in nonclient area */
896 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
897     { WM_NCHITTEST, sent },
898     { WM_SETCURSOR, sent },
899     { WM_NCMOUSEMOVE, posted },
900     { 0 }
901 };
902 /* Moving the mouse in client area */
903 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
904     { WM_NCHITTEST, sent },
905     { WM_SETCURSOR, sent },
906     { WM_MOUSEMOVE, posted },
907     { 0 }
908 };
909 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
910 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
911     { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
912     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
913     { WM_GETMINMAXINFO, sent|defwinproc },
914     { WM_ENTERSIZEMOVE, sent|defwinproc },
915     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
916     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
917     { WM_MOVE, sent|defwinproc },
918     { WM_EXITSIZEMOVE, sent|defwinproc },
919     { 0 }
920 };
921 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
922 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
923     { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
924     { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
925     { WM_GETMINMAXINFO, sent|defwinproc },
926     { WM_ENTERSIZEMOVE, sent|defwinproc },
927     { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
928     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
929     { WM_GETMINMAXINFO, sent|defwinproc },
930     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
931     { WM_NCPAINT, sent|defwinproc|wparam, 1 },
932     { WM_GETTEXT, sent|defwinproc },
933     { WM_ERASEBKGND, sent|defwinproc },
934     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
935     { WM_MOVE, sent|defwinproc },
936     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
937     { WM_EXITSIZEMOVE, sent|defwinproc },
938     { 0 }
939 };
940 /* Resizing child window with MoveWindow (32) */
941 static const struct message WmResizingChildWithMoveWindowSeq[] = {
942     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
943     { WM_NCCALCSIZE, sent|wparam, 1 },
944     { WM_ERASEBKGND, sent|parent|optional },
945     { WM_ERASEBKGND, sent|optional },
946     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
947     { WM_MOVE, sent|defwinproc },
948     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
949     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
950     { 0 }
951 };
952 /* Clicking on inactive button */
953 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
954     { WM_NCHITTEST, sent },
955     { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
956     { WM_MOUSEACTIVATE, sent },
957     { WM_MOUSEACTIVATE, sent|parent|defwinproc },
958     { WM_SETCURSOR, sent },
959     { WM_SETCURSOR, sent|parent|defwinproc },
960     { WM_LBUTTONDOWN, posted },
961     { WM_KILLFOCUS, posted|parent },
962     { WM_SETFOCUS, posted },
963     { WM_CTLCOLORBTN, posted|parent },
964     { BM_SETSTATE, posted },
965     { WM_CTLCOLORBTN, posted|parent },
966     { WM_LBUTTONUP, posted },
967     { BM_SETSTATE, posted },
968     { WM_CTLCOLORBTN, posted|parent },
969     { WM_COMMAND, posted|parent },
970     { 0 }
971 };
972 /* Reparenting a button (16/32) */
973 /* The last child (button) reparented gets topmost for its new parent. */
974 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
975     { WM_SHOWWINDOW, sent|wparam, 0 },
976     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
977     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
978     { WM_ERASEBKGND, sent|parent },
979     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
980     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
981     { WM_CHILDACTIVATE, sent },
982     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
983     { WM_MOVE, sent|defwinproc },
984     { WM_SHOWWINDOW, sent|wparam, 1 },
985     { 0 }
986 };
987 /* Creation of a custom dialog (32) */
988 static const struct message WmCreateCustomDialogSeq[] = {
989     { HCBT_CREATEWND, hook },
990     { WM_GETMINMAXINFO, sent },
991     { WM_NCCREATE, sent },
992     { WM_NCCALCSIZE, sent|wparam, 0 },
993     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
994     { WM_CREATE, sent },
995     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
996     { WM_SHOWWINDOW, sent|wparam, 1 },
997     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
998     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
999     { HCBT_ACTIVATE, hook },
1000     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1001
1002
1003     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1004
1005     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1006
1007     { WM_NCACTIVATE, sent|wparam, 1 },
1008     { WM_GETTEXT, sent|optional|defwinproc },
1009     { WM_GETTEXT, sent|optional|defwinproc },
1010     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1011     { WM_ACTIVATE, sent|wparam, 1 },
1012     { WM_KILLFOCUS, sent|parent },
1013     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1014     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1015     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1016     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1017     { WM_SETFOCUS, sent },
1018     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1019     { WM_NCPAINT, sent|wparam, 1 },
1020     { WM_GETTEXT, sent|optional|defwinproc },
1021     { WM_GETTEXT, sent|optional|defwinproc },
1022     { WM_ERASEBKGND, sent },
1023     { WM_CTLCOLORDLG, sent|defwinproc },
1024     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1025     { WM_GETTEXT, sent|optional },
1026     { WM_GETTEXT, sent|optional },
1027     { WM_NCCALCSIZE, sent|optional },
1028     { WM_NCPAINT, sent|optional },
1029     { WM_GETTEXT, sent|optional|defwinproc },
1030     { WM_GETTEXT, sent|optional|defwinproc },
1031     { WM_ERASEBKGND, sent|optional },
1032     { WM_CTLCOLORDLG, sent|optional|defwinproc },
1033     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1034     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1035     { WM_MOVE, sent },
1036     { 0 }
1037 };
1038 /* Calling EndDialog for a custom dialog (32) */
1039 static const struct message WmEndCustomDialogSeq[] = {
1040     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1041     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1042     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1043     { WM_GETTEXT, sent|optional },
1044     { HCBT_ACTIVATE, hook },
1045     { WM_NCACTIVATE, sent|wparam, 0 },
1046     { WM_GETTEXT, sent|optional|defwinproc },
1047     { WM_GETTEXT, sent|optional|defwinproc },
1048     { WM_ACTIVATE, sent|wparam, 0 },
1049     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1050     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1051     { HCBT_SETFOCUS, hook },
1052     { WM_KILLFOCUS, sent },
1053     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1054     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1055     { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1056     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1057     { WM_SETFOCUS, sent|parent|defwinproc },
1058     { 0 }
1059 };
1060 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1061 static const struct message WmShowCustomDialogSeq[] = {
1062     { WM_SHOWWINDOW, sent|wparam, 1 },
1063     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1064     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1065     { HCBT_ACTIVATE, hook },
1066     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1067
1068     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1069
1070     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1071     { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1072     { WM_NCACTIVATE, sent|wparam, 1 },
1073     { WM_ACTIVATE, sent|wparam, 1 },
1074
1075     { WM_KILLFOCUS, sent|parent },
1076     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1077     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1078     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1079     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1080     { WM_SETFOCUS, sent },
1081     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1082     { WM_NCPAINT, sent|wparam, 1 },
1083     { WM_ERASEBKGND, sent },
1084     { WM_CTLCOLORDLG, sent|defwinproc },
1085     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1086     { 0 }
1087 };
1088 /* Creation and destruction of a modal dialog (32) */
1089 static const struct message WmModalDialogSeq[] = {
1090     { WM_CANCELMODE, sent|parent },
1091     { HCBT_SETFOCUS, hook },
1092     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1093     { WM_KILLFOCUS, sent|parent },
1094     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1095     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1096     { WM_ENABLE, sent|parent|wparam, 0 },
1097     { HCBT_CREATEWND, hook },
1098     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1099     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1100     { WM_SETFONT, sent },
1101     { WM_INITDIALOG, sent },
1102     { WM_CHANGEUISTATE, sent|optional },
1103     { WM_UPDATEUISTATE, sent|optional },
1104     { WM_SHOWWINDOW, sent },
1105     { HCBT_ACTIVATE, hook },
1106     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1107     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1108     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1109     { WM_NCACTIVATE, sent|wparam, 1 },
1110     { WM_GETTEXT, sent|optional },
1111     { WM_ACTIVATE, sent|wparam, 1 },
1112     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1113     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1114     { WM_NCPAINT, sent },
1115     { WM_GETTEXT, sent|optional },
1116     { WM_ERASEBKGND, sent },
1117     { WM_CTLCOLORDLG, sent },
1118     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1119     { WM_GETTEXT, sent|optional },
1120     { WM_NCCALCSIZE, sent|optional },
1121     { WM_NCPAINT, sent|optional },
1122     { WM_GETTEXT, sent|optional },
1123     { WM_ERASEBKGND, sent|optional },
1124     { WM_CTLCOLORDLG, sent|optional },
1125     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1126     { WM_PAINT, sent|optional },
1127     { WM_CTLCOLORBTN, sent },
1128     { WM_ENTERIDLE, sent|parent|optional },
1129     { WM_ENTERIDLE, sent|parent|optional },
1130     { WM_ENTERIDLE, sent|parent|optional },
1131     { WM_ENTERIDLE, sent|parent|optional },
1132     { WM_ENTERIDLE, sent|parent|optional },
1133     { WM_ENTERIDLE, sent|parent|optional },
1134     { WM_ENTERIDLE, sent|parent|optional },
1135     { WM_ENTERIDLE, sent|parent|optional },
1136     { WM_ENTERIDLE, sent|parent|optional },
1137     { WM_ENTERIDLE, sent|parent|optional },
1138     { WM_ENTERIDLE, sent|parent|optional },
1139     { WM_ENTERIDLE, sent|parent|optional },
1140     { WM_ENTERIDLE, sent|parent|optional },
1141     { WM_ENTERIDLE, sent|parent|optional },
1142     { WM_ENTERIDLE, sent|parent|optional },
1143     { WM_ENTERIDLE, sent|parent|optional },
1144     { WM_ENTERIDLE, sent|parent|optional },
1145     { WM_ENTERIDLE, sent|parent|optional },
1146     { WM_ENTERIDLE, sent|parent|optional },
1147     { WM_ENTERIDLE, sent|parent|optional },
1148     { WM_TIMER, sent },
1149     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1150     { WM_ENABLE, sent|parent|wparam, 1 },
1151     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1152     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1153     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1154     { WM_GETTEXT, sent|optional },
1155     { HCBT_ACTIVATE, hook },
1156     { WM_NCACTIVATE, sent|wparam, 0 },
1157     { WM_GETTEXT, sent|optional },
1158     { WM_ACTIVATE, sent|wparam, 0 },
1159     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1160     { WM_WINDOWPOSCHANGING, sent|optional },
1161     { HCBT_SETFOCUS, hook },
1162     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1163     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1164     { WM_SETFOCUS, sent|parent|defwinproc },
1165     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1166     { HCBT_DESTROYWND, hook },
1167     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1168     { WM_DESTROY, sent },
1169     { WM_NCDESTROY, sent },
1170     { 0 }
1171 };
1172 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1173 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1174     /* (inside dialog proc, handling WM_INITDIALOG) */
1175     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1176     { WM_NCCALCSIZE, sent },
1177     { WM_NCACTIVATE, sent|parent|wparam, 0 },
1178     { WM_GETTEXT, sent|defwinproc },
1179     { WM_ACTIVATE, sent|parent|wparam, 0 },
1180     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1181     { WM_WINDOWPOSCHANGING, sent|parent },
1182     { WM_NCACTIVATE, sent|wparam, 1 },
1183     { WM_ACTIVATE, sent|wparam, 1 },
1184     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1185     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1186     /* (setting focus) */
1187     { WM_SHOWWINDOW, sent|wparam, 1 },
1188     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1189     { WM_NCPAINT, sent },
1190     { WM_GETTEXT, sent|defwinproc },
1191     { WM_ERASEBKGND, sent },
1192     { WM_CTLCOLORDLG, sent|defwinproc },
1193     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1194     { WM_PAINT, sent },
1195     /* (bunch of WM_CTLCOLOR* for each control) */
1196     { WM_PAINT, sent|parent },
1197     { WM_ENTERIDLE, sent|parent|wparam, 0 },
1198     { WM_SETCURSOR, sent|parent },
1199     { 0 }
1200 };
1201 /* SetMenu for NonVisible windows with size change*/
1202 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1203     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1204     { WM_NCCALCSIZE, sent|wparam, 1 },
1205     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1206     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1207     { WM_MOVE, sent|defwinproc },
1208     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1209     { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1210     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1211     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1212     { WM_GETTEXT, sent|optional },
1213     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1214     { 0 }
1215 };
1216 /* SetMenu for NonVisible windows with no size change */
1217 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1218     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1219     { WM_NCCALCSIZE, sent|wparam, 1 },
1220     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1221     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1222     { 0 }
1223 };
1224 /* SetMenu for Visible windows with size change */
1225 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1226     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1227     { WM_NCCALCSIZE, sent|wparam, 1 },
1228     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1229     { WM_NCPAINT, sent }, /* wparam != 1 */
1230     { WM_GETTEXT, sent|defwinproc|optional },
1231     { WM_ERASEBKGND, sent|optional },
1232     { WM_ACTIVATE, sent|optional },
1233     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1234     { WM_MOVE, sent|defwinproc },
1235     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1236     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1237     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1238     { WM_ERASEBKGND, sent|optional },
1239     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1240     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1241     { 0 }
1242 };
1243 /* SetMenu for Visible windows with no size change */
1244 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1245     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1246     { WM_NCCALCSIZE, sent|wparam, 1 },
1247     { WM_NCPAINT, sent }, /* wparam != 1 */
1248     { WM_GETTEXT, sent|defwinproc|optional },
1249     { WM_ERASEBKGND, sent|optional },
1250     { WM_ACTIVATE, sent|optional },
1251     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1252     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1253     { 0 }
1254 };
1255 /* DrawMenuBar for a visible window */
1256 static const struct message WmDrawMenuBarSeq[] =
1257 {
1258     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1259     { WM_NCCALCSIZE, sent|wparam, 1 },
1260     { WM_NCPAINT, sent }, /* wparam != 1 */
1261     { WM_GETTEXT, sent|defwinproc|optional },
1262     { WM_ERASEBKGND, sent|optional },
1263     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1264     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1265     { 0 }
1266 };
1267
1268 static const struct message WmSetRedrawFalseSeq[] =
1269 {
1270     { WM_SETREDRAW, sent|wparam, 0 },
1271     { 0 }
1272 };
1273
1274 static const struct message WmSetRedrawTrueSeq[] =
1275 {
1276     { WM_SETREDRAW, sent|wparam, 1 },
1277     { 0 }
1278 };
1279
1280 static const struct message WmEnableWindowSeq_1[] =
1281 {
1282     { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1283     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1284     { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1285     { 0 }
1286 };
1287
1288 static const struct message WmEnableWindowSeq_2[] =
1289 {
1290     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1291     { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1292     { 0 }
1293 };
1294
1295 static const struct message WmGetScrollRangeSeq[] =
1296 {
1297     { SBM_GETRANGE, sent },
1298     { 0 }
1299 };
1300 static const struct message WmGetScrollInfoSeq[] =
1301 {
1302     { SBM_GETSCROLLINFO, sent },
1303     { 0 }
1304 };
1305 static const struct message WmSetScrollRangeSeq[] =
1306 {
1307     /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1308        sends SBM_SETSCROLLINFO.
1309      */
1310     { SBM_SETSCROLLINFO, sent },
1311     { 0 }
1312 };
1313 /* SetScrollRange for a window without a non-client area */
1314 static const struct message WmSetScrollRangeHSeq_empty[] =
1315 {
1316     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1317     { 0 }
1318 };
1319 static const struct message WmSetScrollRangeVSeq_empty[] =
1320 {
1321     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1322     { 0 }
1323 };
1324 static const struct message WmSetScrollRangeHVSeq[] =
1325 {
1326     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1327     { WM_NCCALCSIZE, sent|wparam, 1 },
1328     { WM_GETTEXT, sent|defwinproc|optional },
1329     { WM_ERASEBKGND, sent|optional },
1330     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1331     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1332     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1333     { 0 }
1334 };
1335 /* SetScrollRange for a window with a non-client area */
1336 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1337 {
1338     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1339     { WM_NCCALCSIZE, sent|wparam, 1 },
1340     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1341     { WM_NCPAINT, sent|optional },
1342     { WM_GETTEXT, sent|defwinproc|optional },
1343     { WM_GETTEXT, sent|defwinproc|optional },
1344     { WM_ERASEBKGND, sent|optional },
1345     { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1346     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE },
1347     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1348     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1349     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1350     { WM_GETTEXT, sent|optional },
1351     { WM_GETTEXT, sent|optional },
1352     { WM_GETTEXT, sent|optional },
1353     { WM_GETTEXT, sent|optional },
1354     { 0 }
1355 };
1356 /* test if we receive the right sequence of messages */
1357 /* after calling ShowWindow( SW_SHOWNA) */
1358 static const struct message WmSHOWNAChildInvisParInvis[] = {
1359     { WM_SHOWWINDOW, sent|wparam, 1 },
1360     { 0 }
1361 };
1362 static const struct message WmSHOWNAChildVisParInvis[] = {
1363     { WM_SHOWWINDOW, sent|wparam, 1 },
1364     { 0 }
1365 };
1366 static const struct message WmSHOWNAChildVisParVis[] = {
1367     { WM_SHOWWINDOW, sent|wparam, 1 },
1368     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1369     { 0 }
1370 };
1371 static const struct message WmSHOWNAChildInvisParVis[] = {
1372     { WM_SHOWWINDOW, sent|wparam, 1 },
1373     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1374     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1375     { WM_ERASEBKGND, sent|optional },
1376     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1377     { 0 }
1378 };
1379 static const struct message WmSHOWNATopVisible[] = {
1380     { WM_SHOWWINDOW, sent|wparam, 1 },
1381     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1382     { 0 }
1383 };
1384 static const struct message WmSHOWNATopInvisible[] = {
1385     { WM_SHOWWINDOW, sent|wparam, 1 },
1386     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1387     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1388     { WM_NCPAINT, sent|wparam, 1 },
1389     { WM_GETTEXT, sent|defwinproc|optional },
1390     { WM_ERASEBKGND, sent|optional },
1391     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1392     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1393     { WM_NCPAINT, sent|wparam|optional, 1 },
1394     { WM_ERASEBKGND, sent|optional },
1395     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1396     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1397     { WM_MOVE, sent },
1398     { 0 }
1399 };
1400
1401 static int after_end_dialog, test_def_id;
1402 static int sequence_cnt, sequence_size;
1403 static struct message* sequence;
1404 static int log_all_parent_messages;
1405
1406 /* user32 functions */
1407 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1408 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1409 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1410 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1411 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1412 /* kernel32 functions */
1413 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1414
1415 static void init_procs(void)
1416 {
1417     HMODULE user32 = GetModuleHandleA("user32.dll");
1418     HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1419
1420 #define GET_PROC(dll, func) \
1421     p ## func = (void*)GetProcAddress(dll, #func); \
1422     if(!p ## func) { \
1423       trace("GetProcAddress(%s) failed\n", #func); \
1424     }
1425
1426     GET_PROC(user32, GetAncestor)
1427     GET_PROC(user32, NotifyWinEvent)
1428     GET_PROC(user32, SetWinEventHook)
1429     GET_PROC(user32, TrackMouseEvent)
1430     GET_PROC(user32, UnhookWinEvent)
1431
1432     GET_PROC(kernel32, GetCPInfoExA)
1433
1434 #undef GET_PROC
1435 }
1436
1437 static void add_message(const struct message *msg)
1438 {
1439     if (!sequence) 
1440     {
1441         sequence_size = 10;
1442         sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof (struct message) );
1443     }
1444     if (sequence_cnt == sequence_size) 
1445     {
1446         sequence_size *= 2;
1447         sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof (struct message) );
1448     }
1449     assert(sequence);
1450
1451     sequence[sequence_cnt].message = msg->message;
1452     sequence[sequence_cnt].flags = msg->flags;
1453     sequence[sequence_cnt].wParam = msg->wParam;
1454     sequence[sequence_cnt].lParam = msg->lParam;
1455
1456     sequence_cnt++;
1457 }
1458
1459 /* try to make sure pending X events have been processed before continuing */
1460 static void flush_events(void)
1461 {
1462     MSG msg;
1463     int diff = 100;
1464     DWORD time = GetTickCount() + diff;
1465
1466     while (diff > 0)
1467     {
1468         if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min(10,diff), QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1469         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1470         diff = time - GetTickCount();
1471     }
1472 }
1473
1474 static void flush_sequence(void)
1475 {
1476     HeapFree(GetProcessHeap(), 0, sequence);
1477     sequence = 0;
1478     sequence_cnt = sequence_size = 0;
1479 }
1480
1481 #define ok_sequence( exp, contx, todo) \
1482         ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
1483
1484
1485 static void ok_sequence_(const struct message *expected, const char *context, int todo,
1486         const char *file, int line)
1487 {
1488     static const struct message end_of_sequence = { 0, 0, 0, 0 };
1489     const struct message *actual;
1490     int failcount = 0;
1491     
1492     add_message(&end_of_sequence);
1493
1494     actual = sequence;
1495
1496     while (expected->message && actual->message)
1497     {
1498         trace_( file, line)("expected %04x - actual %04x\n", expected->message, actual->message);
1499
1500         if (expected->message == actual->message)
1501         {
1502             if (expected->flags & wparam)
1503             {
1504                 if (expected->wParam != actual->wParam && todo)
1505                 {
1506                     todo_wine {
1507                         failcount ++;
1508                         ok_( file, line) (FALSE,
1509                             "%s: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1510                             context, expected->message, expected->wParam, actual->wParam);
1511                     }
1512                 }
1513                 else
1514                 ok_( file, line) (expected->wParam == actual->wParam,
1515                      "%s: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1516                      context, expected->message, expected->wParam, actual->wParam);
1517             }
1518             if (expected->flags & lparam)
1519             {
1520                 if (expected->lParam != actual->lParam && todo)
1521                 {
1522                     todo_wine {
1523                         failcount ++;
1524                         ok_( file, line) (FALSE,
1525                             "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1526                             context, expected->message, expected->lParam, actual->lParam);
1527                     }
1528                 }
1529                 else
1530                  ok_( file, line) (expected->lParam == actual->lParam,
1531                      "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1532                      context, expected->message, expected->lParam, actual->lParam);
1533             }
1534             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
1535             {
1536                     todo_wine {
1537                         failcount ++;
1538                         ok_( file, line) (FALSE,
1539                             "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1540                             context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1541                     }
1542             }
1543             else
1544                 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
1545                     "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1546                     context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1547             ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
1548                 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
1549                 context, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
1550             ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
1551                 "%s: the msg 0x%04x should have been %s\n",
1552                 context, expected->message, (expected->flags & posted) ? "posted" : "sent");
1553             ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
1554                 "%s: the msg 0x%04x was expected in %s\n",
1555                 context, expected->message, (expected->flags & parent) ? "parent" : "child");
1556             ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
1557                 "%s: the msg 0x%04x should have been sent by a hook\n",
1558                 context, expected->message);
1559             ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
1560                 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
1561                 context, expected->message);
1562             expected++;
1563             actual++;
1564         }
1565         /* silently drop winevent messages if there is no support for them */
1566         else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1567             expected++;
1568         else if (todo)
1569         {
1570             failcount++;
1571             todo_wine {
1572                 ok_( file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
1573                     context, expected->message, actual->message);
1574             }
1575             flush_sequence();
1576             return;
1577         }
1578         else
1579         {
1580             ok_( file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
1581                 context, expected->message, actual->message);
1582             expected++;
1583             actual++;
1584         }
1585     }
1586
1587     /* skip all optional trailing messages */
1588     while (expected->message && ((expected->flags & optional) ||
1589             ((expected->flags & winevent_hook) && !hEvent_hook)))
1590         expected++;
1591
1592     if (todo)
1593     {
1594         todo_wine {
1595             if (expected->message || actual->message) {
1596                 failcount++;
1597                 ok_( file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
1598                     context, expected->message, actual->message);
1599             }
1600         }
1601     }
1602     else
1603     {
1604         if (expected->message || actual->message)
1605             ok_( file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
1606                 context, expected->message, actual->message);
1607     }
1608     if( todo && !failcount) /* succeeded yet marked todo */
1609         todo_wine {
1610             ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
1611         }
1612
1613     flush_sequence();
1614 }
1615
1616 /******************************** MDI test **********************************/
1617
1618 /* CreateWindow for MDI frame window, initially visible */
1619 static const struct message WmCreateMDIframeSeq[] = {
1620     { HCBT_CREATEWND, hook },
1621     { WM_GETMINMAXINFO, sent },
1622     { WM_NCCREATE, sent },
1623     { WM_NCCALCSIZE, sent|wparam, 0 },
1624     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1625     { WM_CREATE, sent },
1626     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1627     { WM_SHOWWINDOW, sent|wparam, 1 },
1628     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1629     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1630     { HCBT_ACTIVATE, hook },
1631     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1632     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1633     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
1634     { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
1635     { WM_NCACTIVATE, sent|wparam, 1 },
1636     { WM_GETTEXT, sent|defwinproc|optional },
1637     { WM_ACTIVATE, sent|wparam, 1 },
1638     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
1639     { HCBT_SETFOCUS, hook },
1640     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1641     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1642     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1643     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
1644     /* Win9x adds SWP_NOZORDER below */
1645     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1646     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
1647     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1648     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1649     { WM_MOVE, sent },
1650     { 0 }
1651 };
1652 /* DestroyWindow for MDI frame window, initially visible */
1653 static const struct message WmDestroyMDIframeSeq[] = {
1654     { HCBT_DESTROYWND, hook },
1655     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1656     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1657     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
1658     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1659     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
1660     { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
1661     { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
1662     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
1663     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1664     { WM_DESTROY, sent },
1665     { WM_NCDESTROY, sent },
1666     { 0 }
1667 };
1668 /* CreateWindow for MDI client window, initially visible */
1669 static const struct message WmCreateMDIclientSeq[] = {
1670     { HCBT_CREATEWND, hook },
1671     { WM_NCCREATE, sent },
1672     { WM_NCCALCSIZE, sent|wparam, 0 },
1673     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
1674     { WM_CREATE, sent },
1675     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
1676     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1677     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1678     { WM_MOVE, sent },
1679     { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
1680     { WM_SHOWWINDOW, sent|wparam, 1 },
1681     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1682     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1683     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1684     { 0 }
1685 };
1686 /* ShowWindow(SW_SHOW) for MDI client window */
1687 static const struct message WmShowMDIclientSeq[] = {
1688     { WM_SHOWWINDOW, sent|wparam, 1 },
1689     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1690     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1691     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1692     { 0 }
1693 };
1694 /* ShowWindow(SW_HIDE) for MDI client window */
1695 static const struct message WmHideMDIclientSeq[] = {
1696     { WM_SHOWWINDOW, sent|wparam, 0 },
1697     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1698     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
1699     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
1700     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1701     { 0 }
1702 };
1703 /* DestroyWindow for MDI client window, initially visible */
1704 static const struct message WmDestroyMDIclientSeq[] = {
1705     { HCBT_DESTROYWND, hook },
1706     { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
1707     { WM_SHOWWINDOW, sent|wparam, 0 },
1708     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1709     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1710     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1711     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1712     { WM_DESTROY, sent },
1713     { WM_NCDESTROY, sent },
1714     { 0 }
1715 };
1716 /* CreateWindow for MDI child window, initially visible */
1717 static const struct message WmCreateMDIchildVisibleSeq[] = {
1718     { HCBT_CREATEWND, hook },
1719     { WM_NCCREATE, sent }, 
1720     { WM_NCCALCSIZE, sent|wparam, 0 },
1721     { WM_CREATE, sent },
1722     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1723     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1724     { WM_MOVE, sent },
1725     /* Win2k sends wparam set to
1726      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1727      * while Win9x doesn't bother to set child window id according to
1728      * CLIENTCREATESTRUCT.idFirstChild
1729      */
1730     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
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     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1736     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1737     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1738     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1739
1740     /* Win9x: message sequence terminates here. */
1741
1742     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1743     { HCBT_SETFOCUS, hook }, /* in MDI client */
1744     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1745     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
1746     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1747     { WM_SETFOCUS, sent }, /* in MDI client */
1748     { HCBT_SETFOCUS, hook },
1749     { WM_KILLFOCUS, sent }, /* in MDI client */
1750     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1751     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1752     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1753     { WM_SETFOCUS, sent|defwinproc },
1754     { WM_MDIACTIVATE, sent|defwinproc },
1755     { 0 }
1756 };
1757 /* CreateWindow for MDI child window with invisible parent */
1758 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
1759     { HCBT_CREATEWND, hook },
1760     { WM_GETMINMAXINFO, sent },
1761     { WM_NCCREATE, sent }, 
1762     { WM_NCCALCSIZE, sent|wparam, 0 },
1763     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
1764     { WM_CREATE, sent },
1765     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1766     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1767     { WM_MOVE, sent },
1768     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1769     { WM_SHOWWINDOW, sent|wparam, 1 },
1770     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
1771     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1772     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1773     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1774
1775     /* Win9x: message sequence terminates here. */
1776
1777     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1778     { HCBT_SETFOCUS, hook }, /* in MDI client */
1779     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1780     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
1781     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1782     { WM_SETFOCUS, sent }, /* in MDI client */
1783     { HCBT_SETFOCUS, hook },
1784     { WM_KILLFOCUS, sent }, /* in MDI client */
1785     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1786     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1787     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1788     { WM_SETFOCUS, sent|defwinproc },
1789     { WM_MDIACTIVATE, sent|defwinproc },
1790     { 0 }
1791 };
1792 /* DestroyWindow for MDI child window, initially visible */
1793 static const struct message WmDestroyMDIchildVisibleSeq[] = {
1794     { HCBT_DESTROYWND, hook },
1795     /* Win2k sends wparam set to
1796      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1797      * while Win9x doesn't bother to set child window id according to
1798      * CLIENTCREATESTRUCT.idFirstChild
1799      */
1800     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1801     { WM_SHOWWINDOW, sent|wparam, 0 },
1802     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1803     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1804     { WM_ERASEBKGND, sent|parent|optional },
1805     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1806
1807     /* { WM_DESTROY, sent }
1808      * Win9x: message sequence terminates here.
1809      */
1810
1811     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1812     { WM_KILLFOCUS, sent },
1813     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1814     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1815     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1816     { WM_SETFOCUS, sent }, /* in MDI client */
1817
1818     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1819     { WM_KILLFOCUS, sent }, /* in MDI client */
1820     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1821     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1822     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1823     { WM_SETFOCUS, sent }, /* in MDI client */
1824
1825     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1826
1827     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1828     { WM_KILLFOCUS, sent },
1829     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1830     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1831     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1832     { WM_SETFOCUS, sent }, /* in MDI client */
1833
1834     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1835     { WM_KILLFOCUS, sent }, /* in MDI client */
1836     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1837     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1838     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1839     { WM_SETFOCUS, sent }, /* in MDI client */
1840
1841     { WM_DESTROY, sent },
1842
1843     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1844     { WM_KILLFOCUS, sent },
1845     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1846     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1847     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1848     { WM_SETFOCUS, sent }, /* in MDI client */
1849
1850     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1851     { WM_KILLFOCUS, sent }, /* in MDI client */
1852     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1853     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1854     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1855     { WM_SETFOCUS, sent }, /* in MDI client */
1856
1857     { WM_NCDESTROY, sent },
1858     { 0 }
1859 };
1860 /* CreateWindow for MDI child window, initially invisible */
1861 static const struct message WmCreateMDIchildInvisibleSeq[] = {
1862     { HCBT_CREATEWND, hook },
1863     { WM_NCCREATE, sent }, 
1864     { WM_NCCALCSIZE, sent|wparam, 0 },
1865     { WM_CREATE, sent },
1866     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1867     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1868     { WM_MOVE, sent },
1869     /* Win2k sends wparam set to
1870      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1871      * while Win9x doesn't bother to set child window id according to
1872      * CLIENTCREATESTRUCT.idFirstChild
1873      */
1874     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1875     { 0 }
1876 };
1877 /* DestroyWindow for MDI child window, initially invisible */
1878 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
1879     { HCBT_DESTROYWND, hook },
1880     /* Win2k sends wparam set to
1881      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1882      * while Win9x doesn't bother to set child window id according to
1883      * CLIENTCREATESTRUCT.idFirstChild
1884      */
1885     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1886     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1887     { WM_DESTROY, sent },
1888     { WM_NCDESTROY, sent },
1889     /* FIXME: Wine destroys an icon/title window while Windows doesn't */
1890     { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
1891     { 0 }
1892 };
1893 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
1894 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
1895     { HCBT_CREATEWND, hook },
1896     { WM_NCCREATE, sent }, 
1897     { WM_NCCALCSIZE, sent|wparam, 0 },
1898     { WM_CREATE, sent },
1899     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1900     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1901     { WM_MOVE, sent },
1902     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1903     { WM_GETMINMAXINFO, sent },
1904     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
1905     { WM_NCCALCSIZE, sent|wparam, 1 },
1906     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1907     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
1908      /* in MDI frame */
1909     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1910     { WM_NCCALCSIZE, sent|wparam, 1 },
1911     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1912     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1913     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1914     /* Win2k sends wparam set to
1915      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1916      * while Win9x doesn't bother to set child window id according to
1917      * CLIENTCREATESTRUCT.idFirstChild
1918      */
1919     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1920     { WM_SHOWWINDOW, sent|wparam, 1 },
1921     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1922     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1923     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1924     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1925     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1926     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1927     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1928
1929     /* Win9x: message sequence terminates here. */
1930
1931     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1932     { HCBT_SETFOCUS, hook }, /* in MDI client */
1933     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1934     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
1935     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1936     { WM_SETFOCUS, sent }, /* in MDI client */
1937     { HCBT_SETFOCUS, hook },
1938     { WM_KILLFOCUS, sent }, /* in MDI client */
1939     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1940     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1941     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1942     { WM_SETFOCUS, sent|defwinproc },
1943     { WM_MDIACTIVATE, sent|defwinproc },
1944      /* in MDI frame */
1945     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1946     { WM_NCCALCSIZE, sent|wparam, 1 },
1947     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1948     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1949     { 0 }
1950 };
1951 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
1952 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
1953     /* restore the 1st MDI child */
1954     { WM_SETREDRAW, sent|wparam, 0 },
1955     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
1956     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
1957     { WM_NCCALCSIZE, sent|wparam, 1 },
1958     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1959     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1960     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1961      /* in MDI frame */
1962     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1963     { WM_NCCALCSIZE, sent|wparam, 1 },
1964     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1965     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1966     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1967     { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
1968     /* create the 2nd MDI child */
1969     { HCBT_CREATEWND, hook },
1970     { WM_NCCREATE, sent }, 
1971     { WM_NCCALCSIZE, sent|wparam, 0 },
1972     { WM_CREATE, sent },
1973     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1974     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1975     { WM_MOVE, sent },
1976     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1977     { WM_GETMINMAXINFO, sent },
1978     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
1979     { WM_NCCALCSIZE, sent|wparam, 1 },
1980     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1981     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1982     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
1983      /* in MDI frame */
1984     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1985     { WM_NCCALCSIZE, sent|wparam, 1 },
1986     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1987     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1988     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1989     /* Win2k sends wparam set to
1990      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1991      * while Win9x doesn't bother to set child window id according to
1992      * CLIENTCREATESTRUCT.idFirstChild
1993      */
1994     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1995     { WM_SHOWWINDOW, sent|wparam, 1 },
1996     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1997     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1998     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1999     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2000     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2001     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2002
2003     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2004     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2005
2006     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2007
2008     /* Win9x: message sequence terminates here. */
2009
2010     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2011     { HCBT_SETFOCUS, hook },
2012     { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
2013     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2014     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2015     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2016     { WM_SETFOCUS, sent }, /* in MDI client */
2017     { HCBT_SETFOCUS, hook },
2018     { WM_KILLFOCUS, sent }, /* in MDI client */
2019     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2020     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2021     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2022     { WM_SETFOCUS, sent|defwinproc },
2023
2024     { WM_MDIACTIVATE, sent|defwinproc },
2025      /* in MDI frame */
2026     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2027     { WM_NCCALCSIZE, sent|wparam, 1 },
2028     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2029     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2030     { 0 }
2031 };
2032 /* WM_MDICREATE MDI child window, initially visible and maximized */
2033 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2034     { WM_MDICREATE, sent },
2035     { HCBT_CREATEWND, hook },
2036     { WM_NCCREATE, sent }, 
2037     { WM_NCCALCSIZE, sent|wparam, 0 },
2038     { WM_CREATE, sent },
2039     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2040     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2041     { WM_MOVE, sent },
2042     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2043     { WM_GETMINMAXINFO, sent },
2044     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
2045     { WM_NCCALCSIZE, sent|wparam, 1 },
2046     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2047     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2048
2049      /* in MDI frame */
2050     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2051     { WM_NCCALCSIZE, sent|wparam, 1 },
2052     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2053     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2054     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2055
2056     /* Win2k sends wparam set to
2057      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2058      * while Win9x doesn't bother to set child window id according to
2059      * CLIENTCREATESTRUCT.idFirstChild
2060      */
2061     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2062     { WM_SHOWWINDOW, sent|wparam, 1 },
2063     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2064
2065     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2066
2067     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2068     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2069     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2070
2071     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2072     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2073
2074     /* Win9x: message sequence terminates here. */
2075
2076     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2077     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2078     { HCBT_SETFOCUS, hook }, /* in MDI client */
2079     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2080     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2081     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2082     { HCBT_SETFOCUS, hook|optional },
2083     { WM_KILLFOCUS, sent }, /* in MDI client */
2084     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2085     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2086     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2087     { WM_SETFOCUS, sent|defwinproc },
2088
2089     { WM_MDIACTIVATE, sent|defwinproc },
2090
2091      /* in MDI child */
2092     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2093     { WM_NCCALCSIZE, sent|wparam, 1 },
2094     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2095     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2096
2097      /* in MDI frame */
2098     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2099     { WM_NCCALCSIZE, sent|wparam, 1 },
2100     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2101     { WM_MOVE, sent|defwinproc },
2102     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2103
2104      /* in MDI client */
2105     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2106     { WM_NCCALCSIZE, sent|wparam, 1 },
2107     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2108     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2109
2110      /* in MDI child */
2111     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2112     { WM_NCCALCSIZE, sent|wparam, 1 },
2113     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2114     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2115
2116     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2117     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2118     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2119     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2120     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2121
2122     { 0 }
2123 };
2124 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2125 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2126     { HCBT_CREATEWND, hook },
2127     { WM_GETMINMAXINFO, sent },
2128     { WM_NCCREATE, sent }, 
2129     { WM_NCCALCSIZE, sent|wparam, 0 },
2130     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2131     { WM_CREATE, sent },
2132     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2133     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2134     { WM_MOVE, sent },
2135     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2136     { WM_GETMINMAXINFO, sent },
2137     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
2138     { WM_GETMINMAXINFO, sent|defwinproc },
2139     { WM_NCCALCSIZE, sent|wparam, 1 },
2140     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|0x8000 },
2141     { WM_MOVE, sent|defwinproc },
2142     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2143      /* in MDI frame */
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 }, /* MDI frame */
2148     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2149     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2150     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2151     /* Win2k sends wparam set to
2152      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2153      * while Win9x doesn't bother to set child window id according to
2154      * CLIENTCREATESTRUCT.idFirstChild
2155      */
2156     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2157     { 0 }
2158 };
2159 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2160 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2161     { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2162     { HCBT_SYSCOMMAND, hook },
2163     { WM_CLOSE, sent|defwinproc },
2164     { WM_MDIDESTROY, sent }, /* in MDI client */
2165
2166     /* bring the 1st MDI child to top */
2167     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2168     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2169
2170     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2171
2172     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2173     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2174     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2175
2176     /* maximize the 1st MDI child */
2177     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2178     { WM_GETMINMAXINFO, sent|defwinproc },
2179     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|0x8000 },
2180     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2181     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2182     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2183     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2184
2185     /* restore the 2nd MDI child */
2186     { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2187     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2188     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|0x8000 },
2189     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2190
2191     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2192
2193     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2194     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2195
2196     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2197
2198     { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2199      /* in MDI frame */
2200     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2201     { WM_NCCALCSIZE, sent|wparam, 1 },
2202     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2203     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2204     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2205
2206     /* bring the 1st MDI child to top */
2207     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2208     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2209     { HCBT_SETFOCUS, hook },
2210     { WM_KILLFOCUS, sent|defwinproc },
2211     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2212     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2213     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2214     { WM_SETFOCUS, sent }, /* in MDI client */
2215     { HCBT_SETFOCUS, hook },
2216     { WM_KILLFOCUS, sent }, /* in MDI client */
2217     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2218     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2219     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2220     { WM_SETFOCUS, sent|defwinproc },
2221     { WM_MDIACTIVATE, sent|defwinproc },
2222     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2223
2224     /* apparently ShowWindow(SW_SHOW) on an MDI client */
2225     { WM_SHOWWINDOW, sent|wparam, 1 },
2226     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2227     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2228     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2229     { WM_MDIREFRESHMENU, sent },
2230
2231     { HCBT_DESTROYWND, hook },
2232     /* Win2k sends wparam set to
2233      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2234      * while Win9x doesn't bother to set child window id according to
2235      * CLIENTCREATESTRUCT.idFirstChild
2236      */
2237     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2238     { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2239     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2240     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2241     { WM_ERASEBKGND, sent|parent|optional },
2242     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2243
2244     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2245     { WM_DESTROY, sent|defwinproc },
2246     { WM_NCDESTROY, sent|defwinproc },
2247     { 0 }
2248 };
2249 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2250 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2251     { WM_MDIDESTROY, sent }, /* in MDI client */
2252     { WM_SHOWWINDOW, sent|wparam, 0 },
2253     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2254     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2255     { WM_ERASEBKGND, sent|parent|optional },
2256     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2257
2258     { HCBT_SETFOCUS, hook },
2259     { WM_KILLFOCUS, sent },
2260     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2261     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2262     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2263     { WM_SETFOCUS, sent }, /* in MDI client */
2264     { HCBT_SETFOCUS, hook },
2265     { WM_KILLFOCUS, sent }, /* in MDI client */
2266     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2267     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2268     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2269     { WM_SETFOCUS, sent },
2270
2271      /* in MDI child */
2272     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2273     { WM_NCCALCSIZE, sent|wparam, 1 },
2274     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2275     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2276
2277      /* in MDI frame */
2278     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2279     { WM_NCCALCSIZE, sent|wparam, 1 },
2280     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2281     { WM_MOVE, sent|defwinproc },
2282     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2283
2284      /* in MDI client */
2285     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2286     { WM_NCCALCSIZE, sent|wparam, 1 },
2287     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2288     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2289
2290      /* in MDI child */
2291     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2292     { WM_NCCALCSIZE, sent|wparam, 1 },
2293     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2294     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2295
2296      /* in MDI child */
2297     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2298     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2299     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2300     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2301
2302      /* in MDI frame */
2303     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2304     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2305     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2306     { WM_MOVE, sent|defwinproc },
2307     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2308
2309      /* in MDI client */
2310     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2311     { WM_NCCALCSIZE, sent|wparam, 1 },
2312     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2313     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2314
2315      /* in MDI child */
2316     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2317     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2318     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2319     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2320     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2321     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2322
2323     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2324
2325     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2326     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2327     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2328     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2329     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2330
2331      /* in MDI frame */
2332     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2333     { WM_NCCALCSIZE, sent|wparam, 1 },
2334     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2335     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2336
2337     { WM_NCACTIVATE, sent|wparam, 0 },
2338     { WM_MDIACTIVATE, sent },
2339
2340     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2341     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|0x8000 },
2342     { WM_NCCALCSIZE, sent|wparam, 1 },
2343
2344     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2345
2346     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2347     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|0x8000 },
2348     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2349
2350      /* in MDI child */
2351     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2352     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2353     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2354     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2355
2356      /* in MDI frame */
2357     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2358     { WM_NCCALCSIZE, sent|wparam, 1 },
2359     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2360     { WM_MOVE, sent|defwinproc },
2361     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2362
2363      /* in MDI client */
2364     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2365     { WM_NCCALCSIZE, sent|wparam, 1 },
2366     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2367     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2368     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2369     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2370     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2371     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2372     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2373
2374     { HCBT_SETFOCUS, hook },
2375     { WM_KILLFOCUS, sent },
2376     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2377     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2378     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2379     { WM_SETFOCUS, sent }, /* in MDI client */
2380
2381     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2382
2383     { HCBT_DESTROYWND, hook },
2384     /* Win2k sends wparam set to
2385      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2386      * while Win9x doesn't bother to set child window id according to
2387      * CLIENTCREATESTRUCT.idFirstChild
2388      */
2389     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2390
2391     { WM_SHOWWINDOW, sent|wparam, 0 },
2392     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2393     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2394     { WM_ERASEBKGND, sent|parent|optional },
2395     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2396
2397     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2398     { WM_DESTROY, sent },
2399     { WM_NCDESTROY, sent },
2400     { 0 }
2401 };
2402 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
2403 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
2404     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2405     { WM_GETMINMAXINFO, sent },
2406     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
2407     { WM_NCCALCSIZE, sent|wparam, 1 },
2408     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2409     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2410
2411     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2412     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2413     { HCBT_SETFOCUS, hook },
2414     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2415     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2416     { WM_SETFOCUS, sent }, /* in MDI client */
2417     { HCBT_SETFOCUS, hook },
2418     { WM_KILLFOCUS, sent }, /* in MDI client */
2419     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2420     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2421     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2422     { WM_SETFOCUS, sent|defwinproc },
2423     { WM_MDIACTIVATE, sent|defwinproc },
2424     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2425     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2426      /* in MDI frame */
2427     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2428     { WM_NCCALCSIZE, sent|wparam, 1 },
2429     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2430     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2431     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2432     { 0 }
2433 };
2434 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
2435 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
2436     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2437     { WM_GETMINMAXINFO, sent },
2438     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
2439     { WM_GETMINMAXINFO, sent|defwinproc },
2440     { WM_NCCALCSIZE, sent|wparam, 1 },
2441     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2442     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2443
2444     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2445     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2446     { HCBT_SETFOCUS, hook },
2447     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2448     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2449     { WM_SETFOCUS, sent }, /* in MDI client */
2450     { HCBT_SETFOCUS, hook },
2451     { WM_KILLFOCUS, sent }, /* in MDI client */
2452     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2453     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2454     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2455     { WM_SETFOCUS, sent|defwinproc },
2456     { WM_MDIACTIVATE, sent|defwinproc },
2457     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2458     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2459     { 0 }
2460 };
2461 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
2462 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
2463     { WM_MDIMAXIMIZE, sent }, /* in MDI client */
2464     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2465     { WM_GETMINMAXINFO, sent },
2466     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
2467     { WM_GETMINMAXINFO, sent|defwinproc },
2468     { WM_NCCALCSIZE, sent|wparam, 1 },
2469     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
2470     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2471     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|0x8000 },
2472     { WM_MOVE, sent|defwinproc },
2473     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2474
2475     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2476     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2477     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2478     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
2479     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2480     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
2481      /* in MDI frame */
2482     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2483     { WM_NCCALCSIZE, sent|wparam, 1 },
2484     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2485     { WM_MOVE, sent|defwinproc },
2486     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2487     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
2488      /* in MDI client */
2489     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2490     { WM_NCCALCSIZE, sent|wparam, 1 },
2491     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2492     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2493      /* in MDI child */
2494     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2495     { WM_GETMINMAXINFO, sent|defwinproc },
2496     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2497     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2498     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2499     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
2500     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
2501     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2502     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2503     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
2504      /* in MDI frame */
2505     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2506     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
2507     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
2508     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2509     { 0 }
2510 };
2511 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
2512 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
2513     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2514     { WM_GETMINMAXINFO, sent },
2515     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
2516     { WM_NCCALCSIZE, sent|wparam, 1 },
2517     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2518     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2519     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2520      /* in MDI frame */
2521     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2522     { WM_NCCALCSIZE, sent|wparam, 1 },
2523     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2524     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2525     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2526     { 0 }
2527 };
2528 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
2529 static const struct message WmRestoreMDIchildVisibleSeq[] = {
2530     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2531     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
2532     { WM_NCCALCSIZE, sent|wparam, 1 },
2533     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2534     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2535     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2536      /* in MDI frame */
2537     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2538     { WM_NCCALCSIZE, sent|wparam, 1 },
2539     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2540     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2541     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2542     { 0 }
2543 };
2544 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
2545 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
2546     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2547     { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
2548     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
2549     { WM_NCCALCSIZE, sent|wparam, 1 },
2550     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2551     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|0x8000 },
2552     { WM_MOVE, sent|defwinproc },
2553     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2554     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2555     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2556     { HCBT_SETFOCUS, hook },
2557     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2558     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2559     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2560     { WM_SETFOCUS, sent },
2561     { 0 }
2562 };
2563 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
2564 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
2565     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
2566     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|0x8000 },
2567     { WM_NCCALCSIZE, sent|wparam, 1 },
2568     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|0x8000 },
2569     { WM_MOVE, sent|defwinproc },
2570     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
2571     { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
2572     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2573     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2574     /* FIXME: Wine creates an icon/title window while Windows doesn't */
2575     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
2576     { 0 }
2577 };
2578 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
2579 static const struct message WmRestoreMDIchildInisibleSeq[] = {
2580     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2581     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
2582     { WM_NCCALCSIZE, sent|wparam, 1 },
2583     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2584     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2585     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2586     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2587      /* in MDI frame */
2588     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2589     { WM_NCCALCSIZE, sent|wparam, 1 },
2590     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2591     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2592     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2593     { 0 }
2594 };
2595
2596 static HWND mdi_client;
2597 static WNDPROC old_mdi_client_proc;
2598
2599 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2600 {
2601     struct message msg;
2602
2603     /* do not log painting messages */
2604     if (message != WM_PAINT &&
2605         message != WM_NCPAINT &&
2606         message != WM_SYNCPAINT &&
2607         message != WM_ERASEBKGND &&
2608         message != WM_NCPAINT &&
2609         message != WM_NCHITTEST &&
2610         message != WM_GETTEXT &&
2611         message != WM_MDIGETACTIVE &&
2612         message != WM_GETICON &&
2613         message != WM_DEVICECHANGE)
2614     {
2615         trace("mdi client: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
2616
2617         switch (message)
2618         {
2619             case WM_WINDOWPOSCHANGING:
2620             case WM_WINDOWPOSCHANGED:
2621             {
2622                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2623
2624                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2625                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2626                       winpos->hwnd, winpos->hwndInsertAfter,
2627                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2628                 dump_winpos_flags(winpos->flags);
2629
2630                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2631                  * in the high word for internal purposes
2632                  */
2633                 wParam = winpos->flags & 0xffff;
2634                 /* We are not interested in the flags that don't match under XP and Win9x */
2635                 wParam &= ~(SWP_NOZORDER);
2636                 break;
2637             }
2638         }
2639
2640         msg.message = message;
2641         msg.flags = sent|wparam|lparam;
2642         msg.wParam = wParam;
2643         msg.lParam = lParam;
2644         add_message(&msg);
2645     }
2646
2647     return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
2648 }
2649
2650 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2651 {
2652     static long defwndproc_counter = 0;
2653     LRESULT ret;
2654     struct message msg;
2655
2656     /* do not log painting messages */
2657     if (message != WM_PAINT &&
2658         message != WM_NCPAINT &&
2659         message != WM_SYNCPAINT &&
2660         message != WM_ERASEBKGND &&
2661         message != WM_NCPAINT &&
2662         message != WM_NCHITTEST &&
2663         message != WM_GETTEXT &&
2664         message != WM_GETICON &&
2665         message != WM_DEVICECHANGE)
2666     {
2667         trace("mdi child: %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             case WM_MDIACTIVATE:
2692             {
2693                 HWND active, client = GetParent(hwnd);
2694
2695                 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
2696
2697                 if (hwnd == (HWND)lParam) /* if we are being activated */
2698                     ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
2699                 else
2700                     ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
2701                 break;
2702             }
2703         }
2704
2705         msg.message = message;
2706         msg.flags = sent|wparam|lparam;
2707         if (defwndproc_counter) msg.flags |= defwinproc;
2708         msg.wParam = wParam;
2709         msg.lParam = lParam;
2710         add_message(&msg);
2711     }
2712
2713     defwndproc_counter++;
2714     ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
2715     defwndproc_counter--;
2716
2717     return ret;
2718 }
2719
2720 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2721 {
2722     static long defwndproc_counter = 0;
2723     LRESULT ret;
2724     struct message msg;
2725
2726     /* do not log painting messages */
2727     if (message != WM_PAINT &&
2728         message != WM_NCPAINT &&
2729         message != WM_SYNCPAINT &&
2730         message != WM_ERASEBKGND &&
2731         message != WM_NCPAINT &&
2732         message != WM_NCHITTEST &&
2733         message != WM_GETTEXT &&
2734         message != WM_GETICON &&
2735         message != WM_DEVICECHANGE)
2736     {
2737         trace("mdi frame: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
2738
2739         switch (message)
2740         {
2741             case WM_WINDOWPOSCHANGING:
2742             case WM_WINDOWPOSCHANGED:
2743             {
2744                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2745
2746                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2747                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2748                       winpos->hwnd, winpos->hwndInsertAfter,
2749                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2750                 dump_winpos_flags(winpos->flags);
2751
2752                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2753                  * in the high word for internal purposes
2754                  */
2755                 wParam = winpos->flags & 0xffff;
2756                 /* We are not interested in the flags that don't match under XP and Win9x */
2757                 wParam &= ~(SWP_NOZORDER);
2758                 break;
2759             }
2760         }
2761
2762         msg.message = message;
2763         msg.flags = sent|wparam|lparam;
2764         if (defwndproc_counter) msg.flags |= defwinproc;
2765         msg.wParam = wParam;
2766         msg.lParam = lParam;
2767         add_message(&msg);
2768     }
2769
2770     defwndproc_counter++;
2771     ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
2772     defwndproc_counter--;
2773
2774     return ret;
2775 }
2776
2777 static BOOL mdi_RegisterWindowClasses(void)
2778 {
2779     WNDCLASSA cls;
2780
2781     cls.style = 0;
2782     cls.lpfnWndProc = mdi_frame_wnd_proc;
2783     cls.cbClsExtra = 0;
2784     cls.cbWndExtra = 0;
2785     cls.hInstance = GetModuleHandleA(0);
2786     cls.hIcon = 0;
2787     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
2788     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
2789     cls.lpszMenuName = NULL;
2790     cls.lpszClassName = "MDI_frame_class";
2791     if (!RegisterClassA(&cls)) return FALSE;
2792
2793     cls.lpfnWndProc = mdi_child_wnd_proc;
2794     cls.lpszClassName = "MDI_child_class";
2795     if (!RegisterClassA(&cls)) return FALSE;
2796
2797     if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
2798     old_mdi_client_proc = cls.lpfnWndProc;
2799     cls.hInstance = GetModuleHandleA(0);
2800     cls.lpfnWndProc = mdi_client_hook_proc;
2801     cls.lpszClassName = "MDI_client_class";
2802     if (!RegisterClassA(&cls)) assert(0);
2803
2804     return TRUE;
2805 }
2806
2807 static void test_mdi_messages(void)
2808 {
2809     MDICREATESTRUCTA mdi_cs;
2810     CLIENTCREATESTRUCT client_cs;
2811     HWND mdi_frame, mdi_child, mdi_child2, active_child;
2812     BOOL zoomed;
2813     HMENU hMenu = CreateMenu();
2814
2815     assert(mdi_RegisterWindowClasses());
2816
2817     flush_sequence();
2818
2819     trace("creating MDI frame window\n");
2820     mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
2821                                 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2822                                 WS_MAXIMIZEBOX | WS_VISIBLE,
2823                                 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
2824                                 GetDesktopWindow(), hMenu,
2825                                 GetModuleHandleA(0), NULL);
2826     assert(mdi_frame);
2827     ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
2828
2829     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2830     ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
2831
2832     trace("creating MDI client window\n");
2833     client_cs.hWindowMenu = 0;
2834     client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
2835     mdi_client = CreateWindowExA(0, "MDI_client_class",
2836                                  NULL,
2837                                  WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
2838                                  0, 0, 0, 0,
2839                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
2840     assert(mdi_client);
2841     ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
2842
2843     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2844     ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
2845
2846     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2847     ok(!active_child, "wrong active MDI child %p\n", active_child);
2848     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2849
2850     SetFocus(0);
2851     flush_sequence();
2852
2853     trace("creating invisible MDI child window\n");
2854     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2855                                 WS_CHILD,
2856                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2857                                 mdi_client, 0, GetModuleHandleA(0), NULL);
2858     assert(mdi_child);
2859
2860     flush_sequence();
2861     ShowWindow(mdi_child, SW_SHOWNORMAL);
2862     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
2863
2864     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2865     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
2866
2867     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2868     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2869
2870     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2871     ok(!active_child, "wrong active MDI child %p\n", active_child);
2872     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2873
2874     ShowWindow(mdi_child, SW_HIDE);
2875     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
2876     flush_sequence();
2877
2878     ShowWindow(mdi_child, SW_SHOW);
2879     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
2880
2881     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2882     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
2883
2884     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2885     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2886
2887     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2888     ok(!active_child, "wrong active MDI child %p\n", active_child);
2889     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2890
2891     DestroyWindow(mdi_child);
2892     flush_sequence();
2893
2894     trace("creating visible MDI child window\n");
2895     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2896                                 WS_CHILD | WS_VISIBLE,
2897                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2898                                 mdi_client, 0, GetModuleHandleA(0), NULL);
2899     assert(mdi_child);
2900     ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
2901
2902     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2903     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
2904
2905     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2906     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
2907
2908     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2909     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
2910     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2911     flush_sequence();
2912
2913     DestroyWindow(mdi_child);
2914     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
2915
2916     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2917     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2918
2919     /* Win2k: MDI client still returns a just destroyed child as active
2920      * Win9x: MDI client returns 0
2921      */
2922     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2923     ok(active_child == mdi_child || /* win2k */
2924        !active_child, /* win9x */
2925        "wrong active MDI child %p\n", active_child);
2926     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2927
2928     flush_sequence();
2929
2930     trace("creating invisible MDI child window\n");
2931     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2932                                 WS_CHILD,
2933                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2934                                 mdi_client, 0, GetModuleHandleA(0), NULL);
2935     assert(mdi_child2);
2936     ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
2937
2938     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
2939     ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
2940
2941     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2942     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2943
2944     /* Win2k: MDI client still returns a just destroyed child as active
2945      * Win9x: MDI client returns mdi_child2
2946      */
2947     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2948     ok(active_child == mdi_child || /* win2k */
2949        active_child == mdi_child2, /* win9x */
2950        "wrong active MDI child %p\n", active_child);
2951     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2952     flush_sequence();
2953
2954     ShowWindow(mdi_child2, SW_MAXIMIZE);
2955     ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
2956
2957     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2958     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
2959
2960     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2961     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
2962     ok(zoomed, "wrong zoomed state %d\n", zoomed);
2963     flush_sequence();
2964
2965     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2966     ok(GetFocus() == mdi_child2 || /* win2k */
2967        GetFocus() == 0, /* win9x */
2968        "wrong focus window %p\n", GetFocus());
2969
2970     SetFocus(0);
2971     flush_sequence();
2972
2973     ShowWindow(mdi_child2, SW_HIDE);
2974     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
2975
2976     ShowWindow(mdi_child2, SW_RESTORE);
2977     ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
2978     flush_sequence();
2979
2980     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2981     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
2982
2983     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2984     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
2985     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2986     flush_sequence();
2987
2988     SetFocus(0);
2989     flush_sequence();
2990
2991     ShowWindow(mdi_child2, SW_HIDE);
2992     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
2993
2994     ShowWindow(mdi_child2, SW_SHOW);
2995     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
2996
2997     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2998     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2999
3000     ShowWindow(mdi_child2, SW_MAXIMIZE);
3001     ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3002
3003     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3004     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3005
3006     ShowWindow(mdi_child2, SW_RESTORE);
3007     ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3008
3009     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3010     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3011
3012     ShowWindow(mdi_child2, SW_MINIMIZE);
3013     ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3014
3015     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3016     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3017
3018     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3019     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3020     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3021     flush_sequence();
3022
3023     ShowWindow(mdi_child2, SW_RESTORE);
3024     ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", TRUE);
3025
3026     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3027     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3028
3029     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3030     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3031     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3032     flush_sequence();
3033
3034     SetFocus(0);
3035     flush_sequence();
3036
3037     ShowWindow(mdi_child2, SW_HIDE);
3038     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3039
3040     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3041     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3042
3043     DestroyWindow(mdi_child2);
3044     ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3045
3046     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3047     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3048
3049     /* test for maximized MDI children */
3050     trace("creating maximized visible MDI child window 1\n");
3051     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3052                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3053                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3054                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3055     assert(mdi_child);
3056     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3057     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3058
3059     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3060     ok(GetFocus() == mdi_child || /* win2k */
3061        GetFocus() == 0, /* win9x */
3062        "wrong focus window %p\n", GetFocus());
3063
3064     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3065     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3066     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3067     flush_sequence();
3068
3069     trace("creating maximized visible MDI child window 2\n");
3070     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3071                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3072                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3073                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3074     assert(mdi_child2);
3075     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3076     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3077     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3078
3079     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3080     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3081
3082     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3083     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3084     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3085     flush_sequence();
3086
3087     trace("destroying maximized visible MDI child window 2\n");
3088     DestroyWindow(mdi_child2);
3089     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3090
3091     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3092
3093     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3094     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3095
3096     /* Win2k: MDI client still returns a just destroyed child as active
3097      * Win9x: MDI client returns 0
3098      */
3099     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3100     ok(active_child == mdi_child2 || /* win2k */
3101        !active_child, /* win9x */
3102        "wrong active MDI child %p\n", active_child);
3103     flush_sequence();
3104
3105     ShowWindow(mdi_child, SW_MAXIMIZE);
3106     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3107     flush_sequence();
3108
3109     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3110     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3111
3112     trace("re-creating maximized visible MDI child window 2\n");
3113     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3114                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3115                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3116                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3117     assert(mdi_child2);
3118     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3119     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3120     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3121
3122     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3123     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3124
3125     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3126     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3127     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3128     flush_sequence();
3129
3130     SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3131     ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3132     ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3133
3134     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3135     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3136     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3137
3138     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3139     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3140     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3141     flush_sequence();
3142
3143     DestroyWindow(mdi_child);
3144     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3145
3146     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3147     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3148
3149     /* Win2k: MDI client still returns a just destroyed child as active
3150      * Win9x: MDI client returns 0
3151      */
3152     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3153     ok(active_child == mdi_child || /* win2k */
3154        !active_child, /* win9x */
3155        "wrong active MDI child %p\n", active_child);
3156     flush_sequence();
3157
3158     trace("creating maximized invisible MDI child window\n");
3159     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3160                                 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3161                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3162                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3163     assert(mdi_child2);
3164     ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", TRUE);
3165     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3166     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3167     ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3168
3169     /* Win2k: MDI client still returns a just destroyed child as active
3170      * Win9x: MDI client returns 0
3171      */
3172     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3173     ok(active_child == mdi_child || /* win2k */
3174        !active_child, /* win9x */
3175        "wrong active MDI child %p\n", active_child);
3176     flush_sequence();
3177
3178     trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3179     ShowWindow(mdi_child2, SW_MAXIMIZE);
3180     ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3181     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3182     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3183     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3184
3185     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3186     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3187     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3188     flush_sequence();
3189
3190     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3191     flush_sequence();
3192
3193     /* end of test for maximized MDI children */
3194
3195     mdi_cs.szClass = "MDI_child_Class";
3196     mdi_cs.szTitle = "MDI child";
3197     mdi_cs.hOwner = GetModuleHandleA(0);
3198     mdi_cs.x = 0;
3199     mdi_cs.y = 0;
3200     mdi_cs.cx = CW_USEDEFAULT;
3201     mdi_cs.cy = CW_USEDEFAULT;
3202     mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3203     mdi_cs.lParam = 0;
3204     mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3205     ok(mdi_child != 0, "MDI child creation failed\n");
3206     ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3207
3208     ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3209
3210     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3211     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3212
3213     ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3214     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3215     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3216
3217     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3218     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3219     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3220     flush_sequence();
3221
3222     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3223     ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3224
3225     ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3226     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3227     ok(!active_child, "wrong active MDI child %p\n", active_child);
3228
3229     SetFocus(0);
3230     flush_sequence();
3231
3232     DestroyWindow(mdi_client);
3233     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3234
3235     /* test maximization of MDI child with invisible parent */
3236     client_cs.hWindowMenu = 0;
3237     mdi_client = CreateWindow("MDI_client_class",
3238                                  NULL,
3239                                  WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3240                                  0, 0, 660, 430,
3241                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3242     ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3243
3244     ShowWindow(mdi_client, SW_HIDE);
3245     ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3246
3247     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3248                                 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3249                                 0, 0, 650, 440,
3250                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3251     ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3252
3253     SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3254     ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3255     zoomed = IsZoomed(mdi_child);
3256     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3257     
3258     ShowWindow(mdi_client, SW_SHOW);
3259     ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3260
3261     DestroyWindow(mdi_child);
3262     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3263
3264     /* end of test for maximization of MDI child with invisible parent */
3265
3266     /* test for switch maximized MDI children */
3267     trace("creating maximized visible MDI child window 1(Switch test)\n");
3268     mdi_child = 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_child);
3273     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3274     ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3275
3276     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3277     ok(GetFocus() == mdi_child || /* win2k */
3278        GetFocus() == 0, /* win9x */
3279        "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_child, "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("creating maximized visible MDI child window 2(Switch test)\n");
3287     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3288                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3289                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3290                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3291     assert(mdi_child2);
3292     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window(Switch test)\n", TRUE);
3293     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3294     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3295
3296     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3297     ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3298
3299     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3300     ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3301     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3302     flush_sequence();
3303
3304     trace("Switch child window.\n");
3305     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3306     ok_sequence(WmSwitchChild,"Child not switch correctly\n",TRUE);
3307     
3308     trace("end of test for switch maximized MDI children\n");
3309
3310     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3311     flush_sequence();
3312
3313     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3314     flush_sequence();
3315
3316     /* end of test for switch maximized MDI children */
3317
3318     DestroyWindow(mdi_client);
3319     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3320
3321     DestroyWindow(mdi_frame);
3322     ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3323 }
3324 /************************* End of MDI test **********************************/
3325
3326 static void test_WM_SETREDRAW(HWND hwnd)
3327 {
3328     DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3329
3330     flush_sequence();
3331
3332     SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3333     ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3334
3335     ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3336     ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3337
3338     flush_sequence();
3339     SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3340     ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3341
3342     ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3343     ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3344
3345     /* restore original WS_VISIBLE state */
3346     SetWindowLongA(hwnd, GWL_STYLE, style);
3347
3348     flush_sequence();
3349 }
3350
3351 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3352 {
3353     struct message msg;
3354
3355     trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
3356
3357     /* explicitly ignore WM_GETICON message */
3358     if (message == WM_GETICON) return 0;
3359
3360     switch (message)
3361     {
3362         /* ignore */
3363         case WM_MOUSEMOVE:
3364         case WM_SETCURSOR:
3365         case WM_DEVICECHANGE:
3366             return 0;
3367         case WM_NCHITTEST:
3368             return HTCLIENT;
3369
3370         case WM_WINDOWPOSCHANGING:
3371         case WM_WINDOWPOSCHANGED:
3372         {
3373             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
3374
3375             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
3376             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
3377                   winpos->hwnd, winpos->hwndInsertAfter,
3378                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
3379             dump_winpos_flags(winpos->flags);
3380
3381             /* Log only documented flags, win2k uses 0x1000 and 0x2000
3382              * in the high word for internal purposes
3383              */
3384             wParam = winpos->flags & 0xffff;
3385             /* We are not interested in the flags that don't match under XP and Win9x */
3386             wParam &= ~(SWP_NOZORDER);
3387             break;
3388         }
3389     }
3390
3391     msg.message = message;
3392     msg.flags = sent|wparam|lparam;
3393     msg.wParam = wParam;
3394     msg.lParam = lParam;
3395     add_message(&msg);
3396
3397     if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3398     if (message == WM_TIMER) EndDialog( hwnd, 0 );
3399     return 0;
3400 }
3401
3402 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3403 {
3404     DWORD style, exstyle;
3405     INT xmin, xmax;
3406     BOOL ret;
3407
3408     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3409     style = GetWindowLongA(hwnd, GWL_STYLE);
3410     /* do not be confused by WS_DLGFRAME set */
3411     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3412
3413     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3414     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3415
3416     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3417     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3418     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3419         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3420     else
3421         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3422
3423     style = GetWindowLongA(hwnd, GWL_STYLE);
3424     if (set) ok(style & set, "style %08x should be set\n", set);
3425     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3426
3427     /* a subsequent call should do nothing */
3428     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3429     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3430     ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3431
3432     xmin = 0xdeadbeef;
3433     xmax = 0xdeadbeef;
3434     trace("Ignore GetScrollRange error below if you are on Win9x\n");
3435     ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
3436     ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
3437     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3438     ok(xmin == min, "unexpected min scroll value %d\n", xmin);
3439     ok(xmax == max, "unexpected max scroll value %d\n", xmax);
3440 }
3441
3442 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3443 {
3444     DWORD style, exstyle;
3445     SCROLLINFO si;
3446     BOOL ret;
3447
3448     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3449     style = GetWindowLongA(hwnd, GWL_STYLE);
3450     /* do not be confused by WS_DLGFRAME set */
3451     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3452
3453     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3454     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3455
3456     si.cbSize = sizeof(si);
3457     si.fMask = SIF_RANGE;
3458     si.nMin = min;
3459     si.nMax = max;
3460     SetScrollInfo(hwnd, ctl, &si, TRUE);
3461     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3462         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
3463     else
3464         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
3465
3466     style = GetWindowLongA(hwnd, GWL_STYLE);
3467     if (set) ok(style & set, "style %08x should be set\n", set);
3468     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3469
3470     /* a subsequent call should do nothing */
3471     SetScrollInfo(hwnd, ctl, &si, TRUE);
3472     if (style & WS_HSCROLL)
3473         ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3474     else if (style & WS_VSCROLL)
3475         ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3476     else
3477         ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3478
3479     si.fMask = SIF_PAGE;
3480     si.nPage = 5;
3481     SetScrollInfo(hwnd, ctl, &si, FALSE);
3482     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3483
3484     si.fMask = SIF_POS;
3485     si.nPos = max - 1;
3486     SetScrollInfo(hwnd, ctl, &si, FALSE);
3487     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3488
3489     si.fMask = SIF_RANGE;
3490     si.nMin = 0xdeadbeef;
3491     si.nMax = 0xdeadbeef;
3492     ret = GetScrollInfo(hwnd, ctl, &si);
3493     ok( ret, "GetScrollInfo error %d\n", GetLastError());
3494     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3495     ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
3496     ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
3497 }
3498
3499 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
3500 static void test_scroll_messages(HWND hwnd)
3501 {
3502     SCROLLINFO si;
3503     INT min, max;
3504     BOOL ret;
3505
3506     min = 0xdeadbeef;
3507     max = 0xdeadbeef;
3508     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3509     ok( ret, "GetScrollRange error %d\n", GetLastError());
3510     if (sequence->message != WmGetScrollRangeSeq[0].message)
3511         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3512     /* values of min and max are undefined */
3513     flush_sequence();
3514
3515     ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
3516     ok( ret, "SetScrollRange error %d\n", GetLastError());
3517     if (sequence->message != WmSetScrollRangeSeq[0].message)
3518         trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3519     flush_sequence();
3520
3521     min = 0xdeadbeef;
3522     max = 0xdeadbeef;
3523     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3524     ok( ret, "GetScrollRange error %d\n", GetLastError());
3525     if (sequence->message != WmGetScrollRangeSeq[0].message)
3526         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3527     /* values of min and max are undefined */
3528     flush_sequence();
3529
3530     si.cbSize = sizeof(si);
3531     si.fMask = SIF_RANGE;
3532     si.nMin = 20;
3533     si.nMax = 160;
3534     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3535     if (sequence->message != WmSetScrollRangeSeq[0].message)
3536         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3537     flush_sequence();
3538
3539     si.fMask = SIF_PAGE;
3540     si.nPage = 10;
3541     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3542     if (sequence->message != WmSetScrollRangeSeq[0].message)
3543         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3544     flush_sequence();
3545
3546     si.fMask = SIF_POS;
3547     si.nPos = 20;
3548     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3549     if (sequence->message != WmSetScrollRangeSeq[0].message)
3550         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3551     flush_sequence();
3552
3553     si.fMask = SIF_RANGE;
3554     si.nMin = 0xdeadbeef;
3555     si.nMax = 0xdeadbeef;
3556     ret = GetScrollInfo(hwnd, SB_CTL, &si);
3557     ok( ret, "GetScrollInfo error %d\n", GetLastError());
3558     if (sequence->message != WmGetScrollInfoSeq[0].message)
3559         trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3560     /* values of min and max are undefined */
3561     flush_sequence();
3562
3563     /* set WS_HSCROLL */
3564     test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
3565     /* clear WS_HSCROLL */
3566     test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
3567
3568     /* set WS_HSCROLL */
3569     test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
3570     /* clear WS_HSCROLL */
3571     test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
3572
3573     /* set WS_VSCROLL */
3574     test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
3575     /* clear WS_VSCROLL */
3576     test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
3577
3578     /* set WS_VSCROLL */
3579     test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
3580     /* clear WS_VSCROLL */
3581     test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
3582 }
3583
3584 static void test_showwindow(void)
3585 {
3586     HWND hwnd, hchild;
3587     RECT rc;
3588
3589     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
3590                            100, 100, 200, 200, 0, 0, 0, NULL);
3591     ok (hwnd != 0, "Failed to create overlapped window\n");
3592     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
3593                              0, 0, 10, 10, hwnd, 0, 0, NULL);
3594     ok (hchild != 0, "Failed to create child\n");
3595     flush_sequence();
3596
3597     /* ShowWindow( SW_SHOWNA) for invisible top level window */
3598     trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
3599     ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3600     ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", TRUE);
3601     trace("done\n");
3602
3603     /* ShowWindow( SW_SHOWNA) for now visible top level window */
3604     trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
3605     ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3606     ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
3607     trace("done\n");
3608     /* back to invisible */
3609     ShowWindow(hchild, SW_HIDE);
3610     ShowWindow(hwnd, SW_HIDE);
3611     flush_sequence();
3612     /* ShowWindow(SW_SHOWNA) with child and parent invisible */ 
3613     trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
3614     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3615     ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
3616     trace("done\n");
3617     /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */ 
3618     ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
3619     flush_sequence();
3620     trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
3621     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3622     ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
3623     trace("done\n");
3624     /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
3625     ShowWindow( hwnd, SW_SHOW);
3626     flush_sequence();
3627     trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
3628     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3629     ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
3630     trace("done\n");
3631
3632     /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
3633     ShowWindow( hchild, SW_HIDE);
3634     flush_sequence();
3635     trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
3636     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3637     ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
3638     trace("done\n");
3639
3640     SetCapture(hchild);
3641     ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
3642     DestroyWindow(hchild);
3643     ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
3644
3645     DestroyWindow(hwnd);
3646     flush_sequence();
3647
3648     /* Popup windows */
3649     /* Test 1:
3650      * 1. Create invisible maximized popup window.
3651      * 2. Move and resize it.
3652      * 3. Show it maximized.
3653      */
3654     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
3655     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
3656                            100, 100, 200, 200, 0, 0, 0, NULL);
3657     ok (hwnd != 0, "Failed to create popup window\n");
3658     ok(IsZoomed(hwnd), "window should be maximized\n");
3659     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
3660     trace("done\n");
3661
3662     GetWindowRect(hwnd, &rc);
3663     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
3664         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
3665         "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
3666         rc.left, rc.top, rc.right, rc.bottom);
3667     /* Reset window's size & position */
3668     SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
3669     ok(IsZoomed(hwnd), "window should be maximized\n");
3670     flush_sequence();
3671
3672     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
3673     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3674     ok(IsZoomed(hwnd), "window should be maximized\n");
3675     ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
3676     trace("done\n");
3677
3678     GetWindowRect(hwnd, &rc);
3679     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
3680         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
3681         "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
3682         rc.left, rc.top, rc.right, rc.bottom);
3683     DestroyWindow(hwnd);
3684     flush_sequence();
3685
3686     /* Test 2:
3687      * 1. Create invisible maximized popup window.
3688      * 2. Show it maximized.
3689      */
3690     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
3691     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
3692                            100, 100, 200, 200, 0, 0, 0, NULL);
3693     ok (hwnd != 0, "Failed to create popup window\n");
3694     ok(IsZoomed(hwnd), "window should be maximized\n");
3695     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
3696     trace("done\n");
3697
3698     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
3699     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3700     ok(IsZoomed(hwnd), "window should be maximized\n");
3701     ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
3702     trace("done\n");
3703     DestroyWindow(hwnd);
3704     flush_sequence();
3705
3706     /* Test 3:
3707      * 1. Create visible maximized popup window.
3708      */
3709     trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
3710     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
3711                            100, 100, 200, 200, 0, 0, 0, NULL);
3712     ok (hwnd != 0, "Failed to create popup window\n");
3713     ok(IsZoomed(hwnd), "window should be maximized\n");
3714     ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
3715     trace("done\n");
3716     DestroyWindow(hwnd);
3717     flush_sequence();
3718
3719     /* Test 4:
3720      * 1. Create visible popup window.
3721      * 2. Maximize it.
3722      */
3723     trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
3724     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
3725                            100, 100, 200, 200, 0, 0, 0, NULL);
3726     ok (hwnd != 0, "Failed to create popup window\n");
3727     ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
3728     ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
3729     trace("done\n");
3730
3731     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
3732     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3733     ok(IsZoomed(hwnd), "window should be maximized\n");
3734     ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
3735     trace("done\n");
3736     DestroyWindow(hwnd);
3737     flush_sequence();
3738 }
3739
3740 static void test_sys_menu(void)
3741 {
3742     HWND hwnd;
3743     HMENU hmenu;
3744     UINT state;
3745
3746     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
3747                            100, 100, 200, 200, 0, 0, 0, NULL);
3748     ok (hwnd != 0, "Failed to create overlapped window\n");
3749
3750     flush_sequence();
3751
3752     /* test existing window without CS_NOCLOSE style */
3753     hmenu = GetSystemMenu(hwnd, FALSE);
3754     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
3755
3756     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3757     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3758     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
3759
3760     EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
3761     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
3762
3763     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3764     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3765     ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
3766
3767     EnableMenuItem(hmenu, SC_CLOSE, 0);
3768     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
3769
3770     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3771     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3772     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
3773
3774     /* test whether removing WS_SYSMENU destroys a system menu */
3775     SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
3776     SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
3777     flush_sequence();
3778     hmenu = GetSystemMenu(hwnd, FALSE);
3779     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
3780
3781     DestroyWindow(hwnd);
3782
3783     /* test new window with CS_NOCLOSE style */
3784     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
3785                            100, 100, 200, 200, 0, 0, 0, NULL);
3786     ok (hwnd != 0, "Failed to create overlapped window\n");
3787
3788     hmenu = GetSystemMenu(hwnd, FALSE);
3789     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
3790
3791     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3792     ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3793
3794     DestroyWindow(hwnd);
3795
3796     /* test new window without WS_SYSMENU style */
3797     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
3798                            100, 100, 200, 200, 0, 0, 0, NULL);
3799     ok(hwnd != 0, "Failed to create overlapped window\n");
3800
3801     hmenu = GetSystemMenu(hwnd, FALSE);
3802     ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
3803
3804     DestroyWindow(hwnd);
3805 }
3806
3807 /* For shown WS_OVERLAPPEDWINDOW */
3808 static const struct message WmSetIcon_1[] = {
3809     { WM_SETICON, sent },
3810     { 0x00AE, sent|defwinproc|optional }, /* XP */
3811     { WM_GETTEXT, sent|defwinproc|optional },
3812     { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
3813     { 0 }
3814 };
3815
3816 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
3817 static const struct message WmSetIcon_2[] = {
3818     { WM_SETICON, sent },
3819     { 0 }
3820 };
3821
3822 static void test_MsgWaitForMultipleObjects(HWND hwnd)
3823 {
3824     DWORD ret;
3825     MSG msg;
3826
3827     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3828     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
3829
3830     PostMessageA(hwnd, WM_USER, 0, 0);
3831
3832     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3833     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
3834
3835     ok(PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
3836     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
3837
3838     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3839     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
3840
3841     PostMessageA(hwnd, WM_USER, 0, 0);
3842
3843     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3844     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
3845
3846     ok(PeekMessageW( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
3847     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
3848
3849     /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
3850     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3851     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
3852
3853     PostMessageA(hwnd, WM_USER, 0, 0);
3854
3855     /* new incoming message causes it to become signaled again */
3856     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3857     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
3858
3859     ok(PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
3860     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
3861     ok(PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
3862     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
3863 }
3864
3865 /* test if we receive the right sequence of messages */
3866 static void test_messages(void)
3867 {
3868     HWND hwnd, hparent, hchild;
3869     HWND hchild2, hbutton;
3870     HMENU hmenu;
3871     MSG msg;
3872
3873     flush_sequence();
3874
3875     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
3876                            100, 100, 200, 200, 0, 0, 0, NULL);
3877     ok (hwnd != 0, "Failed to create overlapped window\n");
3878     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
3879
3880     /* test ShowWindow(SW_HIDE) on a newly created invisible window */
3881     ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
3882     ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
3883
3884     /* test WM_SETREDRAW on a not visible top level window */
3885     test_WM_SETREDRAW(hwnd);
3886
3887     SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
3888     ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
3889     ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
3890
3891     ok(GetActiveWindow() == hwnd, "window should be active\n");
3892     ok(GetFocus() == hwnd, "window should have input focus\n");
3893     ShowWindow(hwnd, SW_HIDE);
3894     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", TRUE);
3895
3896     ShowWindow(hwnd, SW_SHOW);
3897     ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
3898
3899     ShowWindow(hwnd, SW_HIDE);
3900     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
3901
3902     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3903     ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
3904
3905     ShowWindow(hwnd, SW_RESTORE);
3906     /* FIXME: add ok_sequence() here */
3907     flush_sequence();
3908
3909     ShowWindow(hwnd, SW_MINIMIZE);
3910     ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
3911     flush_sequence();
3912
3913     ShowWindow(hwnd, SW_RESTORE);
3914     /* FIXME: add ok_sequence() here */
3915     flush_sequence();
3916
3917     ShowWindow(hwnd, SW_SHOW);
3918     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
3919
3920     ok(GetActiveWindow() == hwnd, "window should be active\n");
3921     ok(GetFocus() == hwnd, "window should have input focus\n");
3922     SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
3923     ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
3924     ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
3925     ok(GetActiveWindow() == hwnd, "window should still be active\n");
3926
3927     /* test WM_SETREDRAW on a visible top level window */
3928     ShowWindow(hwnd, SW_SHOW);
3929     test_WM_SETREDRAW(hwnd);
3930
3931     trace("testing scroll APIs on a visible top level window %p\n", hwnd);
3932     test_scroll_messages(hwnd);
3933
3934     /* test resizing and moving */
3935     SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
3936     ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
3937     flush_events();
3938     flush_sequence();
3939     SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
3940     ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
3941     flush_events();
3942     flush_sequence();
3943     SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER );
3944     ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
3945     flush_events();
3946     flush_sequence();
3947
3948     /* popups don't get WM_GETMINMAXINFO */
3949     SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
3950     SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
3951     flush_sequence();
3952     SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
3953     ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
3954
3955     DestroyWindow(hwnd);
3956     ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
3957
3958     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3959                               100, 100, 200, 200, 0, 0, 0, NULL);
3960     ok (hparent != 0, "Failed to create parent window\n");
3961     flush_sequence();
3962
3963     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
3964                              0, 0, 10, 10, hparent, 0, 0, NULL);
3965     ok (hchild != 0, "Failed to create child window\n");
3966     ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
3967     DestroyWindow(hchild);
3968     flush_sequence();
3969
3970     /* visible child window with a caption */
3971     hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
3972                              WS_CHILD | WS_VISIBLE | WS_CAPTION,
3973                              0, 0, 10, 10, hparent, 0, 0, NULL);
3974     ok (hchild != 0, "Failed to create child window\n");
3975     ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
3976
3977     trace("testing scroll APIs on a visible child window %p\n", hchild);
3978     test_scroll_messages(hchild);
3979
3980     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
3981     ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
3982
3983     DestroyWindow(hchild);
3984     flush_sequence();
3985
3986     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
3987                              0, 0, 10, 10, hparent, 0, 0, NULL);
3988     ok (hchild != 0, "Failed to create child window\n");
3989     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
3990     
3991     hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
3992                                100, 100, 50, 50, hparent, 0, 0, NULL);
3993     ok (hchild2 != 0, "Failed to create child2 window\n");
3994     flush_sequence();
3995
3996     hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
3997                               0, 100, 50, 50, hchild, 0, 0, NULL);
3998     ok (hbutton != 0, "Failed to create button window\n");
3999
4000     /* test WM_SETREDRAW on a not visible child window */
4001     test_WM_SETREDRAW(hchild);
4002
4003     ShowWindow(hchild, SW_SHOW);
4004     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4005
4006     /* check parent messages too */
4007     log_all_parent_messages++;
4008     ShowWindow(hchild, SW_HIDE);
4009     ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4010     log_all_parent_messages--;
4011
4012     ShowWindow(hchild, SW_SHOW);
4013     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4014
4015     ShowWindow(hchild, SW_HIDE);
4016     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4017
4018     ShowWindow(hchild, SW_SHOW);
4019     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4020
4021     /* test WM_SETREDRAW on a visible child window */
4022     test_WM_SETREDRAW(hchild);
4023
4024     log_all_parent_messages++;
4025     MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4026     ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4027     log_all_parent_messages--;
4028
4029     ShowWindow(hchild, SW_HIDE);
4030     flush_sequence();
4031     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4032     ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4033
4034     ShowWindow(hchild, SW_HIDE);
4035     flush_sequence();
4036     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4037     ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4038
4039     /* DestroyWindow sequence below expects that a child has focus */
4040     SetFocus(hchild);
4041     flush_sequence();
4042
4043     DestroyWindow(hchild);
4044     ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4045     DestroyWindow(hchild2);
4046     DestroyWindow(hbutton);
4047
4048     flush_sequence();
4049     hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4050                              0, 0, 100, 100, hparent, 0, 0, NULL);
4051     ok (hchild != 0, "Failed to create child popup window\n");
4052     ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4053     DestroyWindow(hchild);
4054
4055     /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4056     flush_sequence();
4057     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4058                              0, 0, 100, 100, hparent, 0, 0, NULL);
4059     ok (hchild != 0, "Failed to create popup window\n");
4060     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4061     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4062     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4063     flush_sequence();
4064     ShowWindow(hchild, SW_SHOW);
4065     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4066     flush_sequence();
4067     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4068     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4069     flush_sequence();
4070     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4071     ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", TRUE);
4072     DestroyWindow(hchild);
4073
4074     /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4075      * changes nothing in message sequences.
4076      */
4077     flush_sequence();
4078     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4079                              0, 0, 100, 100, hparent, 0, 0, NULL);
4080     ok (hchild != 0, "Failed to create popup window\n");
4081     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4082     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4083     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4084     flush_sequence();
4085     ShowWindow(hchild, SW_SHOW);
4086     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4087     flush_sequence();
4088     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4089     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4090     DestroyWindow(hchild);
4091
4092     flush_sequence();
4093     hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4094                            0, 0, 100, 100, hparent, 0, 0, NULL);
4095     ok(hwnd != 0, "Failed to create custom dialog window\n");
4096     ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4097
4098     /*
4099     trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4100     test_scroll_messages(hwnd);
4101     */
4102
4103     flush_sequence();
4104
4105     test_def_id = 1;
4106     SendMessage(hwnd, WM_NULL, 0, 0);
4107
4108     flush_sequence();
4109     after_end_dialog = 1;
4110     EndDialog( hwnd, 0 );
4111     ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4112
4113     DestroyWindow(hwnd);
4114     after_end_dialog = 0;
4115     test_def_id = 0;
4116
4117     hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4118                            0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4119     ok(hwnd != 0, "Failed to create custom dialog window\n");
4120     flush_sequence();
4121     trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4122     ShowWindow(hwnd, SW_SHOW);
4123     ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4124     DestroyWindow(hwnd);
4125
4126     flush_sequence();
4127     DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4128     ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4129
4130     DestroyWindow(hparent);
4131     flush_sequence();
4132
4133     /* Message sequence for SetMenu */
4134     ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4135     ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4136
4137     hmenu = CreateMenu();
4138     ok (hmenu != 0, "Failed to create menu\n");
4139     ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4140     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4141                            100, 100, 200, 200, 0, hmenu, 0, NULL);
4142     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4143     ok (SetMenu(hwnd, 0), "SetMenu\n");
4144     ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4145     ok (SetMenu(hwnd, 0), "SetMenu\n");
4146     ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4147     ShowWindow(hwnd, SW_SHOW);
4148     UpdateWindow( hwnd );
4149     flush_events();
4150     flush_sequence();
4151     ok (SetMenu(hwnd, 0), "SetMenu\n");
4152     ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4153     ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4154     ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4155
4156     UpdateWindow( hwnd );
4157     flush_events();
4158     flush_sequence();
4159     ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4160     flush_events();
4161     ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4162
4163     DestroyWindow(hwnd);
4164     flush_sequence();
4165
4166     /* Message sequence for EnableWindow */
4167     hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4168                               100, 100, 200, 200, 0, 0, 0, NULL);
4169     ok (hparent != 0, "Failed to create parent window\n");
4170     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4171                              0, 0, 10, 10, hparent, 0, 0, NULL);
4172     ok (hchild != 0, "Failed to create child window\n");
4173
4174     SetFocus(hchild);
4175     flush_events();
4176     flush_sequence();
4177
4178     EnableWindow(hparent, FALSE);
4179     ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4180
4181     EnableWindow(hparent, TRUE);
4182     ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4183
4184     flush_events();
4185     flush_sequence();
4186
4187     test_MsgWaitForMultipleObjects(hparent);
4188
4189     /* the following test causes an exception in user.exe under win9x */
4190     if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4191     {
4192         DestroyWindow(hparent);
4193         flush_sequence();
4194         return;
4195     }
4196     PostMessageW( hparent, WM_USER+1, 0, 0 );
4197     /* PeekMessage(NULL) fails, but still removes the message */
4198     SetLastError(0xdeadbeef);
4199     ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4200     ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4201         GetLastError() == 0xdeadbeef, /* NT4 */
4202         "last error is %d\n", GetLastError() );
4203     ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4204     ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4205
4206     DestroyWindow(hchild);
4207     DestroyWindow(hparent);
4208     flush_sequence();
4209
4210     /* Message sequences for WM_SETICON */
4211     trace("testing WM_SETICON\n");
4212     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4213                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4214                            NULL, NULL, 0);
4215     ShowWindow(hwnd, SW_SHOW);
4216     UpdateWindow(hwnd);
4217     flush_events();
4218     flush_sequence();
4219     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4220     ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4221
4222     ShowWindow(hwnd, SW_HIDE);
4223     flush_events();
4224     flush_sequence();
4225     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4226     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4227     DestroyWindow(hwnd);
4228     flush_sequence();
4229
4230     hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4231                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4232                            NULL, NULL, 0);
4233     ShowWindow(hwnd, SW_SHOW);
4234     UpdateWindow(hwnd);
4235     flush_events();
4236     flush_sequence();
4237     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4238     ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4239
4240     ShowWindow(hwnd, SW_HIDE);
4241     flush_events();
4242     flush_sequence();
4243     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4244     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4245     DestroyWindow(hwnd);
4246     flush_sequence();
4247 }
4248
4249 static void invisible_parent_tests(void)
4250 {
4251     HWND hparent, hchild;
4252
4253     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4254                               100, 100, 200, 200, 0, 0, 0, NULL);
4255     ok (hparent != 0, "Failed to create parent window\n");
4256     flush_sequence();
4257
4258     /* test showing child with hidden parent */
4259
4260     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4261                              0, 0, 10, 10, hparent, 0, 0, NULL);
4262     ok (hchild != 0, "Failed to create child window\n");
4263     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4264
4265     ShowWindow( hchild, SW_MINIMIZE );
4266     ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4267     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4268     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4269
4270     /* repeat */
4271     flush_events();
4272     flush_sequence();
4273     ShowWindow( hchild, SW_MINIMIZE );
4274     ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4275
4276     DestroyWindow(hchild);
4277     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4278                              0, 0, 10, 10, hparent, 0, 0, NULL);
4279     flush_sequence();
4280
4281     ShowWindow( hchild, SW_MAXIMIZE );
4282     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4283     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4284     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4285
4286     /* repeat */
4287     flush_events();
4288     flush_sequence();
4289     ShowWindow( hchild, SW_MAXIMIZE );
4290     ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4291
4292     DestroyWindow(hchild);
4293     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4294                              0, 0, 10, 10, hparent, 0, 0, NULL);
4295     flush_sequence();
4296
4297     ShowWindow( hchild, SW_RESTORE );
4298     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
4299     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4300     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4301
4302     DestroyWindow(hchild);
4303     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4304                              0, 0, 10, 10, hparent, 0, 0, NULL);
4305     flush_sequence();
4306
4307     ShowWindow( hchild, SW_SHOWMINIMIZED );
4308     ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4309     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4310     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4311
4312     /* repeat */
4313     flush_events();
4314     flush_sequence();
4315     ShowWindow( hchild, SW_SHOWMINIMIZED );
4316     ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4317
4318     DestroyWindow(hchild);
4319     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4320                              0, 0, 10, 10, hparent, 0, 0, NULL);
4321     flush_sequence();
4322
4323     /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
4324     ShowWindow( hchild, SW_SHOWMAXIMIZED );
4325     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
4326     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4327     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4328
4329     DestroyWindow(hchild);
4330     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4331                              0, 0, 10, 10, hparent, 0, 0, NULL);
4332     flush_sequence();
4333
4334     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4335     ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4336     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4337     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4338
4339     /* repeat */
4340     flush_events();
4341     flush_sequence();
4342     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4343     ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4344
4345     DestroyWindow(hchild);
4346     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4347                              0, 0, 10, 10, hparent, 0, 0, NULL);
4348     flush_sequence();
4349
4350     /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
4351     ShowWindow( hchild, SW_FORCEMINIMIZE );
4352     ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
4353 todo_wine {
4354     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4355 }
4356     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4357
4358     DestroyWindow(hchild);
4359     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4360                              0, 0, 10, 10, hparent, 0, 0, NULL);
4361     flush_sequence();
4362
4363     ShowWindow( hchild, SW_SHOWNA );
4364     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4365     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4366     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4367
4368     /* repeat */
4369     flush_events();
4370     flush_sequence();
4371     ShowWindow( hchild, SW_SHOWNA );
4372     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4373
4374     DestroyWindow(hchild);
4375     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4376                              0, 0, 10, 10, hparent, 0, 0, NULL);
4377     flush_sequence();
4378
4379     ShowWindow( hchild, SW_SHOW );
4380     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4381     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4382     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4383
4384     /* repeat */
4385     flush_events();
4386     flush_sequence();
4387     ShowWindow( hchild, SW_SHOW );
4388     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4389
4390     ShowWindow( hchild, SW_HIDE );
4391     ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
4392     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4393     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4394
4395     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4396     ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
4397     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4398     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4399
4400     SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4401     ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
4402     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
4403     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4404
4405     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4406     flush_sequence();
4407     DestroyWindow(hchild);
4408     ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
4409
4410     DestroyWindow(hparent);
4411     flush_sequence();
4412 }
4413
4414 /****************** button message test *************************/
4415 static const struct message WmSetFocusButtonSeq[] =
4416 {
4417     { HCBT_SETFOCUS, hook },
4418     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
4419     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4420     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4421     { WM_SETFOCUS, sent|wparam, 0 },
4422     { WM_CTLCOLORBTN, sent|defwinproc },
4423     { 0 }
4424 };
4425 static const struct message WmKillFocusButtonSeq[] =
4426 {
4427     { HCBT_SETFOCUS, hook },
4428     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4429     { WM_KILLFOCUS, sent|wparam, 0 },
4430     { WM_CTLCOLORBTN, sent|defwinproc },
4431     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
4432     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
4433     { 0 }
4434 };
4435 static const struct message WmSetFocusStaticSeq[] =
4436 {
4437     { HCBT_SETFOCUS, hook },
4438     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
4439     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4440     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4441     { WM_SETFOCUS, sent|wparam, 0 },
4442     { WM_CTLCOLORSTATIC, sent|defwinproc },
4443     { 0 }
4444 };
4445 static const struct message WmKillFocusStaticSeq[] =
4446 {
4447     { HCBT_SETFOCUS, hook },
4448     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4449     { WM_KILLFOCUS, sent|wparam, 0 },
4450     { WM_CTLCOLORSTATIC, sent|defwinproc },
4451     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
4452     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
4453     { 0 }
4454 };
4455 static const struct message WmLButtonDownSeq[] =
4456 {
4457     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
4458     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
4459     { HCBT_SETFOCUS, hook },
4460     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4461     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4462     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4463     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4464     { WM_CTLCOLORBTN, sent|defwinproc },
4465     { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
4466     { WM_CTLCOLORBTN, sent|defwinproc },
4467     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4468     { 0 }
4469 };
4470 static const struct message WmLButtonUpSeq[] =
4471 {
4472     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
4473     { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
4474     { WM_CTLCOLORBTN, sent|defwinproc },
4475     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4476     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
4477     { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
4478     { 0 }
4479 };
4480 static const struct message WmSetFontButtonSeq[] =
4481 {
4482     { WM_SETFONT, sent },
4483     { WM_PAINT, sent },
4484     { WM_ERASEBKGND, sent|defwinproc|optional },
4485     { WM_CTLCOLORBTN, sent|defwinproc },
4486     { 0 }
4487 };
4488
4489 static WNDPROC old_button_proc;
4490
4491 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4492 {
4493     static long defwndproc_counter = 0;
4494     LRESULT ret;
4495     struct message msg;
4496
4497     trace("button: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
4498
4499     /* explicitly ignore WM_GETICON message */
4500     if (message == WM_GETICON) return 0;
4501
4502     msg.message = message;
4503     msg.flags = sent|wparam|lparam;
4504     if (defwndproc_counter) msg.flags |= defwinproc;
4505     msg.wParam = wParam;
4506     msg.lParam = lParam;
4507     add_message(&msg);
4508
4509     if (message == BM_SETSTATE)
4510         ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
4511
4512     defwndproc_counter++;
4513     ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
4514     defwndproc_counter--;
4515
4516     return ret;
4517 }
4518
4519 static void subclass_button(void)
4520 {
4521     WNDCLASSA cls;
4522
4523     if (!GetClassInfoA(0, "button", &cls)) assert(0);
4524
4525     old_button_proc = cls.lpfnWndProc;
4526
4527     cls.hInstance = GetModuleHandle(0);
4528     cls.lpfnWndProc = button_hook_proc;
4529     cls.lpszClassName = "my_button_class";
4530     UnregisterClass(cls.lpszClassName, cls.hInstance);
4531     if (!RegisterClassA(&cls)) assert(0);
4532 }
4533
4534 static void test_button_messages(void)
4535 {
4536     static const struct
4537     {
4538         DWORD style;
4539         DWORD dlg_code;
4540         const struct message *setfocus;
4541         const struct message *killfocus;
4542     } button[] = {
4543         { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
4544           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
4545         { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
4546           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
4547         { BS_CHECKBOX, DLGC_BUTTON,
4548           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4549         { BS_AUTOCHECKBOX, DLGC_BUTTON,
4550           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4551         { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
4552           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4553         { BS_3STATE, DLGC_BUTTON,
4554           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4555         { BS_AUTO3STATE, DLGC_BUTTON,
4556           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4557         { BS_GROUPBOX, DLGC_STATIC,
4558           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4559         { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
4560           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
4561         { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
4562           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4563         { BS_OWNERDRAW, DLGC_BUTTON,
4564           WmSetFocusButtonSeq, WmKillFocusButtonSeq }
4565     };
4566     unsigned int i;
4567     HWND hwnd;
4568     DWORD dlg_code;
4569     HFONT zfont;
4570
4571     subclass_button();
4572
4573     for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
4574     {
4575         hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_POPUP,
4576                                0, 0, 50, 14, 0, 0, 0, NULL);
4577         ok(hwnd != 0, "Failed to create button window\n");
4578
4579         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
4580         ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
4581
4582         ShowWindow(hwnd, SW_SHOW);
4583         UpdateWindow(hwnd);
4584         SetFocus(0);
4585         flush_sequence();
4586
4587         trace("button style %08x\n", button[i].style);
4588         SetFocus(hwnd);
4589         ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
4590
4591         SetFocus(0);
4592         ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
4593
4594         DestroyWindow(hwnd);
4595     }
4596
4597     hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
4598                            0, 0, 50, 14, 0, 0, 0, NULL);
4599     ok(hwnd != 0, "Failed to create button window\n");
4600
4601     SetFocus(0);
4602     flush_events();
4603     flush_sequence();
4604
4605     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
4606     ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
4607
4608     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
4609     ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
4610
4611     flush_sequence();
4612     zfont = (HFONT)GetStockObject(SYSTEM_FONT);
4613     SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
4614     UpdateWindow(hwnd);
4615     ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
4616
4617     DestroyWindow(hwnd);
4618 }
4619
4620 /****************** static message test *************************/
4621 static const struct message WmSetFontStaticSeq[] =
4622 {
4623     { WM_SETFONT, sent },
4624     { WM_PAINT, sent|defwinproc },
4625     { WM_ERASEBKGND, sent|defwinproc|optional },
4626     { WM_CTLCOLORSTATIC, sent|defwinproc },
4627     { 0 }
4628 };
4629
4630 static WNDPROC old_static_proc;
4631
4632 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4633 {
4634     static long defwndproc_counter = 0;
4635     LRESULT ret;
4636     struct message msg;
4637
4638     trace("static: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
4639
4640     /* explicitly ignore WM_GETICON message */
4641     if (message == WM_GETICON) return 0;
4642
4643     msg.message = message;
4644     msg.flags = sent|wparam|lparam;
4645     if (defwndproc_counter) msg.flags |= defwinproc;
4646     msg.wParam = wParam;
4647     msg.lParam = lParam;
4648     add_message(&msg);
4649
4650
4651     defwndproc_counter++;
4652     ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
4653     defwndproc_counter--;
4654
4655     return ret;
4656 }
4657
4658 static void subclass_static(void)
4659 {
4660     WNDCLASSA cls;
4661
4662     if (!GetClassInfoA(0, "static", &cls)) assert(0);
4663
4664     old_static_proc = cls.lpfnWndProc;
4665
4666     cls.hInstance = GetModuleHandle(0);
4667     cls.lpfnWndProc = static_hook_proc;
4668     cls.lpszClassName = "my_static_class";
4669     UnregisterClass(cls.lpszClassName, cls.hInstance);
4670     if (!RegisterClassA(&cls)) assert(0);
4671 }
4672
4673 static void test_static_messages(void)
4674 {
4675     /* FIXME: make as comprehensive as the button message test */
4676     static const struct
4677     {
4678         DWORD style;
4679         DWORD dlg_code;
4680         const struct message *setfont;
4681     } static_ctrl[] = {
4682         { SS_LEFT, DLGC_STATIC,
4683           WmSetFontStaticSeq }
4684     };
4685     unsigned int i;
4686     HWND hwnd;
4687     DWORD dlg_code;
4688
4689     subclass_static();
4690
4691     for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
4692     {
4693         hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
4694                                0, 0, 50, 14, 0, 0, 0, NULL);
4695         ok(hwnd != 0, "Failed to create static window\n");
4696
4697         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
4698         ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
4699
4700         ShowWindow(hwnd, SW_SHOW);
4701         UpdateWindow(hwnd);
4702         SetFocus(0);
4703         flush_sequence();
4704
4705         trace("static style %08x\n", static_ctrl[i].style);
4706         SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
4707         ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
4708
4709         DestroyWindow(hwnd);
4710     }
4711 }
4712
4713 /************* painting message test ********************/
4714
4715 void dump_region(HRGN hrgn)
4716 {
4717     DWORD i, size;
4718     RGNDATA *data = NULL;
4719     RECT *rect;
4720
4721     if (!hrgn)
4722     {
4723         printf( "null region\n" );
4724         return;
4725     }
4726     if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
4727     if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
4728     GetRegionData( hrgn, size, data );
4729     printf("%d rects:", data->rdh.nCount );
4730     for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
4731         printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
4732     printf("\n");
4733     HeapFree( GetProcessHeap(), 0, data );
4734 }
4735
4736 static void check_update_rgn( HWND hwnd, HRGN hrgn )
4737 {
4738     INT ret;
4739     RECT r1, r2;
4740     HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
4741     HRGN update = CreateRectRgn( 0, 0, 0, 0 );
4742
4743     ret = GetUpdateRgn( hwnd, update, FALSE );
4744     ok( ret != ERROR, "GetUpdateRgn failed\n" );
4745     if (ret == NULLREGION)
4746     {
4747         ok( !hrgn, "Update region shouldn't be empty\n" );
4748     }
4749     else
4750     {
4751         if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
4752         {
4753             ok( 0, "Regions are different\n" );
4754             if (winetest_debug > 0)
4755             {
4756                 printf( "Update region: " );
4757                 dump_region( update );
4758                 printf( "Wanted region: " );
4759                 dump_region( hrgn );
4760             }
4761         }
4762     }
4763     GetRgnBox( update, &r1 );
4764     GetUpdateRect( hwnd, &r2, FALSE );
4765     ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
4766         "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
4767         r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
4768
4769     DeleteObject( tmp );
4770     DeleteObject( update );
4771 }
4772
4773 static const struct message WmInvalidateRgn[] = {
4774     { WM_NCPAINT, sent },
4775     { WM_GETTEXT, sent|defwinproc|optional },
4776     { 0 }
4777 };
4778
4779 static const struct message WmGetUpdateRect[] = {
4780     { WM_NCPAINT, sent },
4781     { WM_GETTEXT, sent|defwinproc|optional },
4782     { WM_PAINT, sent },
4783     { 0 }
4784 };
4785
4786 static const struct message WmInvalidateFull[] = {
4787     { WM_NCPAINT, sent|wparam, 1 },
4788     { WM_GETTEXT, sent|defwinproc|optional },
4789     { 0 }
4790 };
4791
4792 static const struct message WmInvalidateErase[] = {
4793     { WM_NCPAINT, sent|wparam, 1 },
4794     { WM_GETTEXT, sent|defwinproc|optional },
4795     { WM_ERASEBKGND, sent },
4796     { 0 }
4797 };
4798
4799 static const struct message WmInvalidatePaint[] = {
4800     { WM_PAINT, sent },
4801     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
4802     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4803     { 0 }
4804 };
4805
4806 static const struct message WmInvalidateErasePaint[] = {
4807     { WM_PAINT, sent },
4808     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
4809     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4810     { WM_ERASEBKGND, sent|beginpaint },
4811     { 0 }
4812 };
4813
4814 static const struct message WmInvalidateErasePaint2[] = {
4815     { WM_PAINT, sent },
4816     { WM_NCPAINT, sent|beginpaint },
4817     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4818     { WM_ERASEBKGND, sent|beginpaint },
4819     { 0 }
4820 };
4821
4822 static const struct message WmErase[] = {
4823     { WM_ERASEBKGND, sent },
4824     { 0 }
4825 };
4826
4827 static const struct message WmPaint[] = {
4828     { WM_PAINT, sent },
4829     { 0 }
4830 };
4831
4832 static const struct message WmParentOnlyPaint[] = {
4833     { WM_PAINT, sent|parent },
4834     { 0 }
4835 };
4836
4837 static const struct message WmInvalidateParent[] = {
4838     { WM_NCPAINT, sent|parent },
4839     { WM_GETTEXT, sent|defwinproc|parent|optional },
4840     { WM_ERASEBKGND, sent|parent },
4841     { 0 }
4842 };
4843
4844 static const struct message WmInvalidateParentChild[] = {
4845     { WM_NCPAINT, sent|parent },
4846     { WM_GETTEXT, sent|defwinproc|parent|optional },
4847     { WM_ERASEBKGND, sent|parent },
4848     { WM_NCPAINT, sent },
4849     { WM_GETTEXT, sent|defwinproc|optional },
4850     { WM_ERASEBKGND, sent },
4851     { 0 }
4852 };
4853
4854 static const struct message WmInvalidateParentChild2[] = {
4855     { WM_ERASEBKGND, sent|parent },
4856     { WM_NCPAINT, sent },
4857     { WM_GETTEXT, sent|defwinproc|optional },
4858     { WM_ERASEBKGND, sent },
4859     { 0 }
4860 };
4861
4862 static const struct message WmParentPaint[] = {
4863     { WM_PAINT, sent|parent },
4864     { WM_PAINT, sent },
4865     { 0 }
4866 };
4867
4868 static const struct message WmParentPaintNc[] = {
4869     { WM_PAINT, sent|parent },
4870     { WM_PAINT, sent },
4871     { WM_NCPAINT, sent|beginpaint },
4872     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4873     { WM_ERASEBKGND, sent|beginpaint },
4874     { 0 }
4875 };
4876
4877 static const struct message WmChildPaintNc[] = {
4878     { WM_PAINT, sent },
4879     { WM_NCPAINT, sent|beginpaint },
4880     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4881     { WM_ERASEBKGND, sent|beginpaint },
4882     { 0 }
4883 };
4884
4885 static const struct message WmParentErasePaint[] = {
4886     { WM_PAINT, sent|parent },
4887     { WM_NCPAINT, sent|parent|beginpaint },
4888     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
4889     { WM_ERASEBKGND, sent|parent|beginpaint },
4890     { WM_PAINT, sent },
4891     { WM_NCPAINT, sent|beginpaint },
4892     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4893     { WM_ERASEBKGND, sent|beginpaint },
4894     { 0 }
4895 };
4896
4897 static const struct message WmParentOnlyNcPaint[] = {
4898     { WM_PAINT, sent|parent },
4899     { WM_NCPAINT, sent|parent|beginpaint },
4900     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
4901     { 0 }
4902 };
4903
4904 static const struct message WmSetParentStyle[] = {
4905     { WM_STYLECHANGING, sent|parent },
4906     { WM_STYLECHANGED, sent|parent },
4907     { 0 }
4908 };
4909
4910 static void test_paint_messages(void)
4911 {
4912     BOOL ret;
4913     RECT rect;
4914     POINT pt;
4915     MSG msg;
4916     HWND hparent, hchild;
4917     HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
4918     HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
4919     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4920                                 100, 100, 200, 200, 0, 0, 0, NULL);
4921     ok (hwnd != 0, "Failed to create overlapped window\n");
4922
4923     ShowWindow( hwnd, SW_SHOW );
4924     UpdateWindow( hwnd );
4925     flush_events();
4926     flush_sequence();
4927
4928     check_update_rgn( hwnd, 0 );
4929     SetRectRgn( hrgn, 10, 10, 20, 20 );
4930     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
4931     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
4932     check_update_rgn( hwnd, hrgn );
4933     SetRectRgn( hrgn2, 20, 20, 30, 30 );
4934     ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
4935     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
4936     CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
4937     check_update_rgn( hwnd, hrgn );
4938     /* validate everything */
4939     ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
4940     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
4941     check_update_rgn( hwnd, 0 );
4942
4943     /* test empty region */
4944     SetRectRgn( hrgn, 10, 10, 10, 15 );
4945     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
4946     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
4947     check_update_rgn( hwnd, 0 );
4948     /* test empty rect */
4949     SetRect( &rect, 10, 10, 10, 15 );
4950     ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
4951     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
4952     check_update_rgn( hwnd, 0 );
4953
4954     /* flush pending messages */
4955     flush_events();
4956     flush_sequence();
4957
4958     GetClientRect( hwnd, &rect );
4959     SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
4960     /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
4961      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
4962      */
4963     trace("testing InvalidateRect(0, NULL, FALSE)\n");
4964     SetRectEmpty( &rect );
4965     ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
4966     check_update_rgn( hwnd, hrgn );
4967     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
4968     flush_events();
4969     ok_sequence( WmPaint, "Paint", FALSE );
4970     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
4971     check_update_rgn( hwnd, 0 );
4972
4973     /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
4974      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
4975      */
4976     trace("testing ValidateRect(0, NULL)\n");
4977     SetRectEmpty( &rect );
4978     ok(ValidateRect(0, &rect), "ValidateRect(0, &rc) should not fail\n");
4979     check_update_rgn( hwnd, hrgn );
4980     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
4981     flush_events();
4982     ok_sequence( WmPaint, "Paint", FALSE );
4983     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
4984     check_update_rgn( hwnd, 0 );
4985
4986     trace("testing InvalidateRgn(0, NULL, FALSE)\n");
4987     SetLastError(0xdeadbeef);
4988     ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
4989     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error code %d\n", GetLastError());
4990     check_update_rgn( hwnd, 0 );
4991     flush_events();
4992     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
4993
4994     trace("testing ValidateRgn(0, NULL)\n");
4995     SetLastError(0xdeadbeef);
4996     ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
4997     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error code %d\n", GetLastError());
4998     check_update_rgn( hwnd, 0 );
4999     flush_events();
5000     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5001
5002     /* now with frame */
5003     SetRectRgn( hrgn, -5, -5, 20, 20 );
5004
5005     /* flush pending messages */
5006     flush_events();
5007     flush_sequence();
5008     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5009     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5010
5011     SetRectRgn( hrgn, 0, 0, 20, 20 );  /* GetUpdateRgn clips to client area */
5012     check_update_rgn( hwnd, hrgn );
5013
5014     flush_sequence();
5015     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5016     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5017
5018     flush_sequence();
5019     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5020     ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
5021
5022     GetClientRect( hwnd, &rect );
5023     SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
5024     check_update_rgn( hwnd, hrgn );
5025
5026     flush_sequence();
5027     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
5028     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5029
5030     flush_sequence();
5031     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
5032     ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
5033     check_update_rgn( hwnd, 0 );
5034
5035     flush_sequence();
5036     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
5037     ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
5038     check_update_rgn( hwnd, 0 );
5039
5040     flush_sequence();
5041     SetRectRgn( hrgn, 0, 0, 100, 100 );
5042     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5043     SetRectRgn( hrgn, 0, 0, 50, 100 );
5044     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
5045     SetRectRgn( hrgn, 50, 0, 100, 100 );
5046     check_update_rgn( hwnd, hrgn );
5047     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5048     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );  /* must not generate messages, everything is valid */
5049     check_update_rgn( hwnd, 0 );
5050
5051     flush_sequence();
5052     SetRectRgn( hrgn, 0, 0, 100, 100 );
5053     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5054     SetRectRgn( hrgn, 0, 0, 100, 50 );
5055     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5056     ok_sequence( WmErase, "Erase", FALSE );
5057     SetRectRgn( hrgn, 0, 50, 100, 100 );
5058     check_update_rgn( hwnd, hrgn );
5059
5060     flush_sequence();
5061     SetRectRgn( hrgn, 0, 0, 100, 100 );
5062     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5063     SetRectRgn( hrgn, 0, 0, 50, 50 );
5064     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
5065     ok_sequence( WmPaint, "Paint", FALSE );
5066
5067     flush_sequence();
5068     SetRectRgn( hrgn, -4, -4, -2, -2 );
5069     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5070     SetRectRgn( hrgn, -200, -200, -198, -198 );
5071     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
5072     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5073
5074     flush_sequence();
5075     SetRectRgn( hrgn, -4, -4, -2, -2 );
5076     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5077     SetRectRgn( hrgn, -4, -4, -3, -3 );
5078     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
5079     SetRectRgn( hrgn, 0, 0, 1, 1 );
5080     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
5081     ok_sequence( WmPaint, "Paint", FALSE );
5082
5083     flush_sequence();
5084     SetRectRgn( hrgn, -4, -4, -1, -1 );
5085     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5086     RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
5087     /* make sure no WM_PAINT was generated */
5088     flush_events();
5089     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5090
5091     flush_sequence();
5092     SetRectRgn( hrgn, -4, -4, -1, -1 );
5093     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5094     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
5095     {
5096         if (msg.hwnd == hwnd && msg.message == WM_PAINT)
5097         {
5098             /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
5099             INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
5100             ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
5101             ret = GetUpdateRect( hwnd, &rect, FALSE );
5102             ok( ret, "Invalid GetUpdateRect result %d\n", ret );
5103             /* this will send WM_NCPAINT and validate the non client area */
5104             ret = GetUpdateRect( hwnd, &rect, TRUE );
5105             ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
5106         }
5107         DispatchMessage( &msg );
5108     }
5109     ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
5110
5111     DestroyWindow( hwnd );
5112
5113     /* now test with a child window */
5114
5115     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
5116                               100, 100, 200, 200, 0, 0, 0, NULL);
5117     ok (hparent != 0, "Failed to create parent window\n");
5118
5119     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
5120                            10, 10, 100, 100, hparent, 0, 0, NULL);
5121     ok (hchild != 0, "Failed to create child window\n");
5122
5123     ShowWindow( hparent, SW_SHOW );
5124     UpdateWindow( hparent );
5125     UpdateWindow( hchild );
5126     flush_events();
5127     flush_sequence();
5128     log_all_parent_messages++;
5129
5130     SetRect( &rect, 0, 0, 50, 50 );
5131     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5132     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5133     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
5134
5135     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5136     pt.x = pt.y = 0;
5137     MapWindowPoints( hchild, hparent, &pt, 1 );
5138     SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
5139     check_update_rgn( hchild, hrgn );
5140     SetRectRgn( hrgn, 0, 0, 50, 50 );
5141     check_update_rgn( hparent, hrgn );
5142     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5143     ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
5144     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5145     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5146
5147     flush_events();
5148     ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
5149
5150     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5151     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5152     ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
5153     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5154     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5155
5156     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
5157     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5158     ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
5159
5160     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
5161     flush_sequence();
5162     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5163     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5164     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
5165
5166     /* flush all paint messages */
5167     flush_events();
5168     flush_sequence();
5169
5170     /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
5171     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5172     SetRectRgn( hrgn, 0, 0, 50, 50 );
5173     check_update_rgn( hparent, hrgn );
5174     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5175     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5176     SetRectRgn( hrgn, 0, 0, 50, 50 );
5177     check_update_rgn( hparent, hrgn );
5178
5179     /* flush all paint messages */
5180     flush_events();
5181     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
5182     flush_sequence();
5183
5184     /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
5185     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5186     SetRectRgn( hrgn, 0, 0, 50, 50 );
5187     check_update_rgn( hparent, hrgn );
5188     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5189     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5190     SetRectRgn( hrgn2, 10, 10, 50, 50 );
5191     CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
5192     check_update_rgn( hparent, hrgn );
5193     /* flush all paint messages */
5194     flush_events();
5195     flush_sequence();
5196
5197     /* same as above but parent gets completely validated */
5198     SetRect( &rect, 20, 20, 30, 30 );
5199     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5200     SetRectRgn( hrgn, 20, 20, 30, 30 );
5201     check_update_rgn( hparent, hrgn );
5202     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5203     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5204     check_update_rgn( hparent, 0 );  /* no update region */
5205     flush_events();
5206     ok_sequence( WmEmptySeq, "WmEmpty", FALSE );  /* and no paint messages */
5207
5208     /* make sure RDW_VALIDATE on child doesn't have the same effect */
5209     flush_sequence();
5210     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5211     SetRectRgn( hrgn, 20, 20, 30, 30 );
5212     check_update_rgn( hparent, hrgn );
5213     RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
5214     SetRectRgn( hrgn, 20, 20, 30, 30 );
5215     check_update_rgn( hparent, hrgn );
5216
5217     /* same as above but normal WM_PAINT doesn't validate parent */
5218     flush_sequence();
5219     SetRect( &rect, 20, 20, 30, 30 );
5220     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5221     SetRectRgn( hrgn, 20, 20, 30, 30 );
5222     check_update_rgn( hparent, hrgn );
5223     /* no WM_PAINT in child while parent still pending */
5224     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5225     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
5226     while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5227     ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
5228
5229     flush_sequence();
5230     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5231     /* no WM_PAINT in child while parent still pending */
5232     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5233     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
5234     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
5235     /* now that parent is valid child should get WM_PAINT */
5236     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5237     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5238     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5239     ok_sequence( WmEmptySeq, "No other message", FALSE );
5240
5241     /* same thing with WS_CLIPCHILDREN in parent */
5242     flush_sequence();
5243     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
5244     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
5245     /* changing style invalidates non client area, but we need to invalidate something else to see it */
5246     RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
5247     ok_sequence( WmEmptySeq, "No message", FALSE );
5248     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
5249     ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
5250
5251     flush_sequence();
5252     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
5253     SetRectRgn( hrgn, 20, 20, 30, 30 );
5254     check_update_rgn( hparent, hrgn );
5255     /* no WM_PAINT in child while parent still pending */
5256     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5257     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
5258     /* WM_PAINT in parent first */
5259     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5260     ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
5261
5262     /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
5263     flush_sequence();
5264     SetRect( &rect, 0, 0, 30, 30 );
5265     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
5266     SetRectRgn( hrgn, 0, 0, 30, 30 );
5267     check_update_rgn( hparent, hrgn );
5268     flush_events();
5269     ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
5270
5271     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
5272     flush_sequence();
5273     SetRect( &rect, -10, 0, 30, 30 );
5274     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
5275     SetRect( &rect, 0, 0, 20, 20 );
5276     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
5277     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
5278     ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
5279
5280     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
5281     flush_sequence();
5282     SetRect( &rect, -10, 0, 30, 30 );
5283     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
5284     SetRect( &rect, 0, 0, 100, 100 );
5285     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
5286     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
5287     ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
5288     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5289     ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
5290
5291     /* test RDW_INTERNALPAINT behavior */
5292
5293     flush_sequence();
5294     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
5295     flush_events();
5296     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
5297
5298     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
5299     flush_events();
5300     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
5301
5302     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
5303     flush_events();
5304     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
5305
5306     assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
5307     UpdateWindow( hparent );
5308     flush_events();
5309     flush_sequence();
5310     trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
5311     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5312     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
5313                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5314     flush_events();
5315     ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
5316
5317     UpdateWindow( hparent );
5318     flush_events();
5319     flush_sequence();
5320     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
5321     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5322     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
5323                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5324     flush_events();
5325     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
5326
5327     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
5328     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
5329     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
5330     flush_events();
5331     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
5332
5333     assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
5334     UpdateWindow( hparent );
5335     flush_events();
5336     flush_sequence();
5337     trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
5338     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5339     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
5340                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5341     flush_events();
5342     ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
5343
5344     UpdateWindow( hparent );
5345     flush_events();
5346     flush_sequence();
5347     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
5348     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5349     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
5350                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5351     flush_events();
5352     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
5353
5354     log_all_parent_messages--;
5355     DestroyWindow( hparent );
5356     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
5357
5358     DeleteObject( hrgn );
5359     DeleteObject( hrgn2 );
5360 }
5361
5362 struct wnd_event
5363 {
5364     HWND hwnd;
5365     HANDLE event;
5366 };
5367
5368 static DWORD WINAPI thread_proc(void *param)
5369 {
5370     MSG msg;
5371     struct wnd_event *wnd_event = (struct wnd_event *)param;
5372
5373     wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
5374                                       100, 100, 200, 200, 0, 0, 0, NULL);
5375     ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
5376
5377     SetEvent(wnd_event->event);
5378
5379     while (GetMessage(&msg, 0, 0, 0))
5380     {
5381         TranslateMessage(&msg);
5382         DispatchMessage(&msg);
5383     }
5384
5385     ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
5386
5387     return 0;
5388 }
5389
5390 static void test_interthread_messages(void)
5391 {
5392     HANDLE hThread;
5393     DWORD tid;
5394     WNDPROC proc;
5395     MSG msg;
5396     char buf[256];
5397     int len, expected_len;
5398     struct wnd_event wnd_event;
5399     BOOL ret;
5400
5401     wnd_event.event = CreateEventW(NULL, 0, 0, NULL);
5402     if (!wnd_event.event)
5403     {
5404         trace("skipping interthread message test under win9x\n");
5405         return;
5406     }
5407
5408     hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
5409     ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
5410
5411     ok(WaitForSingleObject(wnd_event.event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5412
5413     CloseHandle(wnd_event.event);
5414
5415     SetLastError(0xdeadbeef);
5416     ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
5417     ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error code %d\n", GetLastError());
5418
5419     proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
5420     ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
5421
5422     expected_len = lstrlenA("window caption text");
5423     memset(buf, 0, sizeof(buf));
5424     SetLastError(0xdeadbeef);
5425     len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
5426     ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
5427     ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
5428
5429     msg.hwnd = wnd_event.hwnd;
5430     msg.message = WM_GETTEXT;
5431     msg.wParam = sizeof(buf);
5432     msg.lParam = (LPARAM)buf;
5433     memset(buf, 0, sizeof(buf));
5434     SetLastError(0xdeadbeef);
5435     len = DispatchMessageA(&msg);
5436     ok(!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY,
5437        "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
5438
5439     /* the following test causes an exception in user.exe under win9x */
5440     msg.hwnd = wnd_event.hwnd;
5441     msg.message = WM_TIMER;
5442     msg.wParam = 0;
5443     msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
5444     SetLastError(0xdeadbeef);
5445     len = DispatchMessageA(&msg);
5446     ok(!len && GetLastError() == 0xdeadbeef,
5447        "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
5448
5449     ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
5450     ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
5451
5452     ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5453     CloseHandle(hThread);
5454
5455     ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
5456 }
5457
5458
5459 static const struct message WmVkN[] = {
5460     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5461     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5462     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
5463     { WM_CHAR, wparam|lparam, 'n', 1 },
5464     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
5465     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5466     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5467     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5468     { 0 }
5469 };
5470 static const struct message WmShiftVkN[] = {
5471     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
5472     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
5473     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
5474     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5475     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5476     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
5477     { WM_CHAR, wparam|lparam, 'N', 1 },
5478     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
5479     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5480     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5481     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5482     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
5483     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
5484     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
5485     { 0 }
5486 };
5487 static const struct message WmCtrlVkN[] = {
5488     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5489     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5490     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5491     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5492     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5493     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
5494     { WM_CHAR, wparam|lparam, 0x000e, 1 },
5495     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
5496     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5497     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5498     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5499     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5500     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5501     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5502     { 0 }
5503 };
5504 static const struct message WmCtrlVkN_2[] = {
5505     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5506     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5507     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5508     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5509     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5510     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
5511     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5512     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5513     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5514     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5515     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5516     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5517     { 0 }
5518 };
5519 static const struct message WmAltVkN[] = {
5520     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5521     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5522     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5523     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
5524     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
5525     { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
5526     { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
5527     { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
5528     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
5529     { HCBT_SYSCOMMAND, hook },
5530     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
5531     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5532     { 0x00AE, sent|defwinproc|optional }, /* XP */
5533     { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
5534     { WM_INITMENU, sent|defwinproc },
5535     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
5536     { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
5537     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5538     { WM_CAPTURECHANGED, sent|defwinproc },
5539     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
5540     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
5541     { WM_EXITMENULOOP, sent|defwinproc },
5542     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
5543     { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
5544     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
5545     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
5546     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
5547     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5548     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5549     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5550     { 0 }
5551 };
5552 static const struct message WmAltVkN_2[] = {
5553     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5554     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5555     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5556     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
5557     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
5558     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
5559     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
5560     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
5561     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
5562     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5563     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5564     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5565     { 0 }
5566 };
5567 static const struct message WmCtrlAltVkN[] = {
5568     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5569     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5570     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5571     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5572     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5573     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5574     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
5575     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
5576     { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
5577     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
5578     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
5579     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
5580     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5581     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5582     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5583     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5584     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5585     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5586     { 0 }
5587 };
5588 static const struct message WmCtrlShiftVkN[] = {
5589     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5590     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5591     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5592     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
5593     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
5594     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
5595     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5596     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5597     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
5598     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5599     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5600     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5601     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
5602     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
5603     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
5604     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5605     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5606     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5607     { 0 }
5608 };
5609 static const struct message WmCtrlAltShiftVkN[] = {
5610     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5611     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5612     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5613     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5614     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5615     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5616     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
5617     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
5618     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
5619     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
5620     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
5621     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
5622     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
5623     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
5624     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
5625     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
5626     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
5627     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
5628     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5629     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5630     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5631     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5632     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5633     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5634     { 0 }
5635 };
5636 static const struct message WmAltPressRelease[] = {
5637     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5638     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5639     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5640     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5641     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5642     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5643     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
5644     { HCBT_SYSCOMMAND, hook },
5645     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
5646     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5647     { WM_INITMENU, sent|defwinproc },
5648     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
5649     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
5650     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
5651
5652     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
5653
5654     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
5655     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
5656     { WM_CAPTURECHANGED, sent|defwinproc },
5657     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
5658     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
5659     { WM_EXITMENULOOP, sent|defwinproc },
5660     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5661     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5662     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5663     { 0 }
5664 };
5665 static const struct message WmAltMouseButton[] = {
5666     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5667     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5668     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5669     { WM_MOUSEMOVE, wparam|optional, 0, 0 },
5670     { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
5671     { WM_LBUTTONDOWN, wparam, MK_LBUTTON, 0 },
5672     { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON, 0 },
5673     { WM_LBUTTONUP, wparam, 0, 0 },
5674     { WM_LBUTTONUP, sent|wparam, 0, 0 },
5675     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5676     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5677     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5678     { 0 }
5679 };
5680 static const struct message WmF1Seq[] = {
5681     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
5682     { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
5683     { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
5684     { 0x4d, wparam|lparam, 0, 0 },
5685     { 0x4d, sent|wparam|lparam, 0, 0 },
5686     { WM_HELP, sent|defwinproc },
5687     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
5688     { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
5689     { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
5690     { 0 }
5691 };
5692 static const struct message WmVkAppsSeq[] = {
5693     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
5694     { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
5695     { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
5696     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
5697     { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
5698     { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
5699     { WM_CONTEXTMENU, lparam, /*hwnd*/0, (LPARAM)-1 },
5700     { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, (LPARAM)-1 },
5701     { 0 }
5702 };
5703
5704 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
5705 {
5706     MSG msg;
5707
5708     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
5709     {
5710         struct message log_msg;
5711
5712         trace("accel: %p, %04x, %08lx, %08lx\n", msg.hwnd, msg.message, msg.wParam, msg.lParam);
5713
5714         /* ignore some unwanted messages */
5715         if (msg.message == WM_MOUSEMOVE ||
5716             msg.message == WM_GETICON ||
5717             msg.message == WM_DEVICECHANGE)
5718             continue;
5719
5720         log_msg.message = msg.message;
5721         log_msg.flags = wparam|lparam;
5722         log_msg.wParam = msg.wParam;
5723         log_msg.lParam = msg.lParam;
5724         add_message(&log_msg);
5725
5726         if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
5727         {
5728             TranslateMessage(&msg);
5729             DispatchMessage(&msg);
5730         }
5731     }
5732 }
5733
5734 static void test_accelerators(void)
5735 {
5736     RECT rc;
5737     SHORT state;
5738     HACCEL hAccel;
5739     HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5740                                 100, 100, 200, 200, 0, 0, 0, NULL);
5741     BOOL ret;
5742
5743     assert(hwnd != 0);
5744     UpdateWindow(hwnd);
5745     flush_events();
5746     flush_sequence();
5747
5748     SetFocus(hwnd);
5749     ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
5750
5751     state = GetKeyState(VK_SHIFT);
5752     ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
5753     state = GetKeyState(VK_CAPITAL);
5754     ok(state == 0, "wrong CapsLock state %04x\n", state);
5755
5756     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
5757     assert(hAccel != 0);
5758
5759     pump_msg_loop(hwnd, 0);
5760     flush_sequence();
5761
5762     trace("testing VK_N press/release\n");
5763     flush_sequence();
5764     keybd_event('N', 0, 0, 0);
5765     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5766     pump_msg_loop(hwnd, hAccel);
5767     ok_sequence(WmVkN, "VK_N press/release", FALSE);
5768
5769     trace("testing Shift+VK_N press/release\n");
5770     flush_sequence();
5771     keybd_event(VK_SHIFT, 0, 0, 0);
5772     keybd_event('N', 0, 0, 0);
5773     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5774     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
5775     pump_msg_loop(hwnd, hAccel);
5776     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
5777
5778     trace("testing Ctrl+VK_N press/release\n");
5779     flush_sequence();
5780     keybd_event(VK_CONTROL, 0, 0, 0);
5781     keybd_event('N', 0, 0, 0);
5782     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5783     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
5784     pump_msg_loop(hwnd, hAccel);
5785     ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
5786
5787     trace("testing Alt+VK_N press/release\n");
5788     flush_sequence();
5789     keybd_event(VK_MENU, 0, 0, 0);
5790     keybd_event('N', 0, 0, 0);
5791     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5792     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
5793     pump_msg_loop(hwnd, hAccel);
5794     ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
5795
5796     trace("testing Ctrl+Alt+VK_N press/release 1\n");
5797     flush_sequence();
5798     keybd_event(VK_CONTROL, 0, 0, 0);
5799     keybd_event(VK_MENU, 0, 0, 0);
5800     keybd_event('N', 0, 0, 0);
5801     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5802     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
5803     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
5804     pump_msg_loop(hwnd, hAccel);
5805     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
5806
5807     ret = DestroyAcceleratorTable(hAccel);
5808     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
5809
5810     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
5811     assert(hAccel != 0);
5812
5813     trace("testing VK_N press/release\n");
5814     flush_sequence();
5815     keybd_event('N', 0, 0, 0);
5816     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5817     pump_msg_loop(hwnd, hAccel);
5818     ok_sequence(WmVkN, "VK_N press/release", FALSE);
5819
5820     trace("testing Shift+VK_N press/release\n");
5821     flush_sequence();
5822     keybd_event(VK_SHIFT, 0, 0, 0);
5823     keybd_event('N', 0, 0, 0);
5824     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5825     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
5826     pump_msg_loop(hwnd, hAccel);
5827     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
5828
5829     trace("testing Ctrl+VK_N press/release 2\n");
5830     flush_sequence();
5831     keybd_event(VK_CONTROL, 0, 0, 0);
5832     keybd_event('N', 0, 0, 0);
5833     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5834     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
5835     pump_msg_loop(hwnd, hAccel);
5836     ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
5837
5838     trace("testing Alt+VK_N press/release 2\n");
5839     flush_sequence();
5840     keybd_event(VK_MENU, 0, 0, 0);
5841     keybd_event('N', 0, 0, 0);
5842     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5843     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
5844     pump_msg_loop(hwnd, hAccel);
5845     ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
5846
5847     trace("testing Ctrl+Alt+VK_N press/release 2\n");
5848     flush_sequence();
5849     keybd_event(VK_CONTROL, 0, 0, 0);
5850     keybd_event(VK_MENU, 0, 0, 0);
5851     keybd_event('N', 0, 0, 0);
5852     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5853     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
5854     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
5855     pump_msg_loop(hwnd, hAccel);
5856     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
5857
5858     trace("testing Ctrl+Shift+VK_N press/release\n");
5859     flush_sequence();
5860     keybd_event(VK_CONTROL, 0, 0, 0);
5861     keybd_event(VK_SHIFT, 0, 0, 0);
5862     keybd_event('N', 0, 0, 0);
5863     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5864     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
5865     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
5866     pump_msg_loop(hwnd, hAccel);
5867     ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
5868
5869     trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
5870     flush_sequence();
5871     keybd_event(VK_CONTROL, 0, 0, 0);
5872     keybd_event(VK_MENU, 0, 0, 0);
5873     keybd_event(VK_SHIFT, 0, 0, 0);
5874     keybd_event('N', 0, 0, 0);
5875     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
5876     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
5877     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
5878     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
5879     pump_msg_loop(hwnd, hAccel);
5880     ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
5881
5882     ret = DestroyAcceleratorTable(hAccel);
5883     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
5884
5885     trace("testing Alt press/release\n");
5886     flush_sequence();
5887     keybd_event(VK_MENU, 0, 0, 0);
5888     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
5889     keybd_event(VK_MENU, 0, 0, 0);
5890     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
5891     pump_msg_loop(hwnd, 0);
5892     /* this test doesn't pass in Wine for managed windows */
5893     ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
5894
5895     trace("testing Alt+MouseButton press/release\n");
5896     /* first, move mouse pointer inside of the window client area */
5897     GetClientRect(hwnd, &rc);
5898     MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
5899     rc.left += (rc.right - rc.left)/2;
5900     rc.top += (rc.bottom - rc.top)/2;
5901     SetCursorPos(rc.left, rc.top);
5902
5903     flush_events();
5904     flush_sequence();
5905     keybd_event(VK_MENU, 0, 0, 0);
5906     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
5907     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
5908     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
5909     pump_msg_loop(hwnd, 0);
5910     ok_sequence(WmAltMouseButton, "Alt+MouseButton press/release", FALSE);
5911
5912     trace("testing VK_F1 press/release\n");
5913     keybd_event(VK_F1, 0, 0, 0);
5914     keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
5915     pump_msg_loop(hwnd, 0);
5916     ok_sequence(WmF1Seq, "F1 press/release", TRUE);
5917
5918     trace("testing VK_APPS press/release\n");
5919     keybd_event(VK_APPS, 0, 0, 0);
5920     keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
5921     pump_msg_loop(hwnd, 0);
5922     ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
5923
5924     DestroyWindow(hwnd);
5925 }
5926
5927 /************* window procedures ********************/
5928
5929 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message, 
5930                              WPARAM wParam, LPARAM lParam)
5931 {
5932     static long defwndproc_counter = 0;
5933     static long beginpaint_counter = 0;
5934     LRESULT ret;
5935     struct message msg;
5936
5937     trace("%p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
5938
5939     /* explicitly ignore WM_GETICON message */
5940     if (message == WM_GETICON) return 0;
5941
5942     switch (message)
5943     {
5944         case WM_ENABLE:
5945         {
5946             LONG style = GetWindowLongA(hwnd, GWL_STYLE);
5947             ok((BOOL)wParam == !(style & WS_DISABLED),
5948                 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
5949             break;
5950         }
5951
5952         case WM_CAPTURECHANGED:
5953             if (test_DestroyWindow_flag)
5954             {
5955                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
5956                 if (style & WS_CHILD)
5957                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
5958                 else if (style & WS_POPUP)
5959                     lParam = WND_POPUP_ID;
5960                 else
5961                     lParam = WND_PARENT_ID;
5962             }
5963             break;
5964
5965         case WM_NCDESTROY:
5966         {
5967             HWND capture;
5968
5969             ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
5970             capture = GetCapture();
5971             if (capture)
5972             {
5973                 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
5974                 trace("current capture %p, releasing...\n", capture);
5975                 ReleaseCapture();
5976             }
5977         }
5978         /* fall through */
5979         case WM_DESTROY:
5980             if (pGetAncestor)
5981                 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
5982             if (test_DestroyWindow_flag)
5983             {
5984                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
5985                 if (style & WS_CHILD)
5986                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
5987                 else if (style & WS_POPUP)
5988                     lParam = WND_POPUP_ID;
5989                 else
5990                     lParam = WND_PARENT_ID;
5991             }
5992             break;
5993
5994         /* test_accelerators() depends on this */
5995         case WM_NCHITTEST:
5996             return HTCLIENT;
5997     
5998         /* ignore */
5999         case WM_MOUSEMOVE:
6000         case WM_SETCURSOR:
6001         case WM_DEVICECHANGE:
6002             return 0;
6003
6004         case WM_WINDOWPOSCHANGING:
6005         case WM_WINDOWPOSCHANGED:
6006         {
6007             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6008
6009             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6010             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6011                   winpos->hwnd, winpos->hwndInsertAfter,
6012                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6013             dump_winpos_flags(winpos->flags);
6014
6015             /* Log only documented flags, win2k uses 0x1000 and 0x2000
6016              * in the high word for internal purposes
6017              */
6018             wParam = winpos->flags & 0xffff;
6019             /* We are not interested in the flags that don't match under XP and Win9x */
6020             wParam &= ~(SWP_NOZORDER);
6021             break;
6022         }
6023     }
6024
6025     msg.message = message;
6026     msg.flags = sent|wparam|lparam;
6027     if (defwndproc_counter) msg.flags |= defwinproc;
6028     if (beginpaint_counter) msg.flags |= beginpaint;
6029     msg.wParam = wParam;
6030     msg.lParam = lParam;
6031     add_message(&msg);
6032
6033     if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
6034     {
6035         HWND parent = GetParent(hwnd);
6036         RECT rc;
6037         MINMAXINFO *minmax = (MINMAXINFO *)lParam;
6038
6039         GetClientRect(parent, &rc);
6040         trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
6041
6042         trace("ptReserved = (%d,%d)\n"
6043               "ptMaxSize = (%d,%d)\n"
6044               "ptMaxPosition = (%d,%d)\n"
6045               "ptMinTrackSize = (%d,%d)\n"
6046               "ptMaxTrackSize = (%d,%d)\n",
6047               minmax->ptReserved.x, minmax->ptReserved.y,
6048               minmax->ptMaxSize.x, minmax->ptMaxSize.y,
6049               minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
6050               minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
6051               minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
6052
6053         ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
6054            minmax->ptMaxSize.x, rc.right);
6055         ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
6056            minmax->ptMaxSize.y, rc.bottom);
6057     }
6058
6059     if (message == WM_PAINT)
6060     {
6061         PAINTSTRUCT ps;
6062         beginpaint_counter++;
6063         BeginPaint( hwnd, &ps );
6064         beginpaint_counter--;
6065         EndPaint( hwnd, &ps );
6066         return 0;
6067     }
6068
6069     defwndproc_counter++;
6070     ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam) 
6071                   : DefWindowProcA(hwnd, message, wParam, lParam);
6072     defwndproc_counter--;
6073
6074     return ret;
6075 }
6076
6077 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6078 {
6079     return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
6080 }
6081
6082 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6083 {
6084     return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
6085 }
6086
6087 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6088 {
6089     static long defwndproc_counter = 0;
6090     LRESULT ret;
6091     struct message msg;
6092
6093     trace("popup: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6094
6095     /* explicitly ignore WM_GETICON message */
6096     if (message == WM_GETICON) return 0;
6097
6098     msg.message = message;
6099     msg.flags = sent|wparam|lparam;
6100     if (defwndproc_counter) msg.flags |= defwinproc;
6101     msg.wParam = wParam;
6102     msg.lParam = lParam;
6103     add_message(&msg);
6104
6105     if (message == WM_CREATE)
6106     {
6107         DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
6108         SetWindowLongA(hwnd, GWL_STYLE, style);
6109     }
6110
6111     defwndproc_counter++;
6112     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6113     defwndproc_counter--;
6114
6115     return ret;
6116 }
6117
6118 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6119 {
6120     static long defwndproc_counter = 0;
6121     static long beginpaint_counter = 0;
6122     LRESULT ret;
6123     struct message msg;
6124
6125     trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6126
6127     /* explicitly ignore WM_GETICON message */
6128     if (message == WM_GETICON) return 0;
6129
6130     if (log_all_parent_messages ||
6131         message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
6132         message == WM_SETFOCUS || message == WM_KILLFOCUS ||
6133         message == WM_ENABLE || message == WM_ENTERIDLE ||
6134         message == WM_IME_SETCONTEXT)
6135     {
6136         switch (message)
6137         {
6138             /* ignore */
6139             case WM_NCHITTEST:
6140                 return HTCLIENT;
6141             case WM_SETCURSOR:
6142             case WM_MOUSEMOVE:
6143                 return 0;
6144
6145             case WM_ERASEBKGND:
6146             {
6147                 RECT rc;
6148                 INT ret = GetClipBox((HDC)wParam, &rc);
6149
6150                 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
6151                        ret, rc.left, rc.top, rc.right, rc.bottom);
6152                 break;
6153             }
6154
6155             case WM_WINDOWPOSCHANGING:
6156             case WM_WINDOWPOSCHANGED:
6157             {
6158                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6159
6160                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6161                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6162                       winpos->hwnd, winpos->hwndInsertAfter,
6163                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6164                 dump_winpos_flags(winpos->flags);
6165
6166                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
6167                  * in the high word for internal purposes
6168                  */
6169                 wParam = winpos->flags & 0xffff;
6170                 /* We are not interested in the flags that don't match under XP and Win9x */
6171                 wParam &= ~(SWP_NOZORDER);
6172                 break;
6173             }
6174         }
6175
6176         msg.message = message;
6177         msg.flags = sent|parent|wparam|lparam;
6178         if (defwndproc_counter) msg.flags |= defwinproc;
6179         if (beginpaint_counter) msg.flags |= beginpaint;
6180         msg.wParam = wParam;
6181         msg.lParam = lParam;
6182         add_message(&msg);
6183     }
6184
6185     if (message == WM_PAINT)
6186     {
6187         PAINTSTRUCT ps;
6188         beginpaint_counter++;
6189         BeginPaint( hwnd, &ps );
6190         beginpaint_counter--;
6191         EndPaint( hwnd, &ps );
6192         return 0;
6193     }
6194
6195     defwndproc_counter++;
6196     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6197     defwndproc_counter--;
6198
6199     return ret;
6200 }
6201
6202 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6203 {
6204     static long defwndproc_counter = 0;
6205     LRESULT ret;
6206     struct message msg;
6207
6208     trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6209
6210     /* explicitly ignore WM_GETICON message */
6211     if (message == WM_GETICON) return 0;
6212
6213     if (test_def_id)
6214     {
6215         DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
6216         ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
6217         if (after_end_dialog)
6218             ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
6219         else
6220             ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
6221     }
6222
6223     switch (message)
6224     {
6225         case WM_WINDOWPOSCHANGING:
6226         case WM_WINDOWPOSCHANGED:
6227         {
6228             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6229
6230             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6231             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6232                   winpos->hwnd, winpos->hwndInsertAfter,
6233                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6234             dump_winpos_flags(winpos->flags);
6235
6236             /* Log only documented flags, win2k uses 0x1000 and 0x2000
6237              * in the high word for internal purposes
6238              */
6239             wParam = winpos->flags & 0xffff;
6240             /* We are not interested in the flags that don't match under XP and Win9x */
6241             wParam &= ~(SWP_NOZORDER);
6242             break;
6243         }
6244     }
6245
6246     msg.message = message;
6247     msg.flags = sent|wparam|lparam;
6248     if (defwndproc_counter) msg.flags |= defwinproc;
6249     msg.wParam = wParam;
6250     msg.lParam = lParam;
6251     add_message(&msg);
6252
6253     defwndproc_counter++;
6254     ret = DefDlgProcA(hwnd, message, wParam, lParam);
6255     defwndproc_counter--;
6256
6257     return ret;
6258 }
6259
6260 static void dump_winpos_flags(UINT flags)
6261 {
6262     if (!winetest_debug) return;
6263
6264     if (flags & SWP_SHOWWINDOW) printf("|SWP_SHOWWINDOW");
6265     if (flags & SWP_HIDEWINDOW) printf("|SWP_HIDEWINDOW");
6266     if (flags & SWP_NOACTIVATE) printf("|SWP_NOACTIVATE");
6267     if (flags & SWP_FRAMECHANGED) printf("|SWP_FRAMECHANGED");
6268     if (flags & SWP_NOCOPYBITS) printf("|SWP_NOCOPYBITS");
6269     if (flags & SWP_NOOWNERZORDER) printf("|SWP_NOOWNERZORDER");
6270     if (flags & SWP_NOSENDCHANGING) printf("|SWP_NOSENDCHANGING");
6271     if (flags & SWP_DEFERERASE) printf("|SWP_DEFERERASE");
6272     if (flags & SWP_ASYNCWINDOWPOS) printf("|SWP_ASYNCWINDOWPOS");
6273     if (flags & SWP_NOZORDER) printf("|SWP_NOZORDER");
6274     if (flags & SWP_NOREDRAW) printf("|SWP_NOREDRAW");
6275     if (flags & SWP_NOSIZE) printf("|SWP_NOSIZE");
6276     if (flags & SWP_NOMOVE) printf("|SWP_NOMOVE");
6277     if (flags & SWP_NOCLIENTSIZE) printf("|SWP_NOCLIENTSIZE");
6278     if (flags & SWP_NOCLIENTMOVE) printf("|SWP_NOCLIENTMOVE");
6279
6280 #define DUMPED_FLAGS \
6281     (SWP_NOSIZE | \
6282     SWP_NOMOVE | \
6283     SWP_NOZORDER | \
6284     SWP_NOREDRAW | \
6285     SWP_NOACTIVATE | \
6286     SWP_FRAMECHANGED | \
6287     SWP_SHOWWINDOW | \
6288     SWP_HIDEWINDOW | \
6289     SWP_NOCOPYBITS | \
6290     SWP_NOOWNERZORDER | \
6291     SWP_NOSENDCHANGING | \
6292     SWP_DEFERERASE | \
6293     SWP_ASYNCWINDOWPOS | \
6294     SWP_NOCLIENTSIZE | \
6295     SWP_NOCLIENTMOVE)
6296
6297     if(flags & ~DUMPED_FLAGS) printf("|0x%04x", flags & ~DUMPED_FLAGS);
6298     printf("\n");
6299 #undef DUMPED_FLAGS
6300 }
6301
6302 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6303 {
6304     static long defwndproc_counter = 0;
6305     LRESULT ret;
6306     struct message msg;
6307
6308     /* log only specific messages we are interested in */
6309     switch (message)
6310     {
6311 #if 0 /* probably log these as well */
6312     case WM_ACTIVATE:
6313     case WM_SETFOCUS:
6314     case WM_KILLFOCUS:
6315 #endif
6316     case WM_SHOWWINDOW:
6317         trace("WM_SHOWWINDOW %ld\n", wParam);
6318         break;
6319     case WM_SIZE:
6320         trace("WM_SIZE %ld\n", wParam);
6321         break;
6322     case WM_MOVE:
6323         trace("WM_MOVE\n");
6324         break;
6325     case WM_GETMINMAXINFO:
6326         trace("WM_GETMINMAXINFO\n");
6327         break;
6328
6329     case WM_WINDOWPOSCHANGING:
6330     case WM_WINDOWPOSCHANGED:
6331     {
6332         WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6333
6334         trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6335         trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6336               winpos->hwnd, winpos->hwndInsertAfter,
6337               winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6338         trace("flags: ");
6339         dump_winpos_flags(winpos->flags);
6340
6341         /* Log only documented flags, win2k uses 0x1000 and 0x2000
6342          * in the high word for internal purposes
6343          */
6344         wParam = winpos->flags & 0xffff;
6345         /* We are not interested in the flags that don't match under XP and Win9x */
6346         wParam &= ~(SWP_NOZORDER);
6347         break;
6348     }
6349
6350     default: /* ignore */
6351         /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
6352         return DefWindowProcA(hwnd, message, wParam, lParam);
6353     }
6354
6355     msg.message = message;
6356     msg.flags = sent|wparam|lparam;
6357     if (defwndproc_counter) msg.flags |= defwinproc;
6358     msg.wParam = wParam;
6359     msg.lParam = lParam;
6360     add_message(&msg);
6361
6362     defwndproc_counter++;
6363     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6364     defwndproc_counter--;
6365
6366     return ret;
6367 }
6368
6369 static BOOL RegisterWindowClasses(void)
6370 {
6371     WNDCLASSA cls;
6372     WNDCLASSW clsW;
6373
6374     cls.style = 0;
6375     cls.lpfnWndProc = MsgCheckProcA;
6376     cls.cbClsExtra = 0;
6377     cls.cbWndExtra = 0;
6378     cls.hInstance = GetModuleHandleA(0);
6379     cls.hIcon = 0;
6380     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
6381     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6382     cls.lpszMenuName = NULL;
6383     cls.lpszClassName = "TestWindowClass";
6384     if(!RegisterClassA(&cls)) return FALSE;
6385
6386     cls.lpfnWndProc = ShowWindowProcA;
6387     cls.lpszClassName = "ShowWindowClass";
6388     if(!RegisterClassA(&cls)) return FALSE;
6389
6390     cls.lpfnWndProc = PopupMsgCheckProcA;
6391     cls.lpszClassName = "TestPopupClass";
6392     if(!RegisterClassA(&cls)) return FALSE;
6393
6394     cls.lpfnWndProc = ParentMsgCheckProcA;
6395     cls.lpszClassName = "TestParentClass";
6396     if(!RegisterClassA(&cls)) return FALSE;
6397
6398     cls.lpfnWndProc = DefWindowProcA;
6399     cls.lpszClassName = "SimpleWindowClass";
6400     if(!RegisterClassA(&cls)) return FALSE;
6401
6402     cls.style = CS_NOCLOSE;
6403     cls.lpszClassName = "NoCloseWindowClass";
6404     if(!RegisterClassA(&cls)) return FALSE;
6405
6406     ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
6407     cls.style = 0;
6408     cls.hInstance = GetModuleHandleA(0);
6409     cls.hbrBackground = 0;
6410     cls.lpfnWndProc = TestDlgProcA;
6411     cls.lpszClassName = "TestDialogClass";
6412     if(!RegisterClassA(&cls)) return FALSE;
6413
6414     clsW.style = 0;
6415     clsW.lpfnWndProc = MsgCheckProcW;
6416     clsW.cbClsExtra = 0;
6417     clsW.cbWndExtra = 0;
6418     clsW.hInstance = GetModuleHandleW(0);
6419     clsW.hIcon = 0;
6420     clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
6421     clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
6422     clsW.lpszMenuName = NULL;
6423     clsW.lpszClassName = testWindowClassW;
6424     RegisterClassW(&clsW);  /* ignore error, this fails on Win9x */
6425
6426     return TRUE;
6427 }
6428
6429 static HHOOK hCBT_hook;
6430 static DWORD cbt_hook_thread_id;
6431
6432 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
6433
6434     static const char * const CBT_code_name[10] = {
6435         "HCBT_MOVESIZE",
6436         "HCBT_MINMAX",
6437         "HCBT_QS",
6438         "HCBT_CREATEWND",
6439         "HCBT_DESTROYWND",
6440         "HCBT_ACTIVATE",
6441         "HCBT_CLICKSKIPPED",
6442         "HCBT_KEYSKIPPED",
6443         "HCBT_SYSCOMMAND",
6444         "HCBT_SETFOCUS" };
6445     const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
6446     HWND hwnd;
6447     char buf[256];
6448
6449     trace("CBT: %d (%s), %08lx, %08lx\n", nCode, code_name, wParam, lParam);
6450
6451     ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
6452
6453     if (nCode == HCBT_CLICKSKIPPED)
6454     {
6455         /* ignore this event, XP sends it a lot when switching focus between windows */
6456         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
6457     }
6458
6459     if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
6460     {
6461         struct message msg;
6462
6463         msg.message = nCode;
6464         msg.flags = hook|wparam|lparam;
6465         msg.wParam = wParam;
6466         msg.lParam = lParam;
6467         add_message(&msg);
6468
6469         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
6470     }
6471
6472     if (nCode == HCBT_DESTROYWND)
6473     {
6474         if (test_DestroyWindow_flag)
6475         {
6476             DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
6477             if (style & WS_CHILD)
6478                 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
6479             else if (style & WS_POPUP)
6480                 lParam = WND_POPUP_ID;
6481             else
6482                 lParam = WND_PARENT_ID;
6483         }
6484     }
6485
6486     /* Log also SetFocus(0) calls */
6487     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
6488
6489     if (GetClassNameA(hwnd, buf, sizeof(buf)))
6490     {
6491         if (!lstrcmpiA(buf, "TestWindowClass") ||
6492             !lstrcmpiA(buf, "ShowWindowClass") ||
6493             !lstrcmpiA(buf, "TestParentClass") ||
6494             !lstrcmpiA(buf, "TestPopupClass") ||
6495             !lstrcmpiA(buf, "SimpleWindowClass") ||
6496             !lstrcmpiA(buf, "TestDialogClass") ||
6497             !lstrcmpiA(buf, "MDI_frame_class") ||
6498             !lstrcmpiA(buf, "MDI_client_class") ||
6499             !lstrcmpiA(buf, "MDI_child_class") ||
6500             !lstrcmpiA(buf, "my_button_class") ||
6501             !lstrcmpiA(buf, "my_edit_class") ||
6502             !lstrcmpiA(buf, "static") ||
6503             !lstrcmpiA(buf, "MyDialogClass") ||
6504             !lstrcmpiA(buf, "#32770"))
6505         {
6506             struct message msg;
6507
6508             msg.message = nCode;
6509             msg.flags = hook|wparam|lparam;
6510             msg.wParam = wParam;
6511             msg.lParam = lParam;
6512             add_message(&msg);
6513         }
6514     }
6515     return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
6516 }
6517
6518 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
6519                                     DWORD event,
6520                                     HWND hwnd,
6521                                     LONG object_id,
6522                                     LONG child_id,
6523                                     DWORD thread_id,
6524                                     DWORD event_time)
6525 {
6526     char buf[256];
6527
6528     trace("WEH:%p,event %08x,hwnd %p,obj %08x,id %08x,thread %08x,time %08x\n",
6529            hevent, event, hwnd, object_id, child_id, thread_id, event_time);
6530
6531     ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
6532
6533     /* ignore mouse cursor events */
6534     if (object_id == OBJID_CURSOR) return;
6535
6536     if (!hwnd || GetClassNameA(hwnd, buf, sizeof(buf)))
6537     {
6538         if (!hwnd ||
6539             !lstrcmpiA(buf, "TestWindowClass") ||
6540             !lstrcmpiA(buf, "TestParentClass") ||
6541             !lstrcmpiA(buf, "TestPopupClass") ||
6542             !lstrcmpiA(buf, "SimpleWindowClass") ||
6543             !lstrcmpiA(buf, "TestDialogClass") ||
6544             !lstrcmpiA(buf, "MDI_frame_class") ||
6545             !lstrcmpiA(buf, "MDI_client_class") ||
6546             !lstrcmpiA(buf, "MDI_child_class") ||
6547             !lstrcmpiA(buf, "my_button_class") ||
6548             !lstrcmpiA(buf, "my_edit_class") ||
6549             !lstrcmpiA(buf, "static") ||
6550             !lstrcmpiA(buf, "MyDialogClass") ||
6551             !lstrcmpiA(buf, "#32770"))
6552         {
6553             struct message msg;
6554
6555             msg.message = event;
6556             msg.flags = winevent_hook|wparam|lparam;
6557             msg.wParam = object_id;
6558             msg.lParam = child_id;
6559             add_message(&msg);
6560         }
6561     }
6562 }
6563
6564 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
6565 static const WCHAR wszAnsi[] = {'U',0};
6566
6567 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6568 {
6569     switch (uMsg)
6570     {
6571     case CB_FINDSTRINGEXACT:
6572         trace("String: %p\n", (LPCWSTR)lParam);
6573         if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
6574             return 1;
6575         if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
6576             return 0;
6577         return -1;
6578     }
6579     return DefWindowProcW(hwnd, uMsg, wParam, lParam);
6580 }
6581
6582 static const struct message WmGetTextLengthAfromW[] = {
6583     { WM_GETTEXTLENGTH, sent },
6584     { WM_GETTEXT, sent },
6585     { 0 }
6586 };
6587
6588 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
6589
6590 /* dummy window proc for WM_GETTEXTLENGTH test */
6591 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
6592 {
6593     switch(msg)
6594     {
6595     case WM_GETTEXTLENGTH:
6596         return lstrlenW(dummy_window_text) + 37;  /* some random length */
6597     case WM_GETTEXT:
6598         lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
6599         return lstrlenW( (LPWSTR)lp );
6600     default:
6601         return DefWindowProcW( hwnd, msg, wp, lp );
6602     }
6603 }
6604
6605 static void test_message_conversion(void)
6606 {
6607     static const WCHAR wszMsgConversionClass[] =
6608         {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
6609     WNDCLASSW cls;
6610     LRESULT lRes;
6611     HWND hwnd;
6612     WNDPROC wndproc, newproc;
6613     BOOL ret;
6614
6615     cls.style = 0;
6616     cls.lpfnWndProc = MsgConversionProcW;
6617     cls.cbClsExtra = 0;
6618     cls.cbWndExtra = 0;
6619     cls.hInstance = GetModuleHandleW(NULL);
6620     cls.hIcon = NULL;
6621     cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
6622     cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
6623     cls.lpszMenuName = NULL;
6624     cls.lpszClassName = wszMsgConversionClass;
6625     /* this call will fail on Win9x, but that doesn't matter as this test is
6626      * meaningless on those platforms */
6627     if(!RegisterClassW(&cls)) return;
6628
6629     hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
6630                            100, 100, 200, 200, 0, 0, 0, NULL);
6631     ok(hwnd != NULL, "Window creation failed\n");
6632
6633     /* {W, A} -> A */
6634
6635     wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
6636     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6637     ok(lRes == 0, "String should have been converted\n");
6638     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6639     ok(lRes == 1, "String shouldn't have been converted\n");
6640
6641     /* {W, A} -> W */
6642
6643     wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
6644     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6645     ok(lRes == 1, "String shouldn't have been converted\n");
6646     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6647     ok(lRes == 1, "String shouldn't have been converted\n");
6648
6649     /* Synchronous messages */
6650
6651     lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6652     ok(lRes == 0, "String should have been converted\n");
6653     lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6654     ok(lRes == 1, "String shouldn't have been converted\n");
6655
6656     /* Asynchronous messages */
6657
6658     SetLastError(0);
6659     lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6660     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6661         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6662     SetLastError(0);
6663     lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6664     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6665         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6666     SetLastError(0);
6667     lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6668     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6669         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6670     SetLastError(0);
6671     lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6672     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6673         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6674     SetLastError(0);
6675     lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6676     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6677         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6678     SetLastError(0);
6679     lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
6680     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6681         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6682     SetLastError(0);
6683     lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
6684     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6685         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6686     SetLastError(0);
6687     lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
6688     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
6689         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
6690
6691     /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
6692
6693     hwnd = CreateWindowW (testWindowClassW, wszUnicode,
6694                           WS_OVERLAPPEDWINDOW,
6695                           100, 100, 200, 200, 0, 0, 0, NULL);
6696     assert(hwnd);
6697     flush_sequence();
6698     lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
6699     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
6700     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
6701         "got bad length %ld\n", lRes );
6702
6703     flush_sequence();
6704     lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
6705                             hwnd, WM_GETTEXTLENGTH, 0, 0);
6706     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
6707     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
6708         "got bad length %ld\n", lRes );
6709
6710     wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
6711     newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
6712     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
6713     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
6714                                      NULL, 0, NULL, NULL ),
6715         "got bad length %ld\n", lRes );
6716
6717     SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc );  /* restore old wnd proc */
6718     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
6719     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
6720                                      NULL, 0, NULL, NULL ),
6721         "got bad length %ld\n", lRes );
6722
6723     ret = DestroyWindow(hwnd);
6724     ok( ret, "DestroyWindow() error %d\n", GetLastError());
6725 }
6726
6727 struct timer_info
6728 {
6729     HWND hWnd;
6730     HANDLE handles[2];
6731     DWORD id;
6732 };
6733
6734 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
6735 {
6736 }
6737
6738 #define TIMER_ID  0x19
6739
6740 static DWORD WINAPI timer_thread_proc(LPVOID x)
6741 {
6742     struct timer_info *info = x;
6743     DWORD r;
6744
6745     r = KillTimer(info->hWnd, 0x19);
6746     ok(r,"KillTimer failed in thread\n");
6747     r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
6748     ok(r,"SetTimer failed in thread\n");
6749     ok(r==TIMER_ID,"SetTimer id different\n");
6750     r = SetEvent(info->handles[0]);
6751     ok(r,"SetEvent failed in thread\n");
6752     return 0;
6753 }
6754
6755 static void test_timers(void)
6756 {
6757     struct timer_info info;
6758     DWORD id;
6759
6760     info.hWnd = CreateWindow ("TestWindowClass", NULL,
6761        WS_OVERLAPPEDWINDOW ,
6762        CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
6763        NULL, NULL, 0);
6764
6765     info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
6766     ok(info.id, "SetTimer failed\n");
6767     ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
6768     info.handles[0] = CreateEvent(NULL,0,0,NULL);
6769     info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
6770
6771     WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
6772
6773     WaitForSingleObject(info.handles[1], INFINITE);
6774
6775     CloseHandle(info.handles[0]);
6776     CloseHandle(info.handles[1]);
6777
6778     ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
6779
6780     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
6781 }
6782
6783 static int count = 0;
6784 static VOID CALLBACK callback_count(
6785     HWND hwnd,
6786     UINT uMsg,
6787     UINT_PTR idEvent,
6788     DWORD dwTime
6789 )
6790 {
6791     count++;
6792 }
6793
6794 static void test_timers_no_wnd(void)
6795 {
6796     UINT_PTR id, id2;
6797     MSG msg;
6798
6799     count = 0;
6800     id = SetTimer(NULL, 0, 100, callback_count);
6801     ok(id != 0, "did not get id from SetTimer.\n");
6802     id2 = SetTimer(NULL, id, 200, callback_count);
6803     ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
6804     Sleep(150);
6805     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6806     ok(count == 0, "did not get zero count as expected (%i).\n", count);
6807     Sleep(150);
6808     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6809     ok(count == 1, "did not get one count as expected (%i).\n", count);
6810     KillTimer(NULL, id);
6811     Sleep(250);
6812     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6813     ok(count == 1, "killing replaced timer did not work (%i).\n", count);
6814 }
6815
6816 /* Various win events with arbitrary parameters */
6817 static const struct message WmWinEventsSeq[] = {
6818     { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
6819     { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6820     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
6821     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
6822     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
6823     { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
6824     { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
6825     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
6826     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
6827     /* our win event hook ignores OBJID_CURSOR events */
6828     /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
6829     { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
6830     { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
6831     { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
6832     { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
6833     { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
6834     { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6835     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
6836     { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
6837     { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
6838     { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
6839     { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
6840     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
6841     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
6842     { 0 }
6843 };
6844 static const struct message WmWinEventCaretSeq[] = {
6845     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
6846     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
6847     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
6848     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
6849     { 0 }
6850 };
6851 static const struct message WmWinEventCaretSeq_2[] = {
6852     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
6853     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
6854     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
6855     { 0 }
6856 };
6857 static const struct message WmWinEventAlertSeq[] = {
6858     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
6859     { 0 }
6860 };
6861 static const struct message WmWinEventAlertSeq_2[] = {
6862     /* create window in the thread proc */
6863     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
6864     /* our test event */
6865     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
6866     { 0 }
6867 };
6868 static const struct message WmGlobalHookSeq_1[] = {
6869     /* create window in the thread proc */
6870     { HCBT_CREATEWND, hook|lparam, 0, 2 },
6871     /* our test events */
6872     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
6873     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
6874     { 0 }
6875 };
6876 static const struct message WmGlobalHookSeq_2[] = {
6877     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
6878     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
6879     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
6880     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
6881     { 0 }
6882 };
6883
6884 static const struct message WmMouseLLHookSeq[] = {
6885     { WM_MOUSEMOVE, hook },
6886     { WM_LBUTTONUP, hook },
6887     { WM_MOUSEMOVE, hook },
6888     { 0 }
6889 };
6890
6891 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
6892                                          DWORD event,
6893                                          HWND hwnd,
6894                                          LONG object_id,
6895                                          LONG child_id,
6896                                          DWORD thread_id,
6897                                          DWORD event_time)
6898 {
6899     char buf[256];
6900
6901     trace("WEH_2:%p,event %08x,hwnd %p,obj %08x,id %08x,thread %08x,time %08x\n",
6902            hevent, event, hwnd, object_id, child_id, thread_id, event_time);
6903
6904     if (GetClassNameA(hwnd, buf, sizeof(buf)))
6905     {
6906         if (!lstrcmpiA(buf, "TestWindowClass") ||
6907             !lstrcmpiA(buf, "static"))
6908         {
6909             struct message msg;
6910
6911             msg.message = event;
6912             msg.flags = winevent_hook|wparam|lparam;
6913             msg.wParam = object_id;
6914             msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
6915             add_message(&msg);
6916         }
6917     }
6918 }
6919
6920 static HHOOK hCBT_global_hook;
6921 static DWORD cbt_global_hook_thread_id;
6922
6923 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
6924
6925     HWND hwnd;
6926     char buf[256];
6927
6928     trace("CBT_2: %d, %08lx, %08lx\n", nCode, wParam, lParam);
6929
6930     if (nCode == HCBT_SYSCOMMAND)
6931     {
6932         struct message msg;
6933
6934         msg.message = nCode;
6935         msg.flags = hook|wparam|lparam;
6936         msg.wParam = wParam;
6937         msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
6938         add_message(&msg);
6939
6940         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
6941     }
6942     /* WH_MOUSE_LL hook */
6943     if (nCode == HC_ACTION)
6944     {
6945         struct message msg;
6946         MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
6947
6948         /* we can't test for real mouse events */
6949         if (mhll->flags & LLMHF_INJECTED)
6950         {
6951             msg.message = wParam;
6952             msg.flags = hook;
6953             add_message(&msg);
6954         }
6955         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
6956     }
6957
6958     /* Log also SetFocus(0) calls */
6959     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
6960
6961     if (GetClassNameA(hwnd, buf, sizeof(buf)))
6962     {
6963         if (!lstrcmpiA(buf, "TestWindowClass") ||
6964             !lstrcmpiA(buf, "static"))
6965         {
6966             struct message msg;
6967
6968             msg.message = nCode;
6969             msg.flags = hook|wparam|lparam;
6970             msg.wParam = wParam;
6971             msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
6972             add_message(&msg);
6973         }
6974     }
6975     return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
6976 }
6977
6978 static DWORD WINAPI win_event_global_thread_proc(void *param)
6979 {
6980     HWND hwnd;
6981     MSG msg;
6982     HANDLE hevent = *(HANDLE *)param;
6983
6984     assert(pNotifyWinEvent);
6985
6986     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
6987     assert(hwnd);
6988     trace("created thread window %p\n", hwnd);
6989
6990     *(HWND *)param = hwnd;
6991
6992     flush_sequence();
6993     /* this event should be received only by our new hook proc,
6994      * an old one does not expect an event from another thread.
6995      */
6996     pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
6997     SetEvent(hevent);
6998
6999     while (GetMessage(&msg, 0, 0, 0))
7000     {
7001         TranslateMessage(&msg);
7002         DispatchMessage(&msg);
7003     }
7004     return 0;
7005 }
7006
7007 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
7008 {
7009     HWND hwnd;
7010     MSG msg;
7011     HANDLE hevent = *(HANDLE *)param;
7012
7013     flush_sequence();
7014     /* these events should be received only by our new hook proc,
7015      * an old one does not expect an event from another thread.
7016      */
7017
7018     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7019     assert(hwnd);
7020     trace("created thread window %p\n", hwnd);
7021
7022     *(HWND *)param = hwnd;
7023
7024     /* Windows doesn't like when a thread plays games with the focus,
7025        that leads to all kinds of misbehaviours and failures to activate
7026        a window. So, better keep next lines commented out.
7027     SetFocus(0);
7028     SetFocus(hwnd);*/
7029
7030     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7031     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7032
7033     SetEvent(hevent);
7034
7035     while (GetMessage(&msg, 0, 0, 0))
7036     {
7037         TranslateMessage(&msg);
7038         DispatchMessage(&msg);
7039     }
7040     return 0;
7041 }
7042
7043 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
7044 {
7045     HWND hwnd;
7046     MSG msg;
7047     HANDLE hevent = *(HANDLE *)param;
7048
7049     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7050     assert(hwnd);
7051     trace("created thread window %p\n", hwnd);
7052
7053     *(HWND *)param = hwnd;
7054
7055     flush_sequence();
7056
7057     /* Windows doesn't like when a thread plays games with the focus,
7058      * that leads to all kinds of misbehaviours and failures to activate
7059      * a window. So, better don't generate a mouse click message below.
7060      */
7061     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7062     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7063     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7064
7065     SetEvent(hevent);
7066     while (GetMessage(&msg, 0, 0, 0))
7067     {
7068         TranslateMessage(&msg);
7069         DispatchMessage(&msg);
7070     }
7071     return 0;
7072 }
7073
7074 static void test_winevents(void)
7075 {
7076     BOOL ret;
7077     MSG msg;
7078     HWND hwnd, hwnd2;
7079     UINT i;
7080     HANDLE hthread, hevent;
7081     DWORD tid;
7082     HWINEVENTHOOK hhook;
7083     const struct message *events = WmWinEventsSeq;
7084
7085     hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
7086                            WS_OVERLAPPEDWINDOW,
7087                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7088                            NULL, NULL, 0);
7089     assert(hwnd);
7090
7091     /****** start of global hook test *************/
7092     hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7093     assert(hCBT_global_hook);
7094
7095     hevent = CreateEventA(NULL, 0, 0, NULL);
7096     assert(hevent);
7097     hwnd2 = (HWND)hevent;
7098
7099     hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
7100     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7101
7102     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7103
7104     ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
7105
7106     flush_sequence();
7107     /* this one should be received only by old hook proc */
7108     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7109     /* this one should be received only by old hook proc */
7110     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7111
7112     ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
7113
7114     ret = UnhookWindowsHookEx(hCBT_global_hook);
7115     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7116
7117     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7118     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7119     CloseHandle(hthread);
7120     CloseHandle(hevent);
7121     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7122     /****** end of global hook test *************/
7123
7124     if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
7125     {
7126         ok(DestroyWindow(hwnd), "failed to destroy window\n");
7127         return;
7128     }
7129
7130     flush_sequence();
7131
7132     if (0)
7133     {
7134     /* this test doesn't pass under Win9x */
7135     /* win2k ignores events with hwnd == 0 */
7136     SetLastError(0xdeadbeef);
7137     pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
7138     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
7139        GetLastError() == 0xdeadbeef, /* Win9x */
7140        "unexpected error %d\n", GetLastError());
7141     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7142     }
7143
7144     for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
7145         pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
7146
7147     ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
7148
7149     /****** start of event filtering test *************/
7150     hhook = (HWINEVENTHOOK)pSetWinEventHook(
7151         EVENT_OBJECT_SHOW, /* 0x8002 */
7152         EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
7153         GetModuleHandleA(0), win_event_global_hook_proc,
7154         GetCurrentProcessId(), 0,
7155         WINEVENT_INCONTEXT);
7156     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7157
7158     hevent = CreateEventA(NULL, 0, 0, NULL);
7159     assert(hevent);
7160     hwnd2 = (HWND)hevent;
7161
7162     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7163     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7164
7165     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7166
7167     ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
7168
7169     flush_sequence();
7170     /* this one should be received only by old hook proc */
7171     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7172     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7173     /* this one should be received only by old hook proc */
7174     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7175
7176     ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
7177
7178     ret = pUnhookWinEvent(hhook);
7179     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7180
7181     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7182     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7183     CloseHandle(hthread);
7184     CloseHandle(hevent);
7185     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7186     /****** end of event filtering test *************/
7187
7188     /****** start of out of context event test *************/
7189     hhook = (HWINEVENTHOOK)pSetWinEventHook(
7190         EVENT_MIN, EVENT_MAX,
7191         0, win_event_global_hook_proc,
7192         GetCurrentProcessId(), 0,
7193         WINEVENT_OUTOFCONTEXT);
7194     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7195
7196     hevent = CreateEventA(NULL, 0, 0, NULL);
7197     assert(hevent);
7198     hwnd2 = (HWND)hevent;
7199
7200     flush_sequence();
7201
7202     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7203     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7204
7205     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7206
7207     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7208     /* process pending winevent messages */
7209     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7210     ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
7211
7212     flush_sequence();
7213     /* this one should be received only by old hook proc */
7214     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7215     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7216     /* this one should be received only by old hook proc */
7217     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7218
7219     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
7220     /* process pending winevent messages */
7221     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7222     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
7223
7224     ret = pUnhookWinEvent(hhook);
7225     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7226
7227     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7228     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7229     CloseHandle(hthread);
7230     CloseHandle(hevent);
7231     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7232     /****** end of out of context event test *************/
7233
7234     /****** start of MOUSE_LL hook test *************/
7235     hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7236     /* WH_MOUSE_LL is not supported on Win9x platforms */
7237     if (!hCBT_global_hook)
7238     {
7239         trace("Skipping WH_MOUSE_LL test on this platform\n");
7240         goto skip_mouse_ll_hook_test;
7241     }
7242
7243     hevent = CreateEventA(NULL, 0, 0, NULL);
7244     assert(hevent);
7245     hwnd2 = (HWND)hevent;
7246
7247     hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
7248     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7249
7250     while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
7251         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
7252
7253     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
7254     flush_sequence();
7255
7256     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7257     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7258     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7259
7260     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
7261
7262     ret = UnhookWindowsHookEx(hCBT_global_hook);
7263     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7264
7265     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7266     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7267     CloseHandle(hthread);
7268     CloseHandle(hevent);
7269     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7270     /****** end of MOUSE_LL hook test *************/
7271 skip_mouse_ll_hook_test:
7272
7273     ok(DestroyWindow(hwnd), "failed to destroy window\n");
7274 }
7275
7276 static void test_set_hook(void)
7277 {
7278     BOOL ret;
7279     HHOOK hhook;
7280     HWINEVENTHOOK hwinevent_hook;
7281
7282     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
7283     ok(hhook != 0, "local hook does not require hModule set to 0\n");
7284     UnhookWindowsHookEx(hhook);
7285
7286     if (0)
7287     {
7288     /* this test doesn't pass under Win9x: BUG! */
7289     SetLastError(0xdeadbeef);
7290     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
7291     ok(!hhook, "global hook requires hModule != 0\n");
7292     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
7293     }
7294
7295     SetLastError(0xdeadbeef);
7296     hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
7297     ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
7298     ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
7299        GetLastError() == 0xdeadbeef, /* Win9x */
7300        "unexpected error %d\n", GetLastError());
7301
7302     SetLastError(0xdeadbeef);
7303     ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
7304     ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
7305        GetLastError() == 0xdeadbeef, /* Win9x */
7306        "unexpected error %d\n", GetLastError());
7307
7308     if (!pSetWinEventHook || !pUnhookWinEvent) return;
7309
7310     /* even process local incontext hooks require hmodule */
7311     SetLastError(0xdeadbeef);
7312     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7313         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
7314     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
7315     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
7316        GetLastError() == 0xdeadbeef, /* Win9x */
7317        "unexpected error %d\n", GetLastError());
7318
7319     /* even thread local incontext hooks require hmodule */
7320     SetLastError(0xdeadbeef);
7321     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7322         0, win_event_proc, GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
7323     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
7324     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
7325        GetLastError() == 0xdeadbeef, /* Win9x */
7326        "unexpected error %d\n", GetLastError());
7327
7328     if (0)
7329     {
7330     /* these 3 tests don't pass under Win9x */
7331     SetLastError(0xdeadbeef);
7332     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(1, 0,
7333         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7334     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
7335     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
7336
7337     SetLastError(0xdeadbeef);
7338     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(-1, 1,
7339         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7340     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
7341     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
7342
7343     SetLastError(0xdeadbeef);
7344     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7345         0, win_event_proc, 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
7346     ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
7347     ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
7348     }
7349
7350     SetLastError(0xdeadbeef);
7351     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(0, 0,
7352         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7353     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
7354     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
7355     ret = pUnhookWinEvent(hwinevent_hook);
7356     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7357
7358 todo_wine {
7359     /* This call succeeds under win2k SP4, but fails under Wine.
7360        Does win2k test/use passed process id? */
7361     SetLastError(0xdeadbeef);
7362     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7363         0, win_event_proc, 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
7364     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
7365     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
7366     ret = pUnhookWinEvent(hwinevent_hook);
7367     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7368 }
7369
7370     SetLastError(0xdeadbeef);
7371     ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
7372     ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
7373         GetLastError() == 0xdeadbeef, /* Win9x */
7374         "unexpected error %d\n", GetLastError());
7375 }
7376
7377 static const struct message ScrollWindowPaint1[] = {
7378     { WM_PAINT, sent },
7379     { WM_ERASEBKGND, sent|beginpaint },
7380     { 0 }
7381 };
7382
7383 static const struct message ScrollWindowPaint2[] = {
7384     { WM_PAINT, sent },
7385     { 0 }
7386 };
7387
7388 static void test_scrollwindowex(void)
7389 {
7390     HWND hwnd, hchild;
7391     RECT rect={0,0,130,130};
7392
7393     hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
7394             WS_VISIBLE|WS_OVERLAPPEDWINDOW,
7395             100, 100, 200, 200, 0, 0, 0, NULL);
7396     ok (hwnd != 0, "Failed to create overlapped window\n");
7397     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", 
7398             WS_VISIBLE|WS_CAPTION|WS_CHILD,
7399             10, 10, 150, 150, hwnd, 0, 0, NULL);
7400     ok (hchild != 0, "Failed to create child\n");
7401     UpdateWindow(hwnd);
7402     flush_events();
7403     flush_sequence();
7404
7405     /* scroll without the child window */
7406     trace("start scroll\n");
7407     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
7408             SW_ERASE|SW_INVALIDATE);
7409     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7410     trace("end scroll\n");
7411     flush_sequence();
7412     flush_events();
7413     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
7414     flush_events();
7415     flush_sequence();
7416
7417     /* Now without the SW_ERASE flag */
7418     trace("start scroll\n");
7419     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
7420     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7421     trace("end scroll\n");
7422     flush_sequence();
7423     flush_events();
7424     ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
7425     flush_events();
7426     flush_sequence();
7427
7428     /* now scroll the child window as well */
7429     trace("start scroll\n");
7430     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
7431             SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
7432     todo_wine { /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
7433                 /* windows sometimes a WM_MOVE */
7434         ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7435     }
7436     trace("end scroll\n");
7437     flush_sequence();
7438     flush_events();
7439     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
7440     flush_events();
7441     flush_sequence();
7442
7443     /* now scroll with ScrollWindow() */
7444     trace("start scroll with ScrollWindow\n");
7445     ScrollWindow( hwnd, 5, 5, NULL, NULL);
7446     trace("end scroll\n");
7447     flush_sequence();
7448     flush_events();
7449     ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
7450
7451     ok(DestroyWindow(hchild), "failed to destroy window\n");
7452     ok(DestroyWindow(hwnd), "failed to destroy window\n");
7453     flush_sequence();
7454 }
7455
7456 static const struct message destroy_window_with_children[] = {
7457     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
7458     { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
7459     { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
7460     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
7461     { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7462     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7463     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7464     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
7465     { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
7466     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
7467     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
7468     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
7469     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
7470     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
7471     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
7472     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
7473     { 0 }
7474 };
7475
7476 static void test_DestroyWindow(void)
7477 {
7478     BOOL ret;
7479     HWND parent, child1, child2, child3, child4, test;
7480     UINT child_id = WND_CHILD_ID + 1;
7481
7482     parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
7483                              100, 100, 200, 200, 0, 0, 0, NULL);
7484     assert(parent != 0);
7485     child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7486                              0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
7487     assert(child1 != 0);
7488     child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7489                              0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
7490     assert(child2 != 0);
7491     child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7492                              0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
7493     assert(child3 != 0);
7494     child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
7495                              0, 0, 50, 50, parent, 0, 0, NULL);
7496     assert(child4 != 0);
7497
7498     /* test owner/parent of child2 */
7499     test = GetParent(child2);
7500     ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7501     ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
7502     if(pGetAncestor) {
7503         test = pGetAncestor(child2, GA_PARENT);
7504         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7505     }
7506     test = GetWindow(child2, GW_OWNER);
7507     ok(!test, "wrong owner %p\n", test);
7508
7509     test = SetParent(child2, parent);
7510     ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
7511
7512     /* test owner/parent of the parent */
7513     test = GetParent(parent);
7514     ok(!test, "wrong parent %p\n", test);
7515     ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
7516     if(pGetAncestor) {
7517         test = pGetAncestor(parent, GA_PARENT);
7518         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7519     }
7520     test = GetWindow(parent, GW_OWNER);
7521     ok(!test, "wrong owner %p\n", test);
7522
7523     /* test owner/parent of child1 */
7524     test = GetParent(child1);
7525     ok(test == parent, "wrong parent %p\n", test);
7526     ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
7527     if(pGetAncestor) {
7528         test = pGetAncestor(child1, GA_PARENT);
7529         ok(test == parent, "wrong parent %p\n", test);
7530     }
7531     test = GetWindow(child1, GW_OWNER);
7532     ok(!test, "wrong owner %p\n", test);
7533
7534     /* test owner/parent of child2 */
7535     test = GetParent(child2);
7536     ok(test == parent, "wrong parent %p\n", test);
7537     ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
7538     if(pGetAncestor) {
7539         test = pGetAncestor(child2, GA_PARENT);
7540         ok(test == parent, "wrong parent %p\n", test);
7541     }
7542     test = GetWindow(child2, GW_OWNER);
7543     ok(!test, "wrong owner %p\n", test);
7544
7545     /* test owner/parent of child3 */
7546     test = GetParent(child3);
7547     ok(test == child1, "wrong parent %p\n", test);
7548     ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
7549     if(pGetAncestor) {
7550         test = pGetAncestor(child3, GA_PARENT);
7551         ok(test == child1, "wrong parent %p\n", test);
7552     }
7553     test = GetWindow(child3, GW_OWNER);
7554     ok(!test, "wrong owner %p\n", test);
7555
7556     /* test owner/parent of child4 */
7557     test = GetParent(child4);
7558     ok(test == parent, "wrong parent %p\n", test);
7559     ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
7560     if(pGetAncestor) {
7561         test = pGetAncestor(child4, GA_PARENT);
7562         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7563     }
7564     test = GetWindow(child4, GW_OWNER);
7565     ok(test == parent, "wrong owner %p\n", test);
7566
7567     flush_sequence();
7568
7569     trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
7570            parent, child1, child2, child3, child4);
7571
7572     SetCapture(child4);
7573     test = GetCapture();
7574     ok(test == child4, "wrong capture window %p\n", test);
7575
7576     test_DestroyWindow_flag = TRUE;
7577     ret = DestroyWindow(parent);
7578     ok( ret, "DestroyWindow() error %d\n", GetLastError());
7579     test_DestroyWindow_flag = FALSE;
7580     ok_sequence(destroy_window_with_children, "destroy window with children", 0);
7581
7582     ok(!IsWindow(parent), "parent still exists\n");
7583     ok(!IsWindow(child1), "child1 still exists\n");
7584     ok(!IsWindow(child2), "child2 still exists\n");
7585     ok(!IsWindow(child3), "child3 still exists\n");
7586     ok(!IsWindow(child4), "child4 still exists\n");
7587
7588     test = GetCapture();
7589     ok(!test, "wrong capture window %p\n", test);
7590 }
7591
7592
7593 static const struct message WmDispatchPaint[] = {
7594     { WM_NCPAINT, sent },
7595     { WM_GETTEXT, sent|defwinproc|optional },
7596     { WM_GETTEXT, sent|defwinproc|optional },
7597     { WM_ERASEBKGND, sent },
7598     { 0 }
7599 };
7600
7601 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7602 {
7603     if (message == WM_PAINT) return 0;
7604     return MsgCheckProcA( hwnd, message, wParam, lParam );
7605 }
7606
7607 static void test_DispatchMessage(void)
7608 {
7609     RECT rect;
7610     MSG msg;
7611     int count;
7612     HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
7613                                100, 100, 200, 200, 0, 0, 0, NULL);
7614     ShowWindow( hwnd, SW_SHOW );
7615     UpdateWindow( hwnd );
7616     flush_events();
7617     flush_sequence();
7618     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
7619
7620     SetRect( &rect, -5, -5, 5, 5 );
7621     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
7622     count = 0;
7623     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
7624     {
7625         if (msg.message != WM_PAINT) DispatchMessage( &msg );
7626         else
7627         {
7628             flush_sequence();
7629             DispatchMessage( &msg );
7630             /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
7631             if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
7632             else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
7633             if (++count > 10) break;
7634         }
7635     }
7636     ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
7637
7638     trace("now without DispatchMessage\n");
7639     flush_sequence();
7640     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
7641     count = 0;
7642     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
7643     {
7644         if (msg.message != WM_PAINT) DispatchMessage( &msg );
7645         else
7646         {
7647             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
7648             flush_sequence();
7649             /* this will send WM_NCCPAINT just like DispatchMessage does */
7650             GetUpdateRgn( hwnd, hrgn, TRUE );
7651             ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
7652             DeleteObject( hrgn );
7653             GetClientRect( hwnd, &rect );
7654             ValidateRect( hwnd, &rect );  /* this will stop WM_PAINTs */
7655             ok( !count, "Got multiple WM_PAINTs\n" );
7656             if (++count > 10) break;
7657         }
7658     }
7659     DestroyWindow(hwnd);
7660 }
7661
7662
7663 static const struct message WmUser[] = {
7664     { WM_USER, sent },
7665     { 0 }
7666 };
7667
7668 struct sendmsg_info
7669 {
7670     HWND  hwnd;
7671     DWORD timeout;
7672     DWORD ret;
7673 };
7674
7675 static DWORD CALLBACK send_msg_thread( LPVOID arg )
7676 {
7677     struct sendmsg_info *info = arg;
7678     info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
7679     if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT, "unexpected error %d\n", GetLastError());
7680     return 0;
7681 }
7682
7683 static void wait_for_thread( HANDLE thread )
7684 {
7685     while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
7686     {
7687         MSG msg;
7688         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
7689     }
7690 }
7691
7692 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7693 {
7694     if (message == WM_USER) Sleep(200);
7695     return MsgCheckProcA( hwnd, message, wParam, lParam );
7696 }
7697
7698 static void test_SendMessageTimeout(void)
7699 {
7700     HANDLE thread;
7701     struct sendmsg_info info;
7702     DWORD tid;
7703
7704     info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
7705                                100, 100, 200, 200, 0, 0, 0, NULL);
7706     flush_events();
7707     flush_sequence();
7708
7709     info.timeout = 1000;
7710     info.ret = 0xdeadbeef;
7711     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7712     wait_for_thread( thread );
7713     CloseHandle( thread );
7714     ok( info.ret == 1, "SendMessageTimeout failed\n" );
7715     ok_sequence( WmUser, "WmUser", FALSE );
7716
7717     info.timeout = 1;
7718     info.ret = 0xdeadbeef;
7719     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7720     Sleep(100);  /* SendMessageTimeout should timeout here */
7721     wait_for_thread( thread );
7722     CloseHandle( thread );
7723     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
7724     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
7725
7726     /* 0 means infinite timeout */
7727     info.timeout = 0;
7728     info.ret = 0xdeadbeef;
7729     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7730     Sleep(100);
7731     wait_for_thread( thread );
7732     CloseHandle( thread );
7733     ok( info.ret == 1, "SendMessageTimeout failed\n" );
7734     ok_sequence( WmUser, "WmUser", FALSE );
7735
7736     /* timeout is treated as signed despite the prototype */
7737     info.timeout = 0x7fffffff;
7738     info.ret = 0xdeadbeef;
7739     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7740     Sleep(100);
7741     wait_for_thread( thread );
7742     CloseHandle( thread );
7743     ok( info.ret == 1, "SendMessageTimeout failed\n" );
7744     ok_sequence( WmUser, "WmUser", FALSE );
7745
7746     info.timeout = 0x80000000;
7747     info.ret = 0xdeadbeef;
7748     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7749     Sleep(100);
7750     wait_for_thread( thread );
7751     CloseHandle( thread );
7752     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
7753     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
7754
7755     /* now check for timeout during message processing */
7756     SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
7757     info.timeout = 100;
7758     info.ret = 0xdeadbeef;
7759     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7760     wait_for_thread( thread );
7761     CloseHandle( thread );
7762     /* we should timeout but still get the message */
7763     ok( info.ret == 0, "SendMessageTimeout failed\n" );
7764     ok_sequence( WmUser, "WmUser", FALSE );
7765
7766     DestroyWindow( info.hwnd );
7767 }
7768
7769
7770 /****************** edit message test *************************/
7771 #define ID_EDIT 0x1234
7772 static const struct message sl_edit_setfocus[] =
7773 {
7774     { HCBT_SETFOCUS, hook },
7775     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
7776     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
7777     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7778     { WM_SETFOCUS, sent|wparam, 0 },
7779     { WM_CTLCOLOREDIT, sent|parent },
7780     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7781     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7782     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
7783     { 0 }
7784 };
7785 static const struct message ml_edit_setfocus[] =
7786 {
7787     { HCBT_SETFOCUS, hook },
7788     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
7789     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
7790     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7791     { WM_SETFOCUS, sent|wparam, 0 },
7792     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7793     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7794     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7795     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
7796     { 0 }
7797 };
7798 static const struct message sl_edit_killfocus[] =
7799 {
7800     { HCBT_SETFOCUS, hook },
7801     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7802     { WM_KILLFOCUS, sent|wparam, 0 },
7803     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7804     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7805     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
7806     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
7807     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
7808     { 0 }
7809 };
7810 static const struct message sl_edit_lbutton_dblclk[] =
7811 {
7812     { WM_LBUTTONDBLCLK, sent },
7813     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7814     { 0 }
7815 };
7816 static const struct message sl_edit_lbutton_down[] =
7817 {
7818     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
7819     { HCBT_SETFOCUS, hook },
7820     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
7821     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
7822     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7823     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
7824     { WM_CTLCOLOREDIT, sent|parent },
7825     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7826     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7827     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7828     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
7829     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7830     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7831     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7832     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7833     { 0 }
7834 };
7835 static const struct message ml_edit_lbutton_down[] =
7836 {
7837     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
7838     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7839     { HCBT_SETFOCUS, hook },
7840     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
7841     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
7842     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7843     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
7844     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7845     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7846     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
7847     { 0 }
7848 };
7849 static const struct message sl_edit_lbutton_up[] =
7850 {
7851     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
7852     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7853     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
7854     { WM_CAPTURECHANGED, sent|defwinproc },
7855     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7856     { 0 }
7857 };
7858 static const struct message ml_edit_lbutton_up[] =
7859 {
7860     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
7861     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
7862     { WM_CAPTURECHANGED, sent|defwinproc },
7863     { 0 }
7864 };
7865
7866 static WNDPROC old_edit_proc;
7867
7868 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7869 {
7870     static long defwndproc_counter = 0;
7871     LRESULT ret;
7872     struct message msg;
7873
7874     trace("edit: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
7875
7876     /* explicitly ignore WM_GETICON message */
7877     if (message == WM_GETICON) return 0;
7878
7879     msg.message = message;
7880     msg.flags = sent|wparam|lparam;
7881     if (defwndproc_counter) msg.flags |= defwinproc;
7882     msg.wParam = wParam;
7883     msg.lParam = lParam;
7884     add_message(&msg);
7885
7886     defwndproc_counter++;
7887     ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
7888     defwndproc_counter--;
7889
7890     return ret;
7891 }
7892
7893 static void subclass_edit(void)
7894 {
7895     WNDCLASSA cls;
7896
7897     if (!GetClassInfoA(0, "edit", &cls)) assert(0);
7898
7899     old_edit_proc = cls.lpfnWndProc;
7900
7901     cls.hInstance = GetModuleHandle(0);
7902     cls.lpfnWndProc = edit_hook_proc;
7903     cls.lpszClassName = "my_edit_class";
7904     UnregisterClass(cls.lpszClassName, cls.hInstance);
7905     if (!RegisterClassA(&cls)) assert(0);
7906 }
7907
7908 static void test_edit_messages(void)
7909 {
7910     HWND hwnd, parent;
7911     DWORD dlg_code;
7912
7913     subclass_edit();
7914     log_all_parent_messages++;
7915
7916     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7917                              100, 100, 200, 200, 0, 0, 0, NULL);
7918     ok (parent != 0, "Failed to create parent window\n");
7919
7920     /* test single line edit */
7921     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
7922                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
7923     ok(hwnd != 0, "Failed to create edit window\n");
7924
7925     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
7926     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
7927
7928     ShowWindow(hwnd, SW_SHOW);
7929     UpdateWindow(hwnd);
7930     SetFocus(0);
7931     flush_sequence();
7932
7933     SetFocus(hwnd);
7934     ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
7935
7936     SetFocus(0);
7937     ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
7938
7939     SetFocus(0);
7940     ReleaseCapture();
7941     flush_sequence();
7942
7943     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
7944     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
7945
7946     SetFocus(0);
7947     ReleaseCapture();
7948     flush_sequence();
7949
7950     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
7951     ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
7952
7953     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
7954     ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
7955
7956     DestroyWindow(hwnd);
7957
7958     /* test multiline edit */
7959     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
7960                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
7961     ok(hwnd != 0, "Failed to create edit window\n");
7962
7963     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
7964     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
7965        "wrong dlg_code %08x\n", dlg_code);
7966
7967     ShowWindow(hwnd, SW_SHOW);
7968     UpdateWindow(hwnd);
7969     SetFocus(0);
7970     flush_sequence();
7971
7972     SetFocus(hwnd);
7973     ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
7974
7975     SetFocus(0);
7976     ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
7977
7978     SetFocus(0);
7979     ReleaseCapture();
7980     flush_sequence();
7981
7982     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
7983     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
7984
7985     SetFocus(0);
7986     ReleaseCapture();
7987     flush_sequence();
7988
7989     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
7990     ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
7991
7992     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
7993     ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
7994
7995     DestroyWindow(hwnd);
7996     DestroyWindow(parent);
7997
7998     log_all_parent_messages--;
7999 }
8000
8001 /**************************** End of Edit test ******************************/
8002
8003 static const struct message WmKeyDownSkippedSeq[] =
8004 {
8005     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
8006     { 0 }
8007 };
8008 static const struct message WmKeyUpSkippedSeq[] =
8009 {
8010     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8011     { 0 }
8012 };
8013
8014 #define EV_START_STOP 0
8015 #define EV_SENDMSG 1
8016 #define EV_ACK 2
8017
8018 struct peekmsg_info
8019 {
8020     HWND  hwnd;
8021     HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
8022 };
8023
8024 static DWORD CALLBACK send_msg_thread_2(void *param)
8025 {
8026     DWORD ret;
8027     struct peekmsg_info *info = param;
8028
8029     trace("thread: waiting for start\n");
8030     WaitForSingleObject(info->hevent[EV_START_STOP], INFINITE);
8031     trace("thread: looping\n");
8032
8033     while (1)
8034     {
8035         ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
8036
8037         switch (ret)
8038         {
8039         case WAIT_OBJECT_0 + EV_START_STOP:
8040             trace("thread: exiting\n");
8041             return 0;
8042
8043         case WAIT_OBJECT_0 + EV_SENDMSG:
8044             trace("thread: sending message\n");
8045             SendNotifyMessageA(info->hwnd, WM_USER, 0, 0);
8046             SetEvent(info->hevent[EV_ACK]);
8047             break;
8048
8049         default:
8050             trace("unexpected return: %04x\n", ret);
8051             assert(0);
8052             break;
8053         }
8054     }
8055     return 0;
8056 }
8057
8058 static void test_PeekMessage(void)
8059 {
8060     MSG msg;
8061     HANDLE hthread;
8062     DWORD tid, qstatus;
8063     UINT qs_all_input = QS_ALLINPUT;
8064     UINT qs_input = QS_INPUT;
8065     BOOL ret;
8066     struct peekmsg_info info;
8067
8068     info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8069                               100, 100, 200, 200, 0, 0, 0, NULL);
8070     assert(info.hwnd);
8071     ShowWindow(info.hwnd, SW_SHOW);
8072     UpdateWindow(info.hwnd);
8073     SetFocus(info.hwnd);
8074
8075     info.hevent[EV_START_STOP] = CreateEventA(NULL, 0, 0, NULL);
8076     info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
8077     info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
8078
8079     hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
8080     Sleep(100);
8081
8082     trace("signalling to start looping\n");
8083     SetEvent(info.hevent[EV_START_STOP]);
8084
8085     flush_events();
8086     flush_sequence();
8087
8088     SetLastError(0xdeadbeef);
8089     qstatus = GetQueueStatus(qs_all_input);
8090     if (GetLastError() == ERROR_INVALID_FLAGS)
8091     {
8092         trace("QS_RAWINPUT not supported on this platform\n");
8093         qs_all_input &= ~QS_RAWINPUT;
8094         qs_input &= ~QS_RAWINPUT;
8095     }
8096     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8097
8098     trace("signalling to send message\n");
8099     SetEvent(info.hevent[EV_SENDMSG]);
8100     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8101
8102     /* pass invalid QS_xxxx flags */
8103     SetLastError(0xdeadbeef);
8104     qstatus = GetQueueStatus(0xffffffff);
8105     ok(qstatus == 0, "GetQueueStatus should fail: %08x\n", qstatus);
8106     ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
8107
8108     qstatus = GetQueueStatus(qs_all_input);
8109     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
8110        "wrong qstatus %08x\n", qstatus);
8111
8112     msg.message = 0;
8113     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8114     ok(!ret,
8115        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8116         msg.message);
8117     ok_sequence(WmUser, "WmUser", FALSE);
8118
8119     qstatus = GetQueueStatus(qs_all_input);
8120     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8121
8122     keybd_event('N', 0, 0, 0);
8123     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
8124     qstatus = GetQueueStatus(qs_all_input);
8125     ok(qstatus == MAKELONG(QS_KEY, QS_KEY),
8126        "wrong qstatus %08x\n", qstatus);
8127
8128     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8129     qstatus = GetQueueStatus(qs_all_input);
8130     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8131        "wrong qstatus %08x\n", qstatus);
8132
8133     InvalidateRect(info.hwnd, NULL, FALSE);
8134     qstatus = GetQueueStatus(qs_all_input);
8135     ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8136        "wrong qstatus %08x\n", qstatus);
8137
8138     trace("signalling to send message\n");
8139     SetEvent(info.hevent[EV_SENDMSG]);
8140     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8141
8142     qstatus = GetQueueStatus(qs_all_input);
8143     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8144        "wrong qstatus %08x\n", qstatus);
8145
8146     msg.message = 0;
8147     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
8148     ok(!ret,
8149        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8150         msg.message);
8151     ok_sequence(WmUser, "WmUser", FALSE);
8152
8153     qstatus = GetQueueStatus(qs_all_input);
8154     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8155        "wrong qstatus %08x\n", qstatus);
8156
8157     trace("signalling to send message\n");
8158     SetEvent(info.hevent[EV_SENDMSG]);
8159     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8160
8161     qstatus = GetQueueStatus(qs_all_input);
8162     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8163        "wrong qstatus %08x\n", qstatus);
8164
8165     msg.message = 0;
8166     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8167     ok(!ret,
8168        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8169         msg.message);
8170     ok_sequence(WmUser, "WmUser", FALSE);
8171
8172     qstatus = GetQueueStatus(qs_all_input);
8173     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8174        "wrong qstatus %08x\n", qstatus);
8175
8176     msg.message = 0;
8177     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8178     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8179        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8180        ret, msg.message, msg.wParam);
8181     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8182
8183     qstatus = GetQueueStatus(qs_all_input);
8184     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
8185        "wrong qstatus %08x\n", qstatus);
8186
8187     msg.message = 0;
8188     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8189     ok(!ret,
8190        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8191         msg.message);
8192     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8193
8194     qstatus = GetQueueStatus(qs_all_input);
8195     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
8196        "wrong qstatus %08x\n", qstatus);
8197
8198     msg.message = 0;
8199     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
8200     ok(ret && msg.message == WM_PAINT,
8201        "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
8202     DispatchMessageA(&msg);
8203     ok_sequence(WmPaint, "WmPaint", FALSE);
8204
8205     qstatus = GetQueueStatus(qs_all_input);
8206     ok(qstatus == MAKELONG(0, QS_KEY),
8207        "wrong qstatus %08x\n", qstatus);
8208
8209     msg.message = 0;
8210     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
8211     ok(!ret,
8212        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8213         msg.message);
8214     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8215
8216     qstatus = GetQueueStatus(qs_all_input);
8217     ok(qstatus == MAKELONG(0, QS_KEY),
8218        "wrong qstatus %08x\n", qstatus);
8219
8220     trace("signalling to send message\n");
8221     SetEvent(info.hevent[EV_SENDMSG]);
8222     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8223
8224     qstatus = GetQueueStatus(qs_all_input);
8225     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
8226        "wrong qstatus %08x\n", qstatus);
8227
8228     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8229
8230     qstatus = GetQueueStatus(qs_all_input);
8231     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
8232        "wrong qstatus %08x\n", qstatus);
8233
8234     msg.message = 0;
8235     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
8236     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8237        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8238        ret, msg.message, msg.wParam);
8239     ok_sequence(WmUser, "WmUser", FALSE);
8240
8241     qstatus = GetQueueStatus(qs_all_input);
8242     ok(qstatus == MAKELONG(0, QS_KEY),
8243        "wrong qstatus %08x\n", qstatus);
8244
8245     msg.message = 0;
8246     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
8247     ok(!ret,
8248        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8249         msg.message);
8250     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8251
8252     qstatus = GetQueueStatus(qs_all_input);
8253     ok(qstatus == MAKELONG(0, QS_KEY),
8254        "wrong qstatus %08x\n", qstatus);
8255
8256     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8257
8258     qstatus = GetQueueStatus(qs_all_input);
8259     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8260        "wrong qstatus %08x\n", qstatus);
8261
8262     trace("signalling to send message\n");
8263     SetEvent(info.hevent[EV_SENDMSG]);
8264     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8265
8266     qstatus = GetQueueStatus(qs_all_input);
8267     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
8268        "wrong qstatus %08x\n", qstatus);
8269
8270     msg.message = 0;
8271     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
8272     ok(!ret,
8273        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8274         msg.message);
8275     ok_sequence(WmUser, "WmUser", FALSE);
8276
8277     qstatus = GetQueueStatus(qs_all_input);
8278     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
8279        "wrong qstatus %08x\n", qstatus);
8280
8281     msg.message = 0;
8282     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
8283         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
8284     else /* workaround for a missing QS_RAWINPUT support */
8285         ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
8286     ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
8287        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
8288        ret, msg.message, msg.wParam);
8289     ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
8290
8291     qstatus = GetQueueStatus(qs_all_input);
8292     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
8293        "wrong qstatus %08x\n", qstatus);
8294
8295     msg.message = 0;
8296     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
8297         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
8298     else /* workaround for a missing QS_RAWINPUT support */
8299         ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
8300     ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
8301        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
8302        ret, msg.message, msg.wParam);
8303     ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
8304
8305     qstatus = GetQueueStatus(qs_all_input);
8306     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8307        "wrong qstatus %08x\n", qstatus);
8308
8309     msg.message = 0;
8310     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
8311     ok(!ret,
8312        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8313         msg.message);
8314     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8315
8316     qstatus = GetQueueStatus(qs_all_input);
8317     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8318        "wrong qstatus %08x\n", qstatus);
8319
8320     msg.message = 0;
8321     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8322     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8323        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8324        ret, msg.message, msg.wParam);
8325     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8326
8327     qstatus = GetQueueStatus(qs_all_input);
8328     ok(qstatus == 0,
8329        "wrong qstatus %08x\n", qstatus);
8330
8331     msg.message = 0;
8332     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8333     ok(!ret,
8334        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8335         msg.message);
8336     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8337
8338     qstatus = GetQueueStatus(qs_all_input);
8339     ok(qstatus == 0,
8340        "wrong qstatus %08x\n", qstatus);
8341
8342     /* test whether presence of the quit flag in the queue affects
8343      * the queue state
8344      */
8345     PostQuitMessage(0x1234abcd);
8346
8347     qstatus = GetQueueStatus(qs_all_input);
8348     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
8349        "wrong qstatus %08x\n", qstatus);
8350
8351     PostMessageA(info.hwnd, WM_USER, 0, 0);
8352
8353     qstatus = GetQueueStatus(qs_all_input);
8354     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
8355        "wrong qstatus %08x\n", qstatus);
8356
8357     msg.message = 0;
8358     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8359     ok(ret && msg.message == WM_USER,
8360        "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
8361     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8362
8363     qstatus = GetQueueStatus(qs_all_input);
8364     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8365        "wrong qstatus %08x\n", qstatus);
8366
8367     msg.message = 0;
8368     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8369     ok(ret && msg.message == WM_QUIT,
8370        "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
8371     ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
8372     ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
8373     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8374
8375     qstatus = GetQueueStatus(qs_all_input);
8376 todo_wine {
8377     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8378        "wrong qstatus %08x\n", qstatus);
8379 }
8380
8381     msg.message = 0;
8382     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8383     ok(!ret,
8384        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8385         msg.message);
8386     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8387
8388     qstatus = GetQueueStatus(qs_all_input);
8389     ok(qstatus == 0,
8390        "wrong qstatus %08x\n", qstatus);
8391
8392     trace("signalling to exit\n");
8393     SetEvent(info.hevent[EV_START_STOP]);
8394
8395     WaitForSingleObject(hthread, INFINITE);
8396
8397     CloseHandle(hthread);
8398     CloseHandle(info.hevent[0]);
8399     CloseHandle(info.hevent[1]);
8400     CloseHandle(info.hevent[2]);
8401
8402     DestroyWindow(info.hwnd);
8403 }
8404
8405
8406 static void test_quit_message(void)
8407 {
8408     MSG msg;
8409     BOOL ret;
8410
8411     /* test using PostQuitMessage */
8412     PostQuitMessage(0xbeef);
8413
8414     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
8415     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
8416     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8417     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
8418
8419     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
8420     ok(ret, "PostMessage failed with error %d\n", GetLastError());
8421
8422     ret = GetMessage(&msg, NULL, 0, 0);
8423     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
8424     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
8425
8426     /* note: WM_QUIT message received after WM_USER message */
8427     ret = GetMessage(&msg, NULL, 0, 0);
8428     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
8429     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8430     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
8431
8432     ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
8433     ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
8434
8435     /* now test with PostThreadMessage - different behaviour! */
8436     PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
8437
8438     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
8439     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
8440     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8441     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
8442
8443     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
8444     ok(ret, "PostMessage failed with error %d\n", GetLastError());
8445
8446     /* note: we receive the WM_QUIT message first this time */
8447     ret = GetMessage(&msg, NULL, 0, 0);
8448     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
8449     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8450     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
8451
8452     ret = GetMessage(&msg, NULL, 0, 0);
8453     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
8454     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
8455 }
8456
8457 static const struct message WmMouseHoverSeq[] = {
8458     { WM_MOUSEACTIVATE, sent|optional },  /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
8459     { WM_MOUSEACTIVATE, sent|optional },
8460     { WM_TIMER, sent|optional }, /* XP sends it */
8461     { WM_SYSTIMER, sent },
8462     { WM_MOUSEHOVER, sent|wparam, 0 },
8463     { 0 }
8464 };
8465
8466 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
8467 {
8468     MSG msg;
8469     DWORD start_ticks, end_ticks;
8470
8471     start_ticks = GetTickCount();
8472     /* add some deviation (5%) to cover not expected delays */
8473     start_ticks += timeout / 20;
8474
8475     do
8476     {
8477         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
8478         {
8479             /* Timer proc messages are not dispatched to the window proc,
8480              * and therefore not logged.
8481              */
8482             if (msg.message == WM_TIMER || msg.message == WM_SYSTIMER)
8483             {
8484                 struct message s_msg;
8485
8486                 s_msg.message = msg.message;
8487                 s_msg.flags = sent|wparam|lparam;
8488                 s_msg.wParam = msg.wParam;
8489                 s_msg.lParam = msg.lParam;
8490                 add_message(&s_msg);
8491             }
8492             DispatchMessage(&msg);
8493         }
8494
8495         end_ticks = GetTickCount();
8496
8497         /* inject WM_MOUSEMOVE to see how it changes tracking */
8498         if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
8499         {
8500             mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8501             mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8502
8503             inject_mouse_move = FALSE;
8504         }
8505     } while (start_ticks + timeout >= end_ticks);
8506 }
8507
8508 static void test_TrackMouseEvent(void)
8509 {
8510     TRACKMOUSEEVENT tme;
8511     BOOL ret;
8512     HWND hwnd, hchild;
8513     RECT rc_parent, rc_child;
8514     UINT default_hover_time, hover_width = 0, hover_height = 0;
8515
8516 #define track_hover(track_hwnd, track_hover_time) \
8517     tme.cbSize = sizeof(tme); \
8518     tme.dwFlags = TME_HOVER; \
8519     tme.hwndTrack = track_hwnd; \
8520     tme.dwHoverTime = track_hover_time; \
8521     SetLastError(0xdeadbeef); \
8522     ret = pTrackMouseEvent(&tme); \
8523     ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
8524
8525 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
8526     tme.cbSize = sizeof(tme); \
8527     tme.dwFlags = TME_QUERY; \
8528     tme.hwndTrack = (HWND)0xdeadbeef; \
8529     tme.dwHoverTime = 0xdeadbeef; \
8530     SetLastError(0xdeadbeef); \
8531     ret = pTrackMouseEvent(&tme); \
8532     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
8533     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
8534     ok(tme.dwFlags == (expected_track_flags), \
8535        "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
8536     ok(tme.hwndTrack == (expected_track_hwnd), \
8537        "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
8538     ok(tme.dwHoverTime == (expected_hover_time), \
8539        "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
8540
8541 #define track_hover_cancel(track_hwnd) \
8542     tme.cbSize = sizeof(tme); \
8543     tme.dwFlags = TME_HOVER | TME_CANCEL; \
8544     tme.hwndTrack = track_hwnd; \
8545     tme.dwHoverTime = 0xdeadbeef; \
8546     SetLastError(0xdeadbeef); \
8547     ret = pTrackMouseEvent(&tme); \
8548     ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
8549
8550     default_hover_time = 0xdeadbeef;
8551     SetLastError(0xdeadbeef);
8552     ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
8553     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
8554     if (!ret) default_hover_time = 400;
8555     trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
8556
8557     SetLastError(0xdeadbeef);
8558     ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
8559     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
8560     if (!ret) hover_width = 4;
8561     SetLastError(0xdeadbeef);
8562     ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
8563     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
8564     if (!ret) hover_height = 4;
8565     trace("hover rect is %u x %d\n", hover_width, hover_height);
8566
8567     hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
8568                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8569                           CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8570                           NULL, NULL, 0);
8571     assert(hwnd);
8572
8573     hchild = CreateWindowEx(0, "TestWindowClass", NULL,
8574                           WS_CHILD | WS_BORDER | WS_VISIBLE,
8575                           50, 50, 200, 200, hwnd,
8576                           NULL, NULL, 0);
8577     assert(hchild);
8578
8579     flush_events();
8580     flush_sequence();
8581
8582     tme.cbSize = 0;
8583     tme.dwFlags = TME_QUERY;
8584     tme.hwndTrack = (HWND)0xdeadbeef;
8585     tme.dwHoverTime = 0xdeadbeef;
8586     SetLastError(0xdeadbeef);
8587     ret = pTrackMouseEvent(&tme);
8588     ok(!ret, "TrackMouseEvent should fail\n");
8589     ok(GetLastError() == ERROR_INVALID_PARAMETER, "not expected error %d\n", GetLastError());
8590
8591     tme.cbSize = sizeof(tme);
8592     tme.dwFlags = TME_HOVER;
8593     tme.hwndTrack = (HWND)0xdeadbeef;
8594     tme.dwHoverTime = 0xdeadbeef;
8595     SetLastError(0xdeadbeef);
8596     ret = pTrackMouseEvent(&tme);
8597     ok(!ret, "TrackMouseEvent should fail\n");
8598     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "not expected error %d\n", GetLastError());
8599
8600     tme.cbSize = sizeof(tme);
8601     tme.dwFlags = TME_HOVER | TME_CANCEL;
8602     tme.hwndTrack = (HWND)0xdeadbeef;
8603     tme.dwHoverTime = 0xdeadbeef;
8604     SetLastError(0xdeadbeef);
8605     ret = pTrackMouseEvent(&tme);
8606     ok(!ret, "TrackMouseEvent should fail\n");
8607     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "not expected error %d\n", GetLastError());
8608
8609     GetWindowRect(hwnd, &rc_parent);
8610     GetWindowRect(hchild, &rc_child);
8611     SetCursorPos(rc_child.left - 10, rc_child.top - 10);
8612
8613     /* Process messages so that the system updates its internal current
8614      * window and hittest, otherwise TrackMouseEvent calls don't have any
8615      * effect.
8616      */
8617     flush_events();
8618     flush_sequence();
8619
8620     track_query(0, NULL, 0);
8621     track_hover(hchild, 0);
8622     track_query(0, NULL, 0);
8623
8624     flush_events();
8625     flush_sequence();
8626
8627     track_hover(hwnd, 0);
8628     track_query(TME_HOVER, hwnd, default_hover_time);
8629
8630     pump_msg_loop_timeout(default_hover_time, FALSE);
8631     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
8632
8633     track_query(0, NULL, 0);
8634
8635     track_hover(hwnd, HOVER_DEFAULT);
8636     track_query(TME_HOVER, hwnd, default_hover_time);
8637
8638     Sleep(default_hover_time / 2);
8639     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8640     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8641
8642     track_query(TME_HOVER, hwnd, default_hover_time);
8643
8644     pump_msg_loop_timeout(default_hover_time / 2, FALSE);
8645     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
8646
8647     track_query(0, NULL, 0);
8648
8649     track_hover(hwnd, HOVER_DEFAULT);
8650     track_query(TME_HOVER, hwnd, default_hover_time);
8651
8652     pump_msg_loop_timeout(default_hover_time, TRUE);
8653     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
8654
8655     track_query(0, NULL, 0);
8656
8657     track_hover(hwnd, HOVER_DEFAULT);
8658     track_query(TME_HOVER, hwnd, default_hover_time);
8659     track_hover_cancel(hwnd);
8660
8661     DestroyWindow(hwnd);
8662
8663 #undef track_hover
8664 #undef track_query
8665 #undef track_hover_cancel
8666 }
8667
8668
8669 static const struct message WmSetWindowRgn[] = {
8670     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
8671     { WM_NCCALCSIZE, sent|wparam, 1 },
8672     { WM_NCPAINT, sent }, /* wparam != 1 */
8673     { WM_GETTEXT, sent|defwinproc|optional },
8674     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
8675     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
8676     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
8677     { 0 }
8678 };
8679
8680 static const struct message WmSetWindowRgn_no_redraw[] = {
8681     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
8682     { WM_NCCALCSIZE, sent|wparam, 1 },
8683     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
8684     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
8685     { 0 }
8686 };
8687
8688 static const struct message WmSetWindowRgn_clear[] = {
8689     { 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 */
8690     { WM_NCCALCSIZE, sent|wparam, 1 },
8691     { WM_NCPAINT, sent }, /* wparam != 1 */
8692     { WM_GETTEXT, sent|defwinproc|optional },
8693     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
8694     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
8695     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
8696     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
8697     { WM_GETTEXT, sent|defwinproc|optional },
8698     { WM_ERASEBKGND, sent|optional },
8699     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
8700     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
8701     { 0 }
8702 };
8703
8704 static void test_SetWindowRgn(void)
8705 {
8706     HRGN hrgn;
8707     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
8708                                 100, 100, 200, 200, 0, 0, 0, NULL);
8709     ok( hwnd != 0, "Failed to create overlapped window\n" );
8710
8711     ShowWindow( hwnd, SW_SHOW );
8712     UpdateWindow( hwnd );
8713     flush_events();
8714     flush_sequence();
8715
8716     trace("testing SetWindowRgn\n");
8717     hrgn = CreateRectRgn( 0, 0, 150, 150 );
8718     SetWindowRgn( hwnd, hrgn, TRUE );
8719     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
8720
8721     hrgn = CreateRectRgn( 30, 30, 160, 160 );
8722     SetWindowRgn( hwnd, hrgn, FALSE );
8723     ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
8724
8725     hrgn = CreateRectRgn( 0, 0, 180, 180 );
8726     SetWindowRgn( hwnd, hrgn, TRUE );
8727     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
8728
8729     SetWindowRgn( hwnd, 0, TRUE );
8730     ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
8731
8732     DestroyWindow( hwnd );
8733 }
8734
8735 /*************************** ShowWindow() test ******************************/
8736 static const struct message WmShowNormal[] = {
8737     { WM_SHOWWINDOW, sent|wparam, 1 },
8738     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
8739     { HCBT_ACTIVATE, hook },
8740     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
8741     { HCBT_SETFOCUS, hook },
8742     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8743     { 0 }
8744 };
8745 static const struct message WmShow[] = {
8746     { WM_SHOWWINDOW, sent|wparam, 1 },
8747     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
8748     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
8749     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
8750     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
8751     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8752     { 0 }
8753 };
8754 static const struct message WmShowNoActivate_1[] = {
8755     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
8756     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|0x8000 },
8757     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|0x8000 },
8758     { WM_MOVE, sent|defwinproc },
8759     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
8760     { 0 }
8761 };
8762 static const struct message WmShowNoActivate_2[] = {
8763     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
8764     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8765     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8766     { WM_MOVE, sent|defwinproc },
8767     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
8768     { HCBT_SETFOCUS, hook },
8769     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
8770     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
8771     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
8772     { 0 }
8773 };
8774 static const struct message WmShowNA_1[] = {
8775     { WM_SHOWWINDOW, sent|wparam, 1 },
8776     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
8777     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8778     { 0 }
8779 };
8780 static const struct message WmShowNA_2[] = {
8781     { WM_SHOWWINDOW, sent|wparam, 1 },
8782     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
8783     { 0 }
8784 };
8785 static const struct message WmRestore_1[] = {
8786     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
8787     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8788     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
8789     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
8790     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
8791     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8792     { WM_MOVE, sent|defwinproc },
8793     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
8794     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
8795     { 0 }
8796 };
8797 static const struct message WmRestore_2[] = {
8798     { WM_SHOWWINDOW, sent|wparam, 1 },
8799     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
8800     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8801     { 0 }
8802 };
8803 static const struct message WmRestore_3[] = {
8804     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
8805     { WM_GETMINMAXINFO, sent },
8806     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8807     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
8808     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
8809     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
8810     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8811     { WM_MOVE, sent|defwinproc },
8812     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
8813     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
8814     { 0 }
8815 };
8816 static const struct message WmRestore_4[] = {
8817     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
8818     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
8819     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|0x8000 },
8820     { WM_MOVE, sent|defwinproc },
8821     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
8822     { 0 }
8823 };
8824 static const struct message WmRestore_5[] = {
8825     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
8826     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
8827     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|0x8000 },
8828     { WM_MOVE, sent|defwinproc },
8829     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
8830     { 0 }
8831 };
8832 static const struct message WmHide_1[] = {
8833     { WM_SHOWWINDOW, sent|wparam, 0 },
8834     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
8835     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8836     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
8837     { 0 }
8838 };
8839 static const struct message WmHide_2[] = {
8840     { WM_SHOWWINDOW, sent|wparam, 0 },
8841     { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
8842     { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
8843     { 0 }
8844 };
8845 static const struct message WmHide_3[] = {
8846     { WM_SHOWWINDOW, sent|wparam, 0 },
8847     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
8848     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8849     { HCBT_SETFOCUS, hook },
8850     { 0 }
8851 };
8852 static const struct message WmShowMinimized_1[] = {
8853     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
8854     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8855     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
8856     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
8857     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8858     { WM_MOVE, sent|defwinproc },
8859     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
8860     { 0 }
8861 };
8862 static const struct message WmMinimize_1[] = {
8863     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
8864     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
8865     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8866     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8867     { WM_MOVE, sent|defwinproc },
8868     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
8869     { 0 }
8870 };
8871 static const struct message WmMinimize_2[] = {
8872     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
8873     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8874     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8875     { WM_MOVE, sent|defwinproc },
8876     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
8877     { 0 }
8878 };
8879 static const struct message WmMinimize_3[] = {
8880     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
8881     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8882     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8883     { WM_MOVE, sent|defwinproc },
8884     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
8885     { 0 }
8886 };
8887 static const struct message WmShowMinNoActivate[] = {
8888     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
8889     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
8890     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8891     { 0 }
8892 };
8893 static const struct message WmMinMax_1[] = {
8894     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
8895     { 0 }
8896 };
8897 static const struct message WmMinMax_2[] = {
8898     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
8899     { 0 }
8900 };
8901 static const struct message WmMinMax_3[] = {
8902     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
8903     { 0 }
8904 };
8905 static const struct message WmMinMax_4[] = {
8906     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
8907     { 0 }
8908 };
8909 static const struct message WmShowMaximized_1[] = {
8910     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
8911     { WM_GETMINMAXINFO, sent },
8912     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8913     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
8914     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
8915     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
8916     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8917     { WM_MOVE, sent|defwinproc },
8918     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
8919     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
8920     { 0 }
8921 };
8922 static const struct message WmShowMaximized_2[] = {
8923     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
8924     { WM_GETMINMAXINFO, sent },
8925     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
8926     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8927     { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
8928     { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
8929     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8930     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8931     { WM_MOVE, sent|defwinproc },
8932     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
8933     { HCBT_SETFOCUS, hook },
8934     { 0 }
8935 };
8936 static const struct message WmShowMaximized_3[] = {
8937     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
8938     { WM_GETMINMAXINFO, sent },
8939     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
8940     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|0x8000 },
8941     { WM_MOVE, sent|defwinproc },
8942     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
8943     { 0 }
8944 };
8945
8946 static void test_ShowWindow(void)
8947 {
8948     /* ShowWindow commands in random order */
8949     static const struct
8950     {
8951         INT cmd; /* ShowWindow command */
8952         LPARAM ret; /* ShowWindow return value */
8953         DWORD style; /* window style after the command */
8954         const struct message *msg; /* message sequence the command produces */
8955         BOOL todo_msg; /* message sequence doesn't match what Wine does */
8956     } sw[] =
8957     {
8958 /*  1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
8959 /*  2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
8960 /*  3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
8961 /*  4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
8962 /*  5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
8963 /*  6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
8964 /*  7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
8965 /*  8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
8966 /*  9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
8967 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
8968 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
8969 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
8970 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
8971 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
8972 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
8973 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
8974 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
8975 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
8976 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, TRUE },
8977 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
8978 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
8979 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
8980 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
8981 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
8982 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
8983 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
8984 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
8985 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
8986 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
8987 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
8988 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
8989 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, TRUE },
8990 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
8991 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, TRUE }, /* what does this mean?! */
8992 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, TRUE },
8993 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
8994 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
8995 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
8996 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
8997 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, TRUE },
8998 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
8999 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, TRUE },
9000 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
9001 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, TRUE },
9002 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
9003 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
9004 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
9005 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
9006 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
9007 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
9008 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9009 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
9010 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9011 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, TRUE },
9012 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9013 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
9014 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
9015     };
9016     HWND hwnd;
9017     DWORD style;
9018     LPARAM ret;
9019     INT i;
9020
9021 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
9022     hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
9023                           120, 120, 90, 90,
9024                           0, 0, 0, NULL);
9025     assert(hwnd);
9026
9027     style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
9028     ok(style == 0, "expected style 0, got %08x\n", style);
9029
9030     flush_events();
9031     flush_sequence();
9032
9033     for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
9034     {
9035         static const char * const sw_cmd_name[13] =
9036         {
9037             "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
9038             "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
9039             "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
9040             "SW_NORMALNA" /* 0xCC */
9041         };
9042         char comment[64];
9043         INT idx; /* index into the above array of names */
9044
9045         idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
9046
9047         style = GetWindowLong(hwnd, GWL_STYLE);
9048         trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
9049         ret = ShowWindow(hwnd, sw[i].cmd);
9050         ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
9051         style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
9052         ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
9053
9054         sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
9055         ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
9056
9057         flush_events();
9058         flush_sequence();
9059     }
9060
9061     DestroyWindow(hwnd);
9062 }
9063
9064 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9065 {
9066     struct message msg;
9067
9068     trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
9069
9070     switch (message)
9071     {
9072     case WM_WINDOWPOSCHANGING:
9073     case WM_WINDOWPOSCHANGED:
9074     {
9075         WINDOWPOS *winpos = (WINDOWPOS *)lParam;
9076
9077         trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
9078         trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
9079               winpos->hwnd, winpos->hwndInsertAfter,
9080               winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
9081         dump_winpos_flags(winpos->flags);
9082
9083         /* Log only documented flags, win2k uses 0x1000 and 0x2000
9084          * in the high word for internal purposes
9085          */
9086         wParam = winpos->flags & 0xffff;
9087         /* We are not interested in the flags that don't match under XP and Win9x */
9088         wParam &= ~(SWP_NOZORDER);
9089         break;
9090     }
9091
9092     /* explicitly ignore WM_GETICON message */
9093     case WM_GETICON:
9094         return 0;
9095     }
9096
9097     msg.message = message;
9098     msg.flags = sent|wparam|lparam;
9099     msg.wParam = wParam;
9100     msg.lParam = lParam;
9101     add_message(&msg);
9102
9103     /* calling DefDlgProc leads to a recursion under XP */
9104
9105     switch (message)
9106     {
9107     case WM_INITDIALOG:
9108     case WM_GETDLGCODE:
9109         return 0;
9110     }
9111     return 1;
9112 }
9113
9114 static const struct message WmDefDlgSetFocus_1[] = {
9115     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
9116     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
9117     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
9118     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
9119     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
9120     { HCBT_SETFOCUS, hook },
9121     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9122     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9123     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9124     { WM_SETFOCUS, sent|wparam, 0 },
9125     { WM_CTLCOLOREDIT, sent },
9126     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9127     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9128     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9129     { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
9130     { 0 }
9131 };
9132 static const struct message WmDefDlgSetFocus_2[] = {
9133     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
9134     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
9135     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
9136     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
9137     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
9138     { WM_CTLCOLOREDIT, sent|optional }, /* XP */
9139     { 0 }
9140 };
9141 /* Creation of a dialog */
9142 static const struct message WmCreateDialogParamSeq_1[] = {
9143     { HCBT_CREATEWND, hook },
9144     { WM_NCCREATE, sent },
9145     { WM_NCCALCSIZE, sent|wparam, 0 },
9146     { WM_CREATE, sent },
9147     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
9148     { WM_SIZE, sent|wparam, SIZE_RESTORED },
9149     { WM_MOVE, sent },
9150     { WM_SETFONT, sent },
9151     { WM_INITDIALOG, sent },
9152     { WM_CHANGEUISTATE, sent|optional },
9153     { 0 }
9154 };
9155 /* Creation of a dialog */
9156 static const struct message WmCreateDialogParamSeq_2[] = {
9157     { HCBT_CREATEWND, hook },
9158     { WM_NCCREATE, sent },
9159     { WM_NCCALCSIZE, sent|wparam, 0 },
9160     { WM_CREATE, sent },
9161     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
9162     { WM_SIZE, sent|wparam, SIZE_RESTORED },
9163     { WM_MOVE, sent },
9164     { WM_CHANGEUISTATE, sent|optional },
9165     { 0 }
9166 };
9167
9168 static void test_dialog_messages(void)
9169 {
9170     WNDCLASS cls;
9171     HWND hdlg, hedit1, hedit2, hfocus;
9172     LRESULT ret;
9173
9174 #define set_selection(hctl, start, end) \
9175     ret = SendMessage(hctl, EM_SETSEL, start, end); \
9176     ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
9177
9178 #define check_selection(hctl, start, end) \
9179     ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
9180     ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
9181
9182     subclass_edit();
9183
9184     hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
9185                           WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
9186                           0, 0, 100, 100, 0, 0, 0, NULL);
9187     ok(hdlg != 0, "Failed to create custom dialog window\n");
9188
9189     hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
9190                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
9191                            0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
9192     ok(hedit1 != 0, "Failed to create edit control\n");
9193     hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
9194                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
9195                            0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
9196     ok(hedit2 != 0, "Failed to create edit control\n");
9197
9198     SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
9199     SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
9200
9201     hfocus = GetFocus();
9202     ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
9203
9204     SetFocus(hedit2);
9205     hfocus = GetFocus();
9206     ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
9207
9208     check_selection(hedit1, 0, 0);
9209     check_selection(hedit2, 0, 0);
9210
9211     set_selection(hedit2, 0, -1);
9212     check_selection(hedit2, 0, 3);
9213
9214     SetFocus(0);
9215     hfocus = GetFocus();
9216     ok(hfocus == 0, "wrong focus %p\n", hfocus);
9217
9218     flush_sequence();
9219     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
9220     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
9221     ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
9222
9223     hfocus = GetFocus();
9224     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
9225
9226     check_selection(hedit1, 0, 5);
9227     check_selection(hedit2, 0, 3);
9228
9229     flush_sequence();
9230     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
9231     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
9232     ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
9233
9234     hfocus = GetFocus();
9235     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
9236
9237     check_selection(hedit1, 0, 5);
9238     check_selection(hedit2, 0, 3);
9239
9240     EndDialog(hdlg, 0);
9241     DestroyWindow(hedit1);
9242     DestroyWindow(hedit2);
9243     DestroyWindow(hdlg);
9244     flush_sequence();
9245
9246 #undef set_selection
9247 #undef check_selection
9248
9249     ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
9250     cls.lpszClassName = "MyDialogClass";
9251     cls.hInstance = GetModuleHandle(0);
9252     /* need a cast since a dlgproc is used as a wndproc */
9253     cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
9254     if (!RegisterClass(&cls)) assert(0);
9255
9256     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
9257     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
9258     ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
9259     EndDialog(hdlg, 0);
9260     DestroyWindow(hdlg);
9261     flush_sequence();
9262
9263     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
9264     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
9265     ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
9266     EndDialog(hdlg, 0);
9267     DestroyWindow(hdlg);
9268     flush_sequence();
9269
9270     UnregisterClass(cls.lpszClassName, cls.hInstance);
9271 }
9272
9273 static void test_nullCallback(void)
9274 {
9275     HWND hwnd;
9276
9277     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
9278                            100, 100, 200, 200, 0, 0, 0, NULL);
9279     ok (hwnd != 0, "Failed to create overlapped window\n");
9280
9281     SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
9282     flush_events();
9283     DestroyWindow(hwnd);
9284 }
9285
9286 static const struct message SetForegroundWindowSeq[] =
9287 {
9288     { WM_NCACTIVATE, sent|wparam, 0 },
9289     { WM_GETTEXT, sent|defwinproc|optional },
9290     { WM_ACTIVATE, sent|wparam, 0 },
9291     { WM_ACTIVATEAPP, sent|wparam, 0 },
9292     { WM_KILLFOCUS, sent },
9293     { 0 }
9294 };
9295
9296 static void test_SetForegroundWindow(void)
9297 {
9298     HWND hwnd;
9299
9300     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
9301                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9302                            100, 100, 200, 200, 0, 0, 0, NULL);
9303     ok (hwnd != 0, "Failed to create overlapped window\n");
9304     flush_sequence();
9305
9306     trace("SetForegroundWindow( 0 )\n");
9307     SetForegroundWindow( 0 );
9308     ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
9309     trace("SetForegroundWindow( GetDesktopWindow() )\n");
9310     SetForegroundWindow( GetDesktopWindow() );
9311     ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
9312                                         "foreground top level window", FALSE);
9313     trace("done\n");
9314
9315     DestroyWindow(hwnd);
9316 }
9317
9318 static void test_dbcs_wm_char(void)
9319 {
9320     BYTE dbch[2];
9321     WCHAR wch, bad_wch;
9322     HWND hwnd, hwnd2;
9323     MSG msg;
9324     DWORD time;
9325     POINT pt;
9326     DWORD_PTR res;
9327     CPINFOEXA cpinfo;
9328     UINT i, j, k;
9329     struct message wmCharSeq[2];
9330
9331     pGetCPInfoExA( CP_ACP, 0, &cpinfo );
9332     if (cpinfo.MaxCharSize != 2)
9333     {
9334         skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
9335         return;
9336     }
9337
9338     dbch[0] = dbch[1] = 0;
9339     wch = 0;
9340     bad_wch = cpinfo.UnicodeDefaultChar;
9341     for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
9342         for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
9343             for (k = 128; k <= 255; k++)
9344             {
9345                 char str[2];
9346                 WCHAR wstr[2];
9347                 str[0] = j;
9348                 str[1] = k;
9349                 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
9350                     WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
9351                     (BYTE)str[0] == j && (BYTE)str[1] == k &&
9352                     HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
9353                 {
9354                     dbch[0] = j;
9355                     dbch[1] = k;
9356                     wch = wstr[0];
9357                     break;
9358                 }
9359             }
9360
9361     if (!wch)
9362     {
9363         skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
9364         return;
9365     }
9366     trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
9367            dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
9368
9369     hwnd = CreateWindowExW(0, testWindowClassW, NULL,
9370                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
9371     hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
9372                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
9373     ok (hwnd != 0, "Failed to create overlapped window\n");
9374     ok (hwnd2 != 0, "Failed to create overlapped window\n");
9375     flush_sequence();
9376
9377     memset( wmCharSeq, 0, sizeof(wmCharSeq) );
9378     wmCharSeq[0].message = WM_CHAR;
9379     wmCharSeq[0].flags = sent|wparam;
9380     wmCharSeq[0].wParam = wch;
9381
9382     /* posted message */
9383     PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9384     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9385     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9386     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9387     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9388     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
9389     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9390
9391     /* posted thread message */
9392     PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
9393     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9394     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9395     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9396     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9397     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
9398     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9399
9400     /* sent message */
9401     flush_sequence();
9402     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9403     ok_sequence( WmEmptySeq, "no messages", FALSE );
9404     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9405     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9406     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9407
9408     /* sent message with timeout */
9409     flush_sequence();
9410     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
9411     ok_sequence( WmEmptySeq, "no messages", FALSE );
9412     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
9413     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9414     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9415
9416     /* sent message with timeout and callback */
9417     flush_sequence();
9418     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
9419     ok_sequence( WmEmptySeq, "no messages", FALSE );
9420     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
9421     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9422     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9423
9424     /* sent message with callback */
9425     flush_sequence();
9426     SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9427     ok_sequence( WmEmptySeq, "no messages", FALSE );
9428     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
9429     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9430     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9431
9432     /* direct window proc call */
9433     flush_sequence();
9434     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
9435     ok_sequence( WmEmptySeq, "no messages", FALSE );
9436     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
9437     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9438
9439     /* dispatch message */
9440     msg.hwnd = hwnd;
9441     msg.message = WM_CHAR;
9442     msg.wParam = dbch[0];
9443     msg.lParam = 0;
9444     DispatchMessageA( &msg );
9445     ok_sequence( WmEmptySeq, "no messages", FALSE );
9446     msg.wParam = dbch[1];
9447     DispatchMessageA( &msg );
9448     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9449
9450     /* window handle is irrelevant */
9451     flush_sequence();
9452     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
9453     ok_sequence( WmEmptySeq, "no messages", FALSE );
9454     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9455     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9456     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9457
9458     /* interleaved post and send */
9459     flush_sequence();
9460     PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
9461     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
9462     ok_sequence( WmEmptySeq, "no messages", FALSE );
9463     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9464     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9465     ok_sequence( WmEmptySeq, "no messages", FALSE );
9466     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9467     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9468     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
9469     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9470     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9471     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9472     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9473
9474     /* interleaved sent message and winproc */
9475     flush_sequence();
9476     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9477     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
9478     ok_sequence( WmEmptySeq, "no messages", FALSE );
9479     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9480     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9481     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
9482     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9483
9484     /* interleaved winproc and dispatch */
9485     msg.hwnd = hwnd;
9486     msg.message = WM_CHAR;
9487     msg.wParam = dbch[0];
9488     msg.lParam = 0;
9489     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
9490     DispatchMessageA( &msg );
9491     ok_sequence( WmEmptySeq, "no messages", FALSE );
9492     msg.wParam = dbch[1];
9493     DispatchMessageA( &msg );
9494     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9495     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
9496     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9497
9498     /* interleaved sends */
9499     flush_sequence();
9500     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9501     SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
9502     ok_sequence( WmEmptySeq, "no messages", FALSE );
9503     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
9504     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9505     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9506     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9507
9508     /* dbcs WM_CHAR */
9509     flush_sequence();
9510     SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
9511     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9512     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9513
9514     /* other char messages are not magic */
9515     PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
9516     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9517     ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
9518     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
9519     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9520     PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
9521     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9522     ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
9523     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
9524     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9525
9526     /* test retrieving messages */
9527
9528     PostMessageW( hwnd, WM_CHAR, wch, 0 );
9529     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9530     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9531     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9532     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9533     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9534     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9535     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9536     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9537     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9538
9539     /* message filters */
9540     PostMessageW( hwnd, WM_CHAR, wch, 0 );
9541     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9542     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9543     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9544     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9545     /* message id is filtered, hwnd is not */
9546     ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
9547     ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
9548     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9549     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9550     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9551     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9552
9553     /* mixing GetMessage and PostMessage */
9554     PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
9555     ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
9556     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9557     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9558     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9559     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
9560     time = msg.time;
9561     pt = msg.pt;
9562     ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
9563     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
9564     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9565     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9566     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9567     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
9568     ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
9569     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 );
9570     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9571
9572     /* without PM_REMOVE */
9573     PostMessageW( hwnd, WM_CHAR, wch, 0 );
9574     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
9575     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9576     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9577     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9578     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
9579     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9580     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9581     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9582     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
9583     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9584     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9585     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9586     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
9587     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9588     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9589     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9590     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9591
9592     DestroyWindow(hwnd);
9593 }
9594
9595 START_TEST(msg)
9596 {
9597     BOOL ret;
9598     FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
9599
9600     init_procs();
9601
9602     if (!RegisterWindowClasses()) assert(0);
9603
9604     if (pSetWinEventHook)
9605     {
9606         hEvent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
9607                                                       GetModuleHandleA(0),
9608                                                       win_event_proc,
9609                                                       0,
9610                                                       GetCurrentThreadId(),
9611                                                       WINEVENT_INCONTEXT);
9612         assert(hEvent_hook);
9613
9614         if (pIsWinEventHookInstalled)
9615         {
9616             UINT event;
9617             for (event = EVENT_MIN; event <= EVENT_MAX; event++)
9618                 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
9619         }
9620     }
9621
9622     cbt_hook_thread_id = GetCurrentThreadId();
9623     hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
9624     assert(hCBT_hook);
9625
9626     test_winevents();
9627
9628     /* Fix message sequences before removing 4 lines below */
9629 #if 1
9630     if (pUnhookWinEvent && hEvent_hook)
9631     {
9632         ret = pUnhookWinEvent(hEvent_hook);
9633         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
9634         pUnhookWinEvent = 0;
9635     }
9636     hEvent_hook = 0;
9637 #endif
9638
9639     test_ShowWindow();
9640     test_PeekMessage();
9641     test_scrollwindowex();
9642     test_messages();
9643     test_showwindow();
9644     invisible_parent_tests();
9645     test_mdi_messages();
9646     test_button_messages();
9647     test_static_messages();
9648     test_paint_messages();
9649     test_interthread_messages();
9650     test_message_conversion();
9651     test_accelerators();
9652     test_timers();
9653     test_timers_no_wnd();
9654     test_set_hook();
9655     test_DestroyWindow();
9656     test_DispatchMessage();
9657     test_SendMessageTimeout();
9658     test_edit_messages();
9659     test_quit_message();
9660
9661     if (!pTrackMouseEvent)
9662         skip("TrackMouseEvent is not available\n");
9663     else
9664         test_TrackMouseEvent();
9665
9666     test_SetWindowRgn();
9667     test_sys_menu();
9668     test_dialog_messages();
9669     test_nullCallback();
9670     test_SetForegroundWindow();
9671     test_dbcs_wm_char();
9672
9673     UnhookWindowsHookEx(hCBT_hook);
9674     if (pUnhookWinEvent)
9675     {
9676         ret = pUnhookWinEvent(hEvent_hook);
9677         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
9678         SetLastError(0xdeadbeef);
9679         ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
9680         ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
9681            GetLastError() == 0xdeadbeef, /* Win9x */
9682            "unexpected error %d\n", GetLastError());
9683     }
9684     else
9685         skip("UnhookWinEvent is not available\n");
9686 }