quartz: Remove superfluous pointer casts.
[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_NCMOUSEMOVE:
3851         case WM_NCMOUSELEAVE:
3852         case WM_SETCURSOR:
3853         case WM_DEVICECHANGE:
3854             return 0;
3855         case WM_NCHITTEST:
3856             return HTCLIENT;
3857     }
3858
3859     msg.hwnd = hwnd;
3860     msg.message = message;
3861     msg.flags = sent|wparam|lparam;
3862     msg.wParam = wParam;
3863     msg.lParam = lParam;
3864     msg.descr = "dialog";
3865     add_message(&msg);
3866
3867     if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3868     if (message == WM_TIMER) EndDialog( hwnd, 0 );
3869     return 0;
3870 }
3871
3872 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3873 {
3874     DWORD style, exstyle;
3875     INT xmin, xmax;
3876     BOOL ret;
3877
3878     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3879     style = GetWindowLongA(hwnd, GWL_STYLE);
3880     /* do not be confused by WS_DLGFRAME set */
3881     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3882
3883     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3884     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3885
3886     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3887     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3888     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3889         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3890     else
3891         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3892
3893     style = GetWindowLongA(hwnd, GWL_STYLE);
3894     if (set) ok(style & set, "style %08x should be set\n", set);
3895     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3896
3897     /* a subsequent call should do nothing */
3898     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3899     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3900     ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3901
3902     xmin = 0xdeadbeef;
3903     xmax = 0xdeadbeef;
3904     trace("Ignore GetScrollRange error below if you are on Win9x\n");
3905     ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
3906     ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
3907     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3908     ok(xmin == min, "unexpected min scroll value %d\n", xmin);
3909     ok(xmax == max, "unexpected max scroll value %d\n", xmax);
3910 }
3911
3912 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3913 {
3914     DWORD style, exstyle;
3915     SCROLLINFO si;
3916     BOOL ret;
3917
3918     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3919     style = GetWindowLongA(hwnd, GWL_STYLE);
3920     /* do not be confused by WS_DLGFRAME set */
3921     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3922
3923     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3924     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3925
3926     si.cbSize = sizeof(si);
3927     si.fMask = SIF_RANGE;
3928     si.nMin = min;
3929     si.nMax = max;
3930     SetScrollInfo(hwnd, ctl, &si, TRUE);
3931     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3932         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
3933     else
3934         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
3935
3936     style = GetWindowLongA(hwnd, GWL_STYLE);
3937     if (set) ok(style & set, "style %08x should be set\n", set);
3938     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3939
3940     /* a subsequent call should do nothing */
3941     SetScrollInfo(hwnd, ctl, &si, TRUE);
3942     if (style & WS_HSCROLL)
3943         ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3944     else if (style & WS_VSCROLL)
3945         ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3946     else
3947         ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3948
3949     si.fMask = SIF_PAGE;
3950     si.nPage = 5;
3951     SetScrollInfo(hwnd, ctl, &si, FALSE);
3952     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3953
3954     si.fMask = SIF_POS;
3955     si.nPos = max - 1;
3956     SetScrollInfo(hwnd, ctl, &si, FALSE);
3957     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3958
3959     si.fMask = SIF_RANGE;
3960     si.nMin = 0xdeadbeef;
3961     si.nMax = 0xdeadbeef;
3962     ret = GetScrollInfo(hwnd, ctl, &si);
3963     ok( ret, "GetScrollInfo error %d\n", GetLastError());
3964     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3965     ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
3966     ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
3967 }
3968
3969 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
3970 static void test_scroll_messages(HWND hwnd)
3971 {
3972     SCROLLINFO si;
3973     INT min, max;
3974     BOOL ret;
3975
3976     flush_events();
3977     flush_sequence();
3978
3979     min = 0xdeadbeef;
3980     max = 0xdeadbeef;
3981     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3982     ok( ret, "GetScrollRange error %d\n", GetLastError());
3983     if (sequence->message != WmGetScrollRangeSeq[0].message)
3984         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3985     /* values of min and max are undefined */
3986     flush_sequence();
3987
3988     ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
3989     ok( ret, "SetScrollRange error %d\n", GetLastError());
3990     if (sequence->message != WmSetScrollRangeSeq[0].message)
3991         trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3992     flush_sequence();
3993
3994     min = 0xdeadbeef;
3995     max = 0xdeadbeef;
3996     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3997     ok( ret, "GetScrollRange error %d\n", GetLastError());
3998     if (sequence->message != WmGetScrollRangeSeq[0].message)
3999         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4000     /* values of min and max are undefined */
4001     flush_sequence();
4002
4003     si.cbSize = sizeof(si);
4004     si.fMask = SIF_RANGE;
4005     si.nMin = 20;
4006     si.nMax = 160;
4007     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4008     if (sequence->message != WmSetScrollRangeSeq[0].message)
4009         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4010     flush_sequence();
4011
4012     si.fMask = SIF_PAGE;
4013     si.nPage = 10;
4014     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4015     if (sequence->message != WmSetScrollRangeSeq[0].message)
4016         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4017     flush_sequence();
4018
4019     si.fMask = SIF_POS;
4020     si.nPos = 20;
4021     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4022     if (sequence->message != WmSetScrollRangeSeq[0].message)
4023         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4024     flush_sequence();
4025
4026     si.fMask = SIF_RANGE;
4027     si.nMin = 0xdeadbeef;
4028     si.nMax = 0xdeadbeef;
4029     ret = GetScrollInfo(hwnd, SB_CTL, &si);
4030     ok( ret, "GetScrollInfo error %d\n", GetLastError());
4031     if (sequence->message != WmGetScrollInfoSeq[0].message)
4032         trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4033     /* values of min and max are undefined */
4034     flush_sequence();
4035
4036     /* set WS_HSCROLL */
4037     test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4038     /* clear WS_HSCROLL */
4039     test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4040
4041     /* set WS_HSCROLL */
4042     test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4043     /* clear WS_HSCROLL */
4044     test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4045
4046     /* set WS_VSCROLL */
4047     test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4048     /* clear WS_VSCROLL */
4049     test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4050
4051     /* set WS_VSCROLL */
4052     test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4053     /* clear WS_VSCROLL */
4054     test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4055 }
4056
4057 static void test_showwindow(void)
4058 {
4059     HWND hwnd, hchild;
4060     RECT rc;
4061
4062     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4063                            100, 100, 200, 200, 0, 0, 0, NULL);
4064     ok (hwnd != 0, "Failed to create overlapped window\n");
4065     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4066                              0, 0, 10, 10, hwnd, 0, 0, NULL);
4067     ok (hchild != 0, "Failed to create child\n");
4068     flush_sequence();
4069
4070     /* ShowWindow( SW_SHOWNA) for invisible top level window */
4071     trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
4072     ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4073     ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", TRUE);
4074
4075     /* ShowWindow( SW_SHOWNA) for now visible top level window */
4076     trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
4077     ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4078     ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
4079     /* back to invisible */
4080     ShowWindow(hchild, SW_HIDE);
4081     ShowWindow(hwnd, SW_HIDE);
4082     flush_sequence();
4083     /* ShowWindow(SW_SHOWNA) with child and parent invisible */ 
4084     trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
4085     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4086     ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
4087     /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */ 
4088     ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
4089     flush_sequence();
4090     trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
4091     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4092     ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
4093     /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
4094     ShowWindow( hwnd, SW_SHOW);
4095     flush_sequence();
4096     trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
4097     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4098     ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
4099
4100     /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
4101     ShowWindow( hchild, SW_HIDE);
4102     flush_sequence();
4103     trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
4104     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4105     ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
4106
4107     SetCapture(hchild);
4108     ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
4109     DestroyWindow(hchild);
4110     ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
4111
4112     DestroyWindow(hwnd);
4113     flush_sequence();
4114
4115     /* Popup windows */
4116     /* Test 1:
4117      * 1. Create invisible maximized popup window.
4118      * 2. Move and resize it.
4119      * 3. Show it maximized.
4120      */
4121     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4122     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4123                            100, 100, 200, 200, 0, 0, 0, NULL);
4124     ok (hwnd != 0, "Failed to create popup window\n");
4125     ok(IsZoomed(hwnd), "window should be maximized\n");
4126     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4127
4128     GetWindowRect(hwnd, &rc);
4129     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4130         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4131         "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
4132         rc.left, rc.top, rc.right, rc.bottom);
4133     /* Reset window's size & position */
4134     SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
4135     ok(IsZoomed(hwnd), "window should be maximized\n");
4136     flush_sequence();
4137
4138     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4139     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4140     ok(IsZoomed(hwnd), "window should be maximized\n");
4141     ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
4142
4143     GetWindowRect(hwnd, &rc);
4144     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4145         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4146         "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
4147         rc.left, rc.top, rc.right, rc.bottom);
4148     DestroyWindow(hwnd);
4149     flush_sequence();
4150
4151     /* Test 2:
4152      * 1. Create invisible maximized popup window.
4153      * 2. Show it maximized.
4154      */
4155     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4156     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4157                            100, 100, 200, 200, 0, 0, 0, NULL);
4158     ok (hwnd != 0, "Failed to create popup window\n");
4159     ok(IsZoomed(hwnd), "window should be maximized\n");
4160     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4161
4162     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4163     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4164     ok(IsZoomed(hwnd), "window should be maximized\n");
4165     ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
4166     DestroyWindow(hwnd);
4167     flush_sequence();
4168
4169     /* Test 3:
4170      * 1. Create visible maximized popup window.
4171      */
4172     trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
4173     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4174                            100, 100, 200, 200, 0, 0, 0, NULL);
4175     ok (hwnd != 0, "Failed to create popup window\n");
4176     ok(IsZoomed(hwnd), "window should be maximized\n");
4177     ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4178     DestroyWindow(hwnd);
4179     flush_sequence();
4180
4181     /* Test 4:
4182      * 1. Create visible popup window.
4183      * 2. Maximize it.
4184      */
4185     trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
4186     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
4187                            100, 100, 200, 200, 0, 0, 0, NULL);
4188     ok (hwnd != 0, "Failed to create popup window\n");
4189     ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
4190     ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
4191
4192     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
4193     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4194     ok(IsZoomed(hwnd), "window should be maximized\n");
4195     ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
4196     DestroyWindow(hwnd);
4197     flush_sequence();
4198 }
4199
4200 static void test_sys_menu(void)
4201 {
4202     HWND hwnd;
4203     HMENU hmenu;
4204     UINT state;
4205
4206     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4207                            100, 100, 200, 200, 0, 0, 0, NULL);
4208     ok (hwnd != 0, "Failed to create overlapped window\n");
4209
4210     flush_sequence();
4211
4212     /* test existing window without CS_NOCLOSE style */
4213     hmenu = GetSystemMenu(hwnd, FALSE);
4214     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4215
4216     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4217     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4218     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4219
4220     EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
4221     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4222
4223     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4224     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4225     ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
4226
4227     EnableMenuItem(hmenu, SC_CLOSE, 0);
4228     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4229
4230     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4231     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4232     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4233
4234     /* test whether removing WS_SYSMENU destroys a system menu */
4235     SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
4236     SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4237     flush_sequence();
4238     hmenu = GetSystemMenu(hwnd, FALSE);
4239     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4240
4241     DestroyWindow(hwnd);
4242
4243     /* test new window with CS_NOCLOSE style */
4244     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4245                            100, 100, 200, 200, 0, 0, 0, NULL);
4246     ok (hwnd != 0, "Failed to create overlapped window\n");
4247
4248     hmenu = GetSystemMenu(hwnd, FALSE);
4249     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4250
4251     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4252     ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4253
4254     DestroyWindow(hwnd);
4255
4256     /* test new window without WS_SYSMENU style */
4257     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
4258                            100, 100, 200, 200, 0, 0, 0, NULL);
4259     ok(hwnd != 0, "Failed to create overlapped window\n");
4260
4261     hmenu = GetSystemMenu(hwnd, FALSE);
4262     ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
4263
4264     DestroyWindow(hwnd);
4265 }
4266
4267 /* For shown WS_OVERLAPPEDWINDOW */
4268 static const struct message WmSetIcon_1[] = {
4269     { WM_SETICON, sent },
4270     { 0x00AE, sent|defwinproc|optional }, /* XP */
4271     { WM_GETTEXT, sent|defwinproc|optional },
4272     { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
4273     { 0 }
4274 };
4275
4276 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
4277 static const struct message WmSetIcon_2[] = {
4278     { WM_SETICON, sent },
4279     { 0 }
4280 };
4281
4282 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4283 static const struct message WmInitEndSession[] = {
4284     { 0x003B, sent },
4285     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4286     { 0 }
4287 };
4288
4289 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4290 static const struct message WmInitEndSession_2[] = {
4291     { 0x003B, sent },
4292     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4293     { 0 }
4294 };
4295
4296 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4297 static const struct message WmInitEndSession_3[] = {
4298     { 0x003B, sent },
4299     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4300     { 0 }
4301 };
4302
4303 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4304 static const struct message WmInitEndSession_4[] = {
4305     { 0x003B, sent },
4306     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4307     { 0 }
4308 };
4309
4310 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4311 static const struct message WmInitEndSession_5[] = {
4312     { 0x003B, sent },
4313     { WM_ENDSESSION, sent|defwinproc/*|wparam*/|lparam, 1, ENDSESSION_LOGOFF },
4314     { 0 }
4315 };
4316
4317 static const struct message WmOptionalPaint[] = {
4318     { WM_PAINT, sent|optional },
4319     { WM_NCPAINT, sent|beginpaint|optional },
4320     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4321     { WM_ERASEBKGND, sent|beginpaint|optional },
4322     { 0 }
4323 };
4324
4325 static const struct message WmZOrder[] = {
4326     { WM_WINDOWPOSCHANGING, sent|wparam, 0, 0 },
4327     { WM_GETMINMAXINFO, sent|defwinproc|wparam, 0, 0 },
4328     { HCBT_ACTIVATE, hook },
4329     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
4330     { WM_WINDOWPOSCHANGING, sent|wparam, 3, 0 },
4331     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0 },
4332     { WM_GETTEXT, sent|optional },
4333     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
4334     { WM_ACTIVATEAPP, sent|wparam, 1, 0 },
4335     { WM_NCACTIVATE, sent|wparam|lparam, 1, 0 },
4336     { WM_GETTEXT, sent|defwinproc|optional },
4337     { WM_GETTEXT, sent|defwinproc|optional },
4338     { WM_ACTIVATE, sent|wparam|lparam, 1, 0 },
4339     { HCBT_SETFOCUS, hook },
4340     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4341     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4342     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4343     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
4344     { WM_GETTEXT, sent|optional },
4345     { WM_NCCALCSIZE, sent|optional },
4346     { 0 }
4347 };
4348
4349 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4350 {
4351     DWORD ret;
4352     MSG msg;
4353
4354     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4355     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4356
4357     PostMessageA(hwnd, WM_USER, 0, 0);
4358
4359     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4360     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4361
4362     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4363     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4364
4365     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4366     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4367
4368     PostMessageA(hwnd, WM_USER, 0, 0);
4369
4370     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4371     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4372
4373     ok(PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4374     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4375
4376     /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4377     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4378     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4379
4380     PostMessageA(hwnd, WM_USER, 0, 0);
4381
4382     /* new incoming message causes it to become signaled again */
4383     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4384     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4385
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     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4389     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4390 }
4391
4392 /* test if we receive the right sequence of messages */
4393 static void test_messages(void)
4394 {
4395     HWND hwnd, hparent, hchild;
4396     HWND hchild2, hbutton;
4397     HMENU hmenu;
4398     MSG msg;
4399     LRESULT res;
4400
4401     flush_sequence();
4402
4403     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4404                            100, 100, 200, 200, 0, 0, 0, NULL);
4405     ok (hwnd != 0, "Failed to create overlapped window\n");
4406     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4407
4408     /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4409     ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4410     ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4411
4412     /* test WM_SETREDRAW on a not visible top level window */
4413     test_WM_SETREDRAW(hwnd);
4414
4415     SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4416     flush_events();
4417     ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4418     ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4419
4420     ok(GetActiveWindow() == hwnd, "window should be active\n");
4421     ok(GetFocus() == hwnd, "window should have input focus\n");
4422     ShowWindow(hwnd, SW_HIDE);
4423     flush_events();
4424     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4425
4426     ShowWindow(hwnd, SW_SHOW);
4427     flush_events();
4428     ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4429
4430     ShowWindow(hwnd, SW_HIDE);
4431     flush_events();
4432     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4433
4434     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4435     flush_events();
4436     ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4437
4438     ShowWindow(hwnd, SW_RESTORE);
4439     ok_sequence(WmShowRestoreMaxOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", FALSE);
4440     flush_events();
4441     flush_sequence();
4442
4443     ShowWindow(hwnd, SW_MINIMIZE);
4444     flush_events();
4445     ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4446     flush_sequence();
4447
4448     ShowWindow(hwnd, SW_RESTORE);
4449     flush_events();
4450     ok_sequence(WmShowRestoreMinOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4451     flush_sequence();
4452
4453     ShowWindow(hwnd, SW_SHOW);
4454     flush_events();
4455     ok_sequence(WmOptionalPaint, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4456
4457     ok(GetActiveWindow() == hwnd, "window should be active\n");
4458     ok(GetFocus() == hwnd, "window should have input focus\n");
4459     SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4460     ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4461     ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4462     ok(GetActiveWindow() == hwnd, "window should still be active\n");
4463
4464     /* test WM_SETREDRAW on a visible top level window */
4465     ShowWindow(hwnd, SW_SHOW);
4466     flush_events();
4467     test_WM_SETREDRAW(hwnd);
4468
4469     trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4470     test_scroll_messages(hwnd);
4471
4472     /* test resizing and moving */
4473     SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4474     ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4475     flush_events();
4476     flush_sequence();
4477     SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4478     ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4479     flush_events();
4480     flush_sequence();
4481     SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER|SWP_NOACTIVATE );
4482     ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4483     flush_events();
4484     flush_sequence();
4485
4486     /* popups don't get WM_GETMINMAXINFO */
4487     SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4488     SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4489     flush_sequence();
4490     SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4491     ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4492
4493     DestroyWindow(hwnd);
4494     ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4495
4496     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4497                               100, 100, 200, 200, 0, 0, 0, NULL);
4498     ok (hparent != 0, "Failed to create parent window\n");
4499     flush_sequence();
4500
4501     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4502                              0, 0, 10, 10, hparent, 0, 0, NULL);
4503     ok (hchild != 0, "Failed to create child window\n");
4504     ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4505     DestroyWindow(hchild);
4506     flush_sequence();
4507
4508     /* visible child window with a caption */
4509     hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4510                              WS_CHILD | WS_VISIBLE | WS_CAPTION,
4511                              0, 0, 10, 10, hparent, 0, 0, NULL);
4512     ok (hchild != 0, "Failed to create child window\n");
4513     ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4514
4515     trace("testing scroll APIs on a visible child window %p\n", hchild);
4516     test_scroll_messages(hchild);
4517
4518     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4519     ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4520
4521     DestroyWindow(hchild);
4522     flush_sequence();
4523
4524     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4525                              0, 0, 10, 10, hparent, 0, 0, NULL);
4526     ok (hchild != 0, "Failed to create child window\n");
4527     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4528     
4529     hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4530                                100, 100, 50, 50, hparent, 0, 0, NULL);
4531     ok (hchild2 != 0, "Failed to create child2 window\n");
4532     flush_sequence();
4533
4534     hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4535                               0, 100, 50, 50, hchild, 0, 0, NULL);
4536     ok (hbutton != 0, "Failed to create button window\n");
4537
4538     /* test WM_SETREDRAW on a not visible child window */
4539     test_WM_SETREDRAW(hchild);
4540
4541     ShowWindow(hchild, SW_SHOW);
4542     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4543
4544     /* check parent messages too */
4545     log_all_parent_messages++;
4546     ShowWindow(hchild, SW_HIDE);
4547     ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4548     log_all_parent_messages--;
4549
4550     ShowWindow(hchild, SW_SHOW);
4551     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4552
4553     ShowWindow(hchild, SW_HIDE);
4554     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4555
4556     ShowWindow(hchild, SW_SHOW);
4557     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4558
4559     /* test WM_SETREDRAW on a visible child window */
4560     test_WM_SETREDRAW(hchild);
4561
4562     log_all_parent_messages++;
4563     MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4564     ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4565     log_all_parent_messages--;
4566
4567     ShowWindow(hchild, SW_HIDE);
4568     flush_sequence();
4569     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4570     ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4571
4572     ShowWindow(hchild, SW_HIDE);
4573     flush_sequence();
4574     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4575     ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4576
4577     /* DestroyWindow sequence below expects that a child has focus */
4578     SetFocus(hchild);
4579     flush_sequence();
4580
4581     DestroyWindow(hchild);
4582     ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4583     DestroyWindow(hchild2);
4584     DestroyWindow(hbutton);
4585
4586     flush_sequence();
4587     hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4588                              0, 0, 100, 100, hparent, 0, 0, NULL);
4589     ok (hchild != 0, "Failed to create child popup window\n");
4590     ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4591     DestroyWindow(hchild);
4592
4593     /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4594     flush_sequence();
4595     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4596                              0, 0, 100, 100, hparent, 0, 0, NULL);
4597     ok (hchild != 0, "Failed to create popup window\n");
4598     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4599     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4600     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4601     flush_sequence();
4602     ShowWindow(hchild, SW_SHOW);
4603     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4604     flush_sequence();
4605     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4606     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4607     flush_sequence();
4608     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4609     ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
4610     DestroyWindow(hchild);
4611
4612     /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4613      * changes nothing in message sequences.
4614      */
4615     flush_sequence();
4616     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4617                              0, 0, 100, 100, hparent, 0, 0, NULL);
4618     ok (hchild != 0, "Failed to create popup window\n");
4619     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4620     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4621     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4622     flush_sequence();
4623     ShowWindow(hchild, SW_SHOW);
4624     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4625     flush_sequence();
4626     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4627     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4628     DestroyWindow(hchild);
4629
4630     flush_sequence();
4631     hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4632                            0, 0, 100, 100, hparent, 0, 0, NULL);
4633     ok(hwnd != 0, "Failed to create custom dialog window\n");
4634     ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4635
4636     /*
4637     trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4638     test_scroll_messages(hwnd);
4639     */
4640
4641     flush_sequence();
4642
4643     test_def_id = 1;
4644     SendMessage(hwnd, WM_NULL, 0, 0);
4645
4646     flush_sequence();
4647     after_end_dialog = 1;
4648     EndDialog( hwnd, 0 );
4649     ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4650
4651     DestroyWindow(hwnd);
4652     after_end_dialog = 0;
4653     test_def_id = 0;
4654
4655     hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4656                            0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4657     ok(hwnd != 0, "Failed to create custom dialog window\n");
4658     flush_sequence();
4659     trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4660     ShowWindow(hwnd, SW_SHOW);
4661     ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4662     DestroyWindow(hwnd);
4663
4664     flush_sequence();
4665     DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4666     ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4667
4668     DestroyWindow(hparent);
4669     flush_sequence();
4670
4671     /* Message sequence for SetMenu */
4672     ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4673     ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4674
4675     hmenu = CreateMenu();
4676     ok (hmenu != 0, "Failed to create menu\n");
4677     ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4678     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4679                            100, 100, 200, 200, 0, hmenu, 0, NULL);
4680     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4681     ok (SetMenu(hwnd, 0), "SetMenu\n");
4682     ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4683     ok (SetMenu(hwnd, 0), "SetMenu\n");
4684     ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4685     ShowWindow(hwnd, SW_SHOW);
4686     UpdateWindow( hwnd );
4687     flush_events();
4688     flush_sequence();
4689     ok (SetMenu(hwnd, 0), "SetMenu\n");
4690     ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4691     ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4692     ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4693
4694     UpdateWindow( hwnd );
4695     flush_events();
4696     flush_sequence();
4697     ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4698     flush_events();
4699     ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4700
4701     DestroyWindow(hwnd);
4702     flush_sequence();
4703
4704     /* Message sequence for EnableWindow */
4705     hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4706                               100, 100, 200, 200, 0, 0, 0, NULL);
4707     ok (hparent != 0, "Failed to create parent window\n");
4708     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4709                              0, 0, 10, 10, hparent, 0, 0, NULL);
4710     ok (hchild != 0, "Failed to create child window\n");
4711
4712     SetFocus(hchild);
4713     flush_events();
4714     flush_sequence();
4715
4716     EnableWindow(hparent, FALSE);
4717     ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4718
4719     EnableWindow(hparent, TRUE);
4720     ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4721
4722     flush_events();
4723     flush_sequence();
4724
4725     test_MsgWaitForMultipleObjects(hparent);
4726
4727     /* the following test causes an exception in user.exe under win9x */
4728     if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4729     {
4730         DestroyWindow(hparent);
4731         flush_sequence();
4732         return;
4733     }
4734     PostMessageW( hparent, WM_USER+1, 0, 0 );
4735     /* PeekMessage(NULL) fails, but still removes the message */
4736     SetLastError(0xdeadbeef);
4737     ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4738     ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4739         GetLastError() == 0xdeadbeef, /* NT4 */
4740         "last error is %d\n", GetLastError() );
4741     ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4742     ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4743
4744     DestroyWindow(hchild);
4745     DestroyWindow(hparent);
4746     flush_sequence();
4747
4748     /* Message sequences for WM_SETICON */
4749     trace("testing WM_SETICON\n");
4750     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4751                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4752                            NULL, NULL, 0);
4753     ShowWindow(hwnd, SW_SHOW);
4754     UpdateWindow(hwnd);
4755     flush_events();
4756     flush_sequence();
4757     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4758     ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4759
4760     ShowWindow(hwnd, SW_HIDE);
4761     flush_events();
4762     flush_sequence();
4763     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4764     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4765     DestroyWindow(hwnd);
4766     flush_sequence();
4767
4768     hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4769                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4770                            NULL, NULL, 0);
4771     ShowWindow(hwnd, SW_SHOW);
4772     UpdateWindow(hwnd);
4773     flush_events();
4774     flush_sequence();
4775     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4776     ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4777
4778     ShowWindow(hwnd, SW_HIDE);
4779     flush_events();
4780     flush_sequence();
4781     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4782     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4783
4784     flush_sequence();
4785     res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4786     if (!res)
4787     {
4788         todo_wine win_skip( "Message 0x3b not supported\n" );
4789         goto done;
4790     }
4791     ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4792     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4793     res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4794     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4795     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4796     res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4797     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4798     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4799
4800     flush_sequence();
4801     res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4802     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4803     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4804     res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4805     ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4806     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4807
4808     res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4809     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4810     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4811
4812     res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4813     ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4814     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4815
4816 done:
4817     DestroyWindow(hwnd);
4818     flush_sequence();
4819 }
4820
4821 static void test_setwindowpos(void)
4822 {
4823     HWND hwnd;
4824     RECT rc;
4825     LRESULT res;
4826     const INT winX = 100;
4827     const INT winY = 100;
4828     const INT sysX = GetSystemMetrics(SM_CXMINTRACK);
4829
4830     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
4831                            0, 0, winX, winY, 0,
4832                            NULL, NULL, 0);
4833
4834     GetWindowRect(hwnd, &rc);
4835     expect(sysX, rc.right);
4836     expect(winY, rc.bottom);
4837
4838     flush_events();
4839     flush_sequence();
4840     res = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, winX, winY, 0);
4841     ok_sequence(WmZOrder, "Z-Order", TRUE);
4842     ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
4843
4844     GetWindowRect(hwnd, &rc);
4845     expect(sysX, rc.right);
4846     expect(winY, rc.bottom);
4847     DestroyWindow(hwnd);
4848 }
4849
4850 static void invisible_parent_tests(void)
4851 {
4852     HWND hparent, hchild;
4853
4854     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4855                               100, 100, 200, 200, 0, 0, 0, NULL);
4856     ok (hparent != 0, "Failed to create parent window\n");
4857     flush_sequence();
4858
4859     /* test showing child with hidden parent */
4860
4861     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4862                              0, 0, 10, 10, hparent, 0, 0, NULL);
4863     ok (hchild != 0, "Failed to create child window\n");
4864     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4865
4866     ShowWindow( hchild, SW_MINIMIZE );
4867     ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4868     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4869     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4870
4871     /* repeat */
4872     flush_events();
4873     flush_sequence();
4874     ShowWindow( hchild, SW_MINIMIZE );
4875     ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4876
4877     DestroyWindow(hchild);
4878     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4879                              0, 0, 10, 10, hparent, 0, 0, NULL);
4880     flush_sequence();
4881
4882     ShowWindow( hchild, SW_MAXIMIZE );
4883     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4884     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4885     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4886
4887     /* repeat */
4888     flush_events();
4889     flush_sequence();
4890     ShowWindow( hchild, SW_MAXIMIZE );
4891     ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4892
4893     DestroyWindow(hchild);
4894     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4895                              0, 0, 10, 10, hparent, 0, 0, NULL);
4896     flush_sequence();
4897
4898     ShowWindow( hchild, SW_RESTORE );
4899     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
4900     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4901     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4902
4903     DestroyWindow(hchild);
4904     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4905                              0, 0, 10, 10, hparent, 0, 0, NULL);
4906     flush_sequence();
4907
4908     ShowWindow( hchild, SW_SHOWMINIMIZED );
4909     ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4910     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4911     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4912
4913     /* repeat */
4914     flush_events();
4915     flush_sequence();
4916     ShowWindow( hchild, SW_SHOWMINIMIZED );
4917     ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4918
4919     DestroyWindow(hchild);
4920     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4921                              0, 0, 10, 10, hparent, 0, 0, NULL);
4922     flush_sequence();
4923
4924     /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
4925     ShowWindow( hchild, SW_SHOWMAXIMIZED );
4926     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
4927     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4928     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4929
4930     DestroyWindow(hchild);
4931     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4932                              0, 0, 10, 10, hparent, 0, 0, NULL);
4933     flush_sequence();
4934
4935     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4936     ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4937     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4938     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4939
4940     /* repeat */
4941     flush_events();
4942     flush_sequence();
4943     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4944     ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4945
4946     DestroyWindow(hchild);
4947     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4948                              0, 0, 10, 10, hparent, 0, 0, NULL);
4949     flush_sequence();
4950
4951     /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
4952     ShowWindow( hchild, SW_FORCEMINIMIZE );
4953     ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
4954 todo_wine {
4955     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4956 }
4957     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4958
4959     DestroyWindow(hchild);
4960     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4961                              0, 0, 10, 10, hparent, 0, 0, NULL);
4962     flush_sequence();
4963
4964     ShowWindow( hchild, SW_SHOWNA );
4965     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4966     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4967     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4968
4969     /* repeat */
4970     flush_events();
4971     flush_sequence();
4972     ShowWindow( hchild, SW_SHOWNA );
4973     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4974
4975     DestroyWindow(hchild);
4976     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4977                              0, 0, 10, 10, hparent, 0, 0, NULL);
4978     flush_sequence();
4979
4980     ShowWindow( hchild, SW_SHOW );
4981     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4982     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4983     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4984
4985     /* repeat */
4986     flush_events();
4987     flush_sequence();
4988     ShowWindow( hchild, SW_SHOW );
4989     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4990
4991     ShowWindow( hchild, SW_HIDE );
4992     ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
4993     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4994     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4995
4996     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4997     ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
4998     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4999     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5000
5001     SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5002     ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
5003     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
5004     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5005
5006     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5007     flush_sequence();
5008     DestroyWindow(hchild);
5009     ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
5010
5011     DestroyWindow(hparent);
5012     flush_sequence();
5013 }
5014
5015 /****************** button message test *************************/
5016 static const struct message WmSetFocusButtonSeq[] =
5017 {
5018     { HCBT_SETFOCUS, hook },
5019     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5020     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5021     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5022     { WM_SETFOCUS, sent|wparam, 0 },
5023     { WM_CTLCOLORBTN, sent|defwinproc },
5024     { 0 }
5025 };
5026 static const struct message WmKillFocusButtonSeq[] =
5027 {
5028     { HCBT_SETFOCUS, hook },
5029     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5030     { WM_KILLFOCUS, sent|wparam, 0 },
5031     { WM_CTLCOLORBTN, sent|defwinproc },
5032     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5033     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5034     { 0 }
5035 };
5036 static const struct message WmSetFocusStaticSeq[] =
5037 {
5038     { HCBT_SETFOCUS, hook },
5039     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5040     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5041     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5042     { WM_SETFOCUS, sent|wparam, 0 },
5043     { WM_CTLCOLORSTATIC, sent|defwinproc },
5044     { 0 }
5045 };
5046 static const struct message WmKillFocusStaticSeq[] =
5047 {
5048     { HCBT_SETFOCUS, hook },
5049     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5050     { WM_KILLFOCUS, sent|wparam, 0 },
5051     { WM_CTLCOLORSTATIC, sent|defwinproc },
5052     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5053     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5054     { 0 }
5055 };
5056 static const struct message WmLButtonDownSeq[] =
5057 {
5058     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
5059     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5060     { HCBT_SETFOCUS, hook },
5061     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
5062     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5063     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5064     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
5065     { WM_CTLCOLORBTN, sent|defwinproc },
5066     { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
5067     { WM_CTLCOLORBTN, sent|defwinproc },
5068     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5069     { 0 }
5070 };
5071 static const struct message WmLButtonUpSeq[] =
5072 {
5073     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
5074     { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
5075     { WM_CTLCOLORBTN, sent|defwinproc },
5076     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5077     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5078     { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
5079     { 0 }
5080 };
5081 static const struct message WmSetFontButtonSeq[] =
5082 {
5083     { WM_SETFONT, sent },
5084     { WM_PAINT, sent },
5085     { WM_ERASEBKGND, sent|defwinproc|optional },
5086     { WM_CTLCOLORBTN, sent|defwinproc },
5087     { 0 }
5088 };
5089
5090 static WNDPROC old_button_proc;
5091
5092 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5093 {
5094     static long defwndproc_counter = 0;
5095     LRESULT ret;
5096     struct recvd_message msg;
5097
5098     switch (message)
5099     {
5100     case WM_GETICON:
5101     case WM_GETOBJECT:
5102         return 0;  /* ignore them */
5103     case WM_SYNCPAINT:
5104         break;
5105     case BM_SETSTATE:
5106         ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
5107         /* fall through */
5108     default:
5109         msg.hwnd = hwnd;
5110         msg.message = message;
5111         msg.flags = sent|wparam|lparam;
5112         if (defwndproc_counter) msg.flags |= defwinproc;
5113         msg.wParam = wParam;
5114         msg.lParam = lParam;
5115         msg.descr = "button";
5116         add_message(&msg);
5117     }
5118
5119     defwndproc_counter++;
5120     ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
5121     defwndproc_counter--;
5122
5123     return ret;
5124 }
5125
5126 static void subclass_button(void)
5127 {
5128     WNDCLASSA cls;
5129
5130     if (!GetClassInfoA(0, "button", &cls)) assert(0);
5131
5132     old_button_proc = cls.lpfnWndProc;
5133
5134     cls.hInstance = GetModuleHandle(0);
5135     cls.lpfnWndProc = button_hook_proc;
5136     cls.lpszClassName = "my_button_class";
5137     UnregisterClass(cls.lpszClassName, cls.hInstance);
5138     if (!RegisterClassA(&cls)) assert(0);
5139 }
5140
5141 static void test_button_messages(void)
5142 {
5143     static const struct
5144     {
5145         DWORD style;
5146         DWORD dlg_code;
5147         const struct message *setfocus;
5148         const struct message *killfocus;
5149     } button[] = {
5150         { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5151           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5152         { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
5153           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5154         { BS_CHECKBOX, DLGC_BUTTON,
5155           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5156         { BS_AUTOCHECKBOX, DLGC_BUTTON,
5157           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5158         { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5159           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5160         { BS_3STATE, DLGC_BUTTON,
5161           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5162         { BS_AUTO3STATE, DLGC_BUTTON,
5163           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5164         { BS_GROUPBOX, DLGC_STATIC,
5165           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5166         { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5167           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5168         { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5169           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5170         { BS_OWNERDRAW, DLGC_BUTTON,
5171           WmSetFocusButtonSeq, WmKillFocusButtonSeq }
5172     };
5173     unsigned int i;
5174     HWND hwnd;
5175     DWORD dlg_code;
5176     HFONT zfont;
5177
5178     subclass_button();
5179
5180     for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
5181     {
5182         hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_POPUP,
5183                                0, 0, 50, 14, 0, 0, 0, NULL);
5184         ok(hwnd != 0, "Failed to create button window\n");
5185
5186         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5187         ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5188
5189         ShowWindow(hwnd, SW_SHOW);
5190         UpdateWindow(hwnd);
5191         SetFocus(0);
5192         flush_sequence();
5193
5194         trace("button style %08x\n", button[i].style);
5195         SetFocus(hwnd);
5196         ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
5197
5198         SetFocus(0);
5199         ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
5200
5201         DestroyWindow(hwnd);
5202     }
5203
5204     hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
5205                            0, 0, 50, 14, 0, 0, 0, NULL);
5206     ok(hwnd != 0, "Failed to create button window\n");
5207
5208     SetForegroundWindow(hwnd);
5209     SetFocus(0);
5210     flush_events();
5211     flush_sequence();
5212
5213     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
5214     ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
5215
5216     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
5217     ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
5218
5219     flush_sequence();
5220     zfont = GetStockObject(SYSTEM_FONT);
5221     SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
5222     UpdateWindow(hwnd);
5223     ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
5224
5225     DestroyWindow(hwnd);
5226 }
5227
5228 /****************** static message test *************************/
5229 static const struct message WmSetFontStaticSeq[] =
5230 {
5231     { WM_SETFONT, sent },
5232     { WM_PAINT, sent|defwinproc|optional },
5233     { WM_ERASEBKGND, sent|defwinproc|optional },
5234     { WM_CTLCOLORSTATIC, sent|defwinproc|optional },
5235     { 0 }
5236 };
5237
5238 static WNDPROC old_static_proc;
5239
5240 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5241 {
5242     static long defwndproc_counter = 0;
5243     LRESULT ret;
5244     struct recvd_message msg;
5245
5246     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
5247
5248     msg.hwnd = hwnd;
5249     msg.message = message;
5250     msg.flags = sent|wparam|lparam;
5251     if (defwndproc_counter) msg.flags |= defwinproc;
5252     msg.wParam = wParam;
5253     msg.lParam = lParam;
5254     msg.descr = "static";
5255     add_message(&msg);
5256
5257     defwndproc_counter++;
5258     ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
5259     defwndproc_counter--;
5260
5261     return ret;
5262 }
5263
5264 static void subclass_static(void)
5265 {
5266     WNDCLASSA cls;
5267
5268     if (!GetClassInfoA(0, "static", &cls)) assert(0);
5269
5270     old_static_proc = cls.lpfnWndProc;
5271
5272     cls.hInstance = GetModuleHandle(0);
5273     cls.lpfnWndProc = static_hook_proc;
5274     cls.lpszClassName = "my_static_class";
5275     UnregisterClass(cls.lpszClassName, cls.hInstance);
5276     if (!RegisterClassA(&cls)) assert(0);
5277 }
5278
5279 static void test_static_messages(void)
5280 {
5281     /* FIXME: make as comprehensive as the button message test */
5282     static const struct
5283     {
5284         DWORD style;
5285         DWORD dlg_code;
5286         const struct message *setfont;
5287     } static_ctrl[] = {
5288         { SS_LEFT, DLGC_STATIC,
5289           WmSetFontStaticSeq }
5290     };
5291     unsigned int i;
5292     HWND hwnd;
5293     DWORD dlg_code;
5294
5295     subclass_static();
5296
5297     for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
5298     {
5299         hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
5300                                0, 0, 50, 14, 0, 0, 0, NULL);
5301         ok(hwnd != 0, "Failed to create static window\n");
5302
5303         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5304         ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5305
5306         ShowWindow(hwnd, SW_SHOW);
5307         UpdateWindow(hwnd);
5308         SetFocus(0);
5309         flush_sequence();
5310
5311         trace("static style %08x\n", static_ctrl[i].style);
5312         SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
5313         ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
5314
5315         DestroyWindow(hwnd);
5316     }
5317 }
5318
5319 /****************** ComboBox message test *************************/
5320 #define ID_COMBOBOX 0x000f
5321
5322 static const struct message WmKeyDownComboSeq[] =
5323 {
5324     { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
5325     { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
5326     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
5327     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
5328     { WM_CTLCOLOREDIT, sent|parent },
5329     { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
5330     { 0 }
5331 };
5332
5333 static WNDPROC old_combobox_proc;
5334
5335 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5336 {
5337     static long defwndproc_counter = 0;
5338     LRESULT ret;
5339     struct recvd_message msg;
5340
5341     /* do not log painting messages */
5342     if (message != WM_PAINT &&
5343         message != WM_NCPAINT &&
5344         message != WM_SYNCPAINT &&
5345         message != WM_ERASEBKGND &&
5346         message != WM_NCHITTEST &&
5347         message != WM_GETTEXT &&
5348         message != WM_GETICON &&
5349         message != WM_GETOBJECT &&
5350         message != WM_DEVICECHANGE)
5351     {
5352         msg.hwnd = hwnd;
5353         msg.message = message;
5354         msg.flags = sent|wparam|lparam;
5355         if (defwndproc_counter) msg.flags |= defwinproc;
5356         msg.wParam = wParam;
5357         msg.lParam = lParam;
5358         msg.descr = "combo";
5359         add_message(&msg);
5360     }
5361
5362     defwndproc_counter++;
5363     ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5364     defwndproc_counter--;
5365
5366     return ret;
5367 }
5368
5369 static void subclass_combobox(void)
5370 {
5371     WNDCLASSA cls;
5372
5373     if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5374
5375     old_combobox_proc = cls.lpfnWndProc;
5376
5377     cls.hInstance = GetModuleHandle(0);
5378     cls.lpfnWndProc = combobox_hook_proc;
5379     cls.lpszClassName = "my_combobox_class";
5380     UnregisterClass(cls.lpszClassName, cls.hInstance);
5381     if (!RegisterClassA(&cls)) assert(0);
5382 }
5383
5384 static void test_combobox_messages(void)
5385 {
5386     HWND parent, combo;
5387     LRESULT ret;
5388
5389     subclass_combobox();
5390
5391     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5392                              100, 100, 200, 200, 0, 0, 0, NULL);
5393     ok(parent != 0, "Failed to create parent window\n");
5394     flush_sequence();
5395
5396     combo = CreateWindowEx(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5397                            0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5398     ok(combo != 0, "Failed to create combobox window\n");
5399
5400     UpdateWindow(combo);
5401
5402     ret = SendMessage(combo, WM_GETDLGCODE, 0, 0);
5403     ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5404
5405     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5406     ok(ret == 0, "expected 0, got %ld\n", ret);
5407     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5408     ok(ret == 1, "expected 1, got %ld\n", ret);
5409     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5410     ok(ret == 2, "expected 2, got %ld\n", ret);
5411
5412     SendMessage(combo, CB_SETCURSEL, 0, 0);
5413     SetFocus(combo);
5414     flush_sequence();
5415
5416     log_all_parent_messages++;
5417     SendMessage(combo, WM_KEYDOWN, VK_DOWN, 0);
5418     SendMessage(combo, WM_KEYUP, VK_DOWN, 0);
5419     log_all_parent_messages--;
5420     ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5421
5422     DestroyWindow(combo);
5423     DestroyWindow(parent);
5424 }
5425
5426 /****************** WM_IME_KEYDOWN message test *******************/
5427
5428 static const struct message WmImeKeydownMsgSeq_0[] =
5429 {
5430     { WM_IME_KEYDOWN, wparam, VK_RETURN },
5431     { WM_CHAR, wparam, 'A' },
5432     { 0 }
5433 };
5434
5435 static const struct message WmImeKeydownMsgSeq_1[] =
5436 {
5437     { WM_KEYDOWN, optional|wparam, VK_RETURN },
5438     { WM_CHAR,    optional|wparam, VK_RETURN },
5439     { 0 }
5440 };
5441
5442 static LRESULT WINAPI wmime_keydown_procA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5443 {
5444     struct recvd_message msg;
5445
5446     msg.hwnd = hwnd;
5447     msg.message = message;
5448     msg.flags = wparam|lparam;
5449     msg.wParam = wParam;
5450     msg.lParam = lParam;
5451     msg.descr = "wmime_keydown";
5452     add_message(&msg);
5453
5454     return DefWindowProcA(hwnd, message, wParam, lParam);
5455 }
5456
5457 static void register_wmime_keydown_class(void)
5458 {
5459     WNDCLASSA cls;
5460
5461     ZeroMemory(&cls, sizeof(WNDCLASSA));
5462     cls.lpfnWndProc = wmime_keydown_procA;
5463     cls.hInstance = GetModuleHandleA(0);
5464     cls.lpszClassName = "wmime_keydown_class";
5465     if (!RegisterClassA(&cls)) assert(0);
5466 }
5467
5468 static void test_wmime_keydown_message(void)
5469 {
5470     HWND hwnd;
5471     MSG msg;
5472
5473     trace("Message sequences by WM_IME_KEYDOWN\n");
5474
5475     register_wmime_keydown_class();
5476     hwnd = CreateWindowExA(0, "wmime_keydown_class", NULL, WS_OVERLAPPEDWINDOW,
5477                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5478                            NULL, NULL, 0);
5479     flush_events();
5480     flush_sequence();
5481
5482     SendMessage(hwnd, WM_IME_KEYDOWN, VK_RETURN, 0x1c0001);
5483     SendMessage(hwnd, WM_CHAR, 'A', 1);
5484     ok_sequence(WmImeKeydownMsgSeq_0, "WM_IME_KEYDOWN 0", FALSE);
5485
5486     while ( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
5487     {
5488         TranslateMessage(&msg);
5489         DispatchMessage(&msg);
5490     }
5491     ok_sequence(WmImeKeydownMsgSeq_1, "WM_IME_KEYDOWN 1", FALSE);
5492
5493     DestroyWindow(hwnd);
5494 }
5495
5496 /************* painting message test ********************/
5497
5498 void dump_region(HRGN hrgn)
5499 {
5500     DWORD i, size;
5501     RGNDATA *data = NULL;
5502     RECT *rect;
5503
5504     if (!hrgn)
5505     {
5506         printf( "null region\n" );
5507         return;
5508     }
5509     if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5510     if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5511     GetRegionData( hrgn, size, data );
5512     printf("%d rects:", data->rdh.nCount );
5513     for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5514         printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
5515     printf("\n");
5516     HeapFree( GetProcessHeap(), 0, data );
5517 }
5518
5519 static void check_update_rgn( HWND hwnd, HRGN hrgn )
5520 {
5521     INT ret;
5522     RECT r1, r2;
5523     HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
5524     HRGN update = CreateRectRgn( 0, 0, 0, 0 );
5525
5526     ret = GetUpdateRgn( hwnd, update, FALSE );
5527     ok( ret != ERROR, "GetUpdateRgn failed\n" );
5528     if (ret == NULLREGION)
5529     {
5530         ok( !hrgn, "Update region shouldn't be empty\n" );
5531     }
5532     else
5533     {
5534         if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
5535         {
5536             ok( 0, "Regions are different\n" );
5537             if (winetest_debug > 0)
5538             {
5539                 printf( "Update region: " );
5540                 dump_region( update );
5541                 printf( "Wanted region: " );
5542                 dump_region( hrgn );
5543             }
5544         }
5545     }
5546     GetRgnBox( update, &r1 );
5547     GetUpdateRect( hwnd, &r2, FALSE );
5548     ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
5549         "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
5550         r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
5551
5552     DeleteObject( tmp );
5553     DeleteObject( update );
5554 }
5555
5556 static const struct message WmInvalidateRgn[] = {
5557     { WM_NCPAINT, sent },
5558     { WM_GETTEXT, sent|defwinproc|optional },
5559     { 0 }
5560 };
5561
5562 static const struct message WmGetUpdateRect[] = {
5563     { WM_NCPAINT, sent },
5564     { WM_GETTEXT, sent|defwinproc|optional },
5565     { WM_PAINT, sent },
5566     { 0 }
5567 };
5568
5569 static const struct message WmInvalidateFull[] = {
5570     { WM_NCPAINT, sent|wparam, 1 },
5571     { WM_GETTEXT, sent|defwinproc|optional },
5572     { 0 }
5573 };
5574
5575 static const struct message WmInvalidateErase[] = {
5576     { WM_NCPAINT, sent|wparam, 1 },
5577     { WM_GETTEXT, sent|defwinproc|optional },
5578     { WM_ERASEBKGND, sent },
5579     { 0 }
5580 };
5581
5582 static const struct message WmInvalidatePaint[] = {
5583     { WM_PAINT, sent },
5584     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5585     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5586     { 0 }
5587 };
5588
5589 static const struct message WmInvalidateErasePaint[] = {
5590     { WM_PAINT, sent },
5591     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5592     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5593     { WM_ERASEBKGND, sent|beginpaint },
5594     { 0 }
5595 };
5596
5597 static const struct message WmInvalidateErasePaint2[] = {
5598     { WM_PAINT, sent },
5599     { WM_NCPAINT, sent|beginpaint },
5600     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5601     { WM_ERASEBKGND, sent|beginpaint|optional },
5602     { 0 }
5603 };
5604
5605 static const struct message WmErase[] = {
5606     { WM_ERASEBKGND, sent },
5607     { 0 }
5608 };
5609
5610 static const struct message WmPaint[] = {
5611     { WM_PAINT, sent },
5612     { 0 }
5613 };
5614
5615 static const struct message WmParentOnlyPaint[] = {
5616     { WM_PAINT, sent|parent },
5617     { 0 }
5618 };
5619
5620 static const struct message WmInvalidateParent[] = {
5621     { WM_NCPAINT, sent|parent },
5622     { WM_GETTEXT, sent|defwinproc|parent|optional },
5623     { WM_ERASEBKGND, sent|parent },
5624     { 0 }
5625 };
5626
5627 static const struct message WmInvalidateParentChild[] = {
5628     { WM_NCPAINT, sent|parent },
5629     { WM_GETTEXT, sent|defwinproc|parent|optional },
5630     { WM_ERASEBKGND, sent|parent },
5631     { WM_NCPAINT, sent },
5632     { WM_GETTEXT, sent|defwinproc|optional },
5633     { WM_ERASEBKGND, sent },
5634     { 0 }
5635 };
5636
5637 static const struct message WmInvalidateParentChild2[] = {
5638     { WM_ERASEBKGND, sent|parent },
5639     { WM_NCPAINT, sent },
5640     { WM_GETTEXT, sent|defwinproc|optional },
5641     { WM_ERASEBKGND, sent },
5642     { 0 }
5643 };
5644
5645 static const struct message WmParentPaint[] = {
5646     { WM_PAINT, sent|parent },
5647     { WM_PAINT, sent },
5648     { 0 }
5649 };
5650
5651 static const struct message WmParentPaintNc[] = {
5652     { WM_PAINT, sent|parent },
5653     { WM_PAINT, sent },
5654     { WM_NCPAINT, sent|beginpaint },
5655     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5656     { WM_ERASEBKGND, sent|beginpaint|optional },
5657     { 0 }
5658 };
5659
5660 static const struct message WmChildPaintNc[] = {
5661     { WM_PAINT, sent },
5662     { WM_NCPAINT, sent|beginpaint },
5663     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5664     { WM_ERASEBKGND, sent|beginpaint },
5665     { 0 }
5666 };
5667
5668 static const struct message WmParentErasePaint[] = {
5669     { WM_PAINT, sent|parent },
5670     { WM_NCPAINT, sent|parent|beginpaint },
5671     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5672     { WM_ERASEBKGND, sent|parent|beginpaint|optional },
5673     { WM_PAINT, sent },
5674     { WM_NCPAINT, sent|beginpaint },
5675     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5676     { WM_ERASEBKGND, sent|beginpaint|optional },
5677     { 0 }
5678 };
5679
5680 static const struct message WmParentOnlyNcPaint[] = {
5681     { WM_PAINT, sent|parent },
5682     { WM_NCPAINT, sent|parent|beginpaint },
5683     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5684     { 0 }
5685 };
5686
5687 static const struct message WmSetParentStyle[] = {
5688     { WM_STYLECHANGING, sent|parent },
5689     { WM_STYLECHANGED, sent|parent },
5690     { 0 }
5691 };
5692
5693 static void test_paint_messages(void)
5694 {
5695     BOOL ret;
5696     RECT rect;
5697     POINT pt;
5698     MSG msg;
5699     HWND hparent, hchild;
5700     HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
5701     HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
5702     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
5703                                 100, 100, 200, 200, 0, 0, 0, NULL);
5704     ok (hwnd != 0, "Failed to create overlapped window\n");
5705
5706     ShowWindow( hwnd, SW_SHOW );
5707     UpdateWindow( hwnd );
5708     flush_events();
5709     flush_sequence();
5710
5711     check_update_rgn( hwnd, 0 );
5712     SetRectRgn( hrgn, 10, 10, 20, 20 );
5713     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5714     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5715     check_update_rgn( hwnd, hrgn );
5716     SetRectRgn( hrgn2, 20, 20, 30, 30 );
5717     ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
5718     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5719     CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
5720     check_update_rgn( hwnd, hrgn );
5721     /* validate everything */
5722     ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5723     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5724     check_update_rgn( hwnd, 0 );
5725
5726     /* test empty region */
5727     SetRectRgn( hrgn, 10, 10, 10, 15 );
5728     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5729     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5730     check_update_rgn( hwnd, 0 );
5731     /* test empty rect */
5732     SetRect( &rect, 10, 10, 10, 15 );
5733     ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
5734     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5735     check_update_rgn( hwnd, 0 );
5736
5737     /* flush pending messages */
5738     flush_events();
5739     flush_sequence();
5740
5741     GetClientRect( hwnd, &rect );
5742     SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
5743     /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
5744      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5745      */
5746     trace("testing InvalidateRect(0, NULL, FALSE)\n");
5747     SetRectEmpty( &rect );
5748     ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
5749     check_update_rgn( hwnd, hrgn );
5750     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5751     flush_events();
5752     ok_sequence( WmPaint, "Paint", FALSE );
5753     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5754     check_update_rgn( hwnd, 0 );
5755
5756     /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
5757      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5758      */
5759     trace("testing ValidateRect(0, NULL)\n");
5760     SetRectEmpty( &rect );
5761     if (ValidateRect(0, &rect))  /* not supported on Win9x */
5762     {
5763         check_update_rgn( hwnd, hrgn );
5764         ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5765         flush_events();
5766         ok_sequence( WmPaint, "Paint", FALSE );
5767         RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5768         check_update_rgn( hwnd, 0 );
5769     }
5770
5771     trace("testing InvalidateRgn(0, NULL, FALSE)\n");
5772     SetLastError(0xdeadbeef);
5773     ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
5774     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
5775        "wrong error code %d\n", GetLastError());
5776     check_update_rgn( hwnd, 0 );
5777     flush_events();
5778     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5779
5780     trace("testing ValidateRgn(0, NULL)\n");
5781     SetLastError(0xdeadbeef);
5782     ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
5783     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
5784        broken( GetLastError() == 0xdeadbeef ) /* win9x */,
5785        "wrong error code %d\n", GetLastError());
5786     check_update_rgn( hwnd, 0 );
5787     flush_events();
5788     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5789
5790     /* now with frame */
5791     SetRectRgn( hrgn, -5, -5, 20, 20 );
5792
5793     /* flush pending messages */
5794     flush_events();
5795     flush_sequence();
5796     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5797     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5798
5799     SetRectRgn( hrgn, 0, 0, 20, 20 );  /* GetUpdateRgn clips to client area */
5800     check_update_rgn( hwnd, hrgn );
5801
5802     flush_sequence();
5803     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5804     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5805
5806     flush_sequence();
5807     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5808     ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
5809
5810     GetClientRect( hwnd, &rect );
5811     SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
5812     check_update_rgn( hwnd, hrgn );
5813
5814     flush_sequence();
5815     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
5816     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5817
5818     flush_sequence();
5819     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
5820     ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
5821     check_update_rgn( hwnd, 0 );
5822
5823     flush_sequence();
5824     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
5825     ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
5826     check_update_rgn( hwnd, 0 );
5827
5828     flush_sequence();
5829     SetRectRgn( hrgn, 0, 0, 100, 100 );
5830     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5831     SetRectRgn( hrgn, 0, 0, 50, 100 );
5832     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
5833     SetRectRgn( hrgn, 50, 0, 100, 100 );
5834     check_update_rgn( hwnd, hrgn );
5835     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5836     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );  /* must not generate messages, everything is valid */
5837     check_update_rgn( hwnd, 0 );
5838
5839     flush_sequence();
5840     SetRectRgn( hrgn, 0, 0, 100, 100 );
5841     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5842     SetRectRgn( hrgn, 0, 0, 100, 50 );
5843     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5844     ok_sequence( WmErase, "Erase", FALSE );
5845     SetRectRgn( hrgn, 0, 50, 100, 100 );
5846     check_update_rgn( hwnd, hrgn );
5847
5848     flush_sequence();
5849     SetRectRgn( hrgn, 0, 0, 100, 100 );
5850     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5851     SetRectRgn( hrgn, 0, 0, 50, 50 );
5852     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
5853     ok_sequence( WmPaint, "Paint", FALSE );
5854
5855     flush_sequence();
5856     SetRectRgn( hrgn, -4, -4, -2, -2 );
5857     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5858     SetRectRgn( hrgn, -200, -200, -198, -198 );
5859     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
5860     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5861
5862     flush_sequence();
5863     SetRectRgn( hrgn, -4, -4, -2, -2 );
5864     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5865     SetRectRgn( hrgn, -4, -4, -3, -3 );
5866     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
5867     SetRectRgn( hrgn, 0, 0, 1, 1 );
5868     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
5869     ok_sequence( WmPaint, "Paint", FALSE );
5870
5871     flush_sequence();
5872     SetRectRgn( hrgn, -4, -4, -1, -1 );
5873     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5874     RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
5875     /* make sure no WM_PAINT was generated */
5876     flush_events();
5877     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5878
5879     flush_sequence();
5880     SetRectRgn( hrgn, -4, -4, -1, -1 );
5881     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5882     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
5883     {
5884         if (msg.hwnd == hwnd && msg.message == WM_PAINT)
5885         {
5886             /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
5887             INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
5888             ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
5889             ret = GetUpdateRect( hwnd, &rect, FALSE );
5890             ok( ret, "Invalid GetUpdateRect result %d\n", ret );
5891             /* this will send WM_NCPAINT and validate the non client area */
5892             ret = GetUpdateRect( hwnd, &rect, TRUE );
5893             ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
5894         }
5895         DispatchMessage( &msg );
5896     }
5897     ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
5898
5899     DestroyWindow( hwnd );
5900
5901     /* now test with a child window */
5902
5903     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
5904                               100, 100, 200, 200, 0, 0, 0, NULL);
5905     ok (hparent != 0, "Failed to create parent window\n");
5906
5907     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
5908                            10, 10, 100, 100, hparent, 0, 0, NULL);
5909     ok (hchild != 0, "Failed to create child window\n");
5910
5911     ShowWindow( hparent, SW_SHOW );
5912     UpdateWindow( hparent );
5913     UpdateWindow( hchild );
5914     flush_events();
5915     flush_sequence();
5916     log_all_parent_messages++;
5917
5918     SetRect( &rect, 0, 0, 50, 50 );
5919     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5920     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5921     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
5922
5923     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5924     pt.x = pt.y = 0;
5925     MapWindowPoints( hchild, hparent, &pt, 1 );
5926     SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
5927     check_update_rgn( hchild, hrgn );
5928     SetRectRgn( hrgn, 0, 0, 50, 50 );
5929     check_update_rgn( hparent, hrgn );
5930     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5931     ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
5932     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5933     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5934
5935     flush_events();
5936     ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
5937
5938     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5939     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5940     ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
5941     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5942     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5943
5944     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
5945     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5946     ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
5947
5948     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
5949     flush_sequence();
5950     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5951     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5952     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
5953
5954     /* flush all paint messages */
5955     flush_events();
5956     flush_sequence();
5957
5958     /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
5959     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5960     SetRectRgn( hrgn, 0, 0, 50, 50 );
5961     check_update_rgn( hparent, hrgn );
5962     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5963     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5964     SetRectRgn( hrgn, 0, 0, 50, 50 );
5965     check_update_rgn( hparent, hrgn );
5966
5967     /* flush all paint messages */
5968     flush_events();
5969     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
5970     flush_sequence();
5971
5972     /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
5973     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5974     SetRectRgn( hrgn, 0, 0, 50, 50 );
5975     check_update_rgn( hparent, hrgn );
5976     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5977     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5978     SetRectRgn( hrgn2, 10, 10, 50, 50 );
5979     CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
5980     check_update_rgn( hparent, hrgn );
5981     /* flush all paint messages */
5982     flush_events();
5983     flush_sequence();
5984
5985     /* same as above but parent gets completely validated */
5986     SetRect( &rect, 20, 20, 30, 30 );
5987     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5988     SetRectRgn( hrgn, 20, 20, 30, 30 );
5989     check_update_rgn( hparent, hrgn );
5990     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5991     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5992     check_update_rgn( hparent, 0 );  /* no update region */
5993     flush_events();
5994     ok_sequence( WmEmptySeq, "WmEmpty", FALSE );  /* and no paint messages */
5995
5996     /* make sure RDW_VALIDATE on child doesn't have the same effect */
5997     flush_sequence();
5998     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5999     SetRectRgn( hrgn, 20, 20, 30, 30 );
6000     check_update_rgn( hparent, hrgn );
6001     RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
6002     SetRectRgn( hrgn, 20, 20, 30, 30 );
6003     check_update_rgn( hparent, hrgn );
6004
6005     /* same as above but normal WM_PAINT doesn't validate parent */
6006     flush_sequence();
6007     SetRect( &rect, 20, 20, 30, 30 );
6008     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6009     SetRectRgn( hrgn, 20, 20, 30, 30 );
6010     check_update_rgn( hparent, hrgn );
6011     /* no WM_PAINT in child while parent still pending */
6012     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6013     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6014     while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6015     ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
6016
6017     flush_sequence();
6018     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6019     /* no WM_PAINT in child while parent still pending */
6020     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6021     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6022     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
6023     /* now that parent is valid child should get WM_PAINT */
6024     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6025     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6026     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6027     ok_sequence( WmEmptySeq, "No other message", FALSE );
6028
6029     /* same thing with WS_CLIPCHILDREN in parent */
6030     flush_sequence();
6031     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6032     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6033     /* changing style invalidates non client area, but we need to invalidate something else to see it */
6034     RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
6035     ok_sequence( WmEmptySeq, "No message", FALSE );
6036     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
6037     ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
6038
6039     flush_sequence();
6040     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
6041     SetRectRgn( hrgn, 20, 20, 30, 30 );
6042     check_update_rgn( hparent, hrgn );
6043     /* no WM_PAINT in child while parent still pending */
6044     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6045     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6046     /* WM_PAINT in parent first */
6047     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6048     ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
6049
6050     /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
6051     flush_sequence();
6052     SetRect( &rect, 0, 0, 30, 30 );
6053     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
6054     SetRectRgn( hrgn, 0, 0, 30, 30 );
6055     check_update_rgn( hparent, hrgn );
6056     flush_events();
6057     ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
6058
6059     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6060     flush_sequence();
6061     SetRect( &rect, -10, 0, 30, 30 );
6062     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6063     SetRect( &rect, 0, 0, 20, 20 );
6064     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6065     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6066     ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
6067
6068     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6069     flush_sequence();
6070     SetRect( &rect, -10, 0, 30, 30 );
6071     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6072     SetRect( &rect, 0, 0, 100, 100 );
6073     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6074     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6075     ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
6076     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6077     ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
6078
6079     /* test RDW_INTERNALPAINT behavior */
6080
6081     flush_sequence();
6082     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
6083     flush_events();
6084     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6085
6086     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
6087     flush_events();
6088     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6089
6090     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6091     flush_events();
6092     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6093
6094     assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
6095     UpdateWindow( hparent );
6096     flush_events();
6097     flush_sequence();
6098     trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
6099     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6100     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6101                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6102     flush_events();
6103     ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
6104
6105     UpdateWindow( hparent );
6106     flush_events();
6107     flush_sequence();
6108     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
6109     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6110     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6111                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6112     flush_events();
6113     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6114
6115     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6116     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6117     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6118     flush_events();
6119     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6120
6121     assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
6122     UpdateWindow( hparent );
6123     flush_events();
6124     flush_sequence();
6125     trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
6126     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6127     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6128                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6129     flush_events();
6130     ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
6131
6132     UpdateWindow( hparent );
6133     flush_events();
6134     flush_sequence();
6135     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
6136     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6137     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6138                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6139     flush_events();
6140     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6141
6142     ok(GetWindowLong( hparent, GWL_STYLE ) & WS_VISIBLE, "parent should be visible\n");
6143     ok(GetWindowLong( hchild, GWL_STYLE ) & WS_VISIBLE, "child should be visible\n");
6144
6145     UpdateWindow( hparent );
6146     flush_events();
6147     flush_sequence();
6148     trace("testing SetWindowPos(-10000, -10000) on child\n");
6149     SetWindowPos( hchild, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6150     check_update_rgn( hchild, 0 );
6151     flush_events();
6152
6153 #if 0 /* this one doesn't pass under Wine yet */
6154     UpdateWindow( hparent );
6155     flush_events();
6156     flush_sequence();
6157     trace("testing ShowWindow(SW_MINIMIZE) on child\n");
6158     ShowWindow( hchild, SW_MINIMIZE );
6159     check_update_rgn( hchild, 0 );
6160     flush_events();
6161 #endif
6162
6163     UpdateWindow( hparent );
6164     flush_events();
6165     flush_sequence();
6166     trace("testing SetWindowPos(-10000, -10000) on parent\n");
6167     SetWindowPos( hparent, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6168     check_update_rgn( hparent, 0 );
6169     flush_events();
6170
6171     log_all_parent_messages--;
6172     DestroyWindow( hparent );
6173     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6174
6175     /* tests for moving windows off-screen (needs simple WS_POPUP windows) */
6176
6177     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_POPUP | WS_VISIBLE,
6178                               100, 100, 200, 200, 0, 0, 0, NULL);
6179     ok (hparent != 0, "Failed to create parent window\n");
6180
6181     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
6182                            10, 10, 100, 100, hparent, 0, 0, NULL);
6183     ok (hchild != 0, "Failed to create child window\n");
6184
6185     ShowWindow( hparent, SW_SHOW );
6186     UpdateWindow( hparent );
6187     UpdateWindow( hchild );
6188     flush_events();
6189     flush_sequence();
6190
6191     /* moving child outside of parent boundaries changes update region */
6192     SetRect( &rect, 0, 0, 40, 40 );
6193     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6194     SetRectRgn( hrgn, 0, 0, 40, 40 );
6195     check_update_rgn( hchild, hrgn );
6196     MoveWindow( hchild, -10, 10, 100, 100, FALSE );
6197     SetRectRgn( hrgn, 10, 0, 40, 40 );
6198     check_update_rgn( hchild, hrgn );
6199     MoveWindow( hchild, -10, -10, 100, 100, FALSE );
6200     SetRectRgn( hrgn, 10, 10, 40, 40 );
6201     check_update_rgn( hchild, hrgn );
6202
6203     /* moving parent off-screen does too */
6204     SetRect( &rect, 0, 0, 100, 100 );
6205     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
6206     SetRectRgn( hrgn, 0, 0, 100, 100 );
6207     check_update_rgn( hparent, hrgn );
6208     SetRectRgn( hrgn, 10, 10, 40, 40 );
6209     check_update_rgn( hchild, hrgn );
6210     MoveWindow( hparent, -20, -20, 200, 200, FALSE );
6211     SetRectRgn( hrgn, 20, 20, 100, 100 );
6212     check_update_rgn( hparent, hrgn );
6213     SetRectRgn( hrgn, 30, 30, 40, 40 );
6214     check_update_rgn( hchild, hrgn );
6215
6216     /* invalidated region is cropped by the parent rects */
6217     SetRect( &rect, 0, 0, 50, 50 );
6218     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6219     SetRectRgn( hrgn, 30, 30, 50, 50 );
6220     check_update_rgn( hchild, hrgn );
6221
6222     DestroyWindow( hparent );
6223     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6224     flush_sequence();
6225
6226     DeleteObject( hrgn );
6227     DeleteObject( hrgn2 );
6228 }
6229
6230 struct wnd_event
6231 {
6232     HWND hwnd;
6233     HANDLE event;
6234 };
6235
6236 static DWORD WINAPI thread_proc(void *param)
6237 {
6238     MSG msg;
6239     struct wnd_event *wnd_event = (struct wnd_event *)param;
6240
6241     wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
6242                                       100, 100, 200, 200, 0, 0, 0, NULL);
6243     ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
6244
6245     SetEvent(wnd_event->event);
6246
6247     while (GetMessage(&msg, 0, 0, 0))
6248     {
6249         TranslateMessage(&msg);
6250         DispatchMessage(&msg);
6251     }
6252
6253     ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
6254
6255     return 0;
6256 }
6257
6258 static void test_interthread_messages(void)
6259 {
6260     HANDLE hThread;
6261     DWORD tid;
6262     WNDPROC proc;
6263     MSG msg;
6264     char buf[256];
6265     int len, expected_len;
6266     struct wnd_event wnd_event;
6267     BOOL ret;
6268
6269     wnd_event.event = CreateEventW(NULL, 0, 0, NULL);
6270     if (!wnd_event.event)
6271     {
6272         trace("skipping interthread message test under win9x\n");
6273         return;
6274     }
6275
6276     hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
6277     ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
6278
6279     ok(WaitForSingleObject(wnd_event.event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6280
6281     CloseHandle(wnd_event.event);
6282
6283     SetLastError(0xdeadbeef);
6284     ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
6285     ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
6286        "wrong error code %d\n", GetLastError());
6287
6288     proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6289     ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
6290
6291     expected_len = lstrlenA("window caption text");
6292     memset(buf, 0, sizeof(buf));
6293     SetLastError(0xdeadbeef);
6294     len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
6295     ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
6296     ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
6297
6298     msg.hwnd = wnd_event.hwnd;
6299     msg.message = WM_GETTEXT;
6300     msg.wParam = sizeof(buf);
6301     msg.lParam = (LPARAM)buf;
6302     memset(buf, 0, sizeof(buf));
6303     SetLastError(0xdeadbeef);
6304     len = DispatchMessageA(&msg);
6305     ok((!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY) || broken(len), /* nt4 */
6306        "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
6307
6308     /* the following test causes an exception in user.exe under win9x */
6309     msg.hwnd = wnd_event.hwnd;
6310     msg.message = WM_TIMER;
6311     msg.wParam = 0;
6312     msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6313     SetLastError(0xdeadbeef);
6314     len = DispatchMessageA(&msg);
6315     ok(!len && GetLastError() == 0xdeadbeef,
6316        "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
6317
6318     ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
6319     ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
6320
6321     ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6322     CloseHandle(hThread);
6323
6324     ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
6325 }
6326
6327
6328 static const struct message WmVkN[] = {
6329     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6330     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6331     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6332     { WM_CHAR, wparam|lparam, 'n', 1 },
6333     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
6334     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6335     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6336     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6337     { 0 }
6338 };
6339 static const struct message WmShiftVkN[] = {
6340     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6341     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6342     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6343     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6344     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6345     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6346     { WM_CHAR, wparam|lparam, 'N', 1 },
6347     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
6348     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6349     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6350     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6351     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6352     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6353     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6354     { 0 }
6355 };
6356 static const struct message WmCtrlVkN[] = {
6357     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6358     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6359     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6360     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6361     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6362     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6363     { WM_CHAR, wparam|lparam, 0x000e, 1 },
6364     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6365     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6366     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6367     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6368     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6369     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6370     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6371     { 0 }
6372 };
6373 static const struct message WmCtrlVkN_2[] = {
6374     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6375     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6376     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6377     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6378     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6379     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6380     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6381     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6382     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6383     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6384     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6385     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6386     { 0 }
6387 };
6388 static const struct message WmAltVkN[] = {
6389     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6390     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6391     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6392     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6393     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6394     { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6395     { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
6396     { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
6397     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
6398     { HCBT_SYSCOMMAND, hook },
6399     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6400     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6401     { 0x00AE, sent|defwinproc|optional }, /* XP */
6402     { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
6403     { WM_INITMENU, sent|defwinproc },
6404     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6405     { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
6406     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
6407     { WM_CAPTURECHANGED, sent|defwinproc },
6408     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
6409     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6410     { WM_EXITMENULOOP, sent|defwinproc },
6411     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
6412     { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
6413     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6414     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6415     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6416     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6417     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6418     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6419     { 0 }
6420 };
6421 static const struct message WmAltVkN_2[] = {
6422     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6423     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6424     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6425     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6426     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6427     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
6428     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6429     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6430     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6431     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6432     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6433     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6434     { 0 }
6435 };
6436 static const struct message WmCtrlAltVkN[] = {
6437     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6438     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6439     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6440     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6441     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6442     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6443     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6444     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6445     { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6446     { WM_CHAR, optional },
6447     { WM_CHAR, sent|optional },
6448     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6449     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6450     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6451     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6452     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6453     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6454     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6455     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6456     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6457     { 0 }
6458 };
6459 static const struct message WmCtrlShiftVkN[] = {
6460     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6461     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6462     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6463     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6464     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6465     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6466     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6467     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6468     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
6469     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6470     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6471     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6472     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6473     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6474     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6475     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6476     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6477     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6478     { 0 }
6479 };
6480 static const struct message WmCtrlAltShiftVkN[] = {
6481     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6482     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6483     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6484     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6485     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6486     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6487     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
6488     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
6489     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
6490     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6491     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6492     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
6493     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6494     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6495     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6496     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
6497     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
6498     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
6499     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6500     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6501     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6502     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6503     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6504     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6505     { 0 }
6506 };
6507 static const struct message WmAltPressRelease[] = {
6508     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6509     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6510     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6511     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6512     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6513     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6514     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
6515     { HCBT_SYSCOMMAND, hook },
6516     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6517     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6518     { WM_INITMENU, sent|defwinproc },
6519     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6520     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6521     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6522
6523     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
6524
6525     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6526     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
6527     { WM_CAPTURECHANGED, sent|defwinproc },
6528     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
6529     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6530     { WM_EXITMENULOOP, sent|defwinproc },
6531     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6532     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6533     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6534     { 0 }
6535 };
6536 static const struct message WmAltMouseButton[] = {
6537     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6538     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6539     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6540     { WM_MOUSEMOVE, wparam|optional, 0, 0 },
6541     { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
6542     { WM_LBUTTONDOWN, wparam, MK_LBUTTON, 0 },
6543     { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON, 0 },
6544     { WM_LBUTTONUP, wparam, 0, 0 },
6545     { WM_LBUTTONUP, sent|wparam, 0, 0 },
6546     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6547     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6548     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6549     { 0 }
6550 };
6551 static const struct message WmF1Seq[] = {
6552     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
6553     { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
6554     { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
6555     { WM_KEYF1, wparam|lparam, 0, 0 },
6556     { WM_KEYF1, sent|wparam|lparam, 0, 0 },
6557     { WM_HELP, sent|defwinproc },
6558     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
6559     { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
6560     { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
6561     { 0 }
6562 };
6563 static const struct message WmVkAppsSeq[] = {
6564     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
6565     { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
6566     { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
6567     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
6568     { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
6569     { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
6570     { WM_CONTEXTMENU, lparam, /*hwnd*/0, (LPARAM)-1 },
6571     { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, (LPARAM)-1 },
6572     { 0 }
6573 };
6574
6575 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
6576 {
6577     MSG msg;
6578
6579     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
6580     {
6581         struct recvd_message log_msg;
6582
6583         /* ignore some unwanted messages */
6584         if (msg.message == WM_MOUSEMOVE ||
6585             msg.message == WM_GETICON ||
6586             msg.message == WM_GETOBJECT ||
6587             msg.message == WM_TIMER ||
6588             msg.message == WM_DEVICECHANGE)
6589             continue;
6590
6591         log_msg.hwnd = msg.hwnd;
6592         log_msg.message = msg.message;
6593         log_msg.flags = wparam|lparam;
6594         log_msg.wParam = msg.wParam;
6595         log_msg.lParam = msg.lParam;
6596         log_msg.descr = "accel";
6597         add_message(&log_msg);
6598
6599         if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
6600         {
6601             TranslateMessage(&msg);
6602             DispatchMessage(&msg);
6603         }
6604     }
6605 }
6606
6607 static void test_accelerators(void)
6608 {
6609     RECT rc;
6610     SHORT state;
6611     HACCEL hAccel;
6612     HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6613                                 100, 100, 200, 200, 0, 0, 0, NULL);
6614     BOOL ret;
6615
6616     assert(hwnd != 0);
6617     UpdateWindow(hwnd);
6618     flush_events();
6619     flush_sequence();
6620
6621     SetFocus(hwnd);
6622     ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
6623
6624     state = GetKeyState(VK_SHIFT);
6625     ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
6626     state = GetKeyState(VK_CAPITAL);
6627     ok(state == 0, "wrong CapsLock state %04x\n", state);
6628
6629     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
6630     assert(hAccel != 0);
6631
6632     flush_events();
6633     pump_msg_loop(hwnd, 0);
6634     flush_sequence();
6635
6636     trace("testing VK_N press/release\n");
6637     flush_sequence();
6638     keybd_event('N', 0, 0, 0);
6639     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6640     pump_msg_loop(hwnd, hAccel);
6641     ok_sequence(WmVkN, "VK_N press/release", FALSE);
6642
6643     trace("testing Shift+VK_N press/release\n");
6644     flush_sequence();
6645     keybd_event(VK_SHIFT, 0, 0, 0);
6646     keybd_event('N', 0, 0, 0);
6647     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6648     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6649     pump_msg_loop(hwnd, hAccel);
6650     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6651
6652     trace("testing Ctrl+VK_N press/release\n");
6653     flush_sequence();
6654     keybd_event(VK_CONTROL, 0, 0, 0);
6655     keybd_event('N', 0, 0, 0);
6656     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6657     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6658     pump_msg_loop(hwnd, hAccel);
6659     ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
6660
6661     trace("testing Alt+VK_N press/release\n");
6662     flush_sequence();
6663     keybd_event(VK_MENU, 0, 0, 0);
6664     keybd_event('N', 0, 0, 0);
6665     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6666     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6667     pump_msg_loop(hwnd, hAccel);
6668     ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
6669
6670     trace("testing Ctrl+Alt+VK_N press/release 1\n");
6671     flush_sequence();
6672     keybd_event(VK_CONTROL, 0, 0, 0);
6673     keybd_event(VK_MENU, 0, 0, 0);
6674     keybd_event('N', 0, 0, 0);
6675     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6676     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6677     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6678     pump_msg_loop(hwnd, hAccel);
6679     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
6680
6681     ret = DestroyAcceleratorTable(hAccel);
6682     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6683
6684     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
6685     assert(hAccel != 0);
6686
6687     trace("testing VK_N press/release\n");
6688     flush_sequence();
6689     keybd_event('N', 0, 0, 0);
6690     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6691     pump_msg_loop(hwnd, hAccel);
6692     ok_sequence(WmVkN, "VK_N press/release", FALSE);
6693
6694     trace("testing Shift+VK_N press/release\n");
6695     flush_sequence();
6696     keybd_event(VK_SHIFT, 0, 0, 0);
6697     keybd_event('N', 0, 0, 0);
6698     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6699     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6700     pump_msg_loop(hwnd, hAccel);
6701     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6702
6703     trace("testing Ctrl+VK_N press/release 2\n");
6704     flush_sequence();
6705     keybd_event(VK_CONTROL, 0, 0, 0);
6706     keybd_event('N', 0, 0, 0);
6707     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6708     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6709     pump_msg_loop(hwnd, hAccel);
6710     ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
6711
6712     trace("testing Alt+VK_N press/release 2\n");
6713     flush_sequence();
6714     keybd_event(VK_MENU, 0, 0, 0);
6715     keybd_event('N', 0, 0, 0);
6716     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6717     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6718     pump_msg_loop(hwnd, hAccel);
6719     ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
6720
6721     trace("testing Ctrl+Alt+VK_N press/release 2\n");
6722     flush_sequence();
6723     keybd_event(VK_CONTROL, 0, 0, 0);
6724     keybd_event(VK_MENU, 0, 0, 0);
6725     keybd_event('N', 0, 0, 0);
6726     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6727     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6728     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6729     pump_msg_loop(hwnd, hAccel);
6730     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
6731
6732     trace("testing Ctrl+Shift+VK_N press/release\n");
6733     flush_sequence();
6734     keybd_event(VK_CONTROL, 0, 0, 0);
6735     keybd_event(VK_SHIFT, 0, 0, 0);
6736     keybd_event('N', 0, 0, 0);
6737     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6738     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6739     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6740     pump_msg_loop(hwnd, hAccel);
6741     ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
6742
6743     trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
6744     flush_sequence();
6745     keybd_event(VK_CONTROL, 0, 0, 0);
6746     keybd_event(VK_MENU, 0, 0, 0);
6747     keybd_event(VK_SHIFT, 0, 0, 0);
6748     keybd_event('N', 0, 0, 0);
6749     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6750     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6751     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6752     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6753     pump_msg_loop(hwnd, hAccel);
6754     ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
6755
6756     ret = DestroyAcceleratorTable(hAccel);
6757     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6758
6759     trace("testing Alt press/release\n");
6760     flush_sequence();
6761     keybd_event(VK_MENU, 0, 0, 0);
6762     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6763     keybd_event(VK_MENU, 0, 0, 0);
6764     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6765     pump_msg_loop(hwnd, 0);
6766     /* this test doesn't pass in Wine for managed windows */
6767     ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
6768
6769     trace("testing Alt+MouseButton press/release\n");
6770     /* first, move mouse pointer inside of the window client area */
6771     GetClientRect(hwnd, &rc);
6772     MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
6773     rc.left += (rc.right - rc.left)/2;
6774     rc.top += (rc.bottom - rc.top)/2;
6775     SetCursorPos(rc.left, rc.top);
6776
6777     flush_events();
6778     flush_sequence();
6779     keybd_event(VK_MENU, 0, 0, 0);
6780     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
6781     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
6782     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6783     pump_msg_loop(hwnd, 0);
6784     ok_sequence(WmAltMouseButton, "Alt+MouseButton press/release", FALSE);
6785
6786     trace("testing VK_F1 press/release\n");
6787     keybd_event(VK_F1, 0, 0, 0);
6788     keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
6789     pump_msg_loop(hwnd, 0);
6790     ok_sequence(WmF1Seq, "F1 press/release", FALSE);
6791
6792     trace("testing VK_APPS press/release\n");
6793     keybd_event(VK_APPS, 0, 0, 0);
6794     keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
6795     pump_msg_loop(hwnd, 0);
6796     ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
6797
6798     DestroyWindow(hwnd);
6799 }
6800
6801 /************* window procedures ********************/
6802
6803 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message, 
6804                              WPARAM wParam, LPARAM lParam)
6805 {
6806     static long defwndproc_counter = 0;
6807     static long beginpaint_counter = 0;
6808     LRESULT ret;
6809     struct recvd_message msg;
6810
6811     /* ignore registered messages */
6812     if (message >= 0xc000) return 0;
6813
6814     switch (message)
6815     {
6816         case WM_ENABLE:
6817         {
6818             LONG style = GetWindowLongA(hwnd, GWL_STYLE);
6819             ok((BOOL)wParam == !(style & WS_DISABLED),
6820                 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
6821             break;
6822         }
6823
6824         case WM_CAPTURECHANGED:
6825             if (test_DestroyWindow_flag)
6826             {
6827                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6828                 if (style & WS_CHILD)
6829                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6830                 else if (style & WS_POPUP)
6831                     lParam = WND_POPUP_ID;
6832                 else
6833                     lParam = WND_PARENT_ID;
6834             }
6835             break;
6836
6837         case WM_NCDESTROY:
6838         {
6839             HWND capture;
6840
6841             ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
6842             capture = GetCapture();
6843             if (capture)
6844             {
6845                 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
6846                 trace("current capture %p, releasing...\n", capture);
6847                 ReleaseCapture();
6848             }
6849         }
6850         /* fall through */
6851         case WM_DESTROY:
6852             if (pGetAncestor)
6853                 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
6854             if (test_DestroyWindow_flag)
6855             {
6856                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6857                 if (style & WS_CHILD)
6858                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6859                 else if (style & WS_POPUP)
6860                     lParam = WND_POPUP_ID;
6861                 else
6862                     lParam = WND_PARENT_ID;
6863             }
6864             break;
6865
6866         /* test_accelerators() depends on this */
6867         case WM_NCHITTEST:
6868             return HTCLIENT;
6869
6870         /* ignore */
6871         case WM_MOUSEMOVE:
6872         case WM_MOUSEACTIVATE:
6873         case WM_NCMOUSEMOVE:
6874         case WM_SETCURSOR:
6875         case WM_GETICON:
6876         case WM_GETOBJECT:
6877         case WM_DEVICECHANGE:
6878         case WM_IME_SELECT:
6879             return 0;
6880     }
6881
6882     msg.hwnd = hwnd;
6883     msg.message = message;
6884     msg.flags = sent|wparam|lparam;
6885     if (defwndproc_counter) msg.flags |= defwinproc;
6886     if (beginpaint_counter) msg.flags |= beginpaint;
6887     msg.wParam = wParam;
6888     msg.lParam = lParam;
6889     msg.descr = "MsgCheckProc";
6890     add_message(&msg);
6891
6892     if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
6893     {
6894         HWND parent = GetParent(hwnd);
6895         RECT rc;
6896         MINMAXINFO *minmax = (MINMAXINFO *)lParam;
6897
6898         GetClientRect(parent, &rc);
6899         trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
6900         trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
6901               minmax->ptReserved.x, minmax->ptReserved.y,
6902               minmax->ptMaxSize.x, minmax->ptMaxSize.y,
6903               minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
6904               minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
6905               minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
6906
6907         ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
6908            minmax->ptMaxSize.x, rc.right);
6909         ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
6910            minmax->ptMaxSize.y, rc.bottom);
6911     }
6912
6913     if (message == WM_PAINT)
6914     {
6915         PAINTSTRUCT ps;
6916         beginpaint_counter++;
6917         BeginPaint( hwnd, &ps );
6918         beginpaint_counter--;
6919         EndPaint( hwnd, &ps );
6920         return 0;
6921     }
6922
6923     defwndproc_counter++;
6924     ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam) 
6925                   : DefWindowProcA(hwnd, message, wParam, lParam);
6926     defwndproc_counter--;
6927
6928     return ret;
6929 }
6930
6931 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6932 {
6933     return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
6934 }
6935
6936 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6937 {
6938     return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
6939 }
6940
6941 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6942 {
6943     static long defwndproc_counter = 0;
6944     LRESULT ret;
6945     struct recvd_message msg;
6946
6947     switch (message)
6948     {
6949     case WM_GETICON:
6950     case WM_GETOBJECT:
6951         return 0;  /* ignore them */
6952     case WM_QUERYENDSESSION:
6953     case WM_ENDSESSION:
6954         lParam &= ~0x01;  /* Vista adds a 0x01 flag */
6955         break;
6956     }
6957
6958     msg.hwnd = hwnd;
6959     msg.message = message;
6960     msg.flags = sent|wparam|lparam;
6961     if (defwndproc_counter) msg.flags |= defwinproc;
6962     msg.wParam = wParam;
6963     msg.lParam = lParam;
6964     msg.descr = "popup";
6965     add_message(&msg);
6966
6967     if (message == WM_CREATE)
6968     {
6969         DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
6970         SetWindowLongA(hwnd, GWL_STYLE, style);
6971     }
6972
6973     defwndproc_counter++;
6974     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6975     defwndproc_counter--;
6976
6977     return ret;
6978 }
6979
6980 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6981 {
6982     static long defwndproc_counter = 0;
6983     static long beginpaint_counter = 0;
6984     LRESULT ret;
6985     struct recvd_message msg;
6986
6987     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
6988
6989     /* ignore registered messages */
6990     if (message >= 0xc000) return 0;
6991
6992     if (log_all_parent_messages ||
6993         message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
6994         message == WM_SETFOCUS || message == WM_KILLFOCUS ||
6995         message == WM_ENABLE || message == WM_ENTERIDLE ||
6996         message == WM_DRAWITEM ||
6997         message == WM_IME_SETCONTEXT)
6998     {
6999         switch (message)
7000         {
7001             /* ignore */
7002             case WM_NCHITTEST:
7003                 return HTCLIENT;
7004             case WM_SETCURSOR:
7005             case WM_MOUSEMOVE:
7006             case WM_NCMOUSEMOVE:
7007                 return 0;
7008
7009             case WM_ERASEBKGND:
7010             {
7011                 RECT rc;
7012                 INT ret = GetClipBox((HDC)wParam, &rc);
7013
7014                 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
7015                        ret, rc.left, rc.top, rc.right, rc.bottom);
7016                 break;
7017             }
7018         }
7019
7020         msg.hwnd = hwnd;
7021         msg.message = message;
7022         msg.flags = sent|parent|wparam|lparam;
7023         if (defwndproc_counter) msg.flags |= defwinproc;
7024         if (beginpaint_counter) msg.flags |= beginpaint;
7025         msg.wParam = wParam;
7026         msg.lParam = lParam;
7027         msg.descr = "parent";
7028         add_message(&msg);
7029     }
7030
7031     if (message == WM_PAINT)
7032     {
7033         PAINTSTRUCT ps;
7034         beginpaint_counter++;
7035         BeginPaint( hwnd, &ps );
7036         beginpaint_counter--;
7037         EndPaint( hwnd, &ps );
7038         return 0;
7039     }
7040
7041     defwndproc_counter++;
7042     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7043     defwndproc_counter--;
7044
7045     return ret;
7046 }
7047
7048 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7049 {
7050     static long defwndproc_counter = 0;
7051     LRESULT ret;
7052     struct recvd_message msg;
7053
7054     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
7055
7056     if (test_def_id)
7057     {
7058         DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
7059         ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
7060         if (after_end_dialog)
7061             ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
7062         else
7063             ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
7064     }
7065
7066     msg.hwnd = hwnd;
7067     msg.message = message;
7068     msg.flags = sent|wparam|lparam;
7069     if (defwndproc_counter) msg.flags |= defwinproc;
7070     msg.wParam = wParam;
7071     msg.lParam = lParam;
7072     msg.descr = "dialog";
7073     add_message(&msg);
7074
7075     defwndproc_counter++;
7076     ret = DefDlgProcA(hwnd, message, wParam, lParam);
7077     defwndproc_counter--;
7078
7079     return ret;
7080 }
7081
7082 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7083 {
7084     static long defwndproc_counter = 0;
7085     LRESULT ret;
7086     struct recvd_message msg;
7087
7088     /* log only specific messages we are interested in */
7089     switch (message)
7090     {
7091 #if 0 /* probably log these as well */
7092     case WM_ACTIVATE:
7093     case WM_SETFOCUS:
7094     case WM_KILLFOCUS:
7095 #endif
7096     case WM_SHOWWINDOW:
7097     case WM_SIZE:
7098     case WM_MOVE:
7099     case WM_GETMINMAXINFO:
7100     case WM_WINDOWPOSCHANGING:
7101     case WM_WINDOWPOSCHANGED:
7102         break;
7103
7104     default: /* ignore */
7105         /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
7106         return DefWindowProcA(hwnd, message, wParam, lParam);
7107     }
7108
7109     msg.hwnd = hwnd;
7110     msg.message = message;
7111     msg.flags = sent|wparam|lparam;
7112     if (defwndproc_counter) msg.flags |= defwinproc;
7113     msg.wParam = wParam;
7114     msg.lParam = lParam;
7115     msg.descr = "show";
7116     add_message(&msg);
7117
7118     defwndproc_counter++;
7119     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7120     defwndproc_counter--;
7121
7122     return ret;
7123 }
7124
7125 static LRESULT WINAPI PaintLoopProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
7126 {
7127     switch (msg)
7128     {
7129         case WM_CREATE: return 0;
7130         case WM_PAINT:
7131         {
7132             MSG msg2;
7133             static int i = 0;
7134
7135             if (i < 256)
7136             {
7137                 i++;
7138                 if (PeekMessageA(&msg2, 0, 0, 0, 1))
7139                 {
7140                     TranslateMessage(&msg2);
7141                     DispatchMessage(&msg2);
7142                 }
7143                 i--;
7144             }
7145             else ok(broken(1), "infinite loop\n");
7146             if ( i == 0)
7147                 paint_loop_done = 1;
7148             return DefWindowProcA(hWnd,msg,wParam,lParam);
7149         }
7150     }
7151     return DefWindowProcA(hWnd,msg,wParam,lParam);
7152 }
7153
7154 static BOOL RegisterWindowClasses(void)
7155 {
7156     WNDCLASSA cls;
7157     WNDCLASSW clsW;
7158
7159     cls.style = 0;
7160     cls.lpfnWndProc = MsgCheckProcA;
7161     cls.cbClsExtra = 0;
7162     cls.cbWndExtra = 0;
7163     cls.hInstance = GetModuleHandleA(0);
7164     cls.hIcon = 0;
7165     cls.hCursor = LoadCursorA(0, IDC_ARROW);
7166     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7167     cls.lpszMenuName = NULL;
7168     cls.lpszClassName = "TestWindowClass";
7169     if(!RegisterClassA(&cls)) return FALSE;
7170
7171     cls.lpfnWndProc = ShowWindowProcA;
7172     cls.lpszClassName = "ShowWindowClass";
7173     if(!RegisterClassA(&cls)) return FALSE;
7174
7175     cls.lpfnWndProc = PopupMsgCheckProcA;
7176     cls.lpszClassName = "TestPopupClass";
7177     if(!RegisterClassA(&cls)) return FALSE;
7178
7179     cls.lpfnWndProc = ParentMsgCheckProcA;
7180     cls.lpszClassName = "TestParentClass";
7181     if(!RegisterClassA(&cls)) return FALSE;
7182
7183     cls.lpfnWndProc = DefWindowProcA;
7184     cls.lpszClassName = "SimpleWindowClass";
7185     if(!RegisterClassA(&cls)) return FALSE;
7186
7187     cls.lpfnWndProc = PaintLoopProcA;
7188     cls.lpszClassName = "PaintLoopWindowClass";
7189     if(!RegisterClassA(&cls)) return FALSE;
7190
7191     cls.style = CS_NOCLOSE;
7192     cls.lpszClassName = "NoCloseWindowClass";
7193     if(!RegisterClassA(&cls)) return FALSE;
7194
7195     ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
7196     cls.style = 0;
7197     cls.hInstance = GetModuleHandleA(0);
7198     cls.hbrBackground = 0;
7199     cls.lpfnWndProc = TestDlgProcA;
7200     cls.lpszClassName = "TestDialogClass";
7201     if(!RegisterClassA(&cls)) return FALSE;
7202
7203     clsW.style = 0;
7204     clsW.lpfnWndProc = MsgCheckProcW;
7205     clsW.cbClsExtra = 0;
7206     clsW.cbWndExtra = 0;
7207     clsW.hInstance = GetModuleHandleW(0);
7208     clsW.hIcon = 0;
7209     clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
7210     clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
7211     clsW.lpszMenuName = NULL;
7212     clsW.lpszClassName = testWindowClassW;
7213     RegisterClassW(&clsW);  /* ignore error, this fails on Win9x */
7214
7215     return TRUE;
7216 }
7217
7218 static BOOL is_our_logged_class(HWND hwnd)
7219 {
7220     char buf[256];
7221
7222     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7223     {
7224         if (!lstrcmpiA(buf, "TestWindowClass") ||
7225             !lstrcmpiA(buf, "ShowWindowClass") ||
7226             !lstrcmpiA(buf, "TestParentClass") ||
7227             !lstrcmpiA(buf, "TestPopupClass") ||
7228             !lstrcmpiA(buf, "SimpleWindowClass") ||
7229             !lstrcmpiA(buf, "TestDialogClass") ||
7230             !lstrcmpiA(buf, "MDI_frame_class") ||
7231             !lstrcmpiA(buf, "MDI_client_class") ||
7232             !lstrcmpiA(buf, "MDI_child_class") ||
7233             !lstrcmpiA(buf, "my_button_class") ||
7234             !lstrcmpiA(buf, "my_edit_class") ||
7235             !lstrcmpiA(buf, "static") ||
7236             !lstrcmpiA(buf, "ListBox") ||
7237             !lstrcmpiA(buf, "ComboBox") ||
7238             !lstrcmpiA(buf, "MyDialogClass") ||
7239             !lstrcmpiA(buf, "#32770") ||
7240             !lstrcmpiA(buf, "#32768"))
7241         return TRUE;
7242     }
7243     return FALSE;
7244 }
7245
7246 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7247
7248     HWND hwnd;
7249
7250     ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7251
7252     if (nCode == HCBT_CLICKSKIPPED)
7253     {
7254         /* ignore this event, XP sends it a lot when switching focus between windows */
7255         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7256     }
7257
7258     if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
7259     {
7260         struct recvd_message msg;
7261
7262         msg.hwnd = 0;
7263         msg.message = nCode;
7264         msg.flags = hook|wparam|lparam;
7265         msg.wParam = wParam;
7266         msg.lParam = lParam;
7267         msg.descr = "CBT";
7268         add_message(&msg);
7269
7270         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7271     }
7272
7273     if (nCode == HCBT_DESTROYWND)
7274     {
7275         if (test_DestroyWindow_flag)
7276         {
7277             DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
7278             if (style & WS_CHILD)
7279                 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
7280             else if (style & WS_POPUP)
7281                 lParam = WND_POPUP_ID;
7282             else
7283                 lParam = WND_PARENT_ID;
7284         }
7285     }
7286
7287     /* Log also SetFocus(0) calls */
7288     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7289
7290     if (is_our_logged_class(hwnd))
7291     {
7292         struct recvd_message msg;
7293
7294         msg.hwnd = hwnd;
7295         msg.message = nCode;
7296         msg.flags = hook|wparam|lparam;
7297         msg.wParam = wParam;
7298         msg.lParam = lParam;
7299         msg.descr = "CBT";
7300         add_message(&msg);
7301     }
7302     return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7303 }
7304
7305 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
7306                                     DWORD event,
7307                                     HWND hwnd,
7308                                     LONG object_id,
7309                                     LONG child_id,
7310                                     DWORD thread_id,
7311                                     DWORD event_time)
7312 {
7313     ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7314
7315     /* ignore mouse cursor events */
7316     if (object_id == OBJID_CURSOR) return;
7317
7318     if (!hwnd || is_our_logged_class(hwnd))
7319     {
7320         struct recvd_message msg;
7321
7322         msg.hwnd = hwnd;
7323         msg.message = event;
7324         msg.flags = winevent_hook|wparam|lparam;
7325         msg.wParam = object_id;
7326         msg.lParam = child_id;
7327         msg.descr = "WEH";
7328         add_message(&msg);
7329     }
7330 }
7331
7332 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
7333 static const WCHAR wszAnsi[] = {'U',0};
7334
7335 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
7336 {
7337     switch (uMsg)
7338     {
7339     case CB_FINDSTRINGEXACT:
7340         trace("String: %p\n", (LPCWSTR)lParam);
7341         if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
7342             return 1;
7343         if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
7344             return 0;
7345         return -1;
7346     }
7347     return DefWindowProcW(hwnd, uMsg, wParam, lParam);
7348 }
7349
7350 static const struct message WmGetTextLengthAfromW[] = {
7351     { WM_GETTEXTLENGTH, sent },
7352     { WM_GETTEXT, sent|optional },
7353     { 0 }
7354 };
7355
7356 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
7357
7358 /* dummy window proc for WM_GETTEXTLENGTH test */
7359 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
7360 {
7361     switch(msg)
7362     {
7363     case WM_GETTEXTLENGTH:
7364         return lstrlenW(dummy_window_text) + 37;  /* some random length */
7365     case WM_GETTEXT:
7366         lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
7367         return lstrlenW( (LPWSTR)lp );
7368     default:
7369         return DefWindowProcW( hwnd, msg, wp, lp );
7370     }
7371 }
7372
7373 static void test_message_conversion(void)
7374 {
7375     static const WCHAR wszMsgConversionClass[] =
7376         {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
7377     WNDCLASSW cls;
7378     LRESULT lRes;
7379     HWND hwnd;
7380     WNDPROC wndproc, newproc;
7381     BOOL ret;
7382
7383     cls.style = 0;
7384     cls.lpfnWndProc = MsgConversionProcW;
7385     cls.cbClsExtra = 0;
7386     cls.cbWndExtra = 0;
7387     cls.hInstance = GetModuleHandleW(NULL);
7388     cls.hIcon = NULL;
7389     cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
7390     cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
7391     cls.lpszMenuName = NULL;
7392     cls.lpszClassName = wszMsgConversionClass;
7393     /* this call will fail on Win9x, but that doesn't matter as this test is
7394      * meaningless on those platforms */
7395     if(!RegisterClassW(&cls)) return;
7396
7397     hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
7398                            100, 100, 200, 200, 0, 0, 0, NULL);
7399     ok(hwnd != NULL, "Window creation failed\n");
7400
7401     /* {W, A} -> A */
7402
7403     wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
7404     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7405     ok(lRes == 0, "String should have been converted\n");
7406     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7407     ok(lRes == 1, "String shouldn't have been converted\n");
7408
7409     /* {W, A} -> W */
7410
7411     wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
7412     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7413     ok(lRes == 1, "String shouldn't have been converted\n");
7414     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7415     ok(lRes == 1, "String shouldn't have been converted\n");
7416
7417     /* Synchronous messages */
7418
7419     lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7420     ok(lRes == 0, "String should have been converted\n");
7421     lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7422     ok(lRes == 1, "String shouldn't have been converted\n");
7423
7424     /* Asynchronous messages */
7425
7426     SetLastError(0);
7427     lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7428     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7429         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7430     SetLastError(0);
7431     lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7432     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7433         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7434     SetLastError(0);
7435     lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7436     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7437         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7438     SetLastError(0);
7439     lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7440     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7441         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7442     SetLastError(0);
7443     lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7444     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7445         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7446     SetLastError(0);
7447     lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7448     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7449         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7450     SetLastError(0);
7451     lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7452     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7453         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7454     SetLastError(0);
7455     lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7456     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7457         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7458
7459     /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
7460
7461     hwnd = CreateWindowW (testWindowClassW, wszUnicode,
7462                           WS_OVERLAPPEDWINDOW,
7463                           100, 100, 200, 200, 0, 0, 0, NULL);
7464     assert(hwnd);
7465     flush_sequence();
7466     lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
7467     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7468     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7469         "got bad length %ld\n", lRes );
7470
7471     flush_sequence();
7472     lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
7473                             hwnd, WM_GETTEXTLENGTH, 0, 0);
7474     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7475     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7476         "got bad length %ld\n", lRes );
7477
7478     wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
7479     newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
7480     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7481     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7482                                      NULL, 0, NULL, NULL ) ||
7483         broken(lRes == lstrlenW(dummy_window_text) + 37),
7484         "got bad length %ld\n", lRes );
7485
7486     SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc );  /* restore old wnd proc */
7487     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7488     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7489                                      NULL, 0, NULL, NULL ) ||
7490         broken(lRes == lstrlenW(dummy_window_text) + 37),
7491         "got bad length %ld\n", lRes );
7492
7493     ret = DestroyWindow(hwnd);
7494     ok( ret, "DestroyWindow() error %d\n", GetLastError());
7495 }
7496
7497 struct timer_info
7498 {
7499     HWND hWnd;
7500     HANDLE handles[2];
7501     DWORD id;
7502 };
7503
7504 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
7505 {
7506 }
7507
7508 #define TIMER_ID  0x19
7509
7510 static DWORD WINAPI timer_thread_proc(LPVOID x)
7511 {
7512     struct timer_info *info = x;
7513     DWORD r;
7514
7515     r = KillTimer(info->hWnd, 0x19);
7516     ok(r,"KillTimer failed in thread\n");
7517     r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
7518     ok(r,"SetTimer failed in thread\n");
7519     ok(r==TIMER_ID,"SetTimer id different\n");
7520     r = SetEvent(info->handles[0]);
7521     ok(r,"SetEvent failed in thread\n");
7522     return 0;
7523 }
7524
7525 static void test_timers(void)
7526 {
7527     struct timer_info info;
7528     DWORD id;
7529
7530     info.hWnd = CreateWindow ("TestWindowClass", NULL,
7531        WS_OVERLAPPEDWINDOW ,
7532        CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7533        NULL, NULL, 0);
7534
7535     info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
7536     ok(info.id, "SetTimer failed\n");
7537     ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
7538     info.handles[0] = CreateEvent(NULL,0,0,NULL);
7539     info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
7540
7541     WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
7542
7543     WaitForSingleObject(info.handles[1], INFINITE);
7544
7545     CloseHandle(info.handles[0]);
7546     CloseHandle(info.handles[1]);
7547
7548     ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
7549
7550     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
7551 }
7552
7553 static int count = 0;
7554 static VOID CALLBACK callback_count(
7555     HWND hwnd,
7556     UINT uMsg,
7557     UINT_PTR idEvent,
7558     DWORD dwTime
7559 )
7560 {
7561     count++;
7562 }
7563
7564 static void test_timers_no_wnd(void)
7565 {
7566     UINT_PTR id, id2;
7567     MSG msg;
7568
7569     count = 0;
7570     id = SetTimer(NULL, 0, 100, callback_count);
7571     ok(id != 0, "did not get id from SetTimer.\n");
7572     id2 = SetTimer(NULL, id, 200, callback_count);
7573     ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
7574     Sleep(150);
7575     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7576     ok(count == 0, "did not get zero count as expected (%i).\n", count);
7577     Sleep(150);
7578     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7579     ok(count == 1, "did not get one count as expected (%i).\n", count);
7580     KillTimer(NULL, id);
7581     Sleep(250);
7582     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7583     ok(count == 1, "killing replaced timer did not work (%i).\n", count);
7584 }
7585
7586 /* Various win events with arbitrary parameters */
7587 static const struct message WmWinEventsSeq[] = {
7588     { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7589     { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7590     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7591     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7592     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7593     { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7594     { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7595     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7596     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7597     /* our win event hook ignores OBJID_CURSOR events */
7598     /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
7599     { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
7600     { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
7601     { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
7602     { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
7603     { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7604     { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7605     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7606     { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7607     { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7608     { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7609     { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7610     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7611     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7612     { 0 }
7613 };
7614 static const struct message WmWinEventCaretSeq[] = {
7615     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7616     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7617     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
7618     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7619     { 0 }
7620 };
7621 static const struct message WmWinEventCaretSeq_2[] = {
7622     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7623     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7624     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7625     { 0 }
7626 };
7627 static const struct message WmWinEventAlertSeq[] = {
7628     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
7629     { 0 }
7630 };
7631 static const struct message WmWinEventAlertSeq_2[] = {
7632     /* create window in the thread proc */
7633     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
7634     /* our test event */
7635     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
7636     { 0 }
7637 };
7638 static const struct message WmGlobalHookSeq_1[] = {
7639     /* create window in the thread proc */
7640     { HCBT_CREATEWND, hook|lparam, 0, 2 },
7641     /* our test events */
7642     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
7643     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
7644     { 0 }
7645 };
7646 static const struct message WmGlobalHookSeq_2[] = {
7647     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
7648     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
7649     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
7650     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
7651     { 0 }
7652 };
7653
7654 static const struct message WmMouseLLHookSeq[] = {
7655     { WM_MOUSEMOVE, hook },
7656     { WM_LBUTTONUP, hook },
7657     { WM_MOUSEMOVE, hook },
7658     { 0 }
7659 };
7660
7661 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
7662                                          DWORD event,
7663                                          HWND hwnd,
7664                                          LONG object_id,
7665                                          LONG child_id,
7666                                          DWORD thread_id,
7667                                          DWORD event_time)
7668 {
7669     char buf[256];
7670
7671     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7672     {
7673         if (!lstrcmpiA(buf, "TestWindowClass") ||
7674             !lstrcmpiA(buf, "static"))
7675         {
7676             struct recvd_message msg;
7677
7678             msg.hwnd = hwnd;
7679             msg.message = event;
7680             msg.flags = winevent_hook|wparam|lparam;
7681             msg.wParam = object_id;
7682             msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
7683             msg.descr = "WEH_2";
7684             add_message(&msg);
7685         }
7686     }
7687 }
7688
7689 static HHOOK hCBT_global_hook;
7690 static DWORD cbt_global_hook_thread_id;
7691
7692 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7693
7694     HWND hwnd;
7695     char buf[256];
7696
7697     if (nCode == HCBT_SYSCOMMAND)
7698     {
7699         struct recvd_message msg;
7700
7701         msg.hwnd = 0;
7702         msg.message = nCode;
7703         msg.flags = hook|wparam|lparam;
7704         msg.wParam = wParam;
7705         msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7706         msg.descr = "CBT_2";
7707         add_message(&msg);
7708
7709         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7710     }
7711     /* WH_MOUSE_LL hook */
7712     if (nCode == HC_ACTION)
7713     {
7714         MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
7715
7716         /* we can't test for real mouse events */
7717         if (mhll->flags & LLMHF_INJECTED)
7718         {
7719             struct recvd_message msg;
7720
7721             memset (&msg, 0, sizeof (msg));
7722             msg.message = wParam;
7723             msg.flags = hook;
7724             msg.descr = "CBT_2";
7725             add_message(&msg);
7726         }
7727         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7728     }
7729
7730     /* Log also SetFocus(0) calls */
7731     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7732
7733     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7734     {
7735         if (!lstrcmpiA(buf, "TestWindowClass") ||
7736             !lstrcmpiA(buf, "static"))
7737         {
7738             struct recvd_message msg;
7739
7740             msg.hwnd = hwnd;
7741             msg.message = nCode;
7742             msg.flags = hook|wparam|lparam;
7743             msg.wParam = wParam;
7744             msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7745             msg.descr = "CBT_2";
7746             add_message(&msg);
7747         }
7748     }
7749     return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7750 }
7751
7752 static DWORD WINAPI win_event_global_thread_proc(void *param)
7753 {
7754     HWND hwnd;
7755     MSG msg;
7756     HANDLE hevent = *(HANDLE *)param;
7757
7758     assert(pNotifyWinEvent);
7759
7760     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7761     assert(hwnd);
7762     trace("created thread window %p\n", hwnd);
7763
7764     *(HWND *)param = hwnd;
7765
7766     flush_sequence();
7767     /* this event should be received only by our new hook proc,
7768      * an old one does not expect an event from another thread.
7769      */
7770     pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
7771     SetEvent(hevent);
7772
7773     while (GetMessage(&msg, 0, 0, 0))
7774     {
7775         TranslateMessage(&msg);
7776         DispatchMessage(&msg);
7777     }
7778     return 0;
7779 }
7780
7781 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
7782 {
7783     HWND hwnd;
7784     MSG msg;
7785     HANDLE hevent = *(HANDLE *)param;
7786
7787     flush_sequence();
7788     /* these events should be received only by our new hook proc,
7789      * an old one does not expect an event from another thread.
7790      */
7791
7792     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7793     assert(hwnd);
7794     trace("created thread window %p\n", hwnd);
7795
7796     *(HWND *)param = hwnd;
7797
7798     /* Windows doesn't like when a thread plays games with the focus,
7799        that leads to all kinds of misbehaviours and failures to activate
7800        a window. So, better keep next lines commented out.
7801     SetFocus(0);
7802     SetFocus(hwnd);*/
7803
7804     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7805     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7806
7807     SetEvent(hevent);
7808
7809     while (GetMessage(&msg, 0, 0, 0))
7810     {
7811         TranslateMessage(&msg);
7812         DispatchMessage(&msg);
7813     }
7814     return 0;
7815 }
7816
7817 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
7818 {
7819     HWND hwnd;
7820     MSG msg;
7821     HANDLE hevent = *(HANDLE *)param;
7822
7823     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7824     assert(hwnd);
7825     trace("created thread window %p\n", hwnd);
7826
7827     *(HWND *)param = hwnd;
7828
7829     flush_sequence();
7830
7831     /* Windows doesn't like when a thread plays games with the focus,
7832      * that leads to all kinds of misbehaviours and failures to activate
7833      * a window. So, better don't generate a mouse click message below.
7834      */
7835     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7836     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7837     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7838
7839     SetEvent(hevent);
7840     while (GetMessage(&msg, 0, 0, 0))
7841     {
7842         TranslateMessage(&msg);
7843         DispatchMessage(&msg);
7844     }
7845     return 0;
7846 }
7847
7848 static void test_winevents(void)
7849 {
7850     BOOL ret;
7851     MSG msg;
7852     HWND hwnd, hwnd2;
7853     UINT i;
7854     HANDLE hthread, hevent;
7855     DWORD tid;
7856     HWINEVENTHOOK hhook;
7857     const struct message *events = WmWinEventsSeq;
7858
7859     hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
7860                            WS_OVERLAPPEDWINDOW,
7861                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7862                            NULL, NULL, 0);
7863     assert(hwnd);
7864
7865     /****** start of global hook test *************/
7866     hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7867     if (!hCBT_global_hook)
7868     {
7869         ok(DestroyWindow(hwnd), "failed to destroy window\n");
7870         skip( "cannot set global hook\n" );
7871         return;
7872     }
7873
7874     hevent = CreateEventA(NULL, 0, 0, NULL);
7875     assert(hevent);
7876     hwnd2 = (HWND)hevent;
7877
7878     hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
7879     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7880
7881     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7882
7883     ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
7884
7885     flush_sequence();
7886     /* this one should be received only by old hook proc */
7887     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7888     /* this one should be received only by old hook proc */
7889     DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7890
7891     ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
7892
7893     ret = UnhookWindowsHookEx(hCBT_global_hook);
7894     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7895
7896     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7897     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7898     CloseHandle(hthread);
7899     CloseHandle(hevent);
7900     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7901     /****** end of global hook test *************/
7902
7903     if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
7904     {
7905         ok(DestroyWindow(hwnd), "failed to destroy window\n");
7906         return;
7907     }
7908
7909     flush_sequence();
7910
7911     if (0)
7912     {
7913     /* this test doesn't pass under Win9x */
7914     /* win2k ignores events with hwnd == 0 */
7915     SetLastError(0xdeadbeef);
7916     pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
7917     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
7918        GetLastError() == 0xdeadbeef, /* Win9x */
7919        "unexpected error %d\n", GetLastError());
7920     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7921     }
7922
7923     for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
7924         pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
7925
7926     ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
7927
7928     /****** start of event filtering test *************/
7929     hhook = (HWINEVENTHOOK)pSetWinEventHook(
7930         EVENT_OBJECT_SHOW, /* 0x8002 */
7931         EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
7932         GetModuleHandleA(0), win_event_global_hook_proc,
7933         GetCurrentProcessId(), 0,
7934         WINEVENT_INCONTEXT);
7935     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7936
7937     hevent = CreateEventA(NULL, 0, 0, NULL);
7938     assert(hevent);
7939     hwnd2 = (HWND)hevent;
7940
7941     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7942     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7943
7944     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7945
7946     ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
7947
7948     flush_sequence();
7949     /* this one should be received only by old hook proc */
7950     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7951     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7952     /* this one should be received only by old hook proc */
7953     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7954
7955     ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
7956
7957     ret = pUnhookWinEvent(hhook);
7958     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7959
7960     PostThreadMessageA(tid, WM_QUIT, 0, 0);
7961     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7962     CloseHandle(hthread);
7963     CloseHandle(hevent);
7964     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7965     /****** end of event filtering test *************/
7966
7967     /****** start of out of context event test *************/
7968     hhook = (HWINEVENTHOOK)pSetWinEventHook(
7969         EVENT_MIN, EVENT_MAX,
7970         0, win_event_global_hook_proc,
7971         GetCurrentProcessId(), 0,
7972         WINEVENT_OUTOFCONTEXT);
7973     ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7974
7975     hevent = CreateEventA(NULL, 0, 0, NULL);
7976     assert(hevent);
7977     hwnd2 = (HWND)hevent;
7978
7979     flush_sequence();
7980
7981     hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7982     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7983
7984     ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7985
7986     ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7987     /* process pending winevent messages */
7988     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7989     ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
7990
7991     flush_sequence();
7992     /* this one should be received only by old hook proc */
7993     pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7994     pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7995     /* this one should be received only by old hook proc */
7996     pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7997
7998     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
7999     /* process pending winevent messages */
8000     ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8001     ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
8002
8003     ret = pUnhookWinEvent(hhook);
8004     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8005
8006     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8007     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8008     CloseHandle(hthread);
8009     CloseHandle(hevent);
8010     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8011     /****** end of out of context event test *************/
8012
8013     /****** start of MOUSE_LL hook test *************/
8014     hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8015     /* WH_MOUSE_LL is not supported on Win9x platforms */
8016     if (!hCBT_global_hook)
8017     {
8018         trace("Skipping WH_MOUSE_LL test on this platform\n");
8019         goto skip_mouse_ll_hook_test;
8020     }
8021
8022     hevent = CreateEventA(NULL, 0, 0, NULL);
8023     assert(hevent);
8024     hwnd2 = (HWND)hevent;
8025
8026     hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
8027     ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8028
8029     while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
8030         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
8031
8032     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
8033     flush_sequence();
8034
8035     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8036     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8037     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8038
8039     ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
8040
8041     ret = UnhookWindowsHookEx(hCBT_global_hook);
8042     ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8043
8044     PostThreadMessageA(tid, WM_QUIT, 0, 0);
8045     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8046     CloseHandle(hthread);
8047     CloseHandle(hevent);
8048     ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8049     /****** end of MOUSE_LL hook test *************/
8050 skip_mouse_ll_hook_test:
8051
8052     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8053 }
8054
8055 static void test_set_hook(void)
8056 {
8057     BOOL ret;
8058     HHOOK hhook;
8059     HWINEVENTHOOK hwinevent_hook;
8060
8061     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
8062     ok(hhook != 0, "local hook does not require hModule set to 0\n");
8063     UnhookWindowsHookEx(hhook);
8064
8065     if (0)
8066     {
8067     /* this test doesn't pass under Win9x: BUG! */
8068     SetLastError(0xdeadbeef);
8069     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
8070     ok(!hhook, "global hook requires hModule != 0\n");
8071     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
8072     }
8073
8074     SetLastError(0xdeadbeef);
8075     hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
8076     ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
8077     ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
8078        GetLastError() == 0xdeadbeef, /* Win9x */
8079        "unexpected error %d\n", GetLastError());
8080
8081     SetLastError(0xdeadbeef);
8082     ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
8083     ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
8084        GetLastError() == 0xdeadbeef, /* Win9x */
8085        "unexpected error %d\n", GetLastError());
8086
8087     if (!pSetWinEventHook || !pUnhookWinEvent) return;
8088
8089     /* even process local incontext hooks require hmodule */
8090     SetLastError(0xdeadbeef);
8091     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
8092         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
8093     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8094     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8095        GetLastError() == 0xdeadbeef, /* Win9x */
8096        "unexpected error %d\n", GetLastError());
8097
8098     /* even thread local incontext hooks require hmodule */
8099     SetLastError(0xdeadbeef);
8100     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
8101         0, win_event_proc, GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
8102     ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8103     ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8104        GetLastError() == 0xdeadbeef, /* Win9x */
8105        "unexpected error %d\n", GetLastError());
8106
8107     if (0)
8108     {
8109     /* these 3 tests don't pass under Win9x */
8110     SetLastError(0xdeadbeef);
8111     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(1, 0,
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(-1, 1,
8118         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8119     ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8120     ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8121
8122     SetLastError(0xdeadbeef);
8123     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
8124         0, win_event_proc, 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
8125     ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
8126     ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
8127     }
8128
8129     SetLastError(0xdeadbeef);
8130     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(0, 0,
8131         0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8132     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8133     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8134     ret = pUnhookWinEvent(hwinevent_hook);
8135     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8136
8137 todo_wine {
8138     /* This call succeeds under win2k SP4, but fails under Wine.
8139        Does win2k test/use passed process id? */
8140     SetLastError(0xdeadbeef);
8141     hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
8142         0, win_event_proc, 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
8143     ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8144     ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8145     ret = pUnhookWinEvent(hwinevent_hook);
8146     ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8147 }
8148
8149     SetLastError(0xdeadbeef);
8150     ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
8151     ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
8152         GetLastError() == 0xdeadbeef, /* Win9x */
8153         "unexpected error %d\n", GetLastError());
8154 }
8155
8156 static const struct message ScrollWindowPaint1[] = {
8157     { WM_PAINT, sent },
8158     { WM_ERASEBKGND, sent|beginpaint },
8159     { 0 }
8160 };
8161
8162 static const struct message ScrollWindowPaint2[] = {
8163     { WM_PAINT, sent },
8164     { 0 }
8165 };
8166
8167 static void test_scrollwindowex(void)
8168 {
8169     HWND hwnd, hchild;
8170     RECT rect={0,0,130,130};
8171
8172     hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
8173             WS_VISIBLE|WS_OVERLAPPEDWINDOW,
8174             100, 100, 200, 200, 0, 0, 0, NULL);
8175     ok (hwnd != 0, "Failed to create overlapped window\n");
8176     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", 
8177             WS_VISIBLE|WS_CAPTION|WS_CHILD,
8178             10, 10, 150, 150, hwnd, 0, 0, NULL);
8179     ok (hchild != 0, "Failed to create child\n");
8180     UpdateWindow(hwnd);
8181     flush_events();
8182     flush_sequence();
8183
8184     /* scroll without the child window */
8185     trace("start scroll\n");
8186     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8187             SW_ERASE|SW_INVALIDATE);
8188     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8189     trace("end scroll\n");
8190     flush_sequence();
8191     flush_events();
8192     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8193     flush_events();
8194     flush_sequence();
8195
8196     /* Now without the SW_ERASE flag */
8197     trace("start scroll\n");
8198     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
8199     ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8200     trace("end scroll\n");
8201     flush_sequence();
8202     flush_events();
8203     ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
8204     flush_events();
8205     flush_sequence();
8206
8207     /* now scroll the child window as well */
8208     trace("start scroll\n");
8209     ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8210             SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
8211     /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
8212     /* windows sometimes a WM_MOVE */
8213     ok_sequence(WmEmptySeq, "ScrollWindowEx", TRUE);
8214     trace("end scroll\n");
8215     flush_sequence();
8216     flush_events();
8217     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8218     flush_events();
8219     flush_sequence();
8220
8221     /* now scroll with ScrollWindow() */
8222     trace("start scroll with ScrollWindow\n");
8223     ScrollWindow( hwnd, 5, 5, NULL, NULL);
8224     trace("end scroll\n");
8225     flush_sequence();
8226     flush_events();
8227     ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
8228
8229     ok(DestroyWindow(hchild), "failed to destroy window\n");
8230     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8231     flush_sequence();
8232 }
8233
8234 static const struct message destroy_window_with_children[] = {
8235     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8236     { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
8237     { 0x0090, sent|optional },
8238     { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
8239     { 0x0090, sent|optional },
8240     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8241     { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8242     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8243     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8244     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
8245     { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8246     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8247     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8248     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8249     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8250     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8251     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8252     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8253     { 0 }
8254 };
8255
8256 static void test_DestroyWindow(void)
8257 {
8258     BOOL ret;
8259     HWND parent, child1, child2, child3, child4, test;
8260     UINT_PTR child_id = WND_CHILD_ID + 1;
8261
8262     parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8263                              100, 100, 200, 200, 0, 0, 0, NULL);
8264     assert(parent != 0);
8265     child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8266                              0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
8267     assert(child1 != 0);
8268     child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8269                              0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
8270     assert(child2 != 0);
8271     child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8272                              0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
8273     assert(child3 != 0);
8274     child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
8275                              0, 0, 50, 50, parent, 0, 0, NULL);
8276     assert(child4 != 0);
8277
8278     /* test owner/parent of child2 */
8279     test = GetParent(child2);
8280     ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8281     ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8282     if(pGetAncestor) {
8283         test = pGetAncestor(child2, GA_PARENT);
8284         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8285     }
8286     test = GetWindow(child2, GW_OWNER);
8287     ok(!test, "wrong owner %p\n", test);
8288
8289     test = SetParent(child2, parent);
8290     ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
8291
8292     /* test owner/parent of the parent */
8293     test = GetParent(parent);
8294     ok(!test, "wrong parent %p\n", test);
8295     ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
8296     if(pGetAncestor) {
8297         test = pGetAncestor(parent, GA_PARENT);
8298         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8299     }
8300     test = GetWindow(parent, GW_OWNER);
8301     ok(!test, "wrong owner %p\n", test);
8302
8303     /* test owner/parent of child1 */
8304     test = GetParent(child1);
8305     ok(test == parent, "wrong parent %p\n", test);
8306     ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
8307     if(pGetAncestor) {
8308         test = pGetAncestor(child1, GA_PARENT);
8309         ok(test == parent, "wrong parent %p\n", test);
8310     }
8311     test = GetWindow(child1, GW_OWNER);
8312     ok(!test, "wrong owner %p\n", test);
8313
8314     /* test owner/parent of child2 */
8315     test = GetParent(child2);
8316     ok(test == parent, "wrong parent %p\n", test);
8317     ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8318     if(pGetAncestor) {
8319         test = pGetAncestor(child2, GA_PARENT);
8320         ok(test == parent, "wrong parent %p\n", test);
8321     }
8322     test = GetWindow(child2, GW_OWNER);
8323     ok(!test, "wrong owner %p\n", test);
8324
8325     /* test owner/parent of child3 */
8326     test = GetParent(child3);
8327     ok(test == child1, "wrong parent %p\n", test);
8328     ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
8329     if(pGetAncestor) {
8330         test = pGetAncestor(child3, GA_PARENT);
8331         ok(test == child1, "wrong parent %p\n", test);
8332     }
8333     test = GetWindow(child3, GW_OWNER);
8334     ok(!test, "wrong owner %p\n", test);
8335
8336     /* test owner/parent of child4 */
8337     test = GetParent(child4);
8338     ok(test == parent, "wrong parent %p\n", test);
8339     ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
8340     if(pGetAncestor) {
8341         test = pGetAncestor(child4, GA_PARENT);
8342         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8343     }
8344     test = GetWindow(child4, GW_OWNER);
8345     ok(test == parent, "wrong owner %p\n", test);
8346
8347     flush_sequence();
8348
8349     trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
8350            parent, child1, child2, child3, child4);
8351
8352     SetCapture(child4);
8353     test = GetCapture();
8354     ok(test == child4, "wrong capture window %p\n", test);
8355
8356     test_DestroyWindow_flag = TRUE;
8357     ret = DestroyWindow(parent);
8358     ok( ret, "DestroyWindow() error %d\n", GetLastError());
8359     test_DestroyWindow_flag = FALSE;
8360     ok_sequence(destroy_window_with_children, "destroy window with children", 0);
8361
8362     ok(!IsWindow(parent), "parent still exists\n");
8363     ok(!IsWindow(child1), "child1 still exists\n");
8364     ok(!IsWindow(child2), "child2 still exists\n");
8365     ok(!IsWindow(child3), "child3 still exists\n");
8366     ok(!IsWindow(child4), "child4 still exists\n");
8367
8368     test = GetCapture();
8369     ok(!test, "wrong capture window %p\n", test);
8370 }
8371
8372
8373 static const struct message WmDispatchPaint[] = {
8374     { WM_NCPAINT, sent },
8375     { WM_GETTEXT, sent|defwinproc|optional },
8376     { WM_GETTEXT, sent|defwinproc|optional },
8377     { WM_ERASEBKGND, sent },
8378     { 0 }
8379 };
8380
8381 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8382 {
8383     if (message == WM_PAINT) return 0;
8384     return MsgCheckProcA( hwnd, message, wParam, lParam );
8385 }
8386
8387 static void test_DispatchMessage(void)
8388 {
8389     RECT rect;
8390     MSG msg;
8391     int count;
8392     HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8393                                100, 100, 200, 200, 0, 0, 0, NULL);
8394     ShowWindow( hwnd, SW_SHOW );
8395     UpdateWindow( hwnd );
8396     flush_events();
8397     flush_sequence();
8398     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
8399
8400     SetRect( &rect, -5, -5, 5, 5 );
8401     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8402     count = 0;
8403     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8404     {
8405         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8406         else
8407         {
8408             flush_sequence();
8409             DispatchMessage( &msg );
8410             /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
8411             if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8412             else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
8413             if (++count > 10) break;
8414         }
8415     }
8416     ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
8417
8418     trace("now without DispatchMessage\n");
8419     flush_sequence();
8420     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8421     count = 0;
8422     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8423     {
8424         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8425         else
8426         {
8427             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
8428             flush_sequence();
8429             /* this will send WM_NCCPAINT just like DispatchMessage does */
8430             GetUpdateRgn( hwnd, hrgn, TRUE );
8431             ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8432             DeleteObject( hrgn );
8433             GetClientRect( hwnd, &rect );
8434             ValidateRect( hwnd, &rect );  /* this will stop WM_PAINTs */
8435             ok( !count, "Got multiple WM_PAINTs\n" );
8436             if (++count > 10) break;
8437         }
8438     }
8439     DestroyWindow(hwnd);
8440 }
8441
8442
8443 static const struct message WmUser[] = {
8444     { WM_USER, sent },
8445     { 0 }
8446 };
8447
8448 struct sendmsg_info
8449 {
8450     HWND  hwnd;
8451     DWORD timeout;
8452     DWORD ret;
8453 };
8454
8455 static DWORD CALLBACK send_msg_thread( LPVOID arg )
8456 {
8457     struct sendmsg_info *info = arg;
8458     SetLastError( 0xdeadbeef );
8459     info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
8460     if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT ||
8461                         broken(GetLastError() == 0),  /* win9x */
8462                         "unexpected error %d\n", GetLastError());
8463     return 0;
8464 }
8465
8466 static void wait_for_thread( HANDLE thread )
8467 {
8468     while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
8469     {
8470         MSG msg;
8471         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
8472     }
8473 }
8474
8475 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8476 {
8477     if (message == WM_USER) Sleep(200);
8478     return MsgCheckProcA( hwnd, message, wParam, lParam );
8479 }
8480
8481 static void test_SendMessageTimeout(void)
8482 {
8483     HANDLE thread;
8484     struct sendmsg_info info;
8485     DWORD tid;
8486     BOOL is_win9x;
8487
8488     info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8489                                100, 100, 200, 200, 0, 0, 0, NULL);
8490     flush_events();
8491     flush_sequence();
8492
8493     info.timeout = 1000;
8494     info.ret = 0xdeadbeef;
8495     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8496     wait_for_thread( thread );
8497     CloseHandle( thread );
8498     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8499     ok_sequence( WmUser, "WmUser", FALSE );
8500
8501     info.timeout = 1;
8502     info.ret = 0xdeadbeef;
8503     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8504     Sleep(100);  /* SendMessageTimeout should time out here */
8505     wait_for_thread( thread );
8506     CloseHandle( thread );
8507     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8508     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8509
8510     /* 0 means infinite timeout (but not on win9x) */
8511     info.timeout = 0;
8512     info.ret = 0xdeadbeef;
8513     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8514     Sleep(100);
8515     wait_for_thread( thread );
8516     CloseHandle( thread );
8517     is_win9x = !info.ret;
8518     if (is_win9x) ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8519     else ok_sequence( WmUser, "WmUser", FALSE );
8520
8521     /* timeout is treated as signed despite the prototype (but not on win9x) */
8522     info.timeout = 0x7fffffff;
8523     info.ret = 0xdeadbeef;
8524     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8525     Sleep(100);
8526     wait_for_thread( thread );
8527     CloseHandle( thread );
8528     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8529     ok_sequence( WmUser, "WmUser", FALSE );
8530
8531     info.timeout = 0x80000000;
8532     info.ret = 0xdeadbeef;
8533     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8534     Sleep(100);
8535     wait_for_thread( thread );
8536     CloseHandle( thread );
8537     if (is_win9x)
8538     {
8539         ok( info.ret == 1, "SendMessageTimeout failed\n" );
8540         ok_sequence( WmUser, "WmUser", FALSE );
8541     }
8542     else
8543     {
8544         ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8545         ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8546     }
8547
8548     /* now check for timeout during message processing */
8549     SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
8550     info.timeout = 100;
8551     info.ret = 0xdeadbeef;
8552     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8553     wait_for_thread( thread );
8554     CloseHandle( thread );
8555     /* we should time out but still get the message */
8556     ok( info.ret == 0, "SendMessageTimeout failed\n" );
8557     ok_sequence( WmUser, "WmUser", FALSE );
8558
8559     DestroyWindow( info.hwnd );
8560 }
8561
8562
8563 /****************** edit message test *************************/
8564 #define ID_EDIT 0x1234
8565 static const struct message sl_edit_setfocus[] =
8566 {
8567     { HCBT_SETFOCUS, hook },
8568     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8569     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8570     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8571     { WM_SETFOCUS, sent|wparam, 0 },
8572     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8573     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
8574     { WM_CTLCOLOREDIT, sent|parent },
8575     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8576     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8577     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8578     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8579     { 0 }
8580 };
8581 static const struct message ml_edit_setfocus[] =
8582 {
8583     { HCBT_SETFOCUS, hook },
8584     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8585     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8586     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8587     { WM_SETFOCUS, sent|wparam, 0 },
8588     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8589     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8590     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8591     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8592     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8593     { 0 }
8594 };
8595 static const struct message sl_edit_killfocus[] =
8596 {
8597     { HCBT_SETFOCUS, hook },
8598     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8599     { WM_KILLFOCUS, sent|wparam, 0 },
8600     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8601     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8602     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
8603     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
8604     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
8605     { 0 }
8606 };
8607 static const struct message sl_edit_lbutton_dblclk[] =
8608 {
8609     { WM_LBUTTONDBLCLK, sent },
8610     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8611     { 0 }
8612 };
8613 static const struct message sl_edit_lbutton_down[] =
8614 {
8615     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8616     { HCBT_SETFOCUS, hook },
8617     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8618     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8619     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8620     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8621     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8622     { WM_CTLCOLOREDIT, sent|parent },
8623     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8624     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8625     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8626     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8627     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8628     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8629     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8630     { WM_CTLCOLOREDIT, sent|parent|optional },
8631     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8632     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8633     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8634     { 0 }
8635 };
8636 static const struct message ml_edit_lbutton_down[] =
8637 {
8638     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8639     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8640     { HCBT_SETFOCUS, hook },
8641     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8642     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8643     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8644     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8645     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8646     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8647     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8648     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8649     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8650     { 0 }
8651 };
8652 static const struct message sl_edit_lbutton_up[] =
8653 {
8654     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8655     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8656     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8657     { WM_CAPTURECHANGED, sent|defwinproc },
8658     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8659     { 0 }
8660 };
8661 static const struct message ml_edit_lbutton_up[] =
8662 {
8663     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8664     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8665     { WM_CAPTURECHANGED, sent|defwinproc },
8666     { 0 }
8667 };
8668
8669 static WNDPROC old_edit_proc;
8670
8671 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8672 {
8673     static long defwndproc_counter = 0;
8674     LRESULT ret;
8675     struct recvd_message msg;
8676
8677     if (message == WM_GETICON || message == WM_GETOBJECT) return 0;  /* ignore them */
8678
8679     msg.hwnd = hwnd;
8680     msg.message = message;
8681     msg.flags = sent|wparam|lparam;
8682     if (defwndproc_counter) msg.flags |= defwinproc;
8683     msg.wParam = wParam;
8684     msg.lParam = lParam;
8685     msg.descr = "edit";
8686     add_message(&msg);
8687
8688     defwndproc_counter++;
8689     ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
8690     defwndproc_counter--;
8691
8692     return ret;
8693 }
8694
8695 static void subclass_edit(void)
8696 {
8697     WNDCLASSA cls;
8698
8699     if (!GetClassInfoA(0, "edit", &cls)) assert(0);
8700
8701     old_edit_proc = cls.lpfnWndProc;
8702
8703     cls.hInstance = GetModuleHandle(0);
8704     cls.lpfnWndProc = edit_hook_proc;
8705     cls.lpszClassName = "my_edit_class";
8706     UnregisterClass(cls.lpszClassName, cls.hInstance);
8707     if (!RegisterClassA(&cls)) assert(0);
8708 }
8709
8710 static void test_edit_messages(void)
8711 {
8712     HWND hwnd, parent;
8713     DWORD dlg_code;
8714
8715     subclass_edit();
8716     log_all_parent_messages++;
8717
8718     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8719                              100, 100, 200, 200, 0, 0, 0, NULL);
8720     ok (parent != 0, "Failed to create parent window\n");
8721
8722     /* test single line edit */
8723     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
8724                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8725     ok(hwnd != 0, "Failed to create edit window\n");
8726
8727     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8728     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
8729
8730     ShowWindow(hwnd, SW_SHOW);
8731     UpdateWindow(hwnd);
8732     SetFocus(0);
8733     flush_sequence();
8734
8735     SetFocus(hwnd);
8736     ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
8737
8738     SetFocus(0);
8739     ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
8740
8741     SetFocus(0);
8742     ReleaseCapture();
8743     flush_sequence();
8744
8745     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8746     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
8747
8748     SetFocus(0);
8749     ReleaseCapture();
8750     flush_sequence();
8751
8752     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8753     ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
8754
8755     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8756     ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
8757
8758     DestroyWindow(hwnd);
8759
8760     /* test multiline edit */
8761     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
8762                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8763     ok(hwnd != 0, "Failed to create edit window\n");
8764
8765     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8766     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
8767        "wrong dlg_code %08x\n", dlg_code);
8768
8769     ShowWindow(hwnd, SW_SHOW);
8770     UpdateWindow(hwnd);
8771     SetFocus(0);
8772     flush_sequence();
8773
8774     SetFocus(hwnd);
8775     ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
8776
8777     SetFocus(0);
8778     ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
8779
8780     SetFocus(0);
8781     ReleaseCapture();
8782     flush_sequence();
8783
8784     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8785     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
8786
8787     SetFocus(0);
8788     ReleaseCapture();
8789     flush_sequence();
8790
8791     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8792     ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
8793
8794     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8795     ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
8796
8797     DestroyWindow(hwnd);
8798     DestroyWindow(parent);
8799
8800     log_all_parent_messages--;
8801 }
8802
8803 /**************************** End of Edit test ******************************/
8804
8805 static const struct message WmKeyDownSkippedSeq[] =
8806 {
8807     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
8808     { 0 }
8809 };
8810 static const struct message WmKeyDownWasDownSkippedSeq[] =
8811 {
8812     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x40000001 }, /* XP */
8813     { 0 }
8814 };
8815 static const struct message WmKeyUpSkippedSeq[] =
8816 {
8817     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8818     { 0 }
8819 };
8820 static const struct message WmUserKeyUpSkippedSeq[] =
8821 {
8822     { WM_USER, sent },
8823     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8824     { 0 }
8825 };
8826
8827 #define EV_STOP 0
8828 #define EV_SENDMSG 1
8829 #define EV_ACK 2
8830
8831 struct peekmsg_info
8832 {
8833     HWND  hwnd;
8834     HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
8835 };
8836
8837 static DWORD CALLBACK send_msg_thread_2(void *param)
8838 {
8839     DWORD ret;
8840     struct peekmsg_info *info = param;
8841
8842     trace("thread: looping\n");
8843     SetEvent(info->hevent[EV_ACK]);
8844
8845     while (1)
8846     {
8847         ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
8848
8849         switch (ret)
8850         {
8851         case WAIT_OBJECT_0 + EV_STOP:
8852             trace("thread: exiting\n");
8853             return 0;
8854
8855         case WAIT_OBJECT_0 + EV_SENDMSG:
8856             trace("thread: sending message\n");
8857             ok( SendNotifyMessageA(info->hwnd, WM_USER, 0, 0),
8858                 "SendNotifyMessageA failed error %u\n", GetLastError());
8859             SetEvent(info->hevent[EV_ACK]);
8860             break;
8861
8862         default:
8863             trace("unexpected return: %04x\n", ret);
8864             assert(0);
8865             break;
8866         }
8867     }
8868     return 0;
8869 }
8870
8871 static void test_PeekMessage(void)
8872 {
8873     MSG msg;
8874     HANDLE hthread;
8875     DWORD tid, qstatus;
8876     UINT qs_all_input = QS_ALLINPUT;
8877     UINT qs_input = QS_INPUT;
8878     BOOL ret;
8879     struct peekmsg_info info;
8880
8881     info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8882                               100, 100, 200, 200, 0, 0, 0, NULL);
8883     assert(info.hwnd);
8884     ShowWindow(info.hwnd, SW_SHOW);
8885     UpdateWindow(info.hwnd);
8886     SetFocus(info.hwnd);
8887
8888     info.hevent[EV_STOP] = CreateEventA(NULL, 0, 0, NULL);
8889     info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
8890     info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
8891
8892     hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
8893     WaitForSingleObject(info.hevent[EV_ACK], 10000);
8894
8895     flush_events();
8896     flush_sequence();
8897
8898     SetLastError(0xdeadbeef);
8899     qstatus = GetQueueStatus(qs_all_input);
8900     if (GetLastError() == ERROR_INVALID_FLAGS)
8901     {
8902         trace("QS_RAWINPUT not supported on this platform\n");
8903         qs_all_input &= ~QS_RAWINPUT;
8904         qs_input &= ~QS_RAWINPUT;
8905     }
8906     if (qstatus & QS_POSTMESSAGE)
8907     {
8908         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) /* nothing */ ;
8909         qstatus = GetQueueStatus(qs_all_input);
8910     }
8911     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8912
8913     trace("signalling to send message\n");
8914     SetEvent(info.hevent[EV_SENDMSG]);
8915     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8916
8917     /* pass invalid QS_xxxx flags */
8918     SetLastError(0xdeadbeef);
8919     qstatus = GetQueueStatus(0xffffffff);
8920     ok(qstatus == 0 || broken(qstatus)  /* win9x */, "GetQueueStatus should fail: %08x\n", qstatus);
8921     if (!qstatus)
8922     {
8923         ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
8924         qstatus = GetQueueStatus(qs_all_input);
8925     }
8926     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
8927        "wrong qstatus %08x\n", qstatus);
8928
8929     msg.message = 0;
8930     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8931     ok(!ret,
8932        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8933         msg.message);
8934     ok_sequence(WmUser, "WmUser", FALSE);
8935
8936     qstatus = GetQueueStatus(qs_all_input);
8937     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8938
8939     keybd_event('N', 0, 0, 0);
8940     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
8941     qstatus = GetQueueStatus(qs_all_input);
8942     ok(qstatus == MAKELONG(QS_KEY, QS_KEY),
8943        "wrong qstatus %08x\n", qstatus);
8944
8945     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8946     qstatus = GetQueueStatus(qs_all_input);
8947     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8948        "wrong qstatus %08x\n", qstatus);
8949
8950     InvalidateRect(info.hwnd, NULL, FALSE);
8951     qstatus = GetQueueStatus(qs_all_input);
8952     ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8953        "wrong qstatus %08x\n", qstatus);
8954
8955     trace("signalling to send message\n");
8956     SetEvent(info.hevent[EV_SENDMSG]);
8957     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8958
8959     qstatus = GetQueueStatus(qs_all_input);
8960     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8961        "wrong qstatus %08x\n", qstatus);
8962
8963     msg.message = 0;
8964     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
8965     if (ret && msg.message == WM_CHAR)
8966     {
8967         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
8968         goto done;
8969     }
8970     ok(!ret,
8971        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8972         msg.message);
8973     if (!sequence_cnt)  /* nt4 doesn't fetch anything with PM_QS_* flags */
8974     {
8975         win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
8976         goto done;
8977     }
8978     ok_sequence(WmUser, "WmUser", FALSE);
8979
8980     qstatus = GetQueueStatus(qs_all_input);
8981     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8982        "wrong qstatus %08x\n", qstatus);
8983
8984     trace("signalling to send message\n");
8985     SetEvent(info.hevent[EV_SENDMSG]);
8986     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8987
8988     qstatus = GetQueueStatus(qs_all_input);
8989     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8990        "wrong qstatus %08x\n", qstatus);
8991
8992     msg.message = 0;
8993     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE );
8994     ok(!ret,
8995        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8996         msg.message);
8997     ok_sequence(WmUser, "WmUser", FALSE);
8998
8999     qstatus = GetQueueStatus(qs_all_input);
9000     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9001        "wrong qstatus %08x\n", qstatus);
9002
9003     msg.message = 0;
9004     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9005     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9006        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9007        ret, msg.message, msg.wParam);
9008     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9009
9010     qstatus = GetQueueStatus(qs_all_input);
9011     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9012        "wrong qstatus %08x\n", qstatus);
9013
9014     msg.message = 0;
9015     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9016     ok(!ret,
9017        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9018         msg.message);
9019     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9020
9021     qstatus = GetQueueStatus(qs_all_input);
9022     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9023        "wrong qstatus %08x\n", qstatus);
9024
9025     msg.message = 0;
9026     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9027     ok(ret && msg.message == WM_PAINT,
9028        "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
9029     DispatchMessageA(&msg);
9030     ok_sequence(WmPaint, "WmPaint", FALSE);
9031
9032     qstatus = GetQueueStatus(qs_all_input);
9033     ok(qstatus == MAKELONG(0, QS_KEY),
9034        "wrong qstatus %08x\n", qstatus);
9035
9036     msg.message = 0;
9037     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9038     ok(!ret,
9039        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9040         msg.message);
9041     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9042
9043     qstatus = GetQueueStatus(qs_all_input);
9044     ok(qstatus == MAKELONG(0, QS_KEY),
9045        "wrong qstatus %08x\n", qstatus);
9046
9047     trace("signalling to send message\n");
9048     SetEvent(info.hevent[EV_SENDMSG]);
9049     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9050
9051     qstatus = GetQueueStatus(qs_all_input);
9052     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
9053        "wrong qstatus %08x\n", qstatus);
9054
9055     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9056
9057     qstatus = GetQueueStatus(qs_all_input);
9058     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9059        "wrong qstatus %08x\n", qstatus);
9060
9061     msg.message = 0;
9062     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9063     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9064        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9065        ret, msg.message, msg.wParam);
9066     ok_sequence(WmUser, "WmUser", FALSE);
9067
9068     qstatus = GetQueueStatus(qs_all_input);
9069     ok(qstatus == MAKELONG(0, QS_KEY),
9070        "wrong qstatus %08x\n", qstatus);
9071
9072     msg.message = 0;
9073     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9074     ok(!ret,
9075        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9076         msg.message);
9077     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9078
9079     qstatus = GetQueueStatus(qs_all_input);
9080     ok(qstatus == MAKELONG(0, QS_KEY),
9081        "wrong qstatus %08x\n", qstatus);
9082
9083     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9084
9085     qstatus = GetQueueStatus(qs_all_input);
9086     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9087        "wrong qstatus %08x\n", qstatus);
9088
9089     trace("signalling to send message\n");
9090     SetEvent(info.hevent[EV_SENDMSG]);
9091     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9092
9093     qstatus = GetQueueStatus(qs_all_input);
9094     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9095        "wrong qstatus %08x\n", qstatus);
9096
9097     msg.message = 0;
9098     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
9099     ok(!ret,
9100        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9101         msg.message);
9102     ok_sequence(WmUser, "WmUser", FALSE);
9103
9104     qstatus = GetQueueStatus(qs_all_input);
9105     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9106        "wrong qstatus %08x\n", qstatus);
9107
9108     msg.message = 0;
9109     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9110         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9111     else /* workaround for a missing QS_RAWINPUT support */
9112         ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
9113     ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9114        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9115        ret, msg.message, msg.wParam);
9116     ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9117
9118     qstatus = GetQueueStatus(qs_all_input);
9119     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9120        "wrong qstatus %08x\n", qstatus);
9121
9122     msg.message = 0;
9123     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9124         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9125     else /* workaround for a missing QS_RAWINPUT support */
9126         ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
9127     ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9128        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
9129        ret, msg.message, msg.wParam);
9130     ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
9131
9132     qstatus = GetQueueStatus(qs_all_input);
9133     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9134        "wrong qstatus %08x\n", qstatus);
9135
9136     msg.message = 0;
9137     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
9138     ok(!ret,
9139        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9140         msg.message);
9141     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9142
9143     qstatus = GetQueueStatus(qs_all_input);
9144     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9145        "wrong qstatus %08x\n", qstatus);
9146
9147     msg.message = 0;
9148     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9149     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9150        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9151        ret, msg.message, msg.wParam);
9152     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9153
9154     qstatus = GetQueueStatus(qs_all_input);
9155     ok(qstatus == 0,
9156        "wrong qstatus %08x\n", qstatus);
9157
9158     msg.message = 0;
9159     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9160     ok(!ret,
9161        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9162         msg.message);
9163     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9164
9165     qstatus = GetQueueStatus(qs_all_input);
9166     ok(qstatus == 0,
9167        "wrong qstatus %08x\n", qstatus);
9168
9169     /* test whether presence of the quit flag in the queue affects
9170      * the queue state
9171      */
9172     PostQuitMessage(0x1234abcd);
9173
9174     qstatus = GetQueueStatus(qs_all_input);
9175     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9176        "wrong qstatus %08x\n", qstatus);
9177
9178     PostMessageA(info.hwnd, WM_USER, 0, 0);
9179
9180     qstatus = GetQueueStatus(qs_all_input);
9181     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9182        "wrong qstatus %08x\n", qstatus);
9183
9184     msg.message = 0;
9185     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9186     ok(ret && msg.message == WM_USER,
9187        "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
9188     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9189
9190     qstatus = GetQueueStatus(qs_all_input);
9191     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9192        "wrong qstatus %08x\n", qstatus);
9193
9194     msg.message = 0;
9195     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9196     ok(ret && msg.message == WM_QUIT,
9197        "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
9198     ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
9199     ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
9200     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9201
9202     qstatus = GetQueueStatus(qs_all_input);
9203 todo_wine {
9204     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9205        "wrong qstatus %08x\n", qstatus);
9206 }
9207
9208     msg.message = 0;
9209     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9210     ok(!ret,
9211        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9212         msg.message);
9213     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9214
9215     qstatus = GetQueueStatus(qs_all_input);
9216     ok(qstatus == 0,
9217        "wrong qstatus %08x\n", qstatus);
9218
9219     /* some GetMessage tests */
9220
9221     keybd_event('N', 0, 0, 0);
9222     qstatus = GetQueueStatus(qs_all_input);
9223     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9224
9225     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9226     qstatus = GetQueueStatus(qs_all_input);
9227     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9228
9229     if (qstatus)
9230     {
9231         ret = GetMessageA( &msg, 0, 0, 0 );
9232         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9233            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9234            ret, msg.message, msg.wParam);
9235         qstatus = GetQueueStatus(qs_all_input);
9236         ok(qstatus == MAKELONG(0, QS_KEY), "wrong qstatus %08x\n", qstatus);
9237     }
9238
9239     if (qstatus)
9240     {
9241         ret = GetMessageA( &msg, 0, 0, 0 );
9242         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9243            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9244            ret, msg.message, msg.wParam);
9245         ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9246         qstatus = GetQueueStatus(qs_all_input);
9247         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9248     }
9249
9250     keybd_event('N', 0, 0, 0);
9251     qstatus = GetQueueStatus(qs_all_input);
9252     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9253
9254     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9255     qstatus = GetQueueStatus(qs_all_input);
9256     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9257
9258     if (qstatus & (QS_KEY << 16))
9259     {
9260         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9261         ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9262            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9263            ret, msg.message, msg.wParam);
9264         ok_sequence(WmKeyDownWasDownSkippedSeq, "WmKeyDownWasDownSkippedSeq", FALSE);
9265         qstatus = GetQueueStatus(qs_all_input);
9266         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9267     }
9268
9269     if (qstatus)
9270     {
9271         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9272         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9273            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9274            ret, msg.message, msg.wParam);
9275         qstatus = GetQueueStatus(qs_all_input);
9276         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9277     }
9278
9279     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9280     qstatus = GetQueueStatus(qs_all_input);
9281     ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9282
9283     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9284     qstatus = GetQueueStatus(qs_all_input);
9285     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9286
9287     trace("signalling to send message\n");
9288     SetEvent(info.hevent[EV_SENDMSG]);
9289     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9290     qstatus = GetQueueStatus(qs_all_input);
9291     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9292        "wrong qstatus %08x\n", qstatus);
9293
9294     if (qstatus & (QS_KEY << 16))
9295     {
9296         ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9297         ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9298            "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9299            ret, msg.message, msg.wParam);
9300         ok_sequence(WmUserKeyUpSkippedSeq, "WmUserKeyUpSkippedSeq", FALSE);
9301         qstatus = GetQueueStatus(qs_all_input);
9302         ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9303     }
9304
9305     if (qstatus)
9306     {
9307         ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9308         ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9309            "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9310            ret, msg.message, msg.wParam);
9311         qstatus = GetQueueStatus(qs_all_input);
9312         ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9313     }
9314 done:
9315     trace("signalling to exit\n");
9316     SetEvent(info.hevent[EV_STOP]);
9317
9318     WaitForSingleObject(hthread, INFINITE);
9319
9320     CloseHandle(hthread);
9321     CloseHandle(info.hevent[0]);
9322     CloseHandle(info.hevent[1]);
9323     CloseHandle(info.hevent[2]);
9324
9325     DestroyWindow(info.hwnd);
9326 }
9327
9328 static void wait_move_event(HWND hwnd, int x, int y)
9329 {
9330     MSG msg;
9331     DWORD time;
9332     BOOL  ret;
9333     int go = 0;
9334
9335     time = GetTickCount();
9336     while (GetTickCount() - time < 200 && !go) {
9337         ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9338         go  = ret && msg.pt.x > x && msg.pt.y > y;
9339         if (ret && !go) PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE);
9340     }
9341 }
9342
9343 #define STEP 20
9344 static void test_PeekMessage2(void)
9345 {
9346     HWND hwnd;
9347     BOOL ret;
9348     MSG msg;
9349     UINT message;
9350     DWORD time1, time2, time3;
9351     int x1, y1, x2, y2, x3, y3;
9352     POINT pos;
9353
9354     time1 = time2 = time3 = 0;
9355     x1 = y1 = x2 = y2 = x3 = y3 = 0;
9356
9357     /* Initialise window and make sure it is ready for events */
9358     hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
9359                         10, 10, 800, 800, NULL, NULL, NULL, NULL);
9360     assert(hwnd);
9361     trace("Window for test_PeekMessage2 %p\n", hwnd);
9362     ShowWindow(hwnd, SW_SHOW);
9363     UpdateWindow(hwnd);
9364     SetFocus(hwnd);
9365     GetCursorPos(&pos);
9366     SetCursorPos(100, 100);
9367     mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
9368     flush_events();
9369
9370     /* Do initial mousemove, wait until we can see it
9371        and then do our test peek with PM_NOREMOVE. */
9372     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9373     wait_move_event(hwnd, 80, 80);
9374
9375     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9376     ok(ret, "no message available\n");
9377     if (ret) {
9378         trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9379         message = msg.message;
9380         time1 = msg.time;
9381         x1 = msg.pt.x;
9382         y1 = msg.pt.y;
9383         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9384         PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE);
9385     }
9386
9387     /* Allow time to advance a bit, and then simulate the user moving their
9388      * mouse around. After that we peek again with PM_NOREMOVE.
9389      * Although the previous mousemove message was never removed, the
9390      * mousemove we now peek should reflect the recent mouse movements
9391      * because the input queue will merge the move events. */
9392     Sleep(2);
9393     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9394     wait_move_event(hwnd, x1, y1);
9395
9396     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9397     ok(ret, "no message available\n");
9398     if (ret) {
9399         trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9400         message = msg.message;
9401         time2 = msg.time;
9402         x2 = msg.pt.x;
9403         y2 = msg.pt.y;
9404         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9405         ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
9406         ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
9407         PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE);
9408     }
9409
9410     /* Have another go, to drive the point home */
9411     Sleep(2);
9412     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9413     wait_move_event(hwnd, x2, y2);
9414
9415     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9416     ok(ret, "no message available\n");
9417     if (ret) {
9418         trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9419         message = msg.message;
9420         time3 = msg.time;
9421         x3 = msg.pt.x;
9422         y3 = msg.pt.y;
9423         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9424         ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
9425         ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
9426     }
9427
9428     DestroyWindow(hwnd);
9429     SetCursorPos(pos.x, pos.y);
9430     flush_events();
9431 }
9432
9433 static void test_quit_message(void)
9434 {
9435     MSG msg;
9436     BOOL ret;
9437
9438     /* test using PostQuitMessage */
9439     flush_events();
9440     PostQuitMessage(0xbeef);
9441
9442     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9443     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9444     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9445     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9446
9447     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9448     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9449
9450     ret = GetMessage(&msg, NULL, 0, 0);
9451     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9452     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9453
9454     /* note: WM_QUIT message received after WM_USER message */
9455     ret = GetMessage(&msg, NULL, 0, 0);
9456     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9457     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9458     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9459
9460     ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
9461     ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
9462
9463     /* now test with PostThreadMessage - different behaviour! */
9464     PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
9465
9466     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9467     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9468     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9469     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9470
9471     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9472     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9473
9474     /* note: we receive the WM_QUIT message first this time */
9475     ret = GetMessage(&msg, NULL, 0, 0);
9476     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9477     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9478     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9479
9480     ret = GetMessage(&msg, NULL, 0, 0);
9481     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9482     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9483 }
9484
9485 static const struct message WmMouseHoverSeq[] = {
9486     { WM_MOUSEACTIVATE, sent|optional },  /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
9487     { WM_MOUSEACTIVATE, sent|optional },
9488     { WM_TIMER, sent|optional }, /* XP sends it */
9489     { WM_SYSTIMER, sent },
9490     { WM_MOUSEHOVER, sent|wparam, 0 },
9491     { 0 }
9492 };
9493
9494 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
9495 {
9496     MSG msg;
9497     DWORD start_ticks, end_ticks;
9498
9499     start_ticks = GetTickCount();
9500     /* add some deviation (50%) to cover not expected delays */
9501     start_ticks += timeout / 2;
9502
9503     do
9504     {
9505         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
9506         {
9507             /* Timer proc messages are not dispatched to the window proc,
9508              * and therefore not logged.
9509              */
9510             if (msg.message == WM_TIMER || msg.message == WM_SYSTIMER)
9511             {
9512                 struct recvd_message s_msg;
9513
9514                 s_msg.hwnd = msg.hwnd;
9515                 s_msg.message = msg.message;
9516                 s_msg.flags = sent|wparam|lparam;
9517                 s_msg.wParam = msg.wParam;
9518                 s_msg.lParam = msg.lParam;
9519                 s_msg.descr = "msg_loop";
9520                 add_message(&s_msg);
9521             }
9522             DispatchMessage(&msg);
9523         }
9524
9525         end_ticks = GetTickCount();
9526
9527         /* inject WM_MOUSEMOVE to see how it changes tracking */
9528         if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
9529         {
9530             mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9531             mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9532
9533             inject_mouse_move = FALSE;
9534         }
9535     } while (start_ticks + timeout >= end_ticks);
9536 }
9537
9538 static void test_TrackMouseEvent(void)
9539 {
9540     TRACKMOUSEEVENT tme;
9541     BOOL ret;
9542     HWND hwnd, hchild;
9543     RECT rc_parent, rc_child;
9544     UINT default_hover_time, hover_width = 0, hover_height = 0;
9545
9546 #define track_hover(track_hwnd, track_hover_time) \
9547     tme.cbSize = sizeof(tme); \
9548     tme.dwFlags = TME_HOVER; \
9549     tme.hwndTrack = track_hwnd; \
9550     tme.dwHoverTime = track_hover_time; \
9551     SetLastError(0xdeadbeef); \
9552     ret = pTrackMouseEvent(&tme); \
9553     ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
9554
9555 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
9556     tme.cbSize = sizeof(tme); \
9557     tme.dwFlags = TME_QUERY; \
9558     tme.hwndTrack = (HWND)0xdeadbeef; \
9559     tme.dwHoverTime = 0xdeadbeef; \
9560     SetLastError(0xdeadbeef); \
9561     ret = pTrackMouseEvent(&tme); \
9562     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
9563     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
9564     ok(tme.dwFlags == (expected_track_flags), \
9565        "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
9566     ok(tme.hwndTrack == (expected_track_hwnd), \
9567        "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
9568     ok(tme.dwHoverTime == (expected_hover_time), \
9569        "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
9570
9571 #define track_hover_cancel(track_hwnd) \
9572     tme.cbSize = sizeof(tme); \
9573     tme.dwFlags = TME_HOVER | TME_CANCEL; \
9574     tme.hwndTrack = track_hwnd; \
9575     tme.dwHoverTime = 0xdeadbeef; \
9576     SetLastError(0xdeadbeef); \
9577     ret = pTrackMouseEvent(&tme); \
9578     ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
9579
9580     default_hover_time = 0xdeadbeef;
9581     SetLastError(0xdeadbeef);
9582     ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
9583     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9584        "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
9585     if (!ret) default_hover_time = 400;
9586     trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
9587
9588     SetLastError(0xdeadbeef);
9589     ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
9590     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9591        "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
9592     if (!ret) hover_width = 4;
9593     SetLastError(0xdeadbeef);
9594     ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
9595     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9596        "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
9597     if (!ret) hover_height = 4;
9598     trace("hover rect is %u x %d\n", hover_width, hover_height);
9599
9600     hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
9601                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9602                           CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
9603                           NULL, NULL, 0);
9604     assert(hwnd);
9605
9606     hchild = CreateWindowEx(0, "TestWindowClass", NULL,
9607                           WS_CHILD | WS_BORDER | WS_VISIBLE,
9608                           50, 50, 200, 200, hwnd,
9609                           NULL, NULL, 0);
9610     assert(hchild);
9611
9612     SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
9613     flush_events();
9614     flush_sequence();
9615
9616     tme.cbSize = 0;
9617     tme.dwFlags = TME_QUERY;
9618     tme.hwndTrack = (HWND)0xdeadbeef;
9619     tme.dwHoverTime = 0xdeadbeef;
9620     SetLastError(0xdeadbeef);
9621     ret = pTrackMouseEvent(&tme);
9622     ok(!ret, "TrackMouseEvent should fail\n");
9623     ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef),
9624        "not expected error %u\n", GetLastError());
9625
9626     tme.cbSize = sizeof(tme);
9627     tme.dwFlags = TME_HOVER;
9628     tme.hwndTrack = (HWND)0xdeadbeef;
9629     tme.dwHoverTime = 0xdeadbeef;
9630     SetLastError(0xdeadbeef);
9631     ret = pTrackMouseEvent(&tme);
9632     ok(!ret, "TrackMouseEvent should fail\n");
9633     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
9634        "not expected error %u\n", GetLastError());
9635
9636     tme.cbSize = sizeof(tme);
9637     tme.dwFlags = TME_HOVER | TME_CANCEL;
9638     tme.hwndTrack = (HWND)0xdeadbeef;
9639     tme.dwHoverTime = 0xdeadbeef;
9640     SetLastError(0xdeadbeef);
9641     ret = pTrackMouseEvent(&tme);
9642     ok(!ret, "TrackMouseEvent should fail\n");
9643     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
9644        "not expected error %u\n", GetLastError());
9645
9646     GetWindowRect(hwnd, &rc_parent);
9647     GetWindowRect(hchild, &rc_child);
9648     SetCursorPos(rc_child.left - 10, rc_child.top - 10);
9649
9650     /* Process messages so that the system updates its internal current
9651      * window and hittest, otherwise TrackMouseEvent calls don't have any
9652      * effect.
9653      */
9654     flush_events();
9655     flush_sequence();
9656
9657     track_query(0, NULL, 0);
9658     track_hover(hchild, 0);
9659     track_query(0, NULL, 0);
9660
9661     flush_events();
9662     flush_sequence();
9663
9664     track_hover(hwnd, 0);
9665     tme.cbSize = sizeof(tme);
9666     tme.dwFlags = TME_QUERY;
9667     tme.hwndTrack = (HWND)0xdeadbeef;
9668     tme.dwHoverTime = 0xdeadbeef;
9669     SetLastError(0xdeadbeef);
9670     ret = pTrackMouseEvent(&tme);
9671     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());
9672     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize);
9673     if (!tme.dwFlags)
9674     {
9675         skip( "Cursor not inside window, skipping TrackMouseEvent tests\n" );
9676         DestroyWindow( hwnd );
9677         return;
9678     }
9679     ok(tme.dwFlags == TME_HOVER, "wrong tme.dwFlags %08x, expected TME_HOVER\n", tme.dwFlags);
9680     ok(tme.hwndTrack == hwnd, "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, hwnd);
9681     ok(tme.dwHoverTime == default_hover_time, "wrong tme.dwHoverTime %u, expected %u\n",
9682        tme.dwHoverTime, default_hover_time);
9683
9684     pump_msg_loop_timeout(default_hover_time, FALSE);
9685     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9686
9687     track_query(0, NULL, 0);
9688
9689     track_hover(hwnd, HOVER_DEFAULT);
9690     track_query(TME_HOVER, hwnd, default_hover_time);
9691
9692     Sleep(default_hover_time / 2);
9693     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9694     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9695
9696     track_query(TME_HOVER, hwnd, default_hover_time);
9697
9698     pump_msg_loop_timeout(default_hover_time, FALSE);
9699     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9700
9701     track_query(0, NULL, 0);
9702
9703     track_hover(hwnd, HOVER_DEFAULT);
9704     track_query(TME_HOVER, hwnd, default_hover_time);
9705
9706     pump_msg_loop_timeout(default_hover_time, TRUE);
9707     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9708
9709     track_query(0, NULL, 0);
9710
9711     track_hover(hwnd, HOVER_DEFAULT);
9712     track_query(TME_HOVER, hwnd, default_hover_time);
9713     track_hover_cancel(hwnd);
9714
9715     DestroyWindow(hwnd);
9716
9717 #undef track_hover
9718 #undef track_query
9719 #undef track_hover_cancel
9720 }
9721
9722
9723 static const struct message WmSetWindowRgn[] = {
9724     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9725     { WM_NCCALCSIZE, sent|wparam, 1 },
9726     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
9727     { WM_GETTEXT, sent|defwinproc|optional },
9728     { WM_ERASEBKGND, sent|optional },
9729     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9730     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9731     { 0 }
9732 };
9733
9734 static const struct message WmSetWindowRgn_no_redraw[] = {
9735     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9736     { WM_NCCALCSIZE, sent|wparam, 1 },
9737     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9738     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9739     { 0 }
9740 };
9741
9742 static const struct message WmSetWindowRgn_clear[] = {
9743     { WM_WINDOWPOSCHANGING, sent/*|wparam*/, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE/*|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE only on some Windows versions */ },
9744     { WM_NCCALCSIZE, sent|wparam, 1 },
9745     { WM_NCPAINT, sent|optional },
9746     { WM_GETTEXT, sent|defwinproc|optional },
9747     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
9748     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9749     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
9750     { WM_NCPAINT, sent|optional },
9751     { WM_GETTEXT, sent|defwinproc|optional },
9752     { WM_ERASEBKGND, sent|optional },
9753     { WM_WINDOWPOSCHANGING, sent|optional },
9754     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
9755     { WM_NCPAINT, sent|optional },
9756     { WM_GETTEXT, sent|defwinproc|optional },
9757     { WM_ERASEBKGND, sent|optional },
9758     { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9759     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
9760     { WM_NCPAINT, sent|optional },
9761     { WM_GETTEXT, sent|defwinproc|optional },
9762     { WM_ERASEBKGND, sent|optional },
9763     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9764     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9765     { 0 }
9766 };
9767
9768 static void test_SetWindowRgn(void)
9769 {
9770     HRGN hrgn;
9771     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
9772                                 100, 100, 200, 200, 0, 0, 0, NULL);
9773     ok( hwnd != 0, "Failed to create overlapped window\n" );
9774
9775     ShowWindow( hwnd, SW_SHOW );
9776     UpdateWindow( hwnd );
9777     flush_events();
9778     flush_sequence();
9779
9780     trace("testing SetWindowRgn\n");
9781     hrgn = CreateRectRgn( 0, 0, 150, 150 );
9782     SetWindowRgn( hwnd, hrgn, TRUE );
9783     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
9784
9785     hrgn = CreateRectRgn( 30, 30, 160, 160 );
9786     SetWindowRgn( hwnd, hrgn, FALSE );
9787     ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
9788
9789     hrgn = CreateRectRgn( 0, 0, 180, 180 );
9790     SetWindowRgn( hwnd, hrgn, TRUE );
9791     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
9792
9793     SetWindowRgn( hwnd, 0, TRUE );
9794     ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
9795
9796     DestroyWindow( hwnd );
9797 }
9798
9799 /*************************** ShowWindow() test ******************************/
9800 static const struct message WmShowNormal[] = {
9801     { WM_SHOWWINDOW, sent|wparam, 1 },
9802     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9803     { HCBT_ACTIVATE, hook },
9804     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9805     { HCBT_SETFOCUS, hook },
9806     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9807     { 0 }
9808 };
9809 static const struct message WmShow[] = {
9810     { WM_SHOWWINDOW, sent|wparam, 1 },
9811     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9812     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9813     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9814     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9815     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9816     { 0 }
9817 };
9818 static const struct message WmShowNoActivate_1[] = {
9819     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9820     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9821     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9822     { WM_MOVE, sent|defwinproc|optional },
9823     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9824     { 0 }
9825 };
9826 static const struct message WmShowNoActivate_2[] = {
9827     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9828     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9829     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9830     { WM_MOVE, sent|defwinproc },
9831     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9832     { HCBT_SETFOCUS, hook|optional },
9833     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9834     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9835     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9836     { 0 }
9837 };
9838 static const struct message WmShowNA_1[] = {
9839     { WM_SHOWWINDOW, sent|wparam, 1 },
9840     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9841     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9842     { 0 }
9843 };
9844 static const struct message WmShowNA_2[] = {
9845     { WM_SHOWWINDOW, sent|wparam, 1 },
9846     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9847     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9848     { 0 }
9849 };
9850 static const struct message WmRestore_1[] = {
9851     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9852     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9853     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9854     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9855     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9856     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9857     { WM_MOVE, sent|defwinproc },
9858     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9859     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9860     { 0 }
9861 };
9862 static const struct message WmRestore_2[] = {
9863     { WM_SHOWWINDOW, sent|wparam, 1 },
9864     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9865     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9866     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9867     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9868     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9869     { 0 }
9870 };
9871 static const struct message WmRestore_3[] = {
9872     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9873     { WM_GETMINMAXINFO, sent },
9874     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9875     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9876     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9877     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9878     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9879     { WM_MOVE, sent|defwinproc },
9880     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9881     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9882     { 0 }
9883 };
9884 static const struct message WmRestore_4[] = {
9885     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9886     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9887     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9888     { WM_MOVE, sent|defwinproc|optional },
9889     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9890     { 0 }
9891 };
9892 static const struct message WmRestore_5[] = {
9893     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
9894     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9895     { HCBT_ACTIVATE, hook|optional },
9896     { HCBT_SETFOCUS, hook|optional },
9897     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
9898     { WM_MOVE, sent|defwinproc|optional },
9899     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9900     { 0 }
9901 };
9902 static const struct message WmHide_1[] = {
9903     { WM_SHOWWINDOW, sent|wparam, 0 },
9904     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9905     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9906     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9907     { 0 }
9908 };
9909 static const struct message WmHide_2[] = {
9910     { WM_SHOWWINDOW, sent|wparam, 0 },
9911     { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9912     { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9913     { 0 }
9914 };
9915 static const struct message WmHide_3[] = {
9916     { WM_SHOWWINDOW, sent|wparam, 0 },
9917     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9918     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9919     { HCBT_SETFOCUS, hook|optional },
9920     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9921     { 0 }
9922 };
9923 static const struct message WmShowMinimized_1[] = {
9924     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9925     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9926     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9927     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9928     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9929     { WM_MOVE, sent|defwinproc },
9930     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9931     { 0 }
9932 };
9933 static const struct message WmMinimize_1[] = {
9934     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9935     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9936     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9937     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9938     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9939     { WM_MOVE, sent|defwinproc },
9940     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9941     { 0 }
9942 };
9943 static const struct message WmMinimize_2[] = {
9944     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9945     { HCBT_SETFOCUS, hook|optional },
9946     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9947     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9948     { WM_MOVE, sent|defwinproc },
9949     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9950     { 0 }
9951 };
9952 static const struct message WmMinimize_3[] = {
9953     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9954     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9955     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9956     { WM_MOVE, sent|defwinproc },
9957     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9958     { 0 }
9959 };
9960 static const struct message WmShowMinNoActivate[] = {
9961     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9962     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9963     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9964     { 0 }
9965 };
9966 static const struct message WmMinMax_1[] = {
9967     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9968     { 0 }
9969 };
9970 static const struct message WmMinMax_2[] = {
9971     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9972     { WM_GETMINMAXINFO, sent|optional },
9973     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED },
9974     { HCBT_ACTIVATE, hook|optional },
9975     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
9976     { HCBT_SETFOCUS, hook|optional },
9977     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9978     { WM_MOVE, sent|defwinproc|optional },
9979     { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MAXIMIZED },
9980     { HCBT_SETFOCUS, hook|optional },
9981     { 0 }
9982 };
9983 static const struct message WmMinMax_3[] = {
9984     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9985     { 0 }
9986 };
9987 static const struct message WmMinMax_4[] = {
9988     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9989     { 0 }
9990 };
9991 static const struct message WmShowMaximized_1[] = {
9992     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9993     { WM_GETMINMAXINFO, sent },
9994     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9995     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9996     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9997     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9998     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9999     { WM_MOVE, sent|defwinproc },
10000     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10001     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10002     { 0 }
10003 };
10004 static const struct message WmShowMaximized_2[] = {
10005     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10006     { WM_GETMINMAXINFO, sent },
10007     { WM_WINDOWPOSCHANGING, sent|optional },
10008     { HCBT_ACTIVATE, hook|optional },
10009     { WM_WINDOWPOSCHANGED, sent|optional },
10010     { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
10011     { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
10012     { WM_WINDOWPOSCHANGING, sent },
10013     { HCBT_SETFOCUS, hook|optional },
10014     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10015     { WM_MOVE, sent|defwinproc },
10016     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10017     { HCBT_SETFOCUS, hook|optional },
10018     { 0 }
10019 };
10020 static const struct message WmShowMaximized_3[] = {
10021     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10022     { WM_GETMINMAXINFO, sent },
10023     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10024     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10025     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10026     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10027     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10028     { WM_MOVE, sent|defwinproc|optional },
10029     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10030     { 0 }
10031 };
10032
10033 static void test_ShowWindow(void)
10034 {
10035     /* ShowWindow commands in random order */
10036     static const struct
10037     {
10038         INT cmd; /* ShowWindow command */
10039         LPARAM ret; /* ShowWindow return value */
10040         DWORD style; /* window style after the command */
10041         const struct message *msg; /* message sequence the command produces */
10042         BOOL todo_msg; /* message sequence doesn't match what Wine does */
10043     } sw[] =
10044     {
10045 /*  1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
10046 /*  2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10047 /*  3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10048 /*  4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10049 /*  5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
10050 /*  6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
10051 /*  7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
10052 /*  8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10053 /*  9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
10054 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10055 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
10056 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
10057 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
10058 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10059 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
10060 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10061 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
10062 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10063 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10064 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10065 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10066 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
10067 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
10068 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10069 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10070 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
10071 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
10072 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10073 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10074 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
10075 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10076 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, FALSE },
10077 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10078 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE }, /* what does this mean?! */
10079 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE },
10080 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10081 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
10082 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10083 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10084 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, FALSE },
10085 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10086 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, TRUE },
10087 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10088 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10089 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10090 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
10091 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
10092 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
10093 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
10094 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
10095 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10096 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10097 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10098 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, FALSE },
10099 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10100 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
10101 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
10102     };
10103     HWND hwnd;
10104     DWORD style;
10105     LPARAM ret;
10106     INT i;
10107
10108 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
10109     hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
10110                           120, 120, 90, 90,
10111                           0, 0, 0, NULL);
10112     assert(hwnd);
10113
10114     style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10115     ok(style == 0, "expected style 0, got %08x\n", style);
10116
10117     flush_events();
10118     flush_sequence();
10119
10120     for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
10121     {
10122         static const char * const sw_cmd_name[13] =
10123         {
10124             "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
10125             "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
10126             "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
10127             "SW_NORMALNA" /* 0xCC */
10128         };
10129         char comment[64];
10130         INT idx; /* index into the above array of names */
10131
10132         idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
10133
10134         style = GetWindowLong(hwnd, GWL_STYLE);
10135         trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
10136         ret = ShowWindow(hwnd, sw[i].cmd);
10137         ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
10138         style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10139         ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
10140
10141         sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
10142         ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
10143
10144         flush_events();
10145         flush_sequence();
10146     }
10147
10148     DestroyWindow(hwnd);
10149 }
10150
10151 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
10152 {
10153     struct recvd_message msg;
10154
10155     switch (message)
10156     {
10157     case WM_GETICON:
10158     case WM_GETOBJECT:
10159         return 0;  /* ignore them */
10160     }
10161
10162     msg.hwnd = hwnd;
10163     msg.message = message;
10164     msg.flags = sent|wparam|lparam;
10165     msg.wParam = wParam;
10166     msg.lParam = lParam;
10167     msg.descr = "dialog";
10168     add_message(&msg);
10169
10170     /* calling DefDlgProc leads to a recursion under XP */
10171
10172     switch (message)
10173     {
10174     case WM_INITDIALOG:
10175     case WM_GETDLGCODE:
10176         return 0;
10177     }
10178     return 1;
10179 }
10180
10181 static const struct message WmDefDlgSetFocus_1[] = {
10182     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10183     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10184     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10185     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10186     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10187     { HCBT_SETFOCUS, hook },
10188     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
10189     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10190     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10191     { WM_SETFOCUS, sent|wparam, 0 },
10192     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
10193     { WM_CTLCOLOREDIT, sent },
10194     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
10195     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10196     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10197     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10198     { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
10199     { 0 }
10200 };
10201 static const struct message WmDefDlgSetFocus_2[] = {
10202     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10203     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10204     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10205     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10206     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10207     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10208     { WM_CTLCOLOREDIT, sent|optional }, /* XP */
10209     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10210     { 0 }
10211 };
10212 /* Creation of a dialog */
10213 static const struct message WmCreateDialogParamSeq_1[] = {
10214     { HCBT_CREATEWND, hook },
10215     { WM_NCCREATE, sent },
10216     { WM_NCCALCSIZE, sent|wparam, 0 },
10217     { WM_CREATE, sent },
10218     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10219     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10220     { WM_MOVE, sent },
10221     { WM_SETFONT, sent },
10222     { WM_INITDIALOG, sent },
10223     { WM_CHANGEUISTATE, sent|optional },
10224     { 0 }
10225 };
10226 /* Creation of a dialog */
10227 static const struct message WmCreateDialogParamSeq_2[] = {
10228     { HCBT_CREATEWND, hook },
10229     { WM_NCCREATE, sent },
10230     { WM_NCCALCSIZE, sent|wparam, 0 },
10231     { WM_CREATE, sent },
10232     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10233     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10234     { WM_MOVE, sent },
10235     { WM_CHANGEUISTATE, sent|optional },
10236     { 0 }
10237 };
10238
10239 static void test_dialog_messages(void)
10240 {
10241     WNDCLASS cls;
10242     HWND hdlg, hedit1, hedit2, hfocus;
10243     LRESULT ret;
10244
10245 #define set_selection(hctl, start, end) \
10246     ret = SendMessage(hctl, EM_SETSEL, start, end); \
10247     ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
10248
10249 #define check_selection(hctl, start, end) \
10250     ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
10251     ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
10252
10253     subclass_edit();
10254
10255     hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
10256                           WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
10257                           0, 0, 100, 100, 0, 0, 0, NULL);
10258     ok(hdlg != 0, "Failed to create custom dialog window\n");
10259
10260     hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
10261                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10262                            0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
10263     ok(hedit1 != 0, "Failed to create edit control\n");
10264     hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
10265                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10266                            0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
10267     ok(hedit2 != 0, "Failed to create edit control\n");
10268
10269     SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
10270     SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
10271
10272     hfocus = GetFocus();
10273     ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
10274
10275     SetFocus(hedit2);
10276     hfocus = GetFocus();
10277     ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
10278
10279     check_selection(hedit1, 0, 0);
10280     check_selection(hedit2, 0, 0);
10281
10282     set_selection(hedit2, 0, -1);
10283     check_selection(hedit2, 0, 3);
10284
10285     SetFocus(0);
10286     hfocus = GetFocus();
10287     ok(hfocus == 0, "wrong focus %p\n", hfocus);
10288
10289     flush_sequence();
10290     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10291     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10292     ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
10293
10294     hfocus = GetFocus();
10295     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10296
10297     check_selection(hedit1, 0, 5);
10298     check_selection(hedit2, 0, 3);
10299
10300     flush_sequence();
10301     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10302     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10303     ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
10304
10305     hfocus = GetFocus();
10306     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10307
10308     check_selection(hedit1, 0, 5);
10309     check_selection(hedit2, 0, 3);
10310
10311     EndDialog(hdlg, 0);
10312     DestroyWindow(hedit1);
10313     DestroyWindow(hedit2);
10314     DestroyWindow(hdlg);
10315     flush_sequence();
10316
10317 #undef set_selection
10318 #undef check_selection
10319
10320     ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
10321     cls.lpszClassName = "MyDialogClass";
10322     cls.hInstance = GetModuleHandle(0);
10323     /* need a cast since a dlgproc is used as a wndproc */
10324     cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
10325     if (!RegisterClass(&cls)) assert(0);
10326
10327     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
10328     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10329     ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
10330     EndDialog(hdlg, 0);
10331     DestroyWindow(hdlg);
10332     flush_sequence();
10333
10334     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
10335     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10336     ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
10337     EndDialog(hdlg, 0);
10338     DestroyWindow(hdlg);
10339     flush_sequence();
10340
10341     UnregisterClass(cls.lpszClassName, cls.hInstance);
10342 }
10343
10344 static void test_nullCallback(void)
10345 {
10346     HWND hwnd;
10347
10348     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10349                            100, 100, 200, 200, 0, 0, 0, NULL);
10350     ok (hwnd != 0, "Failed to create overlapped window\n");
10351
10352     SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
10353     flush_events();
10354     DestroyWindow(hwnd);
10355 }
10356
10357 /* SetActiveWindow( 0 ) hwnd visible */
10358 static const struct message SetActiveWindowSeq0[] =
10359 {
10360     { HCBT_ACTIVATE, hook },
10361     { WM_NCACTIVATE, sent|wparam, 0 },
10362     { WM_GETTEXT, sent|defwinproc|optional },
10363     { WM_ACTIVATE, sent|wparam, 0 },
10364     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10365     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10366     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10367     { WM_NCACTIVATE, sent|wparam, 1 },
10368     { WM_GETTEXT, sent|defwinproc|optional },
10369     { WM_ACTIVATE, sent|wparam, 1 },
10370     { HCBT_SETFOCUS, hook },
10371     { WM_KILLFOCUS, sent|defwinproc },
10372     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10373     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10374     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10375     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10376     { WM_SETFOCUS, sent|defwinproc },
10377     { WM_GETTEXT, sent|optional },
10378     { 0 }
10379 };
10380 /* SetActiveWindow( hwnd ) hwnd visible */
10381 static const struct message SetActiveWindowSeq1[] =
10382 {
10383     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10384     { 0 }
10385 };
10386 /* SetActiveWindow( popup ) hwnd visible, popup visible */
10387 static const struct message SetActiveWindowSeq2[] =
10388 {
10389     { HCBT_ACTIVATE, hook },
10390     { WM_NCACTIVATE, sent|wparam, 0 },
10391     { WM_GETTEXT, sent|defwinproc|optional },
10392     { WM_ACTIVATE, sent|wparam, 0 },
10393     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10394     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10395     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10396     { WM_NCPAINT, sent|optional },
10397     { WM_GETTEXT, sent|defwinproc|optional },
10398     { WM_ERASEBKGND, sent|optional },
10399     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10400     { WM_NCACTIVATE, sent|wparam, 1 },
10401     { WM_GETTEXT, sent|defwinproc|optional },
10402     { WM_ACTIVATE, sent|wparam, 1 },
10403     { HCBT_SETFOCUS, hook },
10404     { WM_KILLFOCUS, sent|defwinproc },
10405     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10406     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10407     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10408     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10409     { WM_SETFOCUS, sent|defwinproc },
10410     { WM_GETTEXT, sent|optional },
10411     { 0 }
10412 };
10413
10414 /* SetActiveWindow( hwnd ) hwnd not visible */
10415 static const struct message SetActiveWindowSeq3[] =
10416 {
10417     { HCBT_ACTIVATE, hook },
10418     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10419     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10420     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10421     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10422     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10423     { WM_ACTIVATEAPP, sent|wparam, 1 },
10424     { WM_ACTIVATEAPP, sent|wparam, 1 },
10425     { WM_NCACTIVATE, sent|wparam, 1 },
10426     { WM_ACTIVATE, sent|wparam, 1 },
10427     { HCBT_SETFOCUS, hook },
10428     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10429     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10430     { WM_SETFOCUS, sent|defwinproc },
10431     { 0 }
10432 };
10433 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
10434 static const struct message SetActiveWindowSeq4[] =
10435 {
10436     { HCBT_ACTIVATE, hook },
10437     { WM_NCACTIVATE, sent|wparam, 0 },
10438     { WM_GETTEXT, sent|defwinproc|optional },
10439     { WM_ACTIVATE, sent|wparam, 0 },
10440     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10441     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10442     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10443     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10444     { WM_NCACTIVATE, sent|wparam, 1 },
10445     { WM_GETTEXT, sent|defwinproc|optional },
10446     { WM_ACTIVATE, sent|wparam, 1 },
10447     { HCBT_SETFOCUS, hook },
10448     { WM_KILLFOCUS, sent|defwinproc },
10449     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10450     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10451     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10452     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10453     { WM_SETFOCUS, sent|defwinproc },
10454     { 0 }
10455 };
10456
10457
10458 static void test_SetActiveWindow(void)
10459 {
10460     HWND hwnd, popup, ret;
10461
10462     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10463                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10464                            100, 100, 200, 200, 0, 0, 0, NULL);
10465
10466     popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10467                            WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
10468                            100, 100, 200, 200, hwnd, 0, 0, NULL);
10469
10470     ok(hwnd != 0, "Failed to create overlapped window\n");
10471     ok(popup != 0, "Failed to create popup window\n");
10472     SetForegroundWindow( popup );
10473     flush_sequence();
10474
10475     trace("SetActiveWindow(0)\n");
10476     ret = SetActiveWindow(0);
10477     ok( ret == popup, "Failed to SetActiveWindow(0)\n");
10478     ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", TRUE);
10479     flush_sequence();
10480
10481     trace("SetActiveWindow(hwnd), hwnd visible\n");
10482     ret = SetActiveWindow(hwnd);
10483     todo_wine
10484     {
10485         ok( ret == hwnd, "Failed to SetActiveWindow(hwnd), hwnd visible\n");
10486     }
10487     ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
10488     flush_sequence();
10489
10490     trace("SetActiveWindow(popup), hwnd visible, popup visible\n");
10491     ret = SetActiveWindow(popup);
10492     ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visible\n");
10493     ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visible", FALSE);
10494     flush_sequence();
10495
10496     ShowWindow(hwnd, SW_HIDE);
10497     ShowWindow(popup, SW_HIDE);
10498     flush_sequence();
10499
10500     trace("SetActiveWindow(hwnd), hwnd not visible\n");
10501     ret = SetActiveWindow(hwnd);
10502     ok( ret == NULL, "SetActiveWindow(hwnd), hwnd not visible, previous is %p\n", ret );
10503     ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
10504     flush_sequence();
10505
10506     trace("SetActiveWindow(popup), hwnd not visible, popup not visible\n");
10507     ret = SetActiveWindow(popup);
10508     ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
10509     ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visible", TRUE);
10510     flush_sequence();
10511
10512     trace("done\n");
10513
10514     DestroyWindow(hwnd);
10515 }
10516
10517 static const struct message SetForegroundWindowSeq[] =
10518 {
10519     { WM_NCACTIVATE, sent|wparam, 0 },
10520     { WM_GETTEXT, sent|defwinproc|optional },
10521     { WM_ACTIVATE, sent|wparam, 0 },
10522     { WM_ACTIVATEAPP, sent|wparam, 0 },
10523     { WM_KILLFOCUS, sent },
10524     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
10525     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
10526     { 0 }
10527 };
10528
10529 static void test_SetForegroundWindow(void)
10530 {
10531     HWND hwnd;
10532
10533     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
10534                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10535                            100, 100, 200, 200, 0, 0, 0, NULL);
10536     ok (hwnd != 0, "Failed to create overlapped window\n");
10537     flush_sequence();
10538
10539     trace("SetForegroundWindow( 0 )\n");
10540     SetForegroundWindow( 0 );
10541     ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
10542     trace("SetForegroundWindow( GetDesktopWindow() )\n");
10543     SetForegroundWindow( GetDesktopWindow() );
10544     ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
10545                                         "foreground top level window", FALSE);
10546     trace("done\n");
10547
10548     DestroyWindow(hwnd);
10549 }
10550
10551 static void test_dbcs_wm_char(void)
10552 {
10553     BYTE dbch[2];
10554     WCHAR wch, bad_wch;
10555     HWND hwnd, hwnd2;
10556     MSG msg;
10557     DWORD time;
10558     POINT pt;
10559     DWORD_PTR res;
10560     CPINFOEXA cpinfo;
10561     UINT i, j, k;
10562     struct message wmCharSeq[2];
10563
10564     if (!pGetCPInfoExA)
10565     {
10566         skip("GetCPInfoExA is not available\n");
10567         return;
10568     }
10569
10570     pGetCPInfoExA( CP_ACP, 0, &cpinfo );
10571     if (cpinfo.MaxCharSize != 2)
10572     {
10573         skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
10574         return;
10575     }
10576
10577     dbch[0] = dbch[1] = 0;
10578     wch = 0;
10579     bad_wch = cpinfo.UnicodeDefaultChar;
10580     for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
10581         for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
10582             for (k = 128; k <= 255; k++)
10583             {
10584                 char str[2];
10585                 WCHAR wstr[2];
10586                 str[0] = j;
10587                 str[1] = k;
10588                 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
10589                     WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
10590                     (BYTE)str[0] == j && (BYTE)str[1] == k &&
10591                     HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
10592                 {
10593                     dbch[0] = j;
10594                     dbch[1] = k;
10595                     wch = wstr[0];
10596                     break;
10597                 }
10598             }
10599
10600     if (!wch)
10601     {
10602         skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
10603         return;
10604     }
10605     trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
10606            dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
10607
10608     hwnd = CreateWindowExW(0, testWindowClassW, NULL,
10609                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
10610     hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
10611                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
10612     ok (hwnd != 0, "Failed to create overlapped window\n");
10613     ok (hwnd2 != 0, "Failed to create overlapped window\n");
10614     flush_sequence();
10615
10616     memset( wmCharSeq, 0, sizeof(wmCharSeq) );
10617     wmCharSeq[0].message = WM_CHAR;
10618     wmCharSeq[0].flags = sent|wparam;
10619     wmCharSeq[0].wParam = wch;
10620
10621     /* posted message */
10622     PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10623     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10624     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10625     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10626     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10627     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10628     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10629
10630     /* posted thread message */
10631     PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
10632     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10633     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10634     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10635     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10636     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10637     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10638
10639     /* sent message */
10640     flush_sequence();
10641     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10642     ok_sequence( WmEmptySeq, "no messages", FALSE );
10643     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10644     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10645     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10646
10647     /* sent message with timeout */
10648     flush_sequence();
10649     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10650     ok_sequence( WmEmptySeq, "no messages", FALSE );
10651     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10652     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10653     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10654
10655     /* sent message with timeout and callback */
10656     flush_sequence();
10657     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10658     ok_sequence( WmEmptySeq, "no messages", FALSE );
10659     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10660     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10661     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10662
10663     /* sent message with callback */
10664     flush_sequence();
10665     SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10666     ok_sequence( WmEmptySeq, "no messages", FALSE );
10667     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10668     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10669     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10670
10671     /* direct window proc call */
10672     flush_sequence();
10673     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10674     ok_sequence( WmEmptySeq, "no messages", FALSE );
10675     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10676     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10677
10678     /* dispatch message */
10679     msg.hwnd = hwnd;
10680     msg.message = WM_CHAR;
10681     msg.wParam = dbch[0];
10682     msg.lParam = 0;
10683     DispatchMessageA( &msg );
10684     ok_sequence( WmEmptySeq, "no messages", FALSE );
10685     msg.wParam = dbch[1];
10686     DispatchMessageA( &msg );
10687     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10688
10689     /* window handle is irrelevant */
10690     flush_sequence();
10691     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10692     ok_sequence( WmEmptySeq, "no messages", FALSE );
10693     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10694     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10695     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10696
10697     /* interleaved post and send */
10698     flush_sequence();
10699     PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10700     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10701     ok_sequence( WmEmptySeq, "no messages", FALSE );
10702     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10703     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10704     ok_sequence( WmEmptySeq, "no messages", FALSE );
10705     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10706     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10707     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10708     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10709     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10710     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10711     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10712
10713     /* interleaved sent message and winproc */
10714     flush_sequence();
10715     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10716     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10717     ok_sequence( WmEmptySeq, "no messages", FALSE );
10718     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10719     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10720     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10721     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10722
10723     /* interleaved winproc and dispatch */
10724     msg.hwnd = hwnd;
10725     msg.message = WM_CHAR;
10726     msg.wParam = dbch[0];
10727     msg.lParam = 0;
10728     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10729     DispatchMessageA( &msg );
10730     ok_sequence( WmEmptySeq, "no messages", FALSE );
10731     msg.wParam = dbch[1];
10732     DispatchMessageA( &msg );
10733     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10734     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10735     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10736
10737     /* interleaved sends */
10738     flush_sequence();
10739     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10740     SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
10741     ok_sequence( WmEmptySeq, "no messages", FALSE );
10742     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10743     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10744     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10745     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10746
10747     /* dbcs WM_CHAR */
10748     flush_sequence();
10749     SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
10750     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10751     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10752
10753     /* other char messages are not magic */
10754     PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
10755     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10756     ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
10757     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10758     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10759     PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
10760     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10761     ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
10762     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10763     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10764
10765     /* test retrieving messages */
10766
10767     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10768     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10769     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10770     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10771     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10772     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10773     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10774     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10775     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10776     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10777
10778     /* message filters */
10779     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10780     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10781     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10782     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10783     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10784     /* message id is filtered, hwnd is not */
10785     ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
10786     ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
10787     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10788     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10789     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10790     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10791
10792     /* mixing GetMessage and PostMessage */
10793     PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
10794     ok( GetMessageA( &msg, hwnd, 0, 0 ), "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( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10799     time = msg.time;
10800     pt = msg.pt;
10801     ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
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( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10807     ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
10808     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 );
10809     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10810
10811     /* without PM_REMOVE */
10812     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10813     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10814     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10815     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10816     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10817     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10818     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10819     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10820     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10821     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10822     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10823     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10824     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10825     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10826     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10827     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10828     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10829     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10830
10831     DestroyWindow(hwnd);
10832 }
10833
10834 #define ID_LISTBOX 0x000f
10835
10836 static const struct message wm_lb_setcursel_0[] =
10837 {
10838     { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
10839     { WM_CTLCOLORLISTBOX, sent|parent },
10840     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10841     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10842     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10843     { 0 }
10844 };
10845 static const struct message wm_lb_setcursel_1[] =
10846 {
10847     { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
10848     { WM_CTLCOLORLISTBOX, sent|parent },
10849     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
10850     { WM_CTLCOLORLISTBOX, sent|parent },
10851     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
10852     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10853     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10854     { 0 }
10855 };
10856 static const struct message wm_lb_setcursel_2[] =
10857 {
10858     { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
10859     { WM_CTLCOLORLISTBOX, sent|parent },
10860     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
10861     { WM_CTLCOLORLISTBOX, sent|parent },
10862     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
10863     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10864     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10865     { 0 }
10866 };
10867 static const struct message wm_lb_click_0[] =
10868 {
10869     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
10870     { HCBT_SETFOCUS, hook },
10871     { WM_KILLFOCUS, sent|parent },
10872     { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
10873     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10874     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10875     { WM_SETFOCUS, sent|defwinproc },
10876
10877     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
10878     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
10879     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10880     { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
10881     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
10882
10883     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
10884     { WM_CTLCOLORLISTBOX, sent|parent },
10885     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
10886     { WM_CTLCOLORLISTBOX, sent|parent },
10887     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10888     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
10889
10890     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10891     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10892
10893     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
10894     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
10895     { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
10896     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
10897     { 0 }
10898 };
10899
10900 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
10901
10902 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
10903
10904 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
10905 {
10906     static long defwndproc_counter = 0;
10907     LRESULT ret;
10908     struct recvd_message msg;
10909
10910     /* do not log painting messages */
10911     if (message != WM_PAINT &&
10912         message != WM_NCPAINT &&
10913         message != WM_SYNCPAINT &&
10914         message != WM_ERASEBKGND &&
10915         message != WM_NCHITTEST &&
10916         message != WM_GETTEXT &&
10917         message != WM_GETOBJECT &&
10918         message != WM_GETICON &&
10919         message != WM_DEVICECHANGE)
10920     {
10921         msg.hwnd = hwnd;
10922         msg.message = message;
10923         msg.flags = sent|wparam|lparam;
10924         if (defwndproc_counter) msg.flags |= defwinproc;
10925         msg.wParam = wp;
10926         msg.lParam = lp;
10927         msg.descr = "listbox";
10928         add_message(&msg);
10929     }
10930
10931     defwndproc_counter++;
10932     ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
10933     defwndproc_counter--;
10934
10935     return ret;
10936 }
10937
10938 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
10939                                int caret_index, int top_index, int line)
10940 {
10941     LRESULT ret;
10942
10943     /* calling an orig proc helps to avoid unnecessary message logging */
10944     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
10945     ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
10946     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
10947     ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
10948     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
10949     ok_(__FILE__, line)(ret == caret_index, "expected caret index %d, got %ld\n", caret_index, ret);
10950     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
10951     ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
10952 }
10953
10954 static void test_listbox_messages(void)
10955 {
10956     HWND parent, listbox;
10957     LRESULT ret;
10958
10959     parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW  | WS_VISIBLE,
10960                              100, 100, 200, 200, 0, 0, 0, NULL);
10961     listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
10962                               WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
10963                               10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
10964     listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
10965
10966     check_lb_state(listbox, 0, LB_ERR, 0, 0);
10967
10968     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
10969     ok(ret == 0, "expected 0, got %ld\n", ret);
10970     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
10971     ok(ret == 1, "expected 1, got %ld\n", ret);
10972     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
10973     ok(ret == 2, "expected 2, got %ld\n", ret);
10974
10975     check_lb_state(listbox, 3, LB_ERR, 0, 0);
10976
10977     flush_sequence();
10978
10979     log_all_parent_messages++;
10980
10981     trace("selecting item 0\n");
10982     ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
10983     ok(ret == 0, "expected 0, got %ld\n", ret);
10984     ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
10985     check_lb_state(listbox, 3, 0, 0, 0);
10986     flush_sequence();
10987
10988     trace("selecting item 1\n");
10989     ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
10990     ok(ret == 1, "expected 1, got %ld\n", ret);
10991     ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
10992     check_lb_state(listbox, 3, 1, 1, 0);
10993
10994     trace("selecting item 2\n");
10995     ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
10996     ok(ret == 2, "expected 2, got %ld\n", ret);
10997     ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
10998     check_lb_state(listbox, 3, 2, 2, 0);
10999
11000     trace("clicking on item 0\n");
11001     ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
11002     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11003     ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
11004     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11005     ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
11006     check_lb_state(listbox, 3, 0, 0, 0);
11007     flush_sequence();
11008
11009     log_all_parent_messages--;
11010
11011     DestroyWindow(listbox);
11012     DestroyWindow(parent);
11013 }
11014
11015 /*************************** Menu test ******************************/
11016 static const struct message wm_popup_menu_1[] =
11017 {
11018     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11019     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11020     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
11021     { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
11022     { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
11023     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
11024     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11025     { WM_INITMENU, sent|lparam, 0, 0 },
11026     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
11027     { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
11028     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
11029     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
11030     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
11031     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11032     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11033     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
11034     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11035     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11036     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11037     { WM_MENUCOMMAND, sent }, /* |wparam, 200 - Win9x */
11038     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11039     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11040     { 0 }
11041 };
11042 static const struct message wm_popup_menu_2[] =
11043 {
11044     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11045     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11046     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11047     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11048     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11049     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11050     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11051     { WM_INITMENU, sent|lparam, 0, 0 },
11052     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11053     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11054     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11055     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11056     { HCBT_CREATEWND, hook },
11057     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11058                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11059     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11060     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11061     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11062     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11063     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11064     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11065     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11066     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11067     { HCBT_DESTROYWND, hook },
11068     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11069     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11070     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11071     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11072     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11073     { WM_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
11074     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11075     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11076     { 0 }
11077 };
11078 static const struct message wm_popup_menu_3[] =
11079 {
11080     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11081     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11082     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11083     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11084     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11085     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11086     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11087     { WM_INITMENU, sent|lparam, 0, 0 },
11088     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11089     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11090     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11091     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11092     { HCBT_CREATEWND, hook },
11093     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11094                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11095     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11096     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11097     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11098     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11099     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11100     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11101     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11102     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11103     { HCBT_DESTROYWND, hook },
11104     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11105     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11106     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11107     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11108     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11109     { WM_COMMAND, sent|wparam|lparam, 100, 0 },
11110     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11111     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11112     { 0 }
11113 };
11114
11115 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11116 {
11117     if (message == WM_ENTERIDLE ||
11118         message == WM_INITMENU ||
11119         message == WM_INITMENUPOPUP ||
11120         message == WM_MENUSELECT ||
11121         message == WM_PARENTNOTIFY ||
11122         message == WM_ENTERMENULOOP ||
11123         message == WM_EXITMENULOOP ||
11124         message == WM_UNINITMENUPOPUP ||
11125         message == WM_KEYDOWN ||
11126         message == WM_KEYUP ||
11127         message == WM_CHAR ||
11128         message == WM_SYSKEYDOWN ||
11129         message == WM_SYSKEYUP ||
11130         message == WM_SYSCHAR ||
11131         message == WM_COMMAND ||
11132         message == WM_MENUCOMMAND)
11133     {
11134         struct recvd_message msg;
11135
11136         msg.hwnd = hwnd;
11137         msg.message = message;
11138         msg.flags = sent|wparam|lparam;
11139         msg.wParam = wp;
11140         msg.lParam = lp;
11141         msg.descr = "parent_menu_proc";
11142         add_message(&msg);
11143     }
11144
11145     return DefWindowProcA(hwnd, message, wp, lp);
11146 }
11147
11148 static void set_menu_style(HMENU hmenu, DWORD style)
11149 {
11150     MENUINFO mi;
11151     BOOL ret;
11152
11153     mi.cbSize = sizeof(mi);
11154     mi.fMask = MIM_STYLE;
11155     mi.dwStyle = style;
11156     SetLastError(0xdeadbeef);
11157     ret = pSetMenuInfo(hmenu, &mi);
11158     ok(ret, "SetMenuInfo error %u\n", GetLastError());
11159 }
11160
11161 static DWORD get_menu_style(HMENU hmenu)
11162 {
11163     MENUINFO mi;
11164     BOOL ret;
11165
11166     mi.cbSize = sizeof(mi);
11167     mi.fMask = MIM_STYLE;
11168     mi.dwStyle = 0;
11169     SetLastError(0xdeadbeef);
11170     ret = pGetMenuInfo(hmenu, &mi);
11171     ok(ret, "GetMenuInfo error %u\n", GetLastError());
11172
11173     return mi.dwStyle;
11174 }
11175
11176 static void test_menu_messages(void)
11177 {
11178     MSG msg;
11179     WNDCLASSA cls;
11180     HMENU hmenu, hmenu_popup;
11181     HWND hwnd;
11182     DWORD style;
11183
11184     if (!pGetMenuInfo || !pSetMenuInfo)
11185     {
11186         skip("GetMenuInfo and/or SetMenuInfo are not available\n");
11187         return;
11188     }
11189     cls.style = 0;
11190     cls.lpfnWndProc = parent_menu_proc;
11191     cls.cbClsExtra = 0;
11192     cls.cbWndExtra = 0;
11193     cls.hInstance = GetModuleHandleA(0);
11194     cls.hIcon = 0;
11195     cls.hCursor = LoadCursorA(0, IDC_ARROW);
11196     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
11197     cls.lpszMenuName = NULL;
11198     cls.lpszClassName = "TestMenuClass";
11199     UnregisterClass(cls.lpszClassName, cls.hInstance);
11200     if (!RegisterClassA(&cls)) assert(0);
11201
11202     SetLastError(0xdeadbeef);
11203     hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11204                            100, 100, 200, 200, 0, 0, 0, NULL);
11205     ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
11206
11207     SetLastError(0xdeadbeef);
11208     hmenu = LoadMenuA(GetModuleHandle(0), MAKEINTRESOURCE(1));
11209     ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
11210
11211     SetMenu(hwnd, hmenu);
11212     SetForegroundWindow( hwnd );
11213
11214     set_menu_style(hmenu, MNS_NOTIFYBYPOS);
11215     style = get_menu_style(hmenu);
11216     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11217
11218     hmenu_popup = GetSubMenu(hmenu, 0);
11219     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11220     style = get_menu_style(hmenu_popup);
11221     ok(style == 0, "expected 0, got %u\n", style);
11222
11223     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11224     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11225     style = get_menu_style(hmenu_popup);
11226     ok(style == 0, "expected 0, got %u\n", style);
11227
11228     /* Alt+E, Enter */
11229     trace("testing a popup menu command\n");
11230     flush_sequence();
11231     keybd_event(VK_MENU, 0, 0, 0);
11232     keybd_event('E', 0, 0, 0);
11233     keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
11234     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11235     keybd_event(VK_RETURN, 0, 0, 0);
11236     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11237     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11238     {
11239         TranslateMessage(&msg);
11240         DispatchMessage(&msg);
11241     }
11242     ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
11243
11244     /* Alt+F, Right, Enter */
11245     trace("testing submenu of a popup menu command\n");
11246     flush_sequence();
11247     keybd_event(VK_MENU, 0, 0, 0);
11248     keybd_event('F', 0, 0, 0);
11249     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11250     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11251     keybd_event(VK_RIGHT, 0, 0, 0);
11252     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11253     keybd_event(VK_RETURN, 0, 0, 0);
11254     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11255     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11256     {
11257         TranslateMessage(&msg);
11258         DispatchMessage(&msg);
11259     }
11260     ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
11261
11262     set_menu_style(hmenu, 0);
11263     style = get_menu_style(hmenu);
11264     ok(style == 0, "expected 0, got %u\n", style);
11265
11266     hmenu_popup = GetSubMenu(hmenu, 0);
11267     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11268     set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
11269     style = get_menu_style(hmenu_popup);
11270     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11271
11272     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11273     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11274     style = get_menu_style(hmenu_popup);
11275     ok(style == 0, "expected 0, got %u\n", style);
11276
11277     /* Alt+F, Right, Enter */
11278     trace("testing submenu of a popup menu command\n");
11279     flush_sequence();
11280     keybd_event(VK_MENU, 0, 0, 0);
11281     keybd_event('F', 0, 0, 0);
11282     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11283     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11284     keybd_event(VK_RIGHT, 0, 0, 0);
11285     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11286     keybd_event(VK_RETURN, 0, 0, 0);
11287     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11288     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11289     {
11290         TranslateMessage(&msg);
11291         DispatchMessage(&msg);
11292     }
11293     ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
11294
11295     DestroyWindow(hwnd);
11296     DestroyMenu(hmenu);
11297 }
11298
11299
11300 static void test_paintingloop(void)
11301 {
11302     HWND hwnd;
11303
11304     paint_loop_done = 0;
11305     hwnd = CreateWindowExA(0x0,"PaintLoopWindowClass",
11306                                "PaintLoopWindowClass",WS_OVERLAPPEDWINDOW,
11307                                 100, 100, 100, 100, 0, 0, 0, NULL );
11308     ok(hwnd != 0, "PaintLoop window error %u\n", GetLastError());
11309     ShowWindow(hwnd,SW_NORMAL);
11310     SetFocus(hwnd);
11311
11312     while (!paint_loop_done)
11313     {
11314         MSG msg;
11315         if (PeekMessageA(&msg, 0, 0, 0, 1))
11316         {
11317             TranslateMessage(&msg);
11318             DispatchMessage(&msg);
11319         }
11320     }
11321     DestroyWindow(hwnd);
11322 }
11323
11324 START_TEST(msg)
11325 {
11326     BOOL ret;
11327     FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
11328
11329     init_procs();
11330
11331     if (!RegisterWindowClasses()) assert(0);
11332
11333     if (pSetWinEventHook)
11334     {
11335         hEvent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
11336                                                       GetModuleHandleA(0),
11337                                                       win_event_proc,
11338                                                       0,
11339                                                       GetCurrentThreadId(),
11340                                                       WINEVENT_INCONTEXT);
11341         assert(hEvent_hook);
11342
11343         if (pIsWinEventHookInstalled)
11344         {
11345             UINT event;
11346             for (event = EVENT_MIN; event <= EVENT_MAX; event++)
11347                 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
11348         }
11349     }
11350
11351     cbt_hook_thread_id = GetCurrentThreadId();
11352     hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
11353     if (!hCBT_hook) skip( "cannot set global hook, will skip hook tests\n" );
11354
11355     test_winevents();
11356
11357     /* Fix message sequences before removing 4 lines below */
11358 #if 1
11359     if (pUnhookWinEvent && hEvent_hook)
11360     {
11361         ret = pUnhookWinEvent(hEvent_hook);
11362         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
11363         pUnhookWinEvent = 0;
11364     }
11365     hEvent_hook = 0;
11366 #endif
11367
11368     test_ShowWindow();
11369     test_PeekMessage();
11370     test_PeekMessage2();
11371     test_scrollwindowex();
11372     test_messages();
11373     test_setwindowpos();
11374     test_showwindow();
11375     invisible_parent_tests();
11376     test_mdi_messages();
11377     test_button_messages();
11378     test_static_messages();
11379     test_listbox_messages();
11380     test_combobox_messages();
11381     test_wmime_keydown_message();
11382     test_paint_messages();
11383     test_interthread_messages();
11384     test_message_conversion();
11385     test_accelerators();
11386     test_timers();
11387     test_timers_no_wnd();
11388     if (hCBT_hook) test_set_hook();
11389     test_DestroyWindow();
11390     test_DispatchMessage();
11391     test_SendMessageTimeout();
11392     test_edit_messages();
11393     test_quit_message();
11394     test_SetActiveWindow();
11395
11396     if (!pTrackMouseEvent)
11397         skip("TrackMouseEvent is not available\n");
11398     else
11399         test_TrackMouseEvent();
11400
11401     test_SetWindowRgn();
11402     test_sys_menu();
11403     test_dialog_messages();
11404     test_nullCallback();
11405     test_dbcs_wm_char();
11406     test_menu_messages();
11407     test_paintingloop();
11408     /* keep it the last test, under Windows it tends to break the tests
11409      * which rely on active/foreground windows being correct.
11410      */
11411     test_SetForegroundWindow();
11412
11413     UnhookWindowsHookEx(hCBT_hook);
11414     if (pUnhookWinEvent)
11415     {
11416         ret = pUnhookWinEvent(hEvent_hook);
11417         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
11418         SetLastError(0xdeadbeef);
11419         ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
11420         ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
11421            GetLastError() == 0xdeadbeef, /* Win9x */
11422            "unexpected error %d\n", GetLastError());
11423     }
11424     else
11425         skip("UnhookWinEvent is not available\n");
11426 }