wintrust: Use a helper function to get a signer's cert info from a message.
[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 /* Various win events with arbitrary parameters */
6784 static const struct message WmWinEventsSeq[] = {
6785     { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
6786     { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6787     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
6788     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
6789     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
6790     { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
6791     { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
6792     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
6793     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
6794     /* our win event hook ignores OBJID_CURSOR events */
6795     /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
6796     { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
6797     { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
6798     { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
6799     { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
6800     { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
6801     { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6802     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
6803     { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
6804     { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
6805     { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
6806     { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
6807     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
6808     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
6809     { 0 }
6810 };
6811 static const struct message WmWinEventCaretSeq[] = {
6812     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
6813     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
6814     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
6815     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
6816     { 0 }
6817 };
6818 static const struct message WmWinEventCaretSeq_2[] = {
6819     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
6820     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
6821     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
6822     { 0 }
6823 };
6824 static const struct message WmWinEventAlertSeq[] = {
6825     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
6826     { 0 }
6827 };
6828 static const struct message WmWinEventAlertSeq_2[] = {
6829     /* create window in the thread proc */
6830     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
6831     /* our test event */
6832     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
6833     { 0 }
6834 };
6835 static const struct message WmGlobalHookSeq_1[] = {
6836     /* create window in the thread proc */
6837     { HCBT_CREATEWND, hook|lparam, 0, 2 },
6838     /* our test events */
6839     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
6840     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
6841     { 0 }
6842 };
6843 static const struct message WmGlobalHookSeq_2[] = {
6844     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
6845     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
6846     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
6847     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
6848     { 0 }
6849 };
6850
6851 static const struct message WmMouseLLHookSeq[] = {
6852     { WM_MOUSEMOVE, hook },
6853     { WM_LBUTTONUP, hook },
6854     { WM_MOUSEMOVE, hook },
6855     { 0 }
6856 };
6857
6858 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
6859                                          DWORD event,
6860                                          HWND hwnd,
6861                                          LONG object_id,
6862                                          LONG child_id,
6863                                          DWORD thread_id,
6864                                          DWORD event_time)
6865 {
6866     char buf[256];
6867
6868     trace("WEH_2:%p,event %08x,hwnd %p,obj %08x,id %08x,thread %08x,time %08x\n",
6869            hevent, event, hwnd, object_id, child_id, thread_id, event_time);
6870
6871     if (GetClassNameA(hwnd, buf, sizeof(buf)))
6872     {
6873         if (!lstrcmpiA(buf, "TestWindowClass") ||
6874             !lstrcmpiA(buf, "static"))
6875         {
6876             struct message msg;
6877
6878             msg.message = event;
6879             msg.flags = winevent_hook|wparam|lparam;
6880             msg.wParam = object_id;
6881             msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
6882             add_message(&msg);
6883         }
6884     }
6885 }
6886
6887 static HHOOK hCBT_global_hook;
6888 static DWORD cbt_global_hook_thread_id;
6889
6890 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
6891
6892     HWND hwnd;
6893     char buf[256];
6894
6895     trace("CBT_2: %d, %08lx, %08lx\n", nCode, wParam, lParam);
6896
6897     if (nCode == HCBT_SYSCOMMAND)
6898     {
6899         struct message msg;
6900
6901         msg.message = nCode;
6902         msg.flags = hook|wparam|lparam;
6903         msg.wParam = wParam;
6904         msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
6905         add_message(&msg);
6906
6907         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
6908     }
6909     /* WH_MOUSE_LL hook */
6910     if (nCode == HC_ACTION)
6911     {
6912         struct message msg;
6913         MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
6914
6915         /* we can't test for real mouse events */
6916         if (mhll->flags & LLMHF_INJECTED)
6917         {
6918             msg.message = wParam;
6919             msg.flags = hook;
6920             add_message(&msg);
6921         }
6922         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
6923     }
6924
6925     /* Log also SetFocus(0) calls */
6926     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
6927
6928     if (GetClassNameA(hwnd, buf, sizeof(buf)))
6929     {
6930         if (!lstrcmpiA(buf, "TestWindowClass") ||
6931             !lstrcmpiA(buf, "static"))
6932         {
6933             struct message msg;
6934
6935             msg.message = nCode;
6936             msg.flags = hook|wparam|lparam;
6937             msg.wParam = wParam;
6938             msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
6939             add_message(&msg);
6940         }
6941     }
6942     return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
6943 }
6944
6945 static DWORD WINAPI win_event_global_thread_proc(void *param)
6946 {
6947     HWND hwnd;
6948     MSG msg;
6949     HANDLE hevent = *(HANDLE *)param;
6950
6951     assert(pNotifyWinEvent);
6952
6953     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
6954     assert(hwnd);
6955     trace("created thread window %p\n", hwnd);
6956
6957     *(HWND *)param = hwnd;
6958
6959     flush_sequence();
6960     /* this event should be received only by our new hook proc,
6961      * an old one does not expect an event from another thread.
6962      */
6963     pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
6964     SetEvent(hevent);
6965
6966     while (GetMessage(&msg, 0, 0, 0))
6967     {
6968         TranslateMessage(&msg);
6969         DispatchMessage(&msg);
6970     }
6971     return 0;
6972 }
6973
6974 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
6975 {
6976     HWND hwnd;
6977     MSG msg;
6978     HANDLE hevent = *(HANDLE *)param;
6979
6980     flush_sequence();
6981     /* these events should be received only by our new hook proc,
6982      * an old one does not expect an event from another thread.
6983      */
6984
6985     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
6986     assert(hwnd);
6987     trace("created thread window %p\n", hwnd);
6988
6989     *(HWND *)param = hwnd;
6990
6991     /* Windows doesn't like when a thread plays games with the focus,
6992        that leads to all kinds of misbehaviours and failures to activate
6993        a window. So, better keep next lines commented out.
6994     SetFocus(0);
6995     SetFocus(hwnd);*/
6996
6997     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
6998     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
6999
7000     SetEvent(hevent);
7001
7002     while (GetMessage(&msg, 0, 0, 0))
7003     {
7004         TranslateMessage(&msg);
7005         DispatchMessage(&msg);
7006     }
7007     return 0;
7008 }
7009
7010 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
7011 {
7012     HWND hwnd;
7013     MSG msg;
7014     HANDLE hevent = *(HANDLE *)param;
7015
7016     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7017     assert(hwnd);
7018     trace("created thread window %p\n", hwnd);
7019
7020     *(HWND *)param = hwnd;
7021
7022     flush_sequence();
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 don't generate a mouse click message below.
7027      */
7028     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7029     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7030     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7031
7032     SetEvent(hevent);
7033     while (GetMessage(&msg, 0, 0, 0))
7034     {
7035         TranslateMessage(&msg);
7036         DispatchMessage(&msg);
7037     }
7038     return 0;
7039 }
7040
7041 static void test_winevents(void)
7042 {
7043     BOOL ret;
7044     MSG msg;
7045     HWND hwnd, hwnd2;
7046     UINT i;
7047     HANDLE hthread, hevent;
7048     DWORD tid;
7049     HWINEVENTHOOK hhook;
7050     const struct message *events = WmWinEventsSeq;
7051
7052     hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
7053                            WS_OVERLAPPEDWINDOW,
7054                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7055                            NULL, NULL, 0);
7056     assert(hwnd);
7057
7058     /****** start of global hook test *************/
7059     hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7060     assert(hCBT_global_hook);
7061
7062     hevent = CreateEventA(NULL, 0, 0, NULL);
7063     assert(hevent);
7064     hwnd2 = (HWND)hevent;
7065
7066     hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
7067     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7068
7069     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7070
7071     ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
7072
7073     flush_sequence();
7074     /* this one should be received only by old hook proc */
7075     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7076     /* this one should be received only by old hook proc */
7077     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7078
7079     ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
7080
7081     ret = UnhookWindowsHookEx(hCBT_global_hook);
7082     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7083
7084     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7085     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7086     CloseHandle(hthread);
7087     CloseHandle(hevent);
7088     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7089     /****** end of global hook test *************/
7090
7091     if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
7092     {
7093         ok(DestroyWindow(hwnd), "failed to destroy window\n");
7094         return;
7095     }
7096
7097     flush_sequence();
7098
7099     if (0)
7100     {
7101     /* this test doesn't pass under Win9x */
7102     /* win2k ignores events with hwnd == 0 */
7103     SetLastError(0xdeadbeef);
7104     pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
7105     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
7106        GetLastError() == 0xdeadbeef, /* Win9x */
7107        "unexpected error %d\n", GetLastError());
7108     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7109     }
7110
7111     for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
7112         pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
7113
7114     ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
7115
7116     /****** start of event filtering test *************/
7117     hhook = (HWINEVENTHOOK)pSetWinEventHook(
7118         EVENT_OBJECT_SHOW, /* 0x8002 */
7119         EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
7120         GetModuleHandleA(0), win_event_global_hook_proc,
7121         GetCurrentProcessId(), 0,
7122         WINEVENT_INCONTEXT);
7123     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7124
7125     hevent = CreateEventA(NULL, 0, 0, NULL);
7126     assert(hevent);
7127     hwnd2 = (HWND)hevent;
7128
7129     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7130     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7131
7132     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7133
7134     ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
7135
7136     flush_sequence();
7137     /* this one should be received only by old hook proc */
7138     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7139     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7140     /* this one should be received only by old hook proc */
7141     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7142
7143     ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
7144
7145     ret = pUnhookWinEvent(hhook);
7146     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7147
7148     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7149     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7150     CloseHandle(hthread);
7151     CloseHandle(hevent);
7152     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7153     /****** end of event filtering test *************/
7154
7155     /****** start of out of context event test *************/
7156     hhook = (HWINEVENTHOOK)pSetWinEventHook(
7157         EVENT_MIN, EVENT_MAX,
7158         0, win_event_global_hook_proc,
7159         GetCurrentProcessId(), 0,
7160         WINEVENT_OUTOFCONTEXT);
7161     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7162
7163     hevent = CreateEventA(NULL, 0, 0, NULL);
7164     assert(hevent);
7165     hwnd2 = (HWND)hevent;
7166
7167     flush_sequence();
7168
7169     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7170     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7171
7172     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7173
7174     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7175     /* process pending winevent messages */
7176     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7177     ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
7178
7179     flush_sequence();
7180     /* this one should be received only by old hook proc */
7181     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7182     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7183     /* this one should be received only by old hook proc */
7184     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7185
7186     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
7187     /* process pending winevent messages */
7188     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7189     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
7190
7191     ret = pUnhookWinEvent(hhook);
7192     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7193
7194     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7195     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7196     CloseHandle(hthread);
7197     CloseHandle(hevent);
7198     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7199     /****** end of out of context event test *************/
7200
7201     /****** start of MOUSE_LL hook test *************/
7202     hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7203     /* WH_MOUSE_LL is not supported on Win9x platforms */
7204     if (!hCBT_global_hook)
7205     {
7206         trace("Skipping WH_MOUSE_LL test on this platform\n");
7207         goto skip_mouse_ll_hook_test;
7208     }
7209
7210     hevent = CreateEventA(NULL, 0, 0, NULL);
7211     assert(hevent);
7212     hwnd2 = (HWND)hevent;
7213
7214     hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
7215     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7216
7217     while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
7218         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
7219
7220     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
7221     flush_sequence();
7222
7223     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7224     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7225     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7226
7227     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
7228
7229     ret = UnhookWindowsHookEx(hCBT_global_hook);
7230     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7231
7232     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7233     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7234     CloseHandle(hthread);
7235     CloseHandle(hevent);
7236     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7237     /****** end of MOUSE_LL hook test *************/
7238 skip_mouse_ll_hook_test:
7239
7240     ok(DestroyWindow(hwnd), "failed to destroy window\n");
7241 }
7242
7243 static void test_set_hook(void)
7244 {
7245     BOOL ret;
7246     HHOOK hhook;
7247     HWINEVENTHOOK hwinevent_hook;
7248
7249     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
7250     ok(hhook != 0, "local hook does not require hModule set to 0\n");
7251     UnhookWindowsHookEx(hhook);
7252
7253     if (0)
7254     {
7255     /* this test doesn't pass under Win9x: BUG! */
7256     SetLastError(0xdeadbeef);
7257     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
7258     ok(!hhook, "global hook requires hModule != 0\n");
7259     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
7260     }
7261
7262     SetLastError(0xdeadbeef);
7263     hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
7264     ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
7265     ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
7266        GetLastError() == 0xdeadbeef, /* Win9x */
7267        "unexpected error %d\n", GetLastError());
7268
7269     SetLastError(0xdeadbeef);
7270     ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
7271     ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
7272        GetLastError() == 0xdeadbeef, /* Win9x */
7273        "unexpected error %d\n", GetLastError());
7274
7275     if (!pSetWinEventHook || !pUnhookWinEvent) return;
7276
7277     /* even process local incontext hooks require hmodule */
7278     SetLastError(0xdeadbeef);
7279     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7280         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
7281     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
7282     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
7283        GetLastError() == 0xdeadbeef, /* Win9x */
7284        "unexpected error %d\n", GetLastError());
7285
7286     /* even thread local incontext hooks require hmodule */
7287     SetLastError(0xdeadbeef);
7288     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7289         0, win_event_proc, GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
7290     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
7291     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
7292        GetLastError() == 0xdeadbeef, /* Win9x */
7293        "unexpected error %d\n", GetLastError());
7294
7295     if (0)
7296     {
7297     /* these 3 tests don't pass under Win9x */
7298     SetLastError(0xdeadbeef);
7299     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(1, 0,
7300         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7301     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
7302     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
7303
7304     SetLastError(0xdeadbeef);
7305     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(-1, 1,
7306         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7307     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
7308     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
7309
7310     SetLastError(0xdeadbeef);
7311     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7312         0, win_event_proc, 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
7313     ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
7314     ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
7315     }
7316
7317     SetLastError(0xdeadbeef);
7318     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(0, 0,
7319         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7320     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
7321     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
7322     ret = pUnhookWinEvent(hwinevent_hook);
7323     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7324
7325 todo_wine {
7326     /* This call succeeds under win2k SP4, but fails under Wine.
7327        Does win2k test/use passed process id? */
7328     SetLastError(0xdeadbeef);
7329     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7330         0, win_event_proc, 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
7331     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
7332     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
7333     ret = pUnhookWinEvent(hwinevent_hook);
7334     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7335 }
7336
7337     SetLastError(0xdeadbeef);
7338     ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
7339     ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
7340         GetLastError() == 0xdeadbeef, /* Win9x */
7341         "unexpected error %d\n", GetLastError());
7342 }
7343
7344 static const struct message ScrollWindowPaint1[] = {
7345     { WM_PAINT, sent },
7346     { WM_ERASEBKGND, sent|beginpaint },
7347     { 0 }
7348 };
7349
7350 static const struct message ScrollWindowPaint2[] = {
7351     { WM_PAINT, sent },
7352     { 0 }
7353 };
7354
7355 static void test_scrollwindowex(void)
7356 {
7357     HWND hwnd, hchild;
7358     RECT rect={0,0,130,130};
7359
7360     hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
7361             WS_VISIBLE|WS_OVERLAPPEDWINDOW,
7362             100, 100, 200, 200, 0, 0, 0, NULL);
7363     ok (hwnd != 0, "Failed to create overlapped window\n");
7364     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", 
7365             WS_VISIBLE|WS_CAPTION|WS_CHILD,
7366             10, 10, 150, 150, hwnd, 0, 0, NULL);
7367     ok (hchild != 0, "Failed to create child\n");
7368     UpdateWindow(hwnd);
7369     flush_events();
7370     flush_sequence();
7371
7372     /* scroll without the child window */
7373     trace("start scroll\n");
7374     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
7375             SW_ERASE|SW_INVALIDATE);
7376     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7377     trace("end scroll\n");
7378     flush_sequence();
7379     flush_events();
7380     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
7381     flush_events();
7382     flush_sequence();
7383
7384     /* Now without the SW_ERASE flag */
7385     trace("start scroll\n");
7386     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
7387     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7388     trace("end scroll\n");
7389     flush_sequence();
7390     flush_events();
7391     ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
7392     flush_events();
7393     flush_sequence();
7394
7395     /* now scroll the child window as well */
7396     trace("start scroll\n");
7397     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
7398             SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
7399     todo_wine { /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
7400                 /* windows sometimes a WM_MOVE */
7401         ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7402     }
7403     trace("end scroll\n");
7404     flush_sequence();
7405     flush_events();
7406     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
7407     flush_events();
7408     flush_sequence();
7409
7410     /* now scroll with ScrollWindow() */
7411     trace("start scroll with ScrollWindow\n");
7412     ScrollWindow( hwnd, 5, 5, NULL, NULL);
7413     trace("end scroll\n");
7414     flush_sequence();
7415     flush_events();
7416     ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
7417
7418     ok(DestroyWindow(hchild), "failed to destroy window\n");
7419     ok(DestroyWindow(hwnd), "failed to destroy window\n");
7420     flush_sequence();
7421 }
7422
7423 static const struct message destroy_window_with_children[] = {
7424     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
7425     { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
7426     { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
7427     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
7428     { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7429     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7430     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7431     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
7432     { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
7433     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
7434     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
7435     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
7436     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
7437     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
7438     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
7439     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
7440     { 0 }
7441 };
7442
7443 static void test_DestroyWindow(void)
7444 {
7445     BOOL ret;
7446     HWND parent, child1, child2, child3, child4, test;
7447     UINT child_id = WND_CHILD_ID + 1;
7448
7449     parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
7450                              100, 100, 200, 200, 0, 0, 0, NULL);
7451     assert(parent != 0);
7452     child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7453                              0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
7454     assert(child1 != 0);
7455     child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7456                              0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
7457     assert(child2 != 0);
7458     child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7459                              0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
7460     assert(child3 != 0);
7461     child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
7462                              0, 0, 50, 50, parent, 0, 0, NULL);
7463     assert(child4 != 0);
7464
7465     /* test owner/parent of child2 */
7466     test = GetParent(child2);
7467     ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7468     ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
7469     if(pGetAncestor) {
7470         test = pGetAncestor(child2, GA_PARENT);
7471         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7472     }
7473     test = GetWindow(child2, GW_OWNER);
7474     ok(!test, "wrong owner %p\n", test);
7475
7476     test = SetParent(child2, parent);
7477     ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
7478
7479     /* test owner/parent of the parent */
7480     test = GetParent(parent);
7481     ok(!test, "wrong parent %p\n", test);
7482     ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
7483     if(pGetAncestor) {
7484         test = pGetAncestor(parent, GA_PARENT);
7485         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7486     }
7487     test = GetWindow(parent, GW_OWNER);
7488     ok(!test, "wrong owner %p\n", test);
7489
7490     /* test owner/parent of child1 */
7491     test = GetParent(child1);
7492     ok(test == parent, "wrong parent %p\n", test);
7493     ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
7494     if(pGetAncestor) {
7495         test = pGetAncestor(child1, GA_PARENT);
7496         ok(test == parent, "wrong parent %p\n", test);
7497     }
7498     test = GetWindow(child1, GW_OWNER);
7499     ok(!test, "wrong owner %p\n", test);
7500
7501     /* test owner/parent of child2 */
7502     test = GetParent(child2);
7503     ok(test == parent, "wrong parent %p\n", test);
7504     ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
7505     if(pGetAncestor) {
7506         test = pGetAncestor(child2, GA_PARENT);
7507         ok(test == parent, "wrong parent %p\n", test);
7508     }
7509     test = GetWindow(child2, GW_OWNER);
7510     ok(!test, "wrong owner %p\n", test);
7511
7512     /* test owner/parent of child3 */
7513     test = GetParent(child3);
7514     ok(test == child1, "wrong parent %p\n", test);
7515     ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
7516     if(pGetAncestor) {
7517         test = pGetAncestor(child3, GA_PARENT);
7518         ok(test == child1, "wrong parent %p\n", test);
7519     }
7520     test = GetWindow(child3, GW_OWNER);
7521     ok(!test, "wrong owner %p\n", test);
7522
7523     /* test owner/parent of child4 */
7524     test = GetParent(child4);
7525     ok(test == parent, "wrong parent %p\n", test);
7526     ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
7527     if(pGetAncestor) {
7528         test = pGetAncestor(child4, GA_PARENT);
7529         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7530     }
7531     test = GetWindow(child4, GW_OWNER);
7532     ok(test == parent, "wrong owner %p\n", test);
7533
7534     flush_sequence();
7535
7536     trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
7537            parent, child1, child2, child3, child4);
7538
7539     SetCapture(child4);
7540     test = GetCapture();
7541     ok(test == child4, "wrong capture window %p\n", test);
7542
7543     test_DestroyWindow_flag = TRUE;
7544     ret = DestroyWindow(parent);
7545     ok( ret, "DestroyWindow() error %d\n", GetLastError());
7546     test_DestroyWindow_flag = FALSE;
7547     ok_sequence(destroy_window_with_children, "destroy window with children", 0);
7548
7549     ok(!IsWindow(parent), "parent still exists\n");
7550     ok(!IsWindow(child1), "child1 still exists\n");
7551     ok(!IsWindow(child2), "child2 still exists\n");
7552     ok(!IsWindow(child3), "child3 still exists\n");
7553     ok(!IsWindow(child4), "child4 still exists\n");
7554
7555     test = GetCapture();
7556     ok(!test, "wrong capture window %p\n", test);
7557 }
7558
7559
7560 static const struct message WmDispatchPaint[] = {
7561     { WM_NCPAINT, sent },
7562     { WM_GETTEXT, sent|defwinproc|optional },
7563     { WM_GETTEXT, sent|defwinproc|optional },
7564     { WM_ERASEBKGND, sent },
7565     { 0 }
7566 };
7567
7568 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7569 {
7570     if (message == WM_PAINT) return 0;
7571     return MsgCheckProcA( hwnd, message, wParam, lParam );
7572 }
7573
7574 static void test_DispatchMessage(void)
7575 {
7576     RECT rect;
7577     MSG msg;
7578     int count;
7579     HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
7580                                100, 100, 200, 200, 0, 0, 0, NULL);
7581     ShowWindow( hwnd, SW_SHOW );
7582     UpdateWindow( hwnd );
7583     flush_events();
7584     flush_sequence();
7585     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
7586
7587     SetRect( &rect, -5, -5, 5, 5 );
7588     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
7589     count = 0;
7590     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
7591     {
7592         if (msg.message != WM_PAINT) DispatchMessage( &msg );
7593         else
7594         {
7595             flush_sequence();
7596             DispatchMessage( &msg );
7597             /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
7598             if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
7599             else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
7600             if (++count > 10) break;
7601         }
7602     }
7603     ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
7604
7605     trace("now without DispatchMessage\n");
7606     flush_sequence();
7607     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
7608     count = 0;
7609     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
7610     {
7611         if (msg.message != WM_PAINT) DispatchMessage( &msg );
7612         else
7613         {
7614             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
7615             flush_sequence();
7616             /* this will send WM_NCCPAINT just like DispatchMessage does */
7617             GetUpdateRgn( hwnd, hrgn, TRUE );
7618             ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
7619             DeleteObject( hrgn );
7620             GetClientRect( hwnd, &rect );
7621             ValidateRect( hwnd, &rect );  /* this will stop WM_PAINTs */
7622             ok( !count, "Got multiple WM_PAINTs\n" );
7623             if (++count > 10) break;
7624         }
7625     }
7626     DestroyWindow(hwnd);
7627 }
7628
7629
7630 static const struct message WmUser[] = {
7631     { WM_USER, sent },
7632     { 0 }
7633 };
7634
7635 struct sendmsg_info
7636 {
7637     HWND  hwnd;
7638     DWORD timeout;
7639     DWORD ret;
7640 };
7641
7642 static DWORD CALLBACK send_msg_thread( LPVOID arg )
7643 {
7644     struct sendmsg_info *info = arg;
7645     info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
7646     if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT, "unexpected error %d\n", GetLastError());
7647     return 0;
7648 }
7649
7650 static void wait_for_thread( HANDLE thread )
7651 {
7652     while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
7653     {
7654         MSG msg;
7655         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
7656     }
7657 }
7658
7659 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7660 {
7661     if (message == WM_USER) Sleep(200);
7662     return MsgCheckProcA( hwnd, message, wParam, lParam );
7663 }
7664
7665 static void test_SendMessageTimeout(void)
7666 {
7667     HANDLE thread;
7668     struct sendmsg_info info;
7669     DWORD tid;
7670
7671     info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
7672                                100, 100, 200, 200, 0, 0, 0, NULL);
7673     flush_events();
7674     flush_sequence();
7675
7676     info.timeout = 1000;
7677     info.ret = 0xdeadbeef;
7678     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7679     wait_for_thread( thread );
7680     CloseHandle( thread );
7681     ok( info.ret == 1, "SendMessageTimeout failed\n" );
7682     ok_sequence( WmUser, "WmUser", FALSE );
7683
7684     info.timeout = 1;
7685     info.ret = 0xdeadbeef;
7686     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7687     Sleep(100);  /* SendMessageTimeout should timeout here */
7688     wait_for_thread( thread );
7689     CloseHandle( thread );
7690     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
7691     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
7692
7693     /* 0 means infinite timeout */
7694     info.timeout = 0;
7695     info.ret = 0xdeadbeef;
7696     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7697     Sleep(100);
7698     wait_for_thread( thread );
7699     CloseHandle( thread );
7700     ok( info.ret == 1, "SendMessageTimeout failed\n" );
7701     ok_sequence( WmUser, "WmUser", FALSE );
7702
7703     /* timeout is treated as signed despite the prototype */
7704     info.timeout = 0x7fffffff;
7705     info.ret = 0xdeadbeef;
7706     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7707     Sleep(100);
7708     wait_for_thread( thread );
7709     CloseHandle( thread );
7710     ok( info.ret == 1, "SendMessageTimeout failed\n" );
7711     ok_sequence( WmUser, "WmUser", FALSE );
7712
7713     info.timeout = 0x80000000;
7714     info.ret = 0xdeadbeef;
7715     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7716     Sleep(100);
7717     wait_for_thread( thread );
7718     CloseHandle( thread );
7719     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
7720     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
7721
7722     /* now check for timeout during message processing */
7723     SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
7724     info.timeout = 100;
7725     info.ret = 0xdeadbeef;
7726     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
7727     wait_for_thread( thread );
7728     CloseHandle( thread );
7729     /* we should timeout but still get the message */
7730     ok( info.ret == 0, "SendMessageTimeout failed\n" );
7731     ok_sequence( WmUser, "WmUser", FALSE );
7732
7733     DestroyWindow( info.hwnd );
7734 }
7735
7736
7737 /****************** edit message test *************************/
7738 #define ID_EDIT 0x1234
7739 static const struct message sl_edit_setfocus[] =
7740 {
7741     { HCBT_SETFOCUS, hook },
7742     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
7743     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
7744     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7745     { WM_SETFOCUS, sent|wparam, 0 },
7746     { WM_CTLCOLOREDIT, sent|parent },
7747     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7748     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7749     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
7750     { 0 }
7751 };
7752 static const struct message ml_edit_setfocus[] =
7753 {
7754     { HCBT_SETFOCUS, hook },
7755     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
7756     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
7757     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7758     { WM_SETFOCUS, sent|wparam, 0 },
7759     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7760     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7761     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7762     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
7763     { 0 }
7764 };
7765 static const struct message sl_edit_killfocus[] =
7766 {
7767     { HCBT_SETFOCUS, hook },
7768     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7769     { WM_KILLFOCUS, sent|wparam, 0 },
7770     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7771     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7772     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
7773     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
7774     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
7775     { 0 }
7776 };
7777 static const struct message sl_edit_lbutton_dblclk[] =
7778 {
7779     { WM_LBUTTONDBLCLK, sent },
7780     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7781     { 0 }
7782 };
7783 static const struct message sl_edit_lbutton_down[] =
7784 {
7785     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
7786     { HCBT_SETFOCUS, hook },
7787     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
7788     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
7789     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7790     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
7791     { WM_CTLCOLOREDIT, sent|parent },
7792     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7793     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7794     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7795     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
7796     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7797     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7798     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7799     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7800     { 0 }
7801 };
7802 static const struct message ml_edit_lbutton_down[] =
7803 {
7804     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
7805     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7806     { HCBT_SETFOCUS, hook },
7807     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
7808     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
7809     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
7810     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
7811     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7812     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7813     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
7814     { 0 }
7815 };
7816 static const struct message sl_edit_lbutton_up[] =
7817 {
7818     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
7819     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7820     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
7821     { WM_CAPTURECHANGED, sent|defwinproc },
7822     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
7823     { 0 }
7824 };
7825 static const struct message ml_edit_lbutton_up[] =
7826 {
7827     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
7828     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
7829     { WM_CAPTURECHANGED, sent|defwinproc },
7830     { 0 }
7831 };
7832
7833 static WNDPROC old_edit_proc;
7834
7835 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7836 {
7837     static long defwndproc_counter = 0;
7838     LRESULT ret;
7839     struct message msg;
7840
7841     trace("edit: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
7842
7843     /* explicitly ignore WM_GETICON message */
7844     if (message == WM_GETICON) return 0;
7845
7846     msg.message = message;
7847     msg.flags = sent|wparam|lparam;
7848     if (defwndproc_counter) msg.flags |= defwinproc;
7849     msg.wParam = wParam;
7850     msg.lParam = lParam;
7851     add_message(&msg);
7852
7853     defwndproc_counter++;
7854     ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
7855     defwndproc_counter--;
7856
7857     return ret;
7858 }
7859
7860 static void subclass_edit(void)
7861 {
7862     WNDCLASSA cls;
7863
7864     if (!GetClassInfoA(0, "edit", &cls)) assert(0);
7865
7866     old_edit_proc = cls.lpfnWndProc;
7867
7868     cls.hInstance = GetModuleHandle(0);
7869     cls.lpfnWndProc = edit_hook_proc;
7870     cls.lpszClassName = "my_edit_class";
7871     UnregisterClass(cls.lpszClassName, cls.hInstance);
7872     if (!RegisterClassA(&cls)) assert(0);
7873 }
7874
7875 static void test_edit_messages(void)
7876 {
7877     HWND hwnd, parent;
7878     DWORD dlg_code;
7879
7880     subclass_edit();
7881     log_all_parent_messages++;
7882
7883     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7884                              100, 100, 200, 200, 0, 0, 0, NULL);
7885     ok (parent != 0, "Failed to create parent window\n");
7886
7887     /* test single line edit */
7888     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
7889                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
7890     ok(hwnd != 0, "Failed to create edit window\n");
7891
7892     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
7893     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
7894
7895     ShowWindow(hwnd, SW_SHOW);
7896     UpdateWindow(hwnd);
7897     SetFocus(0);
7898     flush_sequence();
7899
7900     SetFocus(hwnd);
7901     ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
7902
7903     SetFocus(0);
7904     ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
7905
7906     SetFocus(0);
7907     ReleaseCapture();
7908     flush_sequence();
7909
7910     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
7911     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
7912
7913     SetFocus(0);
7914     ReleaseCapture();
7915     flush_sequence();
7916
7917     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
7918     ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
7919
7920     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
7921     ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
7922
7923     DestroyWindow(hwnd);
7924
7925     /* test multiline edit */
7926     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
7927                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
7928     ok(hwnd != 0, "Failed to create edit window\n");
7929
7930     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
7931     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
7932        "wrong dlg_code %08x\n", dlg_code);
7933
7934     ShowWindow(hwnd, SW_SHOW);
7935     UpdateWindow(hwnd);
7936     SetFocus(0);
7937     flush_sequence();
7938
7939     SetFocus(hwnd);
7940     ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
7941
7942     SetFocus(0);
7943     ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
7944
7945     SetFocus(0);
7946     ReleaseCapture();
7947     flush_sequence();
7948
7949     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
7950     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
7951
7952     SetFocus(0);
7953     ReleaseCapture();
7954     flush_sequence();
7955
7956     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
7957     ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
7958
7959     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
7960     ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
7961
7962     DestroyWindow(hwnd);
7963     DestroyWindow(parent);
7964
7965     log_all_parent_messages--;
7966 }
7967
7968 /**************************** End of Edit test ******************************/
7969
7970 static const struct message WmKeyDownSkippedSeq[] =
7971 {
7972     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
7973     { 0 }
7974 };
7975 static const struct message WmKeyUpSkippedSeq[] =
7976 {
7977     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
7978     { 0 }
7979 };
7980
7981 #define EV_START_STOP 0
7982 #define EV_SENDMSG 1
7983 #define EV_ACK 2
7984
7985 struct peekmsg_info
7986 {
7987     HWND  hwnd;
7988     HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
7989 };
7990
7991 static DWORD CALLBACK send_msg_thread_2(void *param)
7992 {
7993     DWORD ret;
7994     struct peekmsg_info *info = param;
7995
7996     trace("thread: waiting for start\n");
7997     WaitForSingleObject(info->hevent[EV_START_STOP], INFINITE);
7998     trace("thread: looping\n");
7999
8000     while (1)
8001     {
8002         ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
8003
8004         switch (ret)
8005         {
8006         case WAIT_OBJECT_0 + EV_START_STOP:
8007             trace("thread: exiting\n");
8008             return 0;
8009
8010         case WAIT_OBJECT_0 + EV_SENDMSG:
8011             trace("thread: sending message\n");
8012             SendNotifyMessageA(info->hwnd, WM_USER, 0, 0);
8013             SetEvent(info->hevent[EV_ACK]);
8014             break;
8015
8016         default:
8017             trace("unexpected return: %04x\n", ret);
8018             assert(0);
8019             break;
8020         }
8021     }
8022     return 0;
8023 }
8024
8025 static void test_PeekMessage(void)
8026 {
8027     MSG msg;
8028     HANDLE hthread;
8029     DWORD tid, qstatus;
8030     UINT qs_all_input = QS_ALLINPUT;
8031     UINT qs_input = QS_INPUT;
8032     BOOL ret;
8033     struct peekmsg_info info;
8034
8035     info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8036                               100, 100, 200, 200, 0, 0, 0, NULL);
8037     assert(info.hwnd);
8038     ShowWindow(info.hwnd, SW_SHOW);
8039     UpdateWindow(info.hwnd);
8040     SetFocus(info.hwnd);
8041
8042     info.hevent[EV_START_STOP] = CreateEventA(NULL, 0, 0, NULL);
8043     info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
8044     info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
8045
8046     hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
8047     Sleep(100);
8048
8049     trace("signalling to start looping\n");
8050     SetEvent(info.hevent[EV_START_STOP]);
8051
8052     flush_events();
8053     flush_sequence();
8054
8055     SetLastError(0xdeadbeef);
8056     qstatus = GetQueueStatus(qs_all_input);
8057     if (GetLastError() == ERROR_INVALID_FLAGS)
8058     {
8059         trace("QS_RAWINPUT not supported on this platform\n");
8060         qs_all_input &= ~QS_RAWINPUT;
8061         qs_input &= ~QS_RAWINPUT;
8062     }
8063     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8064
8065     trace("signalling to send message\n");
8066     SetEvent(info.hevent[EV_SENDMSG]);
8067     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8068
8069     /* pass invalid QS_xxxx flags */
8070     SetLastError(0xdeadbeef);
8071     qstatus = GetQueueStatus(0xffffffff);
8072     ok(qstatus == 0, "GetQueueStatus should fail: %08x\n", qstatus);
8073     ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
8074
8075     qstatus = GetQueueStatus(qs_all_input);
8076     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
8077        "wrong qstatus %08x\n", qstatus);
8078
8079     msg.message = 0;
8080     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8081     ok(!ret,
8082        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8083         msg.message);
8084     ok_sequence(WmUser, "WmUser", FALSE);
8085
8086     qstatus = GetQueueStatus(qs_all_input);
8087     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8088
8089     keybd_event('N', 0, 0, 0);
8090     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
8091     qstatus = GetQueueStatus(qs_all_input);
8092     ok(qstatus == MAKELONG(QS_KEY, QS_KEY),
8093        "wrong qstatus %08x\n", qstatus);
8094
8095     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8096     qstatus = GetQueueStatus(qs_all_input);
8097     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8098        "wrong qstatus %08x\n", qstatus);
8099
8100     InvalidateRect(info.hwnd, NULL, FALSE);
8101     qstatus = GetQueueStatus(qs_all_input);
8102     ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8103        "wrong qstatus %08x\n", qstatus);
8104
8105     trace("signalling to send message\n");
8106     SetEvent(info.hevent[EV_SENDMSG]);
8107     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8108
8109     qstatus = GetQueueStatus(qs_all_input);
8110     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8111        "wrong qstatus %08x\n", qstatus);
8112
8113     msg.message = 0;
8114     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
8115     ok(!ret,
8116        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8117         msg.message);
8118     ok_sequence(WmUser, "WmUser", FALSE);
8119
8120     qstatus = GetQueueStatus(qs_all_input);
8121     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8122        "wrong qstatus %08x\n", qstatus);
8123
8124     trace("signalling to send message\n");
8125     SetEvent(info.hevent[EV_SENDMSG]);
8126     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8127
8128     qstatus = GetQueueStatus(qs_all_input);
8129     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8130        "wrong qstatus %08x\n", qstatus);
8131
8132     msg.message = 0;
8133     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8134     ok(!ret,
8135        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8136         msg.message);
8137     ok_sequence(WmUser, "WmUser", FALSE);
8138
8139     qstatus = GetQueueStatus(qs_all_input);
8140     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8141        "wrong qstatus %08x\n", qstatus);
8142
8143     msg.message = 0;
8144     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8145     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8146        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8147        ret, msg.message, msg.wParam);
8148     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8149
8150     qstatus = GetQueueStatus(qs_all_input);
8151     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
8152        "wrong qstatus %08x\n", qstatus);
8153
8154     msg.message = 0;
8155     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8156     ok(!ret,
8157        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8158         msg.message);
8159     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8160
8161     qstatus = GetQueueStatus(qs_all_input);
8162     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
8163        "wrong qstatus %08x\n", qstatus);
8164
8165     msg.message = 0;
8166     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
8167     ok(ret && msg.message == WM_PAINT,
8168        "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
8169     DispatchMessageA(&msg);
8170     ok_sequence(WmPaint, "WmPaint", FALSE);
8171
8172     qstatus = GetQueueStatus(qs_all_input);
8173     ok(qstatus == MAKELONG(0, QS_KEY),
8174        "wrong qstatus %08x\n", qstatus);
8175
8176     msg.message = 0;
8177     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
8178     ok(!ret,
8179        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8180         msg.message);
8181     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8182
8183     qstatus = GetQueueStatus(qs_all_input);
8184     ok(qstatus == MAKELONG(0, QS_KEY),
8185        "wrong qstatus %08x\n", qstatus);
8186
8187     trace("signalling to send message\n");
8188     SetEvent(info.hevent[EV_SENDMSG]);
8189     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8190
8191     qstatus = GetQueueStatus(qs_all_input);
8192     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
8193        "wrong qstatus %08x\n", qstatus);
8194
8195     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8196
8197     qstatus = GetQueueStatus(qs_all_input);
8198     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
8199        "wrong qstatus %08x\n", qstatus);
8200
8201     msg.message = 0;
8202     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
8203     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8204        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8205        ret, msg.message, msg.wParam);
8206     ok_sequence(WmUser, "WmUser", FALSE);
8207
8208     qstatus = GetQueueStatus(qs_all_input);
8209     ok(qstatus == MAKELONG(0, QS_KEY),
8210        "wrong qstatus %08x\n", qstatus);
8211
8212     msg.message = 0;
8213     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
8214     ok(!ret,
8215        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8216         msg.message);
8217     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8218
8219     qstatus = GetQueueStatus(qs_all_input);
8220     ok(qstatus == MAKELONG(0, QS_KEY),
8221        "wrong qstatus %08x\n", qstatus);
8222
8223     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8224
8225     qstatus = GetQueueStatus(qs_all_input);
8226     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8227        "wrong qstatus %08x\n", qstatus);
8228
8229     trace("signalling to send message\n");
8230     SetEvent(info.hevent[EV_SENDMSG]);
8231     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8232
8233     qstatus = GetQueueStatus(qs_all_input);
8234     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
8235        "wrong qstatus %08x\n", qstatus);
8236
8237     msg.message = 0;
8238     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
8239     ok(!ret,
8240        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8241         msg.message);
8242     ok_sequence(WmUser, "WmUser", FALSE);
8243
8244     qstatus = GetQueueStatus(qs_all_input);
8245     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
8246        "wrong qstatus %08x\n", qstatus);
8247
8248     msg.message = 0;
8249     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
8250         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
8251     else /* workaround for a missing QS_RAWINPUT support */
8252         ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
8253     ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
8254        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
8255        ret, msg.message, msg.wParam);
8256     ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
8257
8258     qstatus = GetQueueStatus(qs_all_input);
8259     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
8260        "wrong qstatus %08x\n", qstatus);
8261
8262     msg.message = 0;
8263     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
8264         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
8265     else /* workaround for a missing QS_RAWINPUT support */
8266         ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
8267     ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
8268        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
8269        ret, msg.message, msg.wParam);
8270     ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
8271
8272     qstatus = GetQueueStatus(qs_all_input);
8273     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8274        "wrong qstatus %08x\n", qstatus);
8275
8276     msg.message = 0;
8277     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
8278     ok(!ret,
8279        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8280         msg.message);
8281     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8282
8283     qstatus = GetQueueStatus(qs_all_input);
8284     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8285        "wrong qstatus %08x\n", qstatus);
8286
8287     msg.message = 0;
8288     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8289     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8290        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8291        ret, msg.message, msg.wParam);
8292     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8293
8294     qstatus = GetQueueStatus(qs_all_input);
8295     ok(qstatus == 0,
8296        "wrong qstatus %08x\n", qstatus);
8297
8298     msg.message = 0;
8299     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8300     ok(!ret,
8301        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8302         msg.message);
8303     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8304
8305     qstatus = GetQueueStatus(qs_all_input);
8306     ok(qstatus == 0,
8307        "wrong qstatus %08x\n", qstatus);
8308
8309     /* test whether presence of the quit flag in the queue affects
8310      * the queue state
8311      */
8312     PostQuitMessage(0x1234abcd);
8313
8314     qstatus = GetQueueStatus(qs_all_input);
8315     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
8316        "wrong qstatus %08x\n", qstatus);
8317
8318     PostMessageA(info.hwnd, WM_USER, 0, 0);
8319
8320     qstatus = GetQueueStatus(qs_all_input);
8321     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
8322        "wrong qstatus %08x\n", qstatus);
8323
8324     msg.message = 0;
8325     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8326     ok(ret && msg.message == WM_USER,
8327        "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
8328     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8329
8330     qstatus = GetQueueStatus(qs_all_input);
8331     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8332        "wrong qstatus %08x\n", qstatus);
8333
8334     msg.message = 0;
8335     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8336     ok(ret && msg.message == WM_QUIT,
8337        "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
8338     ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
8339     ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
8340     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8341
8342     qstatus = GetQueueStatus(qs_all_input);
8343 todo_wine {
8344     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8345        "wrong qstatus %08x\n", qstatus);
8346 }
8347
8348     msg.message = 0;
8349     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8350     ok(!ret,
8351        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8352         msg.message);
8353     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8354
8355     qstatus = GetQueueStatus(qs_all_input);
8356     ok(qstatus == 0,
8357        "wrong qstatus %08x\n", qstatus);
8358
8359     trace("signalling to exit\n");
8360     SetEvent(info.hevent[EV_START_STOP]);
8361
8362     WaitForSingleObject(hthread, INFINITE);
8363
8364     CloseHandle(hthread);
8365     CloseHandle(info.hevent[0]);
8366     CloseHandle(info.hevent[1]);
8367     CloseHandle(info.hevent[2]);
8368
8369     DestroyWindow(info.hwnd);
8370 }
8371
8372
8373 static void test_quit_message(void)
8374 {
8375     MSG msg;
8376     BOOL ret;
8377
8378     /* test using PostQuitMessage */
8379     PostQuitMessage(0xbeef);
8380
8381     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
8382     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
8383     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8384     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
8385
8386     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
8387     ok(ret, "PostMessage failed with error %d\n", GetLastError());
8388
8389     ret = GetMessage(&msg, NULL, 0, 0);
8390     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
8391     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
8392
8393     /* note: WM_QUIT message received after WM_USER message */
8394     ret = GetMessage(&msg, NULL, 0, 0);
8395     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
8396     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8397     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
8398
8399     ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
8400     ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
8401
8402     /* now test with PostThreadMessage - different behaviour! */
8403     PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
8404
8405     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
8406     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
8407     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8408     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
8409
8410     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
8411     ok(ret, "PostMessage failed with error %d\n", GetLastError());
8412
8413     /* note: we receive the WM_QUIT message first this time */
8414     ret = GetMessage(&msg, NULL, 0, 0);
8415     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
8416     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8417     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
8418
8419     ret = GetMessage(&msg, NULL, 0, 0);
8420     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
8421     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
8422 }
8423
8424 static const struct message WmMouseHoverSeq[] = {
8425     { WM_MOUSEACTIVATE, sent|optional },  /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
8426     { WM_MOUSEACTIVATE, sent|optional },
8427     { WM_TIMER, sent|optional }, /* XP sends it */
8428     { WM_SYSTIMER, sent },
8429     { WM_MOUSEHOVER, sent|wparam, 0 },
8430     { 0 }
8431 };
8432
8433 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
8434 {
8435     MSG msg;
8436     DWORD start_ticks, end_ticks;
8437
8438     start_ticks = GetTickCount();
8439     /* add some deviation (5%) to cover not expected delays */
8440     start_ticks += timeout / 20;
8441
8442     do
8443     {
8444         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
8445         {
8446             /* Timer proc messages are not dispatched to the window proc,
8447              * and therefore not logged.
8448              */
8449             if (msg.message == WM_TIMER || msg.message == WM_SYSTIMER)
8450             {
8451                 struct message s_msg;
8452
8453                 s_msg.message = msg.message;
8454                 s_msg.flags = sent|wparam|lparam;
8455                 s_msg.wParam = msg.wParam;
8456                 s_msg.lParam = msg.lParam;
8457                 add_message(&s_msg);
8458             }
8459             DispatchMessage(&msg);
8460         }
8461
8462         end_ticks = GetTickCount();
8463
8464         /* inject WM_MOUSEMOVE to see how it changes tracking */
8465         if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
8466         {
8467             mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8468             mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8469
8470             inject_mouse_move = FALSE;
8471         }
8472     } while (start_ticks + timeout >= end_ticks);
8473 }
8474
8475 static void test_TrackMouseEvent(void)
8476 {
8477     TRACKMOUSEEVENT tme;
8478     BOOL ret;
8479     HWND hwnd, hchild;
8480     RECT rc_parent, rc_child;
8481     UINT default_hover_time, hover_width = 0, hover_height = 0;
8482
8483 #define track_hover(track_hwnd, track_hover_time) \
8484     tme.cbSize = sizeof(tme); \
8485     tme.dwFlags = TME_HOVER; \
8486     tme.hwndTrack = track_hwnd; \
8487     tme.dwHoverTime = track_hover_time; \
8488     SetLastError(0xdeadbeef); \
8489     ret = pTrackMouseEvent(&tme); \
8490     ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
8491
8492 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
8493     tme.cbSize = sizeof(tme); \
8494     tme.dwFlags = TME_QUERY; \
8495     tme.hwndTrack = (HWND)0xdeadbeef; \
8496     tme.dwHoverTime = 0xdeadbeef; \
8497     SetLastError(0xdeadbeef); \
8498     ret = pTrackMouseEvent(&tme); \
8499     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
8500     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
8501     ok(tme.dwFlags == (expected_track_flags), \
8502        "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
8503     ok(tme.hwndTrack == (expected_track_hwnd), \
8504        "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
8505     ok(tme.dwHoverTime == (expected_hover_time), \
8506        "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
8507
8508 #define track_hover_cancel(track_hwnd) \
8509     tme.cbSize = sizeof(tme); \
8510     tme.dwFlags = TME_HOVER | TME_CANCEL; \
8511     tme.hwndTrack = track_hwnd; \
8512     tme.dwHoverTime = 0xdeadbeef; \
8513     SetLastError(0xdeadbeef); \
8514     ret = pTrackMouseEvent(&tme); \
8515     ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
8516
8517     default_hover_time = 0xdeadbeef;
8518     SetLastError(0xdeadbeef);
8519     ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
8520     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
8521     if (!ret) default_hover_time = 400;
8522     trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
8523
8524     SetLastError(0xdeadbeef);
8525     ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
8526     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
8527     if (!ret) hover_width = 4;
8528     SetLastError(0xdeadbeef);
8529     ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
8530     ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
8531     if (!ret) hover_height = 4;
8532     trace("hover rect is %u x %d\n", hover_width, hover_height);
8533
8534     hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
8535                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8536                           CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8537                           NULL, NULL, 0);
8538     assert(hwnd);
8539
8540     hchild = CreateWindowEx(0, "TestWindowClass", NULL,
8541                           WS_CHILD | WS_BORDER | WS_VISIBLE,
8542                           50, 50, 200, 200, hwnd,
8543                           NULL, NULL, 0);
8544     assert(hchild);
8545
8546     flush_events();
8547     flush_sequence();
8548
8549     tme.cbSize = 0;
8550     tme.dwFlags = TME_QUERY;
8551     tme.hwndTrack = (HWND)0xdeadbeef;
8552     tme.dwHoverTime = 0xdeadbeef;
8553     SetLastError(0xdeadbeef);
8554     ret = pTrackMouseEvent(&tme);
8555     ok(!ret, "TrackMouseEvent should fail\n");
8556     ok(GetLastError() == ERROR_INVALID_PARAMETER, "not expected error %d\n", GetLastError());
8557
8558     tme.cbSize = sizeof(tme);
8559     tme.dwFlags = TME_HOVER;
8560     tme.hwndTrack = (HWND)0xdeadbeef;
8561     tme.dwHoverTime = 0xdeadbeef;
8562     SetLastError(0xdeadbeef);
8563     ret = pTrackMouseEvent(&tme);
8564     ok(!ret, "TrackMouseEvent should fail\n");
8565     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "not expected error %d\n", GetLastError());
8566
8567     tme.cbSize = sizeof(tme);
8568     tme.dwFlags = TME_HOVER | TME_CANCEL;
8569     tme.hwndTrack = (HWND)0xdeadbeef;
8570     tme.dwHoverTime = 0xdeadbeef;
8571     SetLastError(0xdeadbeef);
8572     ret = pTrackMouseEvent(&tme);
8573     ok(!ret, "TrackMouseEvent should fail\n");
8574     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "not expected error %d\n", GetLastError());
8575
8576     GetWindowRect(hwnd, &rc_parent);
8577     GetWindowRect(hchild, &rc_child);
8578     SetCursorPos(rc_child.left - 10, rc_child.top - 10);
8579
8580     /* Process messages so that the system updates its internal current
8581      * window and hittest, otherwise TrackMouseEvent calls don't have any
8582      * effect.
8583      */
8584     flush_events();
8585     flush_sequence();
8586
8587     track_query(0, NULL, 0);
8588     track_hover(hchild, 0);
8589     track_query(0, NULL, 0);
8590
8591     flush_events();
8592     flush_sequence();
8593
8594     track_hover(hwnd, 0);
8595     track_query(TME_HOVER, hwnd, default_hover_time);
8596
8597     pump_msg_loop_timeout(default_hover_time, FALSE);
8598     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
8599
8600     track_query(0, NULL, 0);
8601
8602     track_hover(hwnd, HOVER_DEFAULT);
8603     track_query(TME_HOVER, hwnd, default_hover_time);
8604
8605     Sleep(default_hover_time / 2);
8606     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8607     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8608
8609     track_query(TME_HOVER, hwnd, default_hover_time);
8610
8611     pump_msg_loop_timeout(default_hover_time / 2, FALSE);
8612     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
8613
8614     track_query(0, NULL, 0);
8615
8616     track_hover(hwnd, HOVER_DEFAULT);
8617     track_query(TME_HOVER, hwnd, default_hover_time);
8618
8619     pump_msg_loop_timeout(default_hover_time, TRUE);
8620     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
8621
8622     track_query(0, NULL, 0);
8623
8624     track_hover(hwnd, HOVER_DEFAULT);
8625     track_query(TME_HOVER, hwnd, default_hover_time);
8626     track_hover_cancel(hwnd);
8627
8628     DestroyWindow(hwnd);
8629
8630 #undef track_hover
8631 #undef track_query
8632 #undef track_hover_cancel
8633 }
8634
8635
8636 static const struct message WmSetWindowRgn[] = {
8637     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
8638     { WM_NCCALCSIZE, sent|wparam, 1 },
8639     { WM_NCPAINT, sent }, /* wparam != 1 */
8640     { WM_GETTEXT, sent|defwinproc|optional },
8641     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
8642     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
8643     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
8644     { 0 }
8645 };
8646
8647 static const struct message WmSetWindowRgn_no_redraw[] = {
8648     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
8649     { WM_NCCALCSIZE, sent|wparam, 1 },
8650     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
8651     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
8652     { 0 }
8653 };
8654
8655 static const struct message WmSetWindowRgn_clear[] = {
8656     { 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 */
8657     { WM_NCCALCSIZE, sent|wparam, 1 },
8658     { WM_NCPAINT, sent }, /* wparam != 1 */
8659     { WM_GETTEXT, sent|defwinproc|optional },
8660     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
8661     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
8662     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
8663     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
8664     { WM_GETTEXT, sent|defwinproc|optional },
8665     { WM_ERASEBKGND, sent|optional },
8666     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
8667     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
8668     { 0 }
8669 };
8670
8671 static void test_SetWindowRgn(void)
8672 {
8673     HRGN hrgn;
8674     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
8675                                 100, 100, 200, 200, 0, 0, 0, NULL);
8676     ok( hwnd != 0, "Failed to create overlapped window\n" );
8677
8678     ShowWindow( hwnd, SW_SHOW );
8679     UpdateWindow( hwnd );
8680     flush_events();
8681     flush_sequence();
8682
8683     trace("testing SetWindowRgn\n");
8684     hrgn = CreateRectRgn( 0, 0, 150, 150 );
8685     SetWindowRgn( hwnd, hrgn, TRUE );
8686     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
8687
8688     hrgn = CreateRectRgn( 30, 30, 160, 160 );
8689     SetWindowRgn( hwnd, hrgn, FALSE );
8690     ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
8691
8692     hrgn = CreateRectRgn( 0, 0, 180, 180 );
8693     SetWindowRgn( hwnd, hrgn, TRUE );
8694     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
8695
8696     SetWindowRgn( hwnd, 0, TRUE );
8697     ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
8698
8699     DestroyWindow( hwnd );
8700 }
8701
8702 /*************************** ShowWindow() test ******************************/
8703 static const struct message WmShowNormal[] = {
8704     { WM_SHOWWINDOW, sent|wparam, 1 },
8705     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
8706     { HCBT_ACTIVATE, hook },
8707     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
8708     { HCBT_SETFOCUS, hook },
8709     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8710     { 0 }
8711 };
8712 static const struct message WmShow[] = {
8713     { WM_SHOWWINDOW, sent|wparam, 1 },
8714     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
8715     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
8716     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
8717     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
8718     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8719     { 0 }
8720 };
8721 static const struct message WmShowNoActivate_1[] = {
8722     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
8723     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|0x8000 },
8724     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|0x8000 },
8725     { WM_MOVE, sent|defwinproc },
8726     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
8727     { 0 }
8728 };
8729 static const struct message WmShowNoActivate_2[] = {
8730     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
8731     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8732     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8733     { WM_MOVE, sent|defwinproc },
8734     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
8735     { HCBT_SETFOCUS, hook },
8736     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
8737     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
8738     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
8739     { 0 }
8740 };
8741 static const struct message WmShowNA_1[] = {
8742     { WM_SHOWWINDOW, sent|wparam, 1 },
8743     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
8744     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8745     { 0 }
8746 };
8747 static const struct message WmShowNA_2[] = {
8748     { WM_SHOWWINDOW, sent|wparam, 1 },
8749     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
8750     { 0 }
8751 };
8752 static const struct message WmRestore_1[] = {
8753     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
8754     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8755     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
8756     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
8757     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
8758     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8759     { WM_MOVE, sent|defwinproc },
8760     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
8761     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
8762     { 0 }
8763 };
8764 static const struct message WmRestore_2[] = {
8765     { WM_SHOWWINDOW, sent|wparam, 1 },
8766     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
8767     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8768     { 0 }
8769 };
8770 static const struct message WmRestore_3[] = {
8771     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
8772     { WM_GETMINMAXINFO, sent },
8773     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8774     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
8775     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
8776     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
8777     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8778     { WM_MOVE, sent|defwinproc },
8779     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
8780     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
8781     { 0 }
8782 };
8783 static const struct message WmRestore_4[] = {
8784     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
8785     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
8786     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|0x8000 },
8787     { WM_MOVE, sent|defwinproc },
8788     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
8789     { 0 }
8790 };
8791 static const struct message WmRestore_5[] = {
8792     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
8793     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
8794     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|0x8000 },
8795     { WM_MOVE, sent|defwinproc },
8796     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
8797     { 0 }
8798 };
8799 static const struct message WmHide_1[] = {
8800     { WM_SHOWWINDOW, sent|wparam, 0 },
8801     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
8802     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8803     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
8804     { 0 }
8805 };
8806 static const struct message WmHide_2[] = {
8807     { WM_SHOWWINDOW, sent|wparam, 0 },
8808     { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
8809     { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
8810     { 0 }
8811 };
8812 static const struct message WmHide_3[] = {
8813     { WM_SHOWWINDOW, sent|wparam, 0 },
8814     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
8815     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8816     { HCBT_SETFOCUS, hook },
8817     { 0 }
8818 };
8819 static const struct message WmShowMinimized_1[] = {
8820     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
8821     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8822     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
8823     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
8824     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8825     { WM_MOVE, sent|defwinproc },
8826     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
8827     { 0 }
8828 };
8829 static const struct message WmMinimize_1[] = {
8830     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
8831     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
8832     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8833     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8834     { WM_MOVE, sent|defwinproc },
8835     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
8836     { 0 }
8837 };
8838 static const struct message WmMinimize_2[] = {
8839     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
8840     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8841     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8842     { WM_MOVE, sent|defwinproc },
8843     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
8844     { 0 }
8845 };
8846 static const struct message WmMinimize_3[] = {
8847     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
8848     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8849     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8850     { WM_MOVE, sent|defwinproc },
8851     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
8852     { 0 }
8853 };
8854 static const struct message WmShowMinNoActivate[] = {
8855     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
8856     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
8857     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8858     { 0 }
8859 };
8860 static const struct message WmMinMax_1[] = {
8861     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
8862     { 0 }
8863 };
8864 static const struct message WmMinMax_2[] = {
8865     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
8866     { 0 }
8867 };
8868 static const struct message WmMinMax_3[] = {
8869     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
8870     { 0 }
8871 };
8872 static const struct message WmMinMax_4[] = {
8873     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
8874     { 0 }
8875 };
8876 static const struct message WmShowMaximized_1[] = {
8877     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
8878     { WM_GETMINMAXINFO, sent },
8879     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8880     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
8881     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
8882     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
8883     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8884     { WM_MOVE, sent|defwinproc },
8885     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
8886     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
8887     { 0 }
8888 };
8889 static const struct message WmShowMaximized_2[] = {
8890     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
8891     { WM_GETMINMAXINFO, sent },
8892     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
8893     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
8894     { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
8895     { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
8896     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8897     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|0x8000 },
8898     { WM_MOVE, sent|defwinproc },
8899     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
8900     { HCBT_SETFOCUS, hook },
8901     { 0 }
8902 };
8903 static const struct message WmShowMaximized_3[] = {
8904     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
8905     { WM_GETMINMAXINFO, sent },
8906     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
8907     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|0x8000 },
8908     { WM_MOVE, sent|defwinproc },
8909     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
8910     { 0 }
8911 };
8912
8913 static void test_ShowWindow(void)
8914 {
8915     /* ShowWindow commands in random order */
8916     static const struct
8917     {
8918         INT cmd; /* ShowWindow command */
8919         LPARAM ret; /* ShowWindow return value */
8920         DWORD style; /* window style after the command */
8921         const struct message *msg; /* message sequence the command produces */
8922         BOOL todo_msg; /* message sequence doesn't match what Wine does */
8923     } sw[] =
8924     {
8925 /*  1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
8926 /*  2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
8927 /*  3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
8928 /*  4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
8929 /*  5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
8930 /*  6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
8931 /*  7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
8932 /*  8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
8933 /*  9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
8934 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
8935 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
8936 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
8937 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
8938 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
8939 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
8940 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
8941 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
8942 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
8943 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, TRUE },
8944 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
8945 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
8946 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
8947 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
8948 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
8949 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
8950 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
8951 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
8952 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
8953 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
8954 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
8955 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
8956 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, TRUE },
8957 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
8958 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, TRUE }, /* what does this mean?! */
8959 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, TRUE },
8960 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
8961 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
8962 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
8963 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
8964 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, TRUE },
8965 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
8966 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, TRUE },
8967 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
8968 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, TRUE },
8969 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
8970 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
8971 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
8972 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
8973 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
8974 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
8975 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
8976 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
8977 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
8978 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, TRUE },
8979 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
8980 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
8981 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
8982     };
8983     HWND hwnd;
8984     DWORD style;
8985     LPARAM ret;
8986     INT i;
8987
8988 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
8989     hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
8990                           120, 120, 90, 90,
8991                           0, 0, 0, NULL);
8992     assert(hwnd);
8993
8994     style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
8995     ok(style == 0, "expected style 0, got %08x\n", style);
8996
8997     flush_events();
8998     flush_sequence();
8999
9000     for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
9001     {
9002         static const char * const sw_cmd_name[13] =
9003         {
9004             "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
9005             "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
9006             "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
9007             "SW_NORMALNA" /* 0xCC */
9008         };
9009         char comment[64];
9010         INT idx; /* index into the above array of names */
9011
9012         idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
9013
9014         style = GetWindowLong(hwnd, GWL_STYLE);
9015         trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
9016         ret = ShowWindow(hwnd, sw[i].cmd);
9017         ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
9018         style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
9019         ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
9020
9021         sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
9022         ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
9023
9024         flush_events();
9025         flush_sequence();
9026     }
9027
9028     DestroyWindow(hwnd);
9029 }
9030
9031 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9032 {
9033     struct message msg;
9034
9035     trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
9036
9037     switch (message)
9038     {
9039     case WM_WINDOWPOSCHANGING:
9040     case WM_WINDOWPOSCHANGED:
9041     {
9042         WINDOWPOS *winpos = (WINDOWPOS *)lParam;
9043
9044         trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
9045         trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
9046               winpos->hwnd, winpos->hwndInsertAfter,
9047               winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
9048         dump_winpos_flags(winpos->flags);
9049
9050         /* Log only documented flags, win2k uses 0x1000 and 0x2000
9051          * in the high word for internal purposes
9052          */
9053         wParam = winpos->flags & 0xffff;
9054         /* We are not interested in the flags that don't match under XP and Win9x */
9055         wParam &= ~(SWP_NOZORDER);
9056         break;
9057     }
9058
9059     /* explicitly ignore WM_GETICON message */
9060     case WM_GETICON:
9061         return 0;
9062     }
9063
9064     msg.message = message;
9065     msg.flags = sent|wparam|lparam;
9066     msg.wParam = wParam;
9067     msg.lParam = lParam;
9068     add_message(&msg);
9069
9070     /* calling DefDlgProc leads to a recursion under XP */
9071
9072     switch (message)
9073     {
9074     case WM_INITDIALOG:
9075     case WM_GETDLGCODE:
9076         return 0;
9077     }
9078     return 1;
9079 }
9080
9081 static const struct message WmDefDlgSetFocus_1[] = {
9082     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
9083     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
9084     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
9085     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
9086     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
9087     { HCBT_SETFOCUS, hook },
9088     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9089     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9090     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9091     { WM_SETFOCUS, sent|wparam, 0 },
9092     { WM_CTLCOLOREDIT, sent },
9093     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9094     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9095     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9096     { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
9097     { 0 }
9098 };
9099 static const struct message WmDefDlgSetFocus_2[] = {
9100     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
9101     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
9102     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
9103     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
9104     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
9105     { WM_CTLCOLOREDIT, sent|optional }, /* XP */
9106     { 0 }
9107 };
9108 /* Creation of a dialog */
9109 static const struct message WmCreateDialogParamSeq_1[] = {
9110     { HCBT_CREATEWND, hook },
9111     { WM_NCCREATE, sent },
9112     { WM_NCCALCSIZE, sent|wparam, 0 },
9113     { WM_CREATE, sent },
9114     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
9115     { WM_SIZE, sent|wparam, SIZE_RESTORED },
9116     { WM_MOVE, sent },
9117     { WM_SETFONT, sent },
9118     { WM_INITDIALOG, sent },
9119     { WM_CHANGEUISTATE, sent|optional },
9120     { 0 }
9121 };
9122 /* Creation of a dialog */
9123 static const struct message WmCreateDialogParamSeq_2[] = {
9124     { HCBT_CREATEWND, hook },
9125     { WM_NCCREATE, sent },
9126     { WM_NCCALCSIZE, sent|wparam, 0 },
9127     { WM_CREATE, sent },
9128     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
9129     { WM_SIZE, sent|wparam, SIZE_RESTORED },
9130     { WM_MOVE, sent },
9131     { WM_CHANGEUISTATE, sent|optional },
9132     { 0 }
9133 };
9134
9135 static void test_dialog_messages(void)
9136 {
9137     WNDCLASS cls;
9138     HWND hdlg, hedit1, hedit2, hfocus;
9139     LRESULT ret;
9140
9141 #define set_selection(hctl, start, end) \
9142     ret = SendMessage(hctl, EM_SETSEL, start, end); \
9143     ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
9144
9145 #define check_selection(hctl, start, end) \
9146     ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
9147     ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
9148
9149     subclass_edit();
9150
9151     hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
9152                           WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
9153                           0, 0, 100, 100, 0, 0, 0, NULL);
9154     ok(hdlg != 0, "Failed to create custom dialog window\n");
9155
9156     hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
9157                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
9158                            0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
9159     ok(hedit1 != 0, "Failed to create edit control\n");
9160     hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
9161                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
9162                            0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
9163     ok(hedit2 != 0, "Failed to create edit control\n");
9164
9165     SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
9166     SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
9167
9168     hfocus = GetFocus();
9169     ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
9170
9171     SetFocus(hedit2);
9172     hfocus = GetFocus();
9173     ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
9174
9175     check_selection(hedit1, 0, 0);
9176     check_selection(hedit2, 0, 0);
9177
9178     set_selection(hedit2, 0, -1);
9179     check_selection(hedit2, 0, 3);
9180
9181     SetFocus(0);
9182     hfocus = GetFocus();
9183     ok(hfocus == 0, "wrong focus %p\n", hfocus);
9184
9185     flush_sequence();
9186     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
9187     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
9188     ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
9189
9190     hfocus = GetFocus();
9191     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
9192
9193     check_selection(hedit1, 0, 5);
9194     check_selection(hedit2, 0, 3);
9195
9196     flush_sequence();
9197     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
9198     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
9199     ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
9200
9201     hfocus = GetFocus();
9202     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
9203
9204     check_selection(hedit1, 0, 5);
9205     check_selection(hedit2, 0, 3);
9206
9207     EndDialog(hdlg, 0);
9208     DestroyWindow(hedit1);
9209     DestroyWindow(hedit2);
9210     DestroyWindow(hdlg);
9211     flush_sequence();
9212
9213 #undef set_selection
9214 #undef check_selection
9215
9216     ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
9217     cls.lpszClassName = "MyDialogClass";
9218     cls.hInstance = GetModuleHandle(0);
9219     /* need a cast since a dlgproc is used as a wndproc */
9220     cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
9221     if (!RegisterClass(&cls)) assert(0);
9222
9223     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
9224     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
9225     ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
9226     EndDialog(hdlg, 0);
9227     DestroyWindow(hdlg);
9228     flush_sequence();
9229
9230     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
9231     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
9232     ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
9233     EndDialog(hdlg, 0);
9234     DestroyWindow(hdlg);
9235     flush_sequence();
9236
9237     UnregisterClass(cls.lpszClassName, cls.hInstance);
9238 }
9239
9240 static void test_nullCallback(void)
9241 {
9242     HWND hwnd;
9243
9244     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
9245                            100, 100, 200, 200, 0, 0, 0, NULL);
9246     ok (hwnd != 0, "Failed to create overlapped window\n");
9247
9248     SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
9249     flush_events();
9250     DestroyWindow(hwnd);
9251 }
9252
9253 static const struct message SetForegroundWindowSeq[] =
9254 {
9255     { WM_NCACTIVATE, sent|wparam, 0 },
9256     { WM_GETTEXT, sent|defwinproc|optional },
9257     { WM_ACTIVATE, sent|wparam, 0 },
9258     { WM_ACTIVATEAPP, sent|wparam, 0 },
9259     { WM_KILLFOCUS, sent },
9260     { 0 }
9261 };
9262
9263 static void test_SetForegroundWindow(void)
9264 {
9265     HWND hwnd;
9266
9267     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
9268                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9269                            100, 100, 200, 200, 0, 0, 0, NULL);
9270     ok (hwnd != 0, "Failed to create overlapped window\n");
9271     flush_sequence();
9272
9273     trace("SetForegroundWindow( 0 )\n");
9274     SetForegroundWindow( 0 );
9275     ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
9276     trace("SetForegroundWindow( GetDesktopWindow() )\n");
9277     SetForegroundWindow( GetDesktopWindow() );
9278     ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
9279                                         "foreground top level window", FALSE);
9280     trace("done\n");
9281
9282     DestroyWindow(hwnd);
9283 }
9284
9285 static void test_dbcs_wm_char(void)
9286 {
9287     BYTE dbch[2];
9288     WCHAR wch, bad_wch;
9289     HWND hwnd, hwnd2;
9290     MSG msg;
9291     DWORD time;
9292     POINT pt;
9293     DWORD_PTR res;
9294     CPINFOEXA cpinfo;
9295     UINT i, j, k;
9296     struct message wmCharSeq[2];
9297
9298     pGetCPInfoExA( CP_ACP, 0, &cpinfo );
9299     if (cpinfo.MaxCharSize != 2)
9300     {
9301         skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
9302         return;
9303     }
9304
9305     dbch[0] = dbch[1] = 0;
9306     wch = 0;
9307     bad_wch = cpinfo.UnicodeDefaultChar;
9308     for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
9309         for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
9310             for (k = 128; k <= 255; k++)
9311             {
9312                 char str[2];
9313                 WCHAR wstr[2];
9314                 str[0] = j;
9315                 str[1] = k;
9316                 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
9317                     WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
9318                     (BYTE)str[0] == j && (BYTE)str[1] == k &&
9319                     HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
9320                 {
9321                     dbch[0] = j;
9322                     dbch[1] = k;
9323                     wch = wstr[0];
9324                     break;
9325                 }
9326             }
9327
9328     if (!wch)
9329     {
9330         skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
9331         return;
9332     }
9333     trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
9334            dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
9335
9336     hwnd = CreateWindowExW(0, testWindowClassW, NULL,
9337                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
9338     hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
9339                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
9340     ok (hwnd != 0, "Failed to create overlapped window\n");
9341     ok (hwnd2 != 0, "Failed to create overlapped window\n");
9342     flush_sequence();
9343
9344     memset( wmCharSeq, 0, sizeof(wmCharSeq) );
9345     wmCharSeq[0].message = WM_CHAR;
9346     wmCharSeq[0].flags = sent|wparam;
9347     wmCharSeq[0].wParam = wch;
9348
9349     /* posted message */
9350     PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9351     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9352     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9353     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9354     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9355     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
9356     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9357
9358     /* posted thread message */
9359     PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
9360     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9361     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9362     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9363     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9364     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
9365     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9366
9367     /* sent message */
9368     flush_sequence();
9369     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9370     ok_sequence( WmEmptySeq, "no messages", FALSE );
9371     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9372     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9373     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9374
9375     /* sent message with timeout */
9376     flush_sequence();
9377     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
9378     ok_sequence( WmEmptySeq, "no messages", FALSE );
9379     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
9380     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9381     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9382
9383     /* sent message with timeout and callback */
9384     flush_sequence();
9385     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
9386     ok_sequence( WmEmptySeq, "no messages", FALSE );
9387     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
9388     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9389     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9390
9391     /* sent message with callback */
9392     flush_sequence();
9393     SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9394     ok_sequence( WmEmptySeq, "no messages", FALSE );
9395     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
9396     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9397     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9398
9399     /* direct window proc call */
9400     flush_sequence();
9401     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
9402     ok_sequence( WmEmptySeq, "no messages", FALSE );
9403     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
9404     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9405
9406     /* dispatch message */
9407     msg.hwnd = hwnd;
9408     msg.message = WM_CHAR;
9409     msg.wParam = dbch[0];
9410     msg.lParam = 0;
9411     DispatchMessageA( &msg );
9412     ok_sequence( WmEmptySeq, "no messages", FALSE );
9413     msg.wParam = dbch[1];
9414     DispatchMessageA( &msg );
9415     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9416
9417     /* window handle is irrelevant */
9418     flush_sequence();
9419     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
9420     ok_sequence( WmEmptySeq, "no messages", FALSE );
9421     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9422     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9423     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9424
9425     /* interleaved post and send */
9426     flush_sequence();
9427     PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
9428     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
9429     ok_sequence( WmEmptySeq, "no messages", FALSE );
9430     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9431     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9432     ok_sequence( WmEmptySeq, "no messages", FALSE );
9433     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9434     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9435     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
9436     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9437     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9438     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9439     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9440
9441     /* interleaved sent message and winproc */
9442     flush_sequence();
9443     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9444     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
9445     ok_sequence( WmEmptySeq, "no messages", FALSE );
9446     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9447     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9448     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
9449     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9450
9451     /* interleaved winproc and dispatch */
9452     msg.hwnd = hwnd;
9453     msg.message = WM_CHAR;
9454     msg.wParam = dbch[0];
9455     msg.lParam = 0;
9456     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
9457     DispatchMessageA( &msg );
9458     ok_sequence( WmEmptySeq, "no messages", FALSE );
9459     msg.wParam = dbch[1];
9460     DispatchMessageA( &msg );
9461     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9462     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
9463     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9464
9465     /* interleaved sends */
9466     flush_sequence();
9467     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9468     SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
9469     ok_sequence( WmEmptySeq, "no messages", FALSE );
9470     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
9471     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9472     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9473     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9474
9475     /* dbcs WM_CHAR */
9476     flush_sequence();
9477     SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
9478     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9479     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9480
9481     /* other char messages are not magic */
9482     PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
9483     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9484     ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
9485     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
9486     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9487     PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
9488     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9489     ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
9490     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
9491     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9492
9493     /* test retrieving messages */
9494
9495     PostMessageW( hwnd, WM_CHAR, wch, 0 );
9496     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9497     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9498     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9499     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9500     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9501     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9502     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9503     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9504     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9505
9506     /* message filters */
9507     PostMessageW( hwnd, WM_CHAR, wch, 0 );
9508     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9509     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9510     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9511     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9512     /* message id is filtered, hwnd is not */
9513     ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
9514     ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
9515     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9516     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9517     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9518     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9519
9520     /* mixing GetMessage and PostMessage */
9521     PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
9522     ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
9523     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9524     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9525     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9526     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
9527     time = msg.time;
9528     pt = msg.pt;
9529     ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
9530     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
9531     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9532     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9533     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9534     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
9535     ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
9536     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 );
9537     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9538
9539     /* without PM_REMOVE */
9540     PostMessageW( hwnd, WM_CHAR, wch, 0 );
9541     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "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     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
9546     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9547     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9548     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9549     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
9550     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9551     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9552     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9553     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
9554     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
9555     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9556     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
9557     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9558
9559     DestroyWindow(hwnd);
9560 }
9561
9562 START_TEST(msg)
9563 {
9564     BOOL ret;
9565     FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
9566
9567     init_procs();
9568
9569     if (!RegisterWindowClasses()) assert(0);
9570
9571     if (pSetWinEventHook)
9572     {
9573         hEvent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
9574                                                       GetModuleHandleA(0),
9575                                                       win_event_proc,
9576                                                       0,
9577                                                       GetCurrentThreadId(),
9578                                                       WINEVENT_INCONTEXT);
9579         assert(hEvent_hook);
9580
9581         if (pIsWinEventHookInstalled)
9582         {
9583             UINT event;
9584             for (event = EVENT_MIN; event <= EVENT_MAX; event++)
9585                 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
9586         }
9587     }
9588
9589     cbt_hook_thread_id = GetCurrentThreadId();
9590     hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
9591     assert(hCBT_hook);
9592
9593     test_winevents();
9594
9595     /* Fix message sequences before removing 4 lines below */
9596 #if 1
9597     if (pUnhookWinEvent && hEvent_hook)
9598     {
9599         ret = pUnhookWinEvent(hEvent_hook);
9600         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
9601         pUnhookWinEvent = 0;
9602     }
9603     hEvent_hook = 0;
9604 #endif
9605
9606     test_ShowWindow();
9607     test_PeekMessage();
9608     test_scrollwindowex();
9609     test_messages();
9610     test_showwindow();
9611     invisible_parent_tests();
9612     test_mdi_messages();
9613     test_button_messages();
9614     test_static_messages();
9615     test_paint_messages();
9616     test_interthread_messages();
9617     test_message_conversion();
9618     test_accelerators();
9619     test_timers();
9620     test_set_hook();
9621     test_DestroyWindow();
9622     test_DispatchMessage();
9623     test_SendMessageTimeout();
9624     test_edit_messages();
9625     test_quit_message();
9626
9627     if (!pTrackMouseEvent)
9628         skip("TrackMouseEvent is not available\n");
9629     else
9630         test_TrackMouseEvent();
9631
9632     test_SetWindowRgn();
9633     test_sys_menu();
9634     test_dialog_messages();
9635     test_nullCallback();
9636     test_SetForegroundWindow();
9637     test_dbcs_wm_char();
9638
9639     UnhookWindowsHookEx(hCBT_hook);
9640     if (pUnhookWinEvent)
9641     {
9642         ret = pUnhookWinEvent(hEvent_hook);
9643         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
9644         SetLastError(0xdeadbeef);
9645         ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
9646         ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
9647            GetLastError() == 0xdeadbeef, /* Win9x */
9648            "unexpected error %d\n", GetLastError());
9649     }
9650     else
9651         skip("UnhookWinEvent is not available\n");
9652 }