ddraw: Get rid of ddcomimpl.h.
[wine] / dlls / user32 / tests / msg.c
1 /*
2  * Unit tests for window message handling
3  *
4  * Copyright 1999 Ove Kaaven
5  * Copyright 2003 Dimitrie O. Paun
6  * Copyright 2004, 2005 Dmitry Timoshkov
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #define _WIN32_WINNT 0x0501 /* For WM_CHANGEUISTATE,QS_RAWINPUT */
24
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winnls.h"
34
35 #include "wine/test.h"
36
37 #define MDI_FIRST_CHILD_ID 2004
38
39 /* undocumented SWP flags - from SDK 3.1 */
40 #define SWP_NOCLIENTSIZE        0x0800
41 #define SWP_NOCLIENTMOVE        0x1000
42 #define SWP_STATECHANGED        0x8000
43
44 #define SW_NORMALNA             0xCC    /* undoc. flag in MinMaximize */
45
46 #ifndef WM_KEYF1
47 #define WM_KEYF1 0x004d
48 #endif
49
50 #ifndef WM_SYSTIMER
51 #define WM_SYSTIMER         0x0118
52 #endif
53
54 #define WND_PARENT_ID           1
55 #define WND_POPUP_ID            2
56 #define WND_CHILD_ID            3
57
58 #ifndef WM_LBTRACKPOINT
59 #define WM_LBTRACKPOINT  0x0131
60 #endif
61
62 /* encoded DRAWITEMSTRUCT into an LPARAM */
63 typedef struct
64 {
65     union
66     {
67         struct
68         {
69             UINT type    : 4;  /* ODT_* flags */
70             UINT ctl_id  : 4;  /* Control ID */
71             UINT item_id : 4;  /* Menu item ID */
72             UINT action  : 4;  /* ODA_* flags */
73             UINT state   : 16; /* ODS_* flags */
74         } item;
75         LPARAM lp;
76     } u;
77 } DRAW_ITEM_STRUCT;
78
79 static BOOL test_DestroyWindow_flag;
80 static HWINEVENTHOOK hEvent_hook;
81 static HHOOK hCBT_hook;
82 static DWORD cbt_hook_thread_id;
83
84 static const WCHAR testWindowClassW[] =
85 { 'T','e','s','t','W','i','n','d','o','w','C','l','a','s','s','W',0 };
86
87 /*
88 FIXME: add tests for these
89 Window Edge Styles (Win31/Win95/98 look), in order of precedence:
90  WS_EX_DLGMODALFRAME: double border, WS_CAPTION allowed
91  WS_THICKFRAME: thick border
92  WS_DLGFRAME: double border, WS_CAPTION not allowed (but possibly shown anyway)
93  WS_BORDER (default for overlapped windows): single black border
94  none (default for child (and popup?) windows): no border
95 */
96
97 typedef enum {
98     sent=0x1,
99     posted=0x2,
100     parent=0x4,
101     wparam=0x8,
102     lparam=0x10,
103     defwinproc=0x20,
104     beginpaint=0x40,
105     optional=0x80,
106     hook=0x100,
107     winevent_hook=0x200
108 } msg_flags_t;
109
110 struct message {
111     UINT message;          /* the WM_* code */
112     msg_flags_t flags;     /* message props */
113     WPARAM wParam;         /* expected value of wParam */
114     LPARAM lParam;         /* expected value of lParam */
115     WPARAM wp_mask;        /* mask for wParam checks */
116     LPARAM lp_mask;        /* mask for lParam checks */
117 };
118
119 struct recvd_message {
120     UINT message;          /* the WM_* code */
121     msg_flags_t flags;     /* message props */
122     HWND hwnd;             /* window that received the message */
123     WPARAM wParam;         /* expected value of wParam */
124     LPARAM lParam;         /* expected value of lParam */
125     int line;              /* source line where logged */
126     const char *descr;     /* description for trace output */
127     char output[512];      /* trace output */
128 };
129
130 /* Empty message sequence */
131 static const struct message WmEmptySeq[] =
132 {
133     { 0 }
134 };
135 /* CreateWindow (for overlapped window, not initially visible) (16/32) */
136 static const struct message WmCreateOverlappedSeq[] = {
137     { HCBT_CREATEWND, hook },
138     { WM_GETMINMAXINFO, sent },
139     { WM_NCCREATE, sent },
140     { WM_NCCALCSIZE, sent|wparam, 0 },
141     { 0x0093, sent|defwinproc|optional },
142     { 0x0094, sent|defwinproc|optional },
143     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
144     { WM_CREATE, sent },
145     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
146     { 0 }
147 };
148 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
149  * for a not visible overlapped window.
150  */
151 static const struct message WmSWP_ShowOverlappedSeq[] = {
152     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
153     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
154     { WM_NCPAINT, sent|wparam|optional, 1 },
155     { WM_GETTEXT, sent|defwinproc|optional },
156     { WM_ERASEBKGND, sent|optional },
157     { HCBT_ACTIVATE, hook },
158     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
159     { WM_NOTIFYFORMAT, sent|optional },
160     { WM_QUERYUISTATE, sent|optional },
161     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
162     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x: SWP_NOSENDCHANGING */
163     { WM_ACTIVATEAPP, sent|wparam, 1 },
164     { WM_NCACTIVATE, sent|wparam, 1 },
165     { WM_GETTEXT, sent|defwinproc|optional },
166     { WM_ACTIVATE, sent|wparam, 1 },
167     { HCBT_SETFOCUS, hook },
168     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
169     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
170     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
171     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
172     { WM_GETTEXT, sent|optional },
173     { WM_NCPAINT, sent|wparam|optional, 1 },
174     { WM_GETTEXT, sent|defwinproc|optional },
175     { WM_ERASEBKGND, sent|optional },
176     /* Win9x adds SWP_NOZORDER below */
177     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
178     { WM_GETTEXT, sent|optional },
179     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
180     { WM_NCPAINT, sent|wparam|optional, 1 },
181     { WM_ERASEBKGND, sent|optional },
182     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
183     { WM_PAINT, sent|optional },
184     { WM_NCPAINT, sent|beginpaint|optional },
185     { WM_ERASEBKGND, sent|beginpaint|optional },
186     { 0 }
187 };
188 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
189  * for a visible overlapped window.
190  */
191 static const struct message WmSWP_HideOverlappedSeq[] = {
192     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
193     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
194     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
195     { 0 }
196 };
197
198 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
199  * for a visible overlapped window.
200  */
201 static const struct message WmSWP_ResizeSeq[] = {
202     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
203     { WM_GETMINMAXINFO, sent|defwinproc },
204     { WM_NCCALCSIZE, sent|wparam, TRUE },
205     { WM_NCPAINT, sent|optional },
206     { WM_GETTEXT, sent|defwinproc|optional },
207     { WM_ERASEBKGND, sent|optional },
208     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
209     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
210     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
211     { WM_NCPAINT, sent|optional },
212     { WM_GETTEXT, sent|defwinproc|optional },
213     { WM_ERASEBKGND, sent|optional },
214     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
215     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
216     { 0 }
217 };
218
219 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
220  * for a visible popup window.
221  */
222 static const struct message WmSWP_ResizePopupSeq[] = {
223     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
224     { WM_GETMINMAXINFO, sent|defwinproc|optional }, /* Win9x */
225     { WM_NCCALCSIZE, sent|wparam, TRUE },
226     { WM_NCPAINT, sent|optional },
227     { WM_GETTEXT, sent|defwinproc|optional },
228     { WM_ERASEBKGND, sent|optional },
229     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
230     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
231     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
232     { WM_NCPAINT, sent|optional },
233     { WM_GETTEXT, sent|defwinproc|optional },
234     { WM_ERASEBKGND, sent|optional },
235     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
236     { 0 }
237 };
238
239 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
240  * for a visible overlapped window.
241  */
242 static const struct message WmSWP_MoveSeq[] = {
243     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE },
244     { WM_NCPAINT, sent|optional },
245     { WM_GETTEXT, sent|defwinproc|optional },
246     { WM_ERASEBKGND, sent|optional },
247     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
248     { WM_MOVE, sent|defwinproc|wparam, 0 },
249     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
250     { 0 }
251 };
252 /* Resize with SetWindowPos(SWP_NOZORDER)
253  * for a visible overlapped window
254  * SWP_NOZORDER is stripped by the logging code
255  */
256 static const struct message WmSWP_ResizeNoZOrder[] = {
257     { WM_WINDOWPOSCHANGING, sent|wparam, /*SWP_NOZORDER|*/SWP_NOACTIVATE },
258     { WM_GETMINMAXINFO, sent|defwinproc },
259     { WM_NCCALCSIZE, sent|wparam, 1 },
260     { WM_NCPAINT, sent },
261     { WM_GETTEXT, sent|defwinproc|optional },
262     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
263     { WM_WINDOWPOSCHANGED, sent|wparam, /*SWP_NOZORDER|*/SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE },
264     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
265     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
266     { WM_NCPAINT, sent|optional }, /* Win9x doesn't send it */
267     { WM_GETTEXT, sent|defwinproc|optional }, /* Win9x doesn't send it */
268     { WM_ERASEBKGND, sent|optional }, /* Win9x doesn't send it */
269     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
270     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
271     { 0 }
272 };
273
274 /* Switch visible mdi children */
275 static const struct message WmSwitchChild[] = {
276     /* Switch MDI child */
277     { WM_MDIACTIVATE, sent },/* in the MDI client */
278     { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 1st MDI child */
279     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
280     { WM_CHILDACTIVATE, sent },/* in the 1st MDI child */
281     /* Deactivate 2nd MDI child */
282     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
283     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
284     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
285     /* Preparing for maximize and maximaze the 1st MDI child */
286     { WM_GETMINMAXINFO, sent|defwinproc }, /* in the 1st MDI child */
287     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED }, /* in the 1st MDI child */
288     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
289     { WM_CHILDACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
290     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 1st MDI child */
291     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED }, /* in the 1st MDI child */
292     /* Lock redraw 2nd MDI child */
293     { WM_SETREDRAW, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
294     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
295     /* Restore 2nd MDI child */
296     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },/* in the 2nd MDI child */
297     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
298     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
299     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 2nd MDI child */
300     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED }, /* in the 2nd MDI child */
301     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
302     /* Redraw 2nd MDI child */
303     { WM_SETREDRAW, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
304     /* Redraw MDI frame */
305     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },/* in MDI frame */
306     { WM_NCCALCSIZE, sent|wparam, 1 },/* in MDI frame */
307     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in MDI frame */
308     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in MDI frame */
309     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
310     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
311     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
312     { HCBT_SETFOCUS, hook },
313     { WM_KILLFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
314     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },/* in the 1st MDI child */
315     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
316     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
317     { WM_SETFOCUS, sent },/* in the MDI client */
318     { HCBT_SETFOCUS, hook },
319     { WM_KILLFOCUS, sent },/* in the MDI client */
320     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
321     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 }, /* in the 1st MDI child */
322     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
323     { WM_SETFOCUS, sent|defwinproc }, /* in the 1st MDI child */
324     { WM_MDIACTIVATE, sent|defwinproc },/* in the 1st MDI child */
325     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* in the 1st MDI child */
326     { 0 }
327 };
328
329 /* Switch visible not maximized mdi children */
330 static const struct message WmSwitchNotMaximizedChild[] = {
331     /* Switch not maximized MDI child */
332     { WM_MDIACTIVATE, sent },/* in the MDI client */
333     { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 2nd MDI child */
334     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
335     { WM_CHILDACTIVATE, sent },/* in the 2nd MDI child */
336     /* Deactivate 1st MDI child */
337     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
338     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
339     /* Activate 2nd MDI child */
340     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE}, /* in the 2nd MDI child */
341     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 2nd MDI child */
342     { HCBT_SETFOCUS, hook }, /* in the 1st MDI child */
343     { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
344     { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
345     { WM_IME_SETCONTEXT, sent|optional }, /* in the  MDI client */
346     { WM_SETFOCUS, sent, 0 }, /* in the  MDI client */
347     { HCBT_SETFOCUS, hook },
348     { WM_KILLFOCUS, sent }, /* in the  MDI client */
349     { WM_IME_SETCONTEXT, sent|optional }, /* in the  MDI client */
350     { WM_IME_SETCONTEXT, sent|defwinproc|optional  }, /* in the 1st MDI child */
351     { WM_SETFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
352     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
353     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in the 2nd MDI child */
354     { 0 }
355 };
356
357
358 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
359                 SWP_NOZORDER|SWP_FRAMECHANGED)
360  * for a visible overlapped window with WS_CLIPCHILDREN style set.
361  */
362 static const struct message WmSWP_FrameChanged_clip[] = {
363     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
364     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
365     { WM_NCPAINT, sent|parent }, /* wparam != 1 */
366     { WM_GETTEXT, sent|parent|defwinproc|optional },
367     { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
368     { WM_NCPAINT, sent }, /* wparam != 1 */
369     { WM_ERASEBKGND, sent },
370     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
371     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
372     { WM_PAINT, sent },
373     { 0 }
374 };
375 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|
376                 SWP_NOZORDER|SWP_FRAMECHANGED)
377  * for a visible overlapped window.
378  */
379 static const struct message WmSWP_FrameChangedDeferErase[] = {
380     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
381     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
382     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
383     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
384     { WM_PAINT, sent|parent },
385     { WM_NCPAINT, sent|beginpaint|parent }, /* wparam != 1 */
386     { WM_GETTEXT, sent|beginpaint|parent|defwinproc|optional },
387     { WM_PAINT, sent },
388     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
389     { WM_ERASEBKGND, sent|beginpaint },
390     { 0 }
391 };
392
393 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
394                 SWP_NOZORDER|SWP_FRAMECHANGED)
395  * for a visible overlapped window without WS_CLIPCHILDREN style set.
396  */
397 static const struct message WmSWP_FrameChanged_noclip[] = {
398     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
399     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
400     { WM_NCPAINT, sent|parent }, /* wparam != 1 */
401     { WM_GETTEXT, sent|parent|defwinproc|optional },
402     { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
403     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
404     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
405     { WM_PAINT, sent },
406     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
407     { WM_ERASEBKGND, sent|beginpaint },
408     { 0 }
409 };
410
411 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
412 static const struct message WmShowOverlappedSeq[] = {
413     { WM_SHOWWINDOW, sent|wparam, 1 },
414     { WM_NCPAINT, sent|wparam|optional, 1 },
415     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
416     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
417     { WM_NCPAINT, sent|wparam|optional, 1 },
418     { WM_GETTEXT, sent|defwinproc|optional },
419     { WM_ERASEBKGND, sent|optional },
420     { HCBT_ACTIVATE, hook },
421     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
422     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
423     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
424     { WM_NCPAINT, sent|wparam|optional, 1 },
425     { WM_ACTIVATEAPP, sent|wparam, 1 },
426     { WM_NCACTIVATE, sent|wparam, 1 },
427     { WM_GETTEXT, sent|defwinproc|optional },
428     { WM_ACTIVATE, sent|wparam, 1 },
429     { HCBT_SETFOCUS, hook },
430     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
431     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
432     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
433     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
434     { WM_GETTEXT, sent|optional },
435     { WM_NCPAINT, sent|wparam|optional, 1 },
436     { WM_GETTEXT, sent|defwinproc|optional },
437     { WM_ERASEBKGND, sent|optional },
438     /* Win9x adds SWP_NOZORDER below */
439     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
440     { WM_NCCALCSIZE, sent|optional },
441     { WM_GETTEXT, sent|optional },
442     { WM_NCPAINT, sent|optional },
443     { WM_ERASEBKGND, sent|optional },
444 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
445        * messages. Does that mean that CreateWindow doesn't set initial
446        * window dimensions for overlapped windows?
447        */
448     { WM_SIZE, sent },
449     { WM_MOVE, sent },
450 #endif
451     { WM_PAINT, sent|optional },
452     { WM_NCPAINT, sent|beginpaint|optional },
453     { 0 }
454 };
455 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible overlapped window */
456 static const struct message WmShowMaxOverlappedSeq[] = {
457     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
458     { WM_GETMINMAXINFO, sent },
459     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
460     { WM_GETMINMAXINFO, sent|defwinproc },
461     { WM_NCCALCSIZE, sent|wparam, TRUE },
462     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
463     { HCBT_ACTIVATE, hook },
464     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
465     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
466     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
467     { WM_ACTIVATEAPP, sent|wparam, 1 },
468     { WM_NCACTIVATE, sent|wparam, 1 },
469     { WM_GETTEXT, sent|defwinproc|optional },
470     { WM_ACTIVATE, sent|wparam, 1 },
471     { HCBT_SETFOCUS, hook },
472     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
473     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
474     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
475     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
476     { WM_GETTEXT, sent|optional },
477     { WM_NCPAINT, sent|wparam|optional, 1 },
478     { WM_GETTEXT, sent|defwinproc|optional },
479     { WM_ERASEBKGND, sent|optional },
480     /* Win9x adds SWP_NOZORDER below */
481     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
482     { WM_MOVE, sent|defwinproc },
483     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
484     { WM_GETTEXT, sent|optional },
485     { WM_NCCALCSIZE, sent|optional },
486     { WM_NCPAINT, sent|optional },
487     { WM_ERASEBKGND, sent|optional },
488     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
489     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
490     { WM_PAINT, sent|optional },
491     { WM_NCPAINT, sent|beginpaint|optional },
492     { WM_ERASEBKGND, sent|beginpaint|optional },
493     { 0 }
494 };
495 /* ShowWindow(SW_RESTORE) for a not visible maximized overlapped window */
496 static const struct message WmShowRestoreMaxOverlappedSeq[] = {
497     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
498     { WM_GETTEXT, sent|optional },
499     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
500     { WM_GETMINMAXINFO, sent|defwinproc },
501     { WM_NCCALCSIZE, sent|wparam, TRUE },
502     { WM_NCPAINT, sent|optional },
503     { WM_GETTEXT, sent|defwinproc|optional },
504     { WM_ERASEBKGND, sent|optional },
505     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
506     { WM_MOVE, sent|defwinproc|optional },
507     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
508     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
509     { WM_NCPAINT, sent|optional },
510     { WM_ERASEBKGND, sent|optional },
511     { WM_PAINT, sent|optional },
512     { WM_NCPAINT, sent|beginpaint|optional },
513     { WM_ERASEBKGND, sent|beginpaint|optional },
514     { 0 }
515 };
516 /* ShowWindow(SW_RESTORE) for a not visible minimized overlapped window */
517 static const struct message WmShowRestoreMinOverlappedSeq[] = {
518     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
519     { WM_QUERYOPEN, sent|optional },
520     { WM_GETTEXT, sent|optional },
521     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED|SWP_NOCOPYBITS },
522     { WM_GETMINMAXINFO, sent|defwinproc },
523     { WM_NCCALCSIZE, sent|wparam, TRUE },
524     { HCBT_ACTIVATE, hook },
525     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
526     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
527     { WM_ACTIVATEAPP, sent|wparam, 1 },
528     { WM_NCACTIVATE, sent|wparam, 1 },
529     { WM_GETTEXT, sent|defwinproc|optional },
530     { WM_ACTIVATE, sent|wparam, 1 },
531     { HCBT_SETFOCUS, hook },
532     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
533     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
534     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
535     { WM_GETTEXT, sent|optional },
536     { WM_NCPAINT, sent|wparam|optional, 1 },
537     { WM_GETTEXT, sent|defwinproc|optional },
538     { WM_ERASEBKGND, sent },
539     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_STATECHANGED|SWP_FRAMECHANGED|SWP_NOCOPYBITS },
540     { WM_MOVE, sent|defwinproc },
541     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
542     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
543     { WM_NCPAINT, sent|wparam|optional, 1 },
544     { WM_ERASEBKGND, sent|optional },
545     { WM_ACTIVATE, sent|wparam, 1 },
546     { WM_GETTEXT, sent|optional },
547     { WM_PAINT, sent|optional },
548     { WM_NCPAINT, sent|beginpaint|optional },
549     { WM_ERASEBKGND, sent|beginpaint|optional },
550     { 0 }
551 };
552 /* ShowWindow(SW_SHOWMINIMIZED) for a not visible overlapped window */
553 static const struct message WmShowMinOverlappedSeq[] = {
554     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
555     { HCBT_SETFOCUS, hook },
556     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
557     { WM_KILLFOCUS, sent },
558     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
559     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
560     { WM_GETTEXT, sent|optional },
561     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCOPYBITS|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
562     { WM_GETMINMAXINFO, sent|defwinproc },
563     { WM_NCCALCSIZE, sent|wparam, TRUE },
564     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
565     { WM_NCPAINT, sent|optional },
566     { WM_GETTEXT, sent|defwinproc|optional },
567     { WM_WINDOWPOSCHANGED, sent },
568     { WM_MOVE, sent|defwinproc },
569     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
570     { WM_NCCALCSIZE, sent|optional },
571     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
572     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
573     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
574     { WM_NCACTIVATE, sent|wparam, 0 },
575     { WM_GETTEXT, sent|defwinproc|optional },
576     { WM_ACTIVATE, sent },
577     { WM_ACTIVATEAPP, sent|wparam, 0 },
578     { WM_PAINT, sent|optional },
579     { WM_NCPAINT, sent|beginpaint|optional },
580     { WM_ERASEBKGND, sent|beginpaint|optional },
581     { 0 }
582 };
583 /* ShowWindow(SW_HIDE) for a visible overlapped window */
584 static const struct message WmHideOverlappedSeq[] = {
585     { WM_SHOWWINDOW, sent|wparam, 0 },
586     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
587     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
588     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
589     { WM_SIZE, sent|optional }, /* XP doesn't send it */
590     { WM_MOVE, sent|optional }, /* XP doesn't send it */
591     { WM_NCACTIVATE, sent|wparam, 0 },
592     { WM_ACTIVATE, sent|wparam, 0 },
593     { WM_ACTIVATEAPP, sent|wparam, 0 },
594     { WM_KILLFOCUS, sent|wparam, 0 },
595     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
596     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
597     { 0 }
598 };
599 /* DestroyWindow for a visible overlapped window */
600 static const struct message WmDestroyOverlappedSeq[] = {
601     { HCBT_DESTROYWND, hook },
602     { 0x0090, sent|optional },
603     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
604     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
605     { 0x0090, sent|optional },
606     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
607     { WM_NCACTIVATE, sent|optional|wparam, 0 },
608     { WM_ACTIVATE, sent|optional|wparam, 0 },
609     { WM_ACTIVATEAPP, sent|optional|wparam, 0 },
610     { WM_KILLFOCUS, sent|optional|wparam, 0 },
611     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
612     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
613     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
614     { WM_DESTROY, sent },
615     { WM_NCDESTROY, sent },
616     { 0 }
617 };
618 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
619 static const struct message WmCreateMaxPopupSeq[] = {
620     { HCBT_CREATEWND, hook },
621     { WM_NCCREATE, sent },
622     { WM_NCCALCSIZE, sent|wparam, 0 },
623     { WM_CREATE, sent },
624     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
625     { WM_SIZE, sent|wparam, SIZE_RESTORED },
626     { WM_MOVE, sent },
627     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
628     { WM_GETMINMAXINFO, sent },
629     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
630     { WM_NCCALCSIZE, sent|wparam, TRUE },
631     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
632     { WM_MOVE, sent|defwinproc },
633     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
634     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
635     { WM_SHOWWINDOW, sent|wparam, 1 },
636     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
637     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
638     { HCBT_ACTIVATE, hook },
639     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
640     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
641     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
642     { WM_NCPAINT, sent|wparam|optional, 1 },
643     { WM_ERASEBKGND, sent|optional },
644     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_NOMOVE|SWP_NOSIZE },
645     { WM_ACTIVATEAPP, sent|wparam, 1 },
646     { WM_NCACTIVATE, sent|wparam, 1 },
647     { WM_ACTIVATE, sent|wparam, 1 },
648     { HCBT_SETFOCUS, hook },
649     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
650     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
651     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
652     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
653     { WM_GETTEXT, sent|optional },
654     { WM_SYNCPAINT, sent|wparam|optional, 4 },
655     { WM_NCPAINT, sent|wparam|optional, 1 },
656     { WM_ERASEBKGND, sent|optional },
657     { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
658     { WM_ERASEBKGND, sent|defwinproc|optional },
659     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
660     { 0 }
661 };
662 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
663 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
664     { HCBT_CREATEWND, hook },
665     { WM_NCCREATE, sent },
666     { WM_NCCALCSIZE, sent|wparam, 0 },
667     { WM_CREATE, sent },
668     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
669     { WM_SIZE, sent|wparam, SIZE_RESTORED },
670     { WM_MOVE, sent },
671     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
672     { WM_GETMINMAXINFO, sent },
673     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED  },
674     { WM_NCCALCSIZE, sent|wparam, TRUE },
675     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
676     { WM_MOVE, sent|defwinproc },
677     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
678     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
679     { 0 }
680 };
681 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
682 static const struct message WmShowMaxPopupResizedSeq[] = {
683     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
684     { WM_GETMINMAXINFO, sent },
685     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
686     { WM_NCCALCSIZE, sent|wparam, TRUE },
687     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
688     { HCBT_ACTIVATE, hook },
689     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
690     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
691     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
692     { WM_ACTIVATEAPP, sent|wparam, 1 },
693     { WM_NCACTIVATE, sent|wparam, 1 },
694     { WM_ACTIVATE, sent|wparam, 1 },
695     { HCBT_SETFOCUS, hook },
696     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
697     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
698     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
699     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
700     { WM_GETTEXT, sent|optional },
701     { WM_NCPAINT, sent|wparam|optional, 1 },
702     { WM_ERASEBKGND, sent|optional },
703     { WM_WINDOWPOSCHANGED, sent },
704     /* WinNT4.0 sends WM_MOVE */
705     { WM_MOVE, sent|defwinproc|optional },
706     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
707     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
708     { 0 }
709 };
710 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
711 static const struct message WmShowMaxPopupSeq[] = {
712     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
713     { WM_GETMINMAXINFO, sent },
714     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
715     { WM_NCCALCSIZE, sent|wparam, TRUE },
716     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
717     { HCBT_ACTIVATE, hook },
718     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
719     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
720     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
721     { WM_ACTIVATEAPP, sent|wparam, 1 },
722     { WM_NCACTIVATE, sent|wparam, 1 },
723     { WM_ACTIVATE, sent|wparam, 1 },
724     { HCBT_SETFOCUS, hook },
725     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
726     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
727     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
728     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
729     { WM_GETTEXT, sent|optional },
730     { WM_SYNCPAINT, sent|wparam|optional, 4 },
731     { WM_NCPAINT, sent|wparam|optional, 1 },
732     { WM_ERASEBKGND, sent|optional },
733     { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
734     { WM_ERASEBKGND, sent|defwinproc|optional },
735     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
736     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
737     { 0 }
738 };
739 /* CreateWindow(WS_VISIBLE) for popup window */
740 static const struct message WmCreatePopupSeq[] = {
741     { HCBT_CREATEWND, hook },
742     { WM_NCCREATE, sent },
743     { WM_NCCALCSIZE, sent|wparam, 0 },
744     { WM_CREATE, sent },
745     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
746     { WM_SIZE, sent|wparam, SIZE_RESTORED },
747     { WM_MOVE, sent },
748     { WM_SHOWWINDOW, sent|wparam, 1 },
749     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
750     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
751     { HCBT_ACTIVATE, hook },
752     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
753     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
754     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
755     { WM_NCPAINT, sent|wparam|optional, 1 },
756     { WM_ERASEBKGND, sent|optional },
757     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
758     { WM_ACTIVATEAPP, sent|wparam, 1 },
759     { WM_NCACTIVATE, sent|wparam, 1 },
760     { WM_ACTIVATE, sent|wparam, 1 },
761     { HCBT_SETFOCUS, hook },
762     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
763     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
764     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
765     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
766     { WM_GETTEXT, sent|optional },
767     { WM_SYNCPAINT, sent|wparam|optional, 4 },
768     { WM_NCPAINT, sent|wparam|optional, 1 },
769     { WM_ERASEBKGND, sent|optional },
770     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
771     { 0 }
772 };
773 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
774 static const struct message WmShowVisMaxPopupSeq[] = {
775     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
776     { WM_GETMINMAXINFO, sent },
777     { WM_GETTEXT, sent|optional },
778     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
779     { WM_GETTEXT, sent|optional },
780     { WM_NCCALCSIZE, sent|wparam, TRUE },
781     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
782     { WM_NCPAINT, sent|wparam|optional, 1 },
783     { WM_ERASEBKGND, sent|optional },
784     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
785     { WM_MOVE, sent|defwinproc },
786     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
787     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
788     { 0 }
789 };
790 /* CreateWindow (for a child popup window, not initially visible) */
791 static const struct message WmCreateChildPopupSeq[] = {
792     { HCBT_CREATEWND, hook },
793     { WM_NCCREATE, sent }, 
794     { WM_NCCALCSIZE, sent|wparam, 0 },
795     { WM_CREATE, sent },
796     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
797     { WM_SIZE, sent|wparam, SIZE_RESTORED },
798     { WM_MOVE, sent },
799     { 0 }
800 };
801 /* CreateWindow (for a popup window, not initially visible,
802  * which sets WS_VISIBLE in WM_CREATE handler)
803  */
804 static const struct message WmCreateInvisiblePopupSeq[] = {
805     { HCBT_CREATEWND, hook },
806     { WM_NCCREATE, sent }, 
807     { WM_NCCALCSIZE, sent|wparam, 0 },
808     { WM_CREATE, sent },
809     { WM_STYLECHANGING, sent },
810     { WM_STYLECHANGED, sent },
811     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
812     { WM_SIZE, sent|wparam, SIZE_RESTORED },
813     { WM_MOVE, sent },
814     { 0 }
815 };
816 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
817  * for a popup window with WS_VISIBLE style set
818  */
819 static const struct message WmShowVisiblePopupSeq_2[] = {
820     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
821     { 0 }
822 };
823 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
824  * for a popup window with WS_VISIBLE style set
825  */
826 static const struct message WmShowVisiblePopupSeq_3[] = {
827     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
828     { HCBT_ACTIVATE, hook },
829     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
830     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
831     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
832     { WM_NCACTIVATE, sent|wparam, 1 },
833     { WM_ACTIVATE, sent|wparam, 1 },
834     { HCBT_SETFOCUS, hook },
835     { WM_KILLFOCUS, sent|parent },
836     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
837     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
838     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
839     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
840     { WM_SETFOCUS, sent|defwinproc },
841     { WM_GETTEXT, sent|optional },
842     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
843     { 0 }
844 };
845 /* CreateWindow (for child window, not initially visible) */
846 static const struct message WmCreateChildSeq[] = {
847     { HCBT_CREATEWND, hook },
848     { WM_NCCREATE, sent }, 
849     /* child is inserted into parent's child list after WM_NCCREATE returns */
850     { WM_NCCALCSIZE, sent|wparam, 0 },
851     { WM_CREATE, sent },
852     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
853     { WM_SIZE, sent|wparam, SIZE_RESTORED },
854     { WM_MOVE, sent },
855     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
856     { 0 }
857 };
858 /* CreateWindow (for maximized child window, not initially visible) */
859 static const struct message WmCreateMaximizedChildSeq[] = {
860     { HCBT_CREATEWND, hook },
861     { WM_NCCREATE, sent }, 
862     { WM_NCCALCSIZE, sent|wparam, 0 },
863     { WM_CREATE, sent },
864     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
865     { WM_SIZE, sent|wparam, SIZE_RESTORED },
866     { WM_MOVE, sent },
867     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
868     { WM_GETMINMAXINFO, sent },
869     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
870     { WM_NCCALCSIZE, sent|wparam, 1 },
871     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
872     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
873     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
874     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
875     { 0 }
876 };
877 /* CreateWindow (for a child window, initially visible) */
878 static const struct message WmCreateVisibleChildSeq[] = {
879     { HCBT_CREATEWND, hook },
880     { WM_NCCREATE, sent }, 
881     /* child is inserted into parent's child list after WM_NCCREATE returns */
882     { WM_NCCALCSIZE, sent|wparam, 0 },
883     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
884     { WM_CREATE, sent },
885     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
886     { WM_SIZE, sent|wparam, SIZE_RESTORED },
887     { WM_MOVE, sent },
888     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
889     { WM_SHOWWINDOW, sent|wparam, 1 },
890     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
891     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
892     { WM_ERASEBKGND, sent|parent|optional },
893     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
894     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
895     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
896     { 0 }
897 };
898 /* ShowWindow(SW_SHOW) for a not visible child window */
899 static const struct message WmShowChildSeq[] = {
900     { WM_SHOWWINDOW, sent|wparam, 1 },
901     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
902     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
903     { WM_ERASEBKGND, sent|parent|optional },
904     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
905     { 0 }
906 };
907 /* ShowWindow(SW_HIDE) for a visible child window */
908 static const struct message WmHideChildSeq[] = {
909     { WM_SHOWWINDOW, sent|wparam, 0 },
910     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
911     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
912     { WM_ERASEBKGND, sent|parent|optional },
913     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
914     { 0 }
915 };
916 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
917 static const struct message WmHideChildSeq2[] = {
918     { WM_SHOWWINDOW, sent|wparam, 0 },
919     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
920     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
921     { WM_ERASEBKGND, sent|parent|optional },
922     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
923     { 0 }
924 };
925 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
926  * for a not visible child window
927  */
928 static const struct message WmShowChildSeq_2[] = {
929     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
930     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
931     { WM_CHILDACTIVATE, sent },
932     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
933     { 0 }
934 };
935 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
936  * for a not visible child window
937  */
938 static const struct message WmShowChildSeq_3[] = {
939     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
940     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
941     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
942     { 0 }
943 };
944 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
945  * for a visible child window with a caption
946  */
947 static const struct message WmShowChildSeq_4[] = {
948     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
949     { WM_CHILDACTIVATE, sent },
950     { 0 }
951 };
952 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
953 static const struct message WmShowChildInvisibleParentSeq_1[] = {
954     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
955     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
956     { WM_NCCALCSIZE, sent|wparam, 1 },
957     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
958     { WM_CHILDACTIVATE, sent|optional },
959     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
960     { WM_MOVE, sent|defwinproc },
961     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
962     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
963     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
964     /* FIXME: Wine creates an icon/title window while Windows doesn't */
965     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
966     { WM_GETTEXT, sent|optional },
967     { 0 }
968 };
969 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
970 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
971     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
972     { 0 }
973 };
974 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
975 static const struct message WmShowChildInvisibleParentSeq_2[] = {
976     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
977     { WM_GETMINMAXINFO, sent },
978     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
979     { WM_NCCALCSIZE, sent|wparam, 1 },
980     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
981     { WM_CHILDACTIVATE, sent },
982     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
983     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
984     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
985     { 0 }
986 };
987 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
988 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
989     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
990     { 0 }
991 };
992 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
993 static const struct message WmShowChildInvisibleParentSeq_3[] = {
994     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
995     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
996     { WM_NCCALCSIZE, sent|wparam, 1 },
997     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
998     { WM_CHILDACTIVATE, sent },
999     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1000     { WM_MOVE, sent|defwinproc },
1001     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
1002     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1003     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1004     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1005     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1006     { WM_GETTEXT, sent|optional },
1007     { 0 }
1008 };
1009 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1010 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
1011     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1012     { 0 }
1013 };
1014 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1015 static const struct message WmShowChildInvisibleParentSeq_4[] = {
1016     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1017     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
1018     { WM_NCCALCSIZE, sent|wparam, 1 },
1019     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1020     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1021     { WM_MOVE, sent|defwinproc },
1022     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
1023     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1024     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1025     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1026     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1027     { WM_GETTEXT, sent|optional },
1028     { 0 }
1029 };
1030 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1031 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
1032     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1033     { 0 }
1034 };
1035 /* ShowWindow(SW_SHOW) for child with invisible parent */
1036 static const struct message WmShowChildInvisibleParentSeq_5[] = {
1037     { WM_SHOWWINDOW, sent|wparam, 1 },
1038     { 0 }
1039 };
1040 /* ShowWindow(SW_HIDE) for child with invisible parent */
1041 static const struct message WmHideChildInvisibleParentSeq[] = {
1042     { WM_SHOWWINDOW, sent|wparam, 0 },
1043     { 0 }
1044 };
1045 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
1046 static const struct message WmShowChildInvisibleParentSeq_6[] = {
1047     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1048     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1049     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1050     { 0 }
1051 };
1052 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
1053 static const struct message WmHideChildInvisibleParentSeq_2[] = {
1054     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1055     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1056     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1057     { 0 }
1058 };
1059 /* DestroyWindow for a visible child window */
1060 static const struct message WmDestroyChildSeq[] = {
1061     { HCBT_DESTROYWND, hook },
1062     { 0x0090, sent|optional },
1063     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1064     { WM_SHOWWINDOW, sent|wparam, 0 },
1065     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1066     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1067     { WM_ERASEBKGND, sent|parent|optional },
1068     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1069     { HCBT_SETFOCUS, hook }, /* set focus to a parent */
1070     { WM_KILLFOCUS, sent },
1071     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1072     { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
1073     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1074     { WM_SETFOCUS, sent|parent },
1075     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1076     { WM_DESTROY, sent },
1077     { WM_DESTROY, sent|optional }, /* some other (IME?) window */
1078     { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
1079     { WM_NCDESTROY, sent },
1080     { 0 }
1081 };
1082 /* DestroyWindow for a visible child window with invisible parent */
1083 static const struct message WmDestroyInvisibleChildSeq[] = {
1084     { HCBT_DESTROYWND, hook },
1085     { 0x0090, sent|optional },
1086     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1087     { WM_SHOWWINDOW, sent|wparam, 0 },
1088     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1089     { WM_DESTROY, sent },
1090     { WM_NCDESTROY, sent },
1091     { 0 }
1092 };
1093 /* Moving the mouse in nonclient area */
1094 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
1095     { WM_NCHITTEST, sent },
1096     { WM_SETCURSOR, sent },
1097     { WM_NCMOUSEMOVE, posted },
1098     { 0 }
1099 };
1100 /* Moving the mouse in client area */
1101 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
1102     { WM_NCHITTEST, sent },
1103     { WM_SETCURSOR, sent },
1104     { WM_MOUSEMOVE, posted },
1105     { 0 }
1106 };
1107 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1108 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
1109     { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
1110     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
1111     { WM_GETMINMAXINFO, sent|defwinproc },
1112     { WM_ENTERSIZEMOVE, sent|defwinproc },
1113     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1114     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1115     { WM_MOVE, sent|defwinproc },
1116     { WM_EXITSIZEMOVE, sent|defwinproc },
1117     { 0 }
1118 };
1119 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1120 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
1121     { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
1122     { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
1123     { WM_GETMINMAXINFO, sent|defwinproc },
1124     { WM_ENTERSIZEMOVE, sent|defwinproc },
1125     { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
1126     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1127     { WM_GETMINMAXINFO, sent|defwinproc },
1128     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1129     { WM_NCPAINT, sent|defwinproc|wparam, 1 },
1130     { WM_GETTEXT, sent|defwinproc },
1131     { WM_ERASEBKGND, sent|defwinproc },
1132     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1133     { WM_MOVE, sent|defwinproc },
1134     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1135     { WM_EXITSIZEMOVE, sent|defwinproc },
1136     { 0 }
1137 };
1138 /* Resizing child window with MoveWindow (32) */
1139 static const struct message WmResizingChildWithMoveWindowSeq[] = {
1140     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1141     { WM_NCCALCSIZE, sent|wparam, 1 },
1142     { WM_ERASEBKGND, sent|parent|optional },
1143     { WM_ERASEBKGND, sent|optional },
1144     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
1145     { WM_MOVE, sent|defwinproc },
1146     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1147     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1148     { 0 }
1149 };
1150 /* Clicking on inactive button */
1151 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
1152     { WM_NCHITTEST, sent },
1153     { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
1154     { WM_MOUSEACTIVATE, sent },
1155     { WM_MOUSEACTIVATE, sent|parent|defwinproc },
1156     { WM_SETCURSOR, sent },
1157     { WM_SETCURSOR, sent|parent|defwinproc },
1158     { WM_LBUTTONDOWN, posted },
1159     { WM_KILLFOCUS, posted|parent },
1160     { WM_SETFOCUS, posted },
1161     { WM_CTLCOLORBTN, posted|parent },
1162     { BM_SETSTATE, posted },
1163     { WM_CTLCOLORBTN, posted|parent },
1164     { WM_LBUTTONUP, posted },
1165     { BM_SETSTATE, posted },
1166     { WM_CTLCOLORBTN, posted|parent },
1167     { WM_COMMAND, posted|parent },
1168     { 0 }
1169 };
1170 /* Reparenting a button (16/32) */
1171 /* The last child (button) reparented gets topmost for its new parent. */
1172 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
1173     { WM_SHOWWINDOW, sent|wparam, 0 },
1174     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1175     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1176     { WM_ERASEBKGND, sent|parent },
1177     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1178     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
1179     { WM_CHILDACTIVATE, sent },
1180     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
1181     { WM_MOVE, sent|defwinproc },
1182     { WM_SHOWWINDOW, sent|wparam, 1 },
1183     { 0 }
1184 };
1185 /* Creation of a custom dialog (32) */
1186 static const struct message WmCreateCustomDialogSeq[] = {
1187     { HCBT_CREATEWND, hook },
1188     { WM_GETMINMAXINFO, sent },
1189     { WM_NCCREATE, sent },
1190     { WM_NCCALCSIZE, sent|wparam, 0 },
1191     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1192     { WM_CREATE, sent },
1193     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1194     { WM_NOTIFYFORMAT, sent|optional },
1195     { WM_QUERYUISTATE, sent|optional },
1196     { WM_WINDOWPOSCHANGING, sent|optional },
1197     { WM_GETMINMAXINFO, sent|optional },
1198     { WM_NCCALCSIZE, sent|optional },
1199     { WM_WINDOWPOSCHANGED, sent|optional },
1200     { WM_SHOWWINDOW, sent|wparam, 1 },
1201     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1202     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1203     { HCBT_ACTIVATE, hook },
1204     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1205
1206
1207     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1208
1209     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1210
1211     { WM_NCACTIVATE, sent|wparam, 1 },
1212     { WM_GETTEXT, sent|optional|defwinproc },
1213     { WM_GETTEXT, sent|optional|defwinproc },
1214     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1215     { WM_ACTIVATE, sent|wparam, 1 },
1216     { WM_GETTEXT, sent|optional },
1217     { WM_KILLFOCUS, sent|parent },
1218     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1219     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1220     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1221     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1222     { WM_SETFOCUS, sent },
1223     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1224     { WM_NCPAINT, sent|wparam, 1 },
1225     { WM_GETTEXT, sent|optional|defwinproc },
1226     { WM_GETTEXT, sent|optional|defwinproc },
1227     { WM_ERASEBKGND, sent },
1228     { WM_CTLCOLORDLG, sent|defwinproc },
1229     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1230     { WM_GETTEXT, sent|optional },
1231     { WM_GETTEXT, sent|optional },
1232     { WM_NCCALCSIZE, sent|optional },
1233     { WM_NCPAINT, sent|optional },
1234     { WM_GETTEXT, sent|optional|defwinproc },
1235     { WM_GETTEXT, sent|optional|defwinproc },
1236     { WM_ERASEBKGND, sent|optional },
1237     { WM_CTLCOLORDLG, sent|optional|defwinproc },
1238     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1239     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1240     { WM_MOVE, sent },
1241     { 0 }
1242 };
1243 /* Calling EndDialog for a custom dialog (32) */
1244 static const struct message WmEndCustomDialogSeq[] = {
1245     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1246     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1247     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1248     { WM_GETTEXT, sent|optional },
1249     { HCBT_ACTIVATE, hook },
1250     { WM_NCACTIVATE, sent|wparam, 0 },
1251     { WM_GETTEXT, sent|optional|defwinproc },
1252     { WM_GETTEXT, sent|optional|defwinproc },
1253     { WM_ACTIVATE, sent|wparam, 0 },
1254     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1255     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1256     { HCBT_SETFOCUS, hook },
1257     { WM_KILLFOCUS, sent },
1258     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1259     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1260     { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1261     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1262     { WM_SETFOCUS, sent|parent|defwinproc },
1263     { 0 }
1264 };
1265 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1266 static const struct message WmShowCustomDialogSeq[] = {
1267     { WM_SHOWWINDOW, sent|wparam, 1 },
1268     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1269     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1270     { HCBT_ACTIVATE, hook },
1271     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1272
1273     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1274
1275     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1276     { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1277     { WM_NCACTIVATE, sent|wparam, 1 },
1278     { WM_ACTIVATE, sent|wparam, 1 },
1279     { WM_GETTEXT, sent|optional },
1280
1281     { WM_KILLFOCUS, sent|parent },
1282     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1283     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1284     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1285     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1286     { WM_SETFOCUS, sent },
1287     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1288     { WM_NCPAINT, sent|wparam, 1 },
1289     { WM_ERASEBKGND, sent },
1290     { WM_CTLCOLORDLG, sent|defwinproc },
1291     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1292     { 0 }
1293 };
1294 /* Creation and destruction of a modal dialog (32) */
1295 static const struct message WmModalDialogSeq[] = {
1296     { WM_CANCELMODE, sent|parent },
1297     { HCBT_SETFOCUS, hook },
1298     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1299     { WM_KILLFOCUS, sent|parent },
1300     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1301     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1302     { WM_ENABLE, sent|parent|wparam, 0 },
1303     { HCBT_CREATEWND, hook },
1304     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1305     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1306     { WM_SETFONT, sent },
1307     { WM_INITDIALOG, sent },
1308     { WM_CHANGEUISTATE, sent|optional },
1309     { WM_UPDATEUISTATE, sent|optional },
1310     { WM_SHOWWINDOW, sent },
1311     { HCBT_ACTIVATE, hook },
1312     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1313     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1314     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1315     { WM_NCACTIVATE, sent|wparam, 1 },
1316     { WM_GETTEXT, sent|optional },
1317     { WM_ACTIVATE, sent|wparam, 1 },
1318     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1319     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1320     { WM_NCPAINT, sent },
1321     { WM_GETTEXT, sent|optional },
1322     { WM_ERASEBKGND, sent },
1323     { WM_CTLCOLORDLG, sent },
1324     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1325     { WM_GETTEXT, sent|optional },
1326     { WM_NCCALCSIZE, sent|optional },
1327     { WM_NCPAINT, sent|optional },
1328     { WM_GETTEXT, sent|optional },
1329     { WM_ERASEBKGND, sent|optional },
1330     { WM_CTLCOLORDLG, sent|optional },
1331     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1332     { WM_PAINT, sent|optional },
1333     { WM_CTLCOLORBTN, sent },
1334     { WM_ENTERIDLE, sent|parent|optional },
1335     { WM_ENTERIDLE, sent|parent|optional },
1336     { WM_ENTERIDLE, sent|parent|optional },
1337     { WM_ENTERIDLE, sent|parent|optional },
1338     { WM_ENTERIDLE, sent|parent|optional },
1339     { WM_ENTERIDLE, sent|parent|optional },
1340     { WM_ENTERIDLE, sent|parent|optional },
1341     { WM_ENTERIDLE, sent|parent|optional },
1342     { WM_ENTERIDLE, sent|parent|optional },
1343     { WM_ENTERIDLE, sent|parent|optional },
1344     { WM_ENTERIDLE, sent|parent|optional },
1345     { WM_ENTERIDLE, sent|parent|optional },
1346     { WM_ENTERIDLE, sent|parent|optional },
1347     { WM_ENTERIDLE, sent|parent|optional },
1348     { WM_ENTERIDLE, sent|parent|optional },
1349     { WM_ENTERIDLE, sent|parent|optional },
1350     { WM_ENTERIDLE, sent|parent|optional },
1351     { WM_ENTERIDLE, sent|parent|optional },
1352     { WM_ENTERIDLE, sent|parent|optional },
1353     { WM_ENTERIDLE, sent|parent|optional },
1354     { WM_TIMER, sent },
1355     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1356     { WM_ENABLE, sent|parent|wparam, 1 },
1357     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1358     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1359     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1360     { WM_GETTEXT, sent|optional },
1361     { HCBT_ACTIVATE, hook },
1362     { WM_NCACTIVATE, sent|wparam, 0 },
1363     { WM_GETTEXT, sent|optional },
1364     { WM_ACTIVATE, sent|wparam, 0 },
1365     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1366     { WM_WINDOWPOSCHANGING, sent|optional },
1367     { WM_WINDOWPOSCHANGED, sent|optional },
1368     { HCBT_SETFOCUS, hook },
1369     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1370     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1371     { WM_SETFOCUS, sent|parent|defwinproc },
1372     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1373     { HCBT_DESTROYWND, hook },
1374     { 0x0090, sent|optional },
1375     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1376     { WM_DESTROY, sent },
1377     { WM_NCDESTROY, sent },
1378     { 0 }
1379 };
1380 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1381 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1382     /* (inside dialog proc, handling WM_INITDIALOG) */
1383     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1384     { WM_NCCALCSIZE, sent },
1385     { WM_NCACTIVATE, sent|parent|wparam, 0 },
1386     { WM_GETTEXT, sent|defwinproc },
1387     { WM_ACTIVATE, sent|parent|wparam, 0 },
1388     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1389     { WM_WINDOWPOSCHANGING, sent|parent },
1390     { WM_NCACTIVATE, sent|wparam, 1 },
1391     { WM_ACTIVATE, sent|wparam, 1 },
1392     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1393     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1394     /* (setting focus) */
1395     { WM_SHOWWINDOW, sent|wparam, 1 },
1396     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1397     { WM_NCPAINT, sent },
1398     { WM_GETTEXT, sent|defwinproc },
1399     { WM_ERASEBKGND, sent },
1400     { WM_CTLCOLORDLG, sent|defwinproc },
1401     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1402     { WM_PAINT, sent },
1403     /* (bunch of WM_CTLCOLOR* for each control) */
1404     { WM_PAINT, sent|parent },
1405     { WM_ENTERIDLE, sent|parent|wparam, 0 },
1406     { WM_SETCURSOR, sent|parent },
1407     { 0 }
1408 };
1409 /* SetMenu for NonVisible windows with size change*/
1410 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1411     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1412     { WM_NCCALCSIZE, sent|wparam, 1 },
1413     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1414     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1415     { WM_MOVE, sent|defwinproc },
1416     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1417     { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1418     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1419     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1420     { WM_GETTEXT, sent|optional },
1421     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1422     { 0 }
1423 };
1424 /* SetMenu for NonVisible windows with no size change */
1425 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1426     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1427     { WM_NCCALCSIZE, sent|wparam, 1 },
1428     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1429     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1430     { 0 }
1431 };
1432 /* SetMenu for Visible windows with size change */
1433 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1434     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1435     { WM_NCCALCSIZE, sent|wparam, 1 },
1436     { 0x0093, sent|defwinproc|optional },
1437     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1438     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1439     { 0x0093, sent|defwinproc|optional },
1440     { 0x0093, sent|defwinproc|optional },
1441     { 0x0091, sent|defwinproc|optional },
1442     { 0x0092, sent|defwinproc|optional },
1443     { WM_GETTEXT, sent|defwinproc|optional },
1444     { WM_ERASEBKGND, sent|optional },
1445     { WM_ACTIVATE, sent|optional },
1446     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1447     { WM_MOVE, sent|defwinproc },
1448     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1449     { 0x0093, sent|optional },
1450     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1451     { 0x0093, sent|defwinproc|optional },
1452     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1453     { 0x0093, sent|defwinproc|optional },
1454     { 0x0093, sent|defwinproc|optional },
1455     { 0x0091, sent|defwinproc|optional },
1456     { 0x0092, sent|defwinproc|optional },
1457     { WM_ERASEBKGND, sent|optional },
1458     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1459     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1460     { 0 }
1461 };
1462 /* SetMenu for Visible windows with no size change */
1463 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1464     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1465     { WM_NCCALCSIZE, sent|wparam, 1 },
1466     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1467     { WM_GETTEXT, sent|defwinproc|optional },
1468     { WM_ERASEBKGND, sent|optional },
1469     { WM_ACTIVATE, sent|optional },
1470     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1471     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1472     { 0 }
1473 };
1474 /* DrawMenuBar for a visible window */
1475 static const struct message WmDrawMenuBarSeq[] =
1476 {
1477     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1478     { WM_NCCALCSIZE, sent|wparam, 1 },
1479     { 0x0093, sent|defwinproc|optional },
1480     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1481     { 0x0093, sent|defwinproc|optional },
1482     { 0x0093, sent|defwinproc|optional },
1483     { 0x0091, sent|defwinproc|optional },
1484     { 0x0092, sent|defwinproc|optional },
1485     { WM_GETTEXT, sent|defwinproc|optional },
1486     { WM_ERASEBKGND, sent|optional },
1487     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1488     { 0x0093, sent|optional },
1489     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1490     { 0 }
1491 };
1492
1493 static const struct message WmSetRedrawFalseSeq[] =
1494 {
1495     { WM_SETREDRAW, sent|wparam, 0 },
1496     { 0 }
1497 };
1498
1499 static const struct message WmSetRedrawTrueSeq[] =
1500 {
1501     { WM_SETREDRAW, sent|wparam, 1 },
1502     { 0 }
1503 };
1504
1505 static const struct message WmEnableWindowSeq_1[] =
1506 {
1507     { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1508     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1509     { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1510     { 0 }
1511 };
1512
1513 static const struct message WmEnableWindowSeq_2[] =
1514 {
1515     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1516     { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1517     { 0 }
1518 };
1519
1520 static const struct message WmGetScrollRangeSeq[] =
1521 {
1522     { SBM_GETRANGE, sent },
1523     { 0 }
1524 };
1525 static const struct message WmGetScrollInfoSeq[] =
1526 {
1527     { SBM_GETSCROLLINFO, sent },
1528     { 0 }
1529 };
1530 static const struct message WmSetScrollRangeSeq[] =
1531 {
1532     /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1533        sends SBM_SETSCROLLINFO.
1534      */
1535     { SBM_SETSCROLLINFO, sent },
1536     { 0 }
1537 };
1538 /* SetScrollRange for a window without a non-client area */
1539 static const struct message WmSetScrollRangeHSeq_empty[] =
1540 {
1541     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1542     { 0 }
1543 };
1544 static const struct message WmSetScrollRangeVSeq_empty[] =
1545 {
1546     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1547     { 0 }
1548 };
1549 static const struct message WmSetScrollRangeHVSeq[] =
1550 {
1551     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1552     { WM_NCCALCSIZE, sent|wparam, 1 },
1553     { WM_GETTEXT, sent|defwinproc|optional },
1554     { WM_ERASEBKGND, sent|optional },
1555     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1556     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1557     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1558     { 0 }
1559 };
1560 /* SetScrollRange for a window with a non-client area */
1561 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1562 {
1563     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1564     { WM_NCCALCSIZE, sent|wparam, 1 },
1565     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1566     { WM_NCPAINT, sent|optional },
1567     { WM_STYLECHANGING, sent|defwinproc|optional },
1568     { WM_STYLECHANGED, sent|defwinproc|optional },
1569     { WM_STYLECHANGING, sent|defwinproc|optional },
1570     { WM_STYLECHANGED, sent|defwinproc|optional },
1571     { WM_STYLECHANGING, sent|defwinproc|optional },
1572     { WM_STYLECHANGED, sent|defwinproc|optional },
1573     { WM_STYLECHANGING, sent|defwinproc|optional },
1574     { WM_STYLECHANGED, sent|defwinproc|optional },
1575     { WM_GETTEXT, sent|defwinproc|optional },
1576     { WM_GETTEXT, sent|defwinproc|optional },
1577     { WM_ERASEBKGND, sent|optional },
1578     { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1579     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE },
1580     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1581     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1582     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1583     { WM_GETTEXT, sent|optional },
1584     { WM_GETTEXT, sent|optional },
1585     { WM_GETTEXT, sent|optional },
1586     { WM_GETTEXT, sent|optional },
1587     { 0 }
1588 };
1589 /* test if we receive the right sequence of messages */
1590 /* after calling ShowWindow( SW_SHOWNA) */
1591 static const struct message WmSHOWNAChildInvisParInvis[] = {
1592     { WM_SHOWWINDOW, sent|wparam, 1 },
1593     { 0 }
1594 };
1595 static const struct message WmSHOWNAChildVisParInvis[] = {
1596     { WM_SHOWWINDOW, sent|wparam, 1 },
1597     { 0 }
1598 };
1599 static const struct message WmSHOWNAChildVisParVis[] = {
1600     { WM_SHOWWINDOW, sent|wparam, 1 },
1601     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1602     { 0 }
1603 };
1604 static const struct message WmSHOWNAChildInvisParVis[] = {
1605     { WM_SHOWWINDOW, sent|wparam, 1 },
1606     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1607     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1608     { WM_ERASEBKGND, sent|optional },
1609     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1610     { 0 }
1611 };
1612 static const struct message WmSHOWNATopVisible[] = {
1613     { WM_SHOWWINDOW, sent|wparam, 1 },
1614     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1615     { WM_NCPAINT, sent|wparam|optional, 1 },
1616     { WM_GETTEXT, sent|defwinproc|optional },
1617     { WM_ERASEBKGND, sent|optional },
1618     { WM_WINDOWPOSCHANGED, sent|optional },
1619     { 0 }
1620 };
1621 static const struct message WmSHOWNATopInvisible[] = {
1622     { WM_NOTIFYFORMAT, sent|optional },
1623     { WM_QUERYUISTATE, sent|optional },
1624     { WM_WINDOWPOSCHANGING, sent|optional },
1625     { WM_GETMINMAXINFO, sent|optional },
1626     { WM_NCCALCSIZE, sent|optional },
1627     { WM_WINDOWPOSCHANGED, sent|optional },
1628     { WM_SHOWWINDOW, sent|wparam, 1 },
1629     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1630     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1631     { WM_NCPAINT, sent|wparam, 1 },
1632     { WM_GETTEXT, sent|defwinproc|optional },
1633     { WM_ERASEBKGND, sent|optional },
1634     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1635     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1636     { WM_NCPAINT, sent|wparam|optional, 1 },
1637     { WM_ERASEBKGND, sent|optional },
1638     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1639     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1640     { WM_MOVE, sent },
1641     { 0 }
1642 };
1643
1644 static int after_end_dialog, test_def_id;
1645 static int sequence_cnt, sequence_size;
1646 static struct recvd_message* sequence;
1647 static int log_all_parent_messages;
1648 static int paint_loop_done;
1649
1650 /* user32 functions */
1651 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1652 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
1653 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1654 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
1655 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1656 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1657 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1658 /* kernel32 functions */
1659 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1660
1661 static void init_procs(void)
1662 {
1663     HMODULE user32 = GetModuleHandleA("user32.dll");
1664     HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1665
1666 #define GET_PROC(dll, func) \
1667     p ## func = (void*)GetProcAddress(dll, #func); \
1668     if(!p ## func) { \
1669       trace("GetProcAddress(%s) failed\n", #func); \
1670     }
1671
1672     GET_PROC(user32, GetAncestor)
1673     GET_PROC(user32, GetMenuInfo)
1674     GET_PROC(user32, NotifyWinEvent)
1675     GET_PROC(user32, SetMenuInfo)
1676     GET_PROC(user32, SetWinEventHook)
1677     GET_PROC(user32, TrackMouseEvent)
1678     GET_PROC(user32, UnhookWinEvent)
1679
1680     GET_PROC(kernel32, GetCPInfoExA)
1681
1682 #undef GET_PROC
1683 }
1684
1685 static const char *get_winpos_flags(UINT flags)
1686 {
1687     static char buffer[300];
1688
1689     buffer[0] = 0;
1690 #define DUMP(flag) do { if (flags & flag) { strcat( buffer, "|" #flag ); flags &= ~flag; } } while(0)
1691     DUMP( SWP_SHOWWINDOW );
1692     DUMP( SWP_HIDEWINDOW );
1693     DUMP( SWP_NOACTIVATE );
1694     DUMP( SWP_FRAMECHANGED );
1695     DUMP( SWP_NOCOPYBITS );
1696     DUMP( SWP_NOOWNERZORDER );
1697     DUMP( SWP_NOSENDCHANGING );
1698     DUMP( SWP_DEFERERASE );
1699     DUMP( SWP_ASYNCWINDOWPOS );
1700     DUMP( SWP_NOZORDER );
1701     DUMP( SWP_NOREDRAW );
1702     DUMP( SWP_NOSIZE );
1703     DUMP( SWP_NOMOVE );
1704     DUMP( SWP_NOCLIENTSIZE );
1705     DUMP( SWP_NOCLIENTMOVE );
1706     if (flags) sprintf(buffer + strlen(buffer),"|0x%04x", flags);
1707     return buffer + 1;
1708 #undef DUMP
1709 }
1710
1711
1712 #define add_message(msg) add_message_(__LINE__,msg);
1713 static void add_message_(int line, const struct recvd_message *msg)
1714 {
1715     struct recvd_message *seq;
1716
1717     if (!sequence) 
1718     {
1719         sequence_size = 10;
1720         sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof(*sequence) );
1721     }
1722     if (sequence_cnt == sequence_size) 
1723     {
1724         sequence_size *= 2;
1725         sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof(*sequence) );
1726     }
1727     assert(sequence);
1728
1729     seq = &sequence[sequence_cnt];
1730     seq->hwnd = msg->hwnd;
1731     seq->message = msg->message;
1732     seq->flags = msg->flags;
1733     seq->wParam = msg->wParam;
1734     seq->lParam = msg->lParam;
1735     seq->line   = line;
1736     seq->descr  = msg->descr;
1737     seq->output[0] = 0;
1738
1739     if (msg->descr)
1740     {
1741         if (msg->flags & hook)
1742         {
1743             static const char * const CBT_code_name[10] =
1744             {
1745                 "HCBT_MOVESIZE",
1746                 "HCBT_MINMAX",
1747                 "HCBT_QS",
1748                 "HCBT_CREATEWND",
1749                 "HCBT_DESTROYWND",
1750                 "HCBT_ACTIVATE",
1751                 "HCBT_CLICKSKIPPED",
1752                 "HCBT_KEYSKIPPED",
1753                 "HCBT_SYSCOMMAND",
1754                 "HCBT_SETFOCUS"
1755             };
1756             const char *code_name = (msg->message <= HCBT_SETFOCUS) ? CBT_code_name[msg->message] : "Unknown";
1757
1758             snprintf( seq->output, sizeof(seq->output), "%s: hook %d (%s) wp %08lx lp %08lx",
1759                       msg->descr, msg->message, code_name, msg->wParam, msg->lParam );
1760         }
1761         else if (msg->flags & winevent_hook)
1762         {
1763             snprintf( seq->output, sizeof(seq->output), "%s: winevent %p %08x %08lx %08lx",
1764                       msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1765         }
1766         else
1767         {
1768             switch (msg->message)
1769             {
1770             case WM_WINDOWPOSCHANGING:
1771             case WM_WINDOWPOSCHANGED:
1772             {
1773                 WINDOWPOS *winpos = (WINDOWPOS *)msg->lParam;
1774
1775                 snprintf( seq->output, sizeof(seq->output),
1776                           "%s: %p WM_WINDOWPOS%s wp %08lx lp %08lx after %p x %d y %d cx %d cy %d flags %s",
1777                           msg->descr, msg->hwnd,
1778                           (msg->message == WM_WINDOWPOSCHANGING) ? "CHANGING" : "CHANGED",
1779                           msg->wParam, msg->lParam, winpos->hwndInsertAfter,
1780                           winpos->x, winpos->y, winpos->cx, winpos->cy,
1781                           get_winpos_flags(winpos->flags) );
1782
1783                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
1784                  * in the high word for internal purposes
1785                  */
1786                 seq->wParam = winpos->flags & 0xffff;
1787                 /* We are not interested in the flags that don't match under XP and Win9x */
1788                 seq->wParam &= ~SWP_NOZORDER;
1789                 break;
1790             }
1791
1792             case WM_DRAWITEM:
1793             {
1794                 DRAW_ITEM_STRUCT di;
1795                 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)msg->lParam;
1796
1797                 snprintf( seq->output, sizeof(seq->output),
1798                           "%s: %p WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x",
1799                           msg->descr, msg->hwnd, dis->CtlType, dis->CtlID,
1800                           dis->itemID, dis->itemAction, dis->itemState);
1801
1802                 di.u.item.type = dis->CtlType;
1803                 di.u.item.ctl_id = dis->CtlID;
1804                 di.u.item.item_id = dis->itemID;
1805                 di.u.item.action = dis->itemAction;
1806                 di.u.item.state = dis->itemState;
1807
1808                 seq->lParam = di.u.lp;
1809                 break;
1810             }
1811             default:
1812                 if (msg->message >= 0xc000) return;  /* ignore registered messages */
1813                 snprintf( seq->output, sizeof(seq->output), "%s: %p %04x wp %08lx lp %08lx",
1814                           msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1815             }
1816         }
1817     }
1818
1819     sequence_cnt++;
1820 }
1821
1822 /* try to make sure pending X events have been processed before continuing */
1823 static void flush_events(void)
1824 {
1825     MSG msg;
1826     int diff = 200;
1827     int min_timeout = 100;
1828     DWORD time = GetTickCount() + diff;
1829
1830     while (diff > 0)
1831     {
1832         if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1833         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1834         diff = time - GetTickCount();
1835         min_timeout = 50;
1836     }
1837 }
1838
1839 static void flush_sequence(void)
1840 {
1841     HeapFree(GetProcessHeap(), 0, sequence);
1842     sequence = 0;
1843     sequence_cnt = sequence_size = 0;
1844 }
1845
1846 static void dump_sequence(const struct message *expected, const char *context, const char *file, int line)
1847 {
1848     const struct recvd_message *actual = sequence;
1849     unsigned int count = 0;
1850
1851     trace_(file, line)("Failed sequence %s:\n", context );
1852     while (expected->message && actual->message)
1853     {
1854         if (actual->output[0])
1855         {
1856             if (expected->flags & hook)
1857             {
1858                 trace_(file, line)( "  %u: expected: hook %04x - actual: %s\n",
1859                                     count, expected->message, actual->output );
1860             }
1861             else if (expected->flags & winevent_hook)
1862             {
1863                 trace_(file, line)( "  %u: expected: winevent %04x - actual: %s\n",
1864                                     count, expected->message, actual->output );
1865             }
1866             else
1867             {
1868                 trace_(file, line)( "  %u: expected: msg %04x - actual: %s\n",
1869                                     count, expected->message, actual->output );
1870             }
1871         }
1872
1873         if (expected->message == actual->message)
1874         {
1875             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) &&
1876                 (expected->flags & optional))
1877             {
1878                 /* don't match messages if their defwinproc status differs */
1879                 expected++;
1880             }
1881             else
1882             {
1883                 expected++;
1884                 actual++;
1885             }
1886         }
1887         /* silently drop winevent messages if there is no support for them */
1888         else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1889             expected++;
1890         else
1891         {
1892             expected++;
1893             actual++;
1894         }
1895         count++;
1896     }
1897
1898     /* optional trailing messages */
1899     while (expected->message && ((expected->flags & optional) ||
1900             ((expected->flags & winevent_hook) && !hEvent_hook)))
1901     {
1902         trace_(file, line)( "  %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1903         expected++;
1904         count++;
1905     }
1906
1907     if (expected->message)
1908         trace_(file, line)( "  %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1909     else if (actual->message && actual->output[0])
1910         trace_(file, line)( "  %u: expected: nothing - actual: %s\n", count, actual->output );
1911 }
1912
1913 #define ok_sequence( exp, contx, todo) \
1914         ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
1915
1916
1917 static void ok_sequence_(const struct message *expected_list, const char *context, int todo,
1918                          const char *file, int line)
1919 {
1920     static const struct recvd_message end_of_sequence;
1921     const struct message *expected = expected_list;
1922     const struct recvd_message *actual;
1923     int failcount = 0, dump = 0;
1924     unsigned int count = 0;
1925
1926     add_message(&end_of_sequence);
1927
1928     actual = sequence;
1929
1930     while (expected->message && actual->message)
1931     {
1932         if (expected->message == actual->message)
1933         {
1934             if (expected->flags & wparam)
1935             {
1936                 if (((expected->wParam ^ actual->wParam) & ~expected->wp_mask) && todo)
1937                 {
1938                     todo_wine {
1939                         failcount ++;
1940                         if (strcmp(winetest_platform, "wine")) dump++;
1941                         ok_( file, line) (FALSE,
1942                             "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1943                             context, count, expected->message, expected->wParam, actual->wParam);
1944                     }
1945                 }
1946                 else
1947                 {
1948                     ok_( file, line)( ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) == 0,
1949                                      "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1950                                      context, count, expected->message, expected->wParam, actual->wParam);
1951                     if ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) dump++;
1952                 }
1953
1954             }
1955             if (expected->flags & lparam)
1956             {
1957                 if (((expected->lParam ^ actual->lParam) & ~expected->lp_mask) && todo)
1958                 {
1959                     todo_wine {
1960                         failcount ++;
1961                         if (strcmp(winetest_platform, "wine")) dump++;
1962                         ok_( file, line) (FALSE,
1963                             "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1964                             context, count, expected->message, expected->lParam, actual->lParam);
1965                     }
1966                 }
1967                 else
1968                 {
1969                     ok_( file, line)(((expected->lParam ^ actual->lParam) & ~expected->lp_mask) == 0,
1970                                      "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1971                                      context, count, expected->message, expected->lParam, actual->lParam);
1972                     if ((expected->lParam ^ actual->lParam) & ~expected->lp_mask) dump++;
1973                 }
1974             }
1975             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) &&
1976                 (expected->flags & optional))
1977             {
1978                 /* don't match messages if their defwinproc status differs */
1979                 expected++;
1980                 count++;
1981                 continue;
1982             }
1983             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
1984             {
1985                     todo_wine {
1986                         failcount ++;
1987                         if (strcmp(winetest_platform, "wine")) dump++;
1988                         ok_( file, line) (FALSE,
1989                             "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1990                             context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1991                     }
1992             }
1993             else
1994             {
1995                 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
1996                     "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1997                     context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1998                 if ((expected->flags & defwinproc) != (actual->flags & defwinproc)) dump++;
1999             }
2000
2001             ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
2002                 "%s: %u: the msg 0x%04x should %shave been sent by BeginPaint\n",
2003                 context, count, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
2004             if ((expected->flags & beginpaint) != (actual->flags & beginpaint)) dump++;
2005
2006             ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
2007                 "%s: %u: the msg 0x%04x should have been %s\n",
2008                 context, count, expected->message, (expected->flags & posted) ? "posted" : "sent");
2009             if ((expected->flags & (sent|posted)) != (actual->flags & (sent|posted))) dump++;
2010
2011             ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
2012                 "%s: %u: the msg 0x%04x was expected in %s\n",
2013                 context, count, expected->message, (expected->flags & parent) ? "parent" : "child");
2014             if ((expected->flags & parent) != (actual->flags & parent)) dump++;
2015
2016             ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
2017                 "%s: %u: the msg 0x%04x should have been sent by a hook\n",
2018                 context, count, expected->message);
2019             if ((expected->flags & hook) != (actual->flags & hook)) dump++;
2020
2021             ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
2022                 "%s: %u: the msg 0x%04x should have been sent by a winevent hook\n",
2023                 context, count, expected->message);
2024             if ((expected->flags & winevent_hook) != (actual->flags & winevent_hook)) dump++;
2025
2026             expected++;
2027             actual++;
2028         }
2029         /* silently drop hook messages if there is no support for them */
2030         else if ((expected->flags & optional) ||
2031                  ((expected->flags & hook) && !hCBT_hook) ||
2032                  ((expected->flags & winevent_hook) && !hEvent_hook))
2033             expected++;
2034         else if (todo)
2035         {
2036             failcount++;
2037             todo_wine {
2038                 if (strcmp(winetest_platform, "wine")) dump++;
2039                 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2040                                   context, count, expected->message, actual->message);
2041             }
2042             goto done;
2043         }
2044         else
2045         {
2046             ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2047                               context, count, expected->message, actual->message);
2048             dump++;
2049             expected++;
2050             actual++;
2051         }
2052         count++;
2053     }
2054
2055     /* skip all optional trailing messages */
2056     while (expected->message && ((expected->flags & optional) ||
2057                                  ((expected->flags & hook) && !hCBT_hook) ||
2058                                  ((expected->flags & winevent_hook) && !hEvent_hook)))
2059         expected++;
2060
2061     if (todo)
2062     {
2063         todo_wine {
2064             if (expected->message || actual->message) {
2065                 failcount++;
2066                 if (strcmp(winetest_platform, "wine")) dump++;
2067                 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2068                                   context, count, expected->message, actual->message);
2069             }
2070         }
2071     }
2072     else
2073     {
2074         if (expected->message || actual->message)
2075         {
2076             dump++;
2077             ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2078                               context, count, expected->message, actual->message);
2079         }
2080     }
2081     if( todo && !failcount) /* succeeded yet marked todo */
2082         todo_wine {
2083             if (!strcmp(winetest_platform, "wine")) dump++;
2084             ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
2085         }
2086
2087 done:
2088     if (dump) dump_sequence(expected_list, context, file, line);
2089     flush_sequence();
2090 }
2091
2092 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
2093
2094 /******************************** MDI test **********************************/
2095
2096 /* CreateWindow for MDI frame window, initially visible */
2097 static const struct message WmCreateMDIframeSeq[] = {
2098     { HCBT_CREATEWND, hook },
2099     { WM_GETMINMAXINFO, sent },
2100     { WM_NCCREATE, sent },
2101     { WM_NCCALCSIZE, sent|wparam, 0 },
2102     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2103     { WM_CREATE, sent },
2104     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2105     { WM_NOTIFYFORMAT, sent|optional },
2106     { WM_QUERYUISTATE, sent|optional },
2107     { WM_WINDOWPOSCHANGING, sent|optional },
2108     { WM_GETMINMAXINFO, sent|optional },
2109     { WM_NCCALCSIZE, sent|optional },
2110     { WM_WINDOWPOSCHANGED, sent|optional },
2111     { WM_SHOWWINDOW, sent|wparam, 1 },
2112     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2113     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2114     { HCBT_ACTIVATE, hook },
2115     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
2116     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
2117     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
2118     { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
2119     { WM_NCACTIVATE, sent|wparam, 1 },
2120     { WM_GETTEXT, sent|defwinproc|optional },
2121     { WM_ACTIVATE, sent|wparam, 1 },
2122     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
2123     { HCBT_SETFOCUS, hook },
2124     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2125     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2126     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2127     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
2128     /* Win9x adds SWP_NOZORDER below */
2129     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2130     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2131     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2132     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2133     { WM_MOVE, sent },
2134     { 0 }
2135 };
2136 /* DestroyWindow for MDI frame window, initially visible */
2137 static const struct message WmDestroyMDIframeSeq[] = {
2138     { HCBT_DESTROYWND, hook },
2139     { 0x0090, sent|optional },
2140     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2141     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2142     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2143     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2144     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
2145     { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2146     { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
2147     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
2148     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2149     { WM_DESTROY, sent },
2150     { WM_NCDESTROY, sent },
2151     { 0 }
2152 };
2153 /* CreateWindow for MDI client window, initially visible */
2154 static const struct message WmCreateMDIclientSeq[] = {
2155     { HCBT_CREATEWND, hook },
2156     { WM_NCCREATE, sent },
2157     { WM_NCCALCSIZE, sent|wparam, 0 },
2158     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2159     { WM_CREATE, sent },
2160     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2161     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2162     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2163     { WM_MOVE, sent },
2164     { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
2165     { WM_SHOWWINDOW, sent|wparam, 1 },
2166     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2167     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2168     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2169     { 0 }
2170 };
2171 /* ShowWindow(SW_SHOW) for MDI client window */
2172 static const struct message WmShowMDIclientSeq[] = {
2173     { WM_SHOWWINDOW, sent|wparam, 1 },
2174     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2175     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2176     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2177     { 0 }
2178 };
2179 /* ShowWindow(SW_HIDE) for MDI client window */
2180 static const struct message WmHideMDIclientSeq[] = {
2181     { WM_SHOWWINDOW, sent|wparam, 0 },
2182     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2183     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
2184     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
2185     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2186     { 0 }
2187 };
2188 /* DestroyWindow for MDI client window, initially visible */
2189 static const struct message WmDestroyMDIclientSeq[] = {
2190     { HCBT_DESTROYWND, hook },
2191     { 0x0090, sent|optional },
2192     { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
2193     { WM_SHOWWINDOW, sent|wparam, 0 },
2194     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2195     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2196     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2197     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2198     { WM_DESTROY, sent },
2199     { WM_NCDESTROY, sent },
2200     { 0 }
2201 };
2202 /* CreateWindow for MDI child window, initially visible */
2203 static const struct message WmCreateMDIchildVisibleSeq[] = {
2204     { HCBT_CREATEWND, hook },
2205     { WM_NCCREATE, sent }, 
2206     { WM_NCCALCSIZE, sent|wparam, 0 },
2207     { WM_CREATE, sent },
2208     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2209     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2210     { WM_MOVE, sent },
2211     /* Win2k sends wparam set to
2212      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2213      * while Win9x doesn't bother to set child window id according to
2214      * CLIENTCREATESTRUCT.idFirstChild
2215      */
2216     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2217     { WM_SHOWWINDOW, sent|wparam, 1 },
2218     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2219     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2220     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2221     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2222     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2223     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2224     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2225
2226     /* Win9x: message sequence terminates here. */
2227
2228     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2229     { HCBT_SETFOCUS, hook }, /* in MDI client */
2230     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2231     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2232     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2233     { WM_SETFOCUS, sent }, /* in MDI client */
2234     { HCBT_SETFOCUS, hook },
2235     { WM_KILLFOCUS, sent }, /* in MDI client */
2236     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2237     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2238     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2239     { WM_SETFOCUS, sent|defwinproc },
2240     { WM_MDIACTIVATE, sent|defwinproc },
2241     { 0 }
2242 };
2243 /* CreateWindow for MDI child window with invisible parent */
2244 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
2245     { HCBT_CREATEWND, hook },
2246     { WM_GETMINMAXINFO, sent },
2247     { WM_NCCREATE, sent }, 
2248     { WM_NCCALCSIZE, sent|wparam, 0 },
2249     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2250     { WM_CREATE, sent },
2251     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2252     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2253     { WM_MOVE, sent },
2254     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2255     { WM_SHOWWINDOW, sent|wparam, 1 },
2256     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2257     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2258     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2259     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2260
2261     /* Win9x: message sequence terminates here. */
2262
2263     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2264     { HCBT_SETFOCUS, hook }, /* in MDI client */
2265     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2266     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2267     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2268     { WM_SETFOCUS, sent }, /* in MDI client */
2269     { HCBT_SETFOCUS, hook },
2270     { WM_KILLFOCUS, sent }, /* in MDI client */
2271     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2272     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2273     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2274     { WM_SETFOCUS, sent|defwinproc },
2275     { WM_MDIACTIVATE, sent|defwinproc },
2276     { 0 }
2277 };
2278 /* DestroyWindow for MDI child window, initially visible */
2279 static const struct message WmDestroyMDIchildVisibleSeq[] = {
2280     { HCBT_DESTROYWND, hook },
2281     /* Win2k sends wparam set to
2282      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2283      * while Win9x doesn't bother to set child window id according to
2284      * CLIENTCREATESTRUCT.idFirstChild
2285      */
2286     { 0x0090, sent|optional },
2287     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2288     { WM_SHOWWINDOW, sent|wparam, 0 },
2289     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2290     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2291     { WM_ERASEBKGND, sent|parent|optional },
2292     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2293
2294     /* { WM_DESTROY, sent }
2295      * Win9x: message sequence terminates here.
2296      */
2297
2298     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2299     { WM_KILLFOCUS, sent },
2300     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2301     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2302     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2303     { WM_SETFOCUS, sent }, /* in MDI client */
2304
2305     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2306     { WM_KILLFOCUS, sent }, /* in MDI client */
2307     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2308     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2309     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2310     { WM_SETFOCUS, sent }, /* in MDI client */
2311
2312     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2313
2314     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2315     { WM_KILLFOCUS, sent },
2316     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2317     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2318     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2319     { WM_SETFOCUS, sent }, /* in MDI client */
2320
2321     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2322     { WM_KILLFOCUS, sent }, /* in MDI client */
2323     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2324     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2325     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2326     { WM_SETFOCUS, sent }, /* in MDI client */
2327
2328     { WM_DESTROY, sent },
2329
2330     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2331     { WM_KILLFOCUS, sent },
2332     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2333     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2334     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2335     { WM_SETFOCUS, sent }, /* in MDI client */
2336
2337     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2338     { WM_KILLFOCUS, sent }, /* in MDI client */
2339     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2340     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2341     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2342     { WM_SETFOCUS, sent }, /* in MDI client */
2343
2344     { WM_NCDESTROY, sent },
2345     { 0 }
2346 };
2347 /* CreateWindow for MDI child window, initially invisible */
2348 static const struct message WmCreateMDIchildInvisibleSeq[] = {
2349     { HCBT_CREATEWND, hook },
2350     { WM_NCCREATE, sent }, 
2351     { WM_NCCALCSIZE, sent|wparam, 0 },
2352     { WM_CREATE, sent },
2353     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2354     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2355     { WM_MOVE, sent },
2356     /* Win2k sends wparam set to
2357      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2358      * while Win9x doesn't bother to set child window id according to
2359      * CLIENTCREATESTRUCT.idFirstChild
2360      */
2361     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2362     { 0 }
2363 };
2364 /* DestroyWindow for MDI child window, initially invisible */
2365 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
2366     { HCBT_DESTROYWND, hook },
2367     /* Win2k sends wparam set to
2368      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2369      * while Win9x doesn't bother to set child window id according to
2370      * CLIENTCREATESTRUCT.idFirstChild
2371      */
2372     { 0x0090, sent|optional },
2373     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2374     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2375     { WM_DESTROY, sent },
2376     { WM_NCDESTROY, sent },
2377     /* FIXME: Wine destroys an icon/title window while Windows doesn't */
2378     { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
2379     { 0 }
2380 };
2381 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
2382 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
2383     { HCBT_CREATEWND, hook },
2384     { WM_NCCREATE, sent }, 
2385     { WM_NCCALCSIZE, sent|wparam, 0 },
2386     { WM_CREATE, sent },
2387     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2388     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2389     { WM_MOVE, sent },
2390     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2391     { WM_GETMINMAXINFO, sent },
2392     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED  },
2393     { WM_NCCALCSIZE, sent|wparam, 1 },
2394     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2395     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2396      /* in MDI frame */
2397     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2398     { WM_NCCALCSIZE, sent|wparam, 1 },
2399     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2400     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2401     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2402     /* Win2k sends wparam set to
2403      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2404      * while Win9x doesn't bother to set child window id according to
2405      * CLIENTCREATESTRUCT.idFirstChild
2406      */
2407     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2408     { WM_SHOWWINDOW, sent|wparam, 1 },
2409     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2410     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2411     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2412     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2413     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2414     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2415     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2416
2417     /* Win9x: message sequence terminates here. */
2418
2419     { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2420     { HCBT_SETFOCUS, hook|optional }, /* in MDI client */
2421     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2422     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2423     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2424     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2425     { HCBT_SETFOCUS, hook|optional },
2426     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2427     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2428     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2429     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2430     { WM_SETFOCUS, sent|defwinproc|optional },
2431     { WM_MDIACTIVATE, sent|defwinproc|optional },
2432      /* in MDI frame */
2433     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2434     { WM_NCCALCSIZE, sent|wparam, 1 },
2435     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2436     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2437     { 0 }
2438 };
2439 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2440 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2441     /* restore the 1st MDI child */
2442     { WM_SETREDRAW, sent|wparam, 0 },
2443     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2444     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2445     { WM_NCCALCSIZE, sent|wparam, 1 },
2446     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2447     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2448     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2449      /* in MDI frame */
2450     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2451     { WM_NCCALCSIZE, sent|wparam, 1 },
2452     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2453     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2454     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2455     { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2456     /* create the 2nd MDI child */
2457     { HCBT_CREATEWND, hook },
2458     { WM_NCCREATE, sent }, 
2459     { WM_NCCALCSIZE, sent|wparam, 0 },
2460     { WM_CREATE, sent },
2461     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2462     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2463     { WM_MOVE, sent },
2464     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2465     { WM_GETMINMAXINFO, sent },
2466     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2467     { WM_NCCALCSIZE, sent|wparam, 1 },
2468     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2469     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2470     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2471      /* in MDI frame */
2472     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2473     { WM_NCCALCSIZE, sent|wparam, 1 },
2474     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2475     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2476     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2477     /* Win2k sends wparam set to
2478      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2479      * while Win9x doesn't bother to set child window id according to
2480      * CLIENTCREATESTRUCT.idFirstChild
2481      */
2482     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2483     { WM_SHOWWINDOW, sent|wparam, 1 },
2484     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2485     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2486     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2487     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2488     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2489     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2490
2491     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2492     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2493
2494     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2495
2496     /* Win9x: message sequence terminates here. */
2497
2498     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2499     { HCBT_SETFOCUS, hook },
2500     { WM_KILLFOCUS, sent|defwinproc|optional }, /* in the 1st MDI child */
2501     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2502     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2503     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2504     { WM_SETFOCUS, sent }, /* in MDI client */
2505     { HCBT_SETFOCUS, hook },
2506     { WM_KILLFOCUS, sent }, /* in MDI client */
2507     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2508     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2509     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2510     { WM_SETFOCUS, sent|defwinproc },
2511
2512     { WM_MDIACTIVATE, sent|defwinproc },
2513      /* in MDI frame */
2514     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2515     { WM_NCCALCSIZE, sent|wparam, 1 },
2516     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2517     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2518     { 0 }
2519 };
2520 /* WM_MDICREATE MDI child window, initially visible and maximized */
2521 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2522     { WM_MDICREATE, sent },
2523     { HCBT_CREATEWND, hook },
2524     { WM_NCCREATE, sent }, 
2525     { WM_NCCALCSIZE, sent|wparam, 0 },
2526     { WM_CREATE, sent },
2527     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2528     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2529     { WM_MOVE, sent },
2530     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2531     { WM_GETMINMAXINFO, sent },
2532     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2533     { WM_NCCALCSIZE, sent|wparam, 1 },
2534     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2535     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2536
2537      /* in MDI frame */
2538     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2539     { WM_NCCALCSIZE, sent|wparam, 1 },
2540     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2541     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2542     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2543
2544     /* Win2k sends wparam set to
2545      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2546      * while Win9x doesn't bother to set child window id according to
2547      * CLIENTCREATESTRUCT.idFirstChild
2548      */
2549     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2550     { WM_SHOWWINDOW, sent|wparam, 1 },
2551     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2552
2553     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2554
2555     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2556     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2557     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2558
2559     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2560     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2561
2562     /* Win9x: message sequence terminates here. */
2563
2564     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2565     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2566     { HCBT_SETFOCUS, hook }, /* in MDI client */
2567     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2568     { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2569     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2570     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2571     { HCBT_SETFOCUS, hook|optional },
2572     { WM_KILLFOCUS, sent }, /* in MDI client */
2573     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2574     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2575     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2576     { WM_SETFOCUS, sent|defwinproc },
2577
2578     { WM_MDIACTIVATE, sent|defwinproc },
2579
2580      /* in MDI child */
2581     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2582     { WM_NCCALCSIZE, sent|wparam, 1 },
2583     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2584     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2585
2586      /* in MDI frame */
2587     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2588     { WM_NCCALCSIZE, sent|wparam, 1 },
2589     { 0x0093, sent|defwinproc|optional },
2590     { 0x0093, sent|defwinproc|optional },
2591     { 0x0093, sent|defwinproc|optional },
2592     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2593     { WM_MOVE, sent|defwinproc },
2594     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2595
2596      /* in MDI client */
2597     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2598     { WM_NCCALCSIZE, sent|wparam, 1 },
2599     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2600     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2601
2602      /* in MDI child */
2603     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2604     { WM_NCCALCSIZE, sent|wparam, 1 },
2605     { 0x0093, sent|optional },
2606     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2607     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2608
2609     { 0x0093, sent|optional },
2610     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2611     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2612     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2613     { 0x0093, sent|defwinproc|optional },
2614     { 0x0093, sent|defwinproc|optional },
2615     { 0x0093, sent|defwinproc|optional },
2616     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2617     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2618
2619     { 0 }
2620 };
2621 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2622 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2623     { HCBT_CREATEWND, hook },
2624     { WM_GETMINMAXINFO, sent },
2625     { WM_NCCREATE, sent }, 
2626     { WM_NCCALCSIZE, sent|wparam, 0 },
2627     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2628     { WM_CREATE, sent },
2629     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2630     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2631     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2632     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI frame */
2633     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2634     { WM_MOVE, sent },
2635     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2636     { WM_GETMINMAXINFO, sent },
2637     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2638     { WM_GETMINMAXINFO, sent|defwinproc },
2639     { WM_NCCALCSIZE, sent|wparam, 1 },
2640     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
2641     { WM_MOVE, sent|defwinproc },
2642     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2643      /* in MDI frame */
2644     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2645     { WM_NCCALCSIZE, sent|wparam, 1 },
2646     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2647     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2648     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2649     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2650     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2651     /* Win2k sends wparam set to
2652      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2653      * while Win9x doesn't bother to set child window id according to
2654      * CLIENTCREATESTRUCT.idFirstChild
2655      */
2656     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2657     { 0 }
2658 };
2659 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2660 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2661     { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2662     { HCBT_SYSCOMMAND, hook },
2663     { WM_CLOSE, sent|defwinproc },
2664     { WM_MDIDESTROY, sent }, /* in MDI client */
2665
2666     /* bring the 1st MDI child to top */
2667     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2668     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2669
2670     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2671
2672     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2673     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2674     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2675
2676     /* maximize the 1st MDI child */
2677     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2678     { WM_GETMINMAXINFO, sent|defwinproc },
2679     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED },
2680     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2681     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2682     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2683     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2684
2685     /* restore the 2nd MDI child */
2686     { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2687     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2688     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2689     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2690
2691     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2692
2693     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2694     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2695
2696     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2697
2698     { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2699      /* in MDI frame */
2700     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2701     { WM_NCCALCSIZE, sent|wparam, 1 },
2702     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2703     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2704     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2705
2706     /* bring the 1st MDI child to top */
2707     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2708     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2709     { HCBT_SETFOCUS, hook },
2710     { WM_KILLFOCUS, sent|defwinproc },
2711     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2712     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2713     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2714     { WM_SETFOCUS, sent }, /* in MDI client */
2715     { HCBT_SETFOCUS, hook },
2716     { WM_KILLFOCUS, sent }, /* in MDI client */
2717     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2718     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2719     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2720     { WM_SETFOCUS, sent|defwinproc },
2721     { WM_MDIACTIVATE, sent|defwinproc },
2722     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2723
2724     /* apparently ShowWindow(SW_SHOW) on an MDI client */
2725     { WM_SHOWWINDOW, sent|wparam, 1 },
2726     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2727     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2728     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2729     { WM_MDIREFRESHMENU, sent },
2730
2731     { HCBT_DESTROYWND, hook },
2732     /* Win2k sends wparam set to
2733      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2734      * while Win9x doesn't bother to set child window id according to
2735      * CLIENTCREATESTRUCT.idFirstChild
2736      */
2737     { 0x0090, sent|defwinproc|optional },
2738     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2739     { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2740     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2741     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2742     { WM_ERASEBKGND, sent|parent|optional },
2743     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2744
2745     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2746     { WM_DESTROY, sent|defwinproc },
2747     { WM_NCDESTROY, sent|defwinproc },
2748     { 0 }
2749 };
2750 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2751 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2752     { WM_MDIDESTROY, sent }, /* in MDI client */
2753     { WM_SHOWWINDOW, sent|wparam, 0 },
2754     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2755     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2756     { WM_ERASEBKGND, sent|parent|optional },
2757     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2758
2759     { HCBT_SETFOCUS, hook },
2760     { WM_KILLFOCUS, sent },
2761     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2762     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2763     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2764     { WM_SETFOCUS, sent }, /* in MDI client */
2765     { HCBT_SETFOCUS, hook },
2766     { WM_KILLFOCUS, sent }, /* in MDI client */
2767     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2768     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2769     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2770     { WM_SETFOCUS, sent },
2771
2772      /* in MDI child */
2773     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2774     { WM_NCCALCSIZE, sent|wparam, 1 },
2775     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2776     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2777
2778      /* in MDI frame */
2779     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2780     { WM_NCCALCSIZE, sent|wparam, 1 },
2781     { 0x0093, sent|defwinproc|optional },
2782     { 0x0093, sent|defwinproc|optional },
2783     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2784     { WM_MOVE, sent|defwinproc },
2785     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2786
2787      /* in MDI client */
2788     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2789     { WM_NCCALCSIZE, sent|wparam, 1 },
2790     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2791     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2792
2793      /* in MDI child */
2794     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2795     { WM_NCCALCSIZE, sent|wparam, 1 },
2796     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2797     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2798
2799      /* in MDI child */
2800     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2801     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2802     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2803     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2804
2805      /* in MDI frame */
2806     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2807     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2808     { 0x0093, sent|defwinproc|optional },
2809     { 0x0093, sent|defwinproc|optional },
2810     { 0x0093, sent|defwinproc|optional },
2811     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2812     { WM_MOVE, sent|defwinproc },
2813     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2814
2815      /* in MDI client */
2816     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2817     { WM_NCCALCSIZE, sent|wparam, 1 },
2818     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2819     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2820
2821      /* in MDI child */
2822     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2823     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2824     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2825     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2826     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2827     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2828
2829     { 0x0093, sent|defwinproc|optional },
2830     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2831     { 0x0093, sent|defwinproc|optional },
2832     { 0x0093, sent|defwinproc|optional },
2833     { 0x0093, sent|defwinproc|optional },
2834     { 0x0093, sent|optional },
2835
2836     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2837     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2838     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2839     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2840     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2841
2842      /* in MDI frame */
2843     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2844     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2845     { 0x0093, sent|defwinproc|optional },
2846     { 0x0093, sent|defwinproc|optional },
2847     { 0x0093, sent|defwinproc|optional },
2848     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2849     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2850     { 0x0093, sent|optional },
2851
2852     { WM_NCACTIVATE, sent|wparam, 0 },
2853     { WM_MDIACTIVATE, sent },
2854
2855     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2856     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2857     { WM_NCCALCSIZE, sent|wparam, 1 },
2858
2859     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2860
2861     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2862     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2863     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2864
2865      /* in MDI child */
2866     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2867     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2868     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2869     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2870
2871      /* in MDI frame */
2872     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2873     { WM_NCCALCSIZE, sent|wparam, 1 },
2874     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2875     { WM_MOVE, sent|defwinproc },
2876     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2877
2878      /* in MDI client */
2879     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2880     { WM_NCCALCSIZE, sent|wparam, 1 },
2881     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2882     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2883     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2884     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2885     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2886     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2887     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2888
2889     { HCBT_SETFOCUS, hook },
2890     { WM_KILLFOCUS, sent },
2891     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2892     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2893     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2894     { WM_SETFOCUS, sent }, /* in MDI client */
2895
2896     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2897
2898     { HCBT_DESTROYWND, hook },
2899     /* Win2k sends wparam set to
2900      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2901      * while Win9x doesn't bother to set child window id according to
2902      * CLIENTCREATESTRUCT.idFirstChild
2903      */
2904     { 0x0090, sent|optional },
2905     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2906
2907     { WM_SHOWWINDOW, sent|wparam, 0 },
2908     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2909     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2910     { WM_ERASEBKGND, sent|parent|optional },
2911     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2912
2913     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2914     { WM_DESTROY, sent },
2915     { WM_NCDESTROY, sent },
2916     { 0 }
2917 };
2918 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
2919 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
2920     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2921     { WM_GETMINMAXINFO, sent },
2922     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
2923     { WM_NCCALCSIZE, sent|wparam, 1 },
2924     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2925     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2926
2927     { WM_WINDOWPOSCHANGING, sent|wparam|optional|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2928     { WM_NCACTIVATE, sent|wparam|optional|defwinproc, 1 },
2929     { HCBT_SETFOCUS, hook|optional },
2930     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2931     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2932     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2933     { HCBT_SETFOCUS, hook|optional },
2934     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2935     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2936     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2937     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2938     { WM_SETFOCUS, sent|optional|defwinproc },
2939     { WM_MDIACTIVATE, sent|optional|defwinproc },
2940     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2941     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2942      /* in MDI frame */
2943     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2944     { WM_NCCALCSIZE, sent|wparam, 1 },
2945     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2946     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2947     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2948     { 0 }
2949 };
2950 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
2951 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
2952     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2953     { WM_GETMINMAXINFO, sent },
2954     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
2955     { WM_GETMINMAXINFO, sent|defwinproc },
2956     { WM_NCCALCSIZE, sent|wparam, 1 },
2957     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2958     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2959
2960     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2961     { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2962     { HCBT_SETFOCUS, hook|optional },
2963     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2964     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2965     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2966     { HCBT_SETFOCUS, hook|optional },
2967     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2968     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2969     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2970     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2971     { WM_SETFOCUS, sent|defwinproc|optional },
2972     { WM_MDIACTIVATE, sent|defwinproc|optional },
2973     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2974     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2975     { 0 }
2976 };
2977 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
2978 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
2979     { WM_MDIMAXIMIZE, sent }, /* in MDI client */
2980     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2981     { WM_GETMINMAXINFO, sent },
2982     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2983     { WM_GETMINMAXINFO, sent|defwinproc },
2984     { WM_NCCALCSIZE, sent|wparam, 1 },
2985     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
2986     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2987     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
2988     { WM_MOVE, sent|defwinproc },
2989     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2990
2991     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2992     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2993     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2994     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
2995     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2996     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
2997      /* in MDI frame */
2998     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2999     { WM_NCCALCSIZE, sent|wparam, 1 },
3000     { 0x0093, sent|defwinproc|optional },
3001     { 0x0094, sent|defwinproc|optional },
3002     { 0x0094, sent|defwinproc|optional },
3003     { 0x0094, sent|defwinproc|optional },
3004     { 0x0094, sent|defwinproc|optional },
3005     { 0x0093, sent|defwinproc|optional },
3006     { 0x0093, sent|defwinproc|optional },
3007     { 0x0091, sent|defwinproc|optional },
3008     { 0x0092, sent|defwinproc|optional },
3009     { 0x0092, sent|defwinproc|optional },
3010     { 0x0092, sent|defwinproc|optional },
3011     { 0x0092, sent|defwinproc|optional },
3012     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3013     { WM_MOVE, sent|defwinproc },
3014     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3015     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
3016      /* in MDI client */
3017     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
3018     { WM_NCCALCSIZE, sent|wparam, 1 },
3019     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3020     { WM_SIZE, sent|wparam, SIZE_RESTORED },
3021      /* in MDI child */
3022     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
3023     { WM_GETMINMAXINFO, sent|defwinproc },
3024     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3025     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3026     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3027     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
3028     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3029     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3030     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3031     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3032      /* in MDI frame */
3033     { 0x0093, sent|optional },
3034     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
3035     { 0x0093, sent|defwinproc|optional },
3036     { 0x0093, sent|defwinproc|optional },
3037     { 0x0093, sent|defwinproc|optional },
3038     { 0x0091, sent|defwinproc|optional },
3039     { 0x0092, sent|defwinproc|optional },
3040     { 0x0092, sent|defwinproc|optional },
3041     { 0x0092, sent|defwinproc|optional },
3042     { 0x0092, sent|defwinproc|optional },
3043     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3044     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3045     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3046     { 0 }
3047 };
3048 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
3049 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
3050     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3051     { WM_GETMINMAXINFO, sent },
3052     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3053     { WM_NCCALCSIZE, sent|wparam, 1 },
3054     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3055     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3056     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3057      /* in MDI frame */
3058     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3059     { WM_NCCALCSIZE, sent|wparam, 1 },
3060     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3061     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3062     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3063     { 0 }
3064 };
3065 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
3066 static const struct message WmRestoreMDIchildVisibleSeq[] = {
3067     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3068     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3069     { WM_NCCALCSIZE, sent|wparam, 1 },
3070     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3071     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3072     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3073      /* in MDI frame */
3074     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3075     { WM_NCCALCSIZE, sent|wparam, 1 },
3076     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3077     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3078     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3079     { 0 }
3080 };
3081 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
3082 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
3083     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3084     { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
3085     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3086     { WM_NCCALCSIZE, sent|wparam, 1 },
3087     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3088     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
3089     { WM_MOVE, sent|defwinproc },
3090     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3091     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3092     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3093     { HCBT_SETFOCUS, hook },
3094     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3095     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
3096     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3097     { WM_SETFOCUS, sent },
3098     { 0 }
3099 };
3100 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
3101 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
3102     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
3103     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3104     { WM_NCCALCSIZE, sent|wparam, 1 },
3105     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
3106     { WM_MOVE, sent|defwinproc },
3107     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
3108     { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
3109     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3110     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3111     /* FIXME: Wine creates an icon/title window while Windows doesn't */
3112     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
3113     { 0 }
3114 };
3115 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
3116 static const struct message WmRestoreMDIchildInisibleSeq[] = {
3117     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3118     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED  },
3119     { WM_NCCALCSIZE, sent|wparam, 1 },
3120     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3121     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3122     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3123     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3124      /* in MDI frame */
3125     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3126     { WM_NCCALCSIZE, sent|wparam, 1 },
3127     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3128     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3129     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3130     { 0 }
3131 };
3132
3133 static HWND mdi_client;
3134 static WNDPROC old_mdi_client_proc;
3135
3136 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3137 {
3138     struct recvd_message msg;
3139
3140     /* do not log painting messages */
3141     if (message != WM_PAINT &&
3142         message != WM_NCPAINT &&
3143         message != WM_SYNCPAINT &&
3144         message != WM_ERASEBKGND &&
3145         message != WM_NCHITTEST &&
3146         message != WM_GETTEXT &&
3147         message != WM_MDIGETACTIVE &&
3148         message != WM_GETICON &&
3149         message != WM_GETOBJECT &&
3150         message != WM_DEVICECHANGE)
3151     {
3152         msg.hwnd = hwnd;
3153         msg.message = message;
3154         msg.flags = sent|wparam|lparam;
3155         msg.wParam = wParam;
3156         msg.lParam = lParam;
3157         msg.descr = "mdi client";
3158         add_message(&msg);
3159     }
3160
3161     return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
3162 }
3163
3164 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3165 {
3166     static long defwndproc_counter = 0;
3167     LRESULT ret;
3168     struct recvd_message msg;
3169
3170     /* do not log painting messages */
3171     if (message != WM_PAINT &&
3172         message != WM_NCPAINT &&
3173         message != WM_SYNCPAINT &&
3174         message != WM_ERASEBKGND &&
3175         message != WM_NCHITTEST &&
3176         message != WM_GETTEXT &&
3177         message != WM_GETICON &&
3178         message != WM_GETOBJECT &&
3179         message != WM_DEVICECHANGE)
3180     {
3181         switch (message)
3182         {
3183             case WM_MDIACTIVATE:
3184             {
3185                 HWND active, client = GetParent(hwnd);
3186
3187                 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
3188
3189                 if (hwnd == (HWND)lParam) /* if we are being activated */
3190                     ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
3191                 else
3192                     ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
3193                 break;
3194             }
3195         }
3196
3197         msg.hwnd = hwnd;
3198         msg.message = message;
3199         msg.flags = sent|wparam|lparam;
3200         if (defwndproc_counter) msg.flags |= defwinproc;
3201         msg.wParam = wParam;
3202         msg.lParam = lParam;
3203         msg.descr = "mdi child";
3204         add_message(&msg);
3205     }
3206
3207     defwndproc_counter++;
3208     ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
3209     defwndproc_counter--;
3210
3211     return ret;
3212 }
3213
3214 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3215 {
3216     static long defwndproc_counter = 0;
3217     LRESULT ret;
3218     struct recvd_message msg;
3219
3220     /* do not log painting messages */
3221     if (message != WM_PAINT &&
3222         message != WM_NCPAINT &&
3223         message != WM_SYNCPAINT &&
3224         message != WM_ERASEBKGND &&
3225         message != WM_NCHITTEST &&
3226         message != WM_GETTEXT &&
3227         message != WM_GETICON &&
3228         message != WM_GETOBJECT &&
3229         message != WM_DEVICECHANGE)
3230     {
3231         msg.hwnd = hwnd;
3232         msg.message = message;
3233         msg.flags = sent|wparam|lparam;
3234         if (defwndproc_counter) msg.flags |= defwinproc;
3235         msg.wParam = wParam;
3236         msg.lParam = lParam;
3237         msg.descr = "mdi frame";
3238         add_message(&msg);
3239     }
3240
3241     defwndproc_counter++;
3242     ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
3243     defwndproc_counter--;
3244
3245     return ret;
3246 }
3247
3248 static BOOL mdi_RegisterWindowClasses(void)
3249 {
3250     WNDCLASSA cls;
3251
3252     cls.style = 0;
3253     cls.lpfnWndProc = mdi_frame_wnd_proc;
3254     cls.cbClsExtra = 0;
3255     cls.cbWndExtra = 0;
3256     cls.hInstance = GetModuleHandleA(0);
3257     cls.hIcon = 0;
3258     cls.hCursor = LoadCursorA(0, IDC_ARROW);
3259     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3260     cls.lpszMenuName = NULL;
3261     cls.lpszClassName = "MDI_frame_class";
3262     if (!RegisterClassA(&cls)) return FALSE;
3263
3264     cls.lpfnWndProc = mdi_child_wnd_proc;
3265     cls.lpszClassName = "MDI_child_class";
3266     if (!RegisterClassA(&cls)) return FALSE;
3267
3268     if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
3269     old_mdi_client_proc = cls.lpfnWndProc;
3270     cls.hInstance = GetModuleHandleA(0);
3271     cls.lpfnWndProc = mdi_client_hook_proc;
3272     cls.lpszClassName = "MDI_client_class";
3273     if (!RegisterClassA(&cls)) assert(0);
3274
3275     return TRUE;
3276 }
3277
3278 static void test_mdi_messages(void)
3279 {
3280     MDICREATESTRUCTA mdi_cs;
3281     CLIENTCREATESTRUCT client_cs;
3282     HWND mdi_frame, mdi_child, mdi_child2, active_child;
3283     BOOL zoomed;
3284     HMENU hMenu = CreateMenu();
3285
3286     assert(mdi_RegisterWindowClasses());
3287
3288     flush_sequence();
3289
3290     trace("creating MDI frame window\n");
3291     mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
3292                                 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3293                                 WS_MAXIMIZEBOX | WS_VISIBLE,
3294                                 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
3295                                 GetDesktopWindow(), hMenu,
3296                                 GetModuleHandleA(0), NULL);
3297     assert(mdi_frame);
3298     ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
3299
3300     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3301     ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
3302
3303     trace("creating MDI client window\n");
3304     client_cs.hWindowMenu = 0;
3305     client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
3306     mdi_client = CreateWindowExA(0, "MDI_client_class",
3307                                  NULL,
3308                                  WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
3309                                  0, 0, 0, 0,
3310                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3311     assert(mdi_client);
3312     ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
3313
3314     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3315     ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
3316
3317     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3318     ok(!active_child, "wrong active MDI child %p\n", active_child);
3319     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3320
3321     SetFocus(0);
3322     flush_sequence();
3323
3324     trace("creating invisible MDI child window\n");
3325     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3326                                 WS_CHILD,
3327                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3328                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3329     assert(mdi_child);
3330
3331     flush_sequence();
3332     ShowWindow(mdi_child, SW_SHOWNORMAL);
3333     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
3334
3335     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3336     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3337
3338     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3339     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3340
3341     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3342     ok(!active_child, "wrong active MDI child %p\n", active_child);
3343     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3344
3345     ShowWindow(mdi_child, SW_HIDE);
3346     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
3347     flush_sequence();
3348
3349     ShowWindow(mdi_child, SW_SHOW);
3350     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
3351
3352     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3353     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3354
3355     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3356     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3357
3358     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3359     ok(!active_child, "wrong active MDI child %p\n", active_child);
3360     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3361
3362     DestroyWindow(mdi_child);
3363     flush_sequence();
3364
3365     trace("creating visible MDI child window\n");
3366     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3367                                 WS_CHILD | WS_VISIBLE,
3368                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3369                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3370     assert(mdi_child);
3371     ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
3372
3373     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3374     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3375
3376     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3377     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3378
3379     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3380     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3381     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3382     flush_sequence();
3383
3384     DestroyWindow(mdi_child);
3385     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3386
3387     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3388     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3389
3390     /* Win2k: MDI client still returns a just destroyed child as active
3391      * Win9x: MDI client returns 0
3392      */
3393     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3394     ok(active_child == mdi_child || /* win2k */
3395        !active_child, /* win9x */
3396        "wrong active MDI child %p\n", active_child);
3397     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3398
3399     flush_sequence();
3400
3401     trace("creating invisible MDI child window\n");
3402     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3403                                 WS_CHILD,
3404                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3405                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3406     assert(mdi_child2);
3407     ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
3408
3409     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
3410     ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
3411
3412     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3413     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3414
3415     /* Win2k: MDI client still returns a just destroyed child as active
3416      * Win9x: MDI client returns mdi_child2
3417      */
3418     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3419     ok(active_child == mdi_child || /* win2k */
3420        active_child == mdi_child2, /* win9x */
3421        "wrong active MDI child %p\n", active_child);
3422     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3423     flush_sequence();
3424
3425     ShowWindow(mdi_child2, SW_MAXIMIZE);
3426     ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3427
3428     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3429     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3430
3431     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3432     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3433     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3434     flush_sequence();
3435
3436     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3437     ok(GetFocus() == mdi_child2 || /* win2k */
3438        GetFocus() == 0, /* win9x */
3439        "wrong focus window %p\n", GetFocus());
3440
3441     SetFocus(0);
3442     flush_sequence();
3443
3444     ShowWindow(mdi_child2, SW_HIDE);
3445     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3446
3447     ShowWindow(mdi_child2, SW_RESTORE);
3448     ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3449     flush_sequence();
3450
3451     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3452     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3453
3454     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3455     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3456     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3457     flush_sequence();
3458
3459     SetFocus(0);
3460     flush_sequence();
3461
3462     ShowWindow(mdi_child2, SW_HIDE);
3463     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3464
3465     ShowWindow(mdi_child2, SW_SHOW);
3466     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3467
3468     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3469     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3470
3471     ShowWindow(mdi_child2, SW_MAXIMIZE);
3472     ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3473
3474     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3475     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3476
3477     ShowWindow(mdi_child2, SW_RESTORE);
3478     ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3479
3480     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3481     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3482
3483     ShowWindow(mdi_child2, SW_MINIMIZE);
3484     ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3485
3486     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3487     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3488
3489     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3490     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3491     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3492     flush_sequence();
3493
3494     ShowWindow(mdi_child2, SW_RESTORE);
3495     ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", TRUE);
3496
3497     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3498     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3499
3500     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3501     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3502     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3503     flush_sequence();
3504
3505     SetFocus(0);
3506     flush_sequence();
3507
3508     ShowWindow(mdi_child2, SW_HIDE);
3509     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3510
3511     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3512     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3513
3514     DestroyWindow(mdi_child2);
3515     ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3516
3517     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3518     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3519
3520     /* test for maximized MDI children */
3521     trace("creating maximized visible MDI child window 1\n");
3522     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3523                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3524                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3525                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3526     assert(mdi_child);
3527     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3528     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3529
3530     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3531     ok(GetFocus() == mdi_child || /* win2k */
3532        GetFocus() == 0, /* win9x */
3533        "wrong focus window %p\n", GetFocus());
3534
3535     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3536     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3537     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3538     flush_sequence();
3539
3540     trace("creating maximized visible MDI child window 2\n");
3541     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3542                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3543                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3544                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3545     assert(mdi_child2);
3546     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3547     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3548     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3549
3550     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3551     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3552
3553     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3554     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3555     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3556     flush_sequence();
3557
3558     trace("destroying maximized visible MDI child window 2\n");
3559     DestroyWindow(mdi_child2);
3560     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3561
3562     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3563
3564     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3565     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3566
3567     /* Win2k: MDI client still returns a just destroyed child as active
3568      * Win9x: MDI client returns 0
3569      */
3570     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3571     ok(active_child == mdi_child2 || /* win2k */
3572        !active_child, /* win9x */
3573        "wrong active MDI child %p\n", active_child);
3574     flush_sequence();
3575
3576     ShowWindow(mdi_child, SW_MAXIMIZE);
3577     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3578     flush_sequence();
3579
3580     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3581     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3582
3583     trace("re-creating maximized visible MDI child window 2\n");
3584     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3585                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3586                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3587                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3588     assert(mdi_child2);
3589     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3590     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3591     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3592
3593     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3594     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3595
3596     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3597     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3598     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3599     flush_sequence();
3600
3601     SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3602     ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3603     ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3604
3605     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3606     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3607     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3608
3609     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3610     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3611     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3612     flush_sequence();
3613
3614     DestroyWindow(mdi_child);
3615     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3616
3617     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3618     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3619
3620     /* Win2k: MDI client still returns a just destroyed child as active
3621      * Win9x: MDI client returns 0
3622      */
3623     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3624     ok(active_child == mdi_child || /* win2k */
3625        !active_child, /* win9x */
3626        "wrong active MDI child %p\n", active_child);
3627     flush_sequence();
3628
3629     trace("creating maximized invisible MDI child window\n");
3630     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3631                                 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3632                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3633                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3634     assert(mdi_child2);
3635     ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", FALSE);
3636     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3637     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3638     ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3639
3640     /* Win2k: MDI client still returns a just destroyed child as active
3641      * Win9x: MDI client returns 0
3642      */
3643     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3644     ok(active_child == mdi_child || /* win2k */
3645        !active_child, /* win9x */
3646        "wrong active MDI child %p\n", active_child);
3647     flush_sequence();
3648
3649     trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3650     ShowWindow(mdi_child2, SW_MAXIMIZE);
3651     ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3652     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3653     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3654     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3655
3656     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3657     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3658     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3659     flush_sequence();
3660
3661     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3662     flush_sequence();
3663
3664     /* end of test for maximized MDI children */
3665     SetFocus(0);
3666     flush_sequence();
3667     trace("creating maximized visible MDI child window 1(Switch test)\n");
3668     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3669                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3670                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3671                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3672     assert(mdi_child);
3673     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3674     ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3675
3676     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3677     ok(GetFocus() == mdi_child || /* win2k */
3678        GetFocus() == 0, /* win9x */
3679        "wrong focus window %p(Switch test)\n", GetFocus());
3680
3681     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3682     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3683     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3684     flush_sequence();
3685
3686     trace("creating maximized visible MDI child window 2(Switch test)\n");
3687     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3688                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3689                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3690                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3691     assert(mdi_child2);
3692     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3693
3694     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3695     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3696
3697     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3698     ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3699
3700     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3701     ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3702     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3703     flush_sequence();
3704
3705     trace("Switch child window.\n");
3706     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3707     ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3708     trace("end of test for switch maximized MDI children\n");
3709     flush_sequence();
3710
3711     /* Prepare for switching test of not maximized MDI children  */
3712     ShowWindow( mdi_child, SW_NORMAL );
3713     ok(!IsZoomed(mdi_child), "wrong zoomed state for %p(Switch test)\n", mdi_child);
3714     ok(!IsZoomed(mdi_child2), "wrong zoomed state for %p(Switch test)\n", mdi_child2);
3715     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
3716     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3717     flush_sequence();
3718
3719     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child2, 0);
3720     ok_sequence(WmSwitchNotMaximizedChild, "Not maximized child did not switch correctly", FALSE);
3721     trace("end of test for switch not maximized MDI children\n");
3722     flush_sequence();
3723
3724     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3725     flush_sequence();
3726
3727     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3728     flush_sequence();
3729
3730     SetFocus(0);
3731     flush_sequence();
3732     /* end of tests for switch maximized/not maximized MDI children */
3733
3734     mdi_cs.szClass = "MDI_child_Class";
3735     mdi_cs.szTitle = "MDI child";
3736     mdi_cs.hOwner = GetModuleHandleA(0);
3737     mdi_cs.x = 0;
3738     mdi_cs.y = 0;
3739     mdi_cs.cx = CW_USEDEFAULT;
3740     mdi_cs.cy = CW_USEDEFAULT;
3741     mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3742     mdi_cs.lParam = 0;
3743     mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3744     ok(mdi_child != 0, "MDI child creation failed\n");
3745     ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3746
3747     ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3748
3749     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3750     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3751
3752     ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3753     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3754     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3755
3756     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3757     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3758     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3759     flush_sequence();
3760
3761     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3762     ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3763
3764     ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3765     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3766     ok(!active_child, "wrong active MDI child %p\n", active_child);
3767
3768     SetFocus(0);
3769     flush_sequence();
3770
3771     DestroyWindow(mdi_client);
3772     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3773
3774     /* test maximization of MDI child with invisible parent */
3775     client_cs.hWindowMenu = 0;
3776     mdi_client = CreateWindow("MDI_client_class",
3777                                  NULL,
3778                                  WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3779                                  0, 0, 660, 430,
3780                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3781     ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3782
3783     ShowWindow(mdi_client, SW_HIDE);
3784     ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3785
3786     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3787                                 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3788                                 0, 0, 650, 440,
3789                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3790     ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3791
3792     SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3793     ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3794     zoomed = IsZoomed(mdi_child);
3795     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3796     
3797     ShowWindow(mdi_client, SW_SHOW);
3798     ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3799
3800     DestroyWindow(mdi_child);
3801     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3802
3803     /* end of test for maximization of MDI child with invisible parent */
3804
3805     DestroyWindow(mdi_client);
3806     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3807
3808     DestroyWindow(mdi_frame);
3809     ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3810 }
3811 /************************* End of MDI test **********************************/
3812
3813 static void test_WM_SETREDRAW(HWND hwnd)
3814 {
3815     DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3816
3817     flush_events();
3818     flush_sequence();
3819
3820     SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3821     ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3822
3823     ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3824     ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3825
3826     flush_sequence();
3827     SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3828     ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3829
3830     ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3831     ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3832
3833     /* restore original WS_VISIBLE state */
3834     SetWindowLongA(hwnd, GWL_STYLE, style);
3835
3836     flush_events();
3837     flush_sequence();
3838 }
3839
3840 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3841 {
3842     struct recvd_message msg;
3843
3844     switch (message)
3845     {
3846         /* ignore */
3847         case WM_GETICON:
3848         case WM_GETOBJECT:
3849         case WM_MOUSEMOVE:
3850         case WM_SETCURSOR:
3851         case WM_DEVICECHANGE:
3852             return 0;
3853         case WM_NCHITTEST:
3854             return HTCLIENT;
3855     }
3856
3857     msg.hwnd = hwnd;
3858     msg.message = message;
3859     msg.flags = sent|wparam|lparam;
3860     msg.wParam = wParam;
3861     msg.lParam = lParam;
3862     msg.descr = "dialog";
3863     add_message(&msg);
3864
3865     if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3866     if (message == WM_TIMER) EndDialog( hwnd, 0 );
3867     return 0;
3868 }
3869
3870 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3871 {
3872     DWORD style, exstyle;
3873     INT xmin, xmax;
3874     BOOL ret;
3875
3876     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3877     style = GetWindowLongA(hwnd, GWL_STYLE);
3878     /* do not be confused by WS_DLGFRAME set */
3879     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3880
3881     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3882     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3883
3884     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3885     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3886     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3887         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3888     else
3889         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3890
3891     style = GetWindowLongA(hwnd, GWL_STYLE);
3892     if (set) ok(style & set, "style %08x should be set\n", set);
3893     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3894
3895     /* a subsequent call should do nothing */
3896     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3897     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3898     ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3899
3900     xmin = 0xdeadbeef;
3901     xmax = 0xdeadbeef;
3902     trace("Ignore GetScrollRange error below if you are on Win9x\n");
3903     ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
3904     ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
3905     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3906     ok(xmin == min, "unexpected min scroll value %d\n", xmin);
3907     ok(xmax == max, "unexpected max scroll value %d\n", xmax);
3908 }
3909
3910 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3911 {
3912     DWORD style, exstyle;
3913     SCROLLINFO si;
3914     BOOL ret;
3915
3916     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3917     style = GetWindowLongA(hwnd, GWL_STYLE);
3918     /* do not be confused by WS_DLGFRAME set */
3919     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3920
3921     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3922     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3923
3924     si.cbSize = sizeof(si);
3925     si.fMask = SIF_RANGE;
3926     si.nMin = min;
3927     si.nMax = max;
3928     SetScrollInfo(hwnd, ctl, &si, TRUE);
3929     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3930         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
3931     else
3932         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
3933
3934     style = GetWindowLongA(hwnd, GWL_STYLE);
3935     if (set) ok(style & set, "style %08x should be set\n", set);
3936     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3937
3938     /* a subsequent call should do nothing */
3939     SetScrollInfo(hwnd, ctl, &si, TRUE);
3940     if (style & WS_HSCROLL)
3941         ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3942     else if (style & WS_VSCROLL)
3943         ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3944     else
3945         ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3946
3947     si.fMask = SIF_PAGE;
3948     si.nPage = 5;
3949     SetScrollInfo(hwnd, ctl, &si, FALSE);
3950     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3951
3952     si.fMask = SIF_POS;
3953     si.nPos = max - 1;
3954     SetScrollInfo(hwnd, ctl, &si, FALSE);
3955     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3956
3957     si.fMask = SIF_RANGE;
3958     si.nMin = 0xdeadbeef;
3959     si.nMax = 0xdeadbeef;
3960     ret = GetScrollInfo(hwnd, ctl, &si);
3961     ok( ret, "GetScrollInfo error %d\n", GetLastError());
3962     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3963     ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
3964     ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
3965 }
3966
3967 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
3968 static void test_scroll_messages(HWND hwnd)
3969 {
3970     SCROLLINFO si;
3971     INT min, max;
3972     BOOL ret;
3973
3974     flush_events();
3975     flush_sequence();
3976
3977     min = 0xdeadbeef;
3978     max = 0xdeadbeef;
3979     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3980     ok( ret, "GetScrollRange error %d\n", GetLastError());
3981     if (sequence->message != WmGetScrollRangeSeq[0].message)
3982         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3983     /* values of min and max are undefined */
3984     flush_sequence();
3985
3986     ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
3987     ok( ret, "SetScrollRange error %d\n", GetLastError());
3988     if (sequence->message != WmSetScrollRangeSeq[0].message)
3989         trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3990     flush_sequence();
3991
3992     min = 0xdeadbeef;
3993     max = 0xdeadbeef;
3994     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3995     ok( ret, "GetScrollRange error %d\n", GetLastError());
3996     if (sequence->message != WmGetScrollRangeSeq[0].message)
3997         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3998     /* values of min and max are undefined */
3999     flush_sequence();
4000
4001     si.cbSize = sizeof(si);
4002     si.fMask = SIF_RANGE;
4003     si.nMin = 20;
4004     si.nMax = 160;
4005     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4006     if (sequence->message != WmSetScrollRangeSeq[0].message)
4007         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4008     flush_sequence();
4009
4010     si.fMask = SIF_PAGE;
4011     si.nPage = 10;
4012     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4013     if (sequence->message != WmSetScrollRangeSeq[0].message)
4014         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4015     flush_sequence();
4016
4017     si.fMask = SIF_POS;
4018     si.nPos = 20;
4019     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4020     if (sequence->message != WmSetScrollRangeSeq[0].message)
4021         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4022     flush_sequence();
4023
4024     si.fMask = SIF_RANGE;
4025     si.nMin = 0xdeadbeef;
4026     si.nMax = 0xdeadbeef;
4027     ret = GetScrollInfo(hwnd, SB_CTL, &si);
4028     ok( ret, "GetScrollInfo error %d\n", GetLastError());
4029     if (sequence->message != WmGetScrollInfoSeq[0].message)
4030         trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4031     /* values of min and max are undefined */
4032     flush_sequence();
4033
4034     /* set WS_HSCROLL */
4035     test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4036     /* clear WS_HSCROLL */
4037     test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4038
4039     /* set WS_HSCROLL */
4040     test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4041     /* clear WS_HSCROLL */
4042     test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4043
4044     /* set WS_VSCROLL */
4045     test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4046     /* clear WS_VSCROLL */
4047     test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4048
4049     /* set WS_VSCROLL */
4050     test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4051     /* clear WS_VSCROLL */
4052     test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4053 }
4054
4055 static void test_showwindow(void)
4056 {
4057     HWND hwnd, hchild;
4058     RECT rc;
4059
4060     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4061                            100, 100, 200, 200, 0, 0, 0, NULL);
4062     ok (hwnd != 0, "Failed to create overlapped window\n");
4063     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4064                              0, 0, 10, 10, hwnd, 0, 0, NULL);
4065     ok (hchild != 0, "Failed to create child\n");
4066     flush_sequence();
4067
4068     /* ShowWindow( SW_SHOWNA) for invisible top level window */
4069     trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
4070     ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4071     ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", TRUE);
4072
4073     /* ShowWindow( SW_SHOWNA) for now visible top level window */
4074     trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
4075     ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4076     ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
4077     /* back to invisible */
4078     ShowWindow(hchild, SW_HIDE);
4079     ShowWindow(hwnd, SW_HIDE);
4080     flush_sequence();
4081     /* ShowWindow(SW_SHOWNA) with child and parent invisible */ 
4082     trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
4083     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4084     ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
4085     /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */ 
4086     ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
4087     flush_sequence();
4088     trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
4089     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4090     ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
4091     /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
4092     ShowWindow( hwnd, SW_SHOW);
4093     flush_sequence();
4094     trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
4095     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4096     ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
4097
4098     /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
4099     ShowWindow( hchild, SW_HIDE);
4100     flush_sequence();
4101     trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
4102     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4103     ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
4104
4105     SetCapture(hchild);
4106     ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
4107     DestroyWindow(hchild);
4108     ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
4109
4110     DestroyWindow(hwnd);
4111     flush_sequence();
4112
4113     /* Popup windows */
4114     /* Test 1:
4115      * 1. Create invisible maximized popup window.
4116      * 2. Move and resize it.
4117      * 3. Show it maximized.
4118      */
4119     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4120     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4121                            100, 100, 200, 200, 0, 0, 0, NULL);
4122     ok (hwnd != 0, "Failed to create popup window\n");
4123     ok(IsZoomed(hwnd), "window should be maximized\n");
4124     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4125
4126     GetWindowRect(hwnd, &rc);
4127     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4128         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4129         "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
4130         rc.left, rc.top, rc.right, rc.bottom);
4131     /* Reset window's size & position */
4132     SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
4133     ok(IsZoomed(hwnd), "window should be maximized\n");
4134     flush_sequence();
4135
4136     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4137     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4138     ok(IsZoomed(hwnd), "window should be maximized\n");
4139     ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
4140
4141     GetWindowRect(hwnd, &rc);
4142     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4143         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4144         "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
4145         rc.left, rc.top, rc.right, rc.bottom);
4146     DestroyWindow(hwnd);
4147     flush_sequence();
4148
4149     /* Test 2:
4150      * 1. Create invisible maximized popup window.
4151      * 2. Show it maximized.
4152      */
4153     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4154     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4155                            100, 100, 200, 200, 0, 0, 0, NULL);
4156     ok (hwnd != 0, "Failed to create popup window\n");
4157     ok(IsZoomed(hwnd), "window should be maximized\n");
4158     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4159
4160     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4161     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4162     ok(IsZoomed(hwnd), "window should be maximized\n");
4163     ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
4164     DestroyWindow(hwnd);
4165     flush_sequence();
4166
4167     /* Test 3:
4168      * 1. Create visible maximized popup window.
4169      */
4170     trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
4171     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4172                            100, 100, 200, 200, 0, 0, 0, NULL);
4173     ok (hwnd != 0, "Failed to create popup window\n");
4174     ok(IsZoomed(hwnd), "window should be maximized\n");
4175     ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4176     DestroyWindow(hwnd);
4177     flush_sequence();
4178
4179     /* Test 4:
4180      * 1. Create visible popup window.
4181      * 2. Maximize it.
4182      */
4183     trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
4184     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
4185                            100, 100, 200, 200, 0, 0, 0, NULL);
4186     ok (hwnd != 0, "Failed to create popup window\n");
4187     ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
4188     ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
4189
4190     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
4191     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4192     ok(IsZoomed(hwnd), "window should be maximized\n");
4193     ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
4194     DestroyWindow(hwnd);
4195     flush_sequence();
4196 }
4197
4198 static void test_sys_menu(void)
4199 {
4200     HWND hwnd;
4201     HMENU hmenu;
4202     UINT state;
4203
4204     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4205                            100, 100, 200, 200, 0, 0, 0, NULL);
4206     ok (hwnd != 0, "Failed to create overlapped window\n");
4207
4208     flush_sequence();
4209
4210     /* test existing window without CS_NOCLOSE style */
4211     hmenu = GetSystemMenu(hwnd, FALSE);
4212     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4213
4214     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4215     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4216     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4217
4218     EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
4219     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4220
4221     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4222     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4223     ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
4224
4225     EnableMenuItem(hmenu, SC_CLOSE, 0);
4226     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4227
4228     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4229     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4230     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4231
4232     /* test whether removing WS_SYSMENU destroys a system menu */
4233     SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
4234     SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4235     flush_sequence();
4236     hmenu = GetSystemMenu(hwnd, FALSE);
4237     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4238
4239     DestroyWindow(hwnd);
4240
4241     /* test new window with CS_NOCLOSE style */
4242     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4243                            100, 100, 200, 200, 0, 0, 0, NULL);
4244     ok (hwnd != 0, "Failed to create overlapped window\n");
4245
4246     hmenu = GetSystemMenu(hwnd, FALSE);
4247     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4248
4249     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4250     ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4251
4252     DestroyWindow(hwnd);
4253
4254     /* test new window without WS_SYSMENU style */
4255     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
4256                            100, 100, 200, 200, 0, 0, 0, NULL);
4257     ok(hwnd != 0, "Failed to create overlapped window\n");
4258
4259     hmenu = GetSystemMenu(hwnd, FALSE);
4260     ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
4261
4262     DestroyWindow(hwnd);
4263 }
4264
4265 /* For shown WS_OVERLAPPEDWINDOW */
4266 static const struct message WmSetIcon_1[] = {
4267     { WM_SETICON, sent },
4268     { 0x00AE, sent|defwinproc|optional }, /* XP */
4269     { WM_GETTEXT, sent|defwinproc|optional },
4270     { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
4271     { 0 }
4272 };
4273
4274 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
4275 static const struct message WmSetIcon_2[] = {
4276     { WM_SETICON, sent },
4277     { 0 }
4278 };
4279
4280 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4281 static const struct message WmInitEndSession[] = {
4282     { 0x003B, sent },
4283     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4284     { 0 }
4285 };
4286
4287 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4288 static const struct message WmInitEndSession_2[] = {
4289     { 0x003B, sent },
4290     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4291     { 0 }
4292 };
4293
4294 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4295 static const struct message WmInitEndSession_3[] = {
4296     { 0x003B, sent },
4297     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4298     { 0 }
4299 };
4300
4301 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4302 static const struct message WmInitEndSession_4[] = {
4303     { 0x003B, sent },
4304     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4305     { 0 }
4306 };
4307
4308 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4309 static const struct message WmInitEndSession_5[] = {
4310     { 0x003B, sent },
4311     { WM_ENDSESSION, sent|defwinproc/*|wparam*/|lparam, 1, ENDSESSION_LOGOFF },
4312     { 0 }
4313 };
4314
4315 static const struct message WmOptionalPaint[] = {
4316     { WM_PAINT, sent|optional },
4317     { WM_NCPAINT, sent|beginpaint|optional },
4318     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4319     { WM_ERASEBKGND, sent|beginpaint|optional },
4320     { 0 }
4321 };
4322
4323 static const struct message WmZOrder[] = {
4324     { WM_WINDOWPOSCHANGING, sent|wparam, 0, 0 },
4325     { WM_GETMINMAXINFO, sent|defwinproc|wparam, 0, 0 },
4326     { HCBT_ACTIVATE, hook },
4327     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
4328     { WM_WINDOWPOSCHANGING, sent|wparam, 3, 0 },
4329     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0 },
4330     { WM_GETTEXT, sent|optional },
4331     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
4332     { WM_ACTIVATEAPP, sent|wparam, 1, 0 },
4333     { WM_NCACTIVATE, sent|wparam|lparam, 1, 0 },
4334     { WM_GETTEXT, sent|defwinproc|optional },
4335     { WM_GETTEXT, sent|defwinproc|optional },
4336     { WM_ACTIVATE, sent|wparam|lparam, 1, 0 },
4337     { HCBT_SETFOCUS, hook },
4338     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4339     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4340     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4341     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
4342     { WM_GETTEXT, sent|optional },
4343     { WM_NCCALCSIZE, sent|optional },
4344     { 0 }
4345 };
4346
4347 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4348 {
4349     DWORD ret;
4350     MSG msg;
4351
4352     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4353     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4354
4355     PostMessageA(hwnd, WM_USER, 0, 0);
4356
4357     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4358     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4359
4360     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4361     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4362
4363     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4364     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4365
4366     PostMessageA(hwnd, WM_USER, 0, 0);
4367
4368     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4369     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4370
4371     ok(PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4372     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4373
4374     /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4375     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4376     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4377
4378     PostMessageA(hwnd, WM_USER, 0, 0);
4379
4380     /* new incoming message causes it to become signaled again */
4381     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4382     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4383
4384     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4385     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4386     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4387     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4388 }
4389
4390 /* test if we receive the right sequence of messages */
4391 static void test_messages(void)
4392 {
4393     HWND hwnd, hparent, hchild;
4394     HWND hchild2, hbutton;
4395     HMENU hmenu;
4396     MSG msg;
4397     LRESULT res;
4398
4399     flush_sequence();
4400
4401     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4402                            100, 100, 200, 200, 0, 0, 0, NULL);
4403     ok (hwnd != 0, "Failed to create overlapped window\n");
4404     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4405
4406     /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4407     ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4408     ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4409
4410     /* test WM_SETREDRAW on a not visible top level window */
4411     test_WM_SETREDRAW(hwnd);
4412
4413     SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4414     flush_events();
4415     ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4416     ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4417
4418     ok(GetActiveWindow() == hwnd, "window should be active\n");
4419     ok(GetFocus() == hwnd, "window should have input focus\n");
4420     ShowWindow(hwnd, SW_HIDE);
4421     flush_events();
4422     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4423
4424     ShowWindow(hwnd, SW_SHOW);
4425     flush_events();
4426     ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4427
4428     ShowWindow(hwnd, SW_HIDE);
4429     flush_events();
4430     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4431
4432     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4433     flush_events();
4434     ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4435
4436     ShowWindow(hwnd, SW_RESTORE);
4437     ok_sequence(WmShowRestoreMaxOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", FALSE);
4438     flush_events();
4439     flush_sequence();
4440
4441     ShowWindow(hwnd, SW_MINIMIZE);
4442     flush_events();
4443     ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4444     flush_sequence();
4445
4446     ShowWindow(hwnd, SW_RESTORE);
4447     flush_events();
4448     ok_sequence(WmShowRestoreMinOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4449     flush_sequence();
4450
4451     ShowWindow(hwnd, SW_SHOW);
4452     flush_events();
4453     ok_sequence(WmOptionalPaint, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4454
4455     ok(GetActiveWindow() == hwnd, "window should be active\n");
4456     ok(GetFocus() == hwnd, "window should have input focus\n");
4457     SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4458     ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4459     ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4460     ok(GetActiveWindow() == hwnd, "window should still be active\n");
4461
4462     /* test WM_SETREDRAW on a visible top level window */
4463     ShowWindow(hwnd, SW_SHOW);
4464     flush_events();
4465     test_WM_SETREDRAW(hwnd);
4466
4467     trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4468     test_scroll_messages(hwnd);
4469
4470     /* test resizing and moving */
4471     SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4472     ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4473     flush_events();
4474     flush_sequence();
4475     SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4476     ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4477     flush_events();
4478     flush_sequence();
4479     SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER|SWP_NOACTIVATE );
4480     ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4481     flush_events();
4482     flush_sequence();
4483
4484     /* popups don't get WM_GETMINMAXINFO */
4485     SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4486     SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4487     flush_sequence();
4488     SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4489     ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4490
4491     DestroyWindow(hwnd);
4492     ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4493
4494     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4495                               100, 100, 200, 200, 0, 0, 0, NULL);
4496     ok (hparent != 0, "Failed to create parent window\n");
4497     flush_sequence();
4498
4499     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4500                              0, 0, 10, 10, hparent, 0, 0, NULL);
4501     ok (hchild != 0, "Failed to create child window\n");
4502     ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4503     DestroyWindow(hchild);
4504     flush_sequence();
4505
4506     /* visible child window with a caption */
4507     hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4508                              WS_CHILD | WS_VISIBLE | WS_CAPTION,
4509                              0, 0, 10, 10, hparent, 0, 0, NULL);
4510     ok (hchild != 0, "Failed to create child window\n");
4511     ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4512
4513     trace("testing scroll APIs on a visible child window %p\n", hchild);
4514     test_scroll_messages(hchild);
4515
4516     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4517     ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4518
4519     DestroyWindow(hchild);
4520     flush_sequence();
4521
4522     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4523                              0, 0, 10, 10, hparent, 0, 0, NULL);
4524     ok (hchild != 0, "Failed to create child window\n");
4525     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4526     
4527     hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4528                                100, 100, 50, 50, hparent, 0, 0, NULL);
4529     ok (hchild2 != 0, "Failed to create child2 window\n");
4530     flush_sequence();
4531
4532     hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4533                               0, 100, 50, 50, hchild, 0, 0, NULL);
4534     ok (hbutton != 0, "Failed to create button window\n");
4535
4536     /* test WM_SETREDRAW on a not visible child window */
4537     test_WM_SETREDRAW(hchild);
4538
4539     ShowWindow(hchild, SW_SHOW);
4540     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4541
4542     /* check parent messages too */
4543     log_all_parent_messages++;
4544     ShowWindow(hchild, SW_HIDE);
4545     ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4546     log_all_parent_messages--;
4547
4548     ShowWindow(hchild, SW_SHOW);
4549     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4550
4551     ShowWindow(hchild, SW_HIDE);
4552     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4553
4554     ShowWindow(hchild, SW_SHOW);
4555     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4556
4557     /* test WM_SETREDRAW on a visible child window */
4558     test_WM_SETREDRAW(hchild);
4559
4560     log_all_parent_messages++;
4561     MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4562     ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4563     log_all_parent_messages--;
4564
4565     ShowWindow(hchild, SW_HIDE);
4566     flush_sequence();
4567     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4568     ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4569
4570     ShowWindow(hchild, SW_HIDE);
4571     flush_sequence();
4572     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4573     ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4574
4575     /* DestroyWindow sequence below expects that a child has focus */
4576     SetFocus(hchild);
4577     flush_sequence();
4578
4579     DestroyWindow(hchild);
4580     ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4581     DestroyWindow(hchild2);
4582     DestroyWindow(hbutton);
4583
4584     flush_sequence();
4585     hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4586                              0, 0, 100, 100, hparent, 0, 0, NULL);
4587     ok (hchild != 0, "Failed to create child popup window\n");
4588     ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4589     DestroyWindow(hchild);
4590
4591     /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4592     flush_sequence();
4593     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4594                              0, 0, 100, 100, hparent, 0, 0, NULL);
4595     ok (hchild != 0, "Failed to create popup window\n");
4596     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4597     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4598     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4599     flush_sequence();
4600     ShowWindow(hchild, SW_SHOW);
4601     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4602     flush_sequence();
4603     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4604     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4605     flush_sequence();
4606     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4607     ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
4608     DestroyWindow(hchild);
4609
4610     /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4611      * changes nothing in message sequences.
4612      */
4613     flush_sequence();
4614     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4615                              0, 0, 100, 100, hparent, 0, 0, NULL);
4616     ok (hchild != 0, "Failed to create popup window\n");
4617     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4618     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4619     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4620     flush_sequence();
4621     ShowWindow(hchild, SW_SHOW);
4622     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4623     flush_sequence();
4624     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4625     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4626     DestroyWindow(hchild);
4627
4628     flush_sequence();
4629     hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4630                            0, 0, 100, 100, hparent, 0, 0, NULL);
4631     ok(hwnd != 0, "Failed to create custom dialog window\n");
4632     ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4633
4634     /*
4635     trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4636     test_scroll_messages(hwnd);
4637     */
4638
4639     flush_sequence();
4640
4641     test_def_id = 1;
4642     SendMessage(hwnd, WM_NULL, 0, 0);
4643
4644     flush_sequence();
4645     after_end_dialog = 1;
4646     EndDialog( hwnd, 0 );
4647     ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4648
4649     DestroyWindow(hwnd);
4650     after_end_dialog = 0;
4651     test_def_id = 0;
4652
4653     hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4654                            0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4655     ok(hwnd != 0, "Failed to create custom dialog window\n");
4656     flush_sequence();
4657     trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4658     ShowWindow(hwnd, SW_SHOW);
4659     ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4660     DestroyWindow(hwnd);
4661
4662     flush_sequence();
4663     DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4664     ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4665
4666     DestroyWindow(hparent);
4667     flush_sequence();
4668
4669     /* Message sequence for SetMenu */
4670     ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4671     ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4672
4673     hmenu = CreateMenu();
4674     ok (hmenu != 0, "Failed to create menu\n");
4675     ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4676     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4677                            100, 100, 200, 200, 0, hmenu, 0, NULL);
4678     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4679     ok (SetMenu(hwnd, 0), "SetMenu\n");
4680     ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4681     ok (SetMenu(hwnd, 0), "SetMenu\n");
4682     ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4683     ShowWindow(hwnd, SW_SHOW);
4684     UpdateWindow( hwnd );
4685     flush_events();
4686     flush_sequence();
4687     ok (SetMenu(hwnd, 0), "SetMenu\n");
4688     ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4689     ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4690     ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4691
4692     UpdateWindow( hwnd );
4693     flush_events();
4694     flush_sequence();
4695     ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4696     flush_events();
4697     ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4698
4699     DestroyWindow(hwnd);
4700     flush_sequence();
4701
4702     /* Message sequence for EnableWindow */
4703     hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4704                               100, 100, 200, 200, 0, 0, 0, NULL);
4705     ok (hparent != 0, "Failed to create parent window\n");
4706     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4707                              0, 0, 10, 10, hparent, 0, 0, NULL);
4708     ok (hchild != 0, "Failed to create child window\n");
4709
4710     SetFocus(hchild);
4711     flush_events();
4712     flush_sequence();
4713
4714     EnableWindow(hparent, FALSE);
4715     ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4716
4717     EnableWindow(hparent, TRUE);
4718     ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4719
4720     flush_events();
4721     flush_sequence();
4722
4723     test_MsgWaitForMultipleObjects(hparent);
4724
4725     /* the following test causes an exception in user.exe under win9x */
4726     if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4727     {
4728         DestroyWindow(hparent);
4729         flush_sequence();
4730         return;
4731     }
4732     PostMessageW( hparent, WM_USER+1, 0, 0 );
4733     /* PeekMessage(NULL) fails, but still removes the message */
4734     SetLastError(0xdeadbeef);
4735     ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4736     ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4737         GetLastError() == 0xdeadbeef, /* NT4 */
4738         "last error is %d\n", GetLastError() );
4739     ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4740     ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4741
4742     DestroyWindow(hchild);
4743     DestroyWindow(hparent);
4744     flush_sequence();
4745
4746     /* Message sequences for WM_SETICON */
4747     trace("testing WM_SETICON\n");
4748     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4749                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4750                            NULL, NULL, 0);
4751     ShowWindow(hwnd, SW_SHOW);
4752     UpdateWindow(hwnd);
4753     flush_events();
4754     flush_sequence();
4755     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4756     ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4757
4758     ShowWindow(hwnd, SW_HIDE);
4759     flush_events();
4760     flush_sequence();
4761     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4762     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4763     DestroyWindow(hwnd);
4764     flush_sequence();
4765
4766     hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4767                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4768                            NULL, NULL, 0);
4769     ShowWindow(hwnd, SW_SHOW);
4770     UpdateWindow(hwnd);
4771     flush_events();
4772     flush_sequence();
4773     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4774     ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4775
4776     ShowWindow(hwnd, SW_HIDE);
4777     flush_events();
4778     flush_sequence();
4779     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4780     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4781
4782     flush_sequence();
4783     res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4784     if (!res)
4785     {
4786         todo_wine win_skip( "Message 0x3b not supported\n" );
4787         goto done;
4788     }
4789     ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4790     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4791     res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4792     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4793     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4794     res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4795     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4796     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4797
4798     flush_sequence();
4799     res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4800     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4801     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4802     res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4803     ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4804     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4805
4806     res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4807     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4808     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4809
4810     res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4811     ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4812     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4813
4814 done:
4815     DestroyWindow(hwnd);
4816     flush_sequence();
4817 }
4818
4819 static void test_setwindowpos(void)
4820 {
4821     HWND hwnd;
4822     RECT rc;
4823     LRESULT res;
4824     const INT winX = 100;
4825     const INT winY = 100;
4826     const INT sysX = GetSystemMetrics(SM_CXMINTRACK);
4827
4828     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
4829                            0, 0, winX, winY, 0,
4830                            NULL, NULL, 0);
4831
4832     GetWindowRect(hwnd, &rc);
4833     expect(sysX, rc.right);
4834     expect(winY, rc.bottom);
4835
4836     flush_events();
4837     flush_sequence();
4838     res = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, winX, winY, 0);
4839     ok_sequence(WmZOrder, "Z-Order", TRUE);
4840     ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
4841
4842     GetWindowRect(hwnd, &rc);
4843     expect(sysX, rc.right);
4844     expect(winY, rc.bottom);
4845     DestroyWindow(hwnd);
4846 }
4847
4848 static void invisible_parent_tests(void)
4849 {
4850     HWND hparent, hchild;
4851
4852     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4853                               100, 100, 200, 200, 0, 0, 0, NULL);
4854     ok (hparent != 0, "Failed to create parent window\n");
4855     flush_sequence();
4856
4857     /* test showing child with hidden parent */
4858
4859     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4860                              0, 0, 10, 10, hparent, 0, 0, NULL);
4861     ok (hchild != 0, "Failed to create child window\n");
4862     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4863
4864     ShowWindow( hchild, SW_MINIMIZE );
4865     ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4866     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4867     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4868
4869     /* repeat */
4870     flush_events();
4871     flush_sequence();
4872     ShowWindow( hchild, SW_MINIMIZE );
4873     ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4874
4875     DestroyWindow(hchild);
4876     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4877                              0, 0, 10, 10, hparent, 0, 0, NULL);
4878     flush_sequence();
4879
4880     ShowWindow( hchild, SW_MAXIMIZE );
4881     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4882     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4883     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4884
4885     /* repeat */
4886     flush_events();
4887     flush_sequence();
4888     ShowWindow( hchild, SW_MAXIMIZE );
4889     ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4890
4891     DestroyWindow(hchild);
4892     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4893                              0, 0, 10, 10, hparent, 0, 0, NULL);
4894     flush_sequence();
4895
4896     ShowWindow( hchild, SW_RESTORE );
4897     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
4898     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4899     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4900
4901     DestroyWindow(hchild);
4902     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4903                              0, 0, 10, 10, hparent, 0, 0, NULL);
4904     flush_sequence();
4905
4906     ShowWindow( hchild, SW_SHOWMINIMIZED );
4907     ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4908     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4909     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4910
4911     /* repeat */
4912     flush_events();
4913     flush_sequence();
4914     ShowWindow( hchild, SW_SHOWMINIMIZED );
4915     ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4916
4917     DestroyWindow(hchild);
4918     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4919                              0, 0, 10, 10, hparent, 0, 0, NULL);
4920     flush_sequence();
4921
4922     /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
4923     ShowWindow( hchild, SW_SHOWMAXIMIZED );
4924     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
4925     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4926     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4927
4928     DestroyWindow(hchild);
4929     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4930                              0, 0, 10, 10, hparent, 0, 0, NULL);
4931     flush_sequence();
4932
4933     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4934     ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4935     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4936     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4937
4938     /* repeat */
4939     flush_events();
4940     flush_sequence();
4941     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4942     ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4943
4944     DestroyWindow(hchild);
4945     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4946                              0, 0, 10, 10, hparent, 0, 0, NULL);
4947     flush_sequence();
4948
4949     /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
4950     ShowWindow( hchild, SW_FORCEMINIMIZE );
4951     ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
4952 todo_wine {
4953     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4954 }
4955     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4956
4957     DestroyWindow(hchild);
4958     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4959                              0, 0, 10, 10, hparent, 0, 0, NULL);
4960     flush_sequence();
4961
4962     ShowWindow( hchild, SW_SHOWNA );
4963     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4964     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4965     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4966
4967     /* repeat */
4968     flush_events();
4969     flush_sequence();
4970     ShowWindow( hchild, SW_SHOWNA );
4971     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4972
4973     DestroyWindow(hchild);
4974     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4975                              0, 0, 10, 10, hparent, 0, 0, NULL);
4976     flush_sequence();
4977
4978     ShowWindow( hchild, SW_SHOW );
4979     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4980     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4981     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4982
4983     /* repeat */
4984     flush_events();
4985     flush_sequence();
4986     ShowWindow( hchild, SW_SHOW );
4987     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4988
4989     ShowWindow( hchild, SW_HIDE );
4990     ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
4991     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4992     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4993
4994     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4995     ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
4996     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4997     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4998
4999     SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5000     ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
5001     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
5002     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5003
5004     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5005     flush_sequence();
5006     DestroyWindow(hchild);
5007     ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
5008
5009     DestroyWindow(hparent);
5010     flush_sequence();
5011 }
5012
5013 /****************** button message test *************************/
5014 static const struct message WmSetFocusButtonSeq[] =
5015 {
5016     { HCBT_SETFOCUS, hook },
5017     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5018     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5019     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5020     { WM_SETFOCUS, sent|wparam, 0 },
5021     { WM_CTLCOLORBTN, sent|defwinproc },
5022     { 0 }
5023 };
5024 static const struct message WmKillFocusButtonSeq[] =
5025 {
5026     { HCBT_SETFOCUS, hook },
5027     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5028     { WM_KILLFOCUS, sent|wparam, 0 },
5029     { WM_CTLCOLORBTN, sent|defwinproc },
5030     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5031     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5032     { 0 }
5033 };
5034 static const struct message WmSetFocusStaticSeq[] =
5035 {
5036     { HCBT_SETFOCUS, hook },
5037     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5038     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5039     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5040     { WM_SETFOCUS, sent|wparam, 0 },
5041     { WM_CTLCOLORSTATIC, sent|defwinproc },
5042     { 0 }
5043 };
5044 static const struct message WmKillFocusStaticSeq[] =
5045 {
5046     { HCBT_SETFOCUS, hook },
5047     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5048     { WM_KILLFOCUS, sent|wparam, 0 },
5049     { WM_CTLCOLORSTATIC, sent|defwinproc },
5050     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5051     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5052     { 0 }
5053 };
5054 static const struct message WmLButtonDownSeq[] =
5055 {
5056     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
5057     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5058     { HCBT_SETFOCUS, hook },
5059     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
5060     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5061     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5062     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
5063     { WM_CTLCOLORBTN, sent|defwinproc },
5064     { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
5065     { WM_CTLCOLORBTN, sent|defwinproc },
5066     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5067     { 0 }
5068 };
5069 static const struct message WmLButtonUpSeq[] =
5070 {
5071     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
5072     { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
5073     { WM_CTLCOLORBTN, sent|defwinproc },
5074     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5075     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5076     { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
5077     { 0 }
5078 };
5079 static const struct message WmSetFontButtonSeq[] =
5080 {
5081     { WM_SETFONT, sent },
5082     { WM_PAINT, sent },
5083     { WM_ERASEBKGND, sent|defwinproc|optional },
5084     { WM_CTLCOLORBTN, sent|defwinproc },
5085     { 0 }
5086 };
5087
5088 static WNDPROC old_button_proc;
5089
5090 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5091 {
5092     static long defwndproc_counter = 0;
5093     LRESULT ret;
5094     struct recvd_message msg;
5095
5096     switch (message)
5097     {
5098     case WM_GETICON:
5099     case WM_GETOBJECT:
5100         return 0;  /* ignore them */
5101     case WM_SYNCPAINT:
5102         break;
5103     case BM_SETSTATE:
5104         ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
5105         /* fall through */
5106     default:
5107         msg.hwnd = hwnd;
5108         msg.message = message;
5109         msg.flags = sent|wparam|lparam;
5110         if (defwndproc_counter) msg.flags |= defwinproc;
5111         msg.wParam = wParam;
5112         msg.lParam = lParam;
5113         msg.descr = "button";
5114         add_message(&msg);
5115     }
5116
5117     defwndproc_counter++;
5118     ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
5119     defwndproc_counter--;
5120
5121     return ret;
5122 }
5123
5124 static void subclass_button(void)
5125 {
5126     WNDCLASSA cls;
5127
5128     if (!GetClassInfoA(0, "button", &cls)) assert(0);
5129
5130     old_button_proc = cls.lpfnWndProc;
5131
5132     cls.hInstance = GetModuleHandle(0);
5133     cls.lpfnWndProc = button_hook_proc;
5134     cls.lpszClassName = "my_button_class";
5135     UnregisterClass(cls.lpszClassName, cls.hInstance);
5136     if (!RegisterClassA(&cls)) assert(0);
5137 }
5138
5139 static void test_button_messages(void)
5140 {
5141     static const struct
5142     {
5143         DWORD style;
5144         DWORD dlg_code;
5145         const struct message *setfocus;
5146         const struct message *killfocus;
5147     } button[] = {
5148         { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5149           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5150         { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
5151           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5152         { BS_CHECKBOX, DLGC_BUTTON,
5153           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5154         { BS_AUTOCHECKBOX, DLGC_BUTTON,
5155           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5156         { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5157           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5158         { BS_3STATE, DLGC_BUTTON,
5159           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5160         { BS_AUTO3STATE, DLGC_BUTTON,
5161           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5162         { BS_GROUPBOX, DLGC_STATIC,
5163           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5164         { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5165           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5166         { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5167           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5168         { BS_OWNERDRAW, DLGC_BUTTON,
5169           WmSetFocusButtonSeq, WmKillFocusButtonSeq }
5170     };
5171     unsigned int i;
5172     HWND hwnd;
5173     DWORD dlg_code;
5174     HFONT zfont;
5175
5176     subclass_button();
5177
5178     for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
5179     {
5180         hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_POPUP,
5181                                0, 0, 50, 14, 0, 0, 0, NULL);
5182         ok(hwnd != 0, "Failed to create button window\n");
5183
5184         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5185         ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5186
5187         ShowWindow(hwnd, SW_SHOW);
5188         UpdateWindow(hwnd);
5189         SetFocus(0);
5190         flush_sequence();
5191
5192         trace("button style %08x\n", button[i].style);
5193         SetFocus(hwnd);
5194         ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
5195
5196         SetFocus(0);
5197         ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
5198
5199         DestroyWindow(hwnd);
5200     }
5201
5202     hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
5203                            0, 0, 50, 14, 0, 0, 0, NULL);
5204     ok(hwnd != 0, "Failed to create button window\n");
5205
5206     SetForegroundWindow(hwnd);
5207     SetFocus(0);
5208     flush_events();
5209     flush_sequence();
5210
5211     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
5212     ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
5213
5214     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
5215     ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
5216
5217     flush_sequence();
5218     zfont = GetStockObject(SYSTEM_FONT);
5219     SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
5220     UpdateWindow(hwnd);
5221     ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
5222
5223     DestroyWindow(hwnd);
5224 }
5225
5226 /****************** static message test *************************/
5227 static const struct message WmSetFontStaticSeq[] =
5228 {
5229     { WM_SETFONT, sent },
5230     { WM_PAINT, sent|defwinproc|optional },
5231     { WM_ERASEBKGND, sent|defwinproc|optional },
5232     { WM_CTLCOLORSTATIC, sent|defwinproc|optional },
5233     { 0 }
5234 };
5235
5236 static WNDPROC old_static_proc;
5237
5238 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5239 {
5240     static long defwndproc_counter = 0;
5241     LRESULT ret;
5242     struct recvd_message msg;
5243
5244     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
5245
5246     msg.hwnd = hwnd;
5247     msg.message = message;
5248     msg.flags = sent|wparam|lparam;
5249     if (defwndproc_counter) msg.flags |= defwinproc;
5250     msg.wParam = wParam;
5251     msg.lParam = lParam;
5252     msg.descr = "static";
5253     add_message(&msg);
5254
5255     defwndproc_counter++;
5256     ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
5257     defwndproc_counter--;
5258
5259     return ret;
5260 }
5261
5262 static void subclass_static(void)
5263 {
5264     WNDCLASSA cls;
5265
5266     if (!GetClassInfoA(0, "static", &cls)) assert(0);
5267
5268     old_static_proc = cls.lpfnWndProc;
5269
5270     cls.hInstance = GetModuleHandle(0);
5271     cls.lpfnWndProc = static_hook_proc;
5272     cls.lpszClassName = "my_static_class";
5273     UnregisterClass(cls.lpszClassName, cls.hInstance);
5274     if (!RegisterClassA(&cls)) assert(0);
5275 }
5276
5277 static void test_static_messages(void)
5278 {
5279     /* FIXME: make as comprehensive as the button message test */
5280     static const struct
5281     {
5282         DWORD style;
5283         DWORD dlg_code;
5284         const struct message *setfont;
5285     } static_ctrl[] = {
5286         { SS_LEFT, DLGC_STATIC,
5287           WmSetFontStaticSeq }
5288     };
5289     unsigned int i;
5290     HWND hwnd;
5291     DWORD dlg_code;
5292
5293     subclass_static();
5294
5295     for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
5296     {
5297         hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
5298                                0, 0, 50, 14, 0, 0, 0, NULL);
5299         ok(hwnd != 0, "Failed to create static window\n");
5300
5301         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5302         ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5303
5304         ShowWindow(hwnd, SW_SHOW);
5305         UpdateWindow(hwnd);
5306         SetFocus(0);
5307         flush_sequence();
5308
5309         trace("static style %08x\n", static_ctrl[i].style);
5310         SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
5311         ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
5312
5313         DestroyWindow(hwnd);
5314     }
5315 }
5316
5317 /****************** ComboBox message test *************************/
5318 #define ID_COMBOBOX 0x000f
5319
5320 static const struct message WmKeyDownComboSeq[] =
5321 {
5322     { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
5323     { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
5324     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
5325     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
5326     { WM_CTLCOLOREDIT, sent|parent },
5327     { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
5328     { 0 }
5329 };
5330
5331 static WNDPROC old_combobox_proc;
5332
5333 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5334 {
5335     static long defwndproc_counter = 0;
5336     LRESULT ret;
5337     struct recvd_message msg;
5338
5339     /* do not log painting messages */
5340     if (message != WM_PAINT &&
5341         message != WM_NCPAINT &&
5342         message != WM_SYNCPAINT &&
5343         message != WM_ERASEBKGND &&
5344         message != WM_NCHITTEST &&
5345         message != WM_GETTEXT &&
5346         message != WM_GETICON &&
5347         message != WM_GETOBJECT &&
5348         message != WM_DEVICECHANGE)
5349     {
5350         msg.hwnd = hwnd;
5351         msg.message = message;
5352         msg.flags = sent|wparam|lparam;
5353         if (defwndproc_counter) msg.flags |= defwinproc;
5354         msg.wParam = wParam;
5355         msg.lParam = lParam;
5356         msg.descr = "combo";
5357         add_message(&msg);
5358     }
5359
5360     defwndproc_counter++;
5361     ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5362     defwndproc_counter--;
5363
5364     return ret;
5365 }
5366
5367 static void subclass_combobox(void)
5368 {
5369     WNDCLASSA cls;
5370
5371     if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5372
5373     old_combobox_proc = cls.lpfnWndProc;
5374
5375     cls.hInstance = GetModuleHandle(0);
5376     cls.lpfnWndProc = combobox_hook_proc;
5377     cls.lpszClassName = "my_combobox_class";
5378     UnregisterClass(cls.lpszClassName, cls.hInstance);
5379     if (!RegisterClassA(&cls)) assert(0);
5380 }
5381
5382 static void test_combobox_messages(void)
5383 {
5384     HWND parent, combo;
5385     LRESULT ret;
5386
5387     subclass_combobox();
5388
5389     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5390                              100, 100, 200, 200, 0, 0, 0, NULL);
5391     ok(parent != 0, "Failed to create parent window\n");
5392     flush_sequence();
5393
5394     combo = CreateWindowEx(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5395                            0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5396     ok(combo != 0, "Failed to create combobox window\n");
5397
5398     UpdateWindow(combo);
5399
5400     ret = SendMessage(combo, WM_GETDLGCODE, 0, 0);
5401     ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5402
5403     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5404     ok(ret == 0, "expected 0, got %ld\n", ret);
5405     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5406     ok(ret == 1, "expected 1, got %ld\n", ret);
5407     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5408     ok(ret == 2, "expected 2, got %ld\n", ret);
5409
5410     SendMessage(combo, CB_SETCURSEL, 0, 0);
5411     SetFocus(combo);
5412     flush_sequence();
5413
5414     log_all_parent_messages++;
5415     SendMessage(combo, WM_KEYDOWN, VK_DOWN, 0);
5416     SendMessage(combo, WM_KEYUP, VK_DOWN, 0);
5417     log_all_parent_messages--;
5418     ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5419
5420     DestroyWindow(combo);
5421     DestroyWindow(parent);
5422 }
5423
5424 /****************** WM_IME_KEYDOWN message test *******************/
5425
5426 static const struct message WmImeKeydownMsgSeq_0[] =
5427 {
5428     { WM_IME_KEYDOWN, wparam, VK_RETURN },
5429     { WM_CHAR, wparam, 'A' },
5430     { 0 }
5431 };
5432
5433 static const struct message WmImeKeydownMsgSeq_1[] =
5434 {
5435     { WM_KEYDOWN, optional|wparam, VK_RETURN },
5436     { WM_CHAR,    optional|wparam, VK_RETURN },
5437     { 0 }
5438 };
5439
5440 static LRESULT WINAPI wmime_keydown_procA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5441 {
5442     struct recvd_message msg;
5443
5444     msg.hwnd = hwnd;
5445     msg.message = message;
5446     msg.flags = wparam|lparam;
5447     msg.wParam = wParam;
5448     msg.lParam = lParam;
5449     msg.descr = "wmime_keydown";
5450     add_message(&msg);
5451
5452     return DefWindowProcA(hwnd, message, wParam, lParam);
5453 }
5454
5455 static void register_wmime_keydown_class(void)
5456 {
5457     WNDCLASSA cls;
5458
5459     ZeroMemory(&cls, sizeof(WNDCLASSA));
5460     cls.lpfnWndProc = wmime_keydown_procA;
5461     cls.hInstance = GetModuleHandleA(0);
5462     cls.lpszClassName = "wmime_keydown_class";
5463     if (!RegisterClassA(&cls)) assert(0);
5464 }
5465
5466 static void test_wmime_keydown_message(void)
5467 {
5468     HWND hwnd;
5469     MSG msg;
5470
5471     trace("Message sequences by WM_IME_KEYDOWN\n");
5472
5473     register_wmime_keydown_class();
5474     hwnd = CreateWindowExA(0, "wmime_keydown_class", NULL, WS_OVERLAPPEDWINDOW,
5475                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5476                            NULL, NULL, 0);
5477     flush_events();
5478     flush_sequence();
5479
5480     SendMessage(hwnd, WM_IME_KEYDOWN, VK_RETURN, 0x1c0001);
5481     SendMessage(hwnd, WM_CHAR, 'A', 1);
5482     ok_sequence(WmImeKeydownMsgSeq_0, "WM_IME_KEYDOWN 0", FALSE);
5483
5484     while ( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
5485     {
5486         TranslateMessage(&msg);
5487         DispatchMessage(&msg);
5488     }
5489     ok_sequence(WmImeKeydownMsgSeq_1, "WM_IME_KEYDOWN 1", FALSE);
5490
5491     DestroyWindow(hwnd);
5492 }
5493
5494 /************* painting message test ********************/
5495
5496 void dump_region(HRGN hrgn)
5497 {
5498     DWORD i, size;
5499     RGNDATA *data = NULL;
5500     RECT *rect;
5501
5502     if (!hrgn)
5503     {
5504         printf( "null region\n" );
5505         return;
5506     }
5507     if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5508     if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5509     GetRegionData( hrgn, size, data );
5510     printf("%d rects:", data->rdh.nCount );
5511     for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5512         printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
5513     printf("\n");
5514     HeapFree( GetProcessHeap(), 0, data );
5515 }
5516
5517 static void check_update_rgn( HWND hwnd, HRGN hrgn )
5518 {
5519     INT ret;
5520     RECT r1, r2;
5521     HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
5522     HRGN update = CreateRectRgn( 0, 0, 0, 0 );
5523
5524     ret = GetUpdateRgn( hwnd, update, FALSE );
5525     ok( ret != ERROR, "GetUpdateRgn failed\n" );
5526     if (ret == NULLREGION)
5527     {
5528         ok( !hrgn, "Update region shouldn't be empty\n" );
5529     }
5530     else
5531     {
5532         if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
5533         {
5534             ok( 0, "Regions are different\n" );
5535             if (winetest_debug > 0)
5536             {
5537                 printf( "Update region: " );
5538                 dump_region( update );
5539                 printf( "Wanted region: " );
5540                 dump_region( hrgn );
5541             }
5542         }
5543     }
5544     GetRgnBox( update, &r1 );
5545     GetUpdateRect( hwnd, &r2, FALSE );
5546     ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
5547         "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
5548         r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
5549
5550     DeleteObject( tmp );
5551     DeleteObject( update );
5552 }
5553
5554 static const struct message WmInvalidateRgn[] = {
5555     { WM_NCPAINT, sent },
5556     { WM_GETTEXT, sent|defwinproc|optional },
5557     { 0 }
5558 };
5559
5560 static const struct message WmGetUpdateRect[] = {
5561     { WM_NCPAINT, sent },
5562     { WM_GETTEXT, sent|defwinproc|optional },
5563     { WM_PAINT, sent },
5564     { 0 }
5565 };
5566
5567 static const struct message WmInvalidateFull[] = {
5568     { WM_NCPAINT, sent|wparam, 1 },
5569     { WM_GETTEXT, sent|defwinproc|optional },
5570     { 0 }
5571 };
5572
5573 static const struct message WmInvalidateErase[] = {
5574     { WM_NCPAINT, sent|wparam, 1 },
5575     { WM_GETTEXT, sent|defwinproc|optional },
5576     { WM_ERASEBKGND, sent },
5577     { 0 }
5578 };
5579
5580 static const struct message WmInvalidatePaint[] = {
5581     { WM_PAINT, sent },
5582     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5583     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5584     { 0 }
5585 };
5586
5587 static const struct message WmInvalidateErasePaint[] = {
5588     { WM_PAINT, sent },
5589     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5590     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5591     { WM_ERASEBKGND, sent|beginpaint },
5592     { 0 }
5593 };
5594
5595 static const struct message WmInvalidateErasePaint2[] = {
5596     { WM_PAINT, sent },
5597     { WM_NCPAINT, sent|beginpaint },
5598     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5599     { WM_ERASEBKGND, sent|beginpaint|optional },
5600     { 0 }
5601 };
5602
5603 static const struct message WmErase[] = {
5604     { WM_ERASEBKGND, sent },
5605     { 0 }
5606 };
5607
5608 static const struct message WmPaint[] = {
5609     { WM_PAINT, sent },
5610     { 0 }
5611 };
5612
5613 static const struct message WmParentOnlyPaint[] = {
5614     { WM_PAINT, sent|parent },
5615     { 0 }
5616 };
5617
5618 static const struct message WmInvalidateParent[] = {
5619     { WM_NCPAINT, sent|parent },
5620     { WM_GETTEXT, sent|defwinproc|parent|optional },
5621     { WM_ERASEBKGND, sent|parent },
5622     { 0 }
5623 };
5624
5625 static const struct message WmInvalidateParentChild[] = {
5626     { WM_NCPAINT, sent|parent },
5627     { WM_GETTEXT, sent|defwinproc|parent|optional },
5628     { WM_ERASEBKGND, sent|parent },
5629     { WM_NCPAINT, sent },
5630     { WM_GETTEXT, sent|defwinproc|optional },
5631     { WM_ERASEBKGND, sent },
5632     { 0 }
5633 };
5634
5635 static const struct message WmInvalidateParentChild2[] = {
5636     { WM_ERASEBKGND, sent|parent },
5637     { WM_NCPAINT, sent },
5638     { WM_GETTEXT, sent|defwinproc|optional },
5639     { WM_ERASEBKGND, sent },
5640     { 0 }
5641 };
5642
5643 static const struct message WmParentPaint[] = {
5644     { WM_PAINT, sent|parent },
5645     { WM_PAINT, sent },
5646     { 0 }
5647 };
5648
5649 static const struct message WmParentPaintNc[] = {
5650     { WM_PAINT, sent|parent },
5651     { WM_PAINT, sent },
5652     { WM_NCPAINT, sent|beginpaint },
5653     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5654     { WM_ERASEBKGND, sent|beginpaint|optional },
5655     { 0 }
5656 };
5657
5658 static const struct message WmChildPaintNc[] = {
5659     { WM_PAINT, sent },
5660     { WM_NCPAINT, sent|beginpaint },
5661     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5662     { WM_ERASEBKGND, sent|beginpaint },
5663     { 0 }
5664 };
5665
5666 static const struct message WmParentErasePaint[] = {
5667     { WM_PAINT, sent|parent },
5668     { WM_NCPAINT, sent|parent|beginpaint },
5669     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5670     { WM_ERASEBKGND, sent|parent|beginpaint|optional },
5671     { WM_PAINT, sent },
5672     { WM_NCPAINT, sent|beginpaint },
5673     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5674     { WM_ERASEBKGND, sent|beginpaint|optional },
5675     { 0 }
5676 };
5677
5678 static const struct message WmParentOnlyNcPaint[] = {
5679     { WM_PAINT, sent|parent },
5680     { WM_NCPAINT, sent|parent|beginpaint },
5681     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5682     { 0 }
5683 };
5684
5685 static const struct message WmSetParentStyle[] = {
5686     { WM_STYLECHANGING, sent|parent },
5687     { WM_STYLECHANGED, sent|parent },
5688     { 0 }
5689 };
5690
5691 static void test_paint_messages(void)
5692 {
5693     BOOL ret;
5694     RECT rect;
5695     POINT pt;
5696     MSG msg;
5697     HWND hparent, hchild;
5698     HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
5699     HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
5700     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
5701                                 100, 100, 200, 200, 0, 0, 0, NULL);
5702     ok (hwnd != 0, "Failed to create overlapped window\n");
5703
5704     ShowWindow( hwnd, SW_SHOW );
5705     UpdateWindow( hwnd );
5706     flush_events();
5707     flush_sequence();
5708
5709     check_update_rgn( hwnd, 0 );
5710     SetRectRgn( hrgn, 10, 10, 20, 20 );
5711     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5712     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5713     check_update_rgn( hwnd, hrgn );
5714     SetRectRgn( hrgn2, 20, 20, 30, 30 );
5715     ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
5716     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5717     CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
5718     check_update_rgn( hwnd, hrgn );
5719     /* validate everything */
5720     ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5721     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5722     check_update_rgn( hwnd, 0 );
5723
5724     /* test empty region */
5725     SetRectRgn( hrgn, 10, 10, 10, 15 );
5726     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5727     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5728     check_update_rgn( hwnd, 0 );
5729     /* test empty rect */
5730     SetRect( &rect, 10, 10, 10, 15 );
5731     ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
5732     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5733     check_update_rgn( hwnd, 0 );
5734
5735     /* flush pending messages */
5736     flush_events();
5737     flush_sequence();
5738
5739     GetClientRect( hwnd, &rect );
5740     SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
5741     /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
5742      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5743      */
5744     trace("testing InvalidateRect(0, NULL, FALSE)\n");
5745     SetRectEmpty( &rect );
5746     ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
5747     check_update_rgn( hwnd, hrgn );
5748     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5749     flush_events();
5750     ok_sequence( WmPaint, "Paint", FALSE );
5751     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5752     check_update_rgn( hwnd, 0 );
5753
5754     /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
5755      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5756      */
5757     trace("testing ValidateRect(0, NULL)\n");
5758     SetRectEmpty( &rect );
5759     if (ValidateRect(0, &rect))  /* not supported on Win9x */
5760     {
5761         check_update_rgn( hwnd, hrgn );
5762         ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5763         flush_events();
5764         ok_sequence( WmPaint, "Paint", FALSE );
5765         RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5766         check_update_rgn( hwnd, 0 );
5767     }
5768
5769     trace("testing InvalidateRgn(0, NULL, FALSE)\n");
5770     SetLastError(0xdeadbeef);
5771     ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
5772     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
5773        "wrong error code %d\n", GetLastError());
5774     check_update_rgn( hwnd, 0 );
5775     flush_events();
5776     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5777
5778     trace("testing ValidateRgn(0, NULL)\n");
5779     SetLastError(0xdeadbeef);
5780     ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
5781     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
5782        broken( GetLastError() == 0xdeadbeef ) /* win9x */,
5783        "wrong error code %d\n", GetLastError());
5784     check_update_rgn( hwnd, 0 );
5785     flush_events();
5786     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5787
5788     /* now with frame */
5789     SetRectRgn( hrgn, -5, -5, 20, 20 );
5790
5791     /* flush pending messages */
5792     flush_events();
5793     flush_sequence();
5794     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5795     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5796
5797     SetRectRgn( hrgn, 0, 0, 20, 20 );  /* GetUpdateRgn clips to client area */
5798     check_update_rgn( hwnd, hrgn );
5799
5800     flush_sequence();
5801     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5802     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5803
5804     flush_sequence();
5805     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5806     ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
5807
5808     GetClientRect( hwnd, &rect );
5809     SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
5810     check_update_rgn( hwnd, hrgn );
5811
5812     flush_sequence();
5813     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
5814     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5815
5816     flush_sequence();
5817     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
5818     ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
5819     check_update_rgn( hwnd, 0 );
5820
5821     flush_sequence();
5822     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
5823     ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
5824     check_update_rgn( hwnd, 0 );
5825
5826     flush_sequence();
5827     SetRectRgn( hrgn, 0, 0, 100, 100 );
5828     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5829     SetRectRgn( hrgn, 0, 0, 50, 100 );
5830     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
5831     SetRectRgn( hrgn, 50, 0, 100, 100 );
5832     check_update_rgn( hwnd, hrgn );
5833     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5834     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );  /* must not generate messages, everything is valid */
5835     check_update_rgn( hwnd, 0 );
5836
5837     flush_sequence();
5838     SetRectRgn( hrgn, 0, 0, 100, 100 );
5839     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5840     SetRectRgn( hrgn, 0, 0, 100, 50 );
5841     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5842     ok_sequence( WmErase, "Erase", FALSE );
5843     SetRectRgn( hrgn, 0, 50, 100, 100 );
5844     check_update_rgn( hwnd, hrgn );
5845
5846     flush_sequence();
5847     SetRectRgn( hrgn, 0, 0, 100, 100 );
5848     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5849     SetRectRgn( hrgn, 0, 0, 50, 50 );
5850     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
5851     ok_sequence( WmPaint, "Paint", FALSE );
5852
5853     flush_sequence();
5854     SetRectRgn( hrgn, -4, -4, -2, -2 );
5855     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5856     SetRectRgn( hrgn, -200, -200, -198, -198 );
5857     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
5858     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5859
5860     flush_sequence();
5861     SetRectRgn( hrgn, -4, -4, -2, -2 );
5862     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5863     SetRectRgn( hrgn, -4, -4, -3, -3 );
5864     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
5865     SetRectRgn( hrgn, 0, 0, 1, 1 );
5866     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
5867     ok_sequence( WmPaint, "Paint", FALSE );
5868
5869     flush_sequence();
5870     SetRectRgn( hrgn, -4, -4, -1, -1 );
5871     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5872     RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
5873     /* make sure no WM_PAINT was generated */
5874     flush_events();
5875     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5876
5877     flush_sequence();
5878     SetRectRgn( hrgn, -4, -4, -1, -1 );
5879     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5880     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
5881     {
5882         if (msg.hwnd == hwnd && msg.message == WM_PAINT)
5883         {
5884             /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
5885             INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
5886             ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
5887             ret = GetUpdateRect( hwnd, &rect, FALSE );
5888             ok( ret, "Invalid GetUpdateRect result %d\n", ret );
5889             /* this will send WM_NCPAINT and validate the non client area */
5890             ret = GetUpdateRect( hwnd, &rect, TRUE );
5891             ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
5892         }
5893         DispatchMessage( &msg );
5894     }
5895     ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
5896
5897     DestroyWindow( hwnd );
5898
5899     /* now test with a child window */
5900
5901     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
5902                               100, 100, 200, 200, 0, 0, 0, NULL);
5903     ok (hparent != 0, "Failed to create parent window\n");
5904
5905     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
5906                            10, 10, 100, 100, hparent, 0, 0, NULL);
5907     ok (hchild != 0, "Failed to create child window\n");
5908
5909     ShowWindow( hparent, SW_SHOW );
5910     UpdateWindow( hparent );
5911     UpdateWindow( hchild );
5912     flush_events();
5913     flush_sequence();
5914     log_all_parent_messages++;
5915
5916     SetRect( &rect, 0, 0, 50, 50 );
5917     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5918     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5919     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
5920
5921     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5922     pt.x = pt.y = 0;
5923     MapWindowPoints( hchild, hparent, &pt, 1 );
5924     SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
5925     check_update_rgn( hchild, hrgn );
5926     SetRectRgn( hrgn, 0, 0, 50, 50 );
5927     check_update_rgn( hparent, hrgn );
5928     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5929     ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
5930     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5931     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5932
5933     flush_events();
5934     ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
5935
5936     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5937     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5938     ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
5939     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5940     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5941
5942     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
5943     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5944     ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
5945
5946     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
5947     flush_sequence();
5948     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5949     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5950     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
5951
5952     /* flush all paint messages */
5953     flush_events();
5954     flush_sequence();
5955
5956     /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
5957     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5958     SetRectRgn( hrgn, 0, 0, 50, 50 );
5959     check_update_rgn( hparent, hrgn );
5960     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5961     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5962     SetRectRgn( hrgn, 0, 0, 50, 50 );
5963     check_update_rgn( hparent, hrgn );
5964
5965     /* flush all paint messages */
5966     flush_events();
5967     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
5968     flush_sequence();
5969
5970     /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
5971     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5972     SetRectRgn( hrgn, 0, 0, 50, 50 );
5973     check_update_rgn( hparent, hrgn );
5974     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5975     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5976     SetRectRgn( hrgn2, 10, 10, 50, 50 );
5977     CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
5978     check_update_rgn( hparent, hrgn );
5979     /* flush all paint messages */
5980     flush_events();
5981     flush_sequence();
5982
5983     /* same as above but parent gets completely validated */
5984     SetRect( &rect, 20, 20, 30, 30 );
5985     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5986     SetRectRgn( hrgn, 20, 20, 30, 30 );
5987     check_update_rgn( hparent, hrgn );
5988     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5989     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5990     check_update_rgn( hparent, 0 );  /* no update region */
5991     flush_events();
5992     ok_sequence( WmEmptySeq, "WmEmpty", FALSE );  /* and no paint messages */
5993
5994     /* make sure RDW_VALIDATE on child doesn't have the same effect */
5995     flush_sequence();
5996     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5997     SetRectRgn( hrgn, 20, 20, 30, 30 );
5998     check_update_rgn( hparent, hrgn );
5999     RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
6000     SetRectRgn( hrgn, 20, 20, 30, 30 );
6001     check_update_rgn( hparent, hrgn );
6002
6003     /* same as above but normal WM_PAINT doesn't validate parent */
6004     flush_sequence();
6005     SetRect( &rect, 20, 20, 30, 30 );
6006     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6007     SetRectRgn( hrgn, 20, 20, 30, 30 );
6008     check_update_rgn( hparent, hrgn );
6009     /* no WM_PAINT in child while parent still pending */
6010     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6011     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6012     while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6013     ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
6014
6015     flush_sequence();
6016     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6017     /* no WM_PAINT in child while parent still pending */
6018     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6019     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6020     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
6021     /* now that parent is valid child should get WM_PAINT */
6022     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6023     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6024     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6025     ok_sequence( WmEmptySeq, "No other message", FALSE );
6026
6027     /* same thing with WS_CLIPCHILDREN in parent */
6028     flush_sequence();
6029     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6030     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6031     /* changing style invalidates non client area, but we need to invalidate something else to see it */
6032     RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
6033     ok_sequence( WmEmptySeq, "No message", FALSE );
6034     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
6035     ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
6036
6037     flush_sequence();
6038     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
6039     SetRectRgn( hrgn, 20, 20, 30, 30 );
6040     check_update_rgn( hparent, hrgn );
6041     /* no WM_PAINT in child while parent still pending */
6042     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6043     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6044     /* WM_PAINT in parent first */
6045     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6046     ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
6047
6048     /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
6049     flush_sequence();
6050     SetRect( &rect, 0, 0, 30, 30 );
6051     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
6052     SetRectRgn( hrgn, 0, 0, 30, 30 );
6053     check_update_rgn( hparent, hrgn );
6054     flush_events();
6055     ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
6056
6057     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6058     flush_sequence();
6059     SetRect( &rect, -10, 0, 30, 30 );
6060     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6061     SetRect( &rect, 0, 0, 20, 20 );
6062     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6063     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6064     ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
6065
6066     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6067     flush_sequence();
6068     SetRect( &rect, -10, 0, 30, 30 );
6069     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6070     SetRect( &rect, 0, 0, 100, 100 );
6071     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6072     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6073     ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
6074     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6075     ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
6076
6077     /* test RDW_INTERNALPAINT behavior */
6078
6079     flush_sequence();
6080     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
6081     flush_events();
6082     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6083
6084     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
6085     flush_events();
6086     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6087
6088     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6089     flush_events();
6090     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6091
6092     assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
6093     UpdateWindow( hparent );
6094     flush_events();
6095     flush_sequence();
6096     trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
6097     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6098     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6099                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6100     flush_events();
6101     ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
6102
6103     UpdateWindow( hparent );
6104     flush_events();
6105     flush_sequence();
6106     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
6107     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6108     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6109                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6110     flush_events();
6111     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6112
6113     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6114     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6115     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6116     flush_events();
6117     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6118
6119     assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
6120     UpdateWindow( hparent );
6121     flush_events();
6122     flush_sequence();
6123     trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
6124     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6125     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6126                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6127     flush_events();
6128     ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
6129
6130     UpdateWindow( hparent );
6131     flush_events();
6132     flush_sequence();
6133     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
6134     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6135     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6136                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6137     flush_events();
6138     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6139
6140     ok(GetWindowLong( hparent, GWL_STYLE ) & WS_VISIBLE, "parent should be visible\n");
6141     ok(GetWindowLong( hchild, GWL_STYLE ) & WS_VISIBLE, "child should be visible\n");
6142
6143     UpdateWindow( hparent );
6144     flush_events();
6145     flush_sequence();
6146     trace("testing SetWindowPos(-10000, -10000) on child\n");
6147     SetWindowPos( hchild, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6148     check_update_rgn( hchild, 0 );
6149     flush_events();
6150
6151 #if 0 /* this one doesn't pass under Wine yet */
6152     UpdateWindow( hparent );
6153     flush_events();
6154     flush_sequence();
6155     trace("testing ShowWindow(SW_MINIMIZE) on child\n");
6156     ShowWindow( hchild, SW_MINIMIZE );
6157     check_update_rgn( hchild, 0 );
6158     flush_events();
6159 #endif
6160
6161     UpdateWindow( hparent );
6162     flush_events();
6163     flush_sequence();
6164     trace("testing SetWindowPos(-10000, -10000) on parent\n");
6165     SetWindowPos( hparent, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6166     check_update_rgn( hparent, 0 );
6167     flush_events();
6168
6169     log_all_parent_messages--;
6170     DestroyWindow( hparent );
6171     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6172
6173     /* tests for moving windows off-screen (needs simple WS_POPUP windows) */
6174
6175     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_POPUP | WS_VISIBLE,
6176                               100, 100, 200, 200, 0, 0, 0, NULL);
6177     ok (hparent != 0, "Failed to create parent window\n");
6178
6179     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
6180                            10, 10, 100, 100, hparent, 0, 0, NULL);
6181     ok (hchild != 0, "Failed to create child window\n");
6182
6183     ShowWindow( hparent, SW_SHOW );
6184     UpdateWindow( hparent );
6185     UpdateWindow( hchild );
6186     flush_events();
6187     flush_sequence();
6188
6189     /* moving child outside of parent boundaries changes update region */
6190     SetRect( &rect, 0, 0, 40, 40 );
6191     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6192     SetRectRgn( hrgn, 0, 0, 40, 40 );
6193     check_update_rgn( hchild, hrgn );
6194     MoveWindow( hchild, -10, 10, 100, 100, FALSE );
6195     SetRectRgn( hrgn, 10, 0, 40, 40 );
6196     check_update_rgn( hchild, hrgn );
6197     MoveWindow( hchild, -10, -10, 100, 100, FALSE );
6198     SetRectRgn( hrgn, 10, 10, 40, 40 );
6199     check_update_rgn( hchild, hrgn );
6200
6201     /* moving parent off-screen does too */
6202     SetRect( &rect, 0, 0, 100, 100 );
6203     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
6204     SetRectRgn( hrgn, 0, 0, 100, 100 );
6205     check_update_rgn( hparent, hrgn );
6206     SetRectRgn( hrgn, 10, 10, 40, 40 );
6207     check_update_rgn( hchild, hrgn );
6208     MoveWindow( hparent, -20, -20, 200, 200, FALSE );
6209     SetRectRgn( hrgn, 20, 20, 100, 100 );
6210     check_update_rgn( hparent, hrgn );
6211     SetRectRgn( hrgn, 30, 30, 40, 40 );
6212     check_update_rgn( hchild, hrgn );
6213
6214     /* invalidated region is cropped by the parent rects */
6215     SetRect( &rect, 0, 0, 50, 50 );
6216     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6217     SetRectRgn( hrgn, 30, 30, 50, 50 );
6218     check_update_rgn( hchild, hrgn );
6219
6220     DestroyWindow( hparent );
6221     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6222     flush_sequence();
6223
6224     DeleteObject( hrgn );
6225     DeleteObject( hrgn2 );
6226 }
6227
6228 struct wnd_event
6229 {
6230     HWND hwnd;
6231     HANDLE event;
6232 };
6233
6234 static DWORD WINAPI thread_proc(void *param)
6235 {
6236     MSG msg;
6237     struct wnd_event *wnd_event = (struct wnd_event *)param;
6238
6239     wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
6240                                       100, 100, 200, 200, 0, 0, 0, NULL);
6241     ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
6242
6243     SetEvent(wnd_event->event);
6244
6245     while (GetMessage(&msg, 0, 0, 0))
6246     {
6247         TranslateMessage(&msg);
6248         DispatchMessage(&msg);
6249     }
6250
6251     ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
6252
6253     return 0;
6254 }
6255
6256 static void test_interthread_messages(void)
6257 {
6258     HANDLE hThread;
6259     DWORD tid;
6260     WNDPROC proc;
6261     MSG msg;
6262     char buf[256];
6263     int len, expected_len;
6264     struct wnd_event wnd_event;
6265     BOOL ret;
6266
6267     wnd_event.event = CreateEventW(NULL, 0, 0, NULL);
6268     if (!wnd_event.event)
6269     {
6270         trace("skipping interthread message test under win9x\n");
6271         return;
6272     }
6273
6274     hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
6275     ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
6276
6277     ok(WaitForSingleObject(wnd_event.event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6278
6279     CloseHandle(wnd_event.event);
6280
6281     SetLastError(0xdeadbeef);
6282     ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
6283     ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
6284        "wrong error code %d\n", GetLastError());
6285
6286     proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6287     ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
6288
6289     expected_len = lstrlenA("window caption text");
6290     memset(buf, 0, sizeof(buf));
6291     SetLastError(0xdeadbeef);
6292     len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
6293     ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
6294     ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
6295
6296     msg.hwnd = wnd_event.hwnd;
6297     msg.message = WM_GETTEXT;
6298     msg.wParam = sizeof(buf);
6299     msg.lParam = (LPARAM)buf;
6300     memset(buf, 0, sizeof(buf));
6301     SetLastError(0xdeadbeef);
6302     len = DispatchMessageA(&msg);
6303     ok((!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY) || broken(len), /* nt4 */
6304        "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
6305
6306     /* the following test causes an exception in user.exe under win9x */
6307     msg.hwnd = wnd_event.hwnd;
6308     msg.message = WM_TIMER;
6309     msg.wParam = 0;
6310     msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6311     SetLastError(0xdeadbeef);
6312     len = DispatchMessageA(&msg);
6313     ok(!len && GetLastError() == 0xdeadbeef,
6314        "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
6315
6316     ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
6317     ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
6318
6319     ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6320     CloseHandle(hThread);
6321
6322     ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
6323 }
6324
6325
6326 static const struct message WmVkN[] = {
6327     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6328     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6329     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6330     { WM_CHAR, wparam|lparam, 'n', 1 },
6331     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
6332     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6333     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6334     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6335     { 0 }
6336 };
6337 static const struct message WmShiftVkN[] = {
6338     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6339     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6340     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6341     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6342     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6343     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6344     { WM_CHAR, wparam|lparam, 'N', 1 },
6345     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
6346     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6347     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6348     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6349     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6350     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6351     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6352     { 0 }
6353 };
6354 static const struct message WmCtrlVkN[] = {
6355     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6356     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6357     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6358     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6359     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6360     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6361     { WM_CHAR, wparam|lparam, 0x000e, 1 },
6362     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6363     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6364     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6365     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6366     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6367     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6368     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6369     { 0 }
6370 };
6371 static const struct message WmCtrlVkN_2[] = {
6372     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6373     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6374     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6375     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6376     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6377     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6378     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6379     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6380     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6381     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6382     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6383     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6384     { 0 }
6385 };
6386 static const struct message WmAltVkN[] = {
6387     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6388     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6389     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6390     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6391     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6392     { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6393     { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
6394     { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
6395     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
6396     { HCBT_SYSCOMMAND, hook },
6397     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6398     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6399     { 0x00AE, sent|defwinproc|optional }, /* XP */
6400     { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
6401     { WM_INITMENU, sent|defwinproc },
6402     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6403     { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
6404     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
6405     { WM_CAPTURECHANGED, sent|defwinproc },
6406     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
6407     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6408     { WM_EXITMENULOOP, sent|defwinproc },
6409     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
6410     { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
6411     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6412     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6413     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6414     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6415     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6416     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6417     { 0 }
6418 };
6419 static const struct message WmAltVkN_2[] = {
6420     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6421     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6422     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6423     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6424     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6425     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
6426     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6427     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6428     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6429     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6430     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6431     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6432     { 0 }
6433 };
6434 static const struct message WmCtrlAltVkN[] = {
6435     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6436     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6437     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6438     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6439     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6440     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6441     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6442     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6443     { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6444     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6445     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6446     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6447     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6448     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6449     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6450     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6451     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6452     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6453     { 0 }
6454 };
6455 static const struct message WmCtrlShiftVkN[] = {
6456     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6457     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6458     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6459     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6460     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6461     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6462     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6463     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6464     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
6465     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6466     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6467     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6468     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6469     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6470     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6471     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6472     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6473     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6474     { 0 }
6475 };
6476 static const struct message WmCtrlAltShiftVkN[] = {
6477     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6478     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6479     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6480     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6481     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6482     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6483     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
6484     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
6485     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
6486     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6487     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6488     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
6489     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6490     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6491     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6492     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
6493     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
6494     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
6495     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6496     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6497     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6498     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6499     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6500     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6501     { 0 }
6502 };
6503 static const struct message WmAltPressRelease[] = {
6504     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6505     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6506     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6507     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6508     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6509     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6510     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
6511     { HCBT_SYSCOMMAND, hook },
6512     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6513     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6514     { WM_INITMENU, sent|defwinproc },
6515     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6516     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6517     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6518
6519     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
6520
6521     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6522     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
6523     { WM_CAPTURECHANGED, sent|defwinproc },
6524     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
6525     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6526     { WM_EXITMENULOOP, sent|defwinproc },
6527     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6528     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6529     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6530     { 0 }
6531 };
6532 static const struct message WmAltMouseButton[] = {
6533     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6534     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6535     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6536     { WM_MOUSEMOVE, wparam|optional, 0, 0 },
6537     { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
6538     { WM_LBUTTONDOWN, wparam, MK_LBUTTON, 0 },
6539     { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON, 0 },
6540     { WM_LBUTTONUP, wparam, 0, 0 },
6541     { WM_LBUTTONUP, sent|wparam, 0, 0 },
6542     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6543     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6544     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6545     { 0 }
6546 };
6547 static const struct message WmF1Seq[] = {
6548     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
6549     { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
6550     { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
6551     { WM_KEYF1, wparam|lparam, 0, 0 },
6552     { WM_KEYF1, sent|wparam|lparam, 0, 0 },
6553     { WM_HELP, sent|defwinproc },
6554     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
6555     { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
6556     { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
6557     { 0 }
6558 };
6559 static const struct message WmVkAppsSeq[] = {
6560     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
6561     { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
6562     { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
6563     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
6564     { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
6565     { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
6566     { WM_CONTEXTMENU, lparam, /*hwnd*/0, (LPARAM)-1 },
6567     { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, (LPARAM)-1 },
6568     { 0 }
6569 };
6570
6571 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
6572 {
6573     MSG msg;
6574
6575     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
6576     {
6577         struct recvd_message log_msg;
6578
6579         /* ignore some unwanted messages */
6580         if (msg.message == WM_MOUSEMOVE ||
6581             msg.message == WM_GETICON ||
6582             msg.message == WM_GETOBJECT ||
6583             msg.message == WM_TIMER ||
6584             msg.message == WM_DEVICECHANGE)
6585             continue;
6586
6587         log_msg.hwnd = msg.hwnd;
6588         log_msg.message = msg.message;
6589         log_msg.flags = wparam|lparam;
6590         log_msg.wParam = msg.wParam;
6591         log_msg.lParam = msg.lParam;
6592         log_msg.descr = "accel";
6593         add_message(&log_msg);
6594
6595         if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
6596         {
6597             TranslateMessage(&msg);
6598             DispatchMessage(&msg);
6599         }
6600     }
6601 }
6602
6603 static void test_accelerators(void)
6604 {
6605     RECT rc;
6606     SHORT state;
6607     HACCEL hAccel;
6608     HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6609                                 100, 100, 200, 200, 0, 0, 0, NULL);
6610     BOOL ret;
6611
6612     assert(hwnd != 0);
6613     UpdateWindow(hwnd);
6614     flush_events();
6615     flush_sequence();
6616
6617     SetFocus(hwnd);
6618     ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
6619
6620     state = GetKeyState(VK_SHIFT);
6621     ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
6622     state = GetKeyState(VK_CAPITAL);
6623     ok(state == 0, "wrong CapsLock state %04x\n", state);
6624
6625     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
6626     assert(hAccel != 0);
6627
6628     flush_events();
6629     pump_msg_loop(hwnd, 0);
6630     flush_sequence();
6631
6632     trace("testing VK_N press/release\n");
6633     flush_sequence();
6634     keybd_event('N', 0, 0, 0);
6635     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6636     pump_msg_loop(hwnd, hAccel);
6637     ok_sequence(WmVkN, "VK_N press/release", FALSE);
6638
6639     trace("testing Shift+VK_N press/release\n");
6640     flush_sequence();
6641     keybd_event(VK_SHIFT, 0, 0, 0);
6642     keybd_event('N', 0, 0, 0);
6643     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6644     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6645     pump_msg_loop(hwnd, hAccel);
6646     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6647
6648     trace("testing Ctrl+VK_N press/release\n");
6649     flush_sequence();
6650     keybd_event(VK_CONTROL, 0, 0, 0);
6651     keybd_event('N', 0, 0, 0);
6652     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6653     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6654     pump_msg_loop(hwnd, hAccel);
6655     ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
6656
6657     trace("testing Alt+VK_N press/release\n");
6658     flush_sequence();
6659     keybd_event(VK_MENU, 0, 0, 0);
6660     keybd_event('N', 0, 0, 0);
6661     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6662     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6663     pump_msg_loop(hwnd, hAccel);
6664     ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
6665
6666     trace("testing Ctrl+Alt+VK_N press/release 1\n");
6667     flush_sequence();
6668     keybd_event(VK_CONTROL, 0, 0, 0);
6669     keybd_event(VK_MENU, 0, 0, 0);
6670     keybd_event('N', 0, 0, 0);
6671     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6672     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6673     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6674     pump_msg_loop(hwnd, hAccel);
6675     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
6676
6677     ret = DestroyAcceleratorTable(hAccel);
6678     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6679
6680     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
6681     assert(hAccel != 0);
6682
6683     trace("testing VK_N press/release\n");
6684     flush_sequence();
6685     keybd_event('N', 0, 0, 0);
6686     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6687     pump_msg_loop(hwnd, hAccel);
6688     ok_sequence(WmVkN, "VK_N press/release", FALSE);
6689
6690     trace("testing Shift+VK_N press/release\n");
6691     flush_sequence();
6692     keybd_event(VK_SHIFT, 0, 0, 0);
6693     keybd_event('N', 0, 0, 0);
6694     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6695     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6696     pump_msg_loop(hwnd, hAccel);
6697     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6698
6699     trace("testing Ctrl+VK_N press/release 2\n");
6700     flush_sequence();
6701     keybd_event(VK_CONTROL, 0, 0, 0);
6702     keybd_event('N', 0, 0, 0);
6703     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6704     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6705     pump_msg_loop(hwnd, hAccel);
6706     ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
6707
6708     trace("testing Alt+VK_N press/release 2\n");
6709     flush_sequence();
6710     keybd_event(VK_MENU, 0, 0, 0);
6711     keybd_event('N', 0, 0, 0);
6712     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6713     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6714     pump_msg_loop(hwnd, hAccel);
6715     ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
6716
6717     trace("testing Ctrl+Alt+VK_N press/release 2\n");
6718     flush_sequence();
6719     keybd_event(VK_CONTROL, 0, 0, 0);
6720     keybd_event(VK_MENU, 0, 0, 0);
6721     keybd_event('N', 0, 0, 0);
6722     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6723     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6724     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6725     pump_msg_loop(hwnd, hAccel);
6726     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
6727
6728     trace("testing Ctrl+Shift+VK_N press/release\n");
6729     flush_sequence();
6730     keybd_event(VK_CONTROL, 0, 0, 0);
6731     keybd_event(VK_SHIFT, 0, 0, 0);
6732     keybd_event('N', 0, 0, 0);
6733     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6734     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6735     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6736     pump_msg_loop(hwnd, hAccel);
6737     ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
6738
6739     trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
6740     flush_sequence();
6741     keybd_event(VK_CONTROL, 0, 0, 0);
6742     keybd_event(VK_MENU, 0, 0, 0);
6743     keybd_event(VK_SHIFT, 0, 0, 0);
6744     keybd_event('N', 0, 0, 0);
6745     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6746     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6747     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6748     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6749     pump_msg_loop(hwnd, hAccel);
6750     ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
6751
6752     ret = DestroyAcceleratorTable(hAccel);
6753     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6754
6755     trace("testing Alt press/release\n");
6756     flush_sequence();
6757     keybd_event(VK_MENU, 0, 0, 0);
6758     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6759     keybd_event(VK_MENU, 0, 0, 0);
6760     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6761     pump_msg_loop(hwnd, 0);
6762     /* this test doesn't pass in Wine for managed windows */
6763     ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
6764
6765     trace("testing Alt+MouseButton press/release\n");
6766     /* first, move mouse pointer inside of the window client area */
6767     GetClientRect(hwnd, &rc);
6768     MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
6769     rc.left += (rc.right - rc.left)/2;
6770     rc.top += (rc.bottom - rc.top)/2;
6771     SetCursorPos(rc.left, rc.top);
6772
6773     flush_events();
6774     flush_sequence();
6775     keybd_event(VK_MENU, 0, 0, 0);
6776     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
6777     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
6778     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6779     pump_msg_loop(hwnd, 0);
6780     ok_sequence(WmAltMouseButton, "Alt+MouseButton press/release", FALSE);
6781
6782     trace("testing VK_F1 press/release\n");
6783     keybd_event(VK_F1, 0, 0, 0);
6784     keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
6785     pump_msg_loop(hwnd, 0);
6786     ok_sequence(WmF1Seq, "F1 press/release", FALSE);
6787
6788     trace("testing VK_APPS press/release\n");
6789     keybd_event(VK_APPS, 0, 0, 0);
6790     keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
6791     pump_msg_loop(hwnd, 0);
6792     ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
6793
6794     DestroyWindow(hwnd);
6795 }
6796
6797 /************* window procedures ********************/
6798
6799 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message, 
6800                              WPARAM wParam, LPARAM lParam)
6801 {
6802     static long defwndproc_counter = 0;
6803     static long beginpaint_counter = 0;
6804     LRESULT ret;
6805     struct recvd_message msg;
6806
6807     /* ignore registered messages */
6808     if (message >= 0xc000) return 0;
6809
6810     switch (message)
6811     {
6812         case WM_ENABLE:
6813         {
6814             LONG style = GetWindowLongA(hwnd, GWL_STYLE);
6815             ok((BOOL)wParam == !(style & WS_DISABLED),
6816                 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
6817             break;
6818         }
6819
6820         case WM_CAPTURECHANGED:
6821             if (test_DestroyWindow_flag)
6822             {
6823                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6824                 if (style & WS_CHILD)
6825                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6826                 else if (style & WS_POPUP)
6827                     lParam = WND_POPUP_ID;
6828                 else
6829                     lParam = WND_PARENT_ID;
6830             }
6831             break;
6832
6833         case WM_NCDESTROY:
6834         {
6835             HWND capture;
6836
6837             ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
6838             capture = GetCapture();
6839             if (capture)
6840             {
6841                 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
6842                 trace("current capture %p, releasing...\n", capture);
6843                 ReleaseCapture();
6844             }
6845         }
6846         /* fall through */
6847         case WM_DESTROY:
6848             if (pGetAncestor)
6849                 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
6850             if (test_DestroyWindow_flag)
6851             {
6852                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6853                 if (style & WS_CHILD)
6854                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6855                 else if (style & WS_POPUP)
6856                     lParam = WND_POPUP_ID;
6857                 else
6858                     lParam = WND_PARENT_ID;
6859             }
6860             break;
6861
6862         /* test_accelerators() depends on this */
6863         case WM_NCHITTEST:
6864             return HTCLIENT;
6865
6866         /* ignore */
6867         case WM_MOUSEMOVE:
6868         case WM_MOUSEACTIVATE:
6869         case WM_NCMOUSEMOVE:
6870         case WM_SETCURSOR:
6871         case WM_GETICON:
6872         case WM_GETOBJECT:
6873         case WM_DEVICECHANGE:
6874             return 0;
6875     }
6876
6877     msg.hwnd = hwnd;
6878     msg.message = message;
6879     msg.flags = sent|wparam|lparam;
6880     if (defwndproc_counter) msg.flags |= defwinproc;
6881     if (beginpaint_counter) msg.flags |= beginpaint;
6882     msg.wParam = wParam;
6883     msg.lParam = lParam;
6884     msg.descr = "MsgCheckProc";
6885     add_message(&msg);
6886
6887     if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
6888     {
6889         HWND parent = GetParent(hwnd);
6890         RECT rc;
6891         MINMAXINFO *minmax = (MINMAXINFO *)lParam;
6892
6893         GetClientRect(parent, &rc);
6894         trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
6895         trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
6896               minmax->ptReserved.x, minmax->ptReserved.y,
6897               minmax->ptMaxSize.x, minmax->ptMaxSize.y,
6898               minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
6899               minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
6900               minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
6901
6902         ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
6903            minmax->ptMaxSize.x, rc.right);
6904         ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
6905            minmax->ptMaxSize.y, rc.bottom);
6906     }
6907
6908     if (message == WM_PAINT)
6909     {
6910         PAINTSTRUCT ps;
6911         beginpaint_counter++;
6912         BeginPaint( hwnd, &ps );
6913         beginpaint_counter--;
6914         EndPaint( hwnd, &ps );
6915         return 0;
6916     }
6917
6918     defwndproc_counter++;
6919     ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam) 
6920                   : DefWindowProcA(hwnd, message, wParam, lParam);
6921     defwndproc_counter--;
6922
6923     return ret;
6924 }
6925
6926 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6927 {
6928     return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
6929 }
6930
6931 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6932 {
6933     return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
6934 }
6935
6936 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6937 {
6938     static long defwndproc_counter = 0;
6939     LRESULT ret;
6940     struct recvd_message msg;
6941
6942     switch (message)
6943     {
6944     case WM_GETICON:
6945     case WM_GETOBJECT:
6946         return 0;  /* ignore them */
6947     case WM_QUERYENDSESSION:
6948     case WM_ENDSESSION:
6949         lParam &= ~0x01;  /* Vista adds a 0x01 flag */
6950         break;
6951     }
6952
6953     msg.hwnd = hwnd;
6954     msg.message = message;
6955     msg.flags = sent|wparam|lparam;
6956     if (defwndproc_counter) msg.flags |= defwinproc;
6957     msg.wParam = wParam;
6958     msg.lParam = lParam;
6959     msg.descr = "popup";
6960     add_message(&msg);
6961
6962     if (message == WM_CREATE)
6963     {
6964         DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
6965         SetWindowLongA(hwnd, GWL_STYLE, style);
6966     }
6967
6968     defwndproc_counter++;
6969     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6970     defwndproc_counter--;
6971
6972     return ret;
6973 }
6974
6975 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6976 {
6977     static long defwndproc_counter = 0;
6978     static long beginpaint_counter = 0;
6979     LRESULT ret;
6980     struct recvd_message msg;
6981
6982     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
6983
6984     /* ignore registered messages */
6985     if (message >= 0xc000) return 0;
6986
6987     if (log_all_parent_messages ||
6988         message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
6989         message == WM_SETFOCUS || message == WM_KILLFOCUS ||
6990         message == WM_ENABLE || message == WM_ENTERIDLE ||
6991         message == WM_DRAWITEM ||
6992         message == WM_IME_SETCONTEXT)
6993     {
6994         switch (message)
6995         {
6996             /* ignore */
6997             case WM_NCHITTEST:
6998                 return HTCLIENT;
6999             case WM_SETCURSOR:
7000             case WM_MOUSEMOVE:
7001                 return 0;
7002
7003             case WM_ERASEBKGND:
7004             {
7005                 RECT rc;
7006                 INT ret = GetClipBox((HDC)wParam, &rc);
7007
7008                 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
7009                        ret, rc.left, rc.top, rc.right, rc.bottom);
7010                 break;
7011             }
7012         }
7013
7014         msg.hwnd = hwnd;
7015         msg.message = message;
7016         msg.flags = sent|parent|wparam|lparam;
7017         if (defwndproc_counter) msg.flags |= defwinproc;
7018         if (beginpaint_counter) msg.flags |= beginpaint;
7019         msg.wParam = wParam;
7020         msg.lParam = lParam;
7021         msg.descr = "parent";
7022         add_message(&msg);
7023     }
7024
7025     if (message == WM_PAINT)
7026     {
7027         PAINTSTRUCT ps;
7028         beginpaint_counter++;
7029         BeginPaint( hwnd, &ps );
7030         beginpaint_counter--;
7031         EndPaint( hwnd, &ps );
7032         return 0;
7033     }
7034
7035     defwndproc_counter++;
7036     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7037     defwndproc_counter--;
7038
7039     return ret;
7040 }
7041
7042 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7043 {
7044     static long defwndproc_counter = 0;
7045     LRESULT ret;
7046     struct recvd_message msg;
7047
7048     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
7049
7050     if (test_def_id)
7051     {
7052         DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
7053         ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
7054         if (after_end_dialog)
7055             ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
7056         else
7057             ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
7058     }
7059
7060     msg.hwnd = hwnd;
7061     msg.message = message;
7062     msg.flags = sent|wparam|lparam;
7063     if (defwndproc_counter) msg.flags |= defwinproc;
7064     msg.wParam = wParam;
7065     msg.lParam = lParam;
7066     msg.descr = "dialog";
7067     add_message(&msg);
7068
7069     defwndproc_counter++;
7070     ret = DefDlgProcA(hwnd, message, wParam, lParam);
7071     defwndproc_counter--;
7072
7073     return ret;
7074 }
7075
7076 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7077 {
7078     static long defwndproc_counter = 0;
7079     LRESULT ret;
7080     struct recvd_message msg;
7081
7082     /* log only specific messages we are interested in */
7083     switch (message)
7084     {
7085 #if 0 /* probably log these as well */
7086     case WM_ACTIVATE:
7087     case WM_SETFOCUS:
7088     case WM_KILLFOCUS:
7089 #endif
7090     case WM_SHOWWINDOW:
7091     case WM_SIZE:
7092     case WM_MOVE:
7093     case WM_GETMINMAXINFO:
7094     case WM_WINDOWPOSCHANGING:
7095     case WM_WINDOWPOSCHANGED:
7096         break;
7097
7098     default: /* ignore */
7099         /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
7100         return DefWindowProcA(hwnd, message, wParam, lParam);
7101     }
7102
7103     msg.hwnd = hwnd;
7104     msg.message = message;
7105     msg.flags = sent|wparam|lparam;
7106     if (defwndproc_counter) msg.flags |= defwinproc;
7107     msg.wParam = wParam;
7108     msg.lParam = lParam;
7109     msg.descr = "show";
7110     add_message(&msg);
7111
7112     defwndproc_counter++;
7113     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7114     defwndproc_counter--;
7115
7116     return ret;
7117 }
7118
7119 static LRESULT WINAPI PaintLoopProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
7120 {
7121     switch (msg)
7122     {
7123         case WM_CREATE: return 0;
7124         case WM_PAINT:
7125         {
7126             MSG msg2;
7127             static int i = 0;
7128
7129             if (i < 256)
7130             {
7131                 i++;
7132                 if (PeekMessageA(&msg2, 0, 0, 0, 1))
7133                 {
7134                     TranslateMessage(&msg2);
7135                     DispatchMessage(&msg2);
7136                 }
7137                 i--;
7138             }
7139             else ok(broken(1), "infinite loop\n");
7140             if ( i == 0)
7141                 paint_loop_done = 1;
7142             return DefWindowProcA(hWnd,msg,wParam,lParam);
7143         }
7144     }
7145     return DefWindowProcA(hWnd,msg,wParam,lParam);
7146 }
7147
7148 static BOOL RegisterWindowClasses(void)
7149 {
7150     WNDCLASSA cls;
7151     WNDCLASSW clsW;
7152
7153     cls.style = 0;
7154     cls.lpfnWndProc = MsgCheckProcA;
7155     cls.cbClsExtra = 0;
7156     cls.cbWndExtra = 0;
7157     cls.hInstance = GetModuleHandleA(0);
7158     cls.hIcon = 0;
7159     cls.hCursor = LoadCursorA(0, IDC_ARROW);
7160     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7161     cls.lpszMenuName = NULL;
7162     cls.lpszClassName = "TestWindowClass";
7163     if(!RegisterClassA(&cls)) return FALSE;
7164
7165     cls.lpfnWndProc = ShowWindowProcA;
7166     cls.lpszClassName = "ShowWindowClass";
7167     if(!RegisterClassA(&cls)) return FALSE;
7168
7169     cls.lpfnWndProc = PopupMsgCheckProcA;
7170     cls.lpszClassName = "TestPopupClass";
7171     if(!RegisterClassA(&cls)) return FALSE;
7172
7173     cls.lpfnWndProc = ParentMsgCheckProcA;
7174     cls.lpszClassName = "TestParentClass";
7175     if(!RegisterClassA(&cls)) return FALSE;
7176
7177     cls.lpfnWndProc = DefWindowProcA;
7178     cls.lpszClassName = "SimpleWindowClass";
7179     if(!RegisterClassA(&cls)) return FALSE;
7180
7181     cls.lpfnWndProc = PaintLoopProcA;
7182     cls.lpszClassName = "PaintLoopWindowClass";
7183     if(!RegisterClassA(&cls)) return FALSE;
7184
7185     cls.style = CS_NOCLOSE;
7186     cls.lpszClassName = "NoCloseWindowClass";
7187     if(!RegisterClassA(&cls)) return FALSE;
7188
7189     ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
7190     cls.style = 0;
7191     cls.hInstance = GetModuleHandleA(0);
7192     cls.hbrBackground = 0;
7193     cls.lpfnWndProc = TestDlgProcA;
7194     cls.lpszClassName = "TestDialogClass";
7195     if(!RegisterClassA(&cls)) return FALSE;
7196
7197     clsW.style = 0;
7198     clsW.lpfnWndProc = MsgCheckProcW;
7199     clsW.cbClsExtra = 0;
7200     clsW.cbWndExtra = 0;
7201     clsW.hInstance = GetModuleHandleW(0);
7202     clsW.hIcon = 0;
7203     clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
7204     clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
7205     clsW.lpszMenuName = NULL;
7206     clsW.lpszClassName = testWindowClassW;
7207     RegisterClassW(&clsW);  /* ignore error, this fails on Win9x */
7208
7209     return TRUE;
7210 }
7211
7212 static BOOL is_our_logged_class(HWND hwnd)
7213 {
7214     char buf[256];
7215
7216     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7217     {
7218         if (!lstrcmpiA(buf, "TestWindowClass") ||
7219             !lstrcmpiA(buf, "ShowWindowClass") ||
7220             !lstrcmpiA(buf, "TestParentClass") ||
7221             !lstrcmpiA(buf, "TestPopupClass") ||
7222             !lstrcmpiA(buf, "SimpleWindowClass") ||
7223             !lstrcmpiA(buf, "TestDialogClass") ||
7224             !lstrcmpiA(buf, "MDI_frame_class") ||
7225             !lstrcmpiA(buf, "MDI_client_class") ||
7226             !lstrcmpiA(buf, "MDI_child_class") ||
7227             !lstrcmpiA(buf, "my_button_class") ||
7228             !lstrcmpiA(buf, "my_edit_class") ||
7229             !lstrcmpiA(buf, "static") ||
7230             !lstrcmpiA(buf, "ListBox") ||
7231             !lstrcmpiA(buf, "ComboBox") ||
7232             !lstrcmpiA(buf, "MyDialogClass") ||
7233             !lstrcmpiA(buf, "#32770") ||
7234             !lstrcmpiA(buf, "#32768"))
7235         return TRUE;
7236     }
7237     return FALSE;
7238 }
7239
7240 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7241
7242     HWND hwnd;
7243
7244     ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7245
7246     if (nCode == HCBT_CLICKSKIPPED)
7247     {
7248         /* ignore this event, XP sends it a lot when switching focus between windows */
7249         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7250     }
7251
7252     if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
7253     {
7254         struct recvd_message msg;
7255
7256         msg.hwnd = 0;
7257         msg.message = nCode;
7258         msg.flags = hook|wparam|lparam;
7259         msg.wParam = wParam;
7260         msg.lParam = lParam;
7261         msg.descr = "CBT";
7262         add_message(&msg);
7263
7264         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7265     }
7266
7267     if (nCode == HCBT_DESTROYWND)
7268     {
7269         if (test_DestroyWindow_flag)
7270         {
7271             DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
7272             if (style & WS_CHILD)
7273                 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
7274             else if (style & WS_POPUP)
7275                 lParam = WND_POPUP_ID;
7276             else
7277                 lParam = WND_PARENT_ID;
7278         }
7279     }
7280
7281     /* Log also SetFocus(0) calls */
7282     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7283
7284     if (is_our_logged_class(hwnd))
7285     {
7286         struct recvd_message msg;
7287
7288         msg.hwnd = hwnd;
7289         msg.message = nCode;
7290         msg.flags = hook|wparam|lparam;
7291         msg.wParam = wParam;
7292         msg.lParam = lParam;
7293         msg.descr = "CBT";
7294         add_message(&msg);
7295     }
7296     return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7297 }
7298
7299 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
7300                                     DWORD event,
7301                                     HWND hwnd,
7302                                     LONG object_id,
7303                                     LONG child_id,
7304                                     DWORD thread_id,
7305                                     DWORD event_time)
7306 {
7307     ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7308
7309     /* ignore mouse cursor events */
7310     if (object_id == OBJID_CURSOR) return;
7311
7312     if (!hwnd || is_our_logged_class(hwnd))
7313     {
7314         struct recvd_message msg;
7315
7316         msg.hwnd = hwnd;
7317         msg.message = event;
7318         msg.flags = winevent_hook|wparam|lparam;
7319         msg.wParam = object_id;
7320         msg.lParam = child_id;
7321         msg.descr = "WEH";
7322         add_message(&msg);
7323     }
7324 }
7325
7326 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
7327 static const WCHAR wszAnsi[] = {'U',0};
7328
7329 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
7330 {
7331     switch (uMsg)
7332     {
7333     case CB_FINDSTRINGEXACT:
7334         trace("String: %p\n", (LPCWSTR)lParam);
7335         if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
7336             return 1;
7337         if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
7338             return 0;
7339         return -1;
7340     }
7341     return DefWindowProcW(hwnd, uMsg, wParam, lParam);
7342 }
7343
7344 static const struct message WmGetTextLengthAfromW[] = {
7345     { WM_GETTEXTLENGTH, sent },
7346     { WM_GETTEXT, sent|optional },
7347     { 0 }
7348 };
7349
7350 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
7351
7352 /* dummy window proc for WM_GETTEXTLENGTH test */
7353 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
7354 {
7355     switch(msg)
7356     {
7357     case WM_GETTEXTLENGTH:
7358         return lstrlenW(dummy_window_text) + 37;  /* some random length */
7359     case WM_GETTEXT:
7360         lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
7361         return lstrlenW( (LPWSTR)lp );
7362     default:
7363         return DefWindowProcW( hwnd, msg, wp, lp );
7364     }
7365 }
7366
7367 static void test_message_conversion(void)
7368 {
7369     static const WCHAR wszMsgConversionClass[] =
7370         {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
7371     WNDCLASSW cls;
7372     LRESULT lRes;
7373     HWND hwnd;
7374     WNDPROC wndproc, newproc;
7375     BOOL ret;
7376
7377     cls.style = 0;
7378     cls.lpfnWndProc = MsgConversionProcW;
7379     cls.cbClsExtra = 0;
7380     cls.cbWndExtra = 0;
7381     cls.hInstance = GetModuleHandleW(NULL);
7382     cls.hIcon = NULL;
7383     cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
7384     cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
7385     cls.lpszMenuName = NULL;
7386     cls.lpszClassName = wszMsgConversionClass;
7387     /* this call will fail on Win9x, but that doesn't matter as this test is
7388      * meaningless on those platforms */
7389     if(!RegisterClassW(&cls)) return;
7390
7391     hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
7392                            100, 100, 200, 200, 0, 0, 0, NULL);
7393     ok(hwnd != NULL, "Window creation failed\n");
7394
7395     /* {W, A} -> A */
7396
7397     wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
7398     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7399     ok(lRes == 0, "String should have been converted\n");
7400     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7401     ok(lRes == 1, "String shouldn't have been converted\n");
7402
7403     /* {W, A} -> W */
7404
7405     wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
7406     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7407     ok(lRes == 1, "String shouldn't have been converted\n");
7408     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7409     ok(lRes == 1, "String shouldn't have been converted\n");
7410
7411     /* Synchronous messages */
7412
7413     lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7414     ok(lRes == 0, "String should have been converted\n");
7415     lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7416     ok(lRes == 1, "String shouldn't have been converted\n");
7417
7418     /* Asynchronous messages */
7419
7420     SetLastError(0);
7421     lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7422     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7423         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7424     SetLastError(0);
7425     lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7426     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7427         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7428     SetLastError(0);
7429     lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7430     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7431         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7432     SetLastError(0);
7433     lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7434     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7435         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7436     SetLastError(0);
7437     lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7438     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7439         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7440     SetLastError(0);
7441     lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7442     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7443         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7444     SetLastError(0);
7445     lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7446     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7447         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7448     SetLastError(0);
7449     lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7450     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7451         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7452
7453     /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
7454
7455     hwnd = CreateWindowW (testWindowClassW, wszUnicode,
7456                           WS_OVERLAPPEDWINDOW,
7457                           100, 100, 200, 200, 0, 0, 0, NULL);
7458     assert(hwnd);
7459     flush_sequence();
7460     lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
7461     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7462     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7463         "got bad length %ld\n", lRes );
7464
7465     flush_sequence();
7466     lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
7467                             hwnd, WM_GETTEXTLENGTH, 0, 0);
7468     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7469     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7470         "got bad length %ld\n", lRes );
7471
7472     wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
7473     newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
7474     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7475     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7476                                      NULL, 0, NULL, NULL ) ||
7477         broken(lRes == lstrlenW(dummy_window_text) + 37),
7478         "got bad length %ld\n", lRes );
7479
7480     SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc );  /* restore old wnd proc */
7481     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7482     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7483                                      NULL, 0, NULL, NULL ) ||
7484         broken(lRes == lstrlenW(dummy_window_text) + 37),
7485         "got bad length %ld\n", lRes );
7486
7487     ret = DestroyWindow(hwnd);
7488     ok( ret, "DestroyWindow() error %d\n", GetLastError());
7489 }
7490
7491 struct timer_info
7492 {
7493     HWND hWnd;
7494     HANDLE handles[2];
7495     DWORD id;
7496 };
7497
7498 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
7499 {
7500 }
7501
7502 #define TIMER_ID  0x19
7503
7504 static DWORD WINAPI timer_thread_proc(LPVOID x)
7505 {
7506     struct timer_info *info = x;
7507     DWORD r;
7508
7509     r = KillTimer(info->hWnd, 0x19);
7510     ok(r,"KillTimer failed in thread\n");
7511     r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
7512     ok(r,"SetTimer failed in thread\n");
7513     ok(r==TIMER_ID,"SetTimer id different\n");
7514     r = SetEvent(info->handles[0]);
7515     ok(r,"SetEvent failed in thread\n");
7516     return 0;
7517 }
7518
7519 static void test_timers(void)
7520 {
7521     struct timer_info info;
7522     DWORD id;
7523
7524     info.hWnd = CreateWindow ("TestWindowClass", NULL,
7525        WS_OVERLAPPEDWINDOW ,
7526        CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7527        NULL, NULL, 0);
7528
7529     info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
7530     ok(info.id, "SetTimer failed\n");
7531     ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
7532     info.handles[0] = CreateEvent(NULL,0,0,NULL);
7533     info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
7534
7535     WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
7536
7537     WaitForSingleObject(info.handles[1], INFINITE);
7538
7539     CloseHandle(info.handles[0]);
7540     CloseHandle(info.handles[1]);
7541
7542     ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
7543
7544     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
7545 }
7546
7547 static int count = 0;
7548 static VOID CALLBACK callback_count(
7549     HWND hwnd,
7550     UINT uMsg,
7551     UINT_PTR idEvent,
7552     DWORD dwTime
7553 )
7554 {
7555     count++;
7556 }
7557
7558 static void test_timers_no_wnd(void)
7559 {
7560     UINT_PTR id, id2;
7561     MSG msg;
7562
7563     count = 0;
7564     id = SetTimer(NULL, 0, 100, callback_count);
7565     ok(id != 0, "did not get id from SetTimer.\n");
7566     id2 = SetTimer(NULL, id, 200, callback_count);
7567     ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
7568     Sleep(150);
7569     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7570     ok(count == 0, "did not get zero count as expected (%i).\n", count);
7571     Sleep(150);
7572     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7573     ok(count == 1, "did not get one count as expected (%i).\n", count);
7574     KillTimer(NULL, id);
7575     Sleep(250);
7576     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7577     ok(count == 1, "killing replaced timer did not work (%i).\n", count);
7578 }
7579
7580 /* Various win events with arbitrary parameters */
7581 static const struct message WmWinEventsSeq[] = {
7582     { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7583     { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7584     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7585     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7586     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7587     { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7588     { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7589     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7590     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7591     /* our win event hook ignores OBJID_CURSOR events */
7592     /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
7593     { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
7594     { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
7595     { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
7596     { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
7597     { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7598     { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7599     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7600     { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7601     { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7602     { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7603     { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7604     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7605     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7606     { 0 }
7607 };
7608 static const struct message WmWinEventCaretSeq[] = {
7609     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7610     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7611     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
7612     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7613     { 0 }
7614 };
7615 static const struct message WmWinEventCaretSeq_2[] = {
7616     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7617     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7618     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7619     { 0 }
7620 };
7621 static const struct message WmWinEventAlertSeq[] = {
7622     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
7623     { 0 }
7624 };
7625 static const struct message WmWinEventAlertSeq_2[] = {
7626     /* create window in the thread proc */
7627     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
7628     /* our test event */
7629     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
7630     { 0 }
7631 };
7632 static const struct message WmGlobalHookSeq_1[] = {
7633     /* create window in the thread proc */
7634     { HCBT_CREATEWND, hook|lparam, 0, 2 },
7635     /* our test events */
7636     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
7637     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
7638     { 0 }
7639 };
7640 static const struct message WmGlobalHookSeq_2[] = {
7641     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
7642     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
7643     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
7644     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
7645     { 0 }
7646 };
7647
7648 static const struct message WmMouseLLHookSeq[] = {
7649     { WM_MOUSEMOVE, hook },
7650     { WM_LBUTTONUP, hook },
7651     { WM_MOUSEMOVE, hook },
7652     { 0 }
7653 };
7654
7655 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
7656                                          DWORD event,
7657                                          HWND hwnd,
7658                                          LONG object_id,
7659                                          LONG child_id,
7660                                          DWORD thread_id,
7661                                          DWORD event_time)
7662 {
7663     char buf[256];
7664
7665     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7666     {
7667         if (!lstrcmpiA(buf, "TestWindowClass") ||
7668             !lstrcmpiA(buf, "static"))
7669         {
7670             struct recvd_message msg;
7671
7672             msg.hwnd = hwnd;
7673             msg.message = event;
7674             msg.flags = winevent_hook|wparam|lparam;
7675             msg.wParam = object_id;
7676             msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
7677             msg.descr = "WEH_2";
7678             add_message(&msg);
7679         }
7680     }
7681 }
7682
7683 static HHOOK hCBT_global_hook;
7684 static DWORD cbt_global_hook_thread_id;
7685
7686 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7687
7688     HWND hwnd;
7689     char buf[256];
7690
7691     if (nCode == HCBT_SYSCOMMAND)
7692     {
7693         struct recvd_message msg;
7694
7695         msg.hwnd = 0;
7696         msg.message = nCode;
7697         msg.flags = hook|wparam|lparam;
7698         msg.wParam = wParam;
7699         msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7700         msg.descr = "CBT_2";
7701         add_message(&msg);
7702
7703         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7704     }
7705     /* WH_MOUSE_LL hook */
7706     if (nCode == HC_ACTION)
7707     {
7708         MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
7709
7710         /* we can't test for real mouse events */
7711         if (mhll->flags & LLMHF_INJECTED)
7712         {
7713             struct recvd_message msg;
7714
7715             memset (&msg, 0, sizeof (msg));
7716             msg.message = wParam;
7717             msg.flags = hook;
7718             msg.descr = "CBT_2";
7719             add_message(&msg);
7720         }
7721         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7722     }
7723
7724     /* Log also SetFocus(0) calls */
7725     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7726
7727     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7728     {
7729         if (!lstrcmpiA(buf, "TestWindowClass") ||
7730             !lstrcmpiA(buf, "static"))
7731         {
7732             struct recvd_message msg;
7733
7734             msg.hwnd = hwnd;
7735             msg.message = nCode;
7736             msg.flags = hook|wparam|lparam;
7737             msg.wParam = wParam;
7738             msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7739             msg.descr = "CBT_2";
7740             add_message(&msg);
7741         }
7742     }
7743     return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7744 }
7745
7746 static DWORD WINAPI win_event_global_thread_proc(void *param)
7747 {
7748     HWND hwnd;
7749     MSG msg;
7750     HANDLE hevent = *(HANDLE *)param;
7751
7752     assert(pNotifyWinEvent);
7753
7754     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7755     assert(hwnd);
7756     trace("created thread window %p\n", hwnd);
7757
7758     *(HWND *)param = hwnd;
7759
7760     flush_sequence();
7761     /* this event should be received only by our new hook proc,
7762      * an old one does not expect an event from another thread.
7763      */
7764     pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
7765     SetEvent(hevent);
7766
7767     while (GetMessage(&msg, 0, 0, 0))
7768     {
7769         TranslateMessage(&msg);
7770         DispatchMessage(&msg);
7771     }
7772     return 0;
7773 }
7774
7775 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
7776 {
7777     HWND hwnd;
7778     MSG msg;
7779     HANDLE hevent = *(HANDLE *)param;
7780
7781     flush_sequence();
7782     /* these events should be received only by our new hook proc,
7783      * an old one does not expect an event from another thread.
7784      */
7785
7786     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7787     assert(hwnd);
7788     trace("created thread window %p\n", hwnd);
7789
7790     *(HWND *)param = hwnd;
7791
7792     /* Windows doesn't like when a thread plays games with the focus,
7793        that leads to all kinds of misbehaviours and failures to activate
7794        a window. So, better keep next lines commented out.
7795     SetFocus(0);
7796     SetFocus(hwnd);*/
7797
7798     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7799     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7800
7801     SetEvent(hevent);
7802
7803     while (GetMessage(&msg, 0, 0, 0))
7804     {
7805         TranslateMessage(&msg);
7806         DispatchMessage(&msg);
7807     }
7808     return 0;
7809 }
7810
7811 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
7812 {
7813     HWND hwnd;
7814     MSG msg;
7815     HANDLE hevent = *(HANDLE *)param;
7816
7817     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7818     assert(hwnd);
7819     trace("created thread window %p\n", hwnd);
7820
7821     *(HWND *)param = hwnd;
7822
7823     flush_sequence();
7824
7825     /* Windows doesn't like when a thread plays games with the focus,
7826      * that leads to all kinds of misbehaviours and failures to activate
7827      * a window. So, better don't generate a mouse click message below.
7828      */
7829     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7830     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7831     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7832
7833     SetEvent(hevent);
7834     while (GetMessage(&msg, 0, 0, 0))
7835     {
7836         TranslateMessage(&msg);
7837         DispatchMessage(&msg);
7838     }
7839     return 0;
7840 }
7841
7842 static void test_winevents(void)
7843 {
7844     BOOL ret;
7845     MSG msg;
7846     HWND hwnd, hwnd2;
7847     UINT i;
7848     HANDLE hthread, hevent;
7849     DWORD tid;
7850     HWINEVENTHOOK hhook;
7851     const struct message *events = WmWinEventsSeq;
7852
7853     hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
7854                            WS_OVERLAPPEDWINDOW,
7855                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7856                            NULL, NULL, 0);
7857     assert(hwnd);
7858
7859     /****** start of global hook test *************/
7860     hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7861     if (!hCBT_global_hook)
7862     {
7863         ok(DestroyWindow(hwnd), "failed to destroy window\n");
7864         skip( "cannot set global hook\n" );
7865         return;
7866     }
7867
7868     hevent = CreateEventA(NULL, 0, 0, NULL);
7869     assert(hevent);
7870     hwnd2 = (HWND)hevent;
7871
7872     hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
7873     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7874
7875     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7876
7877     ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
7878
7879     flush_sequence();
7880     /* this one should be received only by old hook proc */
7881     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7882     /* this one should be received only by old hook proc */
7883     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7884
7885     ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
7886
7887     ret = UnhookWindowsHookEx(hCBT_global_hook);
7888     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7889
7890     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7891     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7892     CloseHandle(hthread);
7893     CloseHandle(hevent);
7894     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7895     /****** end of global hook test *************/
7896
7897     if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
7898     {
7899         ok(DestroyWindow(hwnd), "failed to destroy window\n");
7900         return;
7901     }
7902
7903     flush_sequence();
7904
7905     if (0)
7906     {
7907     /* this test doesn't pass under Win9x */
7908     /* win2k ignores events with hwnd == 0 */
7909     SetLastError(0xdeadbeef);
7910     pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
7911     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
7912        GetLastError() == 0xdeadbeef, /* Win9x */
7913        "unexpected error %d\n", GetLastError());
7914     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7915     }
7916
7917     for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
7918         pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
7919
7920     ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
7921
7922     /****** start of event filtering test *************/
7923     hhook = (HWINEVENTHOOK)pSetWinEventHook(
7924         EVENT_OBJECT_SHOW, /* 0x8002 */
7925         EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
7926         GetModuleHandleA(0), win_event_global_hook_proc,
7927         GetCurrentProcessId(), 0,
7928         WINEVENT_INCONTEXT);
7929     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7930
7931     hevent = CreateEventA(NULL, 0, 0, NULL);
7932     assert(hevent);
7933     hwnd2 = (HWND)hevent;
7934
7935     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7936     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7937
7938     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7939
7940     ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
7941
7942     flush_sequence();
7943     /* this one should be received only by old hook proc */
7944     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7945     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7946     /* this one should be received only by old hook proc */
7947     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7948
7949     ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
7950
7951     ret = pUnhookWinEvent(hhook);
7952     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7953
7954     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7955     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7956     CloseHandle(hthread);
7957     CloseHandle(hevent);
7958     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7959     /****** end of event filtering test *************/
7960
7961     /****** start of out of context event test *************/
7962     hhook = (HWINEVENTHOOK)pSetWinEventHook(
7963         EVENT_MIN, EVENT_MAX,
7964         0, win_event_global_hook_proc,
7965         GetCurrentProcessId(), 0,
7966         WINEVENT_OUTOFCONTEXT);
7967     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7968
7969     hevent = CreateEventA(NULL, 0, 0, NULL);
7970     assert(hevent);
7971     hwnd2 = (HWND)hevent;
7972
7973     flush_sequence();
7974
7975     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7976     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7977
7978     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7979
7980     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7981     /* process pending winevent messages */
7982     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7983     ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
7984
7985     flush_sequence();
7986     /* this one should be received only by old hook proc */
7987     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7988     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7989     /* this one should be received only by old hook proc */
7990     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7991
7992     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
7993     /* process pending winevent messages */
7994     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7995     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
7996
7997     ret = pUnhookWinEvent(hhook);
7998     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7999
8000     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8001     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8002     CloseHandle(hthread);
8003     CloseHandle(hevent);
8004     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8005     /****** end of out of context event test *************/
8006
8007     /****** start of MOUSE_LL hook test *************/
8008     hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8009     /* WH_MOUSE_LL is not supported on Win9x platforms */
8010     if (!hCBT_global_hook)
8011     {
8012         trace("Skipping WH_MOUSE_LL test on this platform\n");
8013         goto skip_mouse_ll_hook_test;
8014     }
8015
8016     hevent = CreateEventA(NULL, 0, 0, NULL);
8017     assert(hevent);
8018     hwnd2 = (HWND)hevent;
8019
8020     hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
8021     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8022
8023     while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
8024         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
8025
8026     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
8027     flush_sequence();
8028
8029     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8030     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8031     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8032
8033     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
8034
8035     ret = UnhookWindowsHookEx(hCBT_global_hook);
8036     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8037
8038     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8039     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8040     CloseHandle(hthread);
8041     CloseHandle(hevent);
8042     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8043     /****** end of MOUSE_LL hook test *************/
8044 skip_mouse_ll_hook_test:
8045
8046     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8047 }
8048
8049 static void test_set_hook(void)
8050 {
8051     BOOL ret;
8052     HHOOK hhook;
8053     HWINEVENTHOOK hwinevent_hook;
8054
8055     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
8056     ok(hhook != 0, "local hook does not require hModule set to 0\n");
8057     UnhookWindowsHookEx(hhook);
8058
8059     if (0)
8060     {
8061     /* this test doesn't pass under Win9x: BUG! */
8062     SetLastError(0xdeadbeef);
8063     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
8064     ok(!hhook, "global hook requires hModule != 0\n");
8065     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
8066     }
8067
8068     SetLastError(0xdeadbeef);
8069     hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
8070     ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
8071     ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
8072        GetLastError() == 0xdeadbeef, /* Win9x */
8073        "unexpected error %d\n", GetLastError());
8074
8075     SetLastError(0xdeadbeef);
8076     ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
8077     ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
8078        GetLastError() == 0xdeadbeef, /* Win9x */
8079        "unexpected error %d\n", GetLastError());
8080
8081     if (!pSetWinEventHook || !pUnhookWinEvent) return;
8082
8083     /* even process local incontext hooks require hmodule */
8084     SetLastError(0xdeadbeef);
8085     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
8086         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
8087     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8088     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8089        GetLastError() == 0xdeadbeef, /* Win9x */
8090        "unexpected error %d\n", GetLastError());
8091
8092     /* even thread local incontext hooks require hmodule */
8093     SetLastError(0xdeadbeef);
8094     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
8095         0, win_event_proc, GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
8096     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8097     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8098        GetLastError() == 0xdeadbeef, /* Win9x */
8099        "unexpected error %d\n", GetLastError());
8100
8101     if (0)
8102     {
8103     /* these 3 tests don't pass under Win9x */
8104     SetLastError(0xdeadbeef);
8105     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(1, 0,
8106         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8107     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8108     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8109
8110     SetLastError(0xdeadbeef);
8111     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(-1, 1,
8112         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8113     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8114     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8115
8116     SetLastError(0xdeadbeef);
8117     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
8118         0, win_event_proc, 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
8119     ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
8120     ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
8121     }
8122
8123     SetLastError(0xdeadbeef);
8124     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(0, 0,
8125         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8126     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8127     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8128     ret = pUnhookWinEvent(hwinevent_hook);
8129     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8130
8131 todo_wine {
8132     /* This call succeeds under win2k SP4, but fails under Wine.
8133        Does win2k test/use passed process id? */
8134     SetLastError(0xdeadbeef);
8135     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
8136         0, win_event_proc, 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
8137     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8138     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8139     ret = pUnhookWinEvent(hwinevent_hook);
8140     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8141 }
8142
8143     SetLastError(0xdeadbeef);
8144     ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
8145     ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
8146         GetLastError() == 0xdeadbeef, /* Win9x */
8147         "unexpected error %d\n", GetLastError());
8148 }
8149
8150 static const struct message ScrollWindowPaint1[] = {
8151     { WM_PAINT, sent },
8152     { WM_ERASEBKGND, sent|beginpaint },
8153     { 0 }
8154 };
8155
8156 static const struct message ScrollWindowPaint2[] = {
8157     { WM_PAINT, sent },
8158     { 0 }
8159 };
8160
8161 static void test_scrollwindowex(void)
8162 {
8163     HWND hwnd, hchild;
8164     RECT rect={0,0,130,130};
8165
8166     hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
8167             WS_VISIBLE|WS_OVERLAPPEDWINDOW,
8168             100, 100, 200, 200, 0, 0, 0, NULL);
8169     ok (hwnd != 0, "Failed to create overlapped window\n");
8170     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", 
8171             WS_VISIBLE|WS_CAPTION|WS_CHILD,
8172             10, 10, 150, 150, hwnd, 0, 0, NULL);
8173     ok (hchild != 0, "Failed to create child\n");
8174     UpdateWindow(hwnd);
8175     flush_events();
8176     flush_sequence();
8177
8178     /* scroll without the child window */
8179     trace("start scroll\n");
8180     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8181             SW_ERASE|SW_INVALIDATE);
8182     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8183     trace("end scroll\n");
8184     flush_sequence();
8185     flush_events();
8186     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8187     flush_events();
8188     flush_sequence();
8189
8190     /* Now without the SW_ERASE flag */
8191     trace("start scroll\n");
8192     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
8193     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8194     trace("end scroll\n");
8195     flush_sequence();
8196     flush_events();
8197     ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
8198     flush_events();
8199     flush_sequence();
8200
8201     /* now scroll the child window as well */
8202     trace("start scroll\n");
8203     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8204             SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
8205     /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
8206     /* windows sometimes a WM_MOVE */
8207     ok_sequence(WmEmptySeq, "ScrollWindowEx", TRUE);
8208     trace("end scroll\n");
8209     flush_sequence();
8210     flush_events();
8211     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8212     flush_events();
8213     flush_sequence();
8214
8215     /* now scroll with ScrollWindow() */
8216     trace("start scroll with ScrollWindow\n");
8217     ScrollWindow( hwnd, 5, 5, NULL, NULL);
8218     trace("end scroll\n");
8219     flush_sequence();
8220     flush_events();
8221     ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
8222
8223     ok(DestroyWindow(hchild), "failed to destroy window\n");
8224     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8225     flush_sequence();
8226 }
8227
8228 static const struct message destroy_window_with_children[] = {
8229     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8230     { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
8231     { 0x0090, sent|optional },
8232     { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
8233     { 0x0090, sent|optional },
8234     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8235     { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8236     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8237     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8238     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
8239     { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8240     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8241     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8242     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8243     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8244     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8245     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8246     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8247     { 0 }
8248 };
8249
8250 static void test_DestroyWindow(void)
8251 {
8252     BOOL ret;
8253     HWND parent, child1, child2, child3, child4, test;
8254     UINT_PTR child_id = WND_CHILD_ID + 1;
8255
8256     parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8257                              100, 100, 200, 200, 0, 0, 0, NULL);
8258     assert(parent != 0);
8259     child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8260                              0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
8261     assert(child1 != 0);
8262     child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8263                              0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
8264     assert(child2 != 0);
8265     child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8266                              0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
8267     assert(child3 != 0);
8268     child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
8269                              0, 0, 50, 50, parent, 0, 0, NULL);
8270     assert(child4 != 0);
8271
8272     /* test owner/parent of child2 */
8273     test = GetParent(child2);
8274     ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8275     ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8276     if(pGetAncestor) {
8277         test = pGetAncestor(child2, GA_PARENT);
8278         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8279     }
8280     test = GetWindow(child2, GW_OWNER);
8281     ok(!test, "wrong owner %p\n", test);
8282
8283     test = SetParent(child2, parent);
8284     ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
8285
8286     /* test owner/parent of the parent */
8287     test = GetParent(parent);
8288     ok(!test, "wrong parent %p\n", test);
8289     ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
8290     if(pGetAncestor) {
8291         test = pGetAncestor(parent, GA_PARENT);
8292         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8293     }
8294     test = GetWindow(parent, GW_OWNER);
8295     ok(!test, "wrong owner %p\n", test);
8296
8297     /* test owner/parent of child1 */
8298     test = GetParent(child1);
8299     ok(test == parent, "wrong parent %p\n", test);
8300     ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
8301     if(pGetAncestor) {
8302         test = pGetAncestor(child1, GA_PARENT);
8303         ok(test == parent, "wrong parent %p\n", test);
8304     }
8305     test = GetWindow(child1, GW_OWNER);
8306     ok(!test, "wrong owner %p\n", test);
8307
8308     /* test owner/parent of child2 */
8309     test = GetParent(child2);
8310     ok(test == parent, "wrong parent %p\n", test);
8311     ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8312     if(pGetAncestor) {
8313         test = pGetAncestor(child2, GA_PARENT);
8314         ok(test == parent, "wrong parent %p\n", test);
8315     }
8316     test = GetWindow(child2, GW_OWNER);
8317     ok(!test, "wrong owner %p\n", test);
8318
8319     /* test owner/parent of child3 */
8320     test = GetParent(child3);
8321     ok(test == child1, "wrong parent %p\n", test);
8322     ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
8323     if(pGetAncestor) {
8324         test = pGetAncestor(child3, GA_PARENT);
8325         ok(test == child1, "wrong parent %p\n", test);
8326     }
8327     test = GetWindow(child3, GW_OWNER);
8328     ok(!test, "wrong owner %p\n", test);
8329
8330     /* test owner/parent of child4 */
8331     test = GetParent(child4);
8332     ok(test == parent, "wrong parent %p\n", test);
8333     ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
8334     if(pGetAncestor) {
8335         test = pGetAncestor(child4, GA_PARENT);
8336         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8337     }
8338     test = GetWindow(child4, GW_OWNER);
8339     ok(test == parent, "wrong owner %p\n", test);
8340
8341     flush_sequence();
8342
8343     trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
8344            parent, child1, child2, child3, child4);
8345
8346     SetCapture(child4);
8347     test = GetCapture();
8348     ok(test == child4, "wrong capture window %p\n", test);
8349
8350     test_DestroyWindow_flag = TRUE;
8351     ret = DestroyWindow(parent);
8352     ok( ret, "DestroyWindow() error %d\n", GetLastError());
8353     test_DestroyWindow_flag = FALSE;
8354     ok_sequence(destroy_window_with_children, "destroy window with children", 0);
8355
8356     ok(!IsWindow(parent), "parent still exists\n");
8357     ok(!IsWindow(child1), "child1 still exists\n");
8358     ok(!IsWindow(child2), "child2 still exists\n");
8359     ok(!IsWindow(child3), "child3 still exists\n");
8360     ok(!IsWindow(child4), "child4 still exists\n");
8361
8362     test = GetCapture();
8363     ok(!test, "wrong capture window %p\n", test);
8364 }
8365
8366
8367 static const struct message WmDispatchPaint[] = {
8368     { WM_NCPAINT, sent },
8369     { WM_GETTEXT, sent|defwinproc|optional },
8370     { WM_GETTEXT, sent|defwinproc|optional },
8371     { WM_ERASEBKGND, sent },
8372     { 0 }
8373 };
8374
8375 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8376 {
8377     if (message == WM_PAINT) return 0;
8378     return MsgCheckProcA( hwnd, message, wParam, lParam );
8379 }
8380
8381 static void test_DispatchMessage(void)
8382 {
8383     RECT rect;
8384     MSG msg;
8385     int count;
8386     HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8387                                100, 100, 200, 200, 0, 0, 0, NULL);
8388     ShowWindow( hwnd, SW_SHOW );
8389     UpdateWindow( hwnd );
8390     flush_events();
8391     flush_sequence();
8392     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
8393
8394     SetRect( &rect, -5, -5, 5, 5 );
8395     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8396     count = 0;
8397     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8398     {
8399         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8400         else
8401         {
8402             flush_sequence();
8403             DispatchMessage( &msg );
8404             /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
8405             if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8406             else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
8407             if (++count > 10) break;
8408         }
8409     }
8410     ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
8411
8412     trace("now without DispatchMessage\n");
8413     flush_sequence();
8414     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8415     count = 0;
8416     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8417     {
8418         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8419         else
8420         {
8421             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
8422             flush_sequence();
8423             /* this will send WM_NCCPAINT just like DispatchMessage does */
8424             GetUpdateRgn( hwnd, hrgn, TRUE );
8425             ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8426             DeleteObject( hrgn );
8427             GetClientRect( hwnd, &rect );
8428             ValidateRect( hwnd, &rect );  /* this will stop WM_PAINTs */
8429             ok( !count, "Got multiple WM_PAINTs\n" );
8430             if (++count > 10) break;
8431         }
8432     }
8433     DestroyWindow(hwnd);
8434 }
8435
8436
8437 static const struct message WmUser[] = {
8438     { WM_USER, sent },
8439     { 0 }
8440 };
8441
8442 struct sendmsg_info
8443 {
8444     HWND  hwnd;
8445     DWORD timeout;
8446     DWORD ret;
8447 };
8448
8449 static DWORD CALLBACK send_msg_thread( LPVOID arg )
8450 {
8451     struct sendmsg_info *info = arg;
8452     SetLastError( 0xdeadbeef );
8453     info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
8454     if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT ||
8455                         broken(GetLastError() == 0),  /* win9x */
8456                         "unexpected error %d\n", GetLastError());
8457     return 0;
8458 }
8459
8460 static void wait_for_thread( HANDLE thread )
8461 {
8462     while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
8463     {
8464         MSG msg;
8465         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
8466     }
8467 }
8468
8469 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8470 {
8471     if (message == WM_USER) Sleep(200);
8472     return MsgCheckProcA( hwnd, message, wParam, lParam );
8473 }
8474
8475 static void test_SendMessageTimeout(void)
8476 {
8477     HANDLE thread;
8478     struct sendmsg_info info;
8479     DWORD tid;
8480     BOOL is_win9x;
8481
8482     info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8483                                100, 100, 200, 200, 0, 0, 0, NULL);
8484     flush_events();
8485     flush_sequence();
8486
8487     info.timeout = 1000;
8488     info.ret = 0xdeadbeef;
8489     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8490     wait_for_thread( thread );
8491     CloseHandle( thread );
8492     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8493     ok_sequence( WmUser, "WmUser", FALSE );
8494
8495     info.timeout = 1;
8496     info.ret = 0xdeadbeef;
8497     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8498     Sleep(100);  /* SendMessageTimeout should time out here */
8499     wait_for_thread( thread );
8500     CloseHandle( thread );
8501     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8502     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8503
8504     /* 0 means infinite timeout (but not on win9x) */
8505     info.timeout = 0;
8506     info.ret = 0xdeadbeef;
8507     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8508     Sleep(100);
8509     wait_for_thread( thread );
8510     CloseHandle( thread );
8511     is_win9x = !info.ret;
8512     if (is_win9x) ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8513     else ok_sequence( WmUser, "WmUser", FALSE );
8514
8515     /* timeout is treated as signed despite the prototype (but not on win9x) */
8516     info.timeout = 0x7fffffff;
8517     info.ret = 0xdeadbeef;
8518     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8519     Sleep(100);
8520     wait_for_thread( thread );
8521     CloseHandle( thread );
8522     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8523     ok_sequence( WmUser, "WmUser", FALSE );
8524
8525     info.timeout = 0x80000000;
8526     info.ret = 0xdeadbeef;
8527     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8528     Sleep(100);
8529     wait_for_thread( thread );
8530     CloseHandle( thread );
8531     if (is_win9x)
8532     {
8533         ok( info.ret == 1, "SendMessageTimeout failed\n" );
8534         ok_sequence( WmUser, "WmUser", FALSE );
8535     }
8536     else
8537     {
8538         ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8539         ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8540     }
8541
8542     /* now check for timeout during message processing */
8543     SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
8544     info.timeout = 100;
8545     info.ret = 0xdeadbeef;
8546     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8547     wait_for_thread( thread );
8548     CloseHandle( thread );
8549     /* we should time out but still get the message */
8550     ok( info.ret == 0, "SendMessageTimeout failed\n" );
8551     ok_sequence( WmUser, "WmUser", FALSE );
8552
8553     DestroyWindow( info.hwnd );
8554 }
8555
8556
8557 /****************** edit message test *************************/
8558 #define ID_EDIT 0x1234
8559 static const struct message sl_edit_setfocus[] =
8560 {
8561     { HCBT_SETFOCUS, hook },
8562     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8563     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8564     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8565     { WM_SETFOCUS, sent|wparam, 0 },
8566     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8567     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
8568     { WM_CTLCOLOREDIT, sent|parent },
8569     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8570     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8571     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8572     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8573     { 0 }
8574 };
8575 static const struct message ml_edit_setfocus[] =
8576 {
8577     { HCBT_SETFOCUS, hook },
8578     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8579     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8580     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8581     { WM_SETFOCUS, sent|wparam, 0 },
8582     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8583     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8584     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8585     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8586     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8587     { 0 }
8588 };
8589 static const struct message sl_edit_killfocus[] =
8590 {
8591     { HCBT_SETFOCUS, hook },
8592     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8593     { WM_KILLFOCUS, sent|wparam, 0 },
8594     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8595     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8596     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
8597     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
8598     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
8599     { 0 }
8600 };
8601 static const struct message sl_edit_lbutton_dblclk[] =
8602 {
8603     { WM_LBUTTONDBLCLK, sent },
8604     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8605     { 0 }
8606 };
8607 static const struct message sl_edit_lbutton_down[] =
8608 {
8609     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8610     { HCBT_SETFOCUS, hook },
8611     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8612     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8613     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8614     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8615     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8616     { WM_CTLCOLOREDIT, sent|parent },
8617     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8618     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8619     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8620     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8621     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8622     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8623     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8624     { WM_CTLCOLOREDIT, sent|parent|optional },
8625     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8626     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8627     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8628     { 0 }
8629 };
8630 static const struct message ml_edit_lbutton_down[] =
8631 {
8632     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8633     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8634     { HCBT_SETFOCUS, hook },
8635     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8636     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8637     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8638     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8639     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8640     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8641     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8642     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8643     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8644     { 0 }
8645 };
8646 static const struct message sl_edit_lbutton_up[] =
8647 {
8648     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8649     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8650     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8651     { WM_CAPTURECHANGED, sent|defwinproc },
8652     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8653     { 0 }
8654 };
8655 static const struct message ml_edit_lbutton_up[] =
8656 {
8657     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8658     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8659     { WM_CAPTURECHANGED, sent|defwinproc },
8660     { 0 }
8661 };
8662
8663 static WNDPROC old_edit_proc;
8664
8665 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8666 {
8667     static long defwndproc_counter = 0;
8668     LRESULT ret;
8669     struct recvd_message msg;
8670
8671     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
8672
8673     msg.hwnd = hwnd;
8674     msg.message = message;
8675     msg.flags = sent|wparam|lparam;
8676     if (defwndproc_counter) msg.flags |= defwinproc;
8677     msg.wParam = wParam;
8678     msg.lParam = lParam;
8679     msg.descr = "edit";
8680     add_message(&msg);
8681
8682     defwndproc_counter++;
8683     ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
8684     defwndproc_counter--;
8685
8686     return ret;
8687 }
8688
8689 static void subclass_edit(void)
8690 {
8691     WNDCLASSA cls;
8692
8693     if (!GetClassInfoA(0, "edit", &cls)) assert(0);
8694
8695     old_edit_proc = cls.lpfnWndProc;
8696
8697     cls.hInstance = GetModuleHandle(0);
8698     cls.lpfnWndProc = edit_hook_proc;
8699     cls.lpszClassName = "my_edit_class";
8700     UnregisterClass(cls.lpszClassName, cls.hInstance);
8701     if (!RegisterClassA(&cls)) assert(0);
8702 }
8703
8704 static void test_edit_messages(void)
8705 {
8706     HWND hwnd, parent;
8707     DWORD dlg_code;
8708
8709     subclass_edit();
8710     log_all_parent_messages++;
8711
8712     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8713                              100, 100, 200, 200, 0, 0, 0, NULL);
8714     ok (parent != 0, "Failed to create parent window\n");
8715
8716     /* test single line edit */
8717     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
8718                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8719     ok(hwnd != 0, "Failed to create edit window\n");
8720
8721     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8722     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
8723
8724     ShowWindow(hwnd, SW_SHOW);
8725     UpdateWindow(hwnd);
8726     SetFocus(0);
8727     flush_sequence();
8728
8729     SetFocus(hwnd);
8730     ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
8731
8732     SetFocus(0);
8733     ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
8734
8735     SetFocus(0);
8736     ReleaseCapture();
8737     flush_sequence();
8738
8739     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8740     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
8741
8742     SetFocus(0);
8743     ReleaseCapture();
8744     flush_sequence();
8745
8746     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8747     ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
8748
8749     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8750     ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
8751
8752     DestroyWindow(hwnd);
8753
8754     /* test multiline edit */
8755     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
8756                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8757     ok(hwnd != 0, "Failed to create edit window\n");
8758
8759     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8760     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
8761        "wrong dlg_code %08x\n", dlg_code);
8762
8763     ShowWindow(hwnd, SW_SHOW);
8764     UpdateWindow(hwnd);
8765     SetFocus(0);
8766     flush_sequence();
8767
8768     SetFocus(hwnd);
8769     ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
8770
8771     SetFocus(0);
8772     ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
8773
8774     SetFocus(0);
8775     ReleaseCapture();
8776     flush_sequence();
8777
8778     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8779     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
8780
8781     SetFocus(0);
8782     ReleaseCapture();
8783     flush_sequence();
8784
8785     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8786     ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
8787
8788     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8789     ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
8790
8791     DestroyWindow(hwnd);
8792     DestroyWindow(parent);
8793
8794     log_all_parent_messages--;
8795 }
8796
8797 /**************************** End of Edit test ******************************/
8798
8799 static const struct message WmKeyDownSkippedSeq[] =
8800 {
8801     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
8802     { 0 }
8803 };
8804 static const struct message WmKeyDownWasDownSkippedSeq[] =
8805 {
8806     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x40000001 }, /* XP */
8807     { 0 }
8808 };
8809 static const struct message WmKeyUpSkippedSeq[] =
8810 {
8811     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8812     { 0 }
8813 };
8814 static const struct message WmUserKeyUpSkippedSeq[] =
8815 {
8816     { WM_USER, sent },
8817     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8818     { 0 }
8819 };
8820
8821 #define EV_STOP 0
8822 #define EV_SENDMSG 1
8823 #define EV_ACK 2
8824
8825 struct peekmsg_info
8826 {
8827     HWND  hwnd;
8828     HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
8829 };
8830
8831 static DWORD CALLBACK send_msg_thread_2(void *param)
8832 {
8833     DWORD ret;
8834     struct peekmsg_info *info = param;
8835
8836     trace("thread: looping\n");
8837     SetEvent(info->hevent[EV_ACK]);
8838
8839     while (1)
8840     {
8841         ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
8842
8843         switch (ret)
8844         {
8845         case WAIT_OBJECT_0 + EV_STOP:
8846             trace("thread: exiting\n");
8847             return 0;
8848
8849         case WAIT_OBJECT_0 + EV_SENDMSG:
8850             trace("thread: sending message\n");
8851             ok( SendNotifyMessageA(info->hwnd, WM_USER, 0, 0),
8852                 "SendNotifyMessageA failed error %u\n", GetLastError());
8853             SetEvent(info->hevent[EV_ACK]);
8854             break;
8855
8856         default:
8857             trace("unexpected return: %04x\n", ret);
8858             assert(0);
8859             break;
8860         }
8861     }
8862     return 0;
8863 }
8864
8865 static void test_PeekMessage(void)
8866 {
8867     MSG msg;
8868     HANDLE hthread;
8869     DWORD tid, qstatus;
8870     UINT qs_all_input = QS_ALLINPUT;
8871     UINT qs_input = QS_INPUT;
8872     BOOL ret;
8873     struct peekmsg_info info;
8874
8875     info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8876                               100, 100, 200, 200, 0, 0, 0, NULL);
8877     assert(info.hwnd);
8878     ShowWindow(info.hwnd, SW_SHOW);
8879     UpdateWindow(info.hwnd);
8880     SetFocus(info.hwnd);
8881
8882     info.hevent[EV_STOP] = CreateEventA(NULL, 0, 0, NULL);
8883     info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
8884     info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
8885
8886     hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
8887     WaitForSingleObject(info.hevent[EV_ACK], 10000);
8888
8889     flush_events();
8890     flush_sequence();
8891
8892     SetLastError(0xdeadbeef);
8893     qstatus = GetQueueStatus(qs_all_input);
8894     if (GetLastError() == ERROR_INVALID_FLAGS)
8895     {
8896         trace("QS_RAWINPUT not supported on this platform\n");
8897         qs_all_input &= ~QS_RAWINPUT;
8898         qs_input &= ~QS_RAWINPUT;
8899     }
8900     if (qstatus & QS_POSTMESSAGE)
8901     {
8902         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) /* nothing */ ;
8903         qstatus = GetQueueStatus(qs_all_input);
8904     }
8905     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8906
8907     trace("signalling to send message\n");
8908     SetEvent(info.hevent[EV_SENDMSG]);
8909     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8910
8911     /* pass invalid QS_xxxx flags */
8912     SetLastError(0xdeadbeef);
8913     qstatus = GetQueueStatus(0xffffffff);
8914     ok(qstatus == 0 || broken(qstatus)  /* win9x */, "GetQueueStatus should fail: %08x\n", qstatus);
8915     if (!qstatus)
8916     {
8917         ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
8918         qstatus = GetQueueStatus(qs_all_input);
8919     }
8920     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
8921        "wrong qstatus %08x\n", qstatus);
8922
8923     msg.message = 0;
8924     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8925     ok(!ret,
8926        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8927         msg.message);
8928     ok_sequence(WmUser, "WmUser", FALSE);
8929
8930     qstatus = GetQueueStatus(qs_all_input);
8931     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8932
8933     keybd_event('N', 0, 0, 0);
8934     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
8935     qstatus = GetQueueStatus(qs_all_input);
8936     ok(qstatus == MAKELONG(QS_KEY, QS_KEY),
8937        "wrong qstatus %08x\n", qstatus);
8938
8939     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8940     qstatus = GetQueueStatus(qs_all_input);
8941     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8942        "wrong qstatus %08x\n", qstatus);
8943
8944     InvalidateRect(info.hwnd, NULL, FALSE);
8945     qstatus = GetQueueStatus(qs_all_input);
8946     ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8947        "wrong qstatus %08x\n", qstatus);
8948
8949     trace("signalling to send message\n");
8950     SetEvent(info.hevent[EV_SENDMSG]);
8951     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8952
8953     qstatus = GetQueueStatus(qs_all_input);
8954     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8955        "wrong qstatus %08x\n", qstatus);
8956
8957     msg.message = 0;
8958     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
8959     if (ret && msg.message == WM_CHAR)
8960     {
8961         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
8962         goto done;
8963     }
8964     ok(!ret,
8965        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8966         msg.message);
8967     if (!sequence_cnt)  /* nt4 doesn't fetch anything with PM_QS_* flags */
8968     {
8969         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
8970         goto done;
8971     }
8972     ok_sequence(WmUser, "WmUser", FALSE);
8973
8974     qstatus = GetQueueStatus(qs_all_input);
8975     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8976        "wrong qstatus %08x\n", qstatus);
8977
8978     trace("signalling to send message\n");
8979     SetEvent(info.hevent[EV_SENDMSG]);
8980     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8981
8982     qstatus = GetQueueStatus(qs_all_input);
8983     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8984        "wrong qstatus %08x\n", qstatus);
8985
8986     msg.message = 0;
8987     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE );
8988     ok(!ret,
8989        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8990         msg.message);
8991     ok_sequence(WmUser, "WmUser", FALSE);
8992
8993     qstatus = GetQueueStatus(qs_all_input);
8994     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8995        "wrong qstatus %08x\n", qstatus);
8996
8997     msg.message = 0;
8998     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8999     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9000        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9001        ret, msg.message, msg.wParam);
9002     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9003
9004     qstatus = GetQueueStatus(qs_all_input);
9005     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9006        "wrong qstatus %08x\n", qstatus);
9007
9008     msg.message = 0;
9009     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9010     ok(!ret,
9011        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9012         msg.message);
9013     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9014
9015     qstatus = GetQueueStatus(qs_all_input);
9016     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9017        "wrong qstatus %08x\n", qstatus);
9018
9019     msg.message = 0;
9020     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9021     ok(ret && msg.message == WM_PAINT,
9022        "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
9023     DispatchMessageA(&msg);
9024     ok_sequence(WmPaint, "WmPaint", FALSE);
9025
9026     qstatus = GetQueueStatus(qs_all_input);
9027     ok(qstatus == MAKELONG(0, QS_KEY),
9028        "wrong qstatus %08x\n", qstatus);
9029
9030     msg.message = 0;
9031     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9032     ok(!ret,
9033        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9034         msg.message);
9035     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9036
9037     qstatus = GetQueueStatus(qs_all_input);
9038     ok(qstatus == MAKELONG(0, QS_KEY),
9039        "wrong qstatus %08x\n", qstatus);
9040
9041     trace("signalling to send message\n");
9042     SetEvent(info.hevent[EV_SENDMSG]);
9043     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9044
9045     qstatus = GetQueueStatus(qs_all_input);
9046     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
9047        "wrong qstatus %08x\n", qstatus);
9048
9049     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9050
9051     qstatus = GetQueueStatus(qs_all_input);
9052     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9053        "wrong qstatus %08x\n", qstatus);
9054
9055     msg.message = 0;
9056     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9057     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9058        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9059        ret, msg.message, msg.wParam);
9060     ok_sequence(WmUser, "WmUser", FALSE);
9061
9062     qstatus = GetQueueStatus(qs_all_input);
9063     ok(qstatus == MAKELONG(0, QS_KEY),
9064        "wrong qstatus %08x\n", qstatus);
9065
9066     msg.message = 0;
9067     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9068     ok(!ret,
9069        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9070         msg.message);
9071     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9072
9073     qstatus = GetQueueStatus(qs_all_input);
9074     ok(qstatus == MAKELONG(0, QS_KEY),
9075        "wrong qstatus %08x\n", qstatus);
9076
9077     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9078
9079     qstatus = GetQueueStatus(qs_all_input);
9080     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9081        "wrong qstatus %08x\n", qstatus);
9082
9083     trace("signalling to send message\n");
9084     SetEvent(info.hevent[EV_SENDMSG]);
9085     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9086
9087     qstatus = GetQueueStatus(qs_all_input);
9088     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9089        "wrong qstatus %08x\n", qstatus);
9090
9091     msg.message = 0;
9092     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
9093     ok(!ret,
9094        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9095         msg.message);
9096     ok_sequence(WmUser, "WmUser", FALSE);
9097
9098     qstatus = GetQueueStatus(qs_all_input);
9099     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9100        "wrong qstatus %08x\n", qstatus);
9101
9102     msg.message = 0;
9103     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9104         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9105     else /* workaround for a missing QS_RAWINPUT support */
9106         ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
9107     ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9108        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9109        ret, msg.message, msg.wParam);
9110     ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9111
9112     qstatus = GetQueueStatus(qs_all_input);
9113     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9114        "wrong qstatus %08x\n", qstatus);
9115
9116     msg.message = 0;
9117     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9118         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9119     else /* workaround for a missing QS_RAWINPUT support */
9120         ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
9121     ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9122        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
9123        ret, msg.message, msg.wParam);
9124     ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
9125
9126     qstatus = GetQueueStatus(qs_all_input);
9127     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9128        "wrong qstatus %08x\n", qstatus);
9129
9130     msg.message = 0;
9131     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
9132     ok(!ret,
9133        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9134         msg.message);
9135     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9136
9137     qstatus = GetQueueStatus(qs_all_input);
9138     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9139        "wrong qstatus %08x\n", qstatus);
9140
9141     msg.message = 0;
9142     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9143     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9144        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9145        ret, msg.message, msg.wParam);
9146     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9147
9148     qstatus = GetQueueStatus(qs_all_input);
9149     ok(qstatus == 0,
9150        "wrong qstatus %08x\n", qstatus);
9151
9152     msg.message = 0;
9153     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9154     ok(!ret,
9155        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9156         msg.message);
9157     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9158
9159     qstatus = GetQueueStatus(qs_all_input);
9160     ok(qstatus == 0,
9161        "wrong qstatus %08x\n", qstatus);
9162
9163     /* test whether presence of the quit flag in the queue affects
9164      * the queue state
9165      */
9166     PostQuitMessage(0x1234abcd);
9167
9168     qstatus = GetQueueStatus(qs_all_input);
9169     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9170        "wrong qstatus %08x\n", qstatus);
9171
9172     PostMessageA(info.hwnd, WM_USER, 0, 0);
9173
9174     qstatus = GetQueueStatus(qs_all_input);
9175     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9176        "wrong qstatus %08x\n", qstatus);
9177
9178     msg.message = 0;
9179     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9180     ok(ret && msg.message == WM_USER,
9181        "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
9182     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9183
9184     qstatus = GetQueueStatus(qs_all_input);
9185     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9186        "wrong qstatus %08x\n", qstatus);
9187
9188     msg.message = 0;
9189     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9190     ok(ret && msg.message == WM_QUIT,
9191        "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
9192     ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
9193     ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
9194     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9195
9196     qstatus = GetQueueStatus(qs_all_input);
9197 todo_wine {
9198     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9199        "wrong qstatus %08x\n", qstatus);
9200 }
9201
9202     msg.message = 0;
9203     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9204     ok(!ret,
9205        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9206         msg.message);
9207     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9208
9209     qstatus = GetQueueStatus(qs_all_input);
9210     ok(qstatus == 0,
9211        "wrong qstatus %08x\n", qstatus);
9212
9213     /* some GetMessage tests */
9214
9215     keybd_event('N', 0, 0, 0);
9216     qstatus = GetQueueStatus(qs_all_input);
9217     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9218
9219     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9220     qstatus = GetQueueStatus(qs_all_input);
9221     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9222
9223     if (qstatus)
9224     {
9225         ret = GetMessageA( &msg, 0, 0, 0 );
9226         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9227            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9228            ret, msg.message, msg.wParam);
9229         qstatus = GetQueueStatus(qs_all_input);
9230         ok(qstatus == MAKELONG(0, QS_KEY), "wrong qstatus %08x\n", qstatus);
9231     }
9232
9233     if (qstatus)
9234     {
9235         ret = GetMessageA( &msg, 0, 0, 0 );
9236         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9237            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9238            ret, msg.message, msg.wParam);
9239         ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9240         qstatus = GetQueueStatus(qs_all_input);
9241         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9242     }
9243
9244     keybd_event('N', 0, 0, 0);
9245     qstatus = GetQueueStatus(qs_all_input);
9246     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9247
9248     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9249     qstatus = GetQueueStatus(qs_all_input);
9250     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9251
9252     if (qstatus & (QS_KEY << 16))
9253     {
9254         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9255         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9256            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9257            ret, msg.message, msg.wParam);
9258         ok_sequence(WmKeyDownWasDownSkippedSeq, "WmKeyDownWasDownSkippedSeq", FALSE);
9259         qstatus = GetQueueStatus(qs_all_input);
9260         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9261     }
9262
9263     if (qstatus)
9264     {
9265         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9266         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9267            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9268            ret, msg.message, msg.wParam);
9269         qstatus = GetQueueStatus(qs_all_input);
9270         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9271     }
9272
9273     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9274     qstatus = GetQueueStatus(qs_all_input);
9275     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9276
9277     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9278     qstatus = GetQueueStatus(qs_all_input);
9279     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9280
9281     trace("signalling to send message\n");
9282     SetEvent(info.hevent[EV_SENDMSG]);
9283     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9284     qstatus = GetQueueStatus(qs_all_input);
9285     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9286        "wrong qstatus %08x\n", qstatus);
9287
9288     if (qstatus & (QS_KEY << 16))
9289     {
9290         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9291         ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9292            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9293            ret, msg.message, msg.wParam);
9294         ok_sequence(WmUserKeyUpSkippedSeq, "WmUserKeyUpSkippedSeq", FALSE);
9295         qstatus = GetQueueStatus(qs_all_input);
9296         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9297     }
9298
9299     if (qstatus)
9300     {
9301         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9302         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9303            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9304            ret, msg.message, msg.wParam);
9305         qstatus = GetQueueStatus(qs_all_input);
9306         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9307     }
9308 done:
9309     trace("signalling to exit\n");
9310     SetEvent(info.hevent[EV_STOP]);
9311
9312     WaitForSingleObject(hthread, INFINITE);
9313
9314     CloseHandle(hthread);
9315     CloseHandle(info.hevent[0]);
9316     CloseHandle(info.hevent[1]);
9317     CloseHandle(info.hevent[2]);
9318
9319     DestroyWindow(info.hwnd);
9320 }
9321
9322 static void wait_move_event(HWND hwnd, int x, int y)
9323 {
9324     MSG msg;
9325     DWORD time;
9326     BOOL  ret;
9327     int go = 0;
9328
9329     time = GetTickCount();
9330     while (GetTickCount() - time < 200 && !go) {
9331         ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9332         go  = ret && msg.pt.x > x && msg.pt.y > y;
9333         if (ret && !go) PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE);
9334     }
9335 }
9336
9337 #define STEP 20
9338 static void test_PeekMessage2(void)
9339 {
9340     HWND hwnd;
9341     BOOL ret;
9342     MSG msg;
9343     UINT message;
9344     DWORD time1, time2, time3;
9345     int x1, y1, x2, y2, x3, y3;
9346     POINT pos;
9347
9348     time1 = time2 = time3 = 0;
9349     x1 = y1 = x2 = y2 = x3 = y3 = 0;
9350
9351     /* Initialise window and make sure it is ready for events */
9352     hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
9353                         10, 10, 800, 800, NULL, NULL, NULL, NULL);
9354     assert(hwnd);
9355     trace("Window for test_PeekMessage2 %p\n", hwnd);
9356     ShowWindow(hwnd, SW_SHOW);
9357     UpdateWindow(hwnd);
9358     SetFocus(hwnd);
9359     GetCursorPos(&pos);
9360     SetCursorPos(100, 100);
9361     mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
9362     flush_events();
9363
9364     /* Do initial mousemove, wait until we can see it
9365        and then do our test peek with PM_NOREMOVE. */
9366     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9367     wait_move_event(hwnd, 80, 80);
9368
9369     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9370     ok(ret, "no message available\n");
9371     if (ret) {
9372         trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9373         message = msg.message;
9374         time1 = msg.time;
9375         x1 = msg.pt.x;
9376         y1 = msg.pt.y;
9377         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9378         PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE);
9379     }
9380
9381     /* Allow time to advance a bit, and then simulate the user moving their
9382      * mouse around. After that we peek again with PM_NOREMOVE.
9383      * Although the previous mousemove message was never removed, the
9384      * mousemove we now peek should reflect the recent mouse movements
9385      * because the input queue will merge the move events. */
9386     Sleep(2);
9387     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9388     wait_move_event(hwnd, x1, y1);
9389
9390     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9391     ok(ret, "no message available\n");
9392     if (ret) {
9393         trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9394         message = msg.message;
9395         time2 = msg.time;
9396         x2 = msg.pt.x;
9397         y2 = msg.pt.y;
9398         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9399         ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
9400         ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
9401         PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE);
9402     }
9403
9404     /* Have another go, to drive the point home */
9405     Sleep(2);
9406     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9407     wait_move_event(hwnd, x2, y2);
9408
9409     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9410     ok(ret, "no message available\n");
9411     if (ret) {
9412         trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9413         message = msg.message;
9414         time3 = msg.time;
9415         x3 = msg.pt.x;
9416         y3 = msg.pt.y;
9417         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9418         ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
9419         ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
9420     }
9421
9422     DestroyWindow(hwnd);
9423     SetCursorPos(pos.x, pos.y);
9424     flush_events();
9425 }
9426
9427 static void test_quit_message(void)
9428 {
9429     MSG msg;
9430     BOOL ret;
9431
9432     /* test using PostQuitMessage */
9433     flush_events();
9434     PostQuitMessage(0xbeef);
9435
9436     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9437     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9438     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9439     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9440
9441     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9442     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9443
9444     ret = GetMessage(&msg, NULL, 0, 0);
9445     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9446     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9447
9448     /* note: WM_QUIT message received after WM_USER message */
9449     ret = GetMessage(&msg, NULL, 0, 0);
9450     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9451     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9452     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9453
9454     ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
9455     ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
9456
9457     /* now test with PostThreadMessage - different behaviour! */
9458     PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
9459
9460     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9461     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9462     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9463     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9464
9465     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9466     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9467
9468     /* note: we receive the WM_QUIT message first this time */
9469     ret = GetMessage(&msg, NULL, 0, 0);
9470     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9471     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9472     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9473
9474     ret = GetMessage(&msg, NULL, 0, 0);
9475     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9476     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9477 }
9478
9479 static const struct message WmMouseHoverSeq[] = {
9480     { WM_MOUSEACTIVATE, sent|optional },  /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
9481     { WM_MOUSEACTIVATE, sent|optional },
9482     { WM_TIMER, sent|optional }, /* XP sends it */
9483     { WM_SYSTIMER, sent },
9484     { WM_MOUSEHOVER, sent|wparam, 0 },
9485     { 0 }
9486 };
9487
9488 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
9489 {
9490     MSG msg;
9491     DWORD start_ticks, end_ticks;
9492
9493     start_ticks = GetTickCount();
9494     /* add some deviation (50%) to cover not expected delays */
9495     start_ticks += timeout / 2;
9496
9497     do
9498     {
9499         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
9500         {
9501             /* Timer proc messages are not dispatched to the window proc,
9502              * and therefore not logged.
9503              */
9504             if (msg.message == WM_TIMER || msg.message == WM_SYSTIMER)
9505             {
9506                 struct recvd_message s_msg;
9507
9508                 s_msg.hwnd = msg.hwnd;
9509                 s_msg.message = msg.message;
9510                 s_msg.flags = sent|wparam|lparam;
9511                 s_msg.wParam = msg.wParam;
9512                 s_msg.lParam = msg.lParam;
9513                 s_msg.descr = "msg_loop";
9514                 add_message(&s_msg);
9515             }
9516             DispatchMessage(&msg);
9517         }
9518
9519         end_ticks = GetTickCount();
9520
9521         /* inject WM_MOUSEMOVE to see how it changes tracking */
9522         if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
9523         {
9524             mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9525             mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9526
9527             inject_mouse_move = FALSE;
9528         }
9529     } while (start_ticks + timeout >= end_ticks);
9530 }
9531
9532 static void test_TrackMouseEvent(void)
9533 {
9534     TRACKMOUSEEVENT tme;
9535     BOOL ret;
9536     HWND hwnd, hchild;
9537     RECT rc_parent, rc_child;
9538     UINT default_hover_time, hover_width = 0, hover_height = 0;
9539
9540 #define track_hover(track_hwnd, track_hover_time) \
9541     tme.cbSize = sizeof(tme); \
9542     tme.dwFlags = TME_HOVER; \
9543     tme.hwndTrack = track_hwnd; \
9544     tme.dwHoverTime = track_hover_time; \
9545     SetLastError(0xdeadbeef); \
9546     ret = pTrackMouseEvent(&tme); \
9547     ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
9548
9549 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
9550     tme.cbSize = sizeof(tme); \
9551     tme.dwFlags = TME_QUERY; \
9552     tme.hwndTrack = (HWND)0xdeadbeef; \
9553     tme.dwHoverTime = 0xdeadbeef; \
9554     SetLastError(0xdeadbeef); \
9555     ret = pTrackMouseEvent(&tme); \
9556     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
9557     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
9558     ok(tme.dwFlags == (expected_track_flags), \
9559        "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
9560     ok(tme.hwndTrack == (expected_track_hwnd), \
9561        "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
9562     ok(tme.dwHoverTime == (expected_hover_time), \
9563        "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
9564
9565 #define track_hover_cancel(track_hwnd) \
9566     tme.cbSize = sizeof(tme); \
9567     tme.dwFlags = TME_HOVER | TME_CANCEL; \
9568     tme.hwndTrack = track_hwnd; \
9569     tme.dwHoverTime = 0xdeadbeef; \
9570     SetLastError(0xdeadbeef); \
9571     ret = pTrackMouseEvent(&tme); \
9572     ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
9573
9574     default_hover_time = 0xdeadbeef;
9575     SetLastError(0xdeadbeef);
9576     ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
9577     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9578        "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
9579     if (!ret) default_hover_time = 400;
9580     trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
9581
9582     SetLastError(0xdeadbeef);
9583     ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
9584     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9585        "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
9586     if (!ret) hover_width = 4;
9587     SetLastError(0xdeadbeef);
9588     ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
9589     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9590        "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
9591     if (!ret) hover_height = 4;
9592     trace("hover rect is %u x %d\n", hover_width, hover_height);
9593
9594     hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
9595                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9596                           CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
9597                           NULL, NULL, 0);
9598     assert(hwnd);
9599
9600     hchild = CreateWindowEx(0, "TestWindowClass", NULL,
9601                           WS_CHILD | WS_BORDER | WS_VISIBLE,
9602                           50, 50, 200, 200, hwnd,
9603                           NULL, NULL, 0);
9604     assert(hchild);
9605
9606     SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
9607     flush_events();
9608     flush_sequence();
9609
9610     tme.cbSize = 0;
9611     tme.dwFlags = TME_QUERY;
9612     tme.hwndTrack = (HWND)0xdeadbeef;
9613     tme.dwHoverTime = 0xdeadbeef;
9614     SetLastError(0xdeadbeef);
9615     ret = pTrackMouseEvent(&tme);
9616     ok(!ret, "TrackMouseEvent should fail\n");
9617     ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef),
9618        "not expected error %u\n", GetLastError());
9619
9620     tme.cbSize = sizeof(tme);
9621     tme.dwFlags = TME_HOVER;
9622     tme.hwndTrack = (HWND)0xdeadbeef;
9623     tme.dwHoverTime = 0xdeadbeef;
9624     SetLastError(0xdeadbeef);
9625     ret = pTrackMouseEvent(&tme);
9626     ok(!ret, "TrackMouseEvent should fail\n");
9627     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
9628        "not expected error %u\n", GetLastError());
9629
9630     tme.cbSize = sizeof(tme);
9631     tme.dwFlags = TME_HOVER | TME_CANCEL;
9632     tme.hwndTrack = (HWND)0xdeadbeef;
9633     tme.dwHoverTime = 0xdeadbeef;
9634     SetLastError(0xdeadbeef);
9635     ret = pTrackMouseEvent(&tme);
9636     ok(!ret, "TrackMouseEvent should fail\n");
9637     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
9638        "not expected error %u\n", GetLastError());
9639
9640     GetWindowRect(hwnd, &rc_parent);
9641     GetWindowRect(hchild, &rc_child);
9642     SetCursorPos(rc_child.left - 10, rc_child.top - 10);
9643
9644     /* Process messages so that the system updates its internal current
9645      * window and hittest, otherwise TrackMouseEvent calls don't have any
9646      * effect.
9647      */
9648     flush_events();
9649     flush_sequence();
9650
9651     track_query(0, NULL, 0);
9652     track_hover(hchild, 0);
9653     track_query(0, NULL, 0);
9654
9655     flush_events();
9656     flush_sequence();
9657
9658     track_hover(hwnd, 0);
9659     track_query(TME_HOVER, hwnd, default_hover_time);
9660
9661     pump_msg_loop_timeout(default_hover_time, FALSE);
9662     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9663
9664     track_query(0, NULL, 0);
9665
9666     track_hover(hwnd, HOVER_DEFAULT);
9667     track_query(TME_HOVER, hwnd, default_hover_time);
9668
9669     Sleep(default_hover_time / 2);
9670     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9671     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9672
9673     track_query(TME_HOVER, hwnd, default_hover_time);
9674
9675     pump_msg_loop_timeout(default_hover_time / 2, FALSE);
9676     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9677
9678     track_query(0, NULL, 0);
9679
9680     track_hover(hwnd, HOVER_DEFAULT);
9681     track_query(TME_HOVER, hwnd, default_hover_time);
9682
9683     pump_msg_loop_timeout(default_hover_time, TRUE);
9684     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9685
9686     track_query(0, NULL, 0);
9687
9688     track_hover(hwnd, HOVER_DEFAULT);
9689     track_query(TME_HOVER, hwnd, default_hover_time);
9690     track_hover_cancel(hwnd);
9691
9692     DestroyWindow(hwnd);
9693
9694 #undef track_hover
9695 #undef track_query
9696 #undef track_hover_cancel
9697 }
9698
9699
9700 static const struct message WmSetWindowRgn[] = {
9701     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9702     { WM_NCCALCSIZE, sent|wparam, 1 },
9703     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
9704     { WM_GETTEXT, sent|defwinproc|optional },
9705     { WM_ERASEBKGND, sent|optional },
9706     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9707     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9708     { 0 }
9709 };
9710
9711 static const struct message WmSetWindowRgn_no_redraw[] = {
9712     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9713     { WM_NCCALCSIZE, sent|wparam, 1 },
9714     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9715     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9716     { 0 }
9717 };
9718
9719 static const struct message WmSetWindowRgn_clear[] = {
9720     { WM_WINDOWPOSCHANGING, sent/*|wparam*/, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE/*|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE only on some Windows versions */ },
9721     { WM_NCCALCSIZE, sent|wparam, 1 },
9722     { WM_NCPAINT, sent|optional },
9723     { WM_GETTEXT, sent|defwinproc|optional },
9724     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
9725     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9726     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
9727     { WM_NCPAINT, sent|optional },
9728     { WM_GETTEXT, sent|defwinproc|optional },
9729     { WM_ERASEBKGND, sent|optional },
9730     { WM_WINDOWPOSCHANGING, sent|optional },
9731     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
9732     { WM_NCPAINT, sent|optional },
9733     { WM_GETTEXT, sent|defwinproc|optional },
9734     { WM_ERASEBKGND, sent|optional },
9735     { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9736     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
9737     { WM_NCPAINT, sent|optional },
9738     { WM_GETTEXT, sent|defwinproc|optional },
9739     { WM_ERASEBKGND, sent|optional },
9740     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9741     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9742     { 0 }
9743 };
9744
9745 static void test_SetWindowRgn(void)
9746 {
9747     HRGN hrgn;
9748     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
9749                                 100, 100, 200, 200, 0, 0, 0, NULL);
9750     ok( hwnd != 0, "Failed to create overlapped window\n" );
9751
9752     ShowWindow( hwnd, SW_SHOW );
9753     UpdateWindow( hwnd );
9754     flush_events();
9755     flush_sequence();
9756
9757     trace("testing SetWindowRgn\n");
9758     hrgn = CreateRectRgn( 0, 0, 150, 150 );
9759     SetWindowRgn( hwnd, hrgn, TRUE );
9760     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
9761
9762     hrgn = CreateRectRgn( 30, 30, 160, 160 );
9763     SetWindowRgn( hwnd, hrgn, FALSE );
9764     ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
9765
9766     hrgn = CreateRectRgn( 0, 0, 180, 180 );
9767     SetWindowRgn( hwnd, hrgn, TRUE );
9768     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
9769
9770     SetWindowRgn( hwnd, 0, TRUE );
9771     ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
9772
9773     DestroyWindow( hwnd );
9774 }
9775
9776 /*************************** ShowWindow() test ******************************/
9777 static const struct message WmShowNormal[] = {
9778     { WM_SHOWWINDOW, sent|wparam, 1 },
9779     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9780     { HCBT_ACTIVATE, hook },
9781     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9782     { HCBT_SETFOCUS, hook },
9783     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9784     { 0 }
9785 };
9786 static const struct message WmShow[] = {
9787     { WM_SHOWWINDOW, sent|wparam, 1 },
9788     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9789     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9790     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9791     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9792     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9793     { 0 }
9794 };
9795 static const struct message WmShowNoActivate_1[] = {
9796     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9797     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9798     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9799     { WM_MOVE, sent|defwinproc|optional },
9800     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9801     { 0 }
9802 };
9803 static const struct message WmShowNoActivate_2[] = {
9804     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9805     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9806     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9807     { WM_MOVE, sent|defwinproc },
9808     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9809     { HCBT_SETFOCUS, hook|optional },
9810     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9811     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9812     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9813     { 0 }
9814 };
9815 static const struct message WmShowNA_1[] = {
9816     { WM_SHOWWINDOW, sent|wparam, 1 },
9817     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9818     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9819     { 0 }
9820 };
9821 static const struct message WmShowNA_2[] = {
9822     { WM_SHOWWINDOW, sent|wparam, 1 },
9823     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9824     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9825     { 0 }
9826 };
9827 static const struct message WmRestore_1[] = {
9828     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9829     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9830     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9831     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9832     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9833     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9834     { WM_MOVE, sent|defwinproc },
9835     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9836     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9837     { 0 }
9838 };
9839 static const struct message WmRestore_2[] = {
9840     { WM_SHOWWINDOW, sent|wparam, 1 },
9841     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9842     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9843     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9844     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9845     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9846     { 0 }
9847 };
9848 static const struct message WmRestore_3[] = {
9849     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9850     { WM_GETMINMAXINFO, sent },
9851     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9852     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9853     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9854     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9855     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9856     { WM_MOVE, sent|defwinproc },
9857     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9858     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9859     { 0 }
9860 };
9861 static const struct message WmRestore_4[] = {
9862     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9863     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9864     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9865     { WM_MOVE, sent|defwinproc|optional },
9866     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9867     { 0 }
9868 };
9869 static const struct message WmRestore_5[] = {
9870     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
9871     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9872     { HCBT_ACTIVATE, hook|optional },
9873     { HCBT_SETFOCUS, hook|optional },
9874     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9875     { WM_MOVE, sent|defwinproc|optional },
9876     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9877     { 0 }
9878 };
9879 static const struct message WmHide_1[] = {
9880     { WM_SHOWWINDOW, sent|wparam, 0 },
9881     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9882     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9883     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9884     { 0 }
9885 };
9886 static const struct message WmHide_2[] = {
9887     { WM_SHOWWINDOW, sent|wparam, 0 },
9888     { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9889     { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9890     { 0 }
9891 };
9892 static const struct message WmHide_3[] = {
9893     { WM_SHOWWINDOW, sent|wparam, 0 },
9894     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9895     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9896     { HCBT_SETFOCUS, hook|optional },
9897     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9898     { 0 }
9899 };
9900 static const struct message WmShowMinimized_1[] = {
9901     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9902     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9903     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9904     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9905     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9906     { WM_MOVE, sent|defwinproc },
9907     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9908     { 0 }
9909 };
9910 static const struct message WmMinimize_1[] = {
9911     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9912     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9913     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9914     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9915     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9916     { WM_MOVE, sent|defwinproc },
9917     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9918     { 0 }
9919 };
9920 static const struct message WmMinimize_2[] = {
9921     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9922     { HCBT_SETFOCUS, hook|optional },
9923     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9924     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9925     { WM_MOVE, sent|defwinproc },
9926     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9927     { 0 }
9928 };
9929 static const struct message WmMinimize_3[] = {
9930     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9931     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9932     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9933     { WM_MOVE, sent|defwinproc },
9934     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9935     { 0 }
9936 };
9937 static const struct message WmShowMinNoActivate[] = {
9938     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9939     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9940     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9941     { 0 }
9942 };
9943 static const struct message WmMinMax_1[] = {
9944     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9945     { 0 }
9946 };
9947 static const struct message WmMinMax_2[] = {
9948     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9949     { WM_GETMINMAXINFO, sent|optional },
9950     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED },
9951     { HCBT_ACTIVATE, hook|optional },
9952     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
9953     { HCBT_SETFOCUS, hook|optional },
9954     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9955     { WM_MOVE, sent|defwinproc|optional },
9956     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MAXIMIZED },
9957     { HCBT_SETFOCUS, hook|optional },
9958     { 0 }
9959 };
9960 static const struct message WmMinMax_3[] = {
9961     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9962     { 0 }
9963 };
9964 static const struct message WmMinMax_4[] = {
9965     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9966     { 0 }
9967 };
9968 static const struct message WmShowMaximized_1[] = {
9969     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9970     { WM_GETMINMAXINFO, sent },
9971     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9972     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9973     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9974     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9975     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9976     { WM_MOVE, sent|defwinproc },
9977     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9978     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9979     { 0 }
9980 };
9981 static const struct message WmShowMaximized_2[] = {
9982     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9983     { WM_GETMINMAXINFO, sent },
9984     { WM_WINDOWPOSCHANGING, sent|optional },
9985     { HCBT_ACTIVATE, hook|optional },
9986     { WM_WINDOWPOSCHANGED, sent|optional },
9987     { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
9988     { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
9989     { WM_WINDOWPOSCHANGING, sent },
9990     { HCBT_SETFOCUS, hook|optional },
9991     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9992     { WM_MOVE, sent|defwinproc },
9993     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9994     { HCBT_SETFOCUS, hook|optional },
9995     { 0 }
9996 };
9997 static const struct message WmShowMaximized_3[] = {
9998     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9999     { WM_GETMINMAXINFO, sent },
10000     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10001     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10002     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10003     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10004     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10005     { WM_MOVE, sent|defwinproc|optional },
10006     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10007     { 0 }
10008 };
10009
10010 static void test_ShowWindow(void)
10011 {
10012     /* ShowWindow commands in random order */
10013     static const struct
10014     {
10015         INT cmd; /* ShowWindow command */
10016         LPARAM ret; /* ShowWindow return value */
10017         DWORD style; /* window style after the command */
10018         const struct message *msg; /* message sequence the command produces */
10019         BOOL todo_msg; /* message sequence doesn't match what Wine does */
10020     } sw[] =
10021     {
10022 /*  1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
10023 /*  2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10024 /*  3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10025 /*  4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10026 /*  5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
10027 /*  6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
10028 /*  7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
10029 /*  8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10030 /*  9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
10031 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10032 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
10033 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
10034 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
10035 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10036 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
10037 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10038 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
10039 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10040 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10041 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10042 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10043 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
10044 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
10045 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10046 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10047 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
10048 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
10049 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10050 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10051 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
10052 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10053 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, FALSE },
10054 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10055 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE }, /* what does this mean?! */
10056 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE },
10057 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10058 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
10059 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10060 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10061 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, FALSE },
10062 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10063 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, TRUE },
10064 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10065 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10066 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10067 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
10068 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
10069 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
10070 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
10071 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
10072 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10073 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10074 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10075 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, FALSE },
10076 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10077 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
10078 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
10079     };
10080     HWND hwnd;
10081     DWORD style;
10082     LPARAM ret;
10083     INT i;
10084
10085 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
10086     hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
10087                           120, 120, 90, 90,
10088                           0, 0, 0, NULL);
10089     assert(hwnd);
10090
10091     style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10092     ok(style == 0, "expected style 0, got %08x\n", style);
10093
10094     flush_events();
10095     flush_sequence();
10096
10097     for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
10098     {
10099         static const char * const sw_cmd_name[13] =
10100         {
10101             "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
10102             "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
10103             "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
10104             "SW_NORMALNA" /* 0xCC */
10105         };
10106         char comment[64];
10107         INT idx; /* index into the above array of names */
10108
10109         idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
10110
10111         style = GetWindowLong(hwnd, GWL_STYLE);
10112         trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
10113         ret = ShowWindow(hwnd, sw[i].cmd);
10114         ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
10115         style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10116         ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
10117
10118         sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
10119         ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
10120
10121         flush_events();
10122         flush_sequence();
10123     }
10124
10125     DestroyWindow(hwnd);
10126 }
10127
10128 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
10129 {
10130     struct recvd_message msg;
10131
10132     switch (message)
10133     {
10134     case WM_GETICON:
10135     case WM_GETOBJECT:
10136         return 0;  /* ignore them */
10137     }
10138
10139     msg.hwnd = hwnd;
10140     msg.message = message;
10141     msg.flags = sent|wparam|lparam;
10142     msg.wParam = wParam;
10143     msg.lParam = lParam;
10144     msg.descr = "dialog";
10145     add_message(&msg);
10146
10147     /* calling DefDlgProc leads to a recursion under XP */
10148
10149     switch (message)
10150     {
10151     case WM_INITDIALOG:
10152     case WM_GETDLGCODE:
10153         return 0;
10154     }
10155     return 1;
10156 }
10157
10158 static const struct message WmDefDlgSetFocus_1[] = {
10159     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10160     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10161     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10162     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10163     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10164     { HCBT_SETFOCUS, hook },
10165     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
10166     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10167     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10168     { WM_SETFOCUS, sent|wparam, 0 },
10169     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
10170     { WM_CTLCOLOREDIT, sent },
10171     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
10172     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10173     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10174     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10175     { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
10176     { 0 }
10177 };
10178 static const struct message WmDefDlgSetFocus_2[] = {
10179     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10180     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10181     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10182     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10183     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10184     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10185     { WM_CTLCOLOREDIT, sent|optional }, /* XP */
10186     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10187     { 0 }
10188 };
10189 /* Creation of a dialog */
10190 static const struct message WmCreateDialogParamSeq_1[] = {
10191     { HCBT_CREATEWND, hook },
10192     { WM_NCCREATE, sent },
10193     { WM_NCCALCSIZE, sent|wparam, 0 },
10194     { WM_CREATE, sent },
10195     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10196     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10197     { WM_MOVE, sent },
10198     { WM_SETFONT, sent },
10199     { WM_INITDIALOG, sent },
10200     { WM_CHANGEUISTATE, sent|optional },
10201     { 0 }
10202 };
10203 /* Creation of a dialog */
10204 static const struct message WmCreateDialogParamSeq_2[] = {
10205     { HCBT_CREATEWND, hook },
10206     { WM_NCCREATE, sent },
10207     { WM_NCCALCSIZE, sent|wparam, 0 },
10208     { WM_CREATE, sent },
10209     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10210     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10211     { WM_MOVE, sent },
10212     { WM_CHANGEUISTATE, sent|optional },
10213     { 0 }
10214 };
10215
10216 static void test_dialog_messages(void)
10217 {
10218     WNDCLASS cls;
10219     HWND hdlg, hedit1, hedit2, hfocus;
10220     LRESULT ret;
10221
10222 #define set_selection(hctl, start, end) \
10223     ret = SendMessage(hctl, EM_SETSEL, start, end); \
10224     ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
10225
10226 #define check_selection(hctl, start, end) \
10227     ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
10228     ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
10229
10230     subclass_edit();
10231
10232     hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
10233                           WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
10234                           0, 0, 100, 100, 0, 0, 0, NULL);
10235     ok(hdlg != 0, "Failed to create custom dialog window\n");
10236
10237     hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
10238                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10239                            0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
10240     ok(hedit1 != 0, "Failed to create edit control\n");
10241     hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
10242                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10243                            0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
10244     ok(hedit2 != 0, "Failed to create edit control\n");
10245
10246     SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
10247     SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
10248
10249     hfocus = GetFocus();
10250     ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
10251
10252     SetFocus(hedit2);
10253     hfocus = GetFocus();
10254     ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
10255
10256     check_selection(hedit1, 0, 0);
10257     check_selection(hedit2, 0, 0);
10258
10259     set_selection(hedit2, 0, -1);
10260     check_selection(hedit2, 0, 3);
10261
10262     SetFocus(0);
10263     hfocus = GetFocus();
10264     ok(hfocus == 0, "wrong focus %p\n", hfocus);
10265
10266     flush_sequence();
10267     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10268     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10269     ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
10270
10271     hfocus = GetFocus();
10272     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10273
10274     check_selection(hedit1, 0, 5);
10275     check_selection(hedit2, 0, 3);
10276
10277     flush_sequence();
10278     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10279     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10280     ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
10281
10282     hfocus = GetFocus();
10283     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10284
10285     check_selection(hedit1, 0, 5);
10286     check_selection(hedit2, 0, 3);
10287
10288     EndDialog(hdlg, 0);
10289     DestroyWindow(hedit1);
10290     DestroyWindow(hedit2);
10291     DestroyWindow(hdlg);
10292     flush_sequence();
10293
10294 #undef set_selection
10295 #undef check_selection
10296
10297     ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
10298     cls.lpszClassName = "MyDialogClass";
10299     cls.hInstance = GetModuleHandle(0);
10300     /* need a cast since a dlgproc is used as a wndproc */
10301     cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
10302     if (!RegisterClass(&cls)) assert(0);
10303
10304     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
10305     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10306     ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
10307     EndDialog(hdlg, 0);
10308     DestroyWindow(hdlg);
10309     flush_sequence();
10310
10311     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
10312     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10313     ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
10314     EndDialog(hdlg, 0);
10315     DestroyWindow(hdlg);
10316     flush_sequence();
10317
10318     UnregisterClass(cls.lpszClassName, cls.hInstance);
10319 }
10320
10321 static void test_nullCallback(void)
10322 {
10323     HWND hwnd;
10324
10325     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10326                            100, 100, 200, 200, 0, 0, 0, NULL);
10327     ok (hwnd != 0, "Failed to create overlapped window\n");
10328
10329     SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
10330     flush_events();
10331     DestroyWindow(hwnd);
10332 }
10333
10334 /* SetActiveWindow( 0 ) hwnd visible */
10335 static const struct message SetActiveWindowSeq0[] =
10336 {
10337     { HCBT_ACTIVATE, hook },
10338     { WM_NCACTIVATE, sent|wparam, 0 },
10339     { WM_GETTEXT, sent|defwinproc|optional },
10340     { WM_ACTIVATE, sent|wparam, 0 },
10341     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10342     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10343     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10344     { WM_NCACTIVATE, sent|wparam, 1 },
10345     { WM_GETTEXT, sent|defwinproc|optional },
10346     { WM_ACTIVATE, sent|wparam, 1 },
10347     { HCBT_SETFOCUS, hook },
10348     { WM_KILLFOCUS, sent|defwinproc },
10349     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10350     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10351     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10352     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10353     { WM_SETFOCUS, sent|defwinproc },
10354     { WM_GETTEXT, sent|optional },
10355     { 0 }
10356 };
10357 /* SetActiveWindow( hwnd ) hwnd visible */
10358 static const struct message SetActiveWindowSeq1[] =
10359 {
10360     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10361     { 0 }
10362 };
10363 /* SetActiveWindow( popup ) hwnd visible, popup visible */
10364 static const struct message SetActiveWindowSeq2[] =
10365 {
10366     { HCBT_ACTIVATE, hook },
10367     { WM_NCACTIVATE, sent|wparam, 0 },
10368     { WM_GETTEXT, sent|defwinproc|optional },
10369     { WM_ACTIVATE, sent|wparam, 0 },
10370     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10371     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10372     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10373     { WM_NCPAINT, sent|optional },
10374     { WM_GETTEXT, sent|defwinproc|optional },
10375     { WM_ERASEBKGND, sent|optional },
10376     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10377     { WM_NCACTIVATE, sent|wparam, 1 },
10378     { WM_GETTEXT, sent|defwinproc|optional },
10379     { WM_ACTIVATE, sent|wparam, 1 },
10380     { HCBT_SETFOCUS, hook },
10381     { WM_KILLFOCUS, sent|defwinproc },
10382     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10383     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10384     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10385     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10386     { WM_SETFOCUS, sent|defwinproc },
10387     { WM_GETTEXT, sent|optional },
10388     { 0 }
10389 };
10390
10391 /* SetActiveWindow( hwnd ) hwnd not visible */
10392 static const struct message SetActiveWindowSeq3[] =
10393 {
10394     { HCBT_ACTIVATE, hook },
10395     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10396     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10397     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10398     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10399     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10400     { WM_ACTIVATEAPP, sent|wparam, 1 },
10401     { WM_ACTIVATEAPP, sent|wparam, 1 },
10402     { WM_NCACTIVATE, sent|wparam, 1 },
10403     { WM_ACTIVATE, sent|wparam, 1 },
10404     { HCBT_SETFOCUS, hook },
10405     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10406     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10407     { WM_SETFOCUS, sent|defwinproc },
10408     { 0 }
10409 };
10410 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
10411 static const struct message SetActiveWindowSeq4[] =
10412 {
10413     { HCBT_ACTIVATE, hook },
10414     { WM_NCACTIVATE, sent|wparam, 0 },
10415     { WM_GETTEXT, sent|defwinproc|optional },
10416     { WM_ACTIVATE, sent|wparam, 0 },
10417     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10418     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10419     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10420     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10421     { WM_NCACTIVATE, sent|wparam, 1 },
10422     { WM_GETTEXT, sent|defwinproc|optional },
10423     { WM_ACTIVATE, sent|wparam, 1 },
10424     { HCBT_SETFOCUS, hook },
10425     { WM_KILLFOCUS, sent|defwinproc },
10426     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10427     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10428     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10429     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10430     { WM_SETFOCUS, sent|defwinproc },
10431     { 0 }
10432 };
10433
10434
10435 static void test_SetActiveWindow(void)
10436 {
10437     HWND hwnd, popup, ret;
10438
10439     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10440                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10441                            100, 100, 200, 200, 0, 0, 0, NULL);
10442
10443     popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10444                            WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
10445                            100, 100, 200, 200, hwnd, 0, 0, NULL);
10446
10447     ok(hwnd != 0, "Failed to create overlapped window\n");
10448     ok(popup != 0, "Failed to create popup window\n");
10449     SetForegroundWindow( popup );
10450     flush_sequence();
10451
10452     trace("SetActiveWindow(0)\n");
10453     ret = SetActiveWindow(0);
10454     ok( ret == popup, "Failed to SetActiveWindow(0)\n");
10455     ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", TRUE);
10456     flush_sequence();
10457
10458     trace("SetActiveWindow(hwnd), hwnd visible\n");
10459     ret = SetActiveWindow(hwnd);
10460     todo_wine
10461     {
10462         ok( ret == hwnd, "Failed to SetActiveWindow(hwnd), hwnd visible\n");
10463     }
10464     ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
10465     flush_sequence();
10466
10467     trace("SetActiveWindow(popup), hwnd visible, popup visible\n");
10468     ret = SetActiveWindow(popup);
10469     ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visible\n");
10470     ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visible", FALSE);
10471     flush_sequence();
10472
10473     ShowWindow(hwnd, SW_HIDE);
10474     ShowWindow(popup, SW_HIDE);
10475     flush_sequence();
10476
10477     trace("SetActiveWindow(hwnd), hwnd not visible\n");
10478     ret = SetActiveWindow(hwnd);
10479     ok( ret == NULL, "SetActiveWindow(hwnd), hwnd not visible, previous is %p\n", ret );
10480     ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
10481     flush_sequence();
10482
10483     trace("SetActiveWindow(popup), hwnd not visible, popup not visible\n");
10484     ret = SetActiveWindow(popup);
10485     ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
10486     ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visible", TRUE);
10487     flush_sequence();
10488
10489     trace("done\n");
10490
10491     DestroyWindow(hwnd);
10492 }
10493
10494 static const struct message SetForegroundWindowSeq[] =
10495 {
10496     { WM_NCACTIVATE, sent|wparam, 0 },
10497     { WM_GETTEXT, sent|defwinproc|optional },
10498     { WM_ACTIVATE, sent|wparam, 0 },
10499     { WM_ACTIVATEAPP, sent|wparam, 0 },
10500     { WM_KILLFOCUS, sent },
10501     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
10502     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
10503     { 0 }
10504 };
10505
10506 static void test_SetForegroundWindow(void)
10507 {
10508     HWND hwnd;
10509
10510     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
10511                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10512                            100, 100, 200, 200, 0, 0, 0, NULL);
10513     ok (hwnd != 0, "Failed to create overlapped window\n");
10514     flush_sequence();
10515
10516     trace("SetForegroundWindow( 0 )\n");
10517     SetForegroundWindow( 0 );
10518     ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
10519     trace("SetForegroundWindow( GetDesktopWindow() )\n");
10520     SetForegroundWindow( GetDesktopWindow() );
10521     ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
10522                                         "foreground top level window", FALSE);
10523     trace("done\n");
10524
10525     DestroyWindow(hwnd);
10526 }
10527
10528 static void test_dbcs_wm_char(void)
10529 {
10530     BYTE dbch[2];
10531     WCHAR wch, bad_wch;
10532     HWND hwnd, hwnd2;
10533     MSG msg;
10534     DWORD time;
10535     POINT pt;
10536     DWORD_PTR res;
10537     CPINFOEXA cpinfo;
10538     UINT i, j, k;
10539     struct message wmCharSeq[2];
10540
10541     if (!pGetCPInfoExA)
10542     {
10543         skip("GetCPInfoExA is not available\n");
10544         return;
10545     }
10546
10547     pGetCPInfoExA( CP_ACP, 0, &cpinfo );
10548     if (cpinfo.MaxCharSize != 2)
10549     {
10550         skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
10551         return;
10552     }
10553
10554     dbch[0] = dbch[1] = 0;
10555     wch = 0;
10556     bad_wch = cpinfo.UnicodeDefaultChar;
10557     for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
10558         for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
10559             for (k = 128; k <= 255; k++)
10560             {
10561                 char str[2];
10562                 WCHAR wstr[2];
10563                 str[0] = j;
10564                 str[1] = k;
10565                 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
10566                     WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
10567                     (BYTE)str[0] == j && (BYTE)str[1] == k &&
10568                     HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
10569                 {
10570                     dbch[0] = j;
10571                     dbch[1] = k;
10572                     wch = wstr[0];
10573                     break;
10574                 }
10575             }
10576
10577     if (!wch)
10578     {
10579         skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
10580         return;
10581     }
10582     trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
10583            dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
10584
10585     hwnd = CreateWindowExW(0, testWindowClassW, NULL,
10586                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
10587     hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
10588                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
10589     ok (hwnd != 0, "Failed to create overlapped window\n");
10590     ok (hwnd2 != 0, "Failed to create overlapped window\n");
10591     flush_sequence();
10592
10593     memset( wmCharSeq, 0, sizeof(wmCharSeq) );
10594     wmCharSeq[0].message = WM_CHAR;
10595     wmCharSeq[0].flags = sent|wparam;
10596     wmCharSeq[0].wParam = wch;
10597
10598     /* posted message */
10599     PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10600     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10601     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10602     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10603     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10604     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10605     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10606
10607     /* posted thread message */
10608     PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
10609     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10610     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10611     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10612     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10613     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10614     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10615
10616     /* sent message */
10617     flush_sequence();
10618     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10619     ok_sequence( WmEmptySeq, "no messages", FALSE );
10620     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10621     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10622     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10623
10624     /* sent message with timeout */
10625     flush_sequence();
10626     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10627     ok_sequence( WmEmptySeq, "no messages", FALSE );
10628     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10629     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10630     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10631
10632     /* sent message with timeout and callback */
10633     flush_sequence();
10634     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10635     ok_sequence( WmEmptySeq, "no messages", FALSE );
10636     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10637     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10638     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10639
10640     /* sent message with callback */
10641     flush_sequence();
10642     SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10643     ok_sequence( WmEmptySeq, "no messages", FALSE );
10644     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10645     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10646     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10647
10648     /* direct window proc call */
10649     flush_sequence();
10650     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10651     ok_sequence( WmEmptySeq, "no messages", FALSE );
10652     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10653     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10654
10655     /* dispatch message */
10656     msg.hwnd = hwnd;
10657     msg.message = WM_CHAR;
10658     msg.wParam = dbch[0];
10659     msg.lParam = 0;
10660     DispatchMessageA( &msg );
10661     ok_sequence( WmEmptySeq, "no messages", FALSE );
10662     msg.wParam = dbch[1];
10663     DispatchMessageA( &msg );
10664     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10665
10666     /* window handle is irrelevant */
10667     flush_sequence();
10668     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10669     ok_sequence( WmEmptySeq, "no messages", FALSE );
10670     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10671     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10672     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10673
10674     /* interleaved post and send */
10675     flush_sequence();
10676     PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10677     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10678     ok_sequence( WmEmptySeq, "no messages", FALSE );
10679     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10680     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10681     ok_sequence( WmEmptySeq, "no messages", FALSE );
10682     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10683     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10684     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10685     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10686     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10687     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10688     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10689
10690     /* interleaved sent message and winproc */
10691     flush_sequence();
10692     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10693     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10694     ok_sequence( WmEmptySeq, "no messages", FALSE );
10695     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10696     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10697     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10698     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10699
10700     /* interleaved winproc and dispatch */
10701     msg.hwnd = hwnd;
10702     msg.message = WM_CHAR;
10703     msg.wParam = dbch[0];
10704     msg.lParam = 0;
10705     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10706     DispatchMessageA( &msg );
10707     ok_sequence( WmEmptySeq, "no messages", FALSE );
10708     msg.wParam = dbch[1];
10709     DispatchMessageA( &msg );
10710     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10711     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10712     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10713
10714     /* interleaved sends */
10715     flush_sequence();
10716     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10717     SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
10718     ok_sequence( WmEmptySeq, "no messages", FALSE );
10719     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10720     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10721     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10722     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10723
10724     /* dbcs WM_CHAR */
10725     flush_sequence();
10726     SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
10727     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10728     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10729
10730     /* other char messages are not magic */
10731     PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
10732     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10733     ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
10734     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10735     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10736     PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
10737     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10738     ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
10739     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10740     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10741
10742     /* test retrieving messages */
10743
10744     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10745     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10746     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10747     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10748     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10749     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10750     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10751     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10752     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10753     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10754
10755     /* message filters */
10756     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10757     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10758     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10759     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10760     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10761     /* message id is filtered, hwnd is not */
10762     ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
10763     ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
10764     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10765     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10766     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10767     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10768
10769     /* mixing GetMessage and PostMessage */
10770     PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
10771     ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
10772     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10773     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10774     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10775     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10776     time = msg.time;
10777     pt = msg.pt;
10778     ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
10779     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10780     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10781     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10782     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10783     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10784     ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
10785     ok( msg.pt.x == pt.x && msg.pt.y == pt.y, "bad point %u,%u/%u,%u\n", msg.pt.x, msg.pt.y, pt.x, pt.y );
10786     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10787
10788     /* without PM_REMOVE */
10789     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10790     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10791     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10792     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10793     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10794     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10795     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10796     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10797     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10798     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10799     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10800     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10801     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10802     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10803     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10804     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10805     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10806     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10807
10808     DestroyWindow(hwnd);
10809 }
10810
10811 #define ID_LISTBOX 0x000f
10812
10813 static const struct message wm_lb_setcursel_0[] =
10814 {
10815     { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
10816     { WM_CTLCOLORLISTBOX, sent|parent },
10817     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10818     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10819     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10820     { 0 }
10821 };
10822 static const struct message wm_lb_setcursel_1[] =
10823 {
10824     { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
10825     { WM_CTLCOLORLISTBOX, sent|parent },
10826     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
10827     { WM_CTLCOLORLISTBOX, sent|parent },
10828     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
10829     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10830     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10831     { 0 }
10832 };
10833 static const struct message wm_lb_setcursel_2[] =
10834 {
10835     { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
10836     { WM_CTLCOLORLISTBOX, sent|parent },
10837     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
10838     { WM_CTLCOLORLISTBOX, sent|parent },
10839     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
10840     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10841     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10842     { 0 }
10843 };
10844 static const struct message wm_lb_click_0[] =
10845 {
10846     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
10847     { HCBT_SETFOCUS, hook },
10848     { WM_KILLFOCUS, sent|parent },
10849     { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
10850     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10851     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10852     { WM_SETFOCUS, sent|defwinproc },
10853
10854     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
10855     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
10856     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10857     { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
10858     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
10859
10860     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
10861     { WM_CTLCOLORLISTBOX, sent|parent },
10862     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
10863     { WM_CTLCOLORLISTBOX, sent|parent },
10864     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10865     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
10866
10867     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10868     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10869
10870     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
10871     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
10872     { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
10873     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
10874     { 0 }
10875 };
10876
10877 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
10878
10879 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
10880
10881 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
10882 {
10883     static long defwndproc_counter = 0;
10884     LRESULT ret;
10885     struct recvd_message msg;
10886
10887     /* do not log painting messages */
10888     if (message != WM_PAINT &&
10889         message != WM_NCPAINT &&
10890         message != WM_SYNCPAINT &&
10891         message != WM_ERASEBKGND &&
10892         message != WM_NCHITTEST &&
10893         message != WM_GETTEXT &&
10894         message != WM_GETOBJECT &&
10895         message != WM_GETICON &&
10896         message != WM_DEVICECHANGE)
10897     {
10898         msg.hwnd = hwnd;
10899         msg.message = message;
10900         msg.flags = sent|wparam|lparam;
10901         if (defwndproc_counter) msg.flags |= defwinproc;
10902         msg.wParam = wp;
10903         msg.lParam = lp;
10904         msg.descr = "listbox";
10905         add_message(&msg);
10906     }
10907
10908     defwndproc_counter++;
10909     ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
10910     defwndproc_counter--;
10911
10912     return ret;
10913 }
10914
10915 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
10916                                int caret_index, int top_index, int line)
10917 {
10918     LRESULT ret;
10919
10920     /* calling an orig proc helps to avoid unnecessary message logging */
10921     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
10922     ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
10923     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
10924     ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
10925     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
10926     ok_(__FILE__, line)(ret == caret_index, "expected caret index %d, got %ld\n", caret_index, ret);
10927     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
10928     ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
10929 }
10930
10931 static void test_listbox_messages(void)
10932 {
10933     HWND parent, listbox;
10934     LRESULT ret;
10935
10936     parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW  | WS_VISIBLE,
10937                              100, 100, 200, 200, 0, 0, 0, NULL);
10938     listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
10939                               WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
10940                               10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
10941     listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
10942
10943     check_lb_state(listbox, 0, LB_ERR, 0, 0);
10944
10945     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
10946     ok(ret == 0, "expected 0, got %ld\n", ret);
10947     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
10948     ok(ret == 1, "expected 1, got %ld\n", ret);
10949     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
10950     ok(ret == 2, "expected 2, got %ld\n", ret);
10951
10952     check_lb_state(listbox, 3, LB_ERR, 0, 0);
10953
10954     flush_sequence();
10955
10956     log_all_parent_messages++;
10957
10958     trace("selecting item 0\n");
10959     ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
10960     ok(ret == 0, "expected 0, got %ld\n", ret);
10961     ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
10962     check_lb_state(listbox, 3, 0, 0, 0);
10963     flush_sequence();
10964
10965     trace("selecting item 1\n");
10966     ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
10967     ok(ret == 1, "expected 1, got %ld\n", ret);
10968     ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
10969     check_lb_state(listbox, 3, 1, 1, 0);
10970
10971     trace("selecting item 2\n");
10972     ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
10973     ok(ret == 2, "expected 2, got %ld\n", ret);
10974     ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
10975     check_lb_state(listbox, 3, 2, 2, 0);
10976
10977     trace("clicking on item 0\n");
10978     ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
10979     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
10980     ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
10981     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
10982     ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
10983     check_lb_state(listbox, 3, 0, 0, 0);
10984     flush_sequence();
10985
10986     log_all_parent_messages--;
10987
10988     DestroyWindow(listbox);
10989     DestroyWindow(parent);
10990 }
10991
10992 /*************************** Menu test ******************************/
10993 static const struct message wm_popup_menu_1[] =
10994 {
10995     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
10996     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
10997     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
10998     { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
10999     { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
11000     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
11001     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11002     { WM_INITMENU, sent|lparam, 0, 0 },
11003     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
11004     { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
11005     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
11006     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
11007     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
11008     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11009     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11010     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
11011     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11012     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11013     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11014     { WM_MENUCOMMAND, sent }, /* |wparam, 200 - Win9x */
11015     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11016     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11017     { 0 }
11018 };
11019 static const struct message wm_popup_menu_2[] =
11020 {
11021     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11022     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11023     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11024     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11025     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11026     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11027     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11028     { WM_INITMENU, sent|lparam, 0, 0 },
11029     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11030     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11031     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11032     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11033     { HCBT_CREATEWND, hook },
11034     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11035                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11036     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11037     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11038     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11039     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11040     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11041     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11042     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11043     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11044     { HCBT_DESTROYWND, hook },
11045     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11046     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11047     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11048     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11049     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11050     { WM_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
11051     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11052     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11053     { 0 }
11054 };
11055 static const struct message wm_popup_menu_3[] =
11056 {
11057     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11058     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11059     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11060     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11061     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11062     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11063     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11064     { WM_INITMENU, sent|lparam, 0, 0 },
11065     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11066     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11067     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11068     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11069     { HCBT_CREATEWND, hook },
11070     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11071                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11072     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11073     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11074     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11075     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11076     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11077     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11078     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11079     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11080     { HCBT_DESTROYWND, hook },
11081     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11082     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11083     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11084     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11085     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11086     { WM_COMMAND, sent|wparam|lparam, 100, 0 },
11087     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11088     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11089     { 0 }
11090 };
11091
11092 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11093 {
11094     if (message == WM_ENTERIDLE ||
11095         message == WM_INITMENU ||
11096         message == WM_INITMENUPOPUP ||
11097         message == WM_MENUSELECT ||
11098         message == WM_PARENTNOTIFY ||
11099         message == WM_ENTERMENULOOP ||
11100         message == WM_EXITMENULOOP ||
11101         message == WM_UNINITMENUPOPUP ||
11102         message == WM_KEYDOWN ||
11103         message == WM_KEYUP ||
11104         message == WM_CHAR ||
11105         message == WM_SYSKEYDOWN ||
11106         message == WM_SYSKEYUP ||
11107         message == WM_SYSCHAR ||
11108         message == WM_COMMAND ||
11109         message == WM_MENUCOMMAND)
11110     {
11111         struct recvd_message msg;
11112
11113         msg.hwnd = hwnd;
11114         msg.message = message;
11115         msg.flags = sent|wparam|lparam;
11116         msg.wParam = wp;
11117         msg.lParam = lp;
11118         msg.descr = "parent_menu_proc";
11119         add_message(&msg);
11120     }
11121
11122     return DefWindowProcA(hwnd, message, wp, lp);
11123 }
11124
11125 static void set_menu_style(HMENU hmenu, DWORD style)
11126 {
11127     MENUINFO mi;
11128     BOOL ret;
11129
11130     mi.cbSize = sizeof(mi);
11131     mi.fMask = MIM_STYLE;
11132     mi.dwStyle = style;
11133     SetLastError(0xdeadbeef);
11134     ret = pSetMenuInfo(hmenu, &mi);
11135     ok(ret, "SetMenuInfo error %u\n", GetLastError());
11136 }
11137
11138 static DWORD get_menu_style(HMENU hmenu)
11139 {
11140     MENUINFO mi;
11141     BOOL ret;
11142
11143     mi.cbSize = sizeof(mi);
11144     mi.fMask = MIM_STYLE;
11145     mi.dwStyle = 0;
11146     SetLastError(0xdeadbeef);
11147     ret = pGetMenuInfo(hmenu, &mi);
11148     ok(ret, "GetMenuInfo error %u\n", GetLastError());
11149
11150     return mi.dwStyle;
11151 }
11152
11153 static void test_menu_messages(void)
11154 {
11155     MSG msg;
11156     WNDCLASSA cls;
11157     HMENU hmenu, hmenu_popup;
11158     HWND hwnd;
11159     DWORD style;
11160
11161     if (!pGetMenuInfo || !pSetMenuInfo)
11162     {
11163         skip("GetMenuInfo and/or SetMenuInfo are not available\n");
11164         return;
11165     }
11166     cls.style = 0;
11167     cls.lpfnWndProc = parent_menu_proc;
11168     cls.cbClsExtra = 0;
11169     cls.cbWndExtra = 0;
11170     cls.hInstance = GetModuleHandleA(0);
11171     cls.hIcon = 0;
11172     cls.hCursor = LoadCursorA(0, IDC_ARROW);
11173     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
11174     cls.lpszMenuName = NULL;
11175     cls.lpszClassName = "TestMenuClass";
11176     UnregisterClass(cls.lpszClassName, cls.hInstance);
11177     if (!RegisterClassA(&cls)) assert(0);
11178
11179     SetLastError(0xdeadbeef);
11180     hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11181                            100, 100, 200, 200, 0, 0, 0, NULL);
11182     ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
11183
11184     SetLastError(0xdeadbeef);
11185     hmenu = LoadMenuA(GetModuleHandle(0), MAKEINTRESOURCE(1));
11186     ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
11187
11188     SetMenu(hwnd, hmenu);
11189     SetForegroundWindow( hwnd );
11190
11191     set_menu_style(hmenu, MNS_NOTIFYBYPOS);
11192     style = get_menu_style(hmenu);
11193     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11194
11195     hmenu_popup = GetSubMenu(hmenu, 0);
11196     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11197     style = get_menu_style(hmenu_popup);
11198     ok(style == 0, "expected 0, got %u\n", style);
11199
11200     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11201     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11202     style = get_menu_style(hmenu_popup);
11203     ok(style == 0, "expected 0, got %u\n", style);
11204
11205     /* Alt+E, Enter */
11206     trace("testing a popup menu command\n");
11207     flush_sequence();
11208     keybd_event(VK_MENU, 0, 0, 0);
11209     keybd_event('E', 0, 0, 0);
11210     keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
11211     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11212     keybd_event(VK_RETURN, 0, 0, 0);
11213     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11214     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11215     {
11216         TranslateMessage(&msg);
11217         DispatchMessage(&msg);
11218     }
11219     ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
11220
11221     /* Alt+F, Right, Enter */
11222     trace("testing submenu of a popup menu command\n");
11223     flush_sequence();
11224     keybd_event(VK_MENU, 0, 0, 0);
11225     keybd_event('F', 0, 0, 0);
11226     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11227     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11228     keybd_event(VK_RIGHT, 0, 0, 0);
11229     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11230     keybd_event(VK_RETURN, 0, 0, 0);
11231     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11232     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11233     {
11234         TranslateMessage(&msg);
11235         DispatchMessage(&msg);
11236     }
11237     ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
11238
11239     set_menu_style(hmenu, 0);
11240     style = get_menu_style(hmenu);
11241     ok(style == 0, "expected 0, got %u\n", style);
11242
11243     hmenu_popup = GetSubMenu(hmenu, 0);
11244     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11245     set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
11246     style = get_menu_style(hmenu_popup);
11247     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11248
11249     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11250     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11251     style = get_menu_style(hmenu_popup);
11252     ok(style == 0, "expected 0, got %u\n", style);
11253
11254     /* Alt+F, Right, Enter */
11255     trace("testing submenu of a popup menu command\n");
11256     flush_sequence();
11257     keybd_event(VK_MENU, 0, 0, 0);
11258     keybd_event('F', 0, 0, 0);
11259     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11260     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11261     keybd_event(VK_RIGHT, 0, 0, 0);
11262     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11263     keybd_event(VK_RETURN, 0, 0, 0);
11264     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11265     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11266     {
11267         TranslateMessage(&msg);
11268         DispatchMessage(&msg);
11269     }
11270     ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
11271
11272     DestroyWindow(hwnd);
11273     DestroyMenu(hmenu);
11274 }
11275
11276
11277 static void test_paintingloop(void)
11278 {
11279     HWND hwnd;
11280
11281     paint_loop_done = 0;
11282     hwnd = CreateWindowExA(0x0,"PaintLoopWindowClass",
11283                                "PaintLoopWindowClass",WS_OVERLAPPEDWINDOW,
11284                                 100, 100, 100, 100, 0, 0, 0, NULL );
11285     ok(hwnd != 0, "PaintLoop window error %u\n", GetLastError());
11286     ShowWindow(hwnd,SW_NORMAL);
11287     SetFocus(hwnd);
11288
11289     while (!paint_loop_done)
11290     {
11291         MSG msg;
11292         if (PeekMessageA(&msg, 0, 0, 0, 1))
11293         {
11294             TranslateMessage(&msg);
11295             DispatchMessage(&msg);
11296         }
11297     }
11298     DestroyWindow(hwnd);
11299 }
11300
11301 START_TEST(msg)
11302 {
11303     BOOL ret;
11304     FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
11305
11306     init_procs();
11307
11308     if (!RegisterWindowClasses()) assert(0);
11309
11310     if (pSetWinEventHook)
11311     {
11312         hEvent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
11313                                                       GetModuleHandleA(0),
11314                                                       win_event_proc,
11315                                                       0,
11316                                                       GetCurrentThreadId(),
11317                                                       WINEVENT_INCONTEXT);
11318         assert(hEvent_hook);
11319
11320         if (pIsWinEventHookInstalled)
11321         {
11322             UINT event;
11323             for (event = EVENT_MIN; event <= EVENT_MAX; event++)
11324                 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
11325         }
11326     }
11327
11328     cbt_hook_thread_id = GetCurrentThreadId();
11329     hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
11330     if (!hCBT_hook) skip( "cannot set global hook, will skip hook tests\n" );
11331
11332     test_winevents();
11333
11334     /* Fix message sequences before removing 4 lines below */
11335 #if 1
11336     if (pUnhookWinEvent && hEvent_hook)
11337     {
11338         ret = pUnhookWinEvent(hEvent_hook);
11339         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
11340         pUnhookWinEvent = 0;
11341     }
11342     hEvent_hook = 0;
11343 #endif
11344
11345     test_ShowWindow();
11346     test_PeekMessage();
11347     test_PeekMessage2();
11348     test_scrollwindowex();
11349     test_messages();
11350     test_setwindowpos();
11351     test_showwindow();
11352     invisible_parent_tests();
11353     test_mdi_messages();
11354     test_button_messages();
11355     test_static_messages();
11356     test_listbox_messages();
11357     test_combobox_messages();
11358     test_wmime_keydown_message();
11359     test_paint_messages();
11360     test_interthread_messages();
11361     test_message_conversion();
11362     test_accelerators();
11363     test_timers();
11364     test_timers_no_wnd();
11365     test_set_hook();
11366     test_DestroyWindow();
11367     test_DispatchMessage();
11368     test_SendMessageTimeout();
11369     test_edit_messages();
11370     test_quit_message();
11371     test_SetActiveWindow();
11372
11373     if (!pTrackMouseEvent)
11374         skip("TrackMouseEvent is not available\n");
11375     else
11376         test_TrackMouseEvent();
11377
11378     test_SetWindowRgn();
11379     test_sys_menu();
11380     test_dialog_messages();
11381     test_nullCallback();
11382     test_dbcs_wm_char();
11383     test_menu_messages();
11384     test_paintingloop();
11385     /* keep it the last test, under Windows it tends to break the tests
11386      * which rely on active/foreground windows being correct.
11387      */
11388     test_SetForegroundWindow();
11389
11390     UnhookWindowsHookEx(hCBT_hook);
11391     if (pUnhookWinEvent)
11392     {
11393         ret = pUnhookWinEvent(hEvent_hook);
11394         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
11395         SetLastError(0xdeadbeef);
11396         ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
11397         ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
11398            GetLastError() == 0xdeadbeef, /* Win9x */
11399            "unexpected error %d\n", GetLastError());
11400     }
11401     else
11402         skip("UnhookWinEvent is not available\n");
11403 }