Add a test for some edit control behaviours, make it pass under Wine.
[wine] / dlls / user / 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include <assert.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26
27 #define _WIN32_WINNT 0x0500 /* For WM_CHANGEUISTATE */
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
43 #define WND_PARENT_ID           1
44 #define WND_POPUP_ID            2
45 #define WND_CHILD_ID            3
46
47 static BOOL test_DestroyWindow_flag;
48 static HWINEVENTHOOK hEvent_hook;
49
50 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
51
52 /*
53 FIXME: add tests for these
54 Window Edge Styles (Win31/Win95/98 look), in order of precedence:
55  WS_EX_DLGMODALFRAME: double border, WS_CAPTION allowed
56  WS_THICKFRAME: thick border
57  WS_DLGFRAME: double border, WS_CAPTION not allowed (but possibly shown anyway)
58  WS_BORDER (default for overlapped windows): single black border
59  none (default for child (and popup?) windows): no border
60 */
61
62 typedef enum {
63     sent=0x1,
64     posted=0x2,
65     parent=0x4,
66     wparam=0x8,
67     lparam=0x10,
68     defwinproc=0x20,
69     beginpaint=0x40,
70     optional=0x80,
71     hook=0x100,
72     winevent_hook=0x200
73 } msg_flags_t;
74
75 struct message {
76     UINT message;          /* the WM_* code */
77     msg_flags_t flags;     /* message props */
78     WPARAM wParam;         /* expected value of wParam */
79     LPARAM lParam;         /* expected value of lParam */
80 };
81
82 /* Empty message sequence */
83 static const struct message WmEmptySeq[] =
84 {
85     { 0 }
86 };
87 /* CreateWindow (for overlapped window, not initially visible) (16/32) */
88 static const struct message WmCreateOverlappedSeq[] = {
89     { HCBT_CREATEWND, hook },
90     { WM_GETMINMAXINFO, sent },
91     { WM_NCCREATE, sent },
92     { WM_NCCALCSIZE, sent|wparam, 0 },
93     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
94     { WM_CREATE, sent },
95     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
96     { 0 }
97 };
98 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
99  * for a not visible overlapped window.
100  */
101 static const struct message WmSWP_ShowOverlappedSeq[] = {
102     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
103     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
104     { WM_NCPAINT, sent|wparam|optional, 1 },
105     { WM_GETTEXT, sent|defwinproc|optional },
106     { WM_ERASEBKGND, sent|optional },
107     { HCBT_ACTIVATE, hook },
108     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
109     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
110     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x: SWP_NOSENDCHANGING */
111     { WM_ACTIVATEAPP, sent|wparam, 1 },
112     { WM_NCACTIVATE, sent|wparam, 1 },
113     { WM_GETTEXT, sent|defwinproc|optional },
114     { WM_ACTIVATE, sent|wparam, 1 },
115     { HCBT_SETFOCUS, hook },
116     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
117     { WM_IME_NOTIFY, sent|defwinproc|optional },
118     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
119     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
120     { WM_NCPAINT, sent|wparam|optional, 1 },
121     { WM_GETTEXT, sent|defwinproc|optional },
122     { WM_ERASEBKGND, sent|optional },
123     /* Win9x adds SWP_NOZORDER below */
124     { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
125     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
126     { WM_NCPAINT, sent|wparam|optional, 1 },
127     { WM_ERASEBKGND, sent|optional },
128     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
129     { 0 }
130 };
131 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
132  * for a visible overlapped window.
133  */
134 static const struct message WmSWP_HideOverlappedSeq[] = {
135     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
136     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
137     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
138     { 0 }
139 };
140
141 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
142  * for a visible overlapped window.
143  */
144 static const struct message WmSWP_ResizeSeq[] = {
145     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE },
146     { WM_GETMINMAXINFO, sent|defwinproc },
147     { WM_NCCALCSIZE, sent|wparam, TRUE },
148     { WM_NCPAINT, sent|optional },
149     { WM_GETTEXT, sent|defwinproc|optional },
150     { WM_ERASEBKGND, sent|optional },
151     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
152     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
153     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
154     { WM_NCPAINT, sent|optional },
155     { WM_GETTEXT, sent|defwinproc|optional },
156     { WM_ERASEBKGND, sent|optional },
157     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
158     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
159     { 0 }
160 };
161
162 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
163  * for a visible popup window.
164  */
165 static const struct message WmSWP_ResizePopupSeq[] = {
166     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE },
167     { WM_NCCALCSIZE, sent|wparam, TRUE },
168     { WM_NCPAINT, sent|optional },
169     { WM_GETTEXT, sent|defwinproc|optional },
170     { WM_ERASEBKGND, sent|optional },
171     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
172     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
173     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
174     { WM_NCPAINT, sent|optional },
175     { WM_GETTEXT, sent|defwinproc|optional },
176     { WM_ERASEBKGND, sent|optional },
177     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
178     { 0 }
179 };
180
181 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
182  * for a visible overlapped window.
183  */
184 static const struct message WmSWP_MoveSeq[] = {
185     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE },
186     { WM_NCPAINT, sent|optional },
187     { WM_GETTEXT, sent|defwinproc|optional },
188     { WM_ERASEBKGND, sent|optional },
189     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER|SWP_NOCLIENTSIZE },
190     { WM_MOVE, sent|defwinproc|wparam, 0 },
191     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
192     { 0 }
193 };
194
195 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
196                 SWP_NOZORDER|SWP_FRAMECHANGED)
197  * for a visible overlapped window with WS_CLIPCHILDREN style set.
198  */
199 static const struct message WmSWP_FrameChanged_clip[] = {
200     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_FRAMECHANGED },
201     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
202     { WM_NCPAINT, sent|parent }, /* wparam != 1 */
203     { WM_GETTEXT, sent|parent|defwinproc|optional },
204     { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
205     { WM_NCPAINT, sent }, /* wparam != 1 */
206     { WM_ERASEBKGND, sent },
207     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
208     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
209     { WM_PAINT, sent },
210     { 0 }
211 };
212 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|
213                 SWP_NOZORDER|SWP_FRAMECHANGED)
214  * for a visible overlapped window.
215  */
216 static const struct message WmSWP_FrameChangedDeferErase[] = {
217     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_FRAMECHANGED },
218     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
219     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
220     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
221     { WM_PAINT, sent|parent },
222     { WM_NCPAINT, sent|beginpaint|parent }, /* wparam != 1 */
223     { WM_GETTEXT, sent|beginpaint|parent|defwinproc|optional },
224     { WM_PAINT, sent },
225     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
226     { WM_ERASEBKGND, sent|beginpaint },
227     { 0 }
228 };
229
230 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
231                 SWP_NOZORDER|SWP_FRAMECHANGED)
232  * for a visible overlapped window without WS_CLIPCHILDREN style set.
233  */
234 static const struct message WmSWP_FrameChanged_noclip[] = {
235     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_FRAMECHANGED },
236     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
237     { WM_NCPAINT, sent|parent }, /* wparam != 1 */
238     { WM_GETTEXT, sent|parent|defwinproc|optional },
239     { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
240     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
241     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
242     { WM_PAINT, sent },
243     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
244     { WM_ERASEBKGND, sent|beginpaint },
245     { 0 }
246 };
247
248 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
249 static const struct message WmShowOverlappedSeq[] = {
250     { WM_SHOWWINDOW, sent|wparam, 1 },
251     { WM_NCPAINT, sent|wparam|optional, 1 },
252     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
253     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
254     { WM_NCPAINT, sent|wparam|optional, 1 },
255     { WM_GETTEXT, sent|defwinproc|optional },
256     { WM_ERASEBKGND, sent|optional },
257     { HCBT_ACTIVATE, hook },
258     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
259     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
260     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
261     { WM_ACTIVATEAPP, sent|wparam, 1 },
262     { WM_NCACTIVATE, sent|wparam, 1 },
263     { WM_GETTEXT, sent|defwinproc|optional },
264     { WM_ACTIVATE, sent|wparam, 1 },
265     { HCBT_SETFOCUS, hook },
266     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
267     { WM_IME_NOTIFY, sent|defwinproc|optional },
268     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
269     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
270     { WM_NCPAINT, sent|wparam|optional, 1 },
271     { WM_GETTEXT, sent|defwinproc|optional },
272     { WM_ERASEBKGND, sent|optional },
273     /* Win9x adds SWP_NOZORDER below */
274     { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
275     { WM_NCCALCSIZE, sent|optional },
276     { WM_NCPAINT, sent|optional },
277     { WM_ERASEBKGND, sent|optional },
278 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
279        * messages. Does that mean that CreateWindow doesn't set initial
280        * window dimensions for overlapped windows?
281        */
282     { WM_SIZE, sent },
283     { WM_MOVE, sent },
284 #endif
285     { 0 }
286 };
287 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible overlapped window */
288 static const struct message WmShowMaxOverlappedSeq[] = {
289     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
290     { WM_GETMINMAXINFO, sent },
291     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
292     { WM_GETMINMAXINFO, sent|defwinproc },
293     { WM_NCCALCSIZE, sent|wparam, TRUE },
294     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
295     { HCBT_ACTIVATE, hook },
296     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
297     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
298     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
299     { WM_ACTIVATEAPP, sent|wparam, 1 },
300     { WM_NCACTIVATE, sent|wparam, 1 },
301     { WM_GETTEXT, sent|defwinproc|optional },
302     { WM_ACTIVATE, sent|wparam, 1 },
303     { HCBT_SETFOCUS, hook },
304     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
305     { WM_IME_NOTIFY, sent|defwinproc|optional },
306     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
307     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
308     { WM_NCPAINT, sent|wparam|optional, 1 },
309     { WM_GETTEXT, sent|defwinproc|optional },
310     { WM_ERASEBKGND, sent|optional },
311     /* Win9x adds SWP_NOZORDER below */
312     { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
313     { WM_MOVE, sent|defwinproc },
314     { WM_SIZE, sent|defwinproc },
315     { WM_NCCALCSIZE, sent|optional },
316     { WM_NCPAINT, sent|optional },
317     { WM_ERASEBKGND, sent|optional },
318     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
319     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
320     { 0 }
321 };
322 /* ShowWindow(SW_HIDE) for a visible overlapped window */
323 static const struct message WmHideOverlappedSeq[] = {
324     { WM_SHOWWINDOW, sent|wparam, 0 },
325     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
326     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
327     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
328     { WM_SIZE, sent|optional }, /* XP doesn't send it */
329     { WM_MOVE, sent|optional }, /* XP doesn't send it */
330     { WM_NCACTIVATE, sent|wparam, 0 },
331     { WM_ACTIVATE, sent|wparam, 0 },
332     { WM_ACTIVATEAPP, sent|wparam, 0 },
333     { WM_KILLFOCUS, sent|wparam, 0 },
334     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
335     { WM_IME_NOTIFY, sent|optional|defwinproc },
336     { 0 }
337 };
338 /* DestroyWindow for a visible overlapped window */
339 static const struct message WmDestroyOverlappedSeq[] = {
340     { HCBT_DESTROYWND, hook },
341     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
342     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
343     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
344     { WM_NCACTIVATE, sent|wparam, 0 },
345     { WM_ACTIVATE, sent|wparam, 0 },
346     { WM_ACTIVATEAPP, sent|wparam, 0 },
347     { WM_KILLFOCUS, sent|wparam, 0 },
348     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
349     { WM_IME_NOTIFY, sent|optional|defwinproc },
350     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
351     { WM_DESTROY, sent },
352     { WM_NCDESTROY, sent },
353     { 0 }
354 };
355 /* CreateWindow (for a child popup window, not initially visible) */
356 static const struct message WmCreateChildPopupSeq[] = {
357     { HCBT_CREATEWND, hook },
358     { WM_NCCREATE, sent }, 
359     { WM_NCCALCSIZE, sent|wparam, 0 },
360     { WM_CREATE, sent },
361     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
362     { WM_SIZE, sent },
363     { WM_MOVE, sent },
364     { 0 }
365 };
366 /* CreateWindow (for a popup window, not initially visible,
367  * which sets WS_VISIBLE in WM_CREATE handler)
368  */
369 static const struct message WmCreateInvisiblePopupSeq[] = {
370     { HCBT_CREATEWND, hook },
371     { WM_NCCREATE, sent }, 
372     { WM_NCCALCSIZE, sent|wparam, 0 },
373     { WM_CREATE, sent },
374     { WM_STYLECHANGING, sent },
375     { WM_STYLECHANGED, sent },
376     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
377     { WM_SIZE, sent },
378     { WM_MOVE, sent },
379     { 0 }
380 };
381 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
382  * for a popup window with WS_VISIBLE style set
383  */
384 static const struct message WmShowVisiblePopupSeq_2[] = {
385     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
386     { 0 }
387 };
388 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
389  * for a popup window with WS_VISIBLE style set
390  */
391 static const struct message WmShowVisiblePopupSeq_3[] = {
392     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
393     { HCBT_ACTIVATE, hook },
394     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
395     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
396     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
397     { WM_NCACTIVATE, sent|wparam, 1 },
398     { WM_ACTIVATE, sent|wparam, 1 },
399     { HCBT_SETFOCUS, hook },
400     { WM_KILLFOCUS, sent|parent },
401     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
402     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
403     { WM_IME_NOTIFY, sent|defwinproc|optional },
404     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
405     { WM_SETFOCUS, sent|defwinproc },
406     { 0 }
407 };
408 /* CreateWindow (for child window, not initially visible) */
409 static const struct message WmCreateChildSeq[] = {
410     { HCBT_CREATEWND, hook },
411     { WM_NCCREATE, sent }, 
412     /* child is inserted into parent's child list after WM_NCCREATE returns */
413     { WM_NCCALCSIZE, sent|wparam, 0 },
414     { WM_CREATE, sent },
415     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
416     { WM_SIZE, sent },
417     { WM_MOVE, sent },
418     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
419     { 0 }
420 };
421 /* CreateWindow (for maximized child window, not initially visible) */
422 static const struct message WmCreateMaximizedChildSeq[] = {
423     { HCBT_CREATEWND, hook },
424     { WM_NCCREATE, sent }, 
425     { WM_NCCALCSIZE, sent|wparam, 0 },
426     { WM_CREATE, sent },
427     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
428     { WM_SIZE, sent },
429     { WM_MOVE, sent },
430     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
431     { WM_GETMINMAXINFO, sent },
432     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
433     { WM_NCCALCSIZE, sent|wparam, 1 },
434     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTMOVE|0x8000 },
435     { WM_SIZE, sent|defwinproc },
436     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
437     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
438     { 0 }
439 };
440 /* CreateWindow (for a child window, initially visible) */
441 static const struct message WmCreateVisibleChildSeq[] = {
442     { HCBT_CREATEWND, hook },
443     { WM_NCCREATE, sent }, 
444     /* child is inserted into parent's child list after WM_NCCREATE returns */
445     { WM_NCCALCSIZE, sent|wparam, 0 },
446     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
447     { WM_CREATE, sent },
448     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
449     { WM_SIZE, sent },
450     { WM_MOVE, sent },
451     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
452     { WM_SHOWWINDOW, sent|wparam, 1 },
453     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER },
454     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
455     { WM_ERASEBKGND, sent|parent|optional },
456     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
457     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
458     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
459     { 0 }
460 };
461 /* ShowWindow(SW_SHOW) for a not visible child window */
462 static const struct message WmShowChildSeq[] = {
463     { WM_SHOWWINDOW, sent|wparam, 1 },
464     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
465     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
466     { WM_ERASEBKGND, sent|parent|optional },
467     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
468     { 0 }
469 };
470 /* ShowWindow(SW_HIDE) for a visible child window */
471 static const struct message WmHideChildSeq[] = {
472     { WM_SHOWWINDOW, sent|wparam, 0 },
473     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
474     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
475     { WM_ERASEBKGND, sent|parent|optional },
476     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
477     { 0 }
478 };
479 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
480  * for a not visible child window
481  */
482 static const struct message WmShowChildSeq_2[] = {
483     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
484     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
485     { WM_CHILDACTIVATE, sent },
486     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
487     { 0 }
488 };
489 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
490  * for a not visible child window
491  */
492 static const struct message WmShowChildSeq_3[] = {
493     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
494     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
495     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
496     { 0 }
497 };
498 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
499  * for a visible child window with a caption
500  */
501 static const struct message WmShowChildSeq_4[] = {
502     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
503     { WM_CHILDACTIVATE, sent },
504     { 0 }
505 };
506 /* ShowWindow(SW_SHOW) for child with invisible parent */
507 static const struct message WmShowChildInvisibleParentSeq[] = {
508     { WM_SHOWWINDOW, sent|wparam, 1 },
509     { 0 }
510 };
511 /* ShowWindow(SW_HIDE) for child with invisible parent */
512 static const struct message WmHideChildInvisibleParentSeq[] = {
513     { WM_SHOWWINDOW, sent|wparam, 0 },
514     { 0 }
515 };
516 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
517 static const struct message WmShowChildInvisibleParentSeq_2[] = {
518     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER },
519     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
520     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
521     { 0 }
522 };
523 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
524 static const struct message WmHideChildInvisibleParentSeq_2[] = {
525     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
526     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
527     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
528     { 0 }
529 };
530 /* DestroyWindow for a visible child window */
531 static const struct message WmDestroyChildSeq[] = {
532     { HCBT_DESTROYWND, hook },
533     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
534     { WM_SHOWWINDOW, sent|wparam, 0 },
535     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
536     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
537     { WM_ERASEBKGND, sent|parent|optional },
538     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
539     { HCBT_SETFOCUS, hook }, /* set focus to a parent */
540     { WM_KILLFOCUS, sent },
541     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
542     { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
543     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
544     { WM_SETFOCUS, sent|parent },
545     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
546     { WM_DESTROY, sent },
547     { WM_DESTROY, sent|optional }, /* some other (IME?) window */
548     { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
549     { WM_NCDESTROY, sent },
550     { 0 }
551 };
552 /* DestroyWindow for a visible child window with invisible parent */
553 static const struct message WmDestroyInvisibleChildSeq[] = {
554     { HCBT_DESTROYWND, hook },
555     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
556     { WM_SHOWWINDOW, sent|wparam, 0 },
557     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
558     { WM_DESTROY, sent },
559     { WM_NCDESTROY, sent },
560     { 0 }
561 };
562 /* Moving the mouse in nonclient area */
563 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
564     { WM_NCHITTEST, sent },
565     { WM_SETCURSOR, sent },
566     { WM_NCMOUSEMOVE, posted },
567     { 0 }
568 };
569 /* Moving the mouse in client area */
570 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
571     { WM_NCHITTEST, sent },
572     { WM_SETCURSOR, sent },
573     { WM_MOUSEMOVE, posted },
574     { 0 }
575 };
576 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
577 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
578     { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
579     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
580     { WM_GETMINMAXINFO, sent|defwinproc },
581     { WM_ENTERSIZEMOVE, sent|defwinproc },
582     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
583     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
584     { WM_MOVE, sent|defwinproc },
585     { WM_EXITSIZEMOVE, sent|defwinproc },
586     { 0 }
587 };
588 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
589 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
590     { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
591     { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
592     { WM_GETMINMAXINFO, sent|defwinproc },
593     { WM_ENTERSIZEMOVE, sent|defwinproc },
594     { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
595     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
596     { WM_GETMINMAXINFO, sent|defwinproc },
597     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
598     { WM_NCPAINT, sent|defwinproc|wparam, 1 },
599     { WM_GETTEXT, sent|defwinproc },
600     { WM_ERASEBKGND, sent|defwinproc },
601     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
602     { WM_MOVE, sent|defwinproc },
603     { WM_SIZE, sent|defwinproc },
604     { WM_EXITSIZEMOVE, sent|defwinproc },
605     { 0 }
606 };
607 /* Resizing child window with MoveWindow (32) */
608 static const struct message WmResizingChildWithMoveWindowSeq[] = {
609     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
610     { WM_NCCALCSIZE, sent|wparam, 1 },
611     { WM_ERASEBKGND, sent|optional },
612     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
613     { WM_MOVE, sent|defwinproc },
614     { WM_SIZE, sent|defwinproc },
615     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
616     { 0 }
617 };
618 /* Clicking on inactive button */
619 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
620     { WM_NCHITTEST, sent },
621     { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
622     { WM_MOUSEACTIVATE, sent },
623     { WM_MOUSEACTIVATE, sent|parent|defwinproc },
624     { WM_SETCURSOR, sent },
625     { WM_SETCURSOR, sent|parent|defwinproc },
626     { WM_LBUTTONDOWN, posted },
627     { WM_KILLFOCUS, posted|parent },
628     { WM_SETFOCUS, posted },
629     { WM_CTLCOLORBTN, posted|parent },
630     { BM_SETSTATE, posted },
631     { WM_CTLCOLORBTN, posted|parent },
632     { WM_LBUTTONUP, posted },
633     { BM_SETSTATE, posted },
634     { WM_CTLCOLORBTN, posted|parent },
635     { WM_COMMAND, posted|parent },
636     { 0 }
637 };
638 /* Reparenting a button (16/32) */
639 /* The last child (button) reparented gets topmost for its new parent. */
640 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
641     { WM_SHOWWINDOW, sent|wparam, 0 },
642     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER },
643     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
644     { WM_ERASEBKGND, sent|parent },
645     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER },
646     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOZORDER },
647     { WM_CHILDACTIVATE, sent },
648     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER },
649     { WM_MOVE, sent|defwinproc },
650     { WM_SHOWWINDOW, sent|wparam, 1 },
651     { 0 }
652 };
653 /* Creation of a custom dialog (32) */
654 static const struct message WmCreateCustomDialogSeq[] = {
655     { HCBT_CREATEWND, hook },
656     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
657     { WM_GETMINMAXINFO, sent },
658     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
659     { WM_NCCREATE, sent },
660     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
661     { WM_NCCALCSIZE, sent|wparam, 0 },
662     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
663     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
664     { WM_CREATE, sent },
665     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
666     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
667     { WM_SHOWWINDOW, sent|wparam, 1 },
668     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
669     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
670     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
671     { HCBT_ACTIVATE, hook },
672     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
673
674     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
675
676     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
677     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
678
679     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
680
681     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
682     { WM_NCACTIVATE, sent|wparam, 1 },
683     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
684     { WM_GETTEXT, sent|optional|defwinproc },
685     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
686     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
687     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
688     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
689     { WM_GETTEXT, sent|optional|defwinproc },
690     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
691     { WM_ACTIVATE, sent|wparam, 1 },
692     { WM_KILLFOCUS, sent|parent },
693     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
694     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
695     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
696     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
697     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
698     { WM_IME_NOTIFY, sent|optional|defwinproc },
699     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
700     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
701     { WM_SETFOCUS, sent },
702     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
703     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
704     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
705     { WM_NCPAINT, sent|wparam, 1 },
706     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
707     { WM_GETTEXT, sent|optional|defwinproc },
708     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
709     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
710     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
711     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
712     { WM_GETTEXT, sent|optional|defwinproc },
713     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
714     { WM_ERASEBKGND, sent },
715     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
716     { WM_CTLCOLORDLG, sent|defwinproc },
717     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
718     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
719     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
720     { WM_GETTEXT, sent|optional },
721     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
722     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
723     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
724     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
725     { WM_GETTEXT, sent|optional },
726     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
727     { WM_NCCALCSIZE, sent|optional },
728     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
729     { WM_NCPAINT, sent|optional },
730     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
731     { WM_GETTEXT, sent|optional|defwinproc },
732     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
733     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
734     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
735     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
736     { WM_GETTEXT, sent|optional|defwinproc },
737     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
738     { WM_ERASEBKGND, sent|optional },
739     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
740     { WM_CTLCOLORDLG, sent|optional|defwinproc },
741     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
742     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
743     { WM_SIZE, sent },
744     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
745     { WM_MOVE, sent },
746     { 0 }
747 };
748 /* Calling EndDialog for a custom dialog (32) */
749 static const struct message WmEndCustomDialogSeq[] = {
750     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
751     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
752     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
753     { WM_GETTEXT, sent|optional },
754     { HCBT_ACTIVATE, hook },
755     { WM_NCACTIVATE, sent|wparam, 0 },
756     { WM_GETTEXT, sent|optional|defwinproc },
757     { WM_GETTEXT, sent|optional|defwinproc },
758     { WM_ACTIVATE, sent|wparam, 0 },
759     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
760     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
761     { HCBT_SETFOCUS, hook },
762     { WM_KILLFOCUS, sent },
763     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
764     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
765     { WM_IME_NOTIFY, sent|optional },
766     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
767     { WM_SETFOCUS, sent|parent|defwinproc },
768     { 0 }
769 };
770 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
771 static const struct message WmShowCustomDialogSeq[] = {
772     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
773     { WM_SHOWWINDOW, sent|wparam, 1 },
774     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
775     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
776     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
777     { HCBT_ACTIVATE, hook },
778     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
779
780     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
781     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
782
783     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
784     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
785     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
786     { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
787     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
788     { WM_NCACTIVATE, sent|wparam, 1 },
789     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
790     { WM_ACTIVATE, sent|wparam, 1 },
791
792     { WM_KILLFOCUS, sent|parent },
793     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
794     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
795     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
796     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
797     { WM_IME_NOTIFY, sent|optional|defwinproc },
798     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
799     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
800     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
801     { WM_SETFOCUS, sent },
802     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
803     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
804     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
805     { WM_NCPAINT, sent|wparam, 1 },
806     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
807     { WM_ERASEBKGND, sent },
808     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
809     { WM_CTLCOLORDLG, sent|defwinproc },
810
811     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
812     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
813     { 0 }
814 };
815 /* Creation and destruction of a modal dialog (32) */
816 static const struct message WmModalDialogSeq[] = {
817     { WM_CANCELMODE, sent|parent },
818     { HCBT_SETFOCUS, hook },
819     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
820     { WM_KILLFOCUS, sent|parent },
821     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
822     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
823     { WM_ENABLE, sent|parent|wparam, 0 },
824     { HCBT_CREATEWND, hook },
825     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
826     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
827     { WM_SETFONT, sent },
828     { WM_INITDIALOG, sent },
829     { WM_CHANGEUISTATE, sent|optional },
830     { WM_SHOWWINDOW, sent },
831     { HCBT_ACTIVATE, hook },
832     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
833     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
834     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
835     { WM_NCACTIVATE, sent|wparam, 1 },
836     { WM_GETTEXT, sent|optional },
837     { WM_ACTIVATE, sent|wparam, 1 },
838     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE },
839     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
840     { WM_NCPAINT, sent },
841     { WM_GETTEXT, sent|optional },
842     { WM_ERASEBKGND, sent },
843     { WM_CTLCOLORDLG, sent },
844     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
845     { WM_GETTEXT, sent|optional },
846     { WM_NCCALCSIZE, sent|optional },
847     { WM_NCPAINT, sent|optional },
848     { WM_GETTEXT, sent|optional },
849     { WM_ERASEBKGND, sent|optional },
850     { WM_CTLCOLORDLG, sent|optional },
851     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
852     { WM_PAINT, sent|optional },
853     { WM_CTLCOLORBTN, sent },
854     { WM_ENTERIDLE, sent|parent|optional },
855     { WM_ENTERIDLE, sent|parent|optional },
856     { WM_ENTERIDLE, sent|parent|optional },
857     { WM_ENTERIDLE, sent|parent|optional },
858     { WM_ENTERIDLE, sent|parent|optional },
859     { WM_ENTERIDLE, sent|parent|optional },
860     { WM_ENTERIDLE, sent|parent|optional },
861     { WM_ENTERIDLE, sent|parent|optional },
862     { WM_ENTERIDLE, sent|parent|optional },
863     { WM_ENTERIDLE, sent|parent|optional },
864     { WM_ENTERIDLE, sent|parent|optional },
865     { WM_ENTERIDLE, sent|parent|optional },
866     { WM_ENTERIDLE, sent|parent|optional },
867     { WM_ENTERIDLE, sent|parent|optional },
868     { WM_ENTERIDLE, sent|parent|optional },
869     { WM_ENTERIDLE, sent|parent|optional },
870     { WM_ENTERIDLE, sent|parent|optional },
871     { WM_ENTERIDLE, sent|parent|optional },
872     { WM_ENTERIDLE, sent|parent|optional },
873     { WM_ENTERIDLE, sent|parent|optional },
874     { WM_TIMER, sent },
875     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
876     { WM_ENABLE, sent|parent|wparam, 1 },
877     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE },
878     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
879     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
880     { WM_GETTEXT, sent|optional },
881     { HCBT_ACTIVATE, hook },
882     { WM_NCACTIVATE, sent|wparam, 0 },
883     { WM_GETTEXT, sent|optional },
884     { WM_ACTIVATE, sent|wparam, 0 },
885     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
886     { WM_WINDOWPOSCHANGING, sent|optional },
887     { HCBT_SETFOCUS, hook },
888     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
889     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
890     { WM_SETFOCUS, sent|parent|defwinproc },
891     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
892     { HCBT_DESTROYWND, hook },
893     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
894     { WM_DESTROY, sent },
895     { WM_NCDESTROY, sent },
896     { 0 }
897 };
898 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
899 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
900     /* (inside dialog proc, handling WM_INITDIALOG) */
901     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
902     { WM_NCCALCSIZE, sent },
903     { WM_NCACTIVATE, sent|parent|wparam, 0 },
904     { WM_GETTEXT, sent|defwinproc },
905     { WM_ACTIVATE, sent|parent|wparam, 0 },
906     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
907     { WM_WINDOWPOSCHANGING, sent|parent },
908     { WM_NCACTIVATE, sent|wparam, 1 },
909     { WM_ACTIVATE, sent|wparam, 1 },
910     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
911     { WM_SIZE, sent|defwinproc },
912     /* (setting focus) */
913     { WM_SHOWWINDOW, sent|wparam, 1 },
914     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
915     { WM_NCPAINT, sent },
916     { WM_GETTEXT, sent|defwinproc },
917     { WM_ERASEBKGND, sent },
918     { WM_CTLCOLORDLG, sent|defwinproc },
919     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
920     { WM_PAINT, sent },
921     /* (bunch of WM_CTLCOLOR* for each control) */
922     { WM_PAINT, sent|parent },
923     { WM_ENTERIDLE, sent|parent|wparam, 0 },
924     { WM_SETCURSOR, sent|parent },
925     { 0 }
926 };
927 /* SetMenu for NonVisible windows with size change*/
928 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
929     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
930     { WM_NCCALCSIZE, sent|wparam, 1 },
931     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
932     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW },
933     { WM_MOVE, sent|defwinproc },
934     { WM_SIZE, sent|defwinproc },
935     { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
936     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
937     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
938     { WM_GETTEXT, sent|optional },
939     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
940     { 0 }
941 };
942 /* SetMenu for NonVisible windows with no size change */
943 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
944     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
945     { WM_NCCALCSIZE, sent|wparam, 1 },
946     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
947     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
948     { 0 }
949 };
950 /* SetMenu for Visible windows with size change */
951 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
952     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
953     { WM_NCCALCSIZE, sent|wparam, 1 },
954     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
955     { WM_NCPAINT, sent }, /* wparam != 1 */
956     { WM_GETTEXT, sent|defwinproc|optional },
957     { WM_ERASEBKGND, sent|optional },
958     { WM_ACTIVATE, sent|optional },
959     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
960     { WM_MOVE, sent|defwinproc },
961     { WM_SIZE, sent|defwinproc },
962     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
963     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
964     { WM_ERASEBKGND, sent|optional },
965     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
966     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
967     { 0 }
968 };
969 /* SetMenu for Visible windows with no size change */
970 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
971     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
972     { WM_NCCALCSIZE, sent|wparam, 1 },
973     { WM_NCPAINT, sent }, /* wparam != 1 */
974     { WM_GETTEXT, sent|defwinproc|optional },
975     { WM_ERASEBKGND, sent|optional },
976     { WM_ACTIVATE, sent|optional },
977     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
978     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
979     { 0 }
980 };
981 /* DrawMenuBar for a visible window */
982 static const struct message WmDrawMenuBarSeq[] =
983 {
984     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
985     { WM_NCCALCSIZE, sent|wparam, 1 },
986     { WM_NCPAINT, sent }, /* wparam != 1 */
987     { WM_GETTEXT, sent|defwinproc|optional },
988     { WM_ERASEBKGND, sent|optional },
989     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
990     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
991     { 0 }
992 };
993
994 static const struct message WmSetRedrawFalseSeq[] =
995 {
996     { WM_SETREDRAW, sent|wparam, 0 },
997     { 0 }
998 };
999
1000 static const struct message WmSetRedrawTrueSeq[] =
1001 {
1002     { WM_SETREDRAW, sent|wparam, 1 },
1003     { 0 }
1004 };
1005
1006 static const struct message WmEnableWindowSeq_1[] =
1007 {
1008     { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1009     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1010     { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1011     { 0 }
1012 };
1013
1014 static const struct message WmEnableWindowSeq_2[] =
1015 {
1016     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1017     { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1018     { 0 }
1019 };
1020
1021 static const struct message WmGetScrollRangeSeq[] =
1022 {
1023     { SBM_GETRANGE, sent },
1024     { 0 }
1025 };
1026 static const struct message WmGetScrollInfoSeq[] =
1027 {
1028     { SBM_GETSCROLLINFO, sent },
1029     { 0 }
1030 };
1031 static const struct message WmSetScrollRangeSeq[] =
1032 {
1033     /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1034        sends SBM_SETSCROLLINFO.
1035      */
1036     { SBM_SETSCROLLINFO, sent },
1037     { 0 }
1038 };
1039 /* SetScrollRange for a window without a non-client area */
1040 static const struct message WmSetScrollRangeHSeq_empty[] =
1041 {
1042     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1043     { 0 }
1044 };
1045 static const struct message WmSetScrollRangeVSeq_empty[] =
1046 {
1047     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1048     { 0 }
1049 };
1050 static const struct message WmSetScrollRangeHVSeq[] =
1051 {
1052     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER },
1053     { WM_NCCALCSIZE, sent|wparam, 1 },
1054     { WM_GETTEXT, sent|defwinproc|optional },
1055     { WM_ERASEBKGND, sent|optional },
1056     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1057     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1058     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1059     { 0 }
1060 };
1061 /* SetScrollRange for a window with a non-client area */
1062 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1063 {
1064     { WM_WINDOWPOSCHANGING, sent, /*|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER*/ },
1065     { WM_NCCALCSIZE, sent|wparam, 1 },
1066     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1067     { WM_NCPAINT, sent|optional },
1068     { WM_GETTEXT, sent|defwinproc|optional },
1069     { WM_GETTEXT, sent|defwinproc|optional },
1070     { WM_ERASEBKGND, sent|optional },
1071     { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1072     { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|0x1000*/ },
1073     { WM_SIZE, sent|defwinproc },
1074     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1075     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1076     { WM_GETTEXT, sent|optional },
1077     { WM_GETTEXT, sent|optional },
1078     { WM_GETTEXT, sent|optional },
1079     { WM_GETTEXT, sent|optional },
1080     { 0 }
1081 };
1082 /* test if we receive the right sequence of messages */
1083 /* after calling ShowWindow( SW_SHOWNA) */
1084 static const struct message WmSHOWNAChildInvisParInvis[] = {
1085     { WM_SHOWWINDOW, sent|wparam, 1 },
1086     { 0 }
1087 };
1088 static const struct message WmSHOWNAChildVisParInvis[] = {
1089     { WM_SHOWWINDOW, sent|wparam, 1 },
1090     { 0 }
1091 };
1092 static const struct message WmSHOWNAChildVisParVis[] = {
1093     { WM_SHOWWINDOW, sent|wparam, 1 },
1094     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER },
1095     { 0 }
1096 };
1097 static const struct message WmSHOWNAChildInvisParVis[] = {
1098     { WM_SHOWWINDOW, sent|wparam, 1 },
1099     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER},
1100     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1101     { WM_ERASEBKGND, sent|optional },
1102     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
1103     { 0 }
1104 };
1105 static const struct message WmSHOWNATopVisible[] = {
1106     { WM_SHOWWINDOW, sent|wparam, 1 },
1107     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1108     { 0 }
1109 };
1110 static const struct message WmSHOWNATopInvisible[] = {
1111     { WM_SHOWWINDOW, sent|wparam, 1 },
1112     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1113     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1114     { WM_NCPAINT, sent|wparam, 1 },
1115     { WM_GETTEXT, sent|defwinproc|optional },
1116     { WM_ERASEBKGND, sent|optional },
1117     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1118     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1119     { WM_NCPAINT, sent|wparam|optional, 1 },
1120     { WM_ERASEBKGND, sent|optional },
1121     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1122     { WM_SIZE, sent },
1123     { WM_MOVE, sent },
1124     { 0 }
1125 };
1126
1127 static int after_end_dialog;
1128 static int sequence_cnt, sequence_size;
1129 static struct message* sequence;
1130 static int log_all_parent_messages;
1131
1132 static void add_message(const struct message *msg)
1133 {
1134     if (!sequence) 
1135     {
1136         sequence_size = 10;
1137         sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof (struct message) );
1138     }
1139     if (sequence_cnt == sequence_size) 
1140     {
1141         sequence_size *= 2;
1142         sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof (struct message) );
1143     }
1144     assert(sequence);
1145
1146     sequence[sequence_cnt].message = msg->message;
1147     sequence[sequence_cnt].flags = msg->flags;
1148     sequence[sequence_cnt].wParam = msg->wParam;
1149     sequence[sequence_cnt].lParam = msg->lParam;
1150
1151     sequence_cnt++;
1152 }
1153
1154 static void flush_sequence(void)
1155 {
1156     HeapFree(GetProcessHeap(), 0, sequence);
1157     sequence = 0;
1158     sequence_cnt = sequence_size = 0;
1159 }
1160
1161 #define ok_sequence( exp, contx, todo) \
1162         ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
1163
1164
1165 static void ok_sequence_(const struct message *expected, const char *context, int todo,
1166         const char *file, int line)
1167 {
1168     static const struct message end_of_sequence = { 0, 0, 0, 0 };
1169     const struct message *actual;
1170     int failcount = 0;
1171     
1172     add_message(&end_of_sequence);
1173
1174     actual = sequence;
1175
1176     while (expected->message && actual->message)
1177     {
1178         trace_( file, line)("expected %04x - actual %04x\n", expected->message, actual->message);
1179
1180         if (expected->message == actual->message)
1181         {
1182             if (expected->flags & wparam)
1183             {
1184                 if (expected->wParam != actual->wParam && todo)
1185                 {
1186                     todo_wine {
1187                         failcount ++;
1188                         ok_( file, line) (FALSE,
1189                             "%s: in msg 0x%04x expecting wParam 0x%x got 0x%x\n",
1190                             context, expected->message, expected->wParam, actual->wParam);
1191                     }
1192                 }
1193                 else
1194                 ok_( file, line) (expected->wParam == actual->wParam,
1195                      "%s: in msg 0x%04x expecting wParam 0x%x got 0x%x\n",
1196                      context, expected->message, expected->wParam, actual->wParam);
1197             }
1198             if (expected->flags & lparam)
1199                  ok_( file, line) (expected->lParam == actual->lParam,
1200                      "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1201                      context, expected->message, expected->lParam, actual->lParam);
1202             ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
1203                 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1204                 context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1205             ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
1206                 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
1207                 context, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
1208             ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
1209                 "%s: the msg 0x%04x should have been %s\n",
1210                 context, expected->message, (expected->flags & posted) ? "posted" : "sent");
1211             ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
1212                 "%s: the msg 0x%04x was expected in %s\n",
1213                 context, expected->message, (expected->flags & parent) ? "parent" : "child");
1214             ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
1215                 "%s: the msg 0x%04x should have been sent by a hook\n",
1216                 context, expected->message);
1217             ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
1218                 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
1219                 context, expected->message);
1220             expected++;
1221             actual++;
1222         }
1223         /* silently drop winevent messages if there is no support for them */
1224         else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1225             expected++;
1226         else if (todo)
1227         {
1228             failcount++;
1229             todo_wine {
1230                 ok_( file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
1231                     context, expected->message, actual->message);
1232             }
1233             flush_sequence();
1234             return;
1235         }
1236         else
1237         {
1238             ok_( file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
1239                 context, expected->message, actual->message);
1240             expected++;
1241             actual++;
1242         }
1243     }
1244
1245     /* skip all optional trailing messages */
1246     while (expected->message && ((expected->flags & optional) ||
1247             ((expected->flags & winevent_hook) && !hEvent_hook)))
1248         expected++;
1249
1250     if (todo)
1251     {
1252         todo_wine {
1253             if (expected->message || actual->message) {
1254                 failcount++;
1255                 ok_( file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
1256                     context, expected->message, actual->message);
1257             }
1258         }
1259     }
1260     else
1261     {
1262         if (expected->message || actual->message)
1263             ok_( file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
1264                 context, expected->message, actual->message);
1265     }
1266     if( todo && !failcount) /* succeeded yet marked todo */
1267         todo_wine {
1268             ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
1269         }
1270
1271     flush_sequence();
1272 }
1273
1274 /******************************** MDI test **********************************/
1275
1276 /* CreateWindow for MDI frame window, initially visible */
1277 static const struct message WmCreateMDIframeSeq[] = {
1278     { HCBT_CREATEWND, hook },
1279     { WM_GETMINMAXINFO, sent },
1280     { WM_NCCREATE, sent },
1281     { WM_NCCALCSIZE, sent|wparam, 0 },
1282     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1283     { WM_CREATE, sent },
1284     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1285     { WM_SHOWWINDOW, sent|wparam, 1 },
1286     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1287     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1288     { HCBT_ACTIVATE, hook },
1289     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1290     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1291     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1292     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* Win9x */
1293     { WM_ACTIVATEAPP, sent|wparam, 1 },
1294     { WM_NCACTIVATE, sent|wparam, 1 },
1295     { WM_GETTEXT, sent|defwinproc|optional },
1296     { WM_ACTIVATE, sent|wparam, 1 },
1297     { HCBT_SETFOCUS, hook },
1298     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1299     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1300     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
1301     /* Win9x adds SWP_NOZORDER below */
1302     { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
1303     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
1304     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1305     { WM_SIZE, sent },
1306     { WM_MOVE, sent },
1307     { 0 }
1308 };
1309 /* DestroyWindow for MDI frame window, initially visible */
1310 static const struct message WmDestroyMDIframeSeq[] = {
1311     { HCBT_DESTROYWND, hook },
1312     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1313     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1314     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1315     { WM_NCACTIVATE, sent|wparam, 0 },
1316     { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
1317     { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
1318     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
1319     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1320     { WM_DESTROY, sent },
1321     { WM_NCDESTROY, sent },
1322     { 0 }
1323 };
1324 /* CreateWindow for MDI client window, initially visible */
1325 static const struct message WmCreateMDIclientSeq[] = {
1326     { HCBT_CREATEWND, hook },
1327     { WM_NCCREATE, sent },
1328     { WM_NCCALCSIZE, sent|wparam, 0 },
1329     { WM_CREATE, sent },
1330     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1331     { WM_SIZE, sent },
1332     { WM_MOVE, sent },
1333     { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
1334     { WM_SHOWWINDOW, sent|wparam, 1 },
1335     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE|SWP_NOMOVE },
1336     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1337     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1338     { 0 }
1339 };
1340 /* DestroyWindow for MDI client window, initially visible */
1341 static const struct message WmDestroyMDIclientSeq[] = {
1342     { HCBT_DESTROYWND, hook },
1343     { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
1344     { WM_SHOWWINDOW, sent|wparam, 0 },
1345     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1346     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1347     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1348     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1349     { WM_DESTROY, sent },
1350     { WM_NCDESTROY, sent },
1351     { 0 }
1352 };
1353 /* CreateWindow for MDI child window, initially visible */
1354 static const struct message WmCreateMDIchildVisibleSeq[] = {
1355     { HCBT_CREATEWND, hook },
1356     { WM_NCCREATE, sent }, 
1357     { WM_NCCALCSIZE, sent|wparam, 0 },
1358     { WM_CREATE, sent },
1359     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1360     { WM_SIZE, sent },
1361     { WM_MOVE, sent },
1362     /* Win2k sends wparam set to
1363      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1364      * while Win9x doesn't bother to set child window id according to
1365      * CLIENTCREATESTRUCT.idFirstChild
1366      */
1367     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1368     { WM_SHOWWINDOW, sent|wparam, 1 },
1369     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1370     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1371     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1372     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1373     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1374     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1375     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1376
1377     /* Win9x: message sequence terminates here. */
1378
1379     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1380     { HCBT_SETFOCUS, hook }, /* in MDI client */
1381     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1382     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1383     { WM_SETFOCUS, sent }, /* in MDI client */
1384     { HCBT_SETFOCUS, hook },
1385     { WM_KILLFOCUS, sent }, /* in MDI client */
1386     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1387     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1388     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1389     { WM_SETFOCUS, sent|defwinproc },
1390     { WM_MDIACTIVATE, sent|defwinproc },
1391     { 0 }
1392 };
1393 /* DestroyWindow for MDI child window, initially visible */
1394 static const struct message WmDestroyMDIchildVisibleSeq[] = {
1395     { HCBT_DESTROYWND, hook },
1396     /* Win2k sends wparam set to
1397      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1398      * while Win9x doesn't bother to set child window id according to
1399      * CLIENTCREATESTRUCT.idFirstChild
1400      */
1401     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1402     { WM_SHOWWINDOW, sent|wparam, 0 },
1403     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1404     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1405     { WM_ERASEBKGND, sent|parent|optional },
1406     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1407
1408     /* { WM_DESTROY, sent }
1409      * Win9x: message sequence terminates here.
1410      */
1411
1412     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1413     { WM_KILLFOCUS, sent },
1414     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1415     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1416     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1417     { WM_SETFOCUS, sent }, /* in MDI client */
1418
1419     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1420     { WM_KILLFOCUS, sent }, /* in MDI client */
1421     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1422     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1423     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1424     { WM_SETFOCUS, sent }, /* in MDI client */
1425
1426     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1427
1428     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1429     { WM_KILLFOCUS, sent },
1430     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1431     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1432     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1433     { WM_SETFOCUS, sent }, /* in MDI client */
1434
1435     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1436     { WM_KILLFOCUS, sent }, /* in MDI client */
1437     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1438     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1439     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1440     { WM_SETFOCUS, sent }, /* in MDI client */
1441
1442     { WM_DESTROY, sent },
1443
1444     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1445     { WM_KILLFOCUS, sent },
1446     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1447     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1448     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1449     { WM_SETFOCUS, sent }, /* in MDI client */
1450
1451     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1452     { WM_KILLFOCUS, sent }, /* in MDI client */
1453     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1454     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1455     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1456     { WM_SETFOCUS, sent }, /* in MDI client */
1457
1458     { WM_NCDESTROY, sent },
1459     { 0 }
1460 };
1461 /* CreateWindow for MDI child window, initially invisible */
1462 static const struct message WmCreateMDIchildInvisibleSeq[] = {
1463     { HCBT_CREATEWND, hook },
1464     { WM_NCCREATE, sent }, 
1465     { WM_NCCALCSIZE, sent|wparam, 0 },
1466     { WM_CREATE, sent },
1467     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1468     { WM_SIZE, sent },
1469     { WM_MOVE, sent },
1470     /* Win2k sends wparam set to
1471      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1472      * while Win9x doesn't bother to set child window id according to
1473      * CLIENTCREATESTRUCT.idFirstChild
1474      */
1475     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1476     { 0 }
1477 };
1478 /* DestroyWindow for MDI child window, initially invisible */
1479 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
1480     { HCBT_DESTROYWND, hook },
1481     /* Win2k sends wparam set to
1482      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1483      * while Win9x doesn't bother to set child window id according to
1484      * CLIENTCREATESTRUCT.idFirstChild
1485      */
1486     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1487     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1488     { WM_DESTROY, sent },
1489     { WM_NCDESTROY, sent },
1490     { 0 }
1491 };
1492 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
1493 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
1494     { HCBT_CREATEWND, hook },
1495     { WM_NCCREATE, sent }, 
1496     { WM_NCCALCSIZE, sent|wparam, 0 },
1497     { WM_CREATE, sent },
1498     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1499     { WM_SIZE, sent },
1500     { WM_MOVE, sent },
1501     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1502     { WM_GETMINMAXINFO, sent },
1503     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
1504     { WM_NCCALCSIZE, sent|wparam, 1 },
1505     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1506     { WM_SIZE, sent|defwinproc },
1507      /* in MDI frame */
1508     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1509     { WM_NCCALCSIZE, sent|wparam, 1 },
1510     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1511     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1512     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1513     /* Win2k sends wparam set to
1514      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1515      * while Win9x doesn't bother to set child window id according to
1516      * CLIENTCREATESTRUCT.idFirstChild
1517      */
1518     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1519     { WM_SHOWWINDOW, sent|wparam, 1 },
1520     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1521     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1522     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1523     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1524     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1525     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1526     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1527
1528     /* Win9x: message sequence terminates here. */
1529
1530     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1531     { HCBT_SETFOCUS, hook }, /* in MDI client */
1532     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1533     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1534     { WM_SETFOCUS, sent }, /* in MDI client */
1535     { HCBT_SETFOCUS, hook },
1536     { WM_KILLFOCUS, sent }, /* in MDI client */
1537     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1538     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1539     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1540     { WM_SETFOCUS, sent|defwinproc },
1541     { WM_MDIACTIVATE, sent|defwinproc },
1542      /* in MDI frame */
1543     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1544     { WM_NCCALCSIZE, sent|wparam, 1 },
1545     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1546     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1547     { 0 }
1548 };
1549 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
1550 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
1551     /* restore the 1st MDI child */
1552     { WM_SETREDRAW, sent|wparam, 0 },
1553     { HCBT_MINMAX, hook },
1554     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
1555     { WM_NCCALCSIZE, sent|wparam, 1 },
1556     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1557     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1558     { WM_SIZE, sent|defwinproc },
1559      /* in MDI frame */
1560     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1561     { WM_NCCALCSIZE, sent|wparam, 1 },
1562     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1563     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1564     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1565     { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
1566     /* create the 2nd MDI child */
1567     { HCBT_CREATEWND, hook },
1568     { WM_NCCREATE, sent }, 
1569     { WM_NCCALCSIZE, sent|wparam, 0 },
1570     { WM_CREATE, sent },
1571     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1572     { WM_SIZE, sent },
1573     { WM_MOVE, sent },
1574     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1575     { WM_GETMINMAXINFO, sent },
1576     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
1577     { WM_NCCALCSIZE, sent|wparam, 1 },
1578     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1579     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1580     { WM_SIZE, sent|defwinproc },
1581      /* in MDI frame */
1582     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1583     { WM_NCCALCSIZE, sent|wparam, 1 },
1584     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1585     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1586     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1587     /* Win2k sends wparam set to
1588      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1589      * while Win9x doesn't bother to set child window id according to
1590      * CLIENTCREATESTRUCT.idFirstChild
1591      */
1592     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1593     { WM_SHOWWINDOW, sent|wparam, 1 },
1594     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1595     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1596     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1597     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1598     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1599     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1600
1601     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
1602     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
1603
1604     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1605
1606     /* Win9x: message sequence terminates here. */
1607
1608     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1609     { HCBT_SETFOCUS, hook },
1610     { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
1611     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
1612     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1613     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1614     { WM_SETFOCUS, sent }, /* in MDI client */
1615     { HCBT_SETFOCUS, hook },
1616     { WM_KILLFOCUS, sent }, /* in MDI client */
1617     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1618     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1619     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1620     { WM_SETFOCUS, sent|defwinproc },
1621
1622     { WM_MDIACTIVATE, sent|defwinproc },
1623      /* in MDI frame */
1624     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1625     { WM_NCCALCSIZE, sent|wparam, 1 },
1626     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1627     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1628     { 0 }
1629 };
1630 /* WM_MDICREATE MDI child window, initially visible and maximized */
1631 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
1632     { WM_MDICREATE, sent },
1633     { HCBT_CREATEWND, hook },
1634     { WM_NCCREATE, sent }, 
1635     { WM_NCCALCSIZE, sent|wparam, 0 },
1636     { WM_CREATE, sent },
1637     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1638     { WM_SIZE, sent },
1639     { WM_MOVE, sent },
1640     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1641     { WM_GETMINMAXINFO, sent },
1642     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
1643     { WM_NCCALCSIZE, sent|wparam, 1 },
1644     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1645     { WM_SIZE, sent|defwinproc },
1646
1647      /* in MDI frame */
1648     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1649     { WM_NCCALCSIZE, sent|wparam, 1 },
1650     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1651     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1652     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1653
1654     /* Win2k sends wparam set to
1655      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1656      * while Win9x doesn't bother to set child window id according to
1657      * CLIENTCREATESTRUCT.idFirstChild
1658      */
1659     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1660     { WM_SHOWWINDOW, sent|wparam, 1 },
1661     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1662
1663     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1664
1665     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1666     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1667     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1668
1669     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1670     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1671
1672     /* Win9x: message sequence terminates here. */
1673
1674     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1675     { HCBT_SETFOCUS, hook }, /* in MDI client */
1676     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1677     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1678     { WM_SETFOCUS, sent }, /* in MDI client */
1679     { HCBT_SETFOCUS, hook },
1680     { WM_KILLFOCUS, sent }, /* in MDI client */
1681     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1682     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1683     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1684     { WM_SETFOCUS, sent|defwinproc },
1685
1686     { WM_MDIACTIVATE, sent|defwinproc },
1687
1688      /* in MDI child */
1689     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1690     { WM_NCCALCSIZE, sent|wparam, 1 },
1691     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1692     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1693
1694      /* in MDI frame */
1695     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1696     { WM_NCCALCSIZE, sent|wparam, 1 },
1697     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1698     { WM_MOVE, sent|defwinproc },
1699     { WM_SIZE, sent|defwinproc },
1700
1701      /* in MDI client */
1702     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
1703     { WM_NCCALCSIZE, sent|wparam, 1 },
1704     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
1705     { WM_SIZE, sent },
1706
1707      /* in MDI child */
1708     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
1709     { WM_NCCALCSIZE, sent|wparam, 1 },
1710     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
1711     { WM_SIZE, sent|defwinproc },
1712
1713     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1714     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
1715     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
1716     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1717     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
1718
1719     { 0 }
1720 };
1721 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
1722 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
1723     { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
1724     { HCBT_SYSCOMMAND, hook },
1725     { WM_CLOSE, sent|defwinproc },
1726     { WM_MDIDESTROY, sent }, /* in MDI client */
1727
1728     /* bring the 1st MDI child to top */
1729     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
1730     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
1731
1732     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1733
1734     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
1735     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
1736     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
1737
1738     /* maximize the 1st MDI child */
1739     { HCBT_MINMAX, hook },
1740     { WM_GETMINMAXINFO, sent|defwinproc },
1741     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|0x8000 },
1742     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1743     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
1744     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1745     { WM_SIZE, sent|defwinproc },
1746
1747     /* restore the 2nd MDI child */
1748     { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
1749     { HCBT_MINMAX, hook },
1750     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOZORDER|0x8000 },
1751     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1752
1753     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1754
1755     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1756     { WM_SIZE, sent|defwinproc },
1757
1758     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1759
1760     { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
1761      /* in MDI frame */
1762     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1763     { WM_NCCALCSIZE, sent|wparam, 1 },
1764     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1765     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1766     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1767
1768     /* bring the 1st MDI child to top */
1769     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1770     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1771     { HCBT_SETFOCUS, hook },
1772     { WM_KILLFOCUS, sent|defwinproc },
1773     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
1774     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1775     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1776     { WM_SETFOCUS, sent }, /* in MDI client */
1777     { HCBT_SETFOCUS, hook },
1778     { WM_KILLFOCUS, sent }, /* in MDI client */
1779     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1780     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1781     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1782     { WM_SETFOCUS, sent|defwinproc },
1783     { WM_MDIACTIVATE, sent|defwinproc },
1784     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1785
1786     /* apparently ShowWindow(SW_SHOW) on an MDI client */
1787     { WM_SHOWWINDOW, sent|wparam, 1 },
1788     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1789     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1790     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1791     { WM_MDIREFRESHMENU, sent },
1792
1793     { HCBT_DESTROYWND, hook },
1794     /* Win2k sends wparam set to
1795      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1796      * while Win9x doesn't bother to set child window id according to
1797      * CLIENTCREATESTRUCT.idFirstChild
1798      */
1799     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1800     { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
1801     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1802     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1803     { WM_ERASEBKGND, sent|parent|optional },
1804     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1805
1806     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1807     { WM_DESTROY, sent|defwinproc },
1808     { WM_NCDESTROY, sent|defwinproc },
1809     { 0 }
1810 };
1811 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
1812 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
1813     { WM_MDIDESTROY, sent }, /* in MDI client */
1814     { WM_SHOWWINDOW, sent|wparam, 0 },
1815     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1816     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1817     { WM_ERASEBKGND, sent|parent|optional },
1818     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1819
1820     { HCBT_SETFOCUS, hook },
1821     { WM_KILLFOCUS, sent },
1822     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1823     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1824     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1825     { WM_SETFOCUS, sent }, /* in MDI client */
1826     { HCBT_SETFOCUS, hook },
1827     { WM_KILLFOCUS, sent }, /* in MDI client */
1828     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1829     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1830     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1831     { WM_SETFOCUS, sent },
1832
1833      /* in MDI child */
1834     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1835     { WM_NCCALCSIZE, sent|wparam, 1 },
1836     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1837     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1838
1839      /* in MDI frame */
1840     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1841     { WM_NCCALCSIZE, sent|wparam, 1 },
1842     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1843     { WM_MOVE, sent|defwinproc },
1844     { WM_SIZE, sent|defwinproc },
1845
1846      /* in MDI client */
1847     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
1848     { WM_NCCALCSIZE, sent|wparam, 1 },
1849     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
1850     { WM_SIZE, sent },
1851
1852      /* in MDI child */
1853     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
1854     { WM_NCCALCSIZE, sent|wparam, 1 },
1855     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
1856     { WM_SIZE, sent|defwinproc },
1857
1858      /* in MDI child */
1859     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1860     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
1861     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1862     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1863
1864      /* in MDI frame */
1865     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1866     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
1867     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1868     { WM_MOVE, sent|defwinproc },
1869     { WM_SIZE, sent|defwinproc },
1870
1871      /* in MDI client */
1872     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
1873     { WM_NCCALCSIZE, sent|wparam, 1 },
1874     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
1875     { WM_SIZE, sent },
1876
1877      /* in MDI child */
1878     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOZORDER },
1879     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
1880     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
1881     { WM_SIZE, sent|defwinproc },
1882     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1883     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
1884
1885     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
1886
1887     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1888     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1889     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
1890     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1891     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
1892
1893      /* in MDI frame */
1894     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1895     { WM_NCCALCSIZE, sent|wparam, 1 },
1896     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1897     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1898
1899     { WM_NCACTIVATE, sent|wparam, 0 },
1900     { WM_MDIACTIVATE, sent },
1901
1902     { HCBT_MINMAX, hook },
1903     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|0x8000 },
1904     { WM_NCCALCSIZE, sent|wparam, 1 },
1905
1906     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1907
1908     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1909     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE|0x8000 },
1910     { WM_SIZE, sent|defwinproc },
1911
1912      /* in MDI child */
1913     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1914     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
1915     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1916     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1917
1918      /* in MDI frame */
1919     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1920     { WM_NCCALCSIZE, sent|wparam, 1 },
1921     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1922     { WM_MOVE, sent|defwinproc },
1923     { WM_SIZE, sent|defwinproc },
1924
1925      /* in MDI client */
1926     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
1927     { WM_NCCALCSIZE, sent|wparam, 1 },
1928     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
1929     { WM_SIZE, sent },
1930     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1931     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
1932     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
1933     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1934     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
1935
1936     { HCBT_SETFOCUS, hook },
1937     { WM_KILLFOCUS, sent },
1938     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1939     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1940     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1941     { WM_SETFOCUS, sent }, /* in MDI client */
1942
1943     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
1944
1945     { HCBT_DESTROYWND, hook },
1946     /* Win2k sends wparam set to
1947      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1948      * while Win9x doesn't bother to set child window id according to
1949      * CLIENTCREATESTRUCT.idFirstChild
1950      */
1951     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1952
1953     { WM_SHOWWINDOW, sent|wparam, 0 },
1954     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1955     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1956     { WM_ERASEBKGND, sent|parent|optional },
1957     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1958
1959     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1960     { WM_DESTROY, sent },
1961     { WM_NCDESTROY, sent },
1962     { 0 }
1963 };
1964 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
1965 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
1966     { HCBT_MINMAX, hook },
1967     { WM_GETMINMAXINFO, sent },
1968     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
1969     { WM_NCCALCSIZE, sent|wparam, 1 },
1970     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1971     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1972
1973     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1974     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1975     { HCBT_SETFOCUS, hook },
1976     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1977     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1978     { WM_SETFOCUS, sent }, /* in MDI client */
1979     { HCBT_SETFOCUS, hook },
1980     { WM_KILLFOCUS, sent }, /* in MDI client */
1981     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1982     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1983     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1984     { WM_SETFOCUS, sent|defwinproc },
1985     { WM_MDIACTIVATE, sent|defwinproc },
1986     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1987     { WM_SIZE, sent|defwinproc },
1988      /* in MDI frame */
1989     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1990     { WM_NCCALCSIZE, sent|wparam, 1 },
1991     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1992     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1993     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1994     { 0 }
1995 };
1996 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
1997 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
1998     { HCBT_MINMAX, hook },
1999     { WM_GETMINMAXINFO, sent },
2000     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
2001     { WM_NCCALCSIZE, sent|wparam, 1 },
2002     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2003     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2004     { WM_SIZE, sent|defwinproc },
2005      /* in MDI frame */
2006     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
2007     { WM_NCCALCSIZE, sent|wparam, 1 },
2008     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2009     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2010     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2011     { 0 }
2012 };
2013 /* ShowWindow(SW_RESTORE) for a visible MDI child window */
2014 static const struct message WmRestoreMDIchildVisibleSeq[] = {
2015     { HCBT_MINMAX, hook },
2016     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
2017     { WM_NCCALCSIZE, sent|wparam, 1 },
2018     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2019     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2020     { WM_SIZE, sent|defwinproc },
2021      /* in MDI frame */
2022     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
2023     { WM_NCCALCSIZE, sent|wparam, 1 },
2024     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2025     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2026     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2027     { 0 }
2028 };
2029 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
2030 static const struct message WmRestoreMDIchildInisibleSeq[] = {
2031     { HCBT_MINMAX, hook },
2032     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
2033     { WM_NCCALCSIZE, sent|wparam, 1 },
2034     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2035     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2036     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
2037     { WM_SIZE, sent|defwinproc },
2038      /* in MDI frame */
2039     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
2040     { WM_NCCALCSIZE, sent|wparam, 1 },
2041     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2042     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2043     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2044     { 0 }
2045 };
2046
2047 static HWND mdi_client;
2048 static WNDPROC old_mdi_client_proc;
2049
2050 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2051 {
2052     struct message msg;
2053
2054     /* do not log painting messages */
2055     if (message != WM_PAINT &&
2056         message != WM_ERASEBKGND &&
2057         message != WM_NCPAINT &&
2058         message != WM_NCHITTEST &&
2059         message != WM_GETTEXT &&
2060         message != WM_MDIGETACTIVE &&
2061         message != WM_GETICON &&
2062         message != WM_DEVICECHANGE)
2063     {
2064         trace("mdi client: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
2065
2066         switch (message)
2067         {
2068             case WM_WINDOWPOSCHANGING:
2069             case WM_WINDOWPOSCHANGED:
2070             {
2071                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2072
2073                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2074                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2075                       winpos->hwnd, winpos->hwndInsertAfter,
2076                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2077
2078                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2079                  * in the high word for internal purposes
2080                  */
2081                 wParam = winpos->flags & 0xffff;
2082                 break;
2083             }
2084         }
2085
2086         msg.message = message;
2087         msg.flags = sent|wparam|lparam;
2088         msg.wParam = wParam;
2089         msg.lParam = lParam;
2090         add_message(&msg);
2091     }
2092
2093     return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
2094 }
2095
2096 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2097 {
2098     static long defwndproc_counter = 0;
2099     LRESULT ret;
2100     struct message msg;
2101
2102     /* do not log painting messages */
2103     if (message != WM_PAINT &&
2104         message != WM_ERASEBKGND &&
2105         message != WM_NCPAINT &&
2106         message != WM_NCHITTEST &&
2107         message != WM_GETTEXT &&
2108         message != WM_GETICON &&
2109         message != WM_DEVICECHANGE)
2110     {
2111         trace("mdi child: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
2112
2113         switch (message)
2114         {
2115             case WM_WINDOWPOSCHANGING:
2116             case WM_WINDOWPOSCHANGED:
2117             {
2118                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2119
2120                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2121                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2122                       winpos->hwnd, winpos->hwndInsertAfter,
2123                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2124
2125                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2126                  * in the high word for internal purposes
2127                  */
2128                 wParam = winpos->flags & 0xffff;
2129                 break;
2130             }
2131
2132             case WM_MDIACTIVATE:
2133             {
2134                 HWND active, client = GetParent(hwnd);
2135
2136                 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
2137
2138                 if (hwnd == (HWND)lParam) /* if we are being activated */
2139                     ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
2140                 else
2141                     ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
2142                 break;
2143             }
2144         }
2145
2146         msg.message = message;
2147         msg.flags = sent|wparam|lparam;
2148         if (defwndproc_counter) msg.flags |= defwinproc;
2149         msg.wParam = wParam;
2150         msg.lParam = lParam;
2151         add_message(&msg);
2152     }
2153
2154     defwndproc_counter++;
2155     ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
2156     defwndproc_counter--;
2157
2158     return ret;
2159 }
2160
2161 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2162 {
2163     static long defwndproc_counter = 0;
2164     LRESULT ret;
2165     struct message msg;
2166
2167     /* do not log painting messages */
2168     if (message != WM_PAINT &&
2169         message != WM_ERASEBKGND &&
2170         message != WM_NCPAINT &&
2171         message != WM_NCHITTEST &&
2172         message != WM_GETTEXT &&
2173         message != WM_GETICON &&
2174         message != WM_DEVICECHANGE)
2175     {
2176         trace("mdi frame: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
2177
2178         switch (message)
2179         {
2180             case WM_WINDOWPOSCHANGING:
2181             case WM_WINDOWPOSCHANGED:
2182             {
2183                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2184
2185                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2186                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2187                       winpos->hwnd, winpos->hwndInsertAfter,
2188                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2189
2190                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2191                  * in the high word for internal purposes
2192                  */
2193                 wParam = winpos->flags & 0xffff;
2194                 break;
2195             }
2196         }
2197
2198         msg.message = message;
2199         msg.flags = sent|wparam|lparam;
2200         if (defwndproc_counter) msg.flags |= defwinproc;
2201         msg.wParam = wParam;
2202         msg.lParam = lParam;
2203         add_message(&msg);
2204     }
2205
2206     defwndproc_counter++;
2207     ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
2208     defwndproc_counter--;
2209
2210     return ret;
2211 }
2212
2213 static BOOL mdi_RegisterWindowClasses(void)
2214 {
2215     WNDCLASSA cls;
2216
2217     cls.style = 0;
2218     cls.lpfnWndProc = mdi_frame_wnd_proc;
2219     cls.cbClsExtra = 0;
2220     cls.cbWndExtra = 0;
2221     cls.hInstance = GetModuleHandleA(0);
2222     cls.hIcon = 0;
2223     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
2224     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
2225     cls.lpszMenuName = NULL;
2226     cls.lpszClassName = "MDI_frame_class";
2227     if (!RegisterClassA(&cls)) return FALSE;
2228
2229     cls.lpfnWndProc = mdi_child_wnd_proc;
2230     cls.lpszClassName = "MDI_child_class";
2231     if (!RegisterClassA(&cls)) return FALSE;
2232
2233     if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
2234     old_mdi_client_proc = cls.lpfnWndProc;
2235     cls.hInstance = GetModuleHandleA(0);
2236     cls.lpfnWndProc = mdi_client_hook_proc;
2237     cls.lpszClassName = "MDI_client_class";
2238     if (!RegisterClassA(&cls)) assert(0);
2239
2240     return TRUE;
2241 }
2242
2243 static void test_mdi_messages(void)
2244 {
2245     MDICREATESTRUCTA mdi_cs;
2246     CLIENTCREATESTRUCT client_cs;
2247     HWND mdi_frame, mdi_child, mdi_child2, active_child;
2248     BOOL zoomed;
2249     HMENU hMenu = CreateMenu();
2250
2251     assert(mdi_RegisterWindowClasses());
2252
2253     flush_sequence();
2254
2255     trace("creating MDI frame window\n");
2256     mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
2257                                 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2258                                 WS_MAXIMIZEBOX | WS_VISIBLE,
2259                                 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
2260                                 GetDesktopWindow(), hMenu,
2261                                 GetModuleHandleA(0), NULL);
2262     assert(mdi_frame);
2263     ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", TRUE);
2264
2265     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2266     ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
2267
2268     trace("creating MDI client window\n");
2269     client_cs.hWindowMenu = 0;
2270     client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
2271     mdi_client = CreateWindowExA(0, "MDI_client_class",
2272                                  NULL,
2273                                  WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
2274                                  0, 0, 0, 0,
2275                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
2276     assert(mdi_client);
2277     ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
2278
2279     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2280     ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
2281
2282     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2283     ok(!active_child, "wrong active MDI child %p\n", active_child);
2284     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2285
2286     SetFocus(0);
2287     flush_sequence();
2288
2289     trace("creating invisible MDI child window\n");
2290     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2291                                 WS_CHILD,
2292                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2293                                 mdi_client, 0, GetModuleHandleA(0), NULL);
2294     assert(mdi_child);
2295
2296     flush_sequence();
2297     ShowWindow(mdi_child, SW_SHOWNORMAL);
2298     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
2299
2300     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2301     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
2302
2303     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2304     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2305
2306     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2307     ok(!active_child, "wrong active MDI child %p\n", active_child);
2308     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2309
2310     ShowWindow(mdi_child, SW_HIDE);
2311     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
2312     flush_sequence();
2313
2314     ShowWindow(mdi_child, SW_SHOW);
2315     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
2316
2317     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2318     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
2319
2320     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2321     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2322
2323     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2324     ok(!active_child, "wrong active MDI child %p\n", active_child);
2325     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2326
2327     DestroyWindow(mdi_child);
2328     flush_sequence();
2329
2330     trace("creating visible MDI child window\n");
2331     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2332                                 WS_CHILD | WS_VISIBLE,
2333                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2334                                 mdi_client, 0, GetModuleHandleA(0), NULL);
2335     assert(mdi_child);
2336     ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
2337
2338     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2339     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
2340
2341     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2342     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
2343
2344     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2345     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
2346     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2347     flush_sequence();
2348
2349     DestroyWindow(mdi_child);
2350     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
2351
2352     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2353     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2354
2355     /* Win2k: MDI client still returns a just destroyed child as active
2356      * Win9x: MDI client returns 0
2357      */
2358     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2359     ok(active_child == mdi_child || /* win2k */
2360        !active_child, /* win9x */
2361        "wrong active MDI child %p\n", active_child);
2362     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2363
2364     flush_sequence();
2365
2366     trace("creating invisible MDI child window\n");
2367     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2368                                 WS_CHILD,
2369                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2370                                 mdi_client, 0, GetModuleHandleA(0), NULL);
2371     assert(mdi_child2);
2372     ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
2373
2374     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
2375     ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
2376
2377     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2378     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2379
2380     /* Win2k: MDI client still returns a just destroyed child as active
2381      * Win9x: MDI client returns mdi_child2
2382      */
2383     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2384     ok(active_child == mdi_child || /* win2k */
2385        active_child == mdi_child2, /* win9x */
2386        "wrong active MDI child %p\n", active_child);
2387     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2388     flush_sequence();
2389
2390     ShowWindow(mdi_child2, SW_MAXIMIZE);
2391     ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", TRUE);
2392
2393     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2394     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
2395
2396     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2397     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
2398     ok(zoomed, "wrong zoomed state %d\n", zoomed);
2399     flush_sequence();
2400
2401     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2402     ok(GetFocus() == mdi_child2 || /* win2k */
2403        GetFocus() == 0, /* win9x */
2404        "wrong focus window %p\n", GetFocus());
2405
2406     SetFocus(0);
2407     flush_sequence();
2408
2409     ShowWindow(mdi_child2, SW_HIDE);
2410     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
2411
2412     ShowWindow(mdi_child2, SW_RESTORE);
2413     ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", TRUE);
2414     flush_sequence();
2415
2416     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2417     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
2418
2419     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2420     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
2421     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2422     flush_sequence();
2423
2424     SetFocus(0);
2425     flush_sequence();
2426
2427     ShowWindow(mdi_child2, SW_HIDE);
2428     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
2429
2430     ShowWindow(mdi_child2, SW_SHOW);
2431     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
2432
2433     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2434     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2435
2436     ShowWindow(mdi_child2, SW_MAXIMIZE);
2437     ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", TRUE);
2438
2439     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2440     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2441
2442     ShowWindow(mdi_child2, SW_RESTORE);
2443     ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):MDI child", TRUE);
2444
2445     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2446     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2447
2448     SetFocus(0);
2449     flush_sequence();
2450
2451     ShowWindow(mdi_child2, SW_HIDE);
2452     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
2453
2454     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2455     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2456
2457     DestroyWindow(mdi_child2);
2458     ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
2459
2460     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2461     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2462
2463     /* test for maximized MDI children */
2464     trace("creating maximized visible MDI child window 1\n");
2465     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2466                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
2467                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2468                                 mdi_client, 0, GetModuleHandleA(0), NULL);
2469     assert(mdi_child);
2470     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
2471     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
2472
2473     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2474     ok(GetFocus() == mdi_child || /* win2k */
2475        GetFocus() == 0, /* win9x */
2476        "wrong focus window %p\n", GetFocus());
2477
2478     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2479     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
2480     ok(zoomed, "wrong zoomed state %d\n", zoomed);
2481     flush_sequence();
2482
2483     trace("creating maximized visible MDI child window 2\n");
2484     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2485                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
2486                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2487                                 mdi_client, 0, GetModuleHandleA(0), NULL);
2488     assert(mdi_child2);
2489     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
2490     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
2491     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
2492
2493     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2494     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
2495
2496     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2497     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
2498     ok(zoomed, "wrong zoomed state %d\n", zoomed);
2499     flush_sequence();
2500
2501     trace("destroying maximized visible MDI child window 2\n");
2502     DestroyWindow(mdi_child2);
2503     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
2504
2505     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
2506
2507     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2508     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2509
2510     /* Win2k: MDI client still returns a just destroyed child as active
2511      * Win9x: MDI client returns 0
2512      */
2513     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2514     ok(active_child == mdi_child2 || /* win2k */
2515        !active_child, /* win9x */
2516        "wrong active MDI child %p\n", active_child);
2517     flush_sequence();
2518
2519     ShowWindow(mdi_child, SW_MAXIMIZE);
2520     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
2521     flush_sequence();
2522
2523     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2524     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
2525
2526     trace("re-creating maximized visible MDI child window 2\n");
2527     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2528                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
2529                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2530                                 mdi_client, 0, GetModuleHandleA(0), NULL);
2531     assert(mdi_child2);
2532     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
2533     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
2534     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
2535
2536     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2537     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
2538
2539     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2540     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
2541     ok(zoomed, "wrong zoomed state %d\n", zoomed);
2542     flush_sequence();
2543
2544     SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
2545     ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
2546     ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
2547
2548     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
2549     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2550     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
2551
2552     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2553     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
2554     ok(zoomed, "wrong zoomed state %d\n", zoomed);
2555     flush_sequence();
2556
2557     DestroyWindow(mdi_child);
2558     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
2559
2560     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2561     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2562
2563     /* Win2k: MDI client still returns a just destroyed child as active
2564      * Win9x: MDI client returns 0
2565      */
2566     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2567     ok(active_child == mdi_child || /* win2k */
2568        !active_child, /* win9x */
2569        "wrong active MDI child %p\n", active_child);
2570     flush_sequence();
2571     /* end of test for maximized MDI children */
2572
2573     mdi_cs.szClass = "MDI_child_Class";
2574     mdi_cs.szTitle = "MDI child";
2575     mdi_cs.hOwner = GetModuleHandleA(0);
2576     mdi_cs.x = 0;
2577     mdi_cs.y = 0;
2578     mdi_cs.cx = CW_USEDEFAULT;
2579     mdi_cs.cy = CW_USEDEFAULT;
2580     mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
2581     mdi_cs.lParam = 0;
2582     mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
2583     ok(mdi_child != 0, "MDI child creation failed\n");
2584     ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
2585
2586     ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
2587
2588     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2589     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
2590
2591     ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
2592     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2593     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
2594
2595     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2596     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
2597     ok(zoomed, "wrong zoomed state %d\n", zoomed);
2598     flush_sequence();
2599
2600     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
2601     ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
2602
2603     ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
2604     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2605     ok(!active_child, "wrong active MDI child %p\n", active_child);
2606
2607     SetFocus(0);
2608     flush_sequence();
2609
2610     DestroyWindow(mdi_client);
2611     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
2612
2613     DestroyWindow(mdi_frame);
2614     ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
2615 }
2616 /************************* End of MDI test **********************************/
2617
2618 static void test_WM_SETREDRAW(HWND hwnd)
2619 {
2620     DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
2621
2622     flush_sequence();
2623
2624     SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
2625     ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
2626
2627     ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
2628     ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
2629
2630     flush_sequence();
2631     SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
2632     ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
2633
2634     ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
2635     ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
2636
2637     /* restore original WS_VISIBLE state */
2638     SetWindowLongA(hwnd, GWL_STYLE, style);
2639
2640     flush_sequence();
2641 }
2642
2643 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2644 {
2645     struct message msg;
2646
2647     trace("dialog: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
2648
2649     /* explicitly ignore WM_GETICON message */
2650     if (message == WM_GETICON) return 0;
2651
2652     switch (message)
2653     {
2654         case WM_WINDOWPOSCHANGING:
2655         case WM_WINDOWPOSCHANGED:
2656         {
2657             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2658
2659             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2660             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2661                   winpos->hwnd, winpos->hwndInsertAfter,
2662                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2663
2664             /* Log only documented flags, win2k uses 0x1000 and 0x2000
2665              * in the high word for internal purposes
2666              */
2667             wParam = winpos->flags & 0xffff;
2668             break;
2669         }
2670     }
2671
2672     msg.message = message;
2673     msg.flags = sent|wparam|lparam;
2674     msg.wParam = wParam;
2675     msg.lParam = lParam;
2676     add_message(&msg);
2677
2678     if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
2679     if (message == WM_TIMER) EndDialog( hwnd, 0 );
2680     return 0;
2681 }
2682
2683 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
2684 {
2685     DWORD style, exstyle;
2686     INT xmin, xmax;
2687     BOOL ret;
2688
2689     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
2690     style = GetWindowLongA(hwnd, GWL_STYLE);
2691     /* do not be confused by WS_DLGFRAME set */
2692     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
2693
2694     if (clear) ok(style & clear, "style %08lx should be set\n", clear);
2695     if (set) ok(!(style & set), "style %08lx should not be set\n", set);
2696
2697     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
2698     ok( ret, "SetScrollRange(%d) error %ld\n", ctl, GetLastError());
2699     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
2700         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
2701     else
2702         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
2703
2704     style = GetWindowLongA(hwnd, GWL_STYLE);
2705     if (set) ok(style & set, "style %08lx should be set\n", set);
2706     if (clear) ok(!(style & clear), "style %08lx should not be set\n", clear);
2707
2708     /* a subsequent call should do nothing */
2709     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
2710     ok( ret, "SetScrollRange(%d) error %ld\n", ctl, GetLastError());
2711     ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
2712
2713     xmin = 0xdeadbeef;
2714     xmax = 0xdeadbeef;
2715     trace("Ignore GetScrollRange error below if you are on Win9x\n");
2716     ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
2717     ok( ret, "GetScrollRange(%d) error %ld\n", ctl, GetLastError());
2718     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
2719     ok(xmin == min, "unexpected min scroll value %d\n", xmin);
2720     ok(xmax == max, "unexpected max scroll value %d\n", xmax);
2721 }
2722
2723 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
2724 {
2725     DWORD style, exstyle;
2726     SCROLLINFO si;
2727     BOOL ret;
2728
2729     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
2730     style = GetWindowLongA(hwnd, GWL_STYLE);
2731     /* do not be confused by WS_DLGFRAME set */
2732     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
2733
2734     if (clear) ok(style & clear, "style %08lx should be set\n", clear);
2735     if (set) ok(!(style & set), "style %08lx should not be set\n", set);
2736
2737     si.cbSize = sizeof(si);
2738     si.fMask = SIF_RANGE;
2739     si.nMin = min;
2740     si.nMax = max;
2741     SetScrollInfo(hwnd, ctl, &si, TRUE);
2742     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
2743         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
2744     else
2745         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
2746
2747     style = GetWindowLongA(hwnd, GWL_STYLE);
2748     if (set) ok(style & set, "style %08lx should be set\n", set);
2749     if (clear) ok(!(style & clear), "style %08lx should not be set\n", clear);
2750
2751     /* a subsequent call should do nothing */
2752     SetScrollInfo(hwnd, ctl, &si, TRUE);
2753     if (style & WS_HSCROLL)
2754         ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
2755     else if (style & WS_VSCROLL)
2756         ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
2757     else
2758         ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
2759
2760     si.fMask = SIF_PAGE;
2761     si.nPage = 5;
2762     SetScrollInfo(hwnd, ctl, &si, FALSE);
2763     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
2764
2765     si.fMask = SIF_POS;
2766     si.nPos = max - 1;
2767     SetScrollInfo(hwnd, ctl, &si, FALSE);
2768     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
2769
2770     si.fMask = SIF_RANGE;
2771     si.nMin = 0xdeadbeef;
2772     si.nMax = 0xdeadbeef;
2773     ret = GetScrollInfo(hwnd, ctl, &si);
2774     ok( ret, "GetScrollInfo error %ld\n", GetLastError());
2775     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
2776     ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
2777     ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
2778 }
2779
2780 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
2781 static void test_scroll_messages(HWND hwnd)
2782 {
2783     SCROLLINFO si;
2784     INT min, max;
2785     BOOL ret;
2786
2787     min = 0xdeadbeef;
2788     max = 0xdeadbeef;
2789     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
2790     ok( ret, "GetScrollRange error %ld\n", GetLastError());
2791     if (sequence->message != WmGetScrollRangeSeq[0].message)
2792         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
2793     /* values of min and max are undefined */
2794     flush_sequence();
2795
2796     ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
2797     ok( ret, "SetScrollRange error %ld\n", GetLastError());
2798     if (sequence->message != WmSetScrollRangeSeq[0].message)
2799         trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
2800     flush_sequence();
2801
2802     min = 0xdeadbeef;
2803     max = 0xdeadbeef;
2804     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
2805     ok( ret, "GetScrollRange error %ld\n", GetLastError());
2806     if (sequence->message != WmGetScrollRangeSeq[0].message)
2807         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
2808     /* values of min and max are undefined */
2809     flush_sequence();
2810
2811     si.cbSize = sizeof(si);
2812     si.fMask = SIF_RANGE;
2813     si.nMin = 20;
2814     si.nMax = 160;
2815     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
2816     if (sequence->message != WmSetScrollRangeSeq[0].message)
2817         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
2818     flush_sequence();
2819
2820     si.fMask = SIF_PAGE;
2821     si.nPage = 10;
2822     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
2823     if (sequence->message != WmSetScrollRangeSeq[0].message)
2824         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
2825     flush_sequence();
2826
2827     si.fMask = SIF_POS;
2828     si.nPos = 20;
2829     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
2830     if (sequence->message != WmSetScrollRangeSeq[0].message)
2831         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
2832     flush_sequence();
2833
2834     si.fMask = SIF_RANGE;
2835     si.nMin = 0xdeadbeef;
2836     si.nMax = 0xdeadbeef;
2837     ret = GetScrollInfo(hwnd, SB_CTL, &si);
2838     ok( ret, "GetScrollInfo error %ld\n", GetLastError());
2839     if (sequence->message != WmGetScrollInfoSeq[0].message)
2840         trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
2841     /* values of min and max are undefined */
2842     flush_sequence();
2843
2844     /* set WS_HSCROLL */
2845     test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
2846     /* clear WS_HSCROLL */
2847     test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
2848
2849     /* set WS_HSCROLL */
2850     test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
2851     /* clear WS_HSCROLL */
2852     test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
2853
2854     /* set WS_VSCROLL */
2855     test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
2856     /* clear WS_VSCROLL */
2857     test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
2858
2859     /* set WS_VSCROLL */
2860     test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
2861     /* clear WS_VSCROLL */
2862     test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
2863 }
2864
2865 static void test_showwindow(void)
2866 {
2867     HWND hwnd, hchild;
2868
2869     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
2870                            100, 100, 200, 200, 0, 0, 0, NULL);
2871     ok (hwnd != 0, "Failed to create overlapped window\n");
2872     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
2873                              0, 0, 10, 10, hwnd, 0, 0, NULL);
2874     ok (hchild != 0, "Failed to create child\n");
2875     flush_sequence();
2876
2877     /* ShowWindow( SW_SHOWNA) for invisible top level window */
2878     trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
2879     ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
2880     ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", TRUE);
2881     trace("done\n");
2882
2883     /* ShowWindow( SW_SHOWNA) for now visible top level window */
2884     trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
2885     ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
2886     ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
2887     trace("done\n");
2888     /* back to invisible */
2889     ShowWindow(hchild, SW_HIDE);
2890     ShowWindow(hwnd, SW_HIDE);
2891     flush_sequence();
2892     /* ShowWindow(SW_SHOWNA) with child and parent invisible */ 
2893     trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
2894     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
2895     ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
2896     trace("done\n");
2897     /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */ 
2898     ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
2899     flush_sequence();
2900     trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
2901     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
2902     ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
2903     trace("done\n");
2904     /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
2905     ShowWindow( hwnd, SW_SHOW);
2906     flush_sequence();
2907     trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
2908     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
2909     ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
2910     trace("done\n");
2911
2912     /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
2913     ShowWindow( hchild, SW_HIDE);
2914     flush_sequence();
2915     trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
2916     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
2917     ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
2918     trace("done\n");
2919
2920     SetCapture(hchild);
2921     ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
2922     DestroyWindow(hchild);
2923     ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
2924
2925     DestroyWindow(hwnd);
2926     flush_sequence();
2927 }
2928
2929 static void test_sys_menu(HWND hwnd)
2930 {
2931     HMENU hmenu;
2932     UINT state;
2933
2934     /* test existing window without CS_NOCLOSE style */
2935     hmenu = GetSystemMenu(hwnd, FALSE);
2936     ok(hmenu != 0, "GetSystemMenu error %ld\n", GetLastError());
2937
2938     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
2939     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
2940     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
2941
2942     EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
2943     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
2944
2945     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
2946     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
2947     ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
2948
2949     EnableMenuItem(hmenu, SC_CLOSE, 0);
2950     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
2951
2952     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
2953     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
2954     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
2955
2956     /* test new window with CS_NOCLOSE style */
2957     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
2958                            100, 100, 200, 200, 0, 0, 0, NULL);
2959     ok (hwnd != 0, "Failed to create overlapped window\n");
2960
2961     hmenu = GetSystemMenu(hwnd, FALSE);
2962     ok(hmenu != 0, "GetSystemMenu error %ld\n", GetLastError());
2963
2964     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
2965     ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
2966
2967     DestroyWindow(hwnd);
2968 }
2969
2970 /* test if we receive the right sequence of messages */
2971 static void test_messages(void)
2972 {
2973     HWND hwnd, hparent, hchild;
2974     HWND hchild2, hbutton;
2975     HMENU hmenu;
2976     MSG msg;
2977     DWORD ret;
2978
2979     flush_sequence();
2980
2981     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
2982                            100, 100, 200, 200, 0, 0, 0, NULL);
2983     ok (hwnd != 0, "Failed to create overlapped window\n");
2984     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
2985
2986     /* test ShowWindow(SW_HIDE) on a newly created invisible window */
2987     ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
2988     ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
2989
2990     /* test WM_SETREDRAW on a not visible top level window */
2991     test_WM_SETREDRAW(hwnd);
2992
2993     SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
2994     ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
2995     ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
2996
2997     ok(GetActiveWindow() == hwnd, "window should be active\n");
2998     ok(GetFocus() == hwnd, "window should have input focus\n");
2999     ShowWindow(hwnd, SW_HIDE);
3000     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", TRUE);
3001
3002     ShowWindow(hwnd, SW_SHOW);
3003     ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
3004
3005     ShowWindow(hwnd, SW_HIDE);
3006     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
3007
3008     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3009     ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
3010
3011     ShowWindow(hwnd, SW_RESTORE);
3012     /* FIXME: add ok_sequence() here */
3013     flush_sequence();
3014
3015     ShowWindow(hwnd, SW_SHOW);
3016     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
3017
3018     ok(GetActiveWindow() == hwnd, "window should be active\n");
3019     ok(GetFocus() == hwnd, "window should have input focus\n");
3020     SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
3021     ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
3022     ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
3023     ok(GetActiveWindow() == hwnd, "window should still be active\n");
3024
3025     /* test WM_SETREDRAW on a visible top level window */
3026     ShowWindow(hwnd, SW_SHOW);
3027     test_WM_SETREDRAW(hwnd);
3028
3029     trace("testing scroll APIs on a visible top level window %p\n", hwnd);
3030     test_scroll_messages(hwnd);
3031
3032     /* test resizing and moving */
3033     SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE );
3034     ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
3035     SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE );
3036     ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
3037
3038     /* popups don't get WM_GETMINMAXINFO */
3039     SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
3040     SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
3041     flush_sequence();
3042     SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE );
3043     ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
3044
3045     test_sys_menu(hwnd);
3046
3047     flush_sequence();
3048     DestroyWindow(hwnd);
3049     ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
3050
3051     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3052                               100, 100, 200, 200, 0, 0, 0, NULL);
3053     ok (hparent != 0, "Failed to create parent window\n");
3054     flush_sequence();
3055
3056     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
3057                              0, 0, 10, 10, hparent, 0, 0, NULL);
3058     ok (hchild != 0, "Failed to create child window\n");
3059     ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", TRUE);
3060     DestroyWindow(hchild);
3061     flush_sequence();
3062
3063     /* visible child window with a caption */
3064     hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
3065                              WS_CHILD | WS_VISIBLE | WS_CAPTION,
3066                              0, 0, 10, 10, hparent, 0, 0, NULL);
3067     ok (hchild != 0, "Failed to create child window\n");
3068     ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
3069
3070     trace("testing scroll APIs on a visible child window %p\n", hchild);
3071     test_scroll_messages(hchild);
3072
3073     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
3074     ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
3075
3076     DestroyWindow(hchild);
3077     flush_sequence();
3078
3079     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
3080                              0, 0, 10, 10, hparent, 0, 0, NULL);
3081     ok (hchild != 0, "Failed to create child window\n");
3082     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
3083     
3084     hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
3085                                100, 100, 50, 50, hparent, 0, 0, NULL);
3086     ok (hchild2 != 0, "Failed to create child2 window\n");
3087     flush_sequence();
3088
3089     hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
3090                               0, 100, 50, 50, hchild, 0, 0, NULL);
3091     ok (hbutton != 0, "Failed to create button window\n");
3092
3093     /* test WM_SETREDRAW on a not visible child window */
3094     test_WM_SETREDRAW(hchild);
3095
3096     ShowWindow(hchild, SW_SHOW);
3097     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
3098
3099     ShowWindow(hchild, SW_HIDE);
3100     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
3101
3102     ShowWindow(hchild, SW_SHOW);
3103     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
3104
3105     /* test WM_SETREDRAW on a visible child window */
3106     test_WM_SETREDRAW(hchild);
3107
3108     MoveWindow(hchild, 10, 10, 20, 20, TRUE);
3109     ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
3110
3111     ShowWindow(hchild, SW_HIDE);
3112     flush_sequence();
3113     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
3114     ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
3115
3116     ShowWindow(hchild, SW_HIDE);
3117     flush_sequence();
3118     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
3119     ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
3120
3121     /* DestroyWindow sequence below expects that a child has focus */
3122     SetFocus(hchild);
3123     flush_sequence();
3124
3125     DestroyWindow(hchild);
3126     ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
3127     DestroyWindow(hchild2);
3128     DestroyWindow(hbutton);
3129
3130     flush_sequence();
3131     hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
3132                              0, 0, 100, 100, hparent, 0, 0, NULL);
3133     ok (hchild != 0, "Failed to create child popup window\n");
3134     ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
3135     DestroyWindow(hchild);
3136
3137     /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
3138     flush_sequence();
3139     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
3140                              0, 0, 100, 100, hparent, 0, 0, NULL);
3141     ok (hchild != 0, "Failed to create popup window\n");
3142     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
3143     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3144     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
3145     flush_sequence();
3146     ShowWindow(hchild, SW_SHOW);
3147     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
3148     flush_sequence();
3149     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
3150     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
3151     flush_sequence();
3152     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
3153     ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
3154     DestroyWindow(hchild);
3155
3156     /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
3157      * changes nothing in message sequences.
3158      */
3159     flush_sequence();
3160     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
3161                              0, 0, 100, 100, hparent, 0, 0, NULL);
3162     ok (hchild != 0, "Failed to create popup window\n");
3163     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
3164     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3165     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
3166     flush_sequence();
3167     ShowWindow(hchild, SW_SHOW);
3168     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
3169     flush_sequence();
3170     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
3171     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
3172     DestroyWindow(hchild);
3173
3174     flush_sequence();
3175     hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
3176                            0, 0, 100, 100, hparent, 0, 0, NULL);
3177     ok(hwnd != 0, "Failed to create custom dialog window\n");
3178     ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
3179
3180     /*
3181     trace("testing scroll APIs on a visible dialog %p\n", hwnd);
3182     test_scroll_messages(hwnd);
3183     */
3184
3185     flush_sequence();
3186     after_end_dialog = 1;
3187     EndDialog( hwnd, 0 );
3188     ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
3189
3190     DestroyWindow(hwnd);
3191     after_end_dialog = 0;
3192
3193     hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
3194                            0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
3195     ok(hwnd != 0, "Failed to create custom dialog window\n");
3196     flush_sequence();
3197     trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
3198     ShowWindow(hwnd, SW_SHOW);
3199     ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
3200     DestroyWindow(hwnd);
3201
3202     flush_sequence();
3203     DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
3204     ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
3205
3206     /* test showing child with hidden parent */
3207     ShowWindow( hparent, SW_HIDE );
3208     flush_sequence();
3209
3210     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
3211                              0, 0, 10, 10, hparent, 0, 0, NULL);
3212     ok (hchild != 0, "Failed to create child window\n");
3213     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
3214
3215     ShowWindow( hchild, SW_SHOW );
3216     ok_sequence(WmShowChildInvisibleParentSeq, "ShowWindow:show child with invisible parent", FALSE);
3217     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3218     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
3219
3220     ShowWindow( hchild, SW_HIDE );
3221     ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
3222     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
3223     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
3224
3225     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
3226     ok_sequence(WmShowChildInvisibleParentSeq_2, "SetWindowPos:show child with invisible parent", FALSE);
3227     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3228     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
3229
3230     SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
3231     ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
3232     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
3233     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
3234
3235     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
3236     flush_sequence();
3237     DestroyWindow(hchild);
3238     ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
3239
3240     DestroyWindow(hparent);
3241     flush_sequence();
3242
3243     /* Message sequence for SetMenu */
3244     ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
3245     ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
3246
3247     hmenu = CreateMenu();
3248     ok (hmenu != 0, "Failed to create menu\n");
3249     ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
3250     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
3251                            100, 100, 200, 200, 0, hmenu, 0, NULL);
3252     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
3253     ok (SetMenu(hwnd, 0), "SetMenu\n");
3254     ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
3255     ok (SetMenu(hwnd, 0), "SetMenu\n");
3256     ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
3257     ShowWindow(hwnd, SW_SHOW);
3258     UpdateWindow( hwnd );
3259     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3260     flush_sequence();
3261     ok (SetMenu(hwnd, 0), "SetMenu\n");
3262     ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
3263     ok (SetMenu(hwnd, hmenu), "SetMenu\n");
3264     ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
3265
3266     UpdateWindow( hwnd );
3267     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3268     flush_sequence();
3269     ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
3270     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3271     ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
3272
3273     DestroyWindow(hwnd);
3274     flush_sequence();
3275
3276     /* Message sequence for EnableWindow */
3277     hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3278                               100, 100, 200, 200, 0, 0, 0, NULL);
3279     ok (hparent != 0, "Failed to create parent window\n");
3280     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
3281                              0, 0, 10, 10, hparent, 0, 0, NULL);
3282     ok (hchild != 0, "Failed to create child window\n");
3283
3284     SetFocus(hchild);
3285     flush_sequence();
3286
3287     EnableWindow(hparent, FALSE);
3288     ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
3289
3290     EnableWindow(hparent, TRUE);
3291     ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
3292
3293     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3294     flush_sequence();
3295
3296     /* MsgWaitForMultipleObjects test */
3297     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3298     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %lx\n", ret);
3299
3300     PostMessageA(hparent, WM_USER, 0, 0);
3301
3302     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3303     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %lx\n", ret);
3304
3305     ok(PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
3306     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
3307
3308     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3309     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %lx\n", ret);
3310     /* end of MsgWaitForMultipleObjects test */
3311
3312     /* the following test causes an exception in user.exe under win9x */
3313     if (!PostMessageW( hparent, WM_USER, 0, 0 )) return;
3314     PostMessageW( hparent, WM_USER+1, 0, 0 );
3315     /* PeekMessage(NULL) fails, but still removes the message */
3316     SetLastError(0xdeadbeef);
3317     ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
3318     ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
3319         GetLastError() == 0xdeadbeef, /* NT4 */
3320         "last error is %ld\n", GetLastError() );
3321     ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
3322     ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
3323
3324     DestroyWindow(hchild);
3325     DestroyWindow(hparent);
3326     flush_sequence();
3327
3328     test_showwindow();
3329 }
3330
3331 /****************** button message test *************************/
3332 static const struct message WmSetFocusButtonSeq[] =
3333 {
3334     { HCBT_SETFOCUS, hook },
3335     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3336     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3337     { WM_SETFOCUS, sent|wparam, 0 },
3338     { WM_CTLCOLORBTN, sent|defwinproc },
3339     { 0 }
3340 };
3341 static const struct message WmKillFocusButtonSeq[] =
3342 {
3343     { HCBT_SETFOCUS, hook },
3344     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3345     { WM_KILLFOCUS, sent|wparam, 0 },
3346     { WM_CTLCOLORBTN, sent|defwinproc },
3347     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
3348     { 0 }
3349 };
3350 static const struct message WmSetFocusStaticSeq[] =
3351 {
3352     { HCBT_SETFOCUS, hook },
3353     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3354     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3355     { WM_SETFOCUS, sent|wparam, 0 },
3356     { WM_CTLCOLORSTATIC, sent|defwinproc },
3357     { 0 }
3358 };
3359 static const struct message WmKillFocusStaticSeq[] =
3360 {
3361     { HCBT_SETFOCUS, hook },
3362     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3363     { WM_KILLFOCUS, sent|wparam, 0 },
3364     { WM_CTLCOLORSTATIC, sent|defwinproc },
3365     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
3366     { 0 }
3367 };
3368 static const struct message WmLButtonDownSeq[] =
3369 {
3370     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
3371     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
3372     { HCBT_SETFOCUS, hook },
3373     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3374     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3375     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
3376     { WM_CTLCOLORBTN, sent|defwinproc },
3377     { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
3378     { WM_CTLCOLORBTN, sent|defwinproc },
3379     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3380     { 0 }
3381 };
3382 static const struct message WmLButtonUpSeq[] =
3383 {
3384     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
3385     { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
3386     { WM_CTLCOLORBTN, sent|defwinproc },
3387     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3388     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
3389     { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
3390     { 0 }
3391 };
3392
3393 static WNDPROC old_button_proc;
3394
3395 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3396 {
3397     static long defwndproc_counter = 0;
3398     LRESULT ret;
3399     struct message msg;
3400
3401     trace("button: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
3402
3403     /* explicitly ignore WM_GETICON message */
3404     if (message == WM_GETICON) return 0;
3405
3406     msg.message = message;
3407     msg.flags = sent|wparam|lparam;
3408     if (defwndproc_counter) msg.flags |= defwinproc;
3409     msg.wParam = wParam;
3410     msg.lParam = lParam;
3411     add_message(&msg);
3412
3413     if (message == BM_SETSTATE)
3414         ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
3415
3416     defwndproc_counter++;
3417     ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
3418     defwndproc_counter--;
3419
3420     return ret;
3421 }
3422
3423 static void subclass_button(void)
3424 {
3425     WNDCLASSA cls;
3426
3427     if (!GetClassInfoA(0, "button", &cls)) assert(0);
3428
3429     old_button_proc = cls.lpfnWndProc;
3430
3431     cls.hInstance = GetModuleHandle(0);
3432     cls.lpfnWndProc = button_hook_proc;
3433     cls.lpszClassName = "my_button_class";
3434     if (!RegisterClassA(&cls)) assert(0);
3435 }
3436
3437 static void test_button_messages(void)
3438 {
3439     static const struct
3440     {
3441         DWORD style;
3442         DWORD dlg_code;
3443         const struct message *setfocus;
3444         const struct message *killfocus;
3445     } button[] = {
3446         { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
3447           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
3448         { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
3449           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
3450         { BS_CHECKBOX, DLGC_BUTTON,
3451           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3452         { BS_AUTOCHECKBOX, DLGC_BUTTON,
3453           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3454         { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
3455           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3456         { BS_3STATE, DLGC_BUTTON,
3457           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3458         { BS_AUTO3STATE, DLGC_BUTTON,
3459           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3460         { BS_GROUPBOX, DLGC_STATIC,
3461           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3462         { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
3463           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
3464         { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
3465           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3466         { BS_OWNERDRAW, DLGC_BUTTON,
3467           WmSetFocusButtonSeq, WmKillFocusButtonSeq }
3468     };
3469     unsigned int i;
3470     HWND hwnd;
3471     DWORD dlg_code;
3472
3473     subclass_button();
3474
3475     for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
3476     {
3477         hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_POPUP,
3478                                0, 0, 50, 14, 0, 0, 0, NULL);
3479         ok(hwnd != 0, "Failed to create button window\n");
3480
3481         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
3482         ok(dlg_code == button[i].dlg_code, "%d: wrong dlg_code %08lx\n", i, dlg_code);
3483
3484         ShowWindow(hwnd, SW_SHOW);
3485         UpdateWindow(hwnd);
3486         SetFocus(0);
3487         flush_sequence();
3488
3489         trace("button style %08lx\n", button[i].style);
3490         SetFocus(hwnd);
3491         ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
3492
3493         SetFocus(0);
3494         ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
3495
3496         DestroyWindow(hwnd);
3497     }
3498
3499     hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
3500                            0, 0, 50, 14, 0, 0, 0, NULL);
3501     ok(hwnd != 0, "Failed to create button window\n");
3502
3503     SetFocus(0);
3504     flush_sequence();
3505
3506     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
3507     ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
3508
3509     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
3510     ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
3511     DestroyWindow(hwnd);
3512 }
3513
3514 /************* painting message test ********************/
3515
3516 void dump_region(HRGN hrgn)
3517 {
3518     DWORD i, size;
3519     RGNDATA *data = NULL;
3520     RECT *rect;
3521
3522     if (!hrgn)
3523     {
3524         printf( "null region\n" );
3525         return;
3526     }
3527     if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
3528     if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
3529     GetRegionData( hrgn, size, data );
3530     printf("%ld rects:", data->rdh.nCount );
3531     for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
3532         printf( " (%ld,%ld)-(%ld,%ld)", rect->left, rect->top, rect->right, rect->bottom );
3533     printf("\n");
3534     HeapFree( GetProcessHeap(), 0, data );
3535 }
3536
3537 static void check_update_rgn( HWND hwnd, HRGN hrgn )
3538 {
3539     INT ret;
3540     RECT r1, r2;
3541     HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
3542     HRGN update = CreateRectRgn( 0, 0, 0, 0 );
3543
3544     ret = GetUpdateRgn( hwnd, update, FALSE );
3545     ok( ret != ERROR, "GetUpdateRgn failed\n" );
3546     if (ret == NULLREGION)
3547     {
3548         ok( !hrgn, "Update region shouldn't be empty\n" );
3549     }
3550     else
3551     {
3552         if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
3553         {
3554             ok( 0, "Regions are different\n" );
3555             if (winetest_debug > 0)
3556             {
3557                 printf( "Update region: " );
3558                 dump_region( update );
3559                 printf( "Wanted region: " );
3560                 dump_region( hrgn );
3561             }
3562         }
3563     }
3564     GetRgnBox( update, &r1 );
3565     GetUpdateRect( hwnd, &r2, FALSE );
3566     ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
3567         "Rectangles are different: %ld,%ld-%ld,%ld / %ld,%ld-%ld,%ld\n",
3568         r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
3569
3570     DeleteObject( tmp );
3571     DeleteObject( update );
3572 }
3573
3574 static const struct message WmInvalidateRgn[] = {
3575     { WM_NCPAINT, sent },
3576     { WM_GETTEXT, sent|defwinproc|optional },
3577     { 0 }
3578 };
3579
3580 static const struct message WmGetUpdateRect[] = {
3581     { WM_NCPAINT, sent },
3582     { WM_GETTEXT, sent|defwinproc|optional },
3583     { WM_PAINT, sent },
3584     { 0 }
3585 };
3586
3587 static const struct message WmInvalidateFull[] = {
3588     { WM_NCPAINT, sent|wparam, 1 },
3589     { WM_GETTEXT, sent|defwinproc|optional },
3590     { 0 }
3591 };
3592
3593 static const struct message WmInvalidateErase[] = {
3594     { WM_NCPAINT, sent|wparam, 1 },
3595     { WM_GETTEXT, sent|defwinproc|optional },
3596     { WM_ERASEBKGND, sent },
3597     { 0 }
3598 };
3599
3600 static const struct message WmInvalidatePaint[] = {
3601     { WM_PAINT, sent },
3602     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
3603     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
3604     { 0 }
3605 };
3606
3607 static const struct message WmInvalidateErasePaint[] = {
3608     { WM_PAINT, sent },
3609     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
3610     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
3611     { WM_ERASEBKGND, sent|beginpaint },
3612     { 0 }
3613 };
3614
3615 static const struct message WmInvalidateErasePaint2[] = {
3616     { WM_PAINT, sent },
3617     { WM_NCPAINT, sent|beginpaint },
3618     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
3619     { WM_ERASEBKGND, sent|beginpaint },
3620     { 0 }
3621 };
3622
3623 static const struct message WmErase[] = {
3624     { WM_ERASEBKGND, sent },
3625     { 0 }
3626 };
3627
3628 static const struct message WmPaint[] = {
3629     { WM_PAINT, sent },
3630     { 0 }
3631 };
3632
3633 static const struct message WmParentOnlyPaint[] = {
3634     { WM_PAINT, sent|parent },
3635     { 0 }
3636 };
3637
3638 static const struct message WmInvalidateParent[] = {
3639     { WM_NCPAINT, sent|parent },
3640     { WM_GETTEXT, sent|defwinproc|parent|optional },
3641     { WM_ERASEBKGND, sent|parent },
3642     { 0 }
3643 };
3644
3645 static const struct message WmInvalidateParentChild[] = {
3646     { WM_NCPAINT, sent|parent },
3647     { WM_GETTEXT, sent|defwinproc|parent|optional },
3648     { WM_ERASEBKGND, sent|parent },
3649     { WM_NCPAINT, sent },
3650     { WM_GETTEXT, sent|defwinproc|optional },
3651     { WM_ERASEBKGND, sent },
3652     { 0 }
3653 };
3654
3655 static const struct message WmInvalidateParentChild2[] = {
3656     { WM_ERASEBKGND, sent|parent },
3657     { WM_NCPAINT, sent },
3658     { WM_GETTEXT, sent|defwinproc|optional },
3659     { WM_ERASEBKGND, sent },
3660     { 0 }
3661 };
3662
3663 static const struct message WmParentPaint[] = {
3664     { WM_PAINT, sent|parent },
3665     { WM_PAINT, sent },
3666     { 0 }
3667 };
3668
3669 static const struct message WmParentPaintNc[] = {
3670     { WM_PAINT, sent|parent },
3671     { WM_PAINT, sent },
3672     { WM_NCPAINT, sent|beginpaint },
3673     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
3674     { WM_ERASEBKGND, sent|beginpaint },
3675     { 0 }
3676 };
3677
3678 static const struct message WmChildPaintNc[] = {
3679     { WM_PAINT, sent },
3680     { WM_NCPAINT, sent|beginpaint },
3681     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
3682     { WM_ERASEBKGND, sent|beginpaint },
3683     { 0 }
3684 };
3685
3686 static const struct message WmParentErasePaint[] = {
3687     { WM_PAINT, sent|parent },
3688     { WM_NCPAINT, sent|parent|beginpaint },
3689     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
3690     { WM_ERASEBKGND, sent|parent|beginpaint },
3691     { WM_PAINT, sent },
3692     { WM_NCPAINT, sent|beginpaint },
3693     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
3694     { WM_ERASEBKGND, sent|beginpaint },
3695     { 0 }
3696 };
3697
3698 static const struct message WmParentOnlyNcPaint[] = {
3699     { WM_PAINT, sent|parent },
3700     { WM_NCPAINT, sent|parent|beginpaint },
3701     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
3702     { 0 }
3703 };
3704
3705 static const struct message WmSetParentStyle[] = {
3706     { WM_STYLECHANGING, sent|parent },
3707     { WM_STYLECHANGED, sent|parent },
3708     { 0 }
3709 };
3710
3711 static void test_paint_messages(void)
3712 {
3713     RECT rect;
3714     POINT pt;
3715     MSG msg;
3716     HWND hparent, hchild;
3717     HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3718     HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
3719     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
3720                                 100, 100, 200, 200, 0, 0, 0, NULL);
3721     ok (hwnd != 0, "Failed to create overlapped window\n");
3722
3723     ShowWindow( hwnd, SW_SHOW );
3724     UpdateWindow( hwnd );
3725
3726     /* try to flush pending X expose events */
3727     MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
3728     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3729
3730     check_update_rgn( hwnd, 0 );
3731     SetRectRgn( hrgn, 10, 10, 20, 20 );
3732     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
3733     check_update_rgn( hwnd, hrgn );
3734     SetRectRgn( hrgn2, 20, 20, 30, 30 );
3735     RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
3736     CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
3737     check_update_rgn( hwnd, hrgn );
3738     /* validate everything */
3739     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
3740     check_update_rgn( hwnd, 0 );
3741
3742     /* flush pending messages */
3743     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3744     flush_sequence();
3745
3746     GetClientRect( hwnd, &rect );
3747     SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
3748     /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
3749      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
3750      */
3751     trace("testing InvalidateRect(0, NULL, FALSE)\n");
3752     SetRectEmpty( &rect );
3753     ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
3754     check_update_rgn( hwnd, hrgn );
3755     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
3756     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3757     ok_sequence( WmPaint, "Paint", FALSE );
3758     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
3759     check_update_rgn( hwnd, 0 );
3760
3761     /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
3762      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
3763      */
3764     trace("testing ValidateRect(0, NULL)\n");
3765     SetRectEmpty( &rect );
3766     ok(ValidateRect(0, &rect), "ValidateRect(0, &rc) should not fail\n");
3767     check_update_rgn( hwnd, hrgn );
3768     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
3769     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3770     ok_sequence( WmPaint, "Paint", FALSE );
3771     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
3772     check_update_rgn( hwnd, 0 );
3773
3774     trace("testing InvalidateRgn(0, NULL, FALSE)\n");
3775     SetLastError(0xdeadbeef);
3776     ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
3777     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error code %ld\n", GetLastError());
3778     check_update_rgn( hwnd, 0 );
3779     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3780     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
3781
3782     trace("testing ValidateRgn(0, NULL)\n");
3783     SetLastError(0xdeadbeef);
3784     ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
3785     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error code %ld\n", GetLastError());
3786     check_update_rgn( hwnd, 0 );
3787     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3788     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
3789
3790     /* now with frame */
3791     SetRectRgn( hrgn, -5, -5, 20, 20 );
3792
3793     /* flush pending messages */
3794     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3795
3796     flush_sequence();
3797     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
3798     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
3799
3800     SetRectRgn( hrgn, 0, 0, 20, 20 );  /* GetUpdateRgn clips to client area */
3801     check_update_rgn( hwnd, hrgn );
3802
3803     flush_sequence();
3804     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
3805     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
3806
3807     flush_sequence();
3808     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
3809     ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
3810
3811     GetClientRect( hwnd, &rect );
3812     SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
3813     check_update_rgn( hwnd, hrgn );
3814
3815     flush_sequence();
3816     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
3817     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
3818
3819     flush_sequence();
3820     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
3821     ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
3822     check_update_rgn( hwnd, 0 );
3823
3824     flush_sequence();
3825     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
3826     ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
3827     check_update_rgn( hwnd, 0 );
3828
3829     flush_sequence();
3830     SetRectRgn( hrgn, 0, 0, 100, 100 );
3831     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
3832     SetRectRgn( hrgn, 0, 0, 50, 100 );
3833     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
3834     SetRectRgn( hrgn, 50, 0, 100, 100 );
3835     check_update_rgn( hwnd, hrgn );
3836     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
3837     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );  /* must not generate messages, everything is valid */
3838     check_update_rgn( hwnd, 0 );
3839
3840     flush_sequence();
3841     SetRectRgn( hrgn, 0, 0, 100, 100 );
3842     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
3843     SetRectRgn( hrgn, 0, 0, 100, 50 );
3844     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
3845     ok_sequence( WmErase, "Erase", FALSE );
3846     SetRectRgn( hrgn, 0, 50, 100, 100 );
3847     check_update_rgn( hwnd, hrgn );
3848
3849     flush_sequence();
3850     SetRectRgn( hrgn, 0, 0, 100, 100 );
3851     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
3852     SetRectRgn( hrgn, 0, 0, 50, 50 );
3853     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
3854     ok_sequence( WmPaint, "Paint", FALSE );
3855
3856     flush_sequence();
3857     SetRectRgn( hrgn, -4, -4, -2, -2 );
3858     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
3859     SetRectRgn( hrgn, -200, -200, -198, -198 );
3860     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
3861     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
3862
3863     flush_sequence();
3864     SetRectRgn( hrgn, -4, -4, -2, -2 );
3865     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
3866     SetRectRgn( hrgn, -4, -4, -3, -3 );
3867     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
3868     SetRectRgn( hrgn, 0, 0, 1, 1 );
3869     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
3870     ok_sequence( WmPaint, "Paint", FALSE );
3871
3872     flush_sequence();
3873     SetRectRgn( hrgn, -4, -4, -1, -1 );
3874     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
3875     RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
3876     /* make sure no WM_PAINT was generated */
3877     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3878     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
3879
3880     flush_sequence();
3881     SetRectRgn( hrgn, -4, -4, -1, -1 );
3882     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
3883     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
3884     {
3885         if (msg.hwnd == hwnd && msg.message == WM_PAINT)
3886         {
3887             /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
3888             INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
3889             ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
3890             ret = GetUpdateRect( hwnd, &rect, FALSE );
3891             ok( ret, "Invalid GetUpdateRect result %d\n", ret );
3892             /* this will send WM_NCPAINT and validate the non client area */
3893             ret = GetUpdateRect( hwnd, &rect, TRUE );
3894             ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
3895         }
3896         DispatchMessage( &msg );
3897     }
3898     ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
3899
3900     DestroyWindow( hwnd );
3901
3902     /* now test with a child window */
3903
3904     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
3905                               100, 100, 200, 200, 0, 0, 0, NULL);
3906     ok (hparent != 0, "Failed to create parent window\n");
3907
3908     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
3909                            10, 10, 100, 100, hparent, 0, 0, NULL);
3910     ok (hchild != 0, "Failed to create child window\n");
3911
3912     ShowWindow( hparent, SW_SHOW );
3913     UpdateWindow( hparent );
3914     UpdateWindow( hchild );
3915     /* try to flush pending X expose events */
3916     MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
3917     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3918
3919     flush_sequence();
3920     log_all_parent_messages++;
3921
3922     SetRect( &rect, 0, 0, 50, 50 );
3923     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
3924     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
3925     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
3926
3927     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
3928     pt.x = pt.y = 0;
3929     MapWindowPoints( hchild, hparent, &pt, 1 );
3930     SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
3931     check_update_rgn( hchild, hrgn );
3932     SetRectRgn( hrgn, 0, 0, 50, 50 );
3933     check_update_rgn( hparent, hrgn );
3934     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
3935     ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
3936     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
3937     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
3938
3939     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3940     ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
3941
3942     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
3943     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
3944     ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
3945     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
3946     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
3947
3948     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
3949     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
3950     ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
3951
3952     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
3953     flush_sequence();
3954     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
3955     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
3956     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
3957
3958     /* flush all paint messages */
3959     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3960     flush_sequence();
3961
3962     /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
3963     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
3964     SetRectRgn( hrgn, 0, 0, 50, 50 );
3965     check_update_rgn( hparent, hrgn );
3966     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
3967     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
3968     SetRectRgn( hrgn, 0, 0, 50, 50 );
3969     check_update_rgn( hparent, hrgn );
3970
3971     /* flush all paint messages */
3972     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3973     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
3974     flush_sequence();
3975
3976     /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
3977     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
3978     SetRectRgn( hrgn, 0, 0, 50, 50 );
3979     check_update_rgn( hparent, hrgn );
3980     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
3981     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
3982     SetRectRgn( hrgn2, 10, 10, 50, 50 );
3983     CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
3984     check_update_rgn( hparent, hrgn );
3985     /* flush all paint messages */
3986     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3987     flush_sequence();
3988
3989     /* same as above but parent gets completely validated */
3990     SetRect( &rect, 20, 20, 30, 30 );
3991     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
3992     SetRectRgn( hrgn, 20, 20, 30, 30 );
3993     check_update_rgn( hparent, hrgn );
3994     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
3995     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
3996     check_update_rgn( hparent, 0 );  /* no update region */
3997     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3998     ok_sequence( WmEmptySeq, "WmEmpty", FALSE );  /* and no paint messages */
3999
4000     /* make sure RDW_VALIDATE on child doesn't have the same effect */
4001     flush_sequence();
4002     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
4003     SetRectRgn( hrgn, 20, 20, 30, 30 );
4004     check_update_rgn( hparent, hrgn );
4005     RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
4006     SetRectRgn( hrgn, 20, 20, 30, 30 );
4007     check_update_rgn( hparent, hrgn );
4008
4009     /* same as above but normal WM_PAINT doesn't validate parent */
4010     flush_sequence();
4011     SetRect( &rect, 20, 20, 30, 30 );
4012     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
4013     SetRectRgn( hrgn, 20, 20, 30, 30 );
4014     check_update_rgn( hparent, hrgn );
4015     /* no WM_PAINT in child while parent still pending */
4016     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4017     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
4018     while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4019     ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
4020
4021     flush_sequence();
4022     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
4023     /* no WM_PAINT in child while parent still pending */
4024     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4025     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
4026     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
4027     /* now that parent is valid child should get WM_PAINT */
4028     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4029     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
4030     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4031     ok_sequence( WmEmptySeq, "No other message", FALSE );
4032
4033     /* same thing with WS_CLIPCHILDREN in parent */
4034     flush_sequence();
4035     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
4036     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
4037     /* changing style invalidates non client area, but we need to invalidate something else to see it */
4038     RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
4039     ok_sequence( WmEmptySeq, "No message", FALSE );
4040     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
4041     ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
4042
4043     flush_sequence();
4044     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
4045     SetRectRgn( hrgn, 20, 20, 30, 30 );
4046     check_update_rgn( hparent, hrgn );
4047     /* no WM_PAINT in child while parent still pending */
4048     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4049     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
4050     /* WM_PAINT in parent first */
4051     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4052     ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
4053
4054     /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
4055     flush_sequence();
4056     SetRect( &rect, 0, 0, 30, 30 );
4057     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
4058     SetRectRgn( hrgn, 0, 0, 30, 30 );
4059     check_update_rgn( hparent, hrgn );
4060     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4061     ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
4062
4063     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
4064     flush_sequence();
4065     SetRect( &rect, -10, 0, 30, 30 );
4066     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
4067     SetRect( &rect, 0, 0, 20, 20 );
4068     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
4069     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
4070     ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
4071
4072     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
4073     flush_sequence();
4074     SetRect( &rect, -10, 0, 30, 30 );
4075     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
4076     SetRect( &rect, 0, 0, 100, 100 );
4077     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
4078     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
4079     ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
4080     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
4081     ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
4082
4083     /* test RDW_INTERNALPAINT behavior */
4084
4085     flush_sequence();
4086     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
4087     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4088     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
4089
4090     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
4091     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4092     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
4093
4094     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
4095     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4096     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
4097
4098     assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
4099     UpdateWindow( hparent );
4100     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4101     flush_sequence();
4102     trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
4103     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
4104     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
4105                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
4106     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4107     ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
4108
4109     UpdateWindow( hparent );
4110     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4111     flush_sequence();
4112     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
4113     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
4114     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
4115                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
4116     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4117     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
4118
4119     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
4120     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
4121     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
4122     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4123     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
4124
4125     assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
4126     UpdateWindow( hparent );
4127     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4128     flush_sequence();
4129     trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
4130     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
4131     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
4132                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
4133     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4134     ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
4135
4136     UpdateWindow( hparent );
4137     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4138     flush_sequence();
4139     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
4140     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
4141     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
4142                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
4143     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
4144     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
4145
4146     log_all_parent_messages--;
4147     DestroyWindow( hparent );
4148     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
4149
4150     DeleteObject( hrgn );
4151     DeleteObject( hrgn2 );
4152 }
4153
4154 struct wnd_event
4155 {
4156     HWND hwnd;
4157     HANDLE event;
4158 };
4159
4160 static DWORD WINAPI thread_proc(void *param)
4161 {
4162     MSG msg;
4163     struct wnd_event *wnd_event = (struct wnd_event *)param;
4164
4165     wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
4166                                       100, 100, 200, 200, 0, 0, 0, NULL);
4167     ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
4168
4169     SetEvent(wnd_event->event);
4170
4171     while (GetMessage(&msg, 0, 0, 0))
4172     {
4173         TranslateMessage(&msg);
4174         DispatchMessage(&msg);
4175     }
4176
4177     ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
4178
4179     return 0;
4180 }
4181
4182 static void test_interthread_messages(void)
4183 {
4184     HANDLE hThread;
4185     DWORD tid;
4186     WNDPROC proc;
4187     MSG msg;
4188     char buf[256];
4189     int len, expected_len;
4190     struct wnd_event wnd_event;
4191     BOOL ret;
4192
4193     wnd_event.event = CreateEventW(NULL, 0, 0, NULL);
4194     if (!wnd_event.event)
4195     {
4196         trace("skipping interthread message test under win9x\n");
4197         return;
4198     }
4199
4200     hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
4201     ok(hThread != NULL, "CreateThread failed, error %ld\n", GetLastError());
4202
4203     ok(WaitForSingleObject(wnd_event.event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
4204
4205     CloseHandle(wnd_event.event);
4206
4207     SetLastError(0xdeadbeef);
4208     ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
4209     ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error code %ld\n", GetLastError());
4210
4211     proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
4212     ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %ld\n", GetLastError());
4213
4214     expected_len = lstrlenA("window caption text");
4215     memset(buf, 0, sizeof(buf));
4216     SetLastError(0xdeadbeef);
4217     len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
4218     ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %ld, len %d, expected len %d\n", GetLastError(), len, expected_len);
4219     ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
4220
4221     msg.hwnd = wnd_event.hwnd;
4222     msg.message = WM_GETTEXT;
4223     msg.wParam = sizeof(buf);
4224     msg.lParam = (LPARAM)buf;
4225     memset(buf, 0, sizeof(buf));
4226     SetLastError(0xdeadbeef);
4227     len = DispatchMessageA(&msg);
4228     ok(!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY,
4229        "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %ld\n", len, GetLastError());
4230
4231     /* the following test causes an exception in user.exe under win9x */
4232     msg.hwnd = wnd_event.hwnd;
4233     msg.message = WM_TIMER;
4234     msg.wParam = 0;
4235     msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
4236     SetLastError(0xdeadbeef);
4237     len = DispatchMessageA(&msg);
4238     ok(!len && GetLastError() == 0xdeadbeef,
4239        "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %ld\n", len, GetLastError());
4240
4241     ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
4242     ok( ret, "PostMessageA(WM_QUIT) error %ld\n", GetLastError());
4243
4244     ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
4245     CloseHandle(hThread);
4246
4247     ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
4248 }
4249
4250
4251 static const struct message WmVkN[] = {
4252     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
4253     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
4254     { WM_CHAR, wparam|lparam, 'n', 1 },
4255     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
4256     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
4257     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
4258     { 0 }
4259 };
4260 static const struct message WmShiftVkN[] = {
4261     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
4262     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
4263     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
4264     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
4265     { WM_CHAR, wparam|lparam, 'N', 1 },
4266     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
4267     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
4268     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
4269     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
4270     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
4271     { 0 }
4272 };
4273 static const struct message WmCtrlVkN[] = {
4274     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
4275     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
4276     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
4277     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
4278     { WM_CHAR, wparam|lparam, 0x000e, 1 },
4279     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
4280     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
4281     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
4282     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
4283     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
4284     { 0 }
4285 };
4286 static const struct message WmCtrlVkN_2[] = {
4287     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
4288     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
4289     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
4290     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
4291     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
4292     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
4293     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
4294     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
4295     { 0 }
4296 };
4297 static const struct message WmAltVkN[] = {
4298     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
4299     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
4300     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
4301     { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
4302     { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
4303     { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
4304     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
4305     { HCBT_SYSCOMMAND, hook },
4306     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
4307     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
4308     { 0x00AE, sent|defwinproc|optional }, /* XP */
4309     { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
4310     { WM_INITMENU, sent|defwinproc },
4311     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
4312     { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
4313     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
4314     { WM_CAPTURECHANGED, sent|defwinproc },
4315     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
4316     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
4317     { WM_EXITMENULOOP, sent|defwinproc },
4318     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
4319     { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
4320     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
4321     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
4322     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4323     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4324     { 0 }
4325 };
4326 static const struct message WmAltVkN_2[] = {
4327     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
4328     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
4329     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
4330     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
4331     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
4332     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
4333     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4334     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4335     { 0 }
4336 };
4337 static const struct message WmCtrlAltVkN[] = {
4338     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
4339     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
4340     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
4341     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
4342     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
4343     { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
4344     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
4345     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
4346     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4347     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4348     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
4349     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
4350     { 0 }
4351 };
4352 static const struct message WmCtrlShiftVkN[] = {
4353     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
4354     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
4355     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
4356     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
4357     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
4358     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
4359     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
4360     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
4361     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
4362     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
4363     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
4364     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
4365     { 0 }
4366 };
4367 static const struct message WmCtrlAltShiftVkN[] = {
4368     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
4369     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
4370     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
4371     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
4372     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
4373     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
4374     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
4375     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
4376     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
4377     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
4378     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
4379     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
4380     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4381     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4382     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
4383     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
4384     { 0 }
4385 };
4386 static const struct message WmAltPressRelease[] = {
4387     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
4388     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
4389     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4390     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4391     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
4392     { HCBT_SYSCOMMAND, hook },
4393     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
4394     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
4395     { WM_INITMENU, sent|defwinproc },
4396     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
4397     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
4398     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
4399
4400     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
4401     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
4402     { WM_CAPTURECHANGED, sent|defwinproc },
4403     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
4404     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
4405     { WM_EXITMENULOOP, sent|defwinproc },
4406     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4407     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4408     { 0 }
4409 };
4410 static const struct message WmAltMouseButton[] = {
4411     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
4412     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
4413     { WM_MOUSEMOVE, wparam|optional, 0, 0 },
4414     { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
4415     { WM_LBUTTONDOWN, wparam, MK_LBUTTON, 0 },
4416     { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON, 0 },
4417     { WM_LBUTTONUP, wparam, 0, 0 },
4418     { WM_LBUTTONUP, sent|wparam, 0, 0 },
4419     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4420     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4421     { 0 }
4422 };
4423 static const struct message WmF1Seq[] = {
4424     { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
4425     { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
4426     { 0x4d, wparam|lparam, 0, 0 },
4427     { 0x4d, sent|wparam|lparam, 0, 0 },
4428     { WM_HELP, sent|defwinproc },
4429     { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
4430     { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
4431     { 0 }
4432 };
4433
4434 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
4435 {
4436     MSG msg;
4437
4438     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
4439     {
4440         struct message log_msg;
4441
4442         trace("accel: %p, %04x, %08x, %08lx\n", msg.hwnd, msg.message, msg.wParam, msg.lParam);
4443
4444         /* ignore some unwanted messages */
4445         if (msg.message == WM_MOUSEMOVE ||
4446             msg.message == WM_GETICON ||
4447             msg.message == WM_DEVICECHANGE)
4448             continue;
4449
4450         log_msg.message = msg.message;
4451         log_msg.flags = wparam|lparam;
4452         log_msg.wParam = msg.wParam;
4453         log_msg.lParam = msg.lParam;
4454         add_message(&log_msg);
4455
4456         if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
4457         {
4458             TranslateMessage(&msg);
4459             DispatchMessage(&msg);
4460         }
4461     }
4462 }
4463
4464 static void test_accelerators(void)
4465 {
4466     RECT rc;
4467     SHORT state;
4468     HACCEL hAccel;
4469     HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4470                                 100, 100, 200, 200, 0, 0, 0, NULL);
4471     BOOL ret;
4472
4473     assert(hwnd != 0);
4474     UpdateWindow(hwnd);
4475     SetFocus(hwnd);
4476     ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
4477
4478     state = GetKeyState(VK_SHIFT);
4479     ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
4480     state = GetKeyState(VK_CAPITAL);
4481     ok(state == 0, "wrong CapsLock state %04x\n", state);
4482
4483     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
4484     assert(hAccel != 0);
4485
4486     pump_msg_loop(hwnd, 0);
4487     flush_sequence();
4488
4489     trace("testing VK_N press/release\n");
4490     flush_sequence();
4491     keybd_event('N', 0, 0, 0);
4492     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4493     pump_msg_loop(hwnd, hAccel);
4494     ok_sequence(WmVkN, "VK_N press/release", FALSE);
4495
4496     trace("testing Shift+VK_N press/release\n");
4497     flush_sequence();
4498     keybd_event(VK_SHIFT, 0, 0, 0);
4499     keybd_event('N', 0, 0, 0);
4500     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4501     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
4502     pump_msg_loop(hwnd, hAccel);
4503     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
4504
4505     trace("testing Ctrl+VK_N press/release\n");
4506     flush_sequence();
4507     keybd_event(VK_CONTROL, 0, 0, 0);
4508     keybd_event('N', 0, 0, 0);
4509     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4510     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
4511     pump_msg_loop(hwnd, hAccel);
4512     ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
4513
4514     trace("testing Alt+VK_N press/release\n");
4515     flush_sequence();
4516     keybd_event(VK_MENU, 0, 0, 0);
4517     keybd_event('N', 0, 0, 0);
4518     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4519     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4520     pump_msg_loop(hwnd, hAccel);
4521     ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
4522
4523     trace("testing Ctrl+Alt+VK_N press/release 1\n");
4524     flush_sequence();
4525     keybd_event(VK_CONTROL, 0, 0, 0);
4526     keybd_event(VK_MENU, 0, 0, 0);
4527     keybd_event('N', 0, 0, 0);
4528     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4529     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4530     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
4531     pump_msg_loop(hwnd, hAccel);
4532     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
4533
4534     ret = DestroyAcceleratorTable(hAccel);
4535     ok( ret, "DestroyAcceleratorTable error %ld\n", GetLastError());
4536
4537     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
4538     assert(hAccel != 0);
4539
4540     trace("testing VK_N press/release\n");
4541     flush_sequence();
4542     keybd_event('N', 0, 0, 0);
4543     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4544     pump_msg_loop(hwnd, hAccel);
4545     ok_sequence(WmVkN, "VK_N press/release", FALSE);
4546
4547     trace("testing Shift+VK_N press/release\n");
4548     flush_sequence();
4549     keybd_event(VK_SHIFT, 0, 0, 0);
4550     keybd_event('N', 0, 0, 0);
4551     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4552     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
4553     pump_msg_loop(hwnd, hAccel);
4554     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
4555
4556     trace("testing Ctrl+VK_N press/release 2\n");
4557     flush_sequence();
4558     keybd_event(VK_CONTROL, 0, 0, 0);
4559     keybd_event('N', 0, 0, 0);
4560     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4561     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
4562     pump_msg_loop(hwnd, hAccel);
4563     ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
4564
4565     trace("testing Alt+VK_N press/release 2\n");
4566     flush_sequence();
4567     keybd_event(VK_MENU, 0, 0, 0);
4568     keybd_event('N', 0, 0, 0);
4569     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4570     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4571     pump_msg_loop(hwnd, hAccel);
4572     ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
4573
4574     trace("testing Ctrl+Alt+VK_N press/release 2\n");
4575     flush_sequence();
4576     keybd_event(VK_CONTROL, 0, 0, 0);
4577     keybd_event(VK_MENU, 0, 0, 0);
4578     keybd_event('N', 0, 0, 0);
4579     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4580     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4581     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
4582     pump_msg_loop(hwnd, hAccel);
4583     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
4584
4585     trace("testing Ctrl+Shift+VK_N press/release\n");
4586     flush_sequence();
4587     keybd_event(VK_CONTROL, 0, 0, 0);
4588     keybd_event(VK_SHIFT, 0, 0, 0);
4589     keybd_event('N', 0, 0, 0);
4590     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4591     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
4592     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
4593     pump_msg_loop(hwnd, hAccel);
4594     ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
4595
4596     trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
4597     flush_sequence();
4598     keybd_event(VK_CONTROL, 0, 0, 0);
4599     keybd_event(VK_MENU, 0, 0, 0);
4600     keybd_event(VK_SHIFT, 0, 0, 0);
4601     keybd_event('N', 0, 0, 0);
4602     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4603     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
4604     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4605     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
4606     pump_msg_loop(hwnd, hAccel);
4607     ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
4608
4609     ret = DestroyAcceleratorTable(hAccel);
4610     ok( ret, "DestroyAcceleratorTable error %ld\n", GetLastError());
4611
4612     trace("testing Alt press/release\n");
4613     flush_sequence();
4614     keybd_event(VK_MENU, 0, 0, 0);
4615     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4616     keybd_event(VK_MENU, 0, 0, 0);
4617     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4618     pump_msg_loop(hwnd, 0);
4619     /* this test doesn't pass in Wine for managed windows */
4620     ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
4621
4622     trace("testing Alt+MouseButton press/release\n");
4623     /* first, move mouse pointer inside of the window client area */
4624     GetClientRect(hwnd, &rc);
4625     MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
4626     rc.left += (rc.right - rc.left)/2;
4627     rc.top += (rc.bottom - rc.top)/2;
4628     SetCursorPos(rc.left, rc.top);
4629
4630     pump_msg_loop(hwnd, 0);
4631     flush_sequence();
4632     keybd_event(VK_MENU, 0, 0, 0);
4633     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
4634     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
4635     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4636     pump_msg_loop(hwnd, 0);
4637     ok_sequence(WmAltMouseButton, "Alt+MouseButton press/release", FALSE);
4638
4639     keybd_event(VK_F1, 0, 0, 0);
4640     keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
4641     pump_msg_loop(hwnd, 0);
4642     ok_sequence(WmF1Seq, "F1 press/release", TRUE);
4643
4644     DestroyWindow(hwnd);
4645 }
4646
4647 /************* window procedures ********************/
4648
4649 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message, 
4650                              WPARAM wParam, LPARAM lParam)
4651 {
4652     static long defwndproc_counter = 0;
4653     static long beginpaint_counter = 0;
4654     LRESULT ret;
4655     struct message msg;
4656
4657     trace("%p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
4658
4659     /* explicitly ignore WM_GETICON message */
4660     if (message == WM_GETICON) return 0;
4661
4662     switch (message)
4663     {
4664         case WM_ENABLE:
4665         {
4666             LONG style = GetWindowLongA(hwnd, GWL_STYLE);
4667             ok((BOOL)wParam == !(style & WS_DISABLED),
4668                 "wrong WS_DISABLED state: %d != %d\n", wParam, !(style & WS_DISABLED));
4669             break;
4670         }
4671
4672         case WM_CAPTURECHANGED:
4673             if (test_DestroyWindow_flag)
4674             {
4675                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
4676                 if (style & WS_CHILD)
4677                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
4678                 else if (style & WS_POPUP)
4679                     lParam = WND_POPUP_ID;
4680                 else
4681                     lParam = WND_PARENT_ID;
4682             }
4683             break;
4684
4685         case WM_NCDESTROY:
4686         {
4687             HWND capture;
4688
4689             ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
4690             capture = GetCapture();
4691             if (capture)
4692             {
4693                 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
4694                 trace("current capture %p, releasing...\n", capture);
4695                 ReleaseCapture();
4696             }
4697         }
4698         /* fall through */
4699         case WM_DESTROY:
4700             if (pGetAncestor)
4701                 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
4702             if (test_DestroyWindow_flag)
4703             {
4704                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
4705                 if (style & WS_CHILD)
4706                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
4707                 else if (style & WS_POPUP)
4708                     lParam = WND_POPUP_ID;
4709                 else
4710                     lParam = WND_PARENT_ID;
4711             }
4712             break;
4713
4714         /* test_accelerators() depends on this */
4715         case WM_NCHITTEST:
4716             return HTCLIENT;
4717     
4718         /* ignore */
4719         case WM_MOUSEMOVE:
4720         case WM_SETCURSOR:
4721         case WM_DEVICECHANGE:
4722             return 0;
4723
4724         case WM_WINDOWPOSCHANGING:
4725         case WM_WINDOWPOSCHANGED:
4726         {
4727             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
4728
4729             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
4730             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
4731                   winpos->hwnd, winpos->hwndInsertAfter,
4732                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
4733
4734             /* Log only documented flags, win2k uses 0x1000 and 0x2000
4735              * in the high word for internal purposes
4736              */
4737             wParam = winpos->flags & 0xffff;
4738             break;
4739         }
4740     }
4741
4742     msg.message = message;
4743     msg.flags = sent|wparam|lparam;
4744     if (defwndproc_counter) msg.flags |= defwinproc;
4745     if (beginpaint_counter) msg.flags |= beginpaint;
4746     msg.wParam = wParam;
4747     msg.lParam = lParam;
4748     add_message(&msg);
4749
4750     if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
4751     {
4752         HWND parent = GetParent(hwnd);
4753         RECT rc;
4754         MINMAXINFO *minmax = (MINMAXINFO *)lParam;
4755
4756         GetClientRect(parent, &rc);
4757         trace("parent %p client size = (%ld x %ld)\n", parent, rc.right, rc.bottom);
4758
4759         trace("ptReserved = (%ld,%ld)\n"
4760               "ptMaxSize = (%ld,%ld)\n"
4761               "ptMaxPosition = (%ld,%ld)\n"
4762               "ptMinTrackSize = (%ld,%ld)\n"
4763               "ptMaxTrackSize = (%ld,%ld)\n",
4764               minmax->ptReserved.x, minmax->ptReserved.y,
4765               minmax->ptMaxSize.x, minmax->ptMaxSize.y,
4766               minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
4767               minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
4768               minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
4769
4770         ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %ld != %ld\n",
4771            minmax->ptMaxSize.x, rc.right);
4772         ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %ld != %ld\n",
4773            minmax->ptMaxSize.y, rc.bottom);
4774     }
4775
4776     if (message == WM_PAINT)
4777     {
4778         PAINTSTRUCT ps;
4779         beginpaint_counter++;
4780         BeginPaint( hwnd, &ps );
4781         beginpaint_counter--;
4782         EndPaint( hwnd, &ps );
4783         return 0;
4784     }
4785
4786     defwndproc_counter++;
4787     ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam) 
4788                   : DefWindowProcA(hwnd, message, wParam, lParam);
4789     defwndproc_counter--;
4790
4791     return ret;
4792 }
4793
4794 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4795 {
4796     return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
4797 }
4798
4799 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4800 {
4801     return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
4802 }
4803
4804 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4805 {
4806     static long defwndproc_counter = 0;
4807     LRESULT ret;
4808     struct message msg;
4809
4810     trace("popup: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
4811
4812     /* explicitly ignore WM_GETICON message */
4813     if (message == WM_GETICON) return 0;
4814
4815     msg.message = message;
4816     msg.flags = sent|wparam|lparam;
4817     if (defwndproc_counter) msg.flags |= defwinproc;
4818     msg.wParam = wParam;
4819     msg.lParam = lParam;
4820     add_message(&msg);
4821
4822     if (message == WM_CREATE)
4823     {
4824         DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
4825         SetWindowLongA(hwnd, GWL_STYLE, style);
4826     }
4827
4828     defwndproc_counter++;
4829     ret = DefWindowProcA(hwnd, message, wParam, lParam);
4830     defwndproc_counter--;
4831
4832     return ret;
4833 }
4834
4835 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4836 {
4837     static long defwndproc_counter = 0;
4838     static long beginpaint_counter = 0;
4839     LRESULT ret;
4840     struct message msg;
4841
4842     trace("parent: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
4843
4844     /* explicitly ignore WM_GETICON message */
4845     if (message == WM_GETICON) return 0;
4846
4847     if (log_all_parent_messages ||
4848         message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
4849         message == WM_SETFOCUS || message == WM_KILLFOCUS ||
4850         message == WM_ENABLE || message == WM_ENTERIDLE ||
4851         message == WM_IME_SETCONTEXT)
4852     {
4853         switch (message)
4854         {
4855             case WM_ERASEBKGND:
4856             {
4857                 RECT rc;
4858                 INT ret = GetClipBox((HDC)wParam, &rc);
4859
4860                 trace("WM_ERASEBKGND: GetClipBox()=%d, (%ld,%ld-%ld,%ld)\n",
4861                        ret, rc.left, rc.top, rc.right, rc.bottom);
4862                 break;
4863             }
4864
4865             case WM_WINDOWPOSCHANGING:
4866             case WM_WINDOWPOSCHANGED:
4867             {
4868                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
4869
4870                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
4871                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
4872                       winpos->hwnd, winpos->hwndInsertAfter,
4873                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
4874
4875                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
4876                  * in the high word for internal purposes
4877                  */
4878                 wParam = winpos->flags & 0xffff;
4879                 break;
4880             }
4881         }
4882
4883         msg.message = message;
4884         msg.flags = sent|parent|wparam|lparam;
4885         if (defwndproc_counter) msg.flags |= defwinproc;
4886         if (beginpaint_counter) msg.flags |= beginpaint;
4887         msg.wParam = wParam;
4888         msg.lParam = lParam;
4889         add_message(&msg);
4890     }
4891
4892     if (message == WM_PAINT)
4893     {
4894         PAINTSTRUCT ps;
4895         beginpaint_counter++;
4896         BeginPaint( hwnd, &ps );
4897         beginpaint_counter--;
4898         EndPaint( hwnd, &ps );
4899         return 0;
4900     }
4901
4902     defwndproc_counter++;
4903     ret = DefWindowProcA(hwnd, message, wParam, lParam);
4904     defwndproc_counter--;
4905
4906     return ret;
4907 }
4908
4909 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4910 {
4911     static long defwndproc_counter = 0;
4912     LRESULT ret;
4913     struct message msg;
4914
4915     trace("dialog: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
4916
4917     /* explicitly ignore WM_GETICON message */
4918     if (message == WM_GETICON) return 0;
4919
4920     DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
4921     ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
4922     if (after_end_dialog)
4923         ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
4924     else
4925         ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
4926
4927     switch (message)
4928     {
4929         case WM_WINDOWPOSCHANGING:
4930         case WM_WINDOWPOSCHANGED:
4931         {
4932             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
4933
4934             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
4935             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
4936                   winpos->hwnd, winpos->hwndInsertAfter,
4937                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
4938
4939             /* Log only documented flags, win2k uses 0x1000 and 0x2000
4940              * in the high word for internal purposes
4941              */
4942             wParam = winpos->flags & 0xffff;
4943             break;
4944         }
4945     }
4946
4947     msg.message = message;
4948     msg.flags = sent|wparam|lparam;
4949     if (defwndproc_counter) msg.flags |= defwinproc;
4950     msg.wParam = wParam;
4951     msg.lParam = lParam;
4952     add_message(&msg);
4953
4954     defwndproc_counter++;
4955     ret = DefDlgProcA(hwnd, message, wParam, lParam);
4956     defwndproc_counter--;
4957
4958     return ret;
4959 }
4960
4961 static BOOL RegisterWindowClasses(void)
4962 {
4963     WNDCLASSA cls;
4964
4965     cls.style = 0;
4966     cls.lpfnWndProc = MsgCheckProcA;
4967     cls.cbClsExtra = 0;
4968     cls.cbWndExtra = 0;
4969     cls.hInstance = GetModuleHandleA(0);
4970     cls.hIcon = 0;
4971     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
4972     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4973     cls.lpszMenuName = NULL;
4974     cls.lpszClassName = "TestWindowClass";
4975     if(!RegisterClassA(&cls)) return FALSE;
4976
4977     cls.lpfnWndProc = PopupMsgCheckProcA;
4978     cls.lpszClassName = "TestPopupClass";
4979     if(!RegisterClassA(&cls)) return FALSE;
4980
4981     cls.lpfnWndProc = ParentMsgCheckProcA;
4982     cls.lpszClassName = "TestParentClass";
4983     if(!RegisterClassA(&cls)) return FALSE;
4984
4985     cls.lpfnWndProc = DefWindowProcA;
4986     cls.lpszClassName = "SimpleWindowClass";
4987     if(!RegisterClassA(&cls)) return FALSE;
4988
4989     cls.style = CS_NOCLOSE;
4990     cls.lpszClassName = "NoCloseWindowClass";
4991     if(!RegisterClassA(&cls)) return FALSE;
4992
4993     ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
4994     cls.style = 0;
4995     cls.hInstance = GetModuleHandleA(0);
4996     cls.hbrBackground = 0;
4997     cls.lpfnWndProc = TestDlgProcA;
4998     cls.lpszClassName = "TestDialogClass";
4999     if(!RegisterClassA(&cls)) return FALSE;
5000
5001     return TRUE;
5002 }
5003
5004 static HHOOK hCBT_hook;
5005 static DWORD cbt_hook_thread_id;
5006
5007 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
5008
5009     static const char *CBT_code_name[10] = {
5010         "HCBT_MOVESIZE",
5011         "HCBT_MINMAX",
5012         "HCBT_QS",
5013         "HCBT_CREATEWND",
5014         "HCBT_DESTROYWND",
5015         "HCBT_ACTIVATE",
5016         "HCBT_CLICKSKIPPED",
5017         "HCBT_KEYSKIPPED",
5018         "HCBT_SYSCOMMAND",
5019         "HCBT_SETFOCUS" };
5020     const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
5021     HWND hwnd;
5022     char buf[256];
5023
5024     trace("CBT: %d (%s), %08x, %08lx\n", nCode, code_name, wParam, lParam);
5025
5026     ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
5027
5028     if (nCode == HCBT_SYSCOMMAND)
5029     {
5030         struct message msg;
5031
5032         msg.message = nCode;
5033         msg.flags = hook|wparam|lparam;
5034         msg.wParam = wParam;
5035         msg.lParam = lParam;
5036         add_message(&msg);
5037
5038         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
5039     }
5040
5041     if (nCode == HCBT_DESTROYWND)
5042     {
5043         if (test_DestroyWindow_flag)
5044         {
5045             DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
5046             if (style & WS_CHILD)
5047                 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
5048             else if (style & WS_POPUP)
5049                 lParam = WND_POPUP_ID;
5050             else
5051                 lParam = WND_PARENT_ID;
5052         }
5053     }
5054
5055     /* Log also SetFocus(0) calls */
5056     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
5057
5058     if (GetClassNameA(hwnd, buf, sizeof(buf)))
5059     {
5060         if (!lstrcmpiA(buf, "TestWindowClass") ||
5061             !lstrcmpiA(buf, "TestParentClass") ||
5062             !lstrcmpiA(buf, "TestPopupClass") ||
5063             !lstrcmpiA(buf, "SimpleWindowClass") ||
5064             !lstrcmpiA(buf, "TestDialogClass") ||
5065             !lstrcmpiA(buf, "MDI_frame_class") ||
5066             !lstrcmpiA(buf, "MDI_client_class") ||
5067             !lstrcmpiA(buf, "MDI_child_class") ||
5068             !lstrcmpiA(buf, "my_button_class") ||
5069             !lstrcmpiA(buf, "my_edit_class") ||
5070             !lstrcmpiA(buf, "static") ||
5071             !lstrcmpiA(buf, "#32770"))
5072         {
5073             struct message msg;
5074
5075             msg.message = nCode;
5076             msg.flags = hook|wparam|lparam;
5077             msg.wParam = wParam;
5078             msg.lParam = lParam;
5079             add_message(&msg);
5080         }
5081     }
5082     return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
5083 }
5084
5085 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
5086                                     DWORD event,
5087                                     HWND hwnd,
5088                                     LONG object_id,
5089                                     LONG child_id,
5090                                     DWORD thread_id,
5091                                     DWORD event_time)
5092 {
5093     char buf[256];
5094
5095     trace("WEH:%p,event %08lx,hwnd %p,obj %08lx,id %08lx,thread %08lx,time %08lx\n",
5096            hevent, event, hwnd, object_id, child_id, thread_id, event_time);
5097
5098     ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
5099
5100     /* ignore mouse cursor events */
5101     if (object_id == OBJID_CURSOR) return;
5102
5103     if (!hwnd || GetClassNameA(hwnd, buf, sizeof(buf)))
5104     {
5105         if (!hwnd ||
5106             !lstrcmpiA(buf, "TestWindowClass") ||
5107             !lstrcmpiA(buf, "TestParentClass") ||
5108             !lstrcmpiA(buf, "TestPopupClass") ||
5109             !lstrcmpiA(buf, "SimpleWindowClass") ||
5110             !lstrcmpiA(buf, "TestDialogClass") ||
5111             !lstrcmpiA(buf, "MDI_frame_class") ||
5112             !lstrcmpiA(buf, "MDI_client_class") ||
5113             !lstrcmpiA(buf, "MDI_child_class") ||
5114             !lstrcmpiA(buf, "my_button_class") ||
5115             !lstrcmpiA(buf, "my_edit_class") ||
5116             !lstrcmpiA(buf, "static") ||
5117             !lstrcmpiA(buf, "#32770"))
5118         {
5119             struct message msg;
5120
5121             msg.message = event;
5122             msg.flags = winevent_hook|wparam|lparam;
5123             msg.wParam = object_id;
5124             msg.lParam = child_id;
5125             add_message(&msg);
5126         }
5127     }
5128 }
5129
5130 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
5131 static const WCHAR wszAnsi[] = {'U',0};
5132
5133 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
5134 {
5135     switch (uMsg)
5136     {
5137     case CB_FINDSTRINGEXACT:
5138         trace("String: %p\n", (LPCWSTR)lParam);
5139         if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
5140             return 1;
5141         if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
5142             return 0;
5143         return -1;
5144     }
5145     return DefWindowProcW(hwnd, uMsg, wParam, lParam);
5146 }
5147
5148 static const struct message WmGetTextLengthAfromW[] = {
5149     { WM_GETTEXTLENGTH, sent },
5150     { WM_GETTEXT, sent },
5151     { 0 }
5152 };
5153
5154 static const WCHAR testWindowClassW[] = 
5155 { 'T','e','s','t','W','i','n','d','o','w','C','l','a','s','s','W',0 };
5156
5157 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
5158
5159 /* dummy window proc for WM_GETTEXTLENGTH test */
5160 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
5161 {
5162     switch(msg)
5163     {
5164     case WM_GETTEXTLENGTH:
5165         return lstrlenW(dummy_window_text) + 37;  /* some random length */
5166     case WM_GETTEXT:
5167         lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
5168         return lstrlenW( (LPWSTR)lp );
5169     default:
5170         return DefWindowProcW( hwnd, msg, wp, lp );
5171     }
5172 }
5173
5174 static void test_message_conversion(void)
5175 {
5176     static const WCHAR wszMsgConversionClass[] =
5177         {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
5178     WNDCLASSW cls;
5179     LRESULT lRes;
5180     HWND hwnd;
5181     WNDPROC wndproc, newproc;
5182     BOOL ret;
5183
5184     cls.style = 0;
5185     cls.lpfnWndProc = MsgConversionProcW;
5186     cls.cbClsExtra = 0;
5187     cls.cbWndExtra = 0;
5188     cls.hInstance = GetModuleHandleW(NULL);
5189     cls.hIcon = NULL;
5190     cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
5191     cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
5192     cls.lpszMenuName = NULL;
5193     cls.lpszClassName = wszMsgConversionClass;
5194     /* this call will fail on Win9x, but that doesn't matter as this test is
5195      * meaningless on those platforms */
5196     if(!RegisterClassW(&cls)) return;
5197
5198     cls.style = 0;
5199     cls.lpfnWndProc = MsgCheckProcW;
5200     cls.cbClsExtra = 0;
5201     cls.cbWndExtra = 0;
5202     cls.hInstance = GetModuleHandleW(0);
5203     cls.hIcon = 0;
5204     cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
5205     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5206     cls.lpszMenuName = NULL;
5207     cls.lpszClassName = testWindowClassW;
5208     if(!RegisterClassW(&cls)) return;
5209
5210     hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
5211                            100, 100, 200, 200, 0, 0, 0, NULL);
5212     ok(hwnd != NULL, "Window creation failed\n");
5213
5214     /* {W, A} -> A */
5215
5216     wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
5217     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
5218     ok(lRes == 0, "String should have been converted\n");
5219     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
5220     ok(lRes == 1, "String shouldn't have been converted\n");
5221
5222     /* {W, A} -> W */
5223
5224     wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
5225     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
5226     ok(lRes == 1, "String shouldn't have been converted\n");
5227     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
5228     ok(lRes == 1, "String shouldn't have been converted\n");
5229
5230     /* Synchronous messages */
5231
5232     lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
5233     ok(lRes == 0, "String should have been converted\n");
5234     lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
5235     ok(lRes == 1, "String shouldn't have been converted\n");
5236
5237     /* Asynchronous messages */
5238
5239     SetLastError(0);
5240     lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
5241     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
5242         "PostMessage on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
5243     SetLastError(0);
5244     lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
5245     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
5246         "PostMessage on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
5247     SetLastError(0);
5248     lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
5249     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
5250         "PosThreadtMessage on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
5251     SetLastError(0);
5252     lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
5253     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
5254         "PosThreadtMessage on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
5255     SetLastError(0);
5256     lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
5257     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
5258         "SendNotifyMessage on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
5259     SetLastError(0);
5260     lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
5261     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
5262         "SendNotifyMessage on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
5263     SetLastError(0);
5264     lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
5265     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
5266         "SendMessageCallback on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
5267     SetLastError(0);
5268     lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
5269     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
5270         "SendMessageCallback on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
5271
5272     /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
5273
5274     hwnd = CreateWindowW (testWindowClassW, wszUnicode,
5275                           WS_OVERLAPPEDWINDOW,
5276                           100, 100, 200, 200, 0, 0, 0, NULL);
5277     assert(hwnd);
5278     flush_sequence();
5279     lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
5280     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
5281     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
5282         "got bad length %ld\n", lRes );
5283
5284     flush_sequence();
5285     lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
5286                             hwnd, WM_GETTEXTLENGTH, 0, 0);
5287     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
5288     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
5289         "got bad length %ld\n", lRes );
5290
5291     wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
5292     newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
5293     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
5294     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
5295                                      NULL, 0, NULL, NULL ),
5296         "got bad length %ld\n", lRes );
5297
5298     SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc );  /* restore old wnd proc */
5299     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
5300     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
5301                                      NULL, 0, NULL, NULL ),
5302         "got bad length %ld\n", lRes );
5303
5304     ret = DestroyWindow(hwnd);
5305     ok( ret, "DestroyWindow() error %ld\n", GetLastError());
5306 }
5307
5308 typedef struct _thread_info
5309 {
5310     HWND hWnd;
5311     HANDLE handles[2];
5312     DWORD id;
5313 } thread_info;
5314
5315 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT id, DWORD dwTime)
5316 {
5317 }
5318
5319 #define TIMER_ID  0x19
5320
5321 static DWORD WINAPI timer_thread_proc(LPVOID x)
5322 {
5323     thread_info *info = x;
5324     DWORD r;
5325
5326     r = KillTimer(info->hWnd, 0x19);
5327     ok(r,"KillTimer failed in thread\n");
5328     r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
5329     ok(r,"SetTimer failed in thread\n");
5330     ok(r==TIMER_ID,"SetTimer id different\n");
5331     r = SetEvent(info->handles[0]);
5332     ok(r,"SetEvent failed in thread\n");
5333     return 0;
5334 }
5335
5336 static void test_timers(void)
5337 {
5338     thread_info info;
5339     DWORD id;
5340
5341     info.hWnd = CreateWindow ("TestWindowClass", NULL,
5342        WS_OVERLAPPEDWINDOW ,
5343        CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5344        NULL, NULL, 0);
5345
5346     info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
5347     ok(info.id, "SetTimer failed\n");
5348     ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
5349     info.handles[0] = CreateEvent(NULL,0,0,NULL);
5350     info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
5351
5352     WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
5353
5354     WaitForSingleObject(info.handles[1], INFINITE);
5355
5356     CloseHandle(info.handles[0]);
5357     CloseHandle(info.handles[1]);
5358
5359     ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
5360
5361     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
5362 }
5363
5364 /* Various win events with arbitrary parameters */
5365 static const struct message WmWinEventsSeq[] = {
5366     { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
5367     { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
5368     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
5369     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
5370     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
5371     { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
5372     { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
5373     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
5374     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
5375     /* our win event hook ignores OBJID_CURSOR events */
5376     /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
5377     { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
5378     { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
5379     { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
5380     { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
5381     { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
5382     { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
5383     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
5384     { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
5385     { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
5386     { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
5387     { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
5388     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
5389     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
5390     { 0 }
5391 };
5392 static const struct message WmWinEventCaretSeq[] = {
5393     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
5394     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
5395     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
5396     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
5397     { 0 }
5398 };
5399 static const struct message WmWinEventCaretSeq_2[] = {
5400     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
5401     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
5402     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
5403     { 0 }
5404 };
5405 static const struct message WmWinEventAlertSeq[] = {
5406     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
5407     { 0 }
5408 };
5409 static const struct message WmWinEventAlertSeq_2[] = {
5410     /* create window in the thread proc */
5411     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
5412     /* our test event */
5413     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
5414     { 0 }
5415 };
5416 static const struct message WmGlobalHookSeq_1[] = {
5417     /* create window in the thread proc */
5418     { HCBT_CREATEWND, hook|lparam, 0, 2 },
5419     /* our test events */
5420     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
5421     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
5422     { 0 }
5423 };
5424 static const struct message WmGlobalHookSeq_2[] = {
5425     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
5426     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
5427     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
5428     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
5429     { 0 }
5430 };
5431
5432 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
5433                                          DWORD event,
5434                                          HWND hwnd,
5435                                          LONG object_id,
5436                                          LONG child_id,
5437                                          DWORD thread_id,
5438                                          DWORD event_time)
5439 {
5440     char buf[256];
5441
5442     trace("WEH_2:%p,event %08lx,hwnd %p,obj %08lx,id %08lx,thread %08lx,time %08lx\n",
5443            hevent, event, hwnd, object_id, child_id, thread_id, event_time);
5444
5445     if (GetClassNameA(hwnd, buf, sizeof(buf)))
5446     {
5447         if (!lstrcmpiA(buf, "TestWindowClass") ||
5448             !lstrcmpiA(buf, "static"))
5449         {
5450             struct message msg;
5451
5452             msg.message = event;
5453             msg.flags = winevent_hook|wparam|lparam;
5454             msg.wParam = object_id;
5455             msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
5456             add_message(&msg);
5457         }
5458     }
5459 }
5460
5461 static HHOOK hCBT_global_hook;
5462 static DWORD cbt_global_hook_thread_id;
5463
5464 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
5465
5466     HWND hwnd;
5467     char buf[256];
5468
5469     trace("CBT_2: %d, %08x, %08lx\n", nCode, wParam, lParam);
5470
5471     if (nCode == HCBT_SYSCOMMAND)
5472     {
5473         struct message msg;
5474
5475         msg.message = nCode;
5476         msg.flags = hook|wparam|lparam;
5477         msg.wParam = wParam;
5478         msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
5479         add_message(&msg);
5480
5481         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
5482     }
5483
5484     /* Log also SetFocus(0) calls */
5485     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
5486
5487     if (GetClassNameA(hwnd, buf, sizeof(buf)))
5488     {
5489         if (!lstrcmpiA(buf, "TestWindowClass") ||
5490             !lstrcmpiA(buf, "static"))
5491         {
5492             struct message msg;
5493
5494             msg.message = nCode;
5495             msg.flags = hook|wparam|lparam;
5496             msg.wParam = wParam;
5497             msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
5498             add_message(&msg);
5499         }
5500     }
5501     return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
5502 }
5503
5504 static DWORD WINAPI win_event_global_thread_proc(void *param)
5505 {
5506     HWND hwnd;
5507     MSG msg;
5508     HANDLE hevent = *(HANDLE *)param;
5509     HMODULE user32 = GetModuleHandleA("user32.dll");
5510     FARPROC pNotifyWinEvent = GetProcAddress(user32, "NotifyWinEvent");
5511
5512     assert(pNotifyWinEvent);
5513
5514     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
5515     assert(hwnd);
5516     trace("created thread window %p\n", hwnd);
5517
5518     *(HWND *)param = hwnd;
5519
5520     flush_sequence();
5521     /* this event should be received only by our new hook proc,
5522      * an old one does not expect an event from another thread.
5523      */
5524     pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
5525     SetEvent(hevent);
5526
5527     while (GetMessage(&msg, 0, 0, 0))
5528     {
5529         TranslateMessage(&msg);
5530         DispatchMessage(&msg);
5531     }
5532     return 0;
5533 }
5534
5535 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
5536 {
5537     HWND hwnd;
5538     MSG msg;
5539     HANDLE hevent = *(HANDLE *)param;
5540
5541     flush_sequence();
5542     /* these events should be received only by our new hook proc,
5543      * an old one does not expect an event from another thread.
5544      */
5545
5546     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
5547     assert(hwnd);
5548     trace("created thread window %p\n", hwnd);
5549
5550     *(HWND *)param = hwnd;
5551
5552     /* Windows doesn't like when a thread plays games with the focus,
5553        that leads to all kinds of misbehaviours and failures to activate
5554        a window. So, better keep next lines commented out.
5555     SetFocus(0);
5556     SetFocus(hwnd);*/
5557
5558     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
5559     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
5560
5561     SetEvent(hevent);
5562
5563     while (GetMessage(&msg, 0, 0, 0))
5564     {
5565         TranslateMessage(&msg);
5566         DispatchMessage(&msg);
5567     }
5568     return 0;
5569 }
5570
5571 static void test_winevents(void)
5572 {
5573     BOOL ret;
5574     MSG msg;
5575     HWND hwnd, hwnd2;
5576     UINT i;
5577     HANDLE hthread, hevent;
5578     DWORD tid;
5579     HWINEVENTHOOK hhook;
5580     const struct message *events = WmWinEventsSeq;
5581     HMODULE user32 = GetModuleHandleA("user32.dll");
5582     FARPROC pSetWinEventHook = GetProcAddress(user32, "SetWinEventHook");
5583     FARPROC pUnhookWinEvent = GetProcAddress(user32, "UnhookWinEvent");
5584     FARPROC pNotifyWinEvent = GetProcAddress(user32, "NotifyWinEvent");
5585
5586     hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
5587                            WS_OVERLAPPEDWINDOW,
5588                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5589                            NULL, NULL, 0);
5590     assert(hwnd);
5591
5592     /****** start of global hook test *************/
5593     hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
5594     assert(hCBT_global_hook);
5595
5596     hevent = CreateEventA(NULL, 0, 0, NULL);
5597     assert(hevent);
5598     hwnd2 = (HWND)hevent;
5599
5600     hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
5601     ok(hthread != NULL, "CreateThread failed, error %ld\n", GetLastError());
5602
5603     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5604
5605     ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
5606
5607     flush_sequence();
5608     /* this one should be received only by old hook proc */
5609     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
5610     /* this one should be received only by old hook proc */
5611     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
5612
5613     ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
5614
5615     ret = UnhookWindowsHookEx(hCBT_global_hook);
5616     ok( ret, "UnhookWindowsHookEx error %ld\n", GetLastError());
5617
5618     PostThreadMessageA(tid, WM_QUIT, 0, 0);
5619     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5620     CloseHandle(hthread);
5621     CloseHandle(hevent);
5622     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
5623     /****** end of global hook test *************/
5624
5625     if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
5626     {
5627         ok(DestroyWindow(hwnd), "failed to destroy window\n");
5628         return;
5629     }
5630
5631     flush_sequence();
5632
5633 #if 0 /* this test doesn't pass under Win9x */
5634     /* win2k ignores events with hwnd == 0 */
5635     SetLastError(0xdeadbeef);
5636     pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
5637     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
5638        GetLastError() == 0xdeadbeef, /* Win9x */
5639        "unexpected error %ld\n", GetLastError());
5640     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
5641 #endif
5642
5643     for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
5644         pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
5645
5646     ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
5647
5648     /****** start of event filtering test *************/
5649     hhook = (HWINEVENTHOOK)pSetWinEventHook(
5650         EVENT_OBJECT_SHOW, /* 0x8002 */
5651         EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
5652         GetModuleHandleA(0), win_event_global_hook_proc,
5653         GetCurrentProcessId(), 0,
5654         WINEVENT_INCONTEXT);
5655     ok(hhook != 0, "SetWinEventHook error %ld\n", GetLastError());
5656
5657     hevent = CreateEventA(NULL, 0, 0, NULL);
5658     assert(hevent);
5659     hwnd2 = (HWND)hevent;
5660
5661     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
5662     ok(hthread != NULL, "CreateThread failed, error %ld\n", GetLastError());
5663
5664     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5665
5666     ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
5667
5668     flush_sequence();
5669     /* this one should be received only by old hook proc */
5670     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
5671     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
5672     /* this one should be received only by old hook proc */
5673     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
5674
5675     ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
5676
5677     ret = pUnhookWinEvent(hhook);
5678     ok( ret, "UnhookWinEvent error %ld\n", GetLastError());
5679
5680     PostThreadMessageA(tid, WM_QUIT, 0, 0);
5681     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5682     CloseHandle(hthread);
5683     CloseHandle(hevent);
5684     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
5685     /****** end of event filtering test *************/
5686
5687     /****** start of out of context event test *************/
5688     hhook = (HWINEVENTHOOK)pSetWinEventHook(
5689         EVENT_MIN, EVENT_MAX,
5690         0, win_event_global_hook_proc,
5691         GetCurrentProcessId(), 0,
5692         WINEVENT_OUTOFCONTEXT);
5693     ok(hhook != 0, "SetWinEventHook error %ld\n", GetLastError());
5694
5695     hevent = CreateEventA(NULL, 0, 0, NULL);
5696     assert(hevent);
5697     hwnd2 = (HWND)hevent;
5698
5699     flush_sequence();
5700
5701     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
5702     ok(hthread != NULL, "CreateThread failed, error %ld\n", GetLastError());
5703
5704     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5705
5706     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
5707     /* process pending winevent messages */
5708     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
5709     ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
5710
5711     flush_sequence();
5712     /* this one should be received only by old hook proc */
5713     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
5714     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
5715     /* this one should be received only by old hook proc */
5716     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
5717
5718     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
5719     /* process pending winevent messages */
5720     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
5721     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
5722
5723     ret = pUnhookWinEvent(hhook);
5724     ok( ret, "UnhookWinEvent error %ld\n", GetLastError());
5725
5726     PostThreadMessageA(tid, WM_QUIT, 0, 0);
5727     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5728     CloseHandle(hthread);
5729     CloseHandle(hevent);
5730     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
5731     /****** end of out of context event test *************/
5732
5733     ok(DestroyWindow(hwnd), "failed to destroy window\n");
5734 }
5735
5736 static void test_set_hook(void)
5737 {
5738     BOOL ret;
5739     HHOOK hhook;
5740     HWINEVENTHOOK hwinevent_hook;
5741     HMODULE user32 = GetModuleHandleA("user32.dll");
5742     FARPROC pSetWinEventHook = GetProcAddress(user32, "SetWinEventHook");
5743     FARPROC pUnhookWinEvent = GetProcAddress(user32, "UnhookWinEvent");
5744
5745     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
5746     ok(hhook != 0, "local hook does not require hModule set to 0\n");
5747     UnhookWindowsHookEx(hhook);
5748
5749 #if 0 /* this test doesn't pass under Win9x: BUG! */
5750     SetLastError(0xdeadbeef);
5751     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
5752     ok(!hhook, "global hook requires hModule != 0\n");
5753     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %ld\n", GetLastError());
5754 #endif
5755
5756     SetLastError(0xdeadbeef);
5757     hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
5758     ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
5759     ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
5760        GetLastError() == 0xdeadbeef, /* Win9x */
5761        "unexpected error %ld\n", GetLastError());
5762
5763     SetLastError(0xdeadbeef);
5764     ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
5765     ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
5766        GetLastError() == 0xdeadbeef, /* Win9x */
5767        "unexpected error %ld\n", GetLastError());
5768
5769     if (!pSetWinEventHook || !pUnhookWinEvent) return;
5770
5771     /* even process local incontext hooks require hmodule */
5772     SetLastError(0xdeadbeef);
5773     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
5774         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
5775     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
5776     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
5777        GetLastError() == 0xdeadbeef, /* Win9x */
5778        "unexpected error %ld\n", GetLastError());
5779
5780     /* even thread local incontext hooks require hmodule */
5781     SetLastError(0xdeadbeef);
5782     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
5783         0, win_event_proc, GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
5784     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
5785     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
5786        GetLastError() == 0xdeadbeef, /* Win9x */
5787        "unexpected error %ld\n", GetLastError());
5788
5789 #if 0 /* these 3 tests don't pass under Win9x */
5790     SetLastError(0xdeadbeef);
5791     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(1, 0,
5792         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
5793     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
5794     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %ld\n", GetLastError());
5795
5796     SetLastError(0xdeadbeef);
5797     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(-1, 1,
5798         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
5799     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
5800     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %ld\n", GetLastError());
5801
5802     SetLastError(0xdeadbeef);
5803     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
5804         0, win_event_proc, 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
5805     ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
5806     ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %ld\n", GetLastError());
5807 #endif
5808
5809     SetLastError(0xdeadbeef);
5810     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(0, 0,
5811         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
5812     ok(hwinevent_hook != 0, "SetWinEventHook error %ld\n", GetLastError());
5813     ok(GetLastError() == 0xdeadbeef, "unexpected error %ld\n", GetLastError());
5814     ret = pUnhookWinEvent(hwinevent_hook);
5815     ok( ret, "UnhookWinEvent error %ld\n", GetLastError());
5816
5817 todo_wine {
5818     /* This call succeeds under win2k SP4, but fails under Wine.
5819        Does win2k test/use passed process id? */
5820     SetLastError(0xdeadbeef);
5821     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
5822         0, win_event_proc, 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
5823     ok(hwinevent_hook != 0, "SetWinEventHook error %ld\n", GetLastError());
5824     ok(GetLastError() == 0xdeadbeef, "unexpected error %ld\n", GetLastError());
5825     ret = pUnhookWinEvent(hwinevent_hook);
5826     ok( ret, "UnhookWinEvent error %ld\n", GetLastError());
5827 }
5828
5829     SetLastError(0xdeadbeef);
5830     ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
5831     ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
5832         GetLastError() == 0xdeadbeef, /* Win9x */
5833         "unexpected error %ld\n", GetLastError());
5834 }
5835
5836 static const struct message ScrollWindowPaint1[] = {
5837     { WM_PAINT, sent },
5838     { WM_ERASEBKGND, sent|beginpaint },
5839     { 0 }
5840 };
5841
5842 static const struct message ScrollWindowPaint2[] = {
5843     { WM_PAINT, sent },
5844     { 0 }
5845 };
5846
5847 static void test_scrollwindowex(void)
5848 {
5849     HWND hwnd, hchild;
5850     RECT rect={0,0,130,130};
5851     MSG msg;
5852
5853     hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
5854             WS_VISIBLE|WS_OVERLAPPEDWINDOW,
5855             100, 100, 200, 200, 0, 0, 0, NULL);
5856     ok (hwnd != 0, "Failed to create overlapped window\n");
5857     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", 
5858             WS_VISIBLE|WS_CAPTION|WS_CHILD,
5859             10, 10, 150, 150, hwnd, 0, 0, NULL);
5860     ok (hchild != 0, "Failed to create child\n");
5861     UpdateWindow(hwnd);
5862     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5863     flush_sequence();
5864
5865     /* scroll without the child window */
5866     trace("start scroll\n");
5867     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
5868             SW_ERASE|SW_INVALIDATE);
5869     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
5870     trace("end scroll\n");
5871     flush_sequence();
5872     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5873     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
5874
5875     /* Now without the SW_ERASE flag */
5876     trace("start scroll\n");
5877     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
5878     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
5879     trace("end scroll\n");
5880     flush_sequence();
5881     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5882     ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
5883
5884     /* now scroll the child window as well */
5885     trace("start scroll\n");
5886     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
5887             SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
5888     todo_wine { /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
5889                 /* windows sometimes a WM_MOVE */
5890         ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
5891     }
5892     trace("end scroll\n");
5893     flush_sequence();
5894     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5895     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
5896
5897     /* now scroll with ScrollWindow() */
5898     trace("start scroll with ScrollWindow\n");
5899     ScrollWindow( hwnd, 5, 5, NULL, NULL);
5900     trace("end scroll\n");
5901     flush_sequence();
5902     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5903     ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
5904
5905     ok(DestroyWindow(hchild), "failed to destroy window\n");
5906     ok(DestroyWindow(hwnd), "failed to destroy window\n");
5907     flush_sequence();
5908 }
5909
5910 static const struct message destroy_window_with_children[] = {
5911     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
5912     { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
5913     { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
5914     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
5915     { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
5916     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
5917     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
5918     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
5919     { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
5920     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
5921     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
5922     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
5923     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
5924     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
5925     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
5926     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
5927     { 0 }
5928 };
5929
5930 static void test_DestroyWindow(void)
5931 {
5932     BOOL ret;
5933     HWND parent, child1, child2, child3, child4, test;
5934     UINT child_id = WND_CHILD_ID + 1;
5935
5936     parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
5937                              100, 100, 200, 200, 0, 0, 0, NULL);
5938     assert(parent != 0);
5939     child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
5940                              0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
5941     assert(child1 != 0);
5942     child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
5943                              0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
5944     assert(child2 != 0);
5945     child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
5946                              0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
5947     assert(child3 != 0);
5948     child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
5949                              0, 0, 50, 50, parent, 0, 0, NULL);
5950     assert(child4 != 0);
5951
5952     /* test owner/parent of child2 */
5953     test = GetParent(child2);
5954     ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
5955     ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
5956     if(pGetAncestor) {
5957         test = pGetAncestor(child2, GA_PARENT);
5958         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
5959     }
5960     test = GetWindow(child2, GW_OWNER);
5961     ok(!test, "wrong owner %p\n", test);
5962
5963     test = SetParent(child2, parent);
5964     ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
5965
5966     /* test owner/parent of the parent */
5967     test = GetParent(parent);
5968     ok(!test, "wrong parent %p\n", test);
5969 todo_wine {
5970     ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
5971 }
5972     if(pGetAncestor) {
5973         test = pGetAncestor(parent, GA_PARENT);
5974         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
5975     }
5976     test = GetWindow(parent, GW_OWNER);
5977     ok(!test, "wrong owner %p\n", test);
5978
5979     /* test owner/parent of child1 */
5980     test = GetParent(child1);
5981     ok(test == parent, "wrong parent %p\n", test);
5982     ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
5983     if(pGetAncestor) {
5984         test = pGetAncestor(child1, GA_PARENT);
5985         ok(test == parent, "wrong parent %p\n", test);
5986     }
5987     test = GetWindow(child1, GW_OWNER);
5988     ok(!test, "wrong owner %p\n", test);
5989
5990     /* test owner/parent of child2 */
5991     test = GetParent(child2);
5992     ok(test == parent, "wrong parent %p\n", test);
5993     ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
5994     if(pGetAncestor) {
5995         test = pGetAncestor(child2, GA_PARENT);
5996         ok(test == parent, "wrong parent %p\n", test);
5997     }
5998     test = GetWindow(child2, GW_OWNER);
5999     ok(!test, "wrong owner %p\n", test);
6000
6001     /* test owner/parent of child3 */
6002     test = GetParent(child3);
6003     ok(test == child1, "wrong parent %p\n", test);
6004     ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
6005     if(pGetAncestor) {
6006         test = pGetAncestor(child3, GA_PARENT);
6007         ok(test == child1, "wrong parent %p\n", test);
6008     }
6009     test = GetWindow(child3, GW_OWNER);
6010     ok(!test, "wrong owner %p\n", test);
6011
6012     /* test owner/parent of child4 */
6013     test = GetParent(child4);
6014     ok(test == parent, "wrong parent %p\n", test);
6015     ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
6016     if(pGetAncestor) {
6017         test = pGetAncestor(child4, GA_PARENT);
6018         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
6019     }
6020     test = GetWindow(child4, GW_OWNER);
6021     ok(test == parent, "wrong owner %p\n", test);
6022
6023     flush_sequence();
6024
6025     trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
6026            parent, child1, child2, child3, child4);
6027
6028     SetCapture(child4);
6029     test = GetCapture();
6030     ok(test == child4, "wrong capture window %p\n", test);
6031
6032     test_DestroyWindow_flag = TRUE;
6033     ret = DestroyWindow(parent);
6034     ok( ret, "DestroyWindow() error %ld\n", GetLastError());
6035     test_DestroyWindow_flag = FALSE;
6036     ok_sequence(destroy_window_with_children, "destroy window with children", 0);
6037
6038     ok(!IsWindow(parent), "parent still exists\n");
6039     ok(!IsWindow(child1), "child1 still exists\n");
6040     ok(!IsWindow(child2), "child2 still exists\n");
6041     ok(!IsWindow(child3), "child3 still exists\n");
6042     ok(!IsWindow(child4), "child4 still exists\n");
6043
6044     test = GetCapture();
6045     ok(!test, "wrong capture window %p\n", test);
6046 }
6047
6048
6049 static const struct message WmDispatchPaint[] = {
6050     { WM_NCPAINT, sent },
6051     { WM_GETTEXT, sent|defwinproc|optional },
6052     { WM_GETTEXT, sent|defwinproc|optional },
6053     { WM_ERASEBKGND, sent },
6054     { 0 }
6055 };
6056
6057 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6058 {
6059     if (message == WM_PAINT) return 0;
6060     return MsgCheckProcA( hwnd, message, wParam, lParam );
6061 }
6062
6063 static void test_DispatchMessage(void)
6064 {
6065     RECT rect;
6066     MSG msg;
6067     int count;
6068     HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
6069                                100, 100, 200, 200, 0, 0, 0, NULL);
6070     ShowWindow( hwnd, SW_SHOW );
6071     UpdateWindow( hwnd );
6072     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6073     flush_sequence();
6074     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
6075
6076     SetRect( &rect, -5, -5, 5, 5 );
6077     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
6078     count = 0;
6079     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
6080     {
6081         if (msg.message != WM_PAINT) DispatchMessage( &msg );
6082         else
6083         {
6084             flush_sequence();
6085             DispatchMessage( &msg );
6086             /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
6087             if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
6088             else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
6089             if (++count > 10) break;
6090         }
6091     }
6092     ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
6093
6094     trace("now without DispatchMessage\n");
6095     flush_sequence();
6096     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
6097     count = 0;
6098     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
6099     {
6100         if (msg.message != WM_PAINT) DispatchMessage( &msg );
6101         else
6102         {
6103             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
6104             flush_sequence();
6105             /* this will send WM_NCCPAINT just like DispatchMessage does */
6106             GetUpdateRgn( hwnd, hrgn, TRUE );
6107             ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
6108             DeleteObject( hrgn );
6109             GetClientRect( hwnd, &rect );
6110             ValidateRect( hwnd, &rect );  /* this will stop WM_PAINTs */
6111             ok( !count, "Got multiple WM_PAINTs\n" );
6112             if (++count > 10) break;
6113         }
6114     }
6115 }
6116
6117
6118 static const struct message WmUser[] = {
6119     { WM_USER, sent },
6120     { 0 }
6121 };
6122
6123 struct thread_info
6124 {
6125     HWND  hwnd;
6126     DWORD timeout;
6127     DWORD ret;
6128 };
6129
6130 static DWORD CALLBACK send_msg_thread( LPVOID arg )
6131 {
6132     struct thread_info *info = arg;
6133     info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
6134     if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT, "unexpected error %ld\n", GetLastError());
6135     return 0;
6136 }
6137
6138 static void wait_for_thread( HANDLE thread )
6139 {
6140     while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
6141     {
6142         MSG msg;
6143         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
6144     }
6145 }
6146
6147 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6148 {
6149     if (message == WM_USER) Sleep(200);
6150     return MsgCheckProcA( hwnd, message, wParam, lParam );
6151 }
6152
6153 static void test_SendMessageTimeout(void)
6154 {
6155     MSG msg;
6156     HANDLE thread;
6157     struct thread_info info;
6158     DWORD tid;
6159
6160     info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
6161                                100, 100, 200, 200, 0, 0, 0, NULL);
6162     while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6163     flush_sequence();
6164
6165     info.timeout = 1000;
6166     info.ret = 0xdeadbeef;
6167     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
6168     wait_for_thread( thread );
6169     CloseHandle( thread );
6170     ok( info.ret == 1, "SendMessageTimeout failed\n" );
6171     ok_sequence( WmUser, "WmUser", FALSE );
6172
6173     info.timeout = 1;
6174     info.ret = 0xdeadbeef;
6175     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
6176     Sleep(100);  /* SendMessageTimeout should timeout here */
6177     wait_for_thread( thread );
6178     CloseHandle( thread );
6179     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
6180     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6181
6182     /* 0 means infinite timeout */
6183     info.timeout = 0;
6184     info.ret = 0xdeadbeef;
6185     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
6186     Sleep(100);
6187     wait_for_thread( thread );
6188     CloseHandle( thread );
6189     ok( info.ret == 1, "SendMessageTimeout failed\n" );
6190     ok_sequence( WmUser, "WmUser", FALSE );
6191
6192     /* timeout is treated as signed despite the prototype */
6193     info.timeout = 0x7fffffff;
6194     info.ret = 0xdeadbeef;
6195     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
6196     Sleep(100);
6197     wait_for_thread( thread );
6198     CloseHandle( thread );
6199     ok( info.ret == 1, "SendMessageTimeout failed\n" );
6200     ok_sequence( WmUser, "WmUser", FALSE );
6201
6202     info.timeout = 0x80000000;
6203     info.ret = 0xdeadbeef;
6204     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
6205     Sleep(100);
6206     wait_for_thread( thread );
6207     CloseHandle( thread );
6208     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
6209     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6210
6211     /* now check for timeout during message processing */
6212     SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
6213     info.timeout = 100;
6214     info.ret = 0xdeadbeef;
6215     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
6216     wait_for_thread( thread );
6217     CloseHandle( thread );
6218     /* we should timeout but still get the message */
6219     ok( info.ret == 0, "SendMessageTimeout failed\n" );
6220     ok_sequence( WmUser, "WmUser", FALSE );
6221
6222     DestroyWindow( info.hwnd );
6223 }
6224
6225
6226 /****************** edit message test *************************/
6227 #define ID_EDIT 0x1234
6228 static const struct message sl_edit_setfocus[] =
6229 {
6230     { HCBT_SETFOCUS, hook },
6231     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
6232     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
6233     { WM_SETFOCUS, sent|wparam, 0 },
6234     { WM_CTLCOLOREDIT, sent|parent },
6235     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
6236     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
6237     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
6238     { 0 }
6239 };
6240 static const struct message ml_edit_setfocus[] =
6241 {
6242     { HCBT_SETFOCUS, hook },
6243     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
6244     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
6245     { WM_SETFOCUS, sent|wparam, 0 },
6246     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
6247     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
6248     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
6249     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
6250     { 0 }
6251 };
6252 static const struct message sl_edit_killfocus[] =
6253 {
6254     { HCBT_SETFOCUS, hook },
6255     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
6256     { WM_KILLFOCUS, sent|wparam, 0 },
6257     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
6258     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
6259     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
6260     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
6261     { 0 }
6262 };
6263 static const struct message sl_edit_lbutton_dblclk[] =
6264 {
6265     { WM_LBUTTONDBLCLK, sent },
6266     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6267     { 0 }
6268 };
6269 static const struct message sl_edit_lbutton_down[] =
6270 {
6271     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
6272     { HCBT_SETFOCUS, hook },
6273     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
6274     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
6275     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
6276     { WM_CTLCOLOREDIT, sent|parent },
6277     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
6278     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
6279     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
6280     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
6281     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6282     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
6283     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
6284     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
6285     { 0 }
6286 };
6287 static const struct message ml_edit_lbutton_down[] =
6288 {
6289     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
6290     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6291     { HCBT_SETFOCUS, hook },
6292     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
6293     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
6294     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
6295     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
6296     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
6297     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
6298     { 0 }
6299 };
6300 static const struct message sl_edit_lbutton_up[] =
6301 {
6302     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
6303     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
6304     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
6305     { WM_CAPTURECHANGED, sent|defwinproc },
6306     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
6307     { 0 }
6308 };
6309 static const struct message ml_edit_lbutton_up[] =
6310 {
6311     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
6312     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
6313     { WM_CAPTURECHANGED, sent|defwinproc },
6314     { 0 }
6315 };
6316
6317 static WNDPROC old_edit_proc;
6318
6319 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6320 {
6321     static long defwndproc_counter = 0;
6322     LRESULT ret;
6323     struct message msg;
6324
6325     trace("edit: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
6326
6327     /* explicitly ignore WM_GETICON message */
6328     if (message == WM_GETICON) return 0;
6329
6330     msg.message = message;
6331     msg.flags = sent|wparam|lparam;
6332     if (defwndproc_counter) msg.flags |= defwinproc;
6333     msg.wParam = wParam;
6334     msg.lParam = lParam;
6335     add_message(&msg);
6336
6337     defwndproc_counter++;
6338     ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
6339     defwndproc_counter--;
6340
6341     return ret;
6342 }
6343
6344 static void subclass_edit(void)
6345 {
6346     WNDCLASSA cls;
6347
6348     if (!GetClassInfoA(0, "edit", &cls)) assert(0);
6349
6350     old_edit_proc = cls.lpfnWndProc;
6351
6352     cls.hInstance = GetModuleHandle(0);
6353     cls.lpfnWndProc = edit_hook_proc;
6354     cls.lpszClassName = "my_edit_class";
6355     if (!RegisterClassA(&cls)) assert(0);
6356 }
6357
6358 static void test_edit_messages(void)
6359 {
6360     HWND hwnd, parent;
6361     DWORD dlg_code;
6362
6363     subclass_edit();
6364     log_all_parent_messages++;
6365
6366     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6367                              100, 100, 200, 200, 0, 0, 0, NULL);
6368     ok (parent != 0, "Failed to create parent window\n");
6369
6370     /* test single line edit */
6371     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
6372                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
6373     ok(hwnd != 0, "Failed to create edit window\n");
6374
6375     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
6376     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08lx\n", dlg_code);
6377
6378     ShowWindow(hwnd, SW_SHOW);
6379     UpdateWindow(hwnd);
6380     SetFocus(0);
6381     flush_sequence();
6382
6383     SetFocus(hwnd);
6384     ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
6385
6386     SetFocus(0);
6387     ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
6388
6389     SetFocus(0);
6390     ReleaseCapture();
6391     flush_sequence();
6392
6393     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
6394     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
6395
6396     SetFocus(0);
6397     ReleaseCapture();
6398     flush_sequence();
6399
6400     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
6401     ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
6402
6403     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
6404     ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
6405
6406     DestroyWindow(hwnd);
6407
6408     /* test multiline edit */
6409     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
6410                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
6411     ok(hwnd != 0, "Failed to create edit window\n");
6412
6413     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
6414     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
6415        "wrong dlg_code %08lx\n", dlg_code);
6416
6417     ShowWindow(hwnd, SW_SHOW);
6418     UpdateWindow(hwnd);
6419     SetFocus(0);
6420     flush_sequence();
6421
6422     SetFocus(hwnd);
6423     ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
6424
6425     SetFocus(0);
6426     ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
6427
6428     SetFocus(0);
6429     ReleaseCapture();
6430     flush_sequence();
6431
6432     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
6433     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
6434
6435     SetFocus(0);
6436     ReleaseCapture();
6437     flush_sequence();
6438
6439     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
6440     ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
6441
6442     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
6443     ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
6444
6445     DestroyWindow(hwnd);
6446     DestroyWindow(parent);
6447
6448     log_all_parent_messages--;
6449 }
6450
6451 /**************************** End of Edit test ******************************/
6452
6453 START_TEST(msg)
6454 {
6455     BOOL ret;
6456     HMODULE user32 = GetModuleHandleA("user32.dll");
6457     FARPROC pSetWinEventHook = GetProcAddress(user32, "SetWinEventHook");
6458     FARPROC pUnhookWinEvent = GetProcAddress(user32, "UnhookWinEvent");
6459     FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
6460     pGetAncestor = (void*) GetProcAddress(user32, "GetAncestor");
6461
6462     if (!RegisterWindowClasses()) assert(0);
6463
6464     if (pSetWinEventHook)
6465     {
6466         hEvent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
6467                                                       GetModuleHandleA(0),
6468                                                       win_event_proc,
6469                                                       0,
6470                                                       GetCurrentThreadId(),
6471                                                       WINEVENT_INCONTEXT);
6472         assert(hEvent_hook);
6473
6474         if (pIsWinEventHookInstalled)
6475         {
6476             UINT event;
6477             for (event = EVENT_MIN; event <= EVENT_MAX; event++)
6478                 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
6479         }
6480     }
6481
6482     cbt_hook_thread_id = GetCurrentThreadId();
6483     hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
6484     assert(hCBT_hook);
6485
6486     test_winevents();
6487
6488     /* Fix message sequences before removing 4 lines below */
6489 #if 1
6490     ret = pUnhookWinEvent(hEvent_hook);
6491     ok( ret, "UnhookWinEvent error %ld\n", GetLastError());
6492     pUnhookWinEvent = 0;
6493     hEvent_hook = 0;
6494 #endif
6495
6496     test_scrollwindowex();
6497     test_messages();
6498     test_mdi_messages();
6499     test_button_messages();
6500     test_paint_messages();
6501     test_interthread_messages();
6502     test_message_conversion();
6503     test_accelerators();
6504     test_timers();
6505     test_set_hook();
6506     test_DestroyWindow();
6507     test_DispatchMessage();
6508     test_SendMessageTimeout();
6509     test_edit_messages();
6510
6511     UnhookWindowsHookEx(hCBT_hook);
6512     if (pUnhookWinEvent)
6513     {
6514         ret = pUnhookWinEvent(hEvent_hook);
6515         ok( ret, "UnhookWinEvent error %ld\n", GetLastError());
6516         SetLastError(0xdeadbeef);
6517         ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
6518         ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
6519            GetLastError() == 0xdeadbeef, /* Win9x */
6520            "unexpected error %ld\n", GetLastError());
6521     }
6522 }