winmm: Fix a failing mixer test on 98 and ME.
[wine] / dlls / user32 / tests / msg.c
1 /*
2  * Unit tests for window message handling
3  *
4  * Copyright 1999 Ove Kaaven
5  * Copyright 2003 Dimitrie O. Paun
6  * Copyright 2004, 2005 Dmitry Timoshkov
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #include <assert.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26
27 #define _WIN32_WINNT 0x0501 /* For WM_CHANGEUISTATE,QS_RAWINPUT */
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winnls.h"
34
35 #include "wine/test.h"
36
37 #define MDI_FIRST_CHILD_ID 2004
38
39 /* undocumented SWP flags - from SDK 3.1 */
40 #define SWP_NOCLIENTSIZE        0x0800
41 #define SWP_NOCLIENTMOVE        0x1000
42 #define SWP_STATECHANGED        0x8000
43
44 #define SW_NORMALNA             0xCC    /* undoc. flag in MinMaximize */
45
46 #ifndef WM_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
82 static void dump_winpos_flags(UINT flags);
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 };
116
117 /* Empty message sequence */
118 static const struct message WmEmptySeq[] =
119 {
120     { 0 }
121 };
122 /* CreateWindow (for overlapped window, not initially visible) (16/32) */
123 static const struct message WmCreateOverlappedSeq[] = {
124     { HCBT_CREATEWND, hook },
125     { WM_GETMINMAXINFO, sent },
126     { WM_NCCREATE, sent },
127     { WM_NCCALCSIZE, sent|wparam, 0 },
128     { 0x0093, sent|defwinproc|optional },
129     { 0x0094, sent|defwinproc|optional },
130     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
131     { WM_CREATE, sent },
132     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
133     { 0 }
134 };
135 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
136  * for a not visible overlapped window.
137  */
138 static const struct message WmSWP_ShowOverlappedSeq[] = {
139     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
140     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
141     { WM_NCPAINT, sent|wparam|optional, 1 },
142     { WM_GETTEXT, sent|defwinproc|optional },
143     { WM_ERASEBKGND, sent|optional },
144     { HCBT_ACTIVATE, hook },
145     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
146     { WM_NOTIFYFORMAT, sent|optional },
147     { WM_QUERYUISTATE, sent|optional },
148     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
149     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x: SWP_NOSENDCHANGING */
150     { WM_ACTIVATEAPP, sent|wparam, 1 },
151     { WM_NCACTIVATE, sent|wparam, 1 },
152     { WM_GETTEXT, sent|defwinproc|optional },
153     { WM_ACTIVATE, sent|wparam, 1 },
154     { HCBT_SETFOCUS, hook },
155     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
156     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
157     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
158     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
159     { WM_GETTEXT, sent|optional },
160     { WM_NCPAINT, sent|wparam|optional, 1 },
161     { WM_GETTEXT, sent|defwinproc|optional },
162     { WM_ERASEBKGND, sent|optional },
163     /* Win9x adds SWP_NOZORDER below */
164     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
165     { WM_GETTEXT, sent|optional },
166     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
167     { WM_NCPAINT, sent|wparam|optional, 1 },
168     { WM_ERASEBKGND, sent|optional },
169     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
170     { WM_PAINT, sent|optional },
171     { WM_NCPAINT, sent|beginpaint|optional },
172     { WM_ERASEBKGND, sent|beginpaint|optional },
173     { 0 }
174 };
175 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
176  * for a visible overlapped window.
177  */
178 static const struct message WmSWP_HideOverlappedSeq[] = {
179     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
180     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
181     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
182     { 0 }
183 };
184
185 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
186  * for a visible overlapped window.
187  */
188 static const struct message WmSWP_ResizeSeq[] = {
189     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
190     { WM_GETMINMAXINFO, sent|defwinproc },
191     { WM_NCCALCSIZE, sent|wparam, TRUE },
192     { WM_NCPAINT, sent|optional },
193     { WM_GETTEXT, sent|defwinproc|optional },
194     { WM_ERASEBKGND, sent|optional },
195     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
196     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
197     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
198     { WM_NCPAINT, sent|optional },
199     { WM_GETTEXT, sent|defwinproc|optional },
200     { WM_ERASEBKGND, sent|optional },
201     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
202     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
203     { 0 }
204 };
205
206 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
207  * for a visible popup window.
208  */
209 static const struct message WmSWP_ResizePopupSeq[] = {
210     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
211     { WM_GETMINMAXINFO, sent|defwinproc|optional }, /* Win9x */
212     { WM_NCCALCSIZE, sent|wparam, TRUE },
213     { WM_NCPAINT, sent|optional },
214     { WM_GETTEXT, sent|defwinproc|optional },
215     { WM_ERASEBKGND, sent|optional },
216     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
217     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
218     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
219     { WM_NCPAINT, sent|optional },
220     { WM_GETTEXT, sent|defwinproc|optional },
221     { WM_ERASEBKGND, sent|optional },
222     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
223     { 0 }
224 };
225
226 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
227  * for a visible overlapped window.
228  */
229 static const struct message WmSWP_MoveSeq[] = {
230     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE },
231     { WM_NCPAINT, sent|optional },
232     { WM_GETTEXT, sent|defwinproc|optional },
233     { WM_ERASEBKGND, sent|optional },
234     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
235     { WM_MOVE, sent|defwinproc|wparam, 0 },
236     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
237     { 0 }
238 };
239 /* Resize with SetWindowPos(SWP_NOZORDER)
240  * for a visible overlapped window
241  * SWP_NOZORDER is stripped by the logging code
242  */
243 static const struct message WmSWP_ResizeNoZOrder[] = {
244     { WM_WINDOWPOSCHANGING, sent|wparam, /*SWP_NOZORDER|*/SWP_NOACTIVATE },
245     { WM_GETMINMAXINFO, sent|defwinproc },
246     { WM_NCCALCSIZE, sent|wparam, 1 },
247     { WM_NCPAINT, sent },
248     { WM_GETTEXT, sent|defwinproc|optional },
249     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
250     { WM_WINDOWPOSCHANGED, sent|wparam, /*SWP_NOZORDER|*/SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE },
251     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
252     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
253     { WM_NCPAINT, sent|optional }, /* Win9x doesn't send it */
254     { WM_GETTEXT, sent|defwinproc|optional }, /* Win9x doesn't send it */
255     { WM_ERASEBKGND, sent|optional }, /* Win9x doesn't send it */
256     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
257     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
258     { 0 }
259 };
260
261 /* Switch visible mdi children */
262 static const struct message WmSwitchChild[] = {
263     /* Switch MDI child */
264     { WM_MDIACTIVATE, sent },/* in the MDI client */
265     { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 1st MDI child */
266     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
267     { WM_CHILDACTIVATE, sent },/* in the 1st MDI child */
268     /* Deactivate 2nd MDI child */
269     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
270     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
271     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
272     /* Preparing for maximize and maximaze the 1st MDI child */
273     { WM_GETMINMAXINFO, sent|defwinproc }, /* in the 1st MDI child */
274     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED }, /* in the 1st MDI child */
275     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
276     { WM_CHILDACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
277     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 1st MDI child */
278     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED }, /* in the 1st MDI child */
279     /* Lock redraw 2nd MDI child */
280     { WM_SETREDRAW, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
281     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
282     /* Restore 2nd MDI child */
283     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },/* in the 2nd MDI child */
284     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
285     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
286     { 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 */
287     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED }, /* in the 2nd MDI child */
288     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
289     /* Redraw 2nd MDI child */
290     { WM_SETREDRAW, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
291     /* Redraw MDI frame */
292     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },/* in MDI frame */
293     { WM_NCCALCSIZE, sent|wparam, 1 },/* in MDI frame */
294     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in MDI frame */
295     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in MDI frame */
296     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
297     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
298     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
299     { HCBT_SETFOCUS, hook },
300     { WM_KILLFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
301     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },/* in the 1st MDI child */
302     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
303     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
304     { WM_SETFOCUS, sent },/* in the MDI client */
305     { HCBT_SETFOCUS, hook },
306     { WM_KILLFOCUS, sent },/* in the MDI client */
307     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
308     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 }, /* in the 1st MDI child */
309     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
310     { WM_SETFOCUS, sent|defwinproc }, /* in the 1st MDI child */
311     { WM_MDIACTIVATE, sent|defwinproc },/* in the 1st MDI child */
312     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* in the 1st MDI child */
313     { 0 }
314 };
315
316 /* Switch visible not maximized mdi children */
317 static const struct message WmSwitchNotMaximizedChild[] = {
318     /* Switch not maximized MDI child */
319     { WM_MDIACTIVATE, sent },/* in the MDI client */
320     { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 2nd MDI child */
321     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
322     { WM_CHILDACTIVATE, sent },/* in the 2nd MDI child */
323     /* Deactivate 1st MDI child */
324     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
325     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
326     /* Activate 2nd MDI child */
327     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE}, /* in the 2nd MDI child */
328     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 2nd MDI child */
329     { HCBT_SETFOCUS, hook }, /* in the 1st MDI child */
330     { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
331     { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
332     { WM_IME_SETCONTEXT, sent|optional }, /* in the  MDI client */
333     { WM_SETFOCUS, sent, 0 }, /* in the  MDI client */
334     { HCBT_SETFOCUS, hook },
335     { WM_KILLFOCUS, sent }, /* in the  MDI client */
336     { WM_IME_SETCONTEXT, sent|optional }, /* in the  MDI client */
337     { WM_IME_SETCONTEXT, sent|defwinproc|optional  }, /* in the 1st MDI child */
338     { WM_SETFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
339     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
340     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in the 2nd MDI child */
341     { 0 }
342 };
343
344
345 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
346                 SWP_NOZORDER|SWP_FRAMECHANGED)
347  * for a visible overlapped window with WS_CLIPCHILDREN style set.
348  */
349 static const struct message WmSWP_FrameChanged_clip[] = {
350     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
351     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
352     { WM_NCPAINT, sent|parent }, /* wparam != 1 */
353     { WM_GETTEXT, sent|parent|defwinproc|optional },
354     { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
355     { WM_NCPAINT, sent }, /* wparam != 1 */
356     { WM_ERASEBKGND, sent },
357     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
358     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
359     { WM_PAINT, sent },
360     { 0 }
361 };
362 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|
363                 SWP_NOZORDER|SWP_FRAMECHANGED)
364  * for a visible overlapped window.
365  */
366 static const struct message WmSWP_FrameChangedDeferErase[] = {
367     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
368     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
369     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
370     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
371     { WM_PAINT, sent|parent },
372     { WM_NCPAINT, sent|beginpaint|parent }, /* wparam != 1 */
373     { WM_GETTEXT, sent|beginpaint|parent|defwinproc|optional },
374     { WM_PAINT, sent },
375     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
376     { WM_ERASEBKGND, sent|beginpaint },
377     { 0 }
378 };
379
380 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
381                 SWP_NOZORDER|SWP_FRAMECHANGED)
382  * for a visible overlapped window without WS_CLIPCHILDREN style set.
383  */
384 static const struct message WmSWP_FrameChanged_noclip[] = {
385     { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
386     { WM_NCCALCSIZE, sent|wparam|parent, 1 },
387     { WM_NCPAINT, sent|parent }, /* wparam != 1 */
388     { WM_GETTEXT, sent|parent|defwinproc|optional },
389     { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
390     { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
391     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
392     { WM_PAINT, sent },
393     { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
394     { WM_ERASEBKGND, sent|beginpaint },
395     { 0 }
396 };
397
398 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
399 static const struct message WmShowOverlappedSeq[] = {
400     { WM_SHOWWINDOW, sent|wparam, 1 },
401     { WM_NCPAINT, sent|wparam|optional, 1 },
402     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
403     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
404     { WM_NCPAINT, sent|wparam|optional, 1 },
405     { WM_GETTEXT, sent|defwinproc|optional },
406     { WM_ERASEBKGND, sent|optional },
407     { HCBT_ACTIVATE, hook },
408     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
409     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
410     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
411     { WM_NCPAINT, sent|wparam|optional, 1 },
412     { WM_ACTIVATEAPP, sent|wparam, 1 },
413     { WM_NCACTIVATE, sent|wparam, 1 },
414     { WM_GETTEXT, sent|defwinproc|optional },
415     { WM_ACTIVATE, sent|wparam, 1 },
416     { HCBT_SETFOCUS, hook },
417     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
418     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
419     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
420     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
421     { WM_GETTEXT, sent|optional },
422     { WM_NCPAINT, sent|wparam|optional, 1 },
423     { WM_GETTEXT, sent|defwinproc|optional },
424     { WM_ERASEBKGND, sent|optional },
425     /* Win9x adds SWP_NOZORDER below */
426     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
427     { WM_NCCALCSIZE, sent|optional },
428     { WM_GETTEXT, sent|optional },
429     { WM_NCPAINT, sent|optional },
430     { WM_ERASEBKGND, sent|optional },
431 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
432        * messages. Does that mean that CreateWindow doesn't set initial
433        * window dimensions for overlapped windows?
434        */
435     { WM_SIZE, sent },
436     { WM_MOVE, sent },
437 #endif
438     { WM_PAINT, sent|optional },
439     { WM_NCPAINT, sent|beginpaint|optional },
440     { 0 }
441 };
442 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible overlapped window */
443 static const struct message WmShowMaxOverlappedSeq[] = {
444     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
445     { WM_GETMINMAXINFO, sent },
446     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
447     { WM_GETMINMAXINFO, sent|defwinproc },
448     { WM_NCCALCSIZE, sent|wparam, TRUE },
449     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
450     { HCBT_ACTIVATE, hook },
451     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
452     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
453     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
454     { WM_ACTIVATEAPP, sent|wparam, 1 },
455     { WM_NCACTIVATE, sent|wparam, 1 },
456     { WM_GETTEXT, sent|defwinproc|optional },
457     { WM_ACTIVATE, sent|wparam, 1 },
458     { HCBT_SETFOCUS, hook },
459     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
460     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
461     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
462     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
463     { WM_GETTEXT, sent|optional },
464     { WM_NCPAINT, sent|wparam|optional, 1 },
465     { WM_GETTEXT, sent|defwinproc|optional },
466     { WM_ERASEBKGND, sent|optional },
467     /* Win9x adds SWP_NOZORDER below */
468     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
469     { WM_MOVE, sent|defwinproc },
470     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
471     { WM_GETTEXT, sent|optional },
472     { WM_NCCALCSIZE, sent|optional },
473     { WM_NCPAINT, sent|optional },
474     { WM_ERASEBKGND, sent|optional },
475     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
476     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
477     { WM_PAINT, sent|optional },
478     { WM_NCPAINT, sent|beginpaint|optional },
479     { WM_ERASEBKGND, sent|beginpaint|optional },
480     { 0 }
481 };
482 /* ShowWindow(SW_RESTORE) for a not visible maximized overlapped window */
483 static const struct message WmShowRestoreMaxOverlappedSeq[] = {
484     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
485     { WM_GETTEXT, sent|optional },
486     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
487     { WM_GETMINMAXINFO, sent|defwinproc },
488     { WM_NCCALCSIZE, sent|wparam, TRUE },
489     { WM_NCPAINT, sent|optional },
490     { WM_GETTEXT, sent|defwinproc|optional },
491     { WM_ERASEBKGND, sent|optional },
492     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
493     { WM_MOVE, sent|defwinproc|optional },
494     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
495     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
496     { WM_NCPAINT, sent|optional },
497     { WM_ERASEBKGND, sent|optional },
498     { WM_PAINT, sent|optional },
499     { WM_NCPAINT, sent|beginpaint|optional },
500     { WM_ERASEBKGND, sent|beginpaint|optional },
501     { 0 }
502 };
503 /* ShowWindow(SW_RESTORE) for a not visible minimized overlapped window */
504 static const struct message WmShowRestoreMinOverlappedSeq[] = {
505     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
506     { WM_QUERYOPEN, sent|optional },
507     { WM_GETTEXT, sent|optional },
508     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED|SWP_NOCOPYBITS },
509     { WM_GETMINMAXINFO, sent|defwinproc },
510     { WM_NCCALCSIZE, sent|wparam, TRUE },
511     { HCBT_ACTIVATE, hook },
512     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
513     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
514     { WM_ACTIVATEAPP, sent|wparam, 1 },
515     { WM_NCACTIVATE, sent|wparam, 1 },
516     { WM_GETTEXT, sent|defwinproc|optional },
517     { WM_ACTIVATE, sent|wparam, 1 },
518     { HCBT_SETFOCUS, hook },
519     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
520     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
521     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
522     { WM_GETTEXT, sent|optional },
523     { WM_NCPAINT, sent|wparam|optional, 1 },
524     { WM_GETTEXT, sent|defwinproc|optional },
525     { WM_ERASEBKGND, sent },
526     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_STATECHANGED|SWP_FRAMECHANGED|SWP_NOCOPYBITS },
527     { WM_MOVE, sent|defwinproc },
528     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
529     { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
530     { WM_NCPAINT, sent|wparam|optional, 1 },
531     { WM_ERASEBKGND, sent|optional },
532     { WM_ACTIVATE, sent|wparam, 1 },
533     { WM_GETTEXT, sent|optional },
534     { WM_PAINT, sent|optional },
535     { WM_NCPAINT, sent|beginpaint|optional },
536     { WM_ERASEBKGND, sent|beginpaint|optional },
537     { 0 }
538 };
539 /* ShowWindow(SW_SHOWMINIMIZED) for a not visible overlapped window */
540 static const struct message WmShowMinOverlappedSeq[] = {
541     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
542     { HCBT_SETFOCUS, hook },
543     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
544     { WM_KILLFOCUS, sent },
545     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
546     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
547     { WM_GETTEXT, sent|optional },
548     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCOPYBITS|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
549     { WM_GETMINMAXINFO, sent|defwinproc },
550     { WM_NCCALCSIZE, sent|wparam, TRUE },
551     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
552     { WM_NCPAINT, sent|optional },
553     { WM_GETTEXT, sent|defwinproc|optional },
554     { WM_WINDOWPOSCHANGED, sent },
555     { WM_MOVE, sent|defwinproc },
556     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
557     { WM_NCCALCSIZE, sent|optional },
558     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
559     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
560     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
561     { WM_NCACTIVATE, sent|wparam, 0 },
562     { WM_GETTEXT, sent|defwinproc|optional },
563     { WM_ACTIVATE, sent },
564     { WM_ACTIVATEAPP, sent|wparam, 0 },
565     { WM_PAINT, sent|optional },
566     { WM_NCPAINT, sent|beginpaint|optional },
567     { WM_ERASEBKGND, sent|beginpaint|optional },
568     { 0 }
569 };
570 /* ShowWindow(SW_HIDE) for a visible overlapped window */
571 static const struct message WmHideOverlappedSeq[] = {
572     { WM_SHOWWINDOW, sent|wparam, 0 },
573     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
574     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
575     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
576     { WM_SIZE, sent|optional }, /* XP doesn't send it */
577     { WM_MOVE, sent|optional }, /* XP doesn't send it */
578     { WM_NCACTIVATE, sent|wparam, 0 },
579     { WM_ACTIVATE, sent|wparam, 0 },
580     { WM_ACTIVATEAPP, sent|wparam, 0 },
581     { WM_KILLFOCUS, sent|wparam, 0 },
582     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
583     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
584     { 0 }
585 };
586 /* DestroyWindow for a visible overlapped window */
587 static const struct message WmDestroyOverlappedSeq[] = {
588     { HCBT_DESTROYWND, hook },
589     { 0x0090, sent|optional },
590     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
591     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
592     { 0x0090, sent|optional },
593     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
594     { WM_NCACTIVATE, sent|optional|wparam, 0 },
595     { WM_ACTIVATE, sent|optional|wparam, 0 },
596     { WM_ACTIVATEAPP, sent|optional|wparam, 0 },
597     { WM_KILLFOCUS, sent|optional|wparam, 0 },
598     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
599     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
600     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
601     { WM_DESTROY, sent },
602     { WM_NCDESTROY, sent },
603     { 0 }
604 };
605 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
606 static const struct message WmCreateMaxPopupSeq[] = {
607     { HCBT_CREATEWND, hook },
608     { WM_NCCREATE, sent },
609     { WM_NCCALCSIZE, sent|wparam, 0 },
610     { WM_CREATE, sent },
611     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
612     { WM_SIZE, sent|wparam, SIZE_RESTORED },
613     { WM_MOVE, sent },
614     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
615     { WM_GETMINMAXINFO, sent },
616     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
617     { WM_NCCALCSIZE, sent|wparam, TRUE },
618     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
619     { WM_MOVE, sent|defwinproc },
620     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
621     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
622     { WM_SHOWWINDOW, sent|wparam, 1 },
623     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
624     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
625     { HCBT_ACTIVATE, hook },
626     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
627     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
628     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
629     { WM_ACTIVATEAPP, sent|wparam, 1 },
630     { WM_NCACTIVATE, sent|wparam, 1 },
631     { WM_ACTIVATE, sent|wparam, 1 },
632     { HCBT_SETFOCUS, hook },
633     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
634     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
635     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
636     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
637     { WM_GETTEXT, sent|optional },
638     { WM_SYNCPAINT, sent|wparam|optional, 4 },
639     { WM_NCPAINT, sent|wparam|optional, 1 },
640     { WM_ERASEBKGND, sent|optional },
641     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
642     { 0 }
643 };
644 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
645 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
646     { HCBT_CREATEWND, hook },
647     { WM_NCCREATE, sent },
648     { WM_NCCALCSIZE, sent|wparam, 0 },
649     { WM_CREATE, sent },
650     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
651     { WM_SIZE, sent|wparam, SIZE_RESTORED },
652     { WM_MOVE, sent },
653     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
654     { WM_GETMINMAXINFO, sent },
655     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED  },
656     { WM_NCCALCSIZE, sent|wparam, TRUE },
657     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
658     { WM_MOVE, sent|defwinproc },
659     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
660     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
661     { 0 }
662 };
663 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
664 static const struct message WmShowMaxPopupResizedSeq[] = {
665     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
666     { WM_GETMINMAXINFO, sent },
667     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
668     { WM_NCCALCSIZE, sent|wparam, TRUE },
669     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
670     { HCBT_ACTIVATE, hook },
671     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
672     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
673     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
674     { WM_ACTIVATEAPP, sent|wparam, 1 },
675     { WM_NCACTIVATE, sent|wparam, 1 },
676     { WM_ACTIVATE, sent|wparam, 1 },
677     { HCBT_SETFOCUS, hook },
678     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
679     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
680     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
681     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
682     { WM_GETTEXT, sent|optional },
683     { WM_NCPAINT, sent|wparam|optional, 1 },
684     { WM_ERASEBKGND, sent|optional },
685     { WM_WINDOWPOSCHANGED, sent },
686     /* WinNT4.0 sends WM_MOVE */
687     { WM_MOVE, sent|defwinproc|optional },
688     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
689     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
690     { 0 }
691 };
692 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
693 static const struct message WmShowMaxPopupSeq[] = {
694     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
695     { WM_GETMINMAXINFO, sent },
696     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
697     { WM_NCCALCSIZE, sent|wparam, TRUE },
698     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
699     { HCBT_ACTIVATE, hook },
700     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
701     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
702     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
703     { WM_ACTIVATEAPP, sent|wparam, 1 },
704     { WM_NCACTIVATE, sent|wparam, 1 },
705     { WM_ACTIVATE, sent|wparam, 1 },
706     { HCBT_SETFOCUS, hook },
707     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
708     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
709     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
710     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
711     { WM_GETTEXT, sent|optional },
712     { WM_SYNCPAINT, sent|wparam|optional, 4 },
713     { WM_NCPAINT, sent|wparam|optional, 1 },
714     { WM_ERASEBKGND, sent|optional },
715     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
716     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
717     { 0 }
718 };
719 /* CreateWindow(WS_VISIBLE) for popup window */
720 static const struct message WmCreatePopupSeq[] = {
721     { HCBT_CREATEWND, hook },
722     { WM_NCCREATE, sent },
723     { WM_NCCALCSIZE, sent|wparam, 0 },
724     { WM_CREATE, sent },
725     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
726     { WM_SIZE, sent|wparam, SIZE_RESTORED },
727     { WM_MOVE, sent },
728     { WM_SHOWWINDOW, sent|wparam, 1 },
729     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
730     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
731     { HCBT_ACTIVATE, hook },
732     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
733     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
734     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
735     { WM_NCPAINT, sent|wparam|optional, 1 },
736     { WM_ERASEBKGND, sent|optional },
737     { WM_ACTIVATEAPP, sent|wparam, 1 },
738     { WM_NCACTIVATE, sent|wparam, 1 },
739     { WM_ACTIVATE, sent|wparam, 1 },
740     { HCBT_SETFOCUS, hook },
741     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
742     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
743     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
744     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
745     { WM_GETTEXT, sent|optional },
746     { WM_SYNCPAINT, sent|wparam|optional, 4 },
747     { WM_NCPAINT, sent|wparam|optional, 1 },
748     { WM_ERASEBKGND, sent|optional },
749     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
750     { 0 }
751 };
752 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
753 static const struct message WmShowVisMaxPopupSeq[] = {
754     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
755     { WM_GETMINMAXINFO, sent },
756     { WM_GETTEXT, sent|optional },
757     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
758     { WM_GETTEXT, sent|optional },
759     { WM_NCCALCSIZE, sent|wparam, TRUE },
760     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
761     { WM_NCPAINT, sent|wparam|optional, 1 },
762     { WM_ERASEBKGND, sent|optional },
763     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
764     { WM_MOVE, sent|defwinproc },
765     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
766     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
767     { 0 }
768 };
769 /* CreateWindow (for a child popup window, not initially visible) */
770 static const struct message WmCreateChildPopupSeq[] = {
771     { HCBT_CREATEWND, hook },
772     { WM_NCCREATE, sent }, 
773     { WM_NCCALCSIZE, sent|wparam, 0 },
774     { WM_CREATE, sent },
775     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
776     { WM_SIZE, sent|wparam, SIZE_RESTORED },
777     { WM_MOVE, sent },
778     { 0 }
779 };
780 /* CreateWindow (for a popup window, not initially visible,
781  * which sets WS_VISIBLE in WM_CREATE handler)
782  */
783 static const struct message WmCreateInvisiblePopupSeq[] = {
784     { HCBT_CREATEWND, hook },
785     { WM_NCCREATE, sent }, 
786     { WM_NCCALCSIZE, sent|wparam, 0 },
787     { WM_CREATE, sent },
788     { WM_STYLECHANGING, sent },
789     { WM_STYLECHANGED, sent },
790     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
791     { WM_SIZE, sent|wparam, SIZE_RESTORED },
792     { WM_MOVE, sent },
793     { 0 }
794 };
795 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
796  * for a popup window with WS_VISIBLE style set
797  */
798 static const struct message WmShowVisiblePopupSeq_2[] = {
799     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
800     { 0 }
801 };
802 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
803  * for a popup window with WS_VISIBLE style set
804  */
805 static const struct message WmShowVisiblePopupSeq_3[] = {
806     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
807     { HCBT_ACTIVATE, hook },
808     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
809     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
810     { WM_WINDOWPOSCHANGING, sent|wparam|optional, 0 },
811     { WM_NCACTIVATE, sent|wparam, 1 },
812     { WM_ACTIVATE, sent|wparam, 1 },
813     { HCBT_SETFOCUS, hook },
814     { WM_KILLFOCUS, sent|parent },
815     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
816     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
817     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
818     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
819     { WM_SETFOCUS, sent|defwinproc },
820     { WM_GETTEXT, sent|optional },
821     { 0 }
822 };
823 /* CreateWindow (for child window, not initially visible) */
824 static const struct message WmCreateChildSeq[] = {
825     { HCBT_CREATEWND, hook },
826     { WM_NCCREATE, sent }, 
827     /* child is inserted into parent's child list after WM_NCCREATE returns */
828     { WM_NCCALCSIZE, sent|wparam, 0 },
829     { WM_CREATE, sent },
830     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
831     { WM_SIZE, sent|wparam, SIZE_RESTORED },
832     { WM_MOVE, sent },
833     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
834     { 0 }
835 };
836 /* CreateWindow (for maximized child window, not initially visible) */
837 static const struct message WmCreateMaximizedChildSeq[] = {
838     { HCBT_CREATEWND, hook },
839     { WM_NCCREATE, sent }, 
840     { WM_NCCALCSIZE, sent|wparam, 0 },
841     { WM_CREATE, sent },
842     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
843     { WM_SIZE, sent|wparam, SIZE_RESTORED },
844     { WM_MOVE, sent },
845     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
846     { WM_GETMINMAXINFO, sent },
847     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
848     { WM_NCCALCSIZE, sent|wparam, 1 },
849     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
850     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
851     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
852     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
853     { 0 }
854 };
855 /* CreateWindow (for a child window, initially visible) */
856 static const struct message WmCreateVisibleChildSeq[] = {
857     { HCBT_CREATEWND, hook },
858     { WM_NCCREATE, sent }, 
859     /* child is inserted into parent's child list after WM_NCCREATE returns */
860     { WM_NCCALCSIZE, sent|wparam, 0 },
861     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
862     { WM_CREATE, sent },
863     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
864     { WM_SIZE, sent|wparam, SIZE_RESTORED },
865     { WM_MOVE, sent },
866     { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
867     { WM_SHOWWINDOW, sent|wparam, 1 },
868     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
869     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
870     { WM_ERASEBKGND, sent|parent|optional },
871     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
872     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
873     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
874     { 0 }
875 };
876 /* ShowWindow(SW_SHOW) for a not visible child window */
877 static const struct message WmShowChildSeq[] = {
878     { WM_SHOWWINDOW, sent|wparam, 1 },
879     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
880     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
881     { WM_ERASEBKGND, sent|parent|optional },
882     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
883     { 0 }
884 };
885 /* ShowWindow(SW_HIDE) for a visible child window */
886 static const struct message WmHideChildSeq[] = {
887     { WM_SHOWWINDOW, sent|wparam, 0 },
888     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
889     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
890     { WM_ERASEBKGND, sent|parent|optional },
891     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
892     { 0 }
893 };
894 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
895 static const struct message WmHideChildSeq2[] = {
896     { WM_SHOWWINDOW, sent|wparam, 0 },
897     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
898     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
899     { WM_ERASEBKGND, sent|parent },
900     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
901     { 0 }
902 };
903 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
904  * for a not visible child window
905  */
906 static const struct message WmShowChildSeq_2[] = {
907     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
908     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
909     { WM_CHILDACTIVATE, sent },
910     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
911     { 0 }
912 };
913 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
914  * for a not visible child window
915  */
916 static const struct message WmShowChildSeq_3[] = {
917     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
918     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
919     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
920     { 0 }
921 };
922 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
923  * for a visible child window with a caption
924  */
925 static const struct message WmShowChildSeq_4[] = {
926     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
927     { WM_CHILDACTIVATE, sent },
928     { 0 }
929 };
930 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
931 static const struct message WmShowChildInvisibleParentSeq_1[] = {
932     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
933     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
934     { WM_NCCALCSIZE, sent|wparam, 1 },
935     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
936     { WM_CHILDACTIVATE, sent|optional },
937     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
938     { WM_MOVE, sent|defwinproc },
939     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
940     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
941     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
942     /* FIXME: Wine creates an icon/title window while Windows doesn't */
943     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
944     { WM_GETTEXT, sent|optional },
945     { 0 }
946 };
947 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
948 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
949     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
950     { 0 }
951 };
952 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
953 static const struct message WmShowChildInvisibleParentSeq_2[] = {
954     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
955     { WM_GETMINMAXINFO, sent },
956     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
957     { WM_NCCALCSIZE, sent|wparam, 1 },
958     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
959     { WM_CHILDACTIVATE, sent },
960     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
961     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
962     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
963     { 0 }
964 };
965 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
966 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
967     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
968     { 0 }
969 };
970 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
971 static const struct message WmShowChildInvisibleParentSeq_3[] = {
972     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
973     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
974     { WM_NCCALCSIZE, sent|wparam, 1 },
975     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
976     { WM_CHILDACTIVATE, sent },
977     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
978     { WM_MOVE, sent|defwinproc },
979     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
980     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
981     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
982     /* FIXME: Wine creates an icon/title window while Windows doesn't */
983     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
984     { WM_GETTEXT, sent|optional },
985     { 0 }
986 };
987 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
988 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
989     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
990     { 0 }
991 };
992 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
993 static const struct message WmShowChildInvisibleParentSeq_4[] = {
994     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
995     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
996     { WM_NCCALCSIZE, sent|wparam, 1 },
997     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
998     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
999     { WM_MOVE, sent|defwinproc },
1000     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
1001     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1002     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1003     /* FIXME: Wine creates an icon/title window while Windows doesn't */
1004     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1005     { WM_GETTEXT, sent|optional },
1006     { 0 }
1007 };
1008 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1009 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
1010     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1011     { 0 }
1012 };
1013 /* ShowWindow(SW_SHOW) for child with invisible parent */
1014 static const struct message WmShowChildInvisibleParentSeq_5[] = {
1015     { WM_SHOWWINDOW, sent|wparam, 1 },
1016     { 0 }
1017 };
1018 /* ShowWindow(SW_HIDE) for child with invisible parent */
1019 static const struct message WmHideChildInvisibleParentSeq[] = {
1020     { WM_SHOWWINDOW, sent|wparam, 0 },
1021     { 0 }
1022 };
1023 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
1024 static const struct message WmShowChildInvisibleParentSeq_6[] = {
1025     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1026     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1027     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1028     { 0 }
1029 };
1030 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
1031 static const struct message WmHideChildInvisibleParentSeq_2[] = {
1032     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1033     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1034     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1035     { 0 }
1036 };
1037 /* DestroyWindow for a visible child window */
1038 static const struct message WmDestroyChildSeq[] = {
1039     { HCBT_DESTROYWND, hook },
1040     { 0x0090, sent|optional },
1041     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1042     { WM_SHOWWINDOW, sent|wparam, 0 },
1043     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1044     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1045     { WM_ERASEBKGND, sent|parent|optional },
1046     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1047     { HCBT_SETFOCUS, hook }, /* set focus to a parent */
1048     { WM_KILLFOCUS, sent },
1049     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1050     { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
1051     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1052     { WM_SETFOCUS, sent|parent },
1053     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1054     { WM_DESTROY, sent },
1055     { WM_DESTROY, sent|optional }, /* some other (IME?) window */
1056     { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
1057     { WM_NCDESTROY, sent },
1058     { 0 }
1059 };
1060 /* DestroyWindow for a visible child window with invisible parent */
1061 static const struct message WmDestroyInvisibleChildSeq[] = {
1062     { HCBT_DESTROYWND, hook },
1063     { 0x0090, sent|optional },
1064     { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1065     { WM_SHOWWINDOW, sent|wparam, 0 },
1066     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1067     { WM_DESTROY, sent },
1068     { WM_NCDESTROY, sent },
1069     { 0 }
1070 };
1071 /* Moving the mouse in nonclient area */
1072 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
1073     { WM_NCHITTEST, sent },
1074     { WM_SETCURSOR, sent },
1075     { WM_NCMOUSEMOVE, posted },
1076     { 0 }
1077 };
1078 /* Moving the mouse in client area */
1079 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
1080     { WM_NCHITTEST, sent },
1081     { WM_SETCURSOR, sent },
1082     { WM_MOUSEMOVE, posted },
1083     { 0 }
1084 };
1085 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1086 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
1087     { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
1088     { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
1089     { WM_GETMINMAXINFO, sent|defwinproc },
1090     { WM_ENTERSIZEMOVE, sent|defwinproc },
1091     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1092     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1093     { WM_MOVE, sent|defwinproc },
1094     { WM_EXITSIZEMOVE, sent|defwinproc },
1095     { 0 }
1096 };
1097 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1098 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
1099     { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
1100     { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
1101     { WM_GETMINMAXINFO, sent|defwinproc },
1102     { WM_ENTERSIZEMOVE, sent|defwinproc },
1103     { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
1104     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1105     { WM_GETMINMAXINFO, sent|defwinproc },
1106     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1107     { WM_NCPAINT, sent|defwinproc|wparam, 1 },
1108     { WM_GETTEXT, sent|defwinproc },
1109     { WM_ERASEBKGND, sent|defwinproc },
1110     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1111     { WM_MOVE, sent|defwinproc },
1112     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1113     { WM_EXITSIZEMOVE, sent|defwinproc },
1114     { 0 }
1115 };
1116 /* Resizing child window with MoveWindow (32) */
1117 static const struct message WmResizingChildWithMoveWindowSeq[] = {
1118     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1119     { WM_NCCALCSIZE, sent|wparam, 1 },
1120     { WM_ERASEBKGND, sent|parent|optional },
1121     { WM_ERASEBKGND, sent|optional },
1122     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
1123     { WM_MOVE, sent|defwinproc },
1124     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1125     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1126     { 0 }
1127 };
1128 /* Clicking on inactive button */
1129 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
1130     { WM_NCHITTEST, sent },
1131     { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
1132     { WM_MOUSEACTIVATE, sent },
1133     { WM_MOUSEACTIVATE, sent|parent|defwinproc },
1134     { WM_SETCURSOR, sent },
1135     { WM_SETCURSOR, sent|parent|defwinproc },
1136     { WM_LBUTTONDOWN, posted },
1137     { WM_KILLFOCUS, posted|parent },
1138     { WM_SETFOCUS, posted },
1139     { WM_CTLCOLORBTN, posted|parent },
1140     { BM_SETSTATE, posted },
1141     { WM_CTLCOLORBTN, posted|parent },
1142     { WM_LBUTTONUP, posted },
1143     { BM_SETSTATE, posted },
1144     { WM_CTLCOLORBTN, posted|parent },
1145     { WM_COMMAND, posted|parent },
1146     { 0 }
1147 };
1148 /* Reparenting a button (16/32) */
1149 /* The last child (button) reparented gets topmost for its new parent. */
1150 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
1151     { WM_SHOWWINDOW, sent|wparam, 0 },
1152     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1153     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1154     { WM_ERASEBKGND, sent|parent },
1155     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1156     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
1157     { WM_CHILDACTIVATE, sent },
1158     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
1159     { WM_MOVE, sent|defwinproc },
1160     { WM_SHOWWINDOW, sent|wparam, 1 },
1161     { 0 }
1162 };
1163 /* Creation of a custom dialog (32) */
1164 static const struct message WmCreateCustomDialogSeq[] = {
1165     { HCBT_CREATEWND, hook },
1166     { WM_GETMINMAXINFO, sent },
1167     { WM_NCCREATE, sent },
1168     { WM_NCCALCSIZE, sent|wparam, 0 },
1169     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1170     { WM_CREATE, sent },
1171     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1172     { WM_NOTIFYFORMAT, sent|optional },
1173     { WM_QUERYUISTATE, sent|optional },
1174     { WM_WINDOWPOSCHANGING, sent|optional },
1175     { WM_GETMINMAXINFO, sent|optional },
1176     { WM_NCCALCSIZE, sent|optional },
1177     { WM_WINDOWPOSCHANGED, sent|optional },
1178     { WM_SHOWWINDOW, sent|wparam, 1 },
1179     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1180     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1181     { HCBT_ACTIVATE, hook },
1182     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1183
1184
1185     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1186
1187     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1188
1189     { WM_NCACTIVATE, sent|wparam, 1 },
1190     { WM_GETTEXT, sent|optional|defwinproc },
1191     { WM_GETTEXT, sent|optional|defwinproc },
1192     { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1193     { WM_ACTIVATE, sent|wparam, 1 },
1194     { WM_GETTEXT, sent|optional },
1195     { WM_KILLFOCUS, sent|parent },
1196     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1197     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1198     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1199     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1200     { WM_SETFOCUS, sent },
1201     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1202     { WM_NCPAINT, sent|wparam, 1 },
1203     { WM_GETTEXT, sent|optional|defwinproc },
1204     { WM_GETTEXT, sent|optional|defwinproc },
1205     { WM_ERASEBKGND, sent },
1206     { WM_CTLCOLORDLG, sent|defwinproc },
1207     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1208     { WM_GETTEXT, sent|optional },
1209     { WM_GETTEXT, sent|optional },
1210     { WM_NCCALCSIZE, sent|optional },
1211     { WM_NCPAINT, sent|optional },
1212     { WM_GETTEXT, sent|optional|defwinproc },
1213     { WM_GETTEXT, sent|optional|defwinproc },
1214     { WM_ERASEBKGND, sent|optional },
1215     { WM_CTLCOLORDLG, sent|optional|defwinproc },
1216     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1217     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1218     { WM_MOVE, sent },
1219     { 0 }
1220 };
1221 /* Calling EndDialog for a custom dialog (32) */
1222 static const struct message WmEndCustomDialogSeq[] = {
1223     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1224     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1225     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1226     { WM_GETTEXT, sent|optional },
1227     { HCBT_ACTIVATE, hook },
1228     { WM_NCACTIVATE, sent|wparam, 0 },
1229     { WM_GETTEXT, sent|optional|defwinproc },
1230     { WM_GETTEXT, sent|optional|defwinproc },
1231     { WM_ACTIVATE, sent|wparam, 0 },
1232     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1233     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1234     { HCBT_SETFOCUS, hook },
1235     { WM_KILLFOCUS, sent },
1236     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1237     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1238     { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1239     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1240     { WM_SETFOCUS, sent|parent|defwinproc },
1241     { 0 }
1242 };
1243 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1244 static const struct message WmShowCustomDialogSeq[] = {
1245     { WM_SHOWWINDOW, sent|wparam, 1 },
1246     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1247     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1248     { HCBT_ACTIVATE, hook },
1249     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1250
1251     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1252
1253     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1254     { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1255     { WM_NCACTIVATE, sent|wparam, 1 },
1256     { WM_ACTIVATE, sent|wparam, 1 },
1257     { WM_GETTEXT, sent|optional },
1258
1259     { WM_KILLFOCUS, sent|parent },
1260     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1261     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1262     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1263     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1264     { WM_SETFOCUS, sent },
1265     { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1266     { WM_NCPAINT, sent|wparam, 1 },
1267     { WM_ERASEBKGND, sent },
1268     { WM_CTLCOLORDLG, sent|defwinproc },
1269     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1270     { 0 }
1271 };
1272 /* Creation and destruction of a modal dialog (32) */
1273 static const struct message WmModalDialogSeq[] = {
1274     { WM_CANCELMODE, sent|parent },
1275     { HCBT_SETFOCUS, hook },
1276     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1277     { WM_KILLFOCUS, sent|parent },
1278     { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1279     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1280     { WM_ENABLE, sent|parent|wparam, 0 },
1281     { HCBT_CREATEWND, hook },
1282     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1283     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1284     { WM_SETFONT, sent },
1285     { WM_INITDIALOG, sent },
1286     { WM_CHANGEUISTATE, sent|optional },
1287     { WM_UPDATEUISTATE, sent|optional },
1288     { WM_SHOWWINDOW, sent },
1289     { HCBT_ACTIVATE, hook },
1290     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1291     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1292     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1293     { WM_NCACTIVATE, sent|wparam, 1 },
1294     { WM_GETTEXT, sent|optional },
1295     { WM_ACTIVATE, sent|wparam, 1 },
1296     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1297     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1298     { WM_NCPAINT, sent },
1299     { WM_GETTEXT, sent|optional },
1300     { WM_ERASEBKGND, sent },
1301     { WM_CTLCOLORDLG, sent },
1302     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1303     { WM_GETTEXT, sent|optional },
1304     { WM_NCCALCSIZE, sent|optional },
1305     { WM_NCPAINT, sent|optional },
1306     { WM_GETTEXT, sent|optional },
1307     { WM_ERASEBKGND, sent|optional },
1308     { WM_CTLCOLORDLG, sent|optional },
1309     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1310     { WM_PAINT, sent|optional },
1311     { WM_CTLCOLORBTN, sent },
1312     { WM_ENTERIDLE, sent|parent|optional },
1313     { WM_ENTERIDLE, sent|parent|optional },
1314     { WM_ENTERIDLE, sent|parent|optional },
1315     { WM_ENTERIDLE, sent|parent|optional },
1316     { WM_ENTERIDLE, sent|parent|optional },
1317     { WM_ENTERIDLE, sent|parent|optional },
1318     { WM_ENTERIDLE, sent|parent|optional },
1319     { WM_ENTERIDLE, sent|parent|optional },
1320     { WM_ENTERIDLE, sent|parent|optional },
1321     { WM_ENTERIDLE, sent|parent|optional },
1322     { WM_ENTERIDLE, sent|parent|optional },
1323     { WM_ENTERIDLE, sent|parent|optional },
1324     { WM_ENTERIDLE, sent|parent|optional },
1325     { WM_ENTERIDLE, sent|parent|optional },
1326     { WM_ENTERIDLE, sent|parent|optional },
1327     { WM_ENTERIDLE, sent|parent|optional },
1328     { WM_ENTERIDLE, sent|parent|optional },
1329     { WM_ENTERIDLE, sent|parent|optional },
1330     { WM_ENTERIDLE, sent|parent|optional },
1331     { WM_ENTERIDLE, sent|parent|optional },
1332     { WM_TIMER, sent },
1333     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1334     { WM_ENABLE, sent|parent|wparam, 1 },
1335     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1336     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1337     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1338     { WM_GETTEXT, sent|optional },
1339     { HCBT_ACTIVATE, hook },
1340     { WM_NCACTIVATE, sent|wparam, 0 },
1341     { WM_GETTEXT, sent|optional },
1342     { WM_ACTIVATE, sent|wparam, 0 },
1343     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1344     { WM_WINDOWPOSCHANGING, sent|optional },
1345     { WM_WINDOWPOSCHANGED, sent|optional },
1346     { HCBT_SETFOCUS, hook },
1347     { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1348     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1349     { WM_SETFOCUS, sent|parent|defwinproc },
1350     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1351     { HCBT_DESTROYWND, hook },
1352     { 0x0090, sent|optional },
1353     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1354     { WM_DESTROY, sent },
1355     { WM_NCDESTROY, sent },
1356     { 0 }
1357 };
1358 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1359 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1360     /* (inside dialog proc, handling WM_INITDIALOG) */
1361     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1362     { WM_NCCALCSIZE, sent },
1363     { WM_NCACTIVATE, sent|parent|wparam, 0 },
1364     { WM_GETTEXT, sent|defwinproc },
1365     { WM_ACTIVATE, sent|parent|wparam, 0 },
1366     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1367     { WM_WINDOWPOSCHANGING, sent|parent },
1368     { WM_NCACTIVATE, sent|wparam, 1 },
1369     { WM_ACTIVATE, sent|wparam, 1 },
1370     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1371     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1372     /* (setting focus) */
1373     { WM_SHOWWINDOW, sent|wparam, 1 },
1374     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1375     { WM_NCPAINT, sent },
1376     { WM_GETTEXT, sent|defwinproc },
1377     { WM_ERASEBKGND, sent },
1378     { WM_CTLCOLORDLG, sent|defwinproc },
1379     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1380     { WM_PAINT, sent },
1381     /* (bunch of WM_CTLCOLOR* for each control) */
1382     { WM_PAINT, sent|parent },
1383     { WM_ENTERIDLE, sent|parent|wparam, 0 },
1384     { WM_SETCURSOR, sent|parent },
1385     { 0 }
1386 };
1387 /* SetMenu for NonVisible windows with size change*/
1388 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1389     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1390     { WM_NCCALCSIZE, sent|wparam, 1 },
1391     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1392     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1393     { WM_MOVE, sent|defwinproc },
1394     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1395     { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1396     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1397     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1398     { WM_GETTEXT, sent|optional },
1399     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1400     { 0 }
1401 };
1402 /* SetMenu for NonVisible windows with no size change */
1403 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1404     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1405     { WM_NCCALCSIZE, sent|wparam, 1 },
1406     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1407     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1408     { 0 }
1409 };
1410 /* SetMenu for Visible windows with size change */
1411 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1412     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1413     { WM_NCCALCSIZE, sent|wparam, 1 },
1414     { 0x0093, sent|defwinproc|optional },
1415     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1416     { WM_NCPAINT, sent }, /* wparam != 1 */
1417     { 0x0093, sent|defwinproc|optional },
1418     { 0x0093, sent|defwinproc|optional },
1419     { 0x0091, sent|defwinproc|optional },
1420     { 0x0092, sent|defwinproc|optional },
1421     { WM_GETTEXT, sent|defwinproc|optional },
1422     { WM_ERASEBKGND, sent|optional },
1423     { WM_ACTIVATE, sent|optional },
1424     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1425     { WM_MOVE, sent|defwinproc },
1426     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1427     { 0x0093, sent|optional },
1428     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1429     { 0x0093, sent|defwinproc|optional },
1430     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1431     { 0x0093, sent|defwinproc|optional },
1432     { 0x0093, sent|defwinproc|optional },
1433     { 0x0091, sent|defwinproc|optional },
1434     { 0x0092, sent|defwinproc|optional },
1435     { WM_ERASEBKGND, sent|optional },
1436     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1437     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1438     { 0 }
1439 };
1440 /* SetMenu for Visible windows with no size change */
1441 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1442     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1443     { WM_NCCALCSIZE, sent|wparam, 1 },
1444     { WM_NCPAINT, sent }, /* wparam != 1 */
1445     { WM_GETTEXT, sent|defwinproc|optional },
1446     { WM_ERASEBKGND, sent|optional },
1447     { WM_ACTIVATE, sent|optional },
1448     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1449     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1450     { 0 }
1451 };
1452 /* DrawMenuBar for a visible window */
1453 static const struct message WmDrawMenuBarSeq[] =
1454 {
1455     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1456     { WM_NCCALCSIZE, sent|wparam, 1 },
1457     { 0x0093, sent|defwinproc|optional },
1458     { WM_NCPAINT, sent }, /* wparam != 1 */
1459     { 0x0093, sent|defwinproc|optional },
1460     { 0x0093, sent|defwinproc|optional },
1461     { 0x0091, sent|defwinproc|optional },
1462     { 0x0092, sent|defwinproc|optional },
1463     { WM_GETTEXT, sent|defwinproc|optional },
1464     { WM_ERASEBKGND, sent|optional },
1465     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1466     { 0x0093, sent|optional },
1467     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1468     { 0 }
1469 };
1470
1471 static const struct message WmSetRedrawFalseSeq[] =
1472 {
1473     { WM_SETREDRAW, sent|wparam, 0 },
1474     { 0 }
1475 };
1476
1477 static const struct message WmSetRedrawTrueSeq[] =
1478 {
1479     { WM_SETREDRAW, sent|wparam, 1 },
1480     { 0 }
1481 };
1482
1483 static const struct message WmEnableWindowSeq_1[] =
1484 {
1485     { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1486     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1487     { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1488     { 0 }
1489 };
1490
1491 static const struct message WmEnableWindowSeq_2[] =
1492 {
1493     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1494     { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1495     { 0 }
1496 };
1497
1498 static const struct message WmGetScrollRangeSeq[] =
1499 {
1500     { SBM_GETRANGE, sent },
1501     { 0 }
1502 };
1503 static const struct message WmGetScrollInfoSeq[] =
1504 {
1505     { SBM_GETSCROLLINFO, sent },
1506     { 0 }
1507 };
1508 static const struct message WmSetScrollRangeSeq[] =
1509 {
1510     /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1511        sends SBM_SETSCROLLINFO.
1512      */
1513     { SBM_SETSCROLLINFO, sent },
1514     { 0 }
1515 };
1516 /* SetScrollRange for a window without a non-client area */
1517 static const struct message WmSetScrollRangeHSeq_empty[] =
1518 {
1519     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1520     { 0 }
1521 };
1522 static const struct message WmSetScrollRangeVSeq_empty[] =
1523 {
1524     { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1525     { 0 }
1526 };
1527 static const struct message WmSetScrollRangeHVSeq[] =
1528 {
1529     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1530     { WM_NCCALCSIZE, sent|wparam, 1 },
1531     { WM_GETTEXT, sent|defwinproc|optional },
1532     { WM_ERASEBKGND, sent|optional },
1533     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1534     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1535     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1536     { 0 }
1537 };
1538 /* SetScrollRange for a window with a non-client area */
1539 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1540 {
1541     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1542     { WM_NCCALCSIZE, sent|wparam, 1 },
1543     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1544     { WM_NCPAINT, sent|optional },
1545     { WM_STYLECHANGING, sent|defwinproc|optional },
1546     { WM_STYLECHANGED, sent|defwinproc|optional },
1547     { WM_STYLECHANGING, sent|defwinproc|optional },
1548     { WM_STYLECHANGED, sent|defwinproc|optional },
1549     { WM_STYLECHANGING, sent|defwinproc|optional },
1550     { WM_STYLECHANGED, sent|defwinproc|optional },
1551     { WM_STYLECHANGING, sent|defwinproc|optional },
1552     { WM_STYLECHANGED, sent|defwinproc|optional },
1553     { WM_GETTEXT, sent|defwinproc|optional },
1554     { WM_GETTEXT, sent|defwinproc|optional },
1555     { WM_ERASEBKGND, sent|optional },
1556     { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1557     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE },
1558     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1559     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1560     { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1561     { WM_GETTEXT, sent|optional },
1562     { WM_GETTEXT, sent|optional },
1563     { WM_GETTEXT, sent|optional },
1564     { WM_GETTEXT, sent|optional },
1565     { 0 }
1566 };
1567 /* test if we receive the right sequence of messages */
1568 /* after calling ShowWindow( SW_SHOWNA) */
1569 static const struct message WmSHOWNAChildInvisParInvis[] = {
1570     { WM_SHOWWINDOW, sent|wparam, 1 },
1571     { 0 }
1572 };
1573 static const struct message WmSHOWNAChildVisParInvis[] = {
1574     { WM_SHOWWINDOW, sent|wparam, 1 },
1575     { 0 }
1576 };
1577 static const struct message WmSHOWNAChildVisParVis[] = {
1578     { WM_SHOWWINDOW, sent|wparam, 1 },
1579     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1580     { 0 }
1581 };
1582 static const struct message WmSHOWNAChildInvisParVis[] = {
1583     { WM_SHOWWINDOW, sent|wparam, 1 },
1584     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1585     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1586     { WM_ERASEBKGND, sent|optional },
1587     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1588     { 0 }
1589 };
1590 static const struct message WmSHOWNATopVisible[] = {
1591     { WM_SHOWWINDOW, sent|wparam, 1 },
1592     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1593     { WM_NCPAINT, sent|wparam|optional, 1 },
1594     { WM_GETTEXT, sent|defwinproc|optional },
1595     { WM_ERASEBKGND, sent|optional },
1596     { WM_WINDOWPOSCHANGED, sent|optional },
1597     { 0 }
1598 };
1599 static const struct message WmSHOWNATopInvisible[] = {
1600     { WM_NOTIFYFORMAT, sent|optional },
1601     { WM_QUERYUISTATE, sent|optional },
1602     { WM_WINDOWPOSCHANGING, sent|optional },
1603     { WM_GETMINMAXINFO, sent|optional },
1604     { WM_NCCALCSIZE, sent|optional },
1605     { WM_WINDOWPOSCHANGED, sent|optional },
1606     { WM_SHOWWINDOW, sent|wparam, 1 },
1607     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1608     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1609     { WM_NCPAINT, sent|wparam, 1 },
1610     { WM_GETTEXT, sent|defwinproc|optional },
1611     { WM_ERASEBKGND, sent|optional },
1612     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1613     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1614     { WM_NCPAINT, sent|wparam|optional, 1 },
1615     { WM_ERASEBKGND, sent|optional },
1616     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1617     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1618     { WM_MOVE, sent },
1619     { 0 }
1620 };
1621
1622 static int after_end_dialog, test_def_id;
1623 static int sequence_cnt, sequence_size;
1624 static struct message* sequence;
1625 static int log_all_parent_messages;
1626 static int paint_loop_done;
1627
1628 /* user32 functions */
1629 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1630 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
1631 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1632 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
1633 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1634 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1635 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1636 /* kernel32 functions */
1637 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1638
1639 static void init_procs(void)
1640 {
1641     HMODULE user32 = GetModuleHandleA("user32.dll");
1642     HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1643
1644 #define GET_PROC(dll, func) \
1645     p ## func = (void*)GetProcAddress(dll, #func); \
1646     if(!p ## func) { \
1647       trace("GetProcAddress(%s) failed\n", #func); \
1648     }
1649
1650     GET_PROC(user32, GetAncestor)
1651     GET_PROC(user32, GetMenuInfo)
1652     GET_PROC(user32, NotifyWinEvent)
1653     GET_PROC(user32, SetMenuInfo)
1654     GET_PROC(user32, SetWinEventHook)
1655     GET_PROC(user32, TrackMouseEvent)
1656     GET_PROC(user32, UnhookWinEvent)
1657
1658     GET_PROC(kernel32, GetCPInfoExA)
1659
1660 #undef GET_PROC
1661 }
1662
1663 static void add_message(const struct message *msg)
1664 {
1665     if (!sequence) 
1666     {
1667         sequence_size = 10;
1668         sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof (struct message) );
1669     }
1670     if (sequence_cnt == sequence_size) 
1671     {
1672         sequence_size *= 2;
1673         sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof (struct message) );
1674     }
1675     assert(sequence);
1676
1677     sequence[sequence_cnt].message = msg->message;
1678     sequence[sequence_cnt].flags = msg->flags;
1679     sequence[sequence_cnt].wParam = msg->wParam;
1680     sequence[sequence_cnt].lParam = msg->lParam;
1681
1682     sequence_cnt++;
1683 }
1684
1685 /* try to make sure pending X events have been processed before continuing */
1686 static void flush_events(void)
1687 {
1688     MSG msg;
1689     int diff = 200;
1690     int min_timeout = 50;
1691     DWORD time = GetTickCount() + diff;
1692
1693     while (diff > 0)
1694     {
1695         if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1696         while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1697         diff = time - GetTickCount();
1698         min_timeout = 20;
1699     }
1700 }
1701
1702 static void flush_sequence(void)
1703 {
1704     HeapFree(GetProcessHeap(), 0, sequence);
1705     sequence = 0;
1706     sequence_cnt = sequence_size = 0;
1707 }
1708
1709 #define ok_sequence( exp, contx, todo) \
1710         ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
1711
1712
1713 static void ok_sequence_(const struct message *expected, const char *context, int todo,
1714         const char *file, int line)
1715 {
1716     static const struct message end_of_sequence = { 0, 0, 0, 0 };
1717     const struct message *actual;
1718     int failcount = 0;
1719     
1720     add_message(&end_of_sequence);
1721
1722     actual = sequence;
1723
1724     while (expected->message && actual->message)
1725     {
1726         trace_( file, line)("expected %04x - actual %04x\n", expected->message, actual->message);
1727
1728         if (expected->message == actual->message)
1729         {
1730             if (expected->flags & wparam)
1731             {
1732                 if (expected->wParam != actual->wParam && todo)
1733                 {
1734                     todo_wine {
1735                         failcount ++;
1736                         ok_( file, line) (FALSE,
1737                             "%s: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1738                             context, expected->message, expected->wParam, actual->wParam);
1739                     }
1740                 }
1741                 else
1742                 ok_( file, line) (expected->wParam == actual->wParam,
1743                      "%s: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1744                      context, expected->message, expected->wParam, actual->wParam);
1745             }
1746             if (expected->flags & lparam)
1747             {
1748                 if (expected->lParam != actual->lParam && todo)
1749                 {
1750                     todo_wine {
1751                         failcount ++;
1752                         ok_( file, line) (FALSE,
1753                             "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1754                             context, expected->message, expected->lParam, actual->lParam);
1755                     }
1756                 }
1757                 else
1758                  ok_( file, line) (expected->lParam == actual->lParam,
1759                      "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1760                      context, expected->message, expected->lParam, actual->lParam);
1761             }
1762             if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
1763             {
1764                     todo_wine {
1765                         failcount ++;
1766                         ok_( file, line) (FALSE,
1767                             "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1768                             context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1769                     }
1770             }
1771             else
1772                 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
1773                     "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1774                     context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1775             ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
1776                 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
1777                 context, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
1778             ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
1779                 "%s: the msg 0x%04x should have been %s\n",
1780                 context, expected->message, (expected->flags & posted) ? "posted" : "sent");
1781             ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
1782                 "%s: the msg 0x%04x was expected in %s\n",
1783                 context, expected->message, (expected->flags & parent) ? "parent" : "child");
1784             ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
1785                 "%s: the msg 0x%04x should have been sent by a hook\n",
1786                 context, expected->message);
1787             ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
1788                 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
1789                 context, expected->message);
1790             expected++;
1791             actual++;
1792         }
1793         /* silently drop winevent messages if there is no support for them */
1794         else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1795             expected++;
1796         else if (todo)
1797         {
1798             failcount++;
1799             todo_wine {
1800                 ok_( file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
1801                     context, expected->message, actual->message);
1802             }
1803             flush_sequence();
1804             return;
1805         }
1806         else
1807         {
1808             ok_( file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
1809                 context, expected->message, actual->message);
1810             expected++;
1811             actual++;
1812         }
1813     }
1814
1815     /* skip all optional trailing messages */
1816     while (expected->message && ((expected->flags & optional) ||
1817             ((expected->flags & winevent_hook) && !hEvent_hook)))
1818         expected++;
1819
1820     if (todo)
1821     {
1822         todo_wine {
1823             if (expected->message || actual->message) {
1824                 failcount++;
1825                 ok_( file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
1826                     context, expected->message, actual->message);
1827             }
1828         }
1829     }
1830     else
1831     {
1832         if (expected->message || actual->message)
1833             ok_( file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
1834                 context, expected->message, actual->message);
1835     }
1836     if( todo && !failcount) /* succeeded yet marked todo */
1837         todo_wine {
1838             ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
1839         }
1840
1841     flush_sequence();
1842 }
1843
1844 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
1845
1846 /******************************** MDI test **********************************/
1847
1848 /* CreateWindow for MDI frame window, initially visible */
1849 static const struct message WmCreateMDIframeSeq[] = {
1850     { HCBT_CREATEWND, hook },
1851     { WM_GETMINMAXINFO, sent },
1852     { WM_NCCREATE, sent },
1853     { WM_NCCALCSIZE, sent|wparam, 0 },
1854     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1855     { WM_CREATE, sent },
1856     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1857     { WM_NOTIFYFORMAT, sent|optional },
1858     { WM_QUERYUISTATE, sent|optional },
1859     { WM_WINDOWPOSCHANGING, sent|optional },
1860     { WM_GETMINMAXINFO, sent|optional },
1861     { WM_NCCALCSIZE, sent|optional },
1862     { WM_WINDOWPOSCHANGED, sent|optional },
1863     { WM_SHOWWINDOW, sent|wparam, 1 },
1864     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1865     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1866     { HCBT_ACTIVATE, hook },
1867     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1868     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1869     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
1870     { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
1871     { WM_NCACTIVATE, sent|wparam, 1 },
1872     { WM_GETTEXT, sent|defwinproc|optional },
1873     { WM_ACTIVATE, sent|wparam, 1 },
1874     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
1875     { HCBT_SETFOCUS, hook },
1876     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1877     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1878     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1879     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
1880     /* Win9x adds SWP_NOZORDER below */
1881     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1882     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
1883     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1884     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1885     { WM_MOVE, sent },
1886     { 0 }
1887 };
1888 /* DestroyWindow for MDI frame window, initially visible */
1889 static const struct message WmDestroyMDIframeSeq[] = {
1890     { HCBT_DESTROYWND, hook },
1891     { 0x0090, sent|optional },
1892     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1893     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1894     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
1895     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1896     { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
1897     { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
1898     { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
1899     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
1900     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1901     { WM_DESTROY, sent },
1902     { WM_NCDESTROY, sent },
1903     { 0 }
1904 };
1905 /* CreateWindow for MDI client window, initially visible */
1906 static const struct message WmCreateMDIclientSeq[] = {
1907     { HCBT_CREATEWND, hook },
1908     { WM_NCCREATE, sent },
1909     { WM_NCCALCSIZE, sent|wparam, 0 },
1910     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
1911     { WM_CREATE, sent },
1912     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
1913     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1914     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1915     { WM_MOVE, sent },
1916     { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
1917     { WM_SHOWWINDOW, sent|wparam, 1 },
1918     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1919     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1920     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1921     { 0 }
1922 };
1923 /* ShowWindow(SW_SHOW) for MDI client window */
1924 static const struct message WmShowMDIclientSeq[] = {
1925     { WM_SHOWWINDOW, sent|wparam, 1 },
1926     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1927     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1928     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1929     { 0 }
1930 };
1931 /* ShowWindow(SW_HIDE) for MDI client window */
1932 static const struct message WmHideMDIclientSeq[] = {
1933     { WM_SHOWWINDOW, sent|wparam, 0 },
1934     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1935     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
1936     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
1937     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1938     { 0 }
1939 };
1940 /* DestroyWindow for MDI client window, initially visible */
1941 static const struct message WmDestroyMDIclientSeq[] = {
1942     { HCBT_DESTROYWND, hook },
1943     { 0x0090, sent|optional },
1944     { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
1945     { WM_SHOWWINDOW, sent|wparam, 0 },
1946     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1947     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1948     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1949     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1950     { WM_DESTROY, sent },
1951     { WM_NCDESTROY, sent },
1952     { 0 }
1953 };
1954 /* CreateWindow for MDI child window, initially visible */
1955 static const struct message WmCreateMDIchildVisibleSeq[] = {
1956     { HCBT_CREATEWND, hook },
1957     { WM_NCCREATE, sent }, 
1958     { WM_NCCALCSIZE, sent|wparam, 0 },
1959     { WM_CREATE, sent },
1960     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1961     { WM_SIZE, sent|wparam, SIZE_RESTORED },
1962     { WM_MOVE, sent },
1963     /* Win2k sends wparam set to
1964      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1965      * while Win9x doesn't bother to set child window id according to
1966      * CLIENTCREATESTRUCT.idFirstChild
1967      */
1968     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1969     { WM_SHOWWINDOW, sent|wparam, 1 },
1970     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1971     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1972     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1973     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1974     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1975     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1976     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1977
1978     /* Win9x: message sequence terminates here. */
1979
1980     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1981     { HCBT_SETFOCUS, hook }, /* in MDI client */
1982     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1983     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
1984     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1985     { WM_SETFOCUS, sent }, /* in MDI client */
1986     { HCBT_SETFOCUS, hook },
1987     { WM_KILLFOCUS, sent }, /* in MDI client */
1988     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1989     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1990     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1991     { WM_SETFOCUS, sent|defwinproc },
1992     { WM_MDIACTIVATE, sent|defwinproc },
1993     { 0 }
1994 };
1995 /* CreateWindow for MDI child window with invisible parent */
1996 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
1997     { HCBT_CREATEWND, hook },
1998     { WM_GETMINMAXINFO, sent },
1999     { WM_NCCREATE, sent }, 
2000     { WM_NCCALCSIZE, sent|wparam, 0 },
2001     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2002     { WM_CREATE, sent },
2003     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2004     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2005     { WM_MOVE, sent },
2006     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2007     { WM_SHOWWINDOW, sent|wparam, 1 },
2008     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2009     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2010     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2011     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2012
2013     /* Win9x: message sequence terminates here. */
2014
2015     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2016     { HCBT_SETFOCUS, hook }, /* in MDI client */
2017     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2018     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2019     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2020     { WM_SETFOCUS, sent }, /* in MDI client */
2021     { HCBT_SETFOCUS, hook },
2022     { WM_KILLFOCUS, sent }, /* in MDI client */
2023     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2024     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2025     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2026     { WM_SETFOCUS, sent|defwinproc },
2027     { WM_MDIACTIVATE, sent|defwinproc },
2028     { 0 }
2029 };
2030 /* DestroyWindow for MDI child window, initially visible */
2031 static const struct message WmDestroyMDIchildVisibleSeq[] = {
2032     { HCBT_DESTROYWND, hook },
2033     /* Win2k sends wparam set to
2034      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2035      * while Win9x doesn't bother to set child window id according to
2036      * CLIENTCREATESTRUCT.idFirstChild
2037      */
2038     { 0x0090, sent|optional },
2039     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2040     { WM_SHOWWINDOW, sent|wparam, 0 },
2041     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2042     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2043     { WM_ERASEBKGND, sent|parent|optional },
2044     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2045
2046     /* { WM_DESTROY, sent }
2047      * Win9x: message sequence terminates here.
2048      */
2049
2050     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2051     { WM_KILLFOCUS, sent },
2052     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2053     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2054     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2055     { WM_SETFOCUS, sent }, /* in MDI client */
2056
2057     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2058     { WM_KILLFOCUS, sent }, /* in MDI client */
2059     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2060     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2061     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2062     { WM_SETFOCUS, sent }, /* in MDI client */
2063
2064     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2065
2066     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2067     { WM_KILLFOCUS, sent },
2068     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2069     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2070     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2071     { WM_SETFOCUS, sent }, /* in MDI client */
2072
2073     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2074     { WM_KILLFOCUS, sent }, /* in MDI client */
2075     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2076     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2077     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2078     { WM_SETFOCUS, sent }, /* in MDI client */
2079
2080     { WM_DESTROY, sent },
2081
2082     { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2083     { WM_KILLFOCUS, sent },
2084     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2085     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2086     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2087     { WM_SETFOCUS, sent }, /* in MDI client */
2088
2089     { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2090     { WM_KILLFOCUS, sent }, /* in MDI client */
2091     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2092     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2093     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2094     { WM_SETFOCUS, sent }, /* in MDI client */
2095
2096     { WM_NCDESTROY, sent },
2097     { 0 }
2098 };
2099 /* CreateWindow for MDI child window, initially invisible */
2100 static const struct message WmCreateMDIchildInvisibleSeq[] = {
2101     { HCBT_CREATEWND, hook },
2102     { WM_NCCREATE, sent }, 
2103     { WM_NCCALCSIZE, sent|wparam, 0 },
2104     { WM_CREATE, sent },
2105     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2106     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2107     { WM_MOVE, sent },
2108     /* Win2k sends wparam set to
2109      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2110      * while Win9x doesn't bother to set child window id according to
2111      * CLIENTCREATESTRUCT.idFirstChild
2112      */
2113     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2114     { 0 }
2115 };
2116 /* DestroyWindow for MDI child window, initially invisible */
2117 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
2118     { HCBT_DESTROYWND, hook },
2119     /* Win2k sends wparam set to
2120      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2121      * while Win9x doesn't bother to set child window id according to
2122      * CLIENTCREATESTRUCT.idFirstChild
2123      */
2124     { 0x0090, sent|optional },
2125     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2126     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2127     { WM_DESTROY, sent },
2128     { WM_NCDESTROY, sent },
2129     /* FIXME: Wine destroys an icon/title window while Windows doesn't */
2130     { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
2131     { 0 }
2132 };
2133 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
2134 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
2135     { HCBT_CREATEWND, hook },
2136     { WM_NCCREATE, sent }, 
2137     { WM_NCCALCSIZE, sent|wparam, 0 },
2138     { WM_CREATE, sent },
2139     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2140     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2141     { WM_MOVE, sent },
2142     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2143     { WM_GETMINMAXINFO, sent },
2144     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED  },
2145     { WM_NCCALCSIZE, sent|wparam, 1 },
2146     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2147     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2148      /* in MDI frame */
2149     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2150     { WM_NCCALCSIZE, sent|wparam, 1 },
2151     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2152     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2153     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2154     /* Win2k sends wparam set to
2155      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2156      * while Win9x doesn't bother to set child window id according to
2157      * CLIENTCREATESTRUCT.idFirstChild
2158      */
2159     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2160     { WM_SHOWWINDOW, sent|wparam, 1 },
2161     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2162     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2163     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2164     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2165     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2166     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2167     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2168
2169     /* Win9x: message sequence terminates here. */
2170
2171     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2172     { HCBT_SETFOCUS, hook }, /* in MDI client */
2173     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2174     { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2175     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2176     { WM_SETFOCUS, sent }, /* in MDI client */
2177     { HCBT_SETFOCUS, hook },
2178     { WM_KILLFOCUS, sent }, /* in MDI client */
2179     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2180     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2181     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2182     { WM_SETFOCUS, sent|defwinproc },
2183     { WM_MDIACTIVATE, sent|defwinproc },
2184      /* in MDI frame */
2185     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2186     { WM_NCCALCSIZE, sent|wparam, 1 },
2187     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2188     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2189     { 0 }
2190 };
2191 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2192 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2193     /* restore the 1st MDI child */
2194     { WM_SETREDRAW, sent|wparam, 0 },
2195     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2196     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2197     { WM_NCCALCSIZE, sent|wparam, 1 },
2198     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2199     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2200     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2201      /* in MDI frame */
2202     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2203     { WM_NCCALCSIZE, sent|wparam, 1 },
2204     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2205     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2206     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2207     { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2208     /* create the 2nd MDI child */
2209     { HCBT_CREATEWND, hook },
2210     { WM_NCCREATE, sent }, 
2211     { WM_NCCALCSIZE, sent|wparam, 0 },
2212     { WM_CREATE, sent },
2213     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2214     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2215     { WM_MOVE, sent },
2216     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2217     { WM_GETMINMAXINFO, sent },
2218     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2219     { WM_NCCALCSIZE, sent|wparam, 1 },
2220     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2221     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2222     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2223      /* in MDI frame */
2224     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2225     { WM_NCCALCSIZE, sent|wparam, 1 },
2226     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2227     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2228     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2229     /* Win2k sends wparam set to
2230      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2231      * while Win9x doesn't bother to set child window id according to
2232      * CLIENTCREATESTRUCT.idFirstChild
2233      */
2234     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2235     { WM_SHOWWINDOW, sent|wparam, 1 },
2236     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2237     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2238     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2239     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2240     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2241     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2242
2243     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2244     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2245
2246     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2247
2248     /* Win9x: message sequence terminates here. */
2249
2250     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2251     { HCBT_SETFOCUS, hook },
2252     { WM_KILLFOCUS, sent|defwinproc|optional }, /* in the 1st MDI child */
2253     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2254     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2255     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2256     { WM_SETFOCUS, sent }, /* in MDI client */
2257     { HCBT_SETFOCUS, hook },
2258     { WM_KILLFOCUS, sent }, /* in MDI client */
2259     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2260     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2261     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2262     { WM_SETFOCUS, sent|defwinproc },
2263
2264     { WM_MDIACTIVATE, sent|defwinproc },
2265      /* in MDI frame */
2266     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2267     { WM_NCCALCSIZE, sent|wparam, 1 },
2268     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2269     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2270     { 0 }
2271 };
2272 /* WM_MDICREATE MDI child window, initially visible and maximized */
2273 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2274     { WM_MDICREATE, sent },
2275     { HCBT_CREATEWND, hook },
2276     { WM_NCCREATE, sent }, 
2277     { WM_NCCALCSIZE, sent|wparam, 0 },
2278     { WM_CREATE, sent },
2279     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2280     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2281     { WM_MOVE, sent },
2282     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2283     { WM_GETMINMAXINFO, sent },
2284     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2285     { WM_NCCALCSIZE, sent|wparam, 1 },
2286     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2287     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2288
2289      /* in MDI frame */
2290     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2291     { WM_NCCALCSIZE, sent|wparam, 1 },
2292     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2293     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2294     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2295
2296     /* Win2k sends wparam set to
2297      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2298      * while Win9x doesn't bother to set child window id according to
2299      * CLIENTCREATESTRUCT.idFirstChild
2300      */
2301     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2302     { WM_SHOWWINDOW, sent|wparam, 1 },
2303     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2304
2305     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2306
2307     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2308     { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2309     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2310
2311     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2312     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2313
2314     /* Win9x: message sequence terminates here. */
2315
2316     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2317     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2318     { HCBT_SETFOCUS, hook }, /* in MDI client */
2319     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2320     { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2321     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2322     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2323     { HCBT_SETFOCUS, hook|optional },
2324     { WM_KILLFOCUS, sent }, /* in MDI client */
2325     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2326     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2327     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2328     { WM_SETFOCUS, sent|defwinproc },
2329
2330     { WM_MDIACTIVATE, sent|defwinproc },
2331
2332      /* in MDI child */
2333     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2334     { WM_NCCALCSIZE, sent|wparam, 1 },
2335     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2336     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2337
2338      /* in MDI frame */
2339     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2340     { WM_NCCALCSIZE, sent|wparam, 1 },
2341     { 0x0093, sent|defwinproc|optional },
2342     { 0x0093, sent|defwinproc|optional },
2343     { 0x0093, sent|defwinproc|optional },
2344     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2345     { WM_MOVE, sent|defwinproc },
2346     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2347
2348      /* in MDI client */
2349     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2350     { WM_NCCALCSIZE, sent|wparam, 1 },
2351     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2352     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2353
2354      /* in MDI child */
2355     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2356     { WM_NCCALCSIZE, sent|wparam, 1 },
2357     { 0x0093, sent|optional },
2358     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2359     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2360
2361     { 0x0093, sent|optional },
2362     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2363     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2364     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2365     { 0x0093, sent|defwinproc|optional },
2366     { 0x0093, sent|defwinproc|optional },
2367     { 0x0093, sent|defwinproc|optional },
2368     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2369     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2370
2371     { 0 }
2372 };
2373 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2374 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2375     { HCBT_CREATEWND, hook },
2376     { WM_GETMINMAXINFO, sent },
2377     { WM_NCCREATE, sent }, 
2378     { WM_NCCALCSIZE, sent|wparam, 0 },
2379     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2380     { WM_CREATE, sent },
2381     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2382     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2383     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE|SWP_NOMOVE }, /* MDI frame */
2384     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI frame */
2385     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* MDI frame */
2386     { WM_MOVE, sent },
2387     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2388     { WM_GETMINMAXINFO, sent },
2389     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2390     { WM_GETMINMAXINFO, sent|defwinproc },
2391     { WM_NCCALCSIZE, sent|wparam, 1 },
2392     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
2393     { WM_MOVE, sent|defwinproc },
2394     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2395      /* in MDI frame */
2396     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2397     { WM_NCCALCSIZE, sent|wparam, 1 },
2398     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2399     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2400     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2401     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2402     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2403     /* Win2k sends wparam set to
2404      * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2405      * while Win9x doesn't bother to set child window id according to
2406      * CLIENTCREATESTRUCT.idFirstChild
2407      */
2408     { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2409     { 0 }
2410 };
2411 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2412 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2413     { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2414     { HCBT_SYSCOMMAND, hook },
2415     { WM_CLOSE, sent|defwinproc },
2416     { WM_MDIDESTROY, sent }, /* in MDI client */
2417
2418     /* bring the 1st MDI child to top */
2419     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2420     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2421
2422     { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2423
2424     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2425     { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2426     { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2427
2428     /* maximize the 1st MDI child */
2429     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2430     { WM_GETMINMAXINFO, sent|defwinproc },
2431     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED },
2432     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2433     { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2434     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2435     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2436
2437     /* restore the 2nd MDI child */
2438     { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2439     { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2440     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2441     { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2442
2443     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2444
2445     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2446     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2447
2448     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2449
2450     { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2451      /* in MDI frame */
2452     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2453     { WM_NCCALCSIZE, sent|wparam, 1 },
2454     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2455     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2456     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2457
2458     /* bring the 1st MDI child to top */
2459     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2460     { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2461     { HCBT_SETFOCUS, hook },
2462     { WM_KILLFOCUS, sent|defwinproc },
2463     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2464     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2465     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2466     { WM_SETFOCUS, sent }, /* in MDI client */
2467     { HCBT_SETFOCUS, hook },
2468     { WM_KILLFOCUS, sent }, /* in MDI client */
2469     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2470     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2471     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2472     { WM_SETFOCUS, sent|defwinproc },
2473     { WM_MDIACTIVATE, sent|defwinproc },
2474     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2475
2476     /* apparently ShowWindow(SW_SHOW) on an MDI client */
2477     { WM_SHOWWINDOW, sent|wparam, 1 },
2478     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2479     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2480     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2481     { WM_MDIREFRESHMENU, sent },
2482
2483     { HCBT_DESTROYWND, hook },
2484     /* Win2k sends wparam set to
2485      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2486      * while Win9x doesn't bother to set child window id according to
2487      * CLIENTCREATESTRUCT.idFirstChild
2488      */
2489     { 0x0090, sent|defwinproc|optional },
2490     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2491     { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2492     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2493     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2494     { WM_ERASEBKGND, sent|parent|optional },
2495     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2496
2497     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2498     { WM_DESTROY, sent|defwinproc },
2499     { WM_NCDESTROY, sent|defwinproc },
2500     { 0 }
2501 };
2502 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2503 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2504     { WM_MDIDESTROY, sent }, /* in MDI client */
2505     { WM_SHOWWINDOW, sent|wparam, 0 },
2506     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2507     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2508     { WM_ERASEBKGND, sent|parent|optional },
2509     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2510
2511     { HCBT_SETFOCUS, hook },
2512     { WM_KILLFOCUS, sent },
2513     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2514     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2515     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2516     { WM_SETFOCUS, sent }, /* in MDI client */
2517     { HCBT_SETFOCUS, hook },
2518     { WM_KILLFOCUS, sent }, /* in MDI client */
2519     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2520     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2521     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2522     { WM_SETFOCUS, sent },
2523
2524      /* in MDI child */
2525     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2526     { WM_NCCALCSIZE, sent|wparam, 1 },
2527     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2528     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2529
2530      /* in MDI frame */
2531     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2532     { WM_NCCALCSIZE, sent|wparam, 1 },
2533     { 0x0093, sent|defwinproc|optional },
2534     { 0x0093, sent|defwinproc|optional },
2535     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2536     { WM_MOVE, sent|defwinproc },
2537     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2538
2539      /* in MDI client */
2540     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2541     { WM_NCCALCSIZE, sent|wparam, 1 },
2542     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2543     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2544
2545      /* in MDI child */
2546     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2547     { WM_NCCALCSIZE, sent|wparam, 1 },
2548     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2549     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2550
2551      /* in MDI child */
2552     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2553     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2554     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2555     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2556
2557      /* in MDI frame */
2558     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2559     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2560     { 0x0093, sent|defwinproc|optional },
2561     { 0x0093, sent|defwinproc|optional },
2562     { 0x0093, sent|defwinproc|optional },
2563     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2564     { WM_MOVE, sent|defwinproc },
2565     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2566
2567      /* in MDI client */
2568     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2569     { WM_NCCALCSIZE, sent|wparam, 1 },
2570     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2571     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2572
2573      /* in MDI child */
2574     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2575     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2576     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2577     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2578     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2579     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2580
2581     { 0x0093, sent|defwinproc|optional },
2582     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2583     { 0x0093, sent|defwinproc|optional },
2584     { 0x0093, sent|defwinproc|optional },
2585     { 0x0093, sent|defwinproc|optional },
2586     { 0x0093, sent|optional },
2587
2588     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2589     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2590     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2591     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2592     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2593
2594      /* in MDI frame */
2595     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2596     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2597     { 0x0093, sent|defwinproc|optional },
2598     { 0x0093, sent|defwinproc|optional },
2599     { 0x0093, sent|defwinproc|optional },
2600     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2601     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2602     { 0x0093, sent|optional },
2603
2604     { WM_NCACTIVATE, sent|wparam, 0 },
2605     { WM_MDIACTIVATE, sent },
2606
2607     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2608     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2609     { WM_NCCALCSIZE, sent|wparam, 1 },
2610
2611     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2612
2613     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2614     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2615     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2616
2617      /* in MDI child */
2618     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2619     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2620     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2621     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2622
2623      /* in MDI frame */
2624     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2625     { WM_NCCALCSIZE, sent|wparam, 1 },
2626     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2627     { WM_MOVE, sent|defwinproc },
2628     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2629
2630      /* in MDI client */
2631     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2632     { WM_NCCALCSIZE, sent|wparam, 1 },
2633     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2634     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2635     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2636     { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2637     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2638     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2639     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2640
2641     { HCBT_SETFOCUS, hook },
2642     { WM_KILLFOCUS, sent },
2643     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2644     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2645     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2646     { WM_SETFOCUS, sent }, /* in MDI client */
2647
2648     { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2649
2650     { HCBT_DESTROYWND, hook },
2651     /* Win2k sends wparam set to
2652      * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2653      * while Win9x doesn't bother to set child window id according to
2654      * CLIENTCREATESTRUCT.idFirstChild
2655      */
2656     { 0x0090, sent|optional },
2657     { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2658
2659     { WM_SHOWWINDOW, sent|wparam, 0 },
2660     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2661     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2662     { WM_ERASEBKGND, sent|parent|optional },
2663     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2664
2665     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2666     { WM_DESTROY, sent },
2667     { WM_NCDESTROY, sent },
2668     { 0 }
2669 };
2670 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
2671 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
2672     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2673     { WM_GETMINMAXINFO, sent },
2674     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
2675     { WM_NCCALCSIZE, sent|wparam, 1 },
2676     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2677     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2678
2679     { WM_WINDOWPOSCHANGING, sent|wparam|optional|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2680     { WM_NCACTIVATE, sent|wparam|optional|defwinproc, 1 },
2681     { HCBT_SETFOCUS, hook|optional },
2682     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2683     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2684     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2685     { HCBT_SETFOCUS, hook|optional },
2686     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2687     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2688     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2689     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2690     { WM_SETFOCUS, sent|optional|defwinproc },
2691     { WM_MDIACTIVATE, sent|optional|defwinproc },
2692     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2693     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2694      /* in MDI frame */
2695     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2696     { WM_NCCALCSIZE, sent|wparam, 1 },
2697     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2698     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2699     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2700     { 0 }
2701 };
2702 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
2703 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
2704     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2705     { WM_GETMINMAXINFO, sent },
2706     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
2707     { WM_GETMINMAXINFO, sent|defwinproc },
2708     { WM_NCCALCSIZE, sent|wparam, 1 },
2709     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2710     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2711
2712     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2713     { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2714     { HCBT_SETFOCUS, hook|optional },
2715     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2716     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2717     { WM_SETFOCUS, sent|optional }, /* in MDI client */
2718     { HCBT_SETFOCUS, hook|optional },
2719     { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2720     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2721     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2722     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2723     { WM_SETFOCUS, sent|defwinproc|optional },
2724     { WM_MDIACTIVATE, sent|defwinproc|optional },
2725     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2726     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2727     { 0 }
2728 };
2729 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
2730 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
2731     { WM_MDIMAXIMIZE, sent }, /* in MDI client */
2732     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2733     { WM_GETMINMAXINFO, sent },
2734     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2735     { WM_GETMINMAXINFO, sent|defwinproc },
2736     { WM_NCCALCSIZE, sent|wparam, 1 },
2737     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
2738     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2739     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
2740     { WM_MOVE, sent|defwinproc },
2741     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2742
2743     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2744     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2745     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2746     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
2747     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2748     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
2749      /* in MDI frame */
2750     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2751     { WM_NCCALCSIZE, sent|wparam, 1 },
2752     { 0x0093, sent|defwinproc|optional },
2753     { 0x0094, sent|defwinproc|optional },
2754     { 0x0094, sent|defwinproc|optional },
2755     { 0x0094, sent|defwinproc|optional },
2756     { 0x0094, sent|defwinproc|optional },
2757     { 0x0093, sent|defwinproc|optional },
2758     { 0x0093, sent|defwinproc|optional },
2759     { 0x0091, sent|defwinproc|optional },
2760     { 0x0092, sent|defwinproc|optional },
2761     { 0x0092, sent|defwinproc|optional },
2762     { 0x0092, sent|defwinproc|optional },
2763     { 0x0092, sent|defwinproc|optional },
2764     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2765     { WM_MOVE, sent|defwinproc },
2766     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2767     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
2768      /* in MDI client */
2769     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2770     { WM_NCCALCSIZE, sent|wparam, 1 },
2771     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2772     { WM_SIZE, sent|wparam, SIZE_RESTORED },
2773      /* in MDI child */
2774     { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2775     { WM_GETMINMAXINFO, sent|defwinproc },
2776     { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2777     { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2778     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2779     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
2780     { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
2781     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2782     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2783     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
2784      /* in MDI frame */
2785     { 0x0093, sent|optional },
2786     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2787     { 0x0093, sent|defwinproc|optional },
2788     { 0x0093, sent|defwinproc|optional },
2789     { 0x0093, sent|defwinproc|optional },
2790     { 0x0091, sent|defwinproc|optional },
2791     { 0x0092, sent|defwinproc|optional },
2792     { 0x0092, sent|defwinproc|optional },
2793     { 0x0092, sent|defwinproc|optional },
2794     { 0x0092, sent|defwinproc|optional },
2795     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
2796     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
2797     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2798     { 0 }
2799 };
2800 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
2801 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
2802     { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2803     { WM_GETMINMAXINFO, sent },
2804     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2805     { WM_NCCALCSIZE, sent|wparam, 1 },
2806     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2807     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2808     { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2809      /* in MDI frame */
2810     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2811     { WM_NCCALCSIZE, sent|wparam, 1 },
2812     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2813     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2814     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2815     { 0 }
2816 };
2817 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
2818 static const struct message WmRestoreMDIchildVisibleSeq[] = {
2819     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2820     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2821     { WM_NCCALCSIZE, sent|wparam, 1 },
2822     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2823     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2824     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2825      /* in MDI frame */
2826     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2827     { WM_NCCALCSIZE, sent|wparam, 1 },
2828     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2829     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2830     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2831     { 0 }
2832 };
2833 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
2834 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
2835     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2836     { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
2837     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
2838     { WM_NCCALCSIZE, sent|wparam, 1 },
2839     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2840     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
2841     { WM_MOVE, sent|defwinproc },
2842     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2843     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2844     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2845     { HCBT_SETFOCUS, hook },
2846     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2847     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2848     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2849     { WM_SETFOCUS, sent },
2850     { 0 }
2851 };
2852 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
2853 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
2854     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
2855     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
2856     { WM_NCCALCSIZE, sent|wparam, 1 },
2857     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
2858     { WM_MOVE, sent|defwinproc },
2859     { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
2860     { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
2861     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2862     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2863     /* FIXME: Wine creates an icon/title window while Windows doesn't */
2864     { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
2865     { 0 }
2866 };
2867 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
2868 static const struct message WmRestoreMDIchildInisibleSeq[] = {
2869     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2870     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED  },
2871     { WM_NCCALCSIZE, sent|wparam, 1 },
2872     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2873     { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2874     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2875     { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2876      /* in MDI frame */
2877     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2878     { WM_NCCALCSIZE, sent|wparam, 1 },
2879     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2880     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2881     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2882     { 0 }
2883 };
2884
2885 static HWND mdi_client;
2886 static WNDPROC old_mdi_client_proc;
2887
2888 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2889 {
2890     struct message msg;
2891
2892     /* do not log painting messages */
2893     if (message != WM_PAINT &&
2894         message != WM_NCPAINT &&
2895         message != WM_SYNCPAINT &&
2896         message != WM_ERASEBKGND &&
2897         message != WM_NCHITTEST &&
2898         message != WM_GETTEXT &&
2899         message != WM_MDIGETACTIVE &&
2900         message != WM_GETICON &&
2901         message != WM_DEVICECHANGE)
2902     {
2903         trace("mdi client: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
2904
2905         switch (message)
2906         {
2907             case WM_WINDOWPOSCHANGING:
2908             case WM_WINDOWPOSCHANGED:
2909             {
2910                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2911
2912                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2913                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x ",
2914                       winpos->hwnd, winpos->hwndInsertAfter,
2915                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2916                 dump_winpos_flags(winpos->flags);
2917
2918                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2919                  * in the high word for internal purposes
2920                  */
2921                 wParam = winpos->flags & 0xffff;
2922                 /* We are not interested in the flags that don't match under XP and Win9x */
2923                 wParam &= ~(SWP_NOZORDER);
2924                 break;
2925             }
2926         }
2927
2928         msg.message = message;
2929         msg.flags = sent|wparam|lparam;
2930         msg.wParam = wParam;
2931         msg.lParam = lParam;
2932         add_message(&msg);
2933     }
2934
2935     return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
2936 }
2937
2938 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2939 {
2940     static long defwndproc_counter = 0;
2941     LRESULT ret;
2942     struct message msg;
2943
2944     /* do not log painting messages */
2945     if (message != WM_PAINT &&
2946         message != WM_NCPAINT &&
2947         message != WM_SYNCPAINT &&
2948         message != WM_ERASEBKGND &&
2949         message != WM_NCHITTEST &&
2950         message != WM_GETTEXT &&
2951         message != WM_GETICON &&
2952         message != WM_DEVICECHANGE)
2953     {
2954         trace("mdi child: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
2955
2956         switch (message)
2957         {
2958             case WM_WINDOWPOSCHANGING:
2959             case WM_WINDOWPOSCHANGED:
2960             {
2961                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2962
2963                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2964                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x ",
2965                       winpos->hwnd, winpos->hwndInsertAfter,
2966                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2967                 dump_winpos_flags(winpos->flags);
2968
2969                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2970                  * in the high word for internal purposes
2971                  */
2972                 wParam = winpos->flags & 0xffff;
2973                 /* We are not interested in the flags that don't match under XP and Win9x */
2974                 wParam &= ~(SWP_NOZORDER);
2975                 break;
2976             }
2977
2978             case WM_MDIACTIVATE:
2979             {
2980                 HWND active, client = GetParent(hwnd);
2981
2982                 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
2983
2984                 if (hwnd == (HWND)lParam) /* if we are being activated */
2985                     ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
2986                 else
2987                     ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
2988                 break;
2989             }
2990         }
2991
2992         msg.message = message;
2993         msg.flags = sent|wparam|lparam;
2994         if (defwndproc_counter) msg.flags |= defwinproc;
2995         msg.wParam = wParam;
2996         msg.lParam = lParam;
2997         add_message(&msg);
2998     }
2999
3000     defwndproc_counter++;
3001     ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
3002     defwndproc_counter--;
3003
3004     return ret;
3005 }
3006
3007 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3008 {
3009     static long defwndproc_counter = 0;
3010     LRESULT ret;
3011     struct message msg;
3012
3013     /* do not log painting messages */
3014     if (message != WM_PAINT &&
3015         message != WM_NCPAINT &&
3016         message != WM_SYNCPAINT &&
3017         message != WM_ERASEBKGND &&
3018         message != WM_NCHITTEST &&
3019         message != WM_GETTEXT &&
3020         message != WM_GETICON &&
3021         message != WM_DEVICECHANGE &&
3022         message < 0xc000)
3023     {
3024         trace("mdi frame: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
3025
3026         switch (message)
3027         {
3028             case WM_WINDOWPOSCHANGING:
3029             case WM_WINDOWPOSCHANGED:
3030             {
3031                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
3032
3033                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
3034                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x ",
3035                       winpos->hwnd, winpos->hwndInsertAfter,
3036                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
3037                 dump_winpos_flags(winpos->flags);
3038
3039                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
3040                  * in the high word for internal purposes
3041                  */
3042                 wParam = winpos->flags & 0xffff;
3043                 /* We are not interested in the flags that don't match under XP and Win9x */
3044                 wParam &= ~(SWP_NOZORDER);
3045                 break;
3046             }
3047         }
3048
3049         msg.message = message;
3050         msg.flags = sent|wparam|lparam;
3051         if (defwndproc_counter) msg.flags |= defwinproc;
3052         msg.wParam = wParam;
3053         msg.lParam = lParam;
3054         add_message(&msg);
3055     }
3056
3057     defwndproc_counter++;
3058     ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
3059     defwndproc_counter--;
3060
3061     return ret;
3062 }
3063
3064 static BOOL mdi_RegisterWindowClasses(void)
3065 {
3066     WNDCLASSA cls;
3067
3068     cls.style = 0;
3069     cls.lpfnWndProc = mdi_frame_wnd_proc;
3070     cls.cbClsExtra = 0;
3071     cls.cbWndExtra = 0;
3072     cls.hInstance = GetModuleHandleA(0);
3073     cls.hIcon = 0;
3074     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3075     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3076     cls.lpszMenuName = NULL;
3077     cls.lpszClassName = "MDI_frame_class";
3078     if (!RegisterClassA(&cls)) return FALSE;
3079
3080     cls.lpfnWndProc = mdi_child_wnd_proc;
3081     cls.lpszClassName = "MDI_child_class";
3082     if (!RegisterClassA(&cls)) return FALSE;
3083
3084     if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
3085     old_mdi_client_proc = cls.lpfnWndProc;
3086     cls.hInstance = GetModuleHandleA(0);
3087     cls.lpfnWndProc = mdi_client_hook_proc;
3088     cls.lpszClassName = "MDI_client_class";
3089     if (!RegisterClassA(&cls)) assert(0);
3090
3091     return TRUE;
3092 }
3093
3094 static void test_mdi_messages(void)
3095 {
3096     MDICREATESTRUCTA mdi_cs;
3097     CLIENTCREATESTRUCT client_cs;
3098     HWND mdi_frame, mdi_child, mdi_child2, active_child;
3099     BOOL zoomed;
3100     HMENU hMenu = CreateMenu();
3101
3102     assert(mdi_RegisterWindowClasses());
3103
3104     flush_sequence();
3105
3106     trace("creating MDI frame window\n");
3107     mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
3108                                 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3109                                 WS_MAXIMIZEBOX | WS_VISIBLE,
3110                                 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
3111                                 GetDesktopWindow(), hMenu,
3112                                 GetModuleHandleA(0), NULL);
3113     assert(mdi_frame);
3114     ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
3115
3116     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3117     ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
3118
3119     trace("creating MDI client window\n");
3120     client_cs.hWindowMenu = 0;
3121     client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
3122     mdi_client = CreateWindowExA(0, "MDI_client_class",
3123                                  NULL,
3124                                  WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
3125                                  0, 0, 0, 0,
3126                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3127     assert(mdi_client);
3128     ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
3129
3130     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3131     ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
3132
3133     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3134     ok(!active_child, "wrong active MDI child %p\n", active_child);
3135     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3136
3137     SetFocus(0);
3138     flush_sequence();
3139
3140     trace("creating invisible MDI child window\n");
3141     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3142                                 WS_CHILD,
3143                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3144                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3145     assert(mdi_child);
3146
3147     flush_sequence();
3148     ShowWindow(mdi_child, SW_SHOWNORMAL);
3149     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
3150
3151     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3152     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3153
3154     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3155     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3156
3157     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3158     ok(!active_child, "wrong active MDI child %p\n", active_child);
3159     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3160
3161     ShowWindow(mdi_child, SW_HIDE);
3162     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
3163     flush_sequence();
3164
3165     ShowWindow(mdi_child, SW_SHOW);
3166     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
3167
3168     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3169     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3170
3171     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3172     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3173
3174     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3175     ok(!active_child, "wrong active MDI child %p\n", active_child);
3176     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3177
3178     DestroyWindow(mdi_child);
3179     flush_sequence();
3180
3181     trace("creating visible MDI child window\n");
3182     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3183                                 WS_CHILD | WS_VISIBLE,
3184                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3185                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3186     assert(mdi_child);
3187     ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
3188
3189     ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3190     ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3191
3192     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3193     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3194
3195     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3196     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3197     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3198     flush_sequence();
3199
3200     DestroyWindow(mdi_child);
3201     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3202
3203     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3204     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3205
3206     /* Win2k: MDI client still returns a just destroyed child as active
3207      * Win9x: MDI client returns 0
3208      */
3209     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3210     ok(active_child == mdi_child || /* win2k */
3211        !active_child, /* win9x */
3212        "wrong active MDI child %p\n", active_child);
3213     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3214
3215     flush_sequence();
3216
3217     trace("creating invisible MDI child window\n");
3218     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3219                                 WS_CHILD,
3220                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3221                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3222     assert(mdi_child2);
3223     ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
3224
3225     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
3226     ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
3227
3228     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3229     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3230
3231     /* Win2k: MDI client still returns a just destroyed child as active
3232      * Win9x: MDI client returns mdi_child2
3233      */
3234     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3235     ok(active_child == mdi_child || /* win2k */
3236        active_child == mdi_child2, /* win9x */
3237        "wrong active MDI child %p\n", active_child);
3238     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3239     flush_sequence();
3240
3241     ShowWindow(mdi_child2, SW_MAXIMIZE);
3242     ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3243
3244     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3245     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3246
3247     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3248     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3249     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3250     flush_sequence();
3251
3252     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3253     ok(GetFocus() == mdi_child2 || /* win2k */
3254        GetFocus() == 0, /* win9x */
3255        "wrong focus window %p\n", GetFocus());
3256
3257     SetFocus(0);
3258     flush_sequence();
3259
3260     ShowWindow(mdi_child2, SW_HIDE);
3261     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3262
3263     ShowWindow(mdi_child2, SW_RESTORE);
3264     ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3265     flush_sequence();
3266
3267     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3268     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3269
3270     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3271     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3272     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3273     flush_sequence();
3274
3275     SetFocus(0);
3276     flush_sequence();
3277
3278     ShowWindow(mdi_child2, SW_HIDE);
3279     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3280
3281     ShowWindow(mdi_child2, SW_SHOW);
3282     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3283
3284     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3285     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3286
3287     ShowWindow(mdi_child2, SW_MAXIMIZE);
3288     ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3289
3290     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3291     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3292
3293     ShowWindow(mdi_child2, SW_RESTORE);
3294     ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3295
3296     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3297     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3298
3299     ShowWindow(mdi_child2, SW_MINIMIZE);
3300     ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3301
3302     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3303     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3304
3305     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3306     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3307     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3308     flush_sequence();
3309
3310     ShowWindow(mdi_child2, SW_RESTORE);
3311     ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", TRUE);
3312
3313     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3314     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3315
3316     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3317     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3318     ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3319     flush_sequence();
3320
3321     SetFocus(0);
3322     flush_sequence();
3323
3324     ShowWindow(mdi_child2, SW_HIDE);
3325     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3326
3327     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3328     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3329
3330     DestroyWindow(mdi_child2);
3331     ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3332
3333     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3334     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3335
3336     /* test for maximized MDI children */
3337     trace("creating maximized visible MDI child window 1\n");
3338     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3339                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3340                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3341                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3342     assert(mdi_child);
3343     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3344     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3345
3346     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3347     ok(GetFocus() == mdi_child || /* win2k */
3348        GetFocus() == 0, /* win9x */
3349        "wrong focus window %p\n", GetFocus());
3350
3351     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3352     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3353     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3354     flush_sequence();
3355
3356     trace("creating maximized visible MDI child window 2\n");
3357     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3358                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3359                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3360                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3361     assert(mdi_child2);
3362     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3363     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3364     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3365
3366     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3367     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3368
3369     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3370     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3371     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3372     flush_sequence();
3373
3374     trace("destroying maximized visible MDI child window 2\n");
3375     DestroyWindow(mdi_child2);
3376     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3377
3378     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3379
3380     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3381     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3382
3383     /* Win2k: MDI client still returns a just destroyed child as active
3384      * Win9x: MDI client returns 0
3385      */
3386     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3387     ok(active_child == mdi_child2 || /* win2k */
3388        !active_child, /* win9x */
3389        "wrong active MDI child %p\n", active_child);
3390     flush_sequence();
3391
3392     ShowWindow(mdi_child, SW_MAXIMIZE);
3393     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3394     flush_sequence();
3395
3396     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3397     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3398
3399     trace("re-creating maximized visible MDI child window 2\n");
3400     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3401                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3402                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3403                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3404     assert(mdi_child2);
3405     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3406     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3407     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3408
3409     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3410     ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3411
3412     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3413     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3414     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3415     flush_sequence();
3416
3417     SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3418     ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3419     ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3420
3421     ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3422     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3423     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3424
3425     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3426     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3427     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3428     flush_sequence();
3429
3430     DestroyWindow(mdi_child);
3431     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3432
3433     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3434     ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3435
3436     /* Win2k: MDI client still returns a just destroyed child as active
3437      * Win9x: MDI client returns 0
3438      */
3439     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3440     ok(active_child == mdi_child || /* win2k */
3441        !active_child, /* win9x */
3442        "wrong active MDI child %p\n", active_child);
3443     flush_sequence();
3444
3445     trace("creating maximized invisible MDI child window\n");
3446     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3447                                 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3448                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3449                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3450     assert(mdi_child2);
3451     ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", FALSE);
3452     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3453     ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3454     ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3455
3456     /* Win2k: MDI client still returns a just destroyed child as active
3457      * Win9x: MDI client returns 0
3458      */
3459     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3460     ok(active_child == mdi_child || /* win2k */
3461        !active_child, /* win9x */
3462        "wrong active MDI child %p\n", active_child);
3463     flush_sequence();
3464
3465     trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3466     ShowWindow(mdi_child2, SW_MAXIMIZE);
3467     ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3468     ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3469     ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3470     ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3471
3472     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3473     ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3474     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3475     flush_sequence();
3476
3477     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3478     flush_sequence();
3479
3480     /* end of test for maximized MDI children */
3481     SetFocus(0);
3482     flush_sequence();
3483     trace("creating maximized visible MDI child window 1(Switch test)\n");
3484     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3485                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3486                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3487                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3488     assert(mdi_child);
3489     ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3490     ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3491
3492     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3493     ok(GetFocus() == mdi_child || /* win2k */
3494        GetFocus() == 0, /* win9x */
3495        "wrong focus window %p(Switch test)\n", GetFocus());
3496
3497     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3498     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3499     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3500     flush_sequence();
3501
3502     trace("creating maximized visible MDI child window 2(Switch test)\n");
3503     mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3504                                 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3505                                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3506                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3507     assert(mdi_child2);
3508     ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3509
3510     ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3511     ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3512
3513     ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3514     ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3515
3516     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3517     ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3518     ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3519     flush_sequence();
3520
3521     trace("Switch child window.\n");
3522     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3523     ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3524     trace("end of test for switch maximized MDI children\n");
3525     flush_sequence();
3526
3527     /* Prepare for switching test of not maximized MDI children  */
3528     ShowWindow( mdi_child, SW_NORMAL );
3529     ok(!IsZoomed(mdi_child), "wrong zoomed state for %p(Switch test)\n", mdi_child);
3530     ok(!IsZoomed(mdi_child2), "wrong zoomed state for %p(Switch test)\n", mdi_child2);
3531     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
3532     ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3533     flush_sequence();
3534
3535     SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child2, 0);
3536     ok_sequence(WmSwitchNotMaximizedChild, "Not maximized child did not switch correctly", FALSE);
3537     trace("end of test for switch not maximized MDI children\n");
3538     flush_sequence();
3539
3540     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3541     flush_sequence();
3542
3543     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3544     flush_sequence();
3545
3546     SetFocus(0);
3547     flush_sequence();
3548     /* end of tests for switch maximized/not maximized MDI children */
3549
3550     mdi_cs.szClass = "MDI_child_Class";
3551     mdi_cs.szTitle = "MDI child";
3552     mdi_cs.hOwner = GetModuleHandleA(0);
3553     mdi_cs.x = 0;
3554     mdi_cs.y = 0;
3555     mdi_cs.cx = CW_USEDEFAULT;
3556     mdi_cs.cy = CW_USEDEFAULT;
3557     mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3558     mdi_cs.lParam = 0;
3559     mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3560     ok(mdi_child != 0, "MDI child creation failed\n");
3561     ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3562
3563     ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3564
3565     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3566     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3567
3568     ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3569     ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3570     ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3571
3572     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3573     ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3574     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3575     flush_sequence();
3576
3577     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3578     ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3579
3580     ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3581     active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3582     ok(!active_child, "wrong active MDI child %p\n", active_child);
3583
3584     SetFocus(0);
3585     flush_sequence();
3586
3587     DestroyWindow(mdi_client);
3588     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3589
3590     /* test maximization of MDI child with invisible parent */
3591     client_cs.hWindowMenu = 0;
3592     mdi_client = CreateWindow("MDI_client_class",
3593                                  NULL,
3594                                  WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3595                                  0, 0, 660, 430,
3596                                  mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3597     ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3598
3599     ShowWindow(mdi_client, SW_HIDE);
3600     ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3601
3602     mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3603                                 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3604                                 0, 0, 650, 440,
3605                                 mdi_client, 0, GetModuleHandleA(0), NULL);
3606     ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3607
3608     SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3609     ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3610     zoomed = IsZoomed(mdi_child);
3611     ok(zoomed, "wrong zoomed state %d\n", zoomed);
3612     
3613     ShowWindow(mdi_client, SW_SHOW);
3614     ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3615
3616     DestroyWindow(mdi_child);
3617     ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3618
3619     /* end of test for maximization of MDI child with invisible parent */
3620
3621     DestroyWindow(mdi_client);
3622     ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3623
3624     DestroyWindow(mdi_frame);
3625     ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3626 }
3627 /************************* End of MDI test **********************************/
3628
3629 static void test_WM_SETREDRAW(HWND hwnd)
3630 {
3631     DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3632
3633     flush_events();
3634     flush_sequence();
3635
3636     SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3637     ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3638
3639     ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3640     ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3641
3642     flush_sequence();
3643     SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3644     ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3645
3646     ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3647     ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3648
3649     /* restore original WS_VISIBLE state */
3650     SetWindowLongA(hwnd, GWL_STYLE, style);
3651
3652     flush_events();
3653     flush_sequence();
3654 }
3655
3656 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3657 {
3658     struct message msg;
3659
3660     trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
3661
3662     /* explicitly ignore WM_GETICON message */
3663     if (message == WM_GETICON) return 0;
3664
3665     /* ignore registered messages */
3666     if (message >= 0xc000) return 0;
3667
3668     switch (message)
3669     {
3670         /* ignore */
3671         case WM_MOUSEMOVE:
3672         case WM_SETCURSOR:
3673         case WM_DEVICECHANGE:
3674             return 0;
3675         case WM_NCHITTEST:
3676             return HTCLIENT;
3677
3678         case WM_WINDOWPOSCHANGING:
3679         case WM_WINDOWPOSCHANGED:
3680         {
3681             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
3682
3683             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
3684             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x ",
3685                   winpos->hwnd, winpos->hwndInsertAfter,
3686                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
3687             dump_winpos_flags(winpos->flags);
3688
3689             /* Log only documented flags, win2k uses 0x1000 and 0x2000
3690              * in the high word for internal purposes
3691              */
3692             wParam = winpos->flags & 0xffff;
3693             /* We are not interested in the flags that don't match under XP and Win9x */
3694             wParam &= ~(SWP_NOZORDER);
3695             break;
3696         }
3697     }
3698
3699     msg.message = message;
3700     msg.flags = sent|wparam|lparam;
3701     msg.wParam = wParam;
3702     msg.lParam = lParam;
3703     add_message(&msg);
3704
3705     if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3706     if (message == WM_TIMER) EndDialog( hwnd, 0 );
3707     return 0;
3708 }
3709
3710 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3711 {
3712     DWORD style, exstyle;
3713     INT xmin, xmax;
3714     BOOL ret;
3715
3716     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3717     style = GetWindowLongA(hwnd, GWL_STYLE);
3718     /* do not be confused by WS_DLGFRAME set */
3719     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3720
3721     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3722     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3723
3724     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3725     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3726     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3727         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3728     else
3729         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3730
3731     style = GetWindowLongA(hwnd, GWL_STYLE);
3732     if (set) ok(style & set, "style %08x should be set\n", set);
3733     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3734
3735     /* a subsequent call should do nothing */
3736     ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3737     ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3738     ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3739
3740     xmin = 0xdeadbeef;
3741     xmax = 0xdeadbeef;
3742     trace("Ignore GetScrollRange error below if you are on Win9x\n");
3743     ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
3744     ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
3745     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3746     ok(xmin == min, "unexpected min scroll value %d\n", xmin);
3747     ok(xmax == max, "unexpected max scroll value %d\n", xmax);
3748 }
3749
3750 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3751 {
3752     DWORD style, exstyle;
3753     SCROLLINFO si;
3754     BOOL ret;
3755
3756     exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3757     style = GetWindowLongA(hwnd, GWL_STYLE);
3758     /* do not be confused by WS_DLGFRAME set */
3759     if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3760
3761     if (clear) ok(style & clear, "style %08x should be set\n", clear);
3762     if (set) ok(!(style & set), "style %08x should not be set\n", set);
3763
3764     si.cbSize = sizeof(si);
3765     si.fMask = SIF_RANGE;
3766     si.nMin = min;
3767     si.nMax = max;
3768     SetScrollInfo(hwnd, ctl, &si, TRUE);
3769     if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3770         ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
3771     else
3772         ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
3773
3774     style = GetWindowLongA(hwnd, GWL_STYLE);
3775     if (set) ok(style & set, "style %08x should be set\n", set);
3776     if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3777
3778     /* a subsequent call should do nothing */
3779     SetScrollInfo(hwnd, ctl, &si, TRUE);
3780     if (style & WS_HSCROLL)
3781         ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3782     else if (style & WS_VSCROLL)
3783         ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3784     else
3785         ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3786
3787     si.fMask = SIF_PAGE;
3788     si.nPage = 5;
3789     SetScrollInfo(hwnd, ctl, &si, FALSE);
3790     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3791
3792     si.fMask = SIF_POS;
3793     si.nPos = max - 1;
3794     SetScrollInfo(hwnd, ctl, &si, FALSE);
3795     ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3796
3797     si.fMask = SIF_RANGE;
3798     si.nMin = 0xdeadbeef;
3799     si.nMax = 0xdeadbeef;
3800     ret = GetScrollInfo(hwnd, ctl, &si);
3801     ok( ret, "GetScrollInfo error %d\n", GetLastError());
3802     ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3803     ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
3804     ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
3805 }
3806
3807 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
3808 static void test_scroll_messages(HWND hwnd)
3809 {
3810     SCROLLINFO si;
3811     INT min, max;
3812     BOOL ret;
3813
3814     flush_events();
3815     flush_sequence();
3816
3817     min = 0xdeadbeef;
3818     max = 0xdeadbeef;
3819     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3820     ok( ret, "GetScrollRange error %d\n", GetLastError());
3821     if (sequence->message != WmGetScrollRangeSeq[0].message)
3822         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3823     /* values of min and max are undefined */
3824     flush_sequence();
3825
3826     ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
3827     ok( ret, "SetScrollRange error %d\n", GetLastError());
3828     if (sequence->message != WmSetScrollRangeSeq[0].message)
3829         trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3830     flush_sequence();
3831
3832     min = 0xdeadbeef;
3833     max = 0xdeadbeef;
3834     ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3835     ok( ret, "GetScrollRange error %d\n", GetLastError());
3836     if (sequence->message != WmGetScrollRangeSeq[0].message)
3837         trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3838     /* values of min and max are undefined */
3839     flush_sequence();
3840
3841     si.cbSize = sizeof(si);
3842     si.fMask = SIF_RANGE;
3843     si.nMin = 20;
3844     si.nMax = 160;
3845     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3846     if (sequence->message != WmSetScrollRangeSeq[0].message)
3847         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3848     flush_sequence();
3849
3850     si.fMask = SIF_PAGE;
3851     si.nPage = 10;
3852     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3853     if (sequence->message != WmSetScrollRangeSeq[0].message)
3854         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3855     flush_sequence();
3856
3857     si.fMask = SIF_POS;
3858     si.nPos = 20;
3859     SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3860     if (sequence->message != WmSetScrollRangeSeq[0].message)
3861         trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3862     flush_sequence();
3863
3864     si.fMask = SIF_RANGE;
3865     si.nMin = 0xdeadbeef;
3866     si.nMax = 0xdeadbeef;
3867     ret = GetScrollInfo(hwnd, SB_CTL, &si);
3868     ok( ret, "GetScrollInfo error %d\n", GetLastError());
3869     if (sequence->message != WmGetScrollInfoSeq[0].message)
3870         trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3871     /* values of min and max are undefined */
3872     flush_sequence();
3873
3874     /* set WS_HSCROLL */
3875     test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
3876     /* clear WS_HSCROLL */
3877     test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
3878
3879     /* set WS_HSCROLL */
3880     test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
3881     /* clear WS_HSCROLL */
3882     test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
3883
3884     /* set WS_VSCROLL */
3885     test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
3886     /* clear WS_VSCROLL */
3887     test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
3888
3889     /* set WS_VSCROLL */
3890     test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
3891     /* clear WS_VSCROLL */
3892     test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
3893 }
3894
3895 static void test_showwindow(void)
3896 {
3897     HWND hwnd, hchild;
3898     RECT rc;
3899
3900     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
3901                            100, 100, 200, 200, 0, 0, 0, NULL);
3902     ok (hwnd != 0, "Failed to create overlapped window\n");
3903     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
3904                              0, 0, 10, 10, hwnd, 0, 0, NULL);
3905     ok (hchild != 0, "Failed to create child\n");
3906     flush_sequence();
3907
3908     /* ShowWindow( SW_SHOWNA) for invisible top level window */
3909     trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
3910     ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3911     ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", TRUE);
3912     trace("done\n");
3913
3914     /* ShowWindow( SW_SHOWNA) for now visible top level window */
3915     trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
3916     ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3917     ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
3918     trace("done\n");
3919     /* back to invisible */
3920     ShowWindow(hchild, SW_HIDE);
3921     ShowWindow(hwnd, SW_HIDE);
3922     flush_sequence();
3923     /* ShowWindow(SW_SHOWNA) with child and parent invisible */ 
3924     trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
3925     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3926     ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
3927     trace("done\n");
3928     /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */ 
3929     ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
3930     flush_sequence();
3931     trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
3932     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3933     ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
3934     trace("done\n");
3935     /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
3936     ShowWindow( hwnd, SW_SHOW);
3937     flush_sequence();
3938     trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
3939     ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3940     ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
3941     trace("done\n");
3942
3943     /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
3944     ShowWindow( hchild, SW_HIDE);
3945     flush_sequence();
3946     trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
3947     ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3948     ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
3949     trace("done\n");
3950
3951     SetCapture(hchild);
3952     ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
3953     DestroyWindow(hchild);
3954     ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
3955
3956     DestroyWindow(hwnd);
3957     flush_sequence();
3958
3959     /* Popup windows */
3960     /* Test 1:
3961      * 1. Create invisible maximized popup window.
3962      * 2. Move and resize it.
3963      * 3. Show it maximized.
3964      */
3965     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
3966     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
3967                            100, 100, 200, 200, 0, 0, 0, NULL);
3968     ok (hwnd != 0, "Failed to create popup window\n");
3969     ok(IsZoomed(hwnd), "window should be maximized\n");
3970     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
3971     trace("done\n");
3972
3973     GetWindowRect(hwnd, &rc);
3974     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
3975         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
3976         "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
3977         rc.left, rc.top, rc.right, rc.bottom);
3978     /* Reset window's size & position */
3979     SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
3980     ok(IsZoomed(hwnd), "window should be maximized\n");
3981     flush_sequence();
3982
3983     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
3984     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3985     ok(IsZoomed(hwnd), "window should be maximized\n");
3986     ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
3987     trace("done\n");
3988
3989     GetWindowRect(hwnd, &rc);
3990     ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
3991         rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
3992         "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
3993         rc.left, rc.top, rc.right, rc.bottom);
3994     DestroyWindow(hwnd);
3995     flush_sequence();
3996
3997     /* Test 2:
3998      * 1. Create invisible maximized popup window.
3999      * 2. Show it maximized.
4000      */
4001     trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4002     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4003                            100, 100, 200, 200, 0, 0, 0, NULL);
4004     ok (hwnd != 0, "Failed to create popup window\n");
4005     ok(IsZoomed(hwnd), "window should be maximized\n");
4006     ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4007     trace("done\n");
4008
4009     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4010     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4011     ok(IsZoomed(hwnd), "window should be maximized\n");
4012     ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
4013     trace("done\n");
4014     DestroyWindow(hwnd);
4015     flush_sequence();
4016
4017     /* Test 3:
4018      * 1. Create visible maximized popup window.
4019      */
4020     trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
4021     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4022                            100, 100, 200, 200, 0, 0, 0, NULL);
4023     ok (hwnd != 0, "Failed to create popup window\n");
4024     ok(IsZoomed(hwnd), "window should be maximized\n");
4025     ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4026     trace("done\n");
4027     DestroyWindow(hwnd);
4028     flush_sequence();
4029
4030     /* Test 4:
4031      * 1. Create visible popup window.
4032      * 2. Maximize it.
4033      */
4034     trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
4035     hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
4036                            100, 100, 200, 200, 0, 0, 0, NULL);
4037     ok (hwnd != 0, "Failed to create popup window\n");
4038     ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
4039     ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
4040     trace("done\n");
4041
4042     trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
4043     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4044     ok(IsZoomed(hwnd), "window should be maximized\n");
4045     ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
4046     trace("done\n");
4047     DestroyWindow(hwnd);
4048     flush_sequence();
4049 }
4050
4051 static void test_sys_menu(void)
4052 {
4053     HWND hwnd;
4054     HMENU hmenu;
4055     UINT state;
4056
4057     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4058                            100, 100, 200, 200, 0, 0, 0, NULL);
4059     ok (hwnd != 0, "Failed to create overlapped window\n");
4060
4061     flush_sequence();
4062
4063     /* test existing window without CS_NOCLOSE style */
4064     hmenu = GetSystemMenu(hwnd, FALSE);
4065     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4066
4067     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4068     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4069     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4070
4071     EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
4072     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4073
4074     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4075     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4076     ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
4077
4078     EnableMenuItem(hmenu, SC_CLOSE, 0);
4079     ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4080
4081     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4082     ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4083     ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4084
4085     /* test whether removing WS_SYSMENU destroys a system menu */
4086     SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
4087     SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4088     flush_sequence();
4089     hmenu = GetSystemMenu(hwnd, FALSE);
4090     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4091
4092     DestroyWindow(hwnd);
4093
4094     /* test new window with CS_NOCLOSE style */
4095     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4096                            100, 100, 200, 200, 0, 0, 0, NULL);
4097     ok (hwnd != 0, "Failed to create overlapped window\n");
4098
4099     hmenu = GetSystemMenu(hwnd, FALSE);
4100     ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4101
4102     state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4103     ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4104
4105     DestroyWindow(hwnd);
4106
4107     /* test new window without WS_SYSMENU style */
4108     hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
4109                            100, 100, 200, 200, 0, 0, 0, NULL);
4110     ok(hwnd != 0, "Failed to create overlapped window\n");
4111
4112     hmenu = GetSystemMenu(hwnd, FALSE);
4113     ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
4114
4115     DestroyWindow(hwnd);
4116 }
4117
4118 /* For shown WS_OVERLAPPEDWINDOW */
4119 static const struct message WmSetIcon_1[] = {
4120     { WM_SETICON, sent },
4121     { 0x00AE, sent|defwinproc|optional }, /* XP */
4122     { WM_GETTEXT, sent|defwinproc|optional },
4123     { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
4124     { 0 }
4125 };
4126
4127 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
4128 static const struct message WmSetIcon_2[] = {
4129     { WM_SETICON, sent },
4130     { 0 }
4131 };
4132
4133 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4134 static const struct message WmInitEndSession[] = {
4135     { 0x003B, sent },
4136     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4137     { 0 }
4138 };
4139
4140 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4141 static const struct message WmInitEndSession_2[] = {
4142     { 0x003B, sent },
4143     { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4144     { 0 }
4145 };
4146
4147 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4148 static const struct message WmInitEndSession_3[] = {
4149     { 0x003B, sent },
4150     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4151     { 0 }
4152 };
4153
4154 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4155 static const struct message WmInitEndSession_4[] = {
4156     { 0x003B, sent },
4157     { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4158     { 0 }
4159 };
4160
4161 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4162 static const struct message WmInitEndSession_5[] = {
4163     { 0x003B, sent },
4164     { WM_ENDSESSION, sent|defwinproc/*|wparam*/|lparam, 1, ENDSESSION_LOGOFF },
4165     { 0 }
4166 };
4167
4168 static const struct message WmZOrder[] = {
4169     { WM_WINDOWPOSCHANGING, sent|wparam, 0, 0 },
4170     { WM_GETMINMAXINFO, sent|defwinproc|wparam, 0, 0 },
4171     { HCBT_ACTIVATE, hook },
4172     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
4173     { WM_WINDOWPOSCHANGING, sent|wparam, 3, 0 },
4174     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0 },
4175     { WM_GETTEXT, sent|optional },
4176     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
4177     { WM_ACTIVATEAPP, sent|wparam, 1, 0 },
4178     { WM_NCACTIVATE, sent|wparam|lparam, 1, 0 },
4179     { WM_GETTEXT, sent|defwinproc|optional },
4180     { WM_GETTEXT, sent|defwinproc|optional },
4181     { WM_ACTIVATE, sent|wparam|lparam, 1, 0 },
4182     { HCBT_SETFOCUS, hook },
4183     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4184     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4185     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4186     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
4187     { WM_GETTEXT, sent|optional },
4188     { WM_NCCALCSIZE, sent|optional },
4189     { 0 }
4190 };
4191
4192 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4193 {
4194     DWORD ret;
4195     MSG msg;
4196
4197     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4198     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4199
4200     PostMessageA(hwnd, WM_USER, 0, 0);
4201
4202     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4203     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4204
4205     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4206     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4207
4208     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4209     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4210
4211     PostMessageA(hwnd, WM_USER, 0, 0);
4212
4213     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4214     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4215
4216     ok(PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4217     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4218
4219     /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4220     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4221     ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4222
4223     PostMessageA(hwnd, WM_USER, 0, 0);
4224
4225     /* new incoming message causes it to become signaled again */
4226     ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4227     ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4228
4229     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4230     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4231     ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4232     ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4233 }
4234
4235 /* test if we receive the right sequence of messages */
4236 static void test_messages(void)
4237 {
4238     HWND hwnd, hparent, hchild;
4239     HWND hchild2, hbutton;
4240     HMENU hmenu;
4241     MSG msg;
4242     LRESULT res;
4243
4244     flush_sequence();
4245
4246     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4247                            100, 100, 200, 200, 0, 0, 0, NULL);
4248     ok (hwnd != 0, "Failed to create overlapped window\n");
4249     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4250
4251     /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4252     ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4253     ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4254
4255     /* test WM_SETREDRAW on a not visible top level window */
4256     test_WM_SETREDRAW(hwnd);
4257
4258     SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4259     flush_events();
4260     ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4261     ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4262
4263     ok(GetActiveWindow() == hwnd, "window should be active\n");
4264     ok(GetFocus() == hwnd, "window should have input focus\n");
4265     ShowWindow(hwnd, SW_HIDE);
4266     flush_events();
4267     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4268
4269     ShowWindow(hwnd, SW_SHOW);
4270     flush_events();
4271     ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4272
4273     ShowWindow(hwnd, SW_HIDE);
4274     flush_events();
4275     ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4276
4277     ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4278     flush_events();
4279     ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4280
4281     ShowWindow(hwnd, SW_RESTORE);
4282     ok_sequence(WmShowRestoreMaxOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", FALSE);
4283     flush_events();
4284     flush_sequence();
4285
4286     ShowWindow(hwnd, SW_MINIMIZE);
4287     flush_events();
4288     ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4289     flush_sequence();
4290
4291     ShowWindow(hwnd, SW_RESTORE);
4292     flush_events();
4293     ok_sequence(WmShowRestoreMinOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4294     flush_sequence();
4295
4296     ShowWindow(hwnd, SW_SHOW);
4297     flush_events();
4298     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4299
4300     ok(GetActiveWindow() == hwnd, "window should be active\n");
4301     ok(GetFocus() == hwnd, "window should have input focus\n");
4302     SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4303     ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4304     ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4305     ok(GetActiveWindow() == hwnd, "window should still be active\n");
4306
4307     /* test WM_SETREDRAW on a visible top level window */
4308     ShowWindow(hwnd, SW_SHOW);
4309     flush_events();
4310     test_WM_SETREDRAW(hwnd);
4311
4312     trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4313     test_scroll_messages(hwnd);
4314
4315     /* test resizing and moving */
4316     SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4317     ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4318     flush_events();
4319     flush_sequence();
4320     SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4321     ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4322     flush_events();
4323     flush_sequence();
4324     SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER|SWP_NOACTIVATE );
4325     ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4326     flush_events();
4327     flush_sequence();
4328
4329     /* popups don't get WM_GETMINMAXINFO */
4330     SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4331     SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4332     flush_sequence();
4333     SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4334     ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4335
4336     DestroyWindow(hwnd);
4337     ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4338
4339     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4340                               100, 100, 200, 200, 0, 0, 0, NULL);
4341     ok (hparent != 0, "Failed to create parent window\n");
4342     flush_sequence();
4343
4344     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4345                              0, 0, 10, 10, hparent, 0, 0, NULL);
4346     ok (hchild != 0, "Failed to create child window\n");
4347     ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4348     DestroyWindow(hchild);
4349     flush_sequence();
4350
4351     /* visible child window with a caption */
4352     hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4353                              WS_CHILD | WS_VISIBLE | WS_CAPTION,
4354                              0, 0, 10, 10, hparent, 0, 0, NULL);
4355     ok (hchild != 0, "Failed to create child window\n");
4356     ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4357
4358     trace("testing scroll APIs on a visible child window %p\n", hchild);
4359     test_scroll_messages(hchild);
4360
4361     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4362     ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4363
4364     DestroyWindow(hchild);
4365     flush_sequence();
4366
4367     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4368                              0, 0, 10, 10, hparent, 0, 0, NULL);
4369     ok (hchild != 0, "Failed to create child window\n");
4370     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4371     
4372     hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4373                                100, 100, 50, 50, hparent, 0, 0, NULL);
4374     ok (hchild2 != 0, "Failed to create child2 window\n");
4375     flush_sequence();
4376
4377     hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4378                               0, 100, 50, 50, hchild, 0, 0, NULL);
4379     ok (hbutton != 0, "Failed to create button window\n");
4380
4381     /* test WM_SETREDRAW on a not visible child window */
4382     test_WM_SETREDRAW(hchild);
4383
4384     ShowWindow(hchild, SW_SHOW);
4385     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4386
4387     /* check parent messages too */
4388     log_all_parent_messages++;
4389     ShowWindow(hchild, SW_HIDE);
4390     ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4391     log_all_parent_messages--;
4392
4393     ShowWindow(hchild, SW_SHOW);
4394     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4395
4396     ShowWindow(hchild, SW_HIDE);
4397     ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4398
4399     ShowWindow(hchild, SW_SHOW);
4400     ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4401
4402     /* test WM_SETREDRAW on a visible child window */
4403     test_WM_SETREDRAW(hchild);
4404
4405     log_all_parent_messages++;
4406     MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4407     ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4408     log_all_parent_messages--;
4409
4410     ShowWindow(hchild, SW_HIDE);
4411     flush_sequence();
4412     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4413     ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4414
4415     ShowWindow(hchild, SW_HIDE);
4416     flush_sequence();
4417     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4418     ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4419
4420     /* DestroyWindow sequence below expects that a child has focus */
4421     SetFocus(hchild);
4422     flush_sequence();
4423
4424     DestroyWindow(hchild);
4425     ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4426     DestroyWindow(hchild2);
4427     DestroyWindow(hbutton);
4428
4429     flush_sequence();
4430     hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4431                              0, 0, 100, 100, hparent, 0, 0, NULL);
4432     ok (hchild != 0, "Failed to create child popup window\n");
4433     ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4434     DestroyWindow(hchild);
4435
4436     /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4437     flush_sequence();
4438     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4439                              0, 0, 100, 100, hparent, 0, 0, NULL);
4440     ok (hchild != 0, "Failed to create popup window\n");
4441     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4442     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4443     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4444     flush_sequence();
4445     ShowWindow(hchild, SW_SHOW);
4446     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4447     flush_sequence();
4448     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4449     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4450     flush_sequence();
4451     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4452     ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
4453     DestroyWindow(hchild);
4454
4455     /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4456      * changes nothing in message sequences.
4457      */
4458     flush_sequence();
4459     hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4460                              0, 0, 100, 100, hparent, 0, 0, NULL);
4461     ok (hchild != 0, "Failed to create popup window\n");
4462     ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4463     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4464     ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4465     flush_sequence();
4466     ShowWindow(hchild, SW_SHOW);
4467     ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4468     flush_sequence();
4469     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4470     ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4471     DestroyWindow(hchild);
4472
4473     flush_sequence();
4474     hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4475                            0, 0, 100, 100, hparent, 0, 0, NULL);
4476     ok(hwnd != 0, "Failed to create custom dialog window\n");
4477     ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4478
4479     /*
4480     trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4481     test_scroll_messages(hwnd);
4482     */
4483
4484     flush_sequence();
4485
4486     test_def_id = 1;
4487     SendMessage(hwnd, WM_NULL, 0, 0);
4488
4489     flush_sequence();
4490     after_end_dialog = 1;
4491     EndDialog( hwnd, 0 );
4492     ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4493
4494     DestroyWindow(hwnd);
4495     after_end_dialog = 0;
4496     test_def_id = 0;
4497
4498     hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4499                            0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4500     ok(hwnd != 0, "Failed to create custom dialog window\n");
4501     flush_sequence();
4502     trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4503     ShowWindow(hwnd, SW_SHOW);
4504     ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4505     DestroyWindow(hwnd);
4506
4507     flush_sequence();
4508     DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4509     ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4510
4511     DestroyWindow(hparent);
4512     flush_sequence();
4513
4514     /* Message sequence for SetMenu */
4515     ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4516     ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4517
4518     hmenu = CreateMenu();
4519     ok (hmenu != 0, "Failed to create menu\n");
4520     ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4521     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4522                            100, 100, 200, 200, 0, hmenu, 0, NULL);
4523     ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4524     ok (SetMenu(hwnd, 0), "SetMenu\n");
4525     ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4526     ok (SetMenu(hwnd, 0), "SetMenu\n");
4527     ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4528     ShowWindow(hwnd, SW_SHOW);
4529     UpdateWindow( hwnd );
4530     flush_events();
4531     flush_sequence();
4532     ok (SetMenu(hwnd, 0), "SetMenu\n");
4533     ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4534     ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4535     ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4536
4537     UpdateWindow( hwnd );
4538     flush_events();
4539     flush_sequence();
4540     ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4541     flush_events();
4542     ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4543
4544     DestroyWindow(hwnd);
4545     flush_sequence();
4546
4547     /* Message sequence for EnableWindow */
4548     hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4549                               100, 100, 200, 200, 0, 0, 0, NULL);
4550     ok (hparent != 0, "Failed to create parent window\n");
4551     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4552                              0, 0, 10, 10, hparent, 0, 0, NULL);
4553     ok (hchild != 0, "Failed to create child window\n");
4554
4555     SetFocus(hchild);
4556     flush_events();
4557     flush_sequence();
4558
4559     EnableWindow(hparent, FALSE);
4560     ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4561
4562     EnableWindow(hparent, TRUE);
4563     ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4564
4565     flush_events();
4566     flush_sequence();
4567
4568     test_MsgWaitForMultipleObjects(hparent);
4569
4570     /* the following test causes an exception in user.exe under win9x */
4571     if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4572     {
4573         DestroyWindow(hparent);
4574         flush_sequence();
4575         return;
4576     }
4577     PostMessageW( hparent, WM_USER+1, 0, 0 );
4578     /* PeekMessage(NULL) fails, but still removes the message */
4579     SetLastError(0xdeadbeef);
4580     ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4581     ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4582         GetLastError() == 0xdeadbeef, /* NT4 */
4583         "last error is %d\n", GetLastError() );
4584     ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4585     ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4586
4587     DestroyWindow(hchild);
4588     DestroyWindow(hparent);
4589     flush_sequence();
4590
4591     /* Message sequences for WM_SETICON */
4592     trace("testing WM_SETICON\n");
4593     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4594                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4595                            NULL, NULL, 0);
4596     ShowWindow(hwnd, SW_SHOW);
4597     UpdateWindow(hwnd);
4598     flush_events();
4599     flush_sequence();
4600     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4601     ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4602
4603     ShowWindow(hwnd, SW_HIDE);
4604     flush_events();
4605     flush_sequence();
4606     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4607     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4608     DestroyWindow(hwnd);
4609     flush_sequence();
4610
4611     hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4612                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4613                            NULL, NULL, 0);
4614     ShowWindow(hwnd, SW_SHOW);
4615     UpdateWindow(hwnd);
4616     flush_events();
4617     flush_sequence();
4618     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4619     ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4620
4621     ShowWindow(hwnd, SW_HIDE);
4622     flush_events();
4623     flush_sequence();
4624     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4625     ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4626
4627     flush_sequence();
4628     res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4629     if (!res)
4630     {
4631         todo_wine win_skip( "Message 0x3b not supported\n" );
4632         goto done;
4633     }
4634     ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4635     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4636     res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4637     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4638     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4639     res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4640     ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4641     ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4642
4643     flush_sequence();
4644     res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4645     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4646     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4647     res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4648     ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4649     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4650
4651     res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4652     ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4653     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4654
4655     res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4656     ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4657     ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4658
4659 done:
4660     DestroyWindow(hwnd);
4661     flush_sequence();
4662 }
4663
4664 static void test_setwindowpos(void)
4665 {
4666     HWND hwnd;
4667     RECT rc;
4668     LRESULT res;
4669     const INT winX = 100;
4670     const INT winY = 100;
4671     const INT sysX = GetSystemMetrics(SM_CXMINTRACK);
4672
4673     hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
4674                            0, 0, winX, winY, 0,
4675                            NULL, NULL, 0);
4676
4677     GetWindowRect(hwnd, &rc);
4678     expect(sysX, rc.right);
4679     expect(winY, rc.bottom);
4680
4681     flush_events();
4682     flush_sequence();
4683     res = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, winX, winY, 0);
4684     ok_sequence(WmZOrder, "Z-Order", TRUE);
4685     ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
4686
4687     GetWindowRect(hwnd, &rc);
4688     expect(sysX, rc.right);
4689     expect(winY, rc.bottom);
4690     DestroyWindow(hwnd);
4691 }
4692
4693 static void invisible_parent_tests(void)
4694 {
4695     HWND hparent, hchild;
4696
4697     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4698                               100, 100, 200, 200, 0, 0, 0, NULL);
4699     ok (hparent != 0, "Failed to create parent window\n");
4700     flush_sequence();
4701
4702     /* test showing child with hidden parent */
4703
4704     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4705                              0, 0, 10, 10, hparent, 0, 0, NULL);
4706     ok (hchild != 0, "Failed to create child window\n");
4707     ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4708
4709     ShowWindow( hchild, SW_MINIMIZE );
4710     ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4711     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4712     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4713
4714     /* repeat */
4715     flush_events();
4716     flush_sequence();
4717     ShowWindow( hchild, SW_MINIMIZE );
4718     ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4719
4720     DestroyWindow(hchild);
4721     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4722                              0, 0, 10, 10, hparent, 0, 0, NULL);
4723     flush_sequence();
4724
4725     ShowWindow( hchild, SW_MAXIMIZE );
4726     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4727     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4728     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4729
4730     /* repeat */
4731     flush_events();
4732     flush_sequence();
4733     ShowWindow( hchild, SW_MAXIMIZE );
4734     ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4735
4736     DestroyWindow(hchild);
4737     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4738                              0, 0, 10, 10, hparent, 0, 0, NULL);
4739     flush_sequence();
4740
4741     ShowWindow( hchild, SW_RESTORE );
4742     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
4743     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4744     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4745
4746     DestroyWindow(hchild);
4747     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4748                              0, 0, 10, 10, hparent, 0, 0, NULL);
4749     flush_sequence();
4750
4751     ShowWindow( hchild, SW_SHOWMINIMIZED );
4752     ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4753     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4754     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4755
4756     /* repeat */
4757     flush_events();
4758     flush_sequence();
4759     ShowWindow( hchild, SW_SHOWMINIMIZED );
4760     ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4761
4762     DestroyWindow(hchild);
4763     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4764                              0, 0, 10, 10, hparent, 0, 0, NULL);
4765     flush_sequence();
4766
4767     /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
4768     ShowWindow( hchild, SW_SHOWMAXIMIZED );
4769     ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
4770     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4771     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4772
4773     DestroyWindow(hchild);
4774     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4775                              0, 0, 10, 10, hparent, 0, 0, NULL);
4776     flush_sequence();
4777
4778     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4779     ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4780     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4781     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4782
4783     /* repeat */
4784     flush_events();
4785     flush_sequence();
4786     ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4787     ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4788
4789     DestroyWindow(hchild);
4790     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4791                              0, 0, 10, 10, hparent, 0, 0, NULL);
4792     flush_sequence();
4793
4794     /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
4795     ShowWindow( hchild, SW_FORCEMINIMIZE );
4796     ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
4797 todo_wine {
4798     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4799 }
4800     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4801
4802     DestroyWindow(hchild);
4803     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4804                              0, 0, 10, 10, hparent, 0, 0, NULL);
4805     flush_sequence();
4806
4807     ShowWindow( hchild, SW_SHOWNA );
4808     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4809     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4810     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4811
4812     /* repeat */
4813     flush_events();
4814     flush_sequence();
4815     ShowWindow( hchild, SW_SHOWNA );
4816     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4817
4818     DestroyWindow(hchild);
4819     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4820                              0, 0, 10, 10, hparent, 0, 0, NULL);
4821     flush_sequence();
4822
4823     ShowWindow( hchild, SW_SHOW );
4824     ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4825     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4826     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4827
4828     /* repeat */
4829     flush_events();
4830     flush_sequence();
4831     ShowWindow( hchild, SW_SHOW );
4832     ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4833
4834     ShowWindow( hchild, SW_HIDE );
4835     ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
4836     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4837     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4838
4839     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4840     ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
4841     ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4842     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4843
4844     SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4845     ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
4846     ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
4847     ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4848
4849     SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4850     flush_sequence();
4851     DestroyWindow(hchild);
4852     ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
4853
4854     DestroyWindow(hparent);
4855     flush_sequence();
4856 }
4857
4858 /****************** button message test *************************/
4859 static const struct message WmSetFocusButtonSeq[] =
4860 {
4861     { HCBT_SETFOCUS, hook },
4862     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
4863     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4864     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4865     { WM_SETFOCUS, sent|wparam, 0 },
4866     { WM_CTLCOLORBTN, sent|defwinproc },
4867     { 0 }
4868 };
4869 static const struct message WmKillFocusButtonSeq[] =
4870 {
4871     { HCBT_SETFOCUS, hook },
4872     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4873     { WM_KILLFOCUS, sent|wparam, 0 },
4874     { WM_CTLCOLORBTN, sent|defwinproc },
4875     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
4876     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
4877     { 0 }
4878 };
4879 static const struct message WmSetFocusStaticSeq[] =
4880 {
4881     { HCBT_SETFOCUS, hook },
4882     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
4883     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4884     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4885     { WM_SETFOCUS, sent|wparam, 0 },
4886     { WM_CTLCOLORSTATIC, sent|defwinproc },
4887     { 0 }
4888 };
4889 static const struct message WmKillFocusStaticSeq[] =
4890 {
4891     { HCBT_SETFOCUS, hook },
4892     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4893     { WM_KILLFOCUS, sent|wparam, 0 },
4894     { WM_CTLCOLORSTATIC, sent|defwinproc },
4895     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
4896     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
4897     { 0 }
4898 };
4899 static const struct message WmLButtonDownSeq[] =
4900 {
4901     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
4902     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
4903     { HCBT_SETFOCUS, hook },
4904     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4905     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4906     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4907     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4908     { WM_CTLCOLORBTN, sent|defwinproc },
4909     { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
4910     { WM_CTLCOLORBTN, sent|defwinproc },
4911     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4912     { 0 }
4913 };
4914 static const struct message WmLButtonUpSeq[] =
4915 {
4916     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
4917     { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
4918     { WM_CTLCOLORBTN, sent|defwinproc },
4919     { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4920     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
4921     { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
4922     { 0 }
4923 };
4924 static const struct message WmSetFontButtonSeq[] =
4925 {
4926     { WM_SETFONT, sent },
4927     { WM_PAINT, sent },
4928     { WM_ERASEBKGND, sent|defwinproc|optional },
4929     { WM_CTLCOLORBTN, sent|defwinproc },
4930     { 0 }
4931 };
4932
4933 static WNDPROC old_button_proc;
4934
4935 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4936 {
4937     static long defwndproc_counter = 0;
4938     LRESULT ret;
4939     struct message msg;
4940
4941     trace("button: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
4942
4943     /* explicitly ignore WM_GETICON message */
4944     if (message == WM_GETICON) return 0;
4945
4946     /* ignore registered messages */
4947     if (message >= 0xc000) return 0;
4948
4949     msg.message = message;
4950     msg.flags = sent|wparam|lparam;
4951     if (defwndproc_counter) msg.flags |= defwinproc;
4952     msg.wParam = wParam;
4953     msg.lParam = lParam;
4954     add_message(&msg);
4955
4956     if (message == BM_SETSTATE)
4957         ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
4958
4959     defwndproc_counter++;
4960     ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
4961     defwndproc_counter--;
4962
4963     return ret;
4964 }
4965
4966 static void subclass_button(void)
4967 {
4968     WNDCLASSA cls;
4969
4970     if (!GetClassInfoA(0, "button", &cls)) assert(0);
4971
4972     old_button_proc = cls.lpfnWndProc;
4973
4974     cls.hInstance = GetModuleHandle(0);
4975     cls.lpfnWndProc = button_hook_proc;
4976     cls.lpszClassName = "my_button_class";
4977     UnregisterClass(cls.lpszClassName, cls.hInstance);
4978     if (!RegisterClassA(&cls)) assert(0);
4979 }
4980
4981 static void test_button_messages(void)
4982 {
4983     static const struct
4984     {
4985         DWORD style;
4986         DWORD dlg_code;
4987         const struct message *setfocus;
4988         const struct message *killfocus;
4989     } button[] = {
4990         { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
4991           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
4992         { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
4993           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
4994         { BS_CHECKBOX, DLGC_BUTTON,
4995           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4996         { BS_AUTOCHECKBOX, DLGC_BUTTON,
4997           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4998         { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
4999           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5000         { BS_3STATE, DLGC_BUTTON,
5001           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5002         { BS_AUTO3STATE, DLGC_BUTTON,
5003           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5004         { BS_GROUPBOX, DLGC_STATIC,
5005           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5006         { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5007           WmSetFocusButtonSeq, WmKillFocusButtonSeq },
5008         { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5009           WmSetFocusStaticSeq, WmKillFocusStaticSeq },
5010         { BS_OWNERDRAW, DLGC_BUTTON,
5011           WmSetFocusButtonSeq, WmKillFocusButtonSeq }
5012     };
5013     unsigned int i;
5014     HWND hwnd;
5015     DWORD dlg_code;
5016     HFONT zfont;
5017
5018     subclass_button();
5019
5020     for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
5021     {
5022         hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_POPUP,
5023                                0, 0, 50, 14, 0, 0, 0, NULL);
5024         ok(hwnd != 0, "Failed to create button window\n");
5025
5026         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5027         ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5028
5029         ShowWindow(hwnd, SW_SHOW);
5030         UpdateWindow(hwnd);
5031         SetFocus(0);
5032         flush_sequence();
5033
5034         trace("button style %08x\n", button[i].style);
5035         SetFocus(hwnd);
5036         ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
5037
5038         SetFocus(0);
5039         ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
5040
5041         DestroyWindow(hwnd);
5042     }
5043
5044     hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
5045                            0, 0, 50, 14, 0, 0, 0, NULL);
5046     ok(hwnd != 0, "Failed to create button window\n");
5047
5048     SetFocus(0);
5049     flush_events();
5050     flush_sequence();
5051
5052     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
5053     ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
5054
5055     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
5056     ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
5057
5058     flush_sequence();
5059     zfont = (HFONT)GetStockObject(SYSTEM_FONT);
5060     SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
5061     UpdateWindow(hwnd);
5062     ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
5063
5064     DestroyWindow(hwnd);
5065 }
5066
5067 /****************** static message test *************************/
5068 static const struct message WmSetFontStaticSeq[] =
5069 {
5070     { WM_SETFONT, sent },
5071     { WM_PAINT, sent|defwinproc },
5072     { WM_ERASEBKGND, sent|defwinproc|optional },
5073     { WM_CTLCOLORSTATIC, sent|defwinproc },
5074     { 0 }
5075 };
5076
5077 static WNDPROC old_static_proc;
5078
5079 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5080 {
5081     static long defwndproc_counter = 0;
5082     LRESULT ret;
5083     struct message msg;
5084
5085     trace("static: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
5086
5087     /* explicitly ignore WM_GETICON message */
5088     if (message == WM_GETICON) return 0;
5089
5090     /* ignore registered messages */
5091     if (message >= 0xc000) return 0;
5092
5093     msg.message = message;
5094     msg.flags = sent|wparam|lparam;
5095     if (defwndproc_counter) msg.flags |= defwinproc;
5096     msg.wParam = wParam;
5097     msg.lParam = lParam;
5098     add_message(&msg);
5099
5100     defwndproc_counter++;
5101     ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
5102     defwndproc_counter--;
5103
5104     return ret;
5105 }
5106
5107 static void subclass_static(void)
5108 {
5109     WNDCLASSA cls;
5110
5111     if (!GetClassInfoA(0, "static", &cls)) assert(0);
5112
5113     old_static_proc = cls.lpfnWndProc;
5114
5115     cls.hInstance = GetModuleHandle(0);
5116     cls.lpfnWndProc = static_hook_proc;
5117     cls.lpszClassName = "my_static_class";
5118     UnregisterClass(cls.lpszClassName, cls.hInstance);
5119     if (!RegisterClassA(&cls)) assert(0);
5120 }
5121
5122 static void test_static_messages(void)
5123 {
5124     /* FIXME: make as comprehensive as the button message test */
5125     static const struct
5126     {
5127         DWORD style;
5128         DWORD dlg_code;
5129         const struct message *setfont;
5130     } static_ctrl[] = {
5131         { SS_LEFT, DLGC_STATIC,
5132           WmSetFontStaticSeq }
5133     };
5134     unsigned int i;
5135     HWND hwnd;
5136     DWORD dlg_code;
5137
5138     subclass_static();
5139
5140     for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
5141     {
5142         hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
5143                                0, 0, 50, 14, 0, 0, 0, NULL);
5144         ok(hwnd != 0, "Failed to create static window\n");
5145
5146         dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5147         ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5148
5149         ShowWindow(hwnd, SW_SHOW);
5150         UpdateWindow(hwnd);
5151         SetFocus(0);
5152         flush_sequence();
5153
5154         trace("static style %08x\n", static_ctrl[i].style);
5155         SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
5156         ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
5157
5158         DestroyWindow(hwnd);
5159     }
5160 }
5161
5162 /****************** ComboBox message test *************************/
5163 #define ID_COMBOBOX 0x000f
5164
5165 static const struct message WmKeyDownComboSeq[] =
5166 {
5167     { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
5168     { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
5169     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
5170     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
5171     { WM_CTLCOLOREDIT, sent|parent },
5172     { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
5173     { 0 }
5174 };
5175
5176 static WNDPROC old_combobox_proc;
5177
5178 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5179 {
5180     static long defwndproc_counter = 0;
5181     LRESULT ret;
5182     struct message msg;
5183
5184     /* do not log painting messages */
5185     if (message != WM_PAINT &&
5186         message != WM_NCPAINT &&
5187         message != WM_SYNCPAINT &&
5188         message != WM_ERASEBKGND &&
5189         message != WM_NCHITTEST &&
5190         message != WM_GETTEXT &&
5191         message != WM_GETICON &&
5192         message != WM_DEVICECHANGE)
5193     {
5194         trace("combo: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
5195
5196         msg.message = message;
5197         msg.flags = sent|wparam|lparam;
5198         if (defwndproc_counter) msg.flags |= defwinproc;
5199         msg.wParam = wParam;
5200         msg.lParam = lParam;
5201         add_message(&msg);
5202     }
5203
5204     defwndproc_counter++;
5205     ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5206     defwndproc_counter--;
5207
5208     return ret;
5209 }
5210
5211 static void subclass_combobox(void)
5212 {
5213     WNDCLASSA cls;
5214
5215     if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5216
5217     old_combobox_proc = cls.lpfnWndProc;
5218
5219     cls.hInstance = GetModuleHandle(0);
5220     cls.lpfnWndProc = combobox_hook_proc;
5221     cls.lpszClassName = "my_combobox_class";
5222     UnregisterClass(cls.lpszClassName, cls.hInstance);
5223     if (!RegisterClassA(&cls)) assert(0);
5224 }
5225
5226 static void test_combobox_messages(void)
5227 {
5228     HWND parent, combo;
5229     LRESULT ret;
5230
5231     subclass_combobox();
5232
5233     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5234                              100, 100, 200, 200, 0, 0, 0, NULL);
5235     ok(parent != 0, "Failed to create parent window\n");
5236     flush_sequence();
5237
5238     combo = CreateWindowEx(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5239                            0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5240     ok(combo != 0, "Failed to create combobox window\n");
5241
5242     UpdateWindow(combo);
5243
5244     ret = SendMessage(combo, WM_GETDLGCODE, 0, 0);
5245     ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5246
5247     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5248     ok(ret == 0, "expected 0, got %ld\n", ret);
5249     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5250     ok(ret == 1, "expected 1, got %ld\n", ret);
5251     ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5252     ok(ret == 2, "expected 2, got %ld\n", ret);
5253
5254     SendMessage(combo, CB_SETCURSEL, 0, 0);
5255     SetFocus(combo);
5256     flush_sequence();
5257
5258     log_all_parent_messages++;
5259     SendMessage(combo, WM_KEYDOWN, VK_DOWN, 0);
5260     SendMessage(combo, WM_KEYUP, VK_DOWN, 0);
5261     log_all_parent_messages--;
5262     ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5263
5264     DestroyWindow(combo);
5265     DestroyWindow(parent);
5266 }
5267
5268 /****************** WM_IME_KEYDOWN message test *******************/
5269
5270 static const struct message WmImeKeydownMsgSeq_0[] =
5271 {
5272     { WM_IME_KEYDOWN, wparam, VK_RETURN },
5273     { WM_CHAR, wparam, 'A' },
5274     { 0 }
5275 };
5276
5277 static const struct message WmImeKeydownMsgSeq_1[] =
5278 {
5279     { WM_KEYDOWN, optional|wparam, VK_RETURN },
5280     { WM_CHAR,    optional|wparam, VK_RETURN },
5281     { 0 }
5282 };
5283
5284 static LRESULT WINAPI wmime_keydown_procA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5285 {
5286     struct message msg;
5287
5288     trace("wmime_keydown_procA: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
5289
5290     msg.message = message;
5291     msg.flags = wparam|lparam;
5292     msg.wParam = wParam;
5293     msg.lParam = lParam;
5294     add_message(&msg);
5295
5296     return DefWindowProcA(hwnd, message, wParam, lParam);
5297 }
5298
5299 static void register_wmime_keydown_class(void)
5300 {
5301     WNDCLASSA cls;
5302
5303     ZeroMemory(&cls, sizeof(WNDCLASSA));
5304     cls.lpfnWndProc = wmime_keydown_procA;
5305     cls.hInstance = GetModuleHandleA(0);
5306     cls.lpszClassName = "wmime_keydown_class";
5307     if (!RegisterClassA(&cls)) assert(0);
5308 }
5309
5310 void test_wmime_keydown_message(void)
5311 {
5312     HWND hwnd;
5313     MSG msg;
5314
5315     trace("Message sequences by WM_IME_KEYDOWN\n");
5316
5317     register_wmime_keydown_class();
5318     hwnd = CreateWindowExA(0, "wmime_keydown_class", NULL, WS_OVERLAPPEDWINDOW,
5319                            CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5320                            NULL, NULL, 0);
5321     flush_events();
5322     flush_sequence();
5323
5324     SendMessage(hwnd, WM_IME_KEYDOWN, VK_RETURN, 0x1c0001);
5325     SendMessage(hwnd, WM_CHAR, 'A', 1);
5326     ok_sequence(WmImeKeydownMsgSeq_0, "WM_IME_KEYDOWN 0", FALSE);
5327
5328     while ( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
5329     {
5330         TranslateMessage(&msg);
5331         DispatchMessage(&msg);
5332     }
5333     ok_sequence(WmImeKeydownMsgSeq_1, "WM_IME_KEYDOWN 1", FALSE);
5334
5335     DestroyWindow(hwnd);
5336 }
5337
5338 /************* painting message test ********************/
5339
5340 void dump_region(HRGN hrgn)
5341 {
5342     DWORD i, size;
5343     RGNDATA *data = NULL;
5344     RECT *rect;
5345
5346     if (!hrgn)
5347     {
5348         printf( "null region\n" );
5349         return;
5350     }
5351     if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5352     if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5353     GetRegionData( hrgn, size, data );
5354     printf("%d rects:", data->rdh.nCount );
5355     for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5356         printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
5357     printf("\n");
5358     HeapFree( GetProcessHeap(), 0, data );
5359 }
5360
5361 static void check_update_rgn( HWND hwnd, HRGN hrgn )
5362 {
5363     INT ret;
5364     RECT r1, r2;
5365     HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
5366     HRGN update = CreateRectRgn( 0, 0, 0, 0 );
5367
5368     ret = GetUpdateRgn( hwnd, update, FALSE );
5369     ok( ret != ERROR, "GetUpdateRgn failed\n" );
5370     if (ret == NULLREGION)
5371     {
5372         ok( !hrgn, "Update region shouldn't be empty\n" );
5373     }
5374     else
5375     {
5376         if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
5377         {
5378             ok( 0, "Regions are different\n" );
5379             if (winetest_debug > 0)
5380             {
5381                 printf( "Update region: " );
5382                 dump_region( update );
5383                 printf( "Wanted region: " );
5384                 dump_region( hrgn );
5385             }
5386         }
5387     }
5388     GetRgnBox( update, &r1 );
5389     GetUpdateRect( hwnd, &r2, FALSE );
5390     ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
5391         "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
5392         r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
5393
5394     DeleteObject( tmp );
5395     DeleteObject( update );
5396 }
5397
5398 static const struct message WmInvalidateRgn[] = {
5399     { WM_NCPAINT, sent },
5400     { WM_GETTEXT, sent|defwinproc|optional },
5401     { 0 }
5402 };
5403
5404 static const struct message WmGetUpdateRect[] = {
5405     { WM_NCPAINT, sent },
5406     { WM_GETTEXT, sent|defwinproc|optional },
5407     { WM_PAINT, sent },
5408     { 0 }
5409 };
5410
5411 static const struct message WmInvalidateFull[] = {
5412     { WM_NCPAINT, sent|wparam, 1 },
5413     { WM_GETTEXT, sent|defwinproc|optional },
5414     { 0 }
5415 };
5416
5417 static const struct message WmInvalidateErase[] = {
5418     { WM_NCPAINT, sent|wparam, 1 },
5419     { WM_GETTEXT, sent|defwinproc|optional },
5420     { WM_ERASEBKGND, sent },
5421     { 0 }
5422 };
5423
5424 static const struct message WmInvalidatePaint[] = {
5425     { WM_PAINT, sent },
5426     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5427     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5428     { 0 }
5429 };
5430
5431 static const struct message WmInvalidateErasePaint[] = {
5432     { WM_PAINT, sent },
5433     { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5434     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5435     { WM_ERASEBKGND, sent|beginpaint },
5436     { 0 }
5437 };
5438
5439 static const struct message WmInvalidateErasePaint2[] = {
5440     { WM_PAINT, sent },
5441     { WM_NCPAINT, sent|beginpaint },
5442     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5443     { WM_ERASEBKGND, sent|beginpaint },
5444     { 0 }
5445 };
5446
5447 static const struct message WmErase[] = {
5448     { WM_ERASEBKGND, sent },
5449     { 0 }
5450 };
5451
5452 static const struct message WmPaint[] = {
5453     { WM_PAINT, sent },
5454     { 0 }
5455 };
5456
5457 static const struct message WmParentOnlyPaint[] = {
5458     { WM_PAINT, sent|parent },
5459     { 0 }
5460 };
5461
5462 static const struct message WmInvalidateParent[] = {
5463     { WM_NCPAINT, sent|parent },
5464     { WM_GETTEXT, sent|defwinproc|parent|optional },
5465     { WM_ERASEBKGND, sent|parent },
5466     { 0 }
5467 };
5468
5469 static const struct message WmInvalidateParentChild[] = {
5470     { WM_NCPAINT, sent|parent },
5471     { WM_GETTEXT, sent|defwinproc|parent|optional },
5472     { WM_ERASEBKGND, sent|parent },
5473     { WM_NCPAINT, sent },
5474     { WM_GETTEXT, sent|defwinproc|optional },
5475     { WM_ERASEBKGND, sent },
5476     { 0 }
5477 };
5478
5479 static const struct message WmInvalidateParentChild2[] = {
5480     { WM_ERASEBKGND, sent|parent },
5481     { WM_NCPAINT, sent },
5482     { WM_GETTEXT, sent|defwinproc|optional },
5483     { WM_ERASEBKGND, sent },
5484     { 0 }
5485 };
5486
5487 static const struct message WmParentPaint[] = {
5488     { WM_PAINT, sent|parent },
5489     { WM_PAINT, sent },
5490     { 0 }
5491 };
5492
5493 static const struct message WmParentPaintNc[] = {
5494     { WM_PAINT, sent|parent },
5495     { WM_PAINT, sent },
5496     { WM_NCPAINT, sent|beginpaint },
5497     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5498     { WM_ERASEBKGND, sent|beginpaint },
5499     { 0 }
5500 };
5501
5502 static const struct message WmChildPaintNc[] = {
5503     { WM_PAINT, sent },
5504     { WM_NCPAINT, sent|beginpaint },
5505     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5506     { WM_ERASEBKGND, sent|beginpaint },
5507     { 0 }
5508 };
5509
5510 static const struct message WmParentErasePaint[] = {
5511     { WM_PAINT, sent|parent },
5512     { WM_NCPAINT, sent|parent|beginpaint },
5513     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5514     { WM_ERASEBKGND, sent|parent|beginpaint },
5515     { WM_PAINT, sent },
5516     { WM_NCPAINT, sent|beginpaint },
5517     { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5518     { WM_ERASEBKGND, sent|beginpaint },
5519     { 0 }
5520 };
5521
5522 static const struct message WmParentOnlyNcPaint[] = {
5523     { WM_PAINT, sent|parent },
5524     { WM_NCPAINT, sent|parent|beginpaint },
5525     { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5526     { 0 }
5527 };
5528
5529 static const struct message WmSetParentStyle[] = {
5530     { WM_STYLECHANGING, sent|parent },
5531     { WM_STYLECHANGED, sent|parent },
5532     { 0 }
5533 };
5534
5535 static void test_paint_messages(void)
5536 {
5537     BOOL ret;
5538     RECT rect;
5539     POINT pt;
5540     MSG msg;
5541     HWND hparent, hchild;
5542     HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
5543     HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
5544     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
5545                                 100, 100, 200, 200, 0, 0, 0, NULL);
5546     ok (hwnd != 0, "Failed to create overlapped window\n");
5547
5548     ShowWindow( hwnd, SW_SHOW );
5549     UpdateWindow( hwnd );
5550     flush_events();
5551     flush_sequence();
5552
5553     check_update_rgn( hwnd, 0 );
5554     SetRectRgn( hrgn, 10, 10, 20, 20 );
5555     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5556     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5557     check_update_rgn( hwnd, hrgn );
5558     SetRectRgn( hrgn2, 20, 20, 30, 30 );
5559     ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
5560     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5561     CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
5562     check_update_rgn( hwnd, hrgn );
5563     /* validate everything */
5564     ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5565     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5566     check_update_rgn( hwnd, 0 );
5567
5568     /* test empty region */
5569     SetRectRgn( hrgn, 10, 10, 10, 15 );
5570     ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5571     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5572     check_update_rgn( hwnd, 0 );
5573     /* test empty rect */
5574     SetRect( &rect, 10, 10, 10, 15 );
5575     ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
5576     ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5577     check_update_rgn( hwnd, 0 );
5578
5579     /* flush pending messages */
5580     flush_events();
5581     flush_sequence();
5582
5583     GetClientRect( hwnd, &rect );
5584     SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
5585     /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
5586      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5587      */
5588     trace("testing InvalidateRect(0, NULL, FALSE)\n");
5589     SetRectEmpty( &rect );
5590     ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
5591     check_update_rgn( hwnd, hrgn );
5592     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5593     flush_events();
5594     ok_sequence( WmPaint, "Paint", FALSE );
5595     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5596     check_update_rgn( hwnd, 0 );
5597
5598     /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
5599      * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5600      */
5601     trace("testing ValidateRect(0, NULL)\n");
5602     SetRectEmpty( &rect );
5603     ok(ValidateRect(0, &rect), "ValidateRect(0, &rc) should not fail\n");
5604     check_update_rgn( hwnd, hrgn );
5605     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5606     flush_events();
5607     ok_sequence( WmPaint, "Paint", FALSE );
5608     RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5609     check_update_rgn( hwnd, 0 );
5610
5611     trace("testing InvalidateRgn(0, NULL, FALSE)\n");
5612     SetLastError(0xdeadbeef);
5613     ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
5614     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
5615        "wrong error code %d\n", GetLastError());
5616     check_update_rgn( hwnd, 0 );
5617     flush_events();
5618     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5619
5620     trace("testing ValidateRgn(0, NULL)\n");
5621     SetLastError(0xdeadbeef);
5622     ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
5623     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error code %d\n", GetLastError());
5624     check_update_rgn( hwnd, 0 );
5625     flush_events();
5626     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5627
5628     /* now with frame */
5629     SetRectRgn( hrgn, -5, -5, 20, 20 );
5630
5631     /* flush pending messages */
5632     flush_events();
5633     flush_sequence();
5634     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5635     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5636
5637     SetRectRgn( hrgn, 0, 0, 20, 20 );  /* GetUpdateRgn clips to client area */
5638     check_update_rgn( hwnd, hrgn );
5639
5640     flush_sequence();
5641     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5642     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5643
5644     flush_sequence();
5645     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5646     ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
5647
5648     GetClientRect( hwnd, &rect );
5649     SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
5650     check_update_rgn( hwnd, hrgn );
5651
5652     flush_sequence();
5653     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
5654     ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5655
5656     flush_sequence();
5657     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
5658     ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
5659     check_update_rgn( hwnd, 0 );
5660
5661     flush_sequence();
5662     RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
5663     ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
5664     check_update_rgn( hwnd, 0 );
5665
5666     flush_sequence();
5667     SetRectRgn( hrgn, 0, 0, 100, 100 );
5668     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5669     SetRectRgn( hrgn, 0, 0, 50, 100 );
5670     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
5671     SetRectRgn( hrgn, 50, 0, 100, 100 );
5672     check_update_rgn( hwnd, hrgn );
5673     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5674     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );  /* must not generate messages, everything is valid */
5675     check_update_rgn( hwnd, 0 );
5676
5677     flush_sequence();
5678     SetRectRgn( hrgn, 0, 0, 100, 100 );
5679     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5680     SetRectRgn( hrgn, 0, 0, 100, 50 );
5681     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5682     ok_sequence( WmErase, "Erase", FALSE );
5683     SetRectRgn( hrgn, 0, 50, 100, 100 );
5684     check_update_rgn( hwnd, hrgn );
5685
5686     flush_sequence();
5687     SetRectRgn( hrgn, 0, 0, 100, 100 );
5688     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5689     SetRectRgn( hrgn, 0, 0, 50, 50 );
5690     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
5691     ok_sequence( WmPaint, "Paint", FALSE );
5692
5693     flush_sequence();
5694     SetRectRgn( hrgn, -4, -4, -2, -2 );
5695     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5696     SetRectRgn( hrgn, -200, -200, -198, -198 );
5697     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
5698     ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5699
5700     flush_sequence();
5701     SetRectRgn( hrgn, -4, -4, -2, -2 );
5702     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5703     SetRectRgn( hrgn, -4, -4, -3, -3 );
5704     RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
5705     SetRectRgn( hrgn, 0, 0, 1, 1 );
5706     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
5707     ok_sequence( WmPaint, "Paint", FALSE );
5708
5709     flush_sequence();
5710     SetRectRgn( hrgn, -4, -4, -1, -1 );
5711     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5712     RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
5713     /* make sure no WM_PAINT was generated */
5714     flush_events();
5715     ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5716
5717     flush_sequence();
5718     SetRectRgn( hrgn, -4, -4, -1, -1 );
5719     RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5720     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
5721     {
5722         if (msg.hwnd == hwnd && msg.message == WM_PAINT)
5723         {
5724             /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
5725             INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
5726             ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
5727             ret = GetUpdateRect( hwnd, &rect, FALSE );
5728             ok( ret, "Invalid GetUpdateRect result %d\n", ret );
5729             /* this will send WM_NCPAINT and validate the non client area */
5730             ret = GetUpdateRect( hwnd, &rect, TRUE );
5731             ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
5732         }
5733         DispatchMessage( &msg );
5734     }
5735     ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
5736
5737     DestroyWindow( hwnd );
5738
5739     /* now test with a child window */
5740
5741     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
5742                               100, 100, 200, 200, 0, 0, 0, NULL);
5743     ok (hparent != 0, "Failed to create parent window\n");
5744
5745     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
5746                            10, 10, 100, 100, hparent, 0, 0, NULL);
5747     ok (hchild != 0, "Failed to create child window\n");
5748
5749     ShowWindow( hparent, SW_SHOW );
5750     UpdateWindow( hparent );
5751     UpdateWindow( hchild );
5752     flush_events();
5753     flush_sequence();
5754     log_all_parent_messages++;
5755
5756     SetRect( &rect, 0, 0, 50, 50 );
5757     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5758     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5759     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
5760
5761     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5762     pt.x = pt.y = 0;
5763     MapWindowPoints( hchild, hparent, &pt, 1 );
5764     SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
5765     check_update_rgn( hchild, hrgn );
5766     SetRectRgn( hrgn, 0, 0, 50, 50 );
5767     check_update_rgn( hparent, hrgn );
5768     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5769     ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
5770     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5771     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5772
5773     flush_events();
5774     ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
5775
5776     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5777     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5778     ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
5779     RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5780     ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5781
5782     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
5783     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5784     ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
5785
5786     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
5787     flush_sequence();
5788     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5789     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5790     ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
5791
5792     /* flush all paint messages */
5793     flush_events();
5794     flush_sequence();
5795
5796     /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
5797     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5798     SetRectRgn( hrgn, 0, 0, 50, 50 );
5799     check_update_rgn( hparent, hrgn );
5800     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5801     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5802     SetRectRgn( hrgn, 0, 0, 50, 50 );
5803     check_update_rgn( hparent, hrgn );
5804
5805     /* flush all paint messages */
5806     flush_events();
5807     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
5808     flush_sequence();
5809
5810     /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
5811     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5812     SetRectRgn( hrgn, 0, 0, 50, 50 );
5813     check_update_rgn( hparent, hrgn );
5814     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5815     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5816     SetRectRgn( hrgn2, 10, 10, 50, 50 );
5817     CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
5818     check_update_rgn( hparent, hrgn );
5819     /* flush all paint messages */
5820     flush_events();
5821     flush_sequence();
5822
5823     /* same as above but parent gets completely validated */
5824     SetRect( &rect, 20, 20, 30, 30 );
5825     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5826     SetRectRgn( hrgn, 20, 20, 30, 30 );
5827     check_update_rgn( hparent, hrgn );
5828     RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5829     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5830     check_update_rgn( hparent, 0 );  /* no update region */
5831     flush_events();
5832     ok_sequence( WmEmptySeq, "WmEmpty", FALSE );  /* and no paint messages */
5833
5834     /* make sure RDW_VALIDATE on child doesn't have the same effect */
5835     flush_sequence();
5836     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5837     SetRectRgn( hrgn, 20, 20, 30, 30 );
5838     check_update_rgn( hparent, hrgn );
5839     RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
5840     SetRectRgn( hrgn, 20, 20, 30, 30 );
5841     check_update_rgn( hparent, hrgn );
5842
5843     /* same as above but normal WM_PAINT doesn't validate parent */
5844     flush_sequence();
5845     SetRect( &rect, 20, 20, 30, 30 );
5846     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5847     SetRectRgn( hrgn, 20, 20, 30, 30 );
5848     check_update_rgn( hparent, hrgn );
5849     /* no WM_PAINT in child while parent still pending */
5850     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5851     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
5852     while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5853     ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
5854
5855     flush_sequence();
5856     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5857     /* no WM_PAINT in child while parent still pending */
5858     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5859     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
5860     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
5861     /* now that parent is valid child should get WM_PAINT */
5862     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5863     ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5864     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5865     ok_sequence( WmEmptySeq, "No other message", FALSE );
5866
5867     /* same thing with WS_CLIPCHILDREN in parent */
5868     flush_sequence();
5869     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
5870     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
5871     /* changing style invalidates non client area, but we need to invalidate something else to see it */
5872     RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
5873     ok_sequence( WmEmptySeq, "No message", FALSE );
5874     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
5875     ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
5876
5877     flush_sequence();
5878     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
5879     SetRectRgn( hrgn, 20, 20, 30, 30 );
5880     check_update_rgn( hparent, hrgn );
5881     /* no WM_PAINT in child while parent still pending */
5882     while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5883     ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
5884     /* WM_PAINT in parent first */
5885     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5886     ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
5887
5888     /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
5889     flush_sequence();
5890     SetRect( &rect, 0, 0, 30, 30 );
5891     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
5892     SetRectRgn( hrgn, 0, 0, 30, 30 );
5893     check_update_rgn( hparent, hrgn );
5894     flush_events();
5895     ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
5896
5897     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
5898     flush_sequence();
5899     SetRect( &rect, -10, 0, 30, 30 );
5900     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
5901     SetRect( &rect, 0, 0, 20, 20 );
5902     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
5903     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
5904     ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
5905
5906     /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
5907     flush_sequence();
5908     SetRect( &rect, -10, 0, 30, 30 );
5909     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
5910     SetRect( &rect, 0, 0, 100, 100 );
5911     RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
5912     RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
5913     ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
5914     RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5915     ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
5916
5917     /* test RDW_INTERNALPAINT behavior */
5918
5919     flush_sequence();
5920     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
5921     flush_events();
5922     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
5923
5924     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
5925     flush_events();
5926     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
5927
5928     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
5929     flush_events();
5930     ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
5931
5932     assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
5933     UpdateWindow( hparent );
5934     flush_events();
5935     flush_sequence();
5936     trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
5937     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5938     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
5939                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5940     flush_events();
5941     ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
5942
5943     UpdateWindow( hparent );
5944     flush_events();
5945     flush_sequence();
5946     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
5947     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5948     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
5949                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5950     flush_events();
5951     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
5952
5953     SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
5954     ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
5955     RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
5956     flush_events();
5957     ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
5958
5959     assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
5960     UpdateWindow( hparent );
5961     flush_events();
5962     flush_sequence();
5963     trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
5964     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5965     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
5966                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5967     flush_events();
5968     ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
5969
5970     UpdateWindow( hparent );
5971     flush_events();
5972     flush_sequence();
5973     trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
5974     RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5975     SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
5976                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5977     flush_events();
5978     ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
5979
5980     ok(GetWindowLong( hparent, GWL_STYLE ) & WS_VISIBLE, "parent should be visible\n");
5981     ok(GetWindowLong( hchild, GWL_STYLE ) & WS_VISIBLE, "child should be visible\n");
5982
5983     UpdateWindow( hparent );
5984     flush_events();
5985     flush_sequence();
5986     trace("testing SetWindowPos(-10000, -10000) on child\n");
5987     SetWindowPos( hchild, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
5988     check_update_rgn( hchild, 0 );
5989     flush_events();
5990
5991 #if 0 /* this one doesn't pass under Wine yet */
5992     UpdateWindow( hparent );
5993     flush_events();
5994     flush_sequence();
5995     trace("testing ShowWindow(SW_MINIMIZE) on child\n");
5996     ShowWindow( hchild, SW_MINIMIZE );
5997     check_update_rgn( hchild, 0 );
5998     flush_events();
5999 #endif
6000
6001     UpdateWindow( hparent );
6002     flush_events();
6003     flush_sequence();
6004     trace("testing SetWindowPos(-10000, -10000) on parent\n");
6005     SetWindowPos( hparent, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6006     check_update_rgn( hparent, 0 );
6007     flush_events();
6008
6009     log_all_parent_messages--;
6010     DestroyWindow( hparent );
6011     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6012
6013     /* tests for moving windows off-screen (needs simple WS_POPUP windows) */
6014
6015     hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_POPUP | WS_VISIBLE,
6016                               100, 100, 200, 200, 0, 0, 0, NULL);
6017     ok (hparent != 0, "Failed to create parent window\n");
6018
6019     hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
6020                            10, 10, 100, 100, hparent, 0, 0, NULL);
6021     ok (hchild != 0, "Failed to create child window\n");
6022
6023     ShowWindow( hparent, SW_SHOW );
6024     UpdateWindow( hparent );
6025     UpdateWindow( hchild );
6026     flush_events();
6027     flush_sequence();
6028
6029     /* moving child outside of parent boundaries changes update region */
6030     SetRect( &rect, 0, 0, 40, 40 );
6031     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6032     SetRectRgn( hrgn, 0, 0, 40, 40 );
6033     check_update_rgn( hchild, hrgn );
6034     MoveWindow( hchild, -10, 10, 100, 100, FALSE );
6035     SetRectRgn( hrgn, 10, 0, 40, 40 );
6036     check_update_rgn( hchild, hrgn );
6037     MoveWindow( hchild, -10, -10, 100, 100, FALSE );
6038     SetRectRgn( hrgn, 10, 10, 40, 40 );
6039     check_update_rgn( hchild, hrgn );
6040
6041     /* moving parent off-screen does too */
6042     SetRect( &rect, 0, 0, 100, 100 );
6043     RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
6044     SetRectRgn( hrgn, 0, 0, 100, 100 );
6045     check_update_rgn( hparent, hrgn );
6046     SetRectRgn( hrgn, 10, 10, 40, 40 );
6047     check_update_rgn( hchild, hrgn );
6048     MoveWindow( hparent, -20, -20, 200, 200, FALSE );
6049     SetRectRgn( hrgn, 20, 20, 100, 100 );
6050     check_update_rgn( hparent, hrgn );
6051     SetRectRgn( hrgn, 30, 30, 40, 40 );
6052     check_update_rgn( hchild, hrgn );
6053
6054     /* invalidated region is cropped by the parent rects */
6055     SetRect( &rect, 0, 0, 50, 50 );
6056     RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6057     SetRectRgn( hrgn, 30, 30, 50, 50 );
6058     check_update_rgn( hchild, hrgn );
6059
6060     DestroyWindow( hparent );
6061     ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6062     flush_sequence();
6063
6064     DeleteObject( hrgn );
6065     DeleteObject( hrgn2 );
6066 }
6067
6068 struct wnd_event
6069 {
6070     HWND hwnd;
6071     HANDLE event;
6072 };
6073
6074 static DWORD WINAPI thread_proc(void *param)
6075 {
6076     MSG msg;
6077     struct wnd_event *wnd_event = (struct wnd_event *)param;
6078
6079     wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
6080                                       100, 100, 200, 200, 0, 0, 0, NULL);
6081     ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
6082
6083     SetEvent(wnd_event->event);
6084
6085     while (GetMessage(&msg, 0, 0, 0))
6086     {
6087         TranslateMessage(&msg);
6088         DispatchMessage(&msg);
6089     }
6090
6091     ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
6092
6093     return 0;
6094 }
6095
6096 static void test_interthread_messages(void)
6097 {
6098     HANDLE hThread;
6099     DWORD tid;
6100     WNDPROC proc;
6101     MSG msg;
6102     char buf[256];
6103     int len, expected_len;
6104     struct wnd_event wnd_event;
6105     BOOL ret;
6106
6107     wnd_event.event = CreateEventW(NULL, 0, 0, NULL);
6108     if (!wnd_event.event)
6109     {
6110         trace("skipping interthread message test under win9x\n");
6111         return;
6112     }
6113
6114     hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
6115     ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
6116
6117     ok(WaitForSingleObject(wnd_event.event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6118
6119     CloseHandle(wnd_event.event);
6120
6121     SetLastError(0xdeadbeef);
6122     ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
6123     ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
6124        "wrong error code %d\n", GetLastError());
6125
6126     proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6127     ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
6128
6129     expected_len = lstrlenA("window caption text");
6130     memset(buf, 0, sizeof(buf));
6131     SetLastError(0xdeadbeef);
6132     len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
6133     ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
6134     ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
6135
6136     msg.hwnd = wnd_event.hwnd;
6137     msg.message = WM_GETTEXT;
6138     msg.wParam = sizeof(buf);
6139     msg.lParam = (LPARAM)buf;
6140     memset(buf, 0, sizeof(buf));
6141     SetLastError(0xdeadbeef);
6142     len = DispatchMessageA(&msg);
6143     ok((!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY) || broken(len), /* nt4 */
6144        "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
6145
6146     /* the following test causes an exception in user.exe under win9x */
6147     msg.hwnd = wnd_event.hwnd;
6148     msg.message = WM_TIMER;
6149     msg.wParam = 0;
6150     msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6151     SetLastError(0xdeadbeef);
6152     len = DispatchMessageA(&msg);
6153     ok(!len && GetLastError() == 0xdeadbeef,
6154        "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
6155
6156     ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
6157     ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
6158
6159     ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6160     CloseHandle(hThread);
6161
6162     ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
6163 }
6164
6165
6166 static const struct message WmVkN[] = {
6167     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6168     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6169     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6170     { WM_CHAR, wparam|lparam, 'n', 1 },
6171     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
6172     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6173     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6174     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6175     { 0 }
6176 };
6177 static const struct message WmShiftVkN[] = {
6178     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6179     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6180     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6181     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6182     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6183     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6184     { WM_CHAR, wparam|lparam, 'N', 1 },
6185     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
6186     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6187     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6188     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6189     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6190     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6191     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6192     { 0 }
6193 };
6194 static const struct message WmCtrlVkN[] = {
6195     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6196     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6197     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6198     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6199     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6200     { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6201     { WM_CHAR, wparam|lparam, 0x000e, 1 },
6202     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6203     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6204     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6205     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6206     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6207     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6208     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6209     { 0 }
6210 };
6211 static const struct message WmCtrlVkN_2[] = {
6212     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6213     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6214     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6215     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6216     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6217     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6218     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6219     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6220     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6221     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6222     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6223     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6224     { 0 }
6225 };
6226 static const struct message WmAltVkN[] = {
6227     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6228     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6229     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6230     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6231     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6232     { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6233     { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
6234     { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
6235     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
6236     { HCBT_SYSCOMMAND, hook },
6237     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6238     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6239     { 0x00AE, sent|defwinproc|optional }, /* XP */
6240     { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
6241     { WM_INITMENU, sent|defwinproc },
6242     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6243     { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
6244     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
6245     { WM_CAPTURECHANGED, sent|defwinproc },
6246     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
6247     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6248     { WM_EXITMENULOOP, sent|defwinproc },
6249     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
6250     { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
6251     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6252     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6253     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6254     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6255     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6256     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6257     { 0 }
6258 };
6259 static const struct message WmAltVkN_2[] = {
6260     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6261     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6262     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6263     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6264     { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6265     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
6266     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6267     { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6268     { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6269     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6270     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6271     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6272     { 0 }
6273 };
6274 static const struct message WmCtrlAltVkN[] = {
6275     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6276     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6277     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6278     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6279     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6280     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6281     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6282     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6283     { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6284     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6285     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6286     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6287     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6288     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6289     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6290     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6291     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6292     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6293     { 0 }
6294 };
6295 static const struct message WmCtrlShiftVkN[] = {
6296     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6297     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6298     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6299     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6300     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6301     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6302     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6303     { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6304     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
6305     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6306     { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6307     { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6308     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6309     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6310     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6311     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6312     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6313     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6314     { 0 }
6315 };
6316 static const struct message WmCtrlAltShiftVkN[] = {
6317     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6318     { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6319     { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6320     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6321     { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6322     { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6323     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
6324     { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
6325     { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
6326     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6327     { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6328     { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
6329     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6330     { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6331     { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6332     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
6333     { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
6334     { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
6335     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6336     { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6337     { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6338     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6339     { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6340     { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6341     { 0 }
6342 };
6343 static const struct message WmAltPressRelease[] = {
6344     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6345     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6346     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6347     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6348     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6349     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6350     { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
6351     { HCBT_SYSCOMMAND, hook },
6352     { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6353     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6354     { WM_INITMENU, sent|defwinproc },
6355     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6356     { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6357     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6358
6359     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
6360
6361     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6362     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
6363     { WM_CAPTURECHANGED, sent|defwinproc },
6364     { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
6365     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6366     { WM_EXITMENULOOP, sent|defwinproc },
6367     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6368     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6369     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6370     { 0 }
6371 };
6372 static const struct message WmAltMouseButton[] = {
6373     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6374     { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6375     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6376     { WM_MOUSEMOVE, wparam|optional, 0, 0 },
6377     { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
6378     { WM_LBUTTONDOWN, wparam, MK_LBUTTON, 0 },
6379     { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON, 0 },
6380     { WM_LBUTTONUP, wparam, 0, 0 },
6381     { WM_LBUTTONUP, sent|wparam, 0, 0 },
6382     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6383     { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6384     { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6385     { 0 }
6386 };
6387 static const struct message WmF1Seq[] = {
6388     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
6389     { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
6390     { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
6391     { WM_KEYF1, wparam|lparam, 0, 0 },
6392     { WM_KEYF1, sent|wparam|lparam, 0, 0 },
6393     { WM_HELP, sent|defwinproc },
6394     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
6395     { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
6396     { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
6397     { 0 }
6398 };
6399 static const struct message WmVkAppsSeq[] = {
6400     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
6401     { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
6402     { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
6403     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
6404     { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
6405     { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
6406     { WM_CONTEXTMENU, lparam, /*hwnd*/0, (LPARAM)-1 },
6407     { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, (LPARAM)-1 },
6408     { 0 }
6409 };
6410
6411 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
6412 {
6413     MSG msg;
6414
6415     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
6416     {
6417         struct message log_msg;
6418
6419         trace("accel: %p, %04x, %08lx, %08lx\n", msg.hwnd, msg.message, msg.wParam, msg.lParam);
6420
6421         /* ignore some unwanted messages */
6422         if (msg.message == WM_MOUSEMOVE ||
6423             msg.message == WM_GETICON ||
6424             msg.message == WM_TIMER ||
6425             msg.message == WM_DEVICECHANGE)
6426             continue;
6427
6428         log_msg.message = msg.message;
6429         log_msg.flags = wparam|lparam;
6430         log_msg.wParam = msg.wParam;
6431         log_msg.lParam = msg.lParam;
6432         add_message(&log_msg);
6433
6434         if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
6435         {
6436             TranslateMessage(&msg);
6437             DispatchMessage(&msg);
6438         }
6439     }
6440 }
6441
6442 static void test_accelerators(void)
6443 {
6444     RECT rc;
6445     SHORT state;
6446     HACCEL hAccel;
6447     HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6448                                 100, 100, 200, 200, 0, 0, 0, NULL);
6449     BOOL ret;
6450
6451     assert(hwnd != 0);
6452     UpdateWindow(hwnd);
6453     flush_events();
6454     flush_sequence();
6455
6456     SetFocus(hwnd);
6457     ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
6458
6459     state = GetKeyState(VK_SHIFT);
6460     ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
6461     state = GetKeyState(VK_CAPITAL);
6462     ok(state == 0, "wrong CapsLock state %04x\n", state);
6463
6464     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
6465     assert(hAccel != 0);
6466
6467     flush_events();
6468     pump_msg_loop(hwnd, 0);
6469     flush_sequence();
6470
6471     trace("testing VK_N press/release\n");
6472     flush_sequence();
6473     keybd_event('N', 0, 0, 0);
6474     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6475     pump_msg_loop(hwnd, hAccel);
6476     ok_sequence(WmVkN, "VK_N press/release", FALSE);
6477
6478     trace("testing Shift+VK_N press/release\n");
6479     flush_sequence();
6480     keybd_event(VK_SHIFT, 0, 0, 0);
6481     keybd_event('N', 0, 0, 0);
6482     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6483     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6484     pump_msg_loop(hwnd, hAccel);
6485     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6486
6487     trace("testing Ctrl+VK_N press/release\n");
6488     flush_sequence();
6489     keybd_event(VK_CONTROL, 0, 0, 0);
6490     keybd_event('N', 0, 0, 0);
6491     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6492     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6493     pump_msg_loop(hwnd, hAccel);
6494     ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
6495
6496     trace("testing Alt+VK_N press/release\n");
6497     flush_sequence();
6498     keybd_event(VK_MENU, 0, 0, 0);
6499     keybd_event('N', 0, 0, 0);
6500     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6501     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6502     pump_msg_loop(hwnd, hAccel);
6503     ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
6504
6505     trace("testing Ctrl+Alt+VK_N press/release 1\n");
6506     flush_sequence();
6507     keybd_event(VK_CONTROL, 0, 0, 0);
6508     keybd_event(VK_MENU, 0, 0, 0);
6509     keybd_event('N', 0, 0, 0);
6510     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6511     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6512     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6513     pump_msg_loop(hwnd, hAccel);
6514     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
6515
6516     ret = DestroyAcceleratorTable(hAccel);
6517     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6518
6519     hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
6520     assert(hAccel != 0);
6521
6522     trace("testing VK_N press/release\n");
6523     flush_sequence();
6524     keybd_event('N', 0, 0, 0);
6525     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6526     pump_msg_loop(hwnd, hAccel);
6527     ok_sequence(WmVkN, "VK_N press/release", FALSE);
6528
6529     trace("testing Shift+VK_N press/release\n");
6530     flush_sequence();
6531     keybd_event(VK_SHIFT, 0, 0, 0);
6532     keybd_event('N', 0, 0, 0);
6533     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6534     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6535     pump_msg_loop(hwnd, hAccel);
6536     ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6537
6538     trace("testing Ctrl+VK_N press/release 2\n");
6539     flush_sequence();
6540     keybd_event(VK_CONTROL, 0, 0, 0);
6541     keybd_event('N', 0, 0, 0);
6542     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6543     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6544     pump_msg_loop(hwnd, hAccel);
6545     ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
6546
6547     trace("testing Alt+VK_N press/release 2\n");
6548     flush_sequence();
6549     keybd_event(VK_MENU, 0, 0, 0);
6550     keybd_event('N', 0, 0, 0);
6551     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6552     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6553     pump_msg_loop(hwnd, hAccel);
6554     ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
6555
6556     trace("testing Ctrl+Alt+VK_N press/release 2\n");
6557     flush_sequence();
6558     keybd_event(VK_CONTROL, 0, 0, 0);
6559     keybd_event(VK_MENU, 0, 0, 0);
6560     keybd_event('N', 0, 0, 0);
6561     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6562     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6563     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6564     pump_msg_loop(hwnd, hAccel);
6565     ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
6566
6567     trace("testing Ctrl+Shift+VK_N press/release\n");
6568     flush_sequence();
6569     keybd_event(VK_CONTROL, 0, 0, 0);
6570     keybd_event(VK_SHIFT, 0, 0, 0);
6571     keybd_event('N', 0, 0, 0);
6572     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6573     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6574     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6575     pump_msg_loop(hwnd, hAccel);
6576     ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
6577
6578     trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
6579     flush_sequence();
6580     keybd_event(VK_CONTROL, 0, 0, 0);
6581     keybd_event(VK_MENU, 0, 0, 0);
6582     keybd_event(VK_SHIFT, 0, 0, 0);
6583     keybd_event('N', 0, 0, 0);
6584     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6585     keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6586     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6587     keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6588     pump_msg_loop(hwnd, hAccel);
6589     ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
6590
6591     ret = DestroyAcceleratorTable(hAccel);
6592     ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6593
6594     trace("testing Alt press/release\n");
6595     flush_sequence();
6596     keybd_event(VK_MENU, 0, 0, 0);
6597     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6598     keybd_event(VK_MENU, 0, 0, 0);
6599     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6600     pump_msg_loop(hwnd, 0);
6601     /* this test doesn't pass in Wine for managed windows */
6602     ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
6603
6604     trace("testing Alt+MouseButton press/release\n");
6605     /* first, move mouse pointer inside of the window client area */
6606     GetClientRect(hwnd, &rc);
6607     MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
6608     rc.left += (rc.right - rc.left)/2;
6609     rc.top += (rc.bottom - rc.top)/2;
6610     SetCursorPos(rc.left, rc.top);
6611
6612     flush_events();
6613     flush_sequence();
6614     keybd_event(VK_MENU, 0, 0, 0);
6615     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
6616     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
6617     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6618     pump_msg_loop(hwnd, 0);
6619     ok_sequence(WmAltMouseButton, "Alt+MouseButton press/release", FALSE);
6620
6621     trace("testing VK_F1 press/release\n");
6622     keybd_event(VK_F1, 0, 0, 0);
6623     keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
6624     pump_msg_loop(hwnd, 0);
6625     ok_sequence(WmF1Seq, "F1 press/release", FALSE);
6626
6627     trace("testing VK_APPS press/release\n");
6628     keybd_event(VK_APPS, 0, 0, 0);
6629     keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
6630     pump_msg_loop(hwnd, 0);
6631     ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
6632
6633     DestroyWindow(hwnd);
6634 }
6635
6636 /************* window procedures ********************/
6637
6638 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message, 
6639                              WPARAM wParam, LPARAM lParam)
6640 {
6641     static long defwndproc_counter = 0;
6642     static long beginpaint_counter = 0;
6643     LRESULT ret;
6644     struct message msg;
6645
6646     trace("%p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6647
6648     /* explicitly ignore WM_GETICON message */
6649     if (message == WM_GETICON) return 0;
6650
6651     /* ignore registered messages */
6652     if (message >= 0xc000) return 0;
6653
6654     switch (message)
6655     {
6656         case WM_ENABLE:
6657         {
6658             LONG style = GetWindowLongA(hwnd, GWL_STYLE);
6659             ok((BOOL)wParam == !(style & WS_DISABLED),
6660                 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
6661             break;
6662         }
6663
6664         case WM_CAPTURECHANGED:
6665             if (test_DestroyWindow_flag)
6666             {
6667                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6668                 if (style & WS_CHILD)
6669                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6670                 else if (style & WS_POPUP)
6671                     lParam = WND_POPUP_ID;
6672                 else
6673                     lParam = WND_PARENT_ID;
6674             }
6675             break;
6676
6677         case WM_NCDESTROY:
6678         {
6679             HWND capture;
6680
6681             ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
6682             capture = GetCapture();
6683             if (capture)
6684             {
6685                 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
6686                 trace("current capture %p, releasing...\n", capture);
6687                 ReleaseCapture();
6688             }
6689         }
6690         /* fall through */
6691         case WM_DESTROY:
6692             if (pGetAncestor)
6693                 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
6694             if (test_DestroyWindow_flag)
6695             {
6696                 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6697                 if (style & WS_CHILD)
6698                     lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6699                 else if (style & WS_POPUP)
6700                     lParam = WND_POPUP_ID;
6701                 else
6702                     lParam = WND_PARENT_ID;
6703             }
6704             break;
6705
6706         /* test_accelerators() depends on this */
6707         case WM_NCHITTEST:
6708             return HTCLIENT;
6709     
6710         /* ignore */
6711         case WM_MOUSEMOVE:
6712         case WM_SETCURSOR:
6713         case WM_DEVICECHANGE:
6714             return 0;
6715
6716         case WM_WINDOWPOSCHANGING:
6717         case WM_WINDOWPOSCHANGED:
6718         {
6719             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6720
6721             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6722             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x ",
6723                   winpos->hwnd, winpos->hwndInsertAfter,
6724                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6725             dump_winpos_flags(winpos->flags);
6726
6727             /* Log only documented flags, win2k uses 0x1000 and 0x2000
6728              * in the high word for internal purposes
6729              */
6730             wParam = winpos->flags & 0xffff;
6731             /* We are not interested in the flags that don't match under XP and Win9x */
6732             wParam &= ~(SWP_NOZORDER);
6733             break;
6734         }
6735     }
6736
6737     msg.message = message;
6738     msg.flags = sent|wparam|lparam;
6739     if (defwndproc_counter) msg.flags |= defwinproc;
6740     if (beginpaint_counter) msg.flags |= beginpaint;
6741     msg.wParam = wParam;
6742     msg.lParam = lParam;
6743     add_message(&msg);
6744
6745     if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
6746     {
6747         HWND parent = GetParent(hwnd);
6748         RECT rc;
6749         MINMAXINFO *minmax = (MINMAXINFO *)lParam;
6750
6751         GetClientRect(parent, &rc);
6752         trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
6753         trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
6754               minmax->ptReserved.x, minmax->ptReserved.y,
6755               minmax->ptMaxSize.x, minmax->ptMaxSize.y,
6756               minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
6757               minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
6758               minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
6759
6760         ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
6761            minmax->ptMaxSize.x, rc.right);
6762         ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
6763            minmax->ptMaxSize.y, rc.bottom);
6764     }
6765
6766     if (message == WM_PAINT)
6767     {
6768         PAINTSTRUCT ps;
6769         beginpaint_counter++;
6770         BeginPaint( hwnd, &ps );
6771         beginpaint_counter--;
6772         EndPaint( hwnd, &ps );
6773         return 0;
6774     }
6775
6776     defwndproc_counter++;
6777     ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam) 
6778                   : DefWindowProcA(hwnd, message, wParam, lParam);
6779     defwndproc_counter--;
6780
6781     return ret;
6782 }
6783
6784 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6785 {
6786     return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
6787 }
6788
6789 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6790 {
6791     return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
6792 }
6793
6794 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6795 {
6796     static long defwndproc_counter = 0;
6797     LRESULT ret;
6798     struct message msg;
6799
6800     trace("popup: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6801
6802     switch (message)
6803     {
6804     case WM_GETICON:
6805         /* explicitly ignore WM_GETICON message */
6806         return 0;
6807     case WM_QUERYENDSESSION:
6808     case WM_ENDSESSION:
6809         lParam &= ~0x01;  /* Vista adds a 0x01 flag */
6810         break;
6811     }
6812
6813     msg.message = message;
6814     msg.flags = sent|wparam|lparam;
6815     if (defwndproc_counter) msg.flags |= defwinproc;
6816     msg.wParam = wParam;
6817     msg.lParam = lParam;
6818     add_message(&msg);
6819
6820     if (message == WM_CREATE)
6821     {
6822         DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
6823         SetWindowLongA(hwnd, GWL_STYLE, style);
6824     }
6825
6826     defwndproc_counter++;
6827     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6828     defwndproc_counter--;
6829
6830     return ret;
6831 }
6832
6833 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6834 {
6835     static long defwndproc_counter = 0;
6836     static long beginpaint_counter = 0;
6837     LRESULT ret;
6838     struct message msg;
6839     LPARAM logged_lParam;
6840
6841     trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6842
6843     /* explicitly ignore WM_GETICON message */
6844     if (message == WM_GETICON) return 0;
6845
6846     /* ignore registered messages */
6847     if (message >= 0xc000) return 0;
6848
6849     logged_lParam=lParam;
6850     if (log_all_parent_messages ||
6851         message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
6852         message == WM_SETFOCUS || message == WM_KILLFOCUS ||
6853         message == WM_ENABLE || message == WM_ENTERIDLE ||
6854         message == WM_DRAWITEM ||
6855         message == WM_IME_SETCONTEXT)
6856     {
6857         switch (message)
6858         {
6859             /* ignore */
6860             case WM_NCHITTEST:
6861                 return HTCLIENT;
6862             case WM_SETCURSOR:
6863             case WM_MOUSEMOVE:
6864                 return 0;
6865
6866             case WM_ERASEBKGND:
6867             {
6868                 RECT rc;
6869                 INT ret = GetClipBox((HDC)wParam, &rc);
6870
6871                 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
6872                        ret, rc.left, rc.top, rc.right, rc.bottom);
6873                 break;
6874             }
6875
6876             case WM_WINDOWPOSCHANGING:
6877             case WM_WINDOWPOSCHANGED:
6878             {
6879                 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6880
6881                 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6882                 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x ",
6883                       winpos->hwnd, winpos->hwndInsertAfter,
6884                       winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6885                 dump_winpos_flags(winpos->flags);
6886
6887                 /* Log only documented flags, win2k uses 0x1000 and 0x2000
6888                  * in the high word for internal purposes
6889                  */
6890                 wParam = winpos->flags & 0xffff;
6891                 /* We are not interested in the flags that don't match under XP and Win9x */
6892                 wParam &= ~(SWP_NOZORDER);
6893                 break;
6894             }
6895
6896             case WM_DRAWITEM:
6897             {
6898                 /* encode DRAWITEMSTRUCT into an LPARAM */
6899                 DRAW_ITEM_STRUCT di;
6900                 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam;
6901
6902                 trace("WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x\n",
6903                       dis->CtlType, dis->CtlID, dis->itemID, dis->itemAction, dis->itemState);
6904
6905                 di.u.item.type = dis->CtlType;
6906                 di.u.item.ctl_id = dis->CtlID;
6907                 di.u.item.item_id = dis->itemID;
6908                 di.u.item.action = dis->itemAction;
6909                 di.u.item.state = dis->itemState;
6910
6911                 logged_lParam = di.u.lp;
6912                 break;
6913             }
6914         }
6915
6916         msg.message = message;
6917         msg.flags = sent|parent|wparam|lparam;
6918         if (defwndproc_counter) msg.flags |= defwinproc;
6919         if (beginpaint_counter) msg.flags |= beginpaint;
6920         msg.wParam = wParam;
6921         msg.lParam = logged_lParam;
6922         add_message(&msg);
6923     }
6924
6925     if (message == WM_PAINT)
6926     {
6927         PAINTSTRUCT ps;
6928         beginpaint_counter++;
6929         BeginPaint( hwnd, &ps );
6930         beginpaint_counter--;
6931         EndPaint( hwnd, &ps );
6932         return 0;
6933     }
6934
6935     defwndproc_counter++;
6936     ret = DefWindowProcA(hwnd, message, wParam, lParam);
6937     defwndproc_counter--;
6938
6939     return ret;
6940 }
6941
6942 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6943 {
6944     static long defwndproc_counter = 0;
6945     LRESULT ret;
6946     struct message msg;
6947
6948     trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6949
6950     /* explicitly ignore WM_GETICON message */
6951     if (message == WM_GETICON) return 0;
6952
6953     /* ignore registered messages */
6954     if (message >= 0xc000) return 0;
6955
6956     if (test_def_id)
6957     {
6958         DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
6959         ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
6960         if (after_end_dialog)
6961             ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
6962         else
6963             ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
6964     }
6965
6966     switch (message)
6967     {
6968         case WM_WINDOWPOSCHANGING:
6969         case WM_WINDOWPOSCHANGED:
6970         {
6971             WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6972
6973             trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6974             trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x ",
6975                   winpos->hwnd, winpos->hwndInsertAfter,
6976                   winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6977             dump_winpos_flags(winpos->flags);
6978
6979             /* Log only documented flags, win2k uses 0x1000 and 0x2000
6980              * in the high word for internal purposes
6981              */
6982             wParam = winpos->flags & 0xffff;
6983             /* We are not interested in the flags that don't match under XP and Win9x */
6984             wParam &= ~(SWP_NOZORDER);
6985             break;
6986         }
6987     }
6988
6989     msg.message = message;
6990     msg.flags = sent|wparam|lparam;
6991     if (defwndproc_counter) msg.flags |= defwinproc;
6992     msg.wParam = wParam;
6993     msg.lParam = lParam;
6994     add_message(&msg);
6995
6996     defwndproc_counter++;
6997     ret = DefDlgProcA(hwnd, message, wParam, lParam);
6998     defwndproc_counter--;
6999
7000     return ret;
7001 }
7002
7003 static void dump_winpos_flags(UINT flags)
7004 {
7005     if (!winetest_debug) return;
7006
7007     if (flags & SWP_SHOWWINDOW) printf("|SWP_SHOWWINDOW");
7008     if (flags & SWP_HIDEWINDOW) printf("|SWP_HIDEWINDOW");
7009     if (flags & SWP_NOACTIVATE) printf("|SWP_NOACTIVATE");
7010     if (flags & SWP_FRAMECHANGED) printf("|SWP_FRAMECHANGED");
7011     if (flags & SWP_NOCOPYBITS) printf("|SWP_NOCOPYBITS");
7012     if (flags & SWP_NOOWNERZORDER) printf("|SWP_NOOWNERZORDER");
7013     if (flags & SWP_NOSENDCHANGING) printf("|SWP_NOSENDCHANGING");
7014     if (flags & SWP_DEFERERASE) printf("|SWP_DEFERERASE");
7015     if (flags & SWP_ASYNCWINDOWPOS) printf("|SWP_ASYNCWINDOWPOS");
7016     if (flags & SWP_NOZORDER) printf("|SWP_NOZORDER");
7017     if (flags & SWP_NOREDRAW) printf("|SWP_NOREDRAW");
7018     if (flags & SWP_NOSIZE) printf("|SWP_NOSIZE");
7019     if (flags & SWP_NOMOVE) printf("|SWP_NOMOVE");
7020     if (flags & SWP_NOCLIENTSIZE) printf("|SWP_NOCLIENTSIZE");
7021     if (flags & SWP_NOCLIENTMOVE) printf("|SWP_NOCLIENTMOVE");
7022
7023 #define DUMPED_FLAGS \
7024     (SWP_NOSIZE | \
7025     SWP_NOMOVE | \
7026     SWP_NOZORDER | \
7027     SWP_NOREDRAW | \
7028     SWP_NOACTIVATE | \
7029     SWP_FRAMECHANGED | \
7030     SWP_SHOWWINDOW | \
7031     SWP_HIDEWINDOW | \
7032     SWP_NOCOPYBITS | \
7033     SWP_NOOWNERZORDER | \
7034     SWP_NOSENDCHANGING | \
7035     SWP_DEFERERASE | \
7036     SWP_ASYNCWINDOWPOS | \
7037     SWP_NOCLIENTSIZE | \
7038     SWP_NOCLIENTMOVE)
7039
7040     if(flags & ~DUMPED_FLAGS) printf("|0x%04x", flags & ~DUMPED_FLAGS);
7041     printf("\n");
7042 #undef DUMPED_FLAGS
7043 }
7044
7045 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7046 {
7047     static long defwndproc_counter = 0;
7048     LRESULT ret;
7049     struct message msg;
7050
7051     /* log only specific messages we are interested in */
7052     switch (message)
7053     {
7054 #if 0 /* probably log these as well */
7055     case WM_ACTIVATE:
7056     case WM_SETFOCUS:
7057     case WM_KILLFOCUS:
7058 #endif
7059     case WM_SHOWWINDOW:
7060         trace("WM_SHOWWINDOW %ld\n", wParam);
7061         break;
7062     case WM_SIZE:
7063         trace("WM_SIZE %ld\n", wParam);
7064         break;
7065     case WM_MOVE:
7066         trace("WM_MOVE\n");
7067         break;
7068     case WM_GETMINMAXINFO:
7069         trace("WM_GETMINMAXINFO\n");
7070         break;
7071
7072     case WM_WINDOWPOSCHANGING:
7073     case WM_WINDOWPOSCHANGED:
7074     {
7075         WINDOWPOS *winpos = (WINDOWPOS *)lParam;
7076
7077         trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
7078         trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
7079               winpos->hwnd, winpos->hwndInsertAfter,
7080               winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
7081         trace("flags: ");
7082         dump_winpos_flags(winpos->flags);
7083
7084         /* Log only documented flags, win2k uses 0x1000 and 0x2000
7085          * in the high word for internal purposes
7086          */
7087         wParam = winpos->flags & 0xffff;
7088         /* We are not interested in the flags that don't match under XP and Win9x */
7089         wParam &= ~(SWP_NOZORDER);
7090         break;
7091     }
7092
7093     default: /* ignore */
7094         /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
7095         return DefWindowProcA(hwnd, message, wParam, lParam);
7096     }
7097
7098     msg.message = message;
7099     msg.flags = sent|wparam|lparam;
7100     if (defwndproc_counter) msg.flags |= defwinproc;
7101     msg.wParam = wParam;
7102     msg.lParam = lParam;
7103     add_message(&msg);
7104
7105     defwndproc_counter++;
7106     ret = DefWindowProcA(hwnd, message, wParam, lParam);
7107     defwndproc_counter--;
7108
7109     return ret;
7110 }
7111
7112 LRESULT WINAPI PaintLoopProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
7113 {
7114     switch (msg)
7115     {
7116         case WM_CREATE: return 0;
7117         case WM_PAINT:
7118         {
7119             MSG msg2;
7120             static int i = 0;
7121
7122             if (i < 256)
7123             {
7124                 i++;
7125                 if (PeekMessageA(&msg2, 0, 0, 0, 1))
7126                 {
7127                     TranslateMessage(&msg2);
7128                     DispatchMessage(&msg2);
7129                 }
7130                 i--;
7131             }
7132             else ok(broken(1), "infinite loop\n");
7133             if ( i == 0)
7134                 paint_loop_done = 1;
7135             return DefWindowProcA(hWnd,msg,wParam,lParam);
7136         }
7137     }
7138     return DefWindowProcA(hWnd,msg,wParam,lParam);
7139 }
7140
7141 static BOOL RegisterWindowClasses(void)
7142 {
7143     WNDCLASSA cls;
7144     WNDCLASSW clsW;
7145
7146     cls.style = 0;
7147     cls.lpfnWndProc = MsgCheckProcA;
7148     cls.cbClsExtra = 0;
7149     cls.cbWndExtra = 0;
7150     cls.hInstance = GetModuleHandleA(0);
7151     cls.hIcon = 0;
7152     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
7153     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7154     cls.lpszMenuName = NULL;
7155     cls.lpszClassName = "TestWindowClass";
7156     if(!RegisterClassA(&cls)) return FALSE;
7157
7158     cls.lpfnWndProc = ShowWindowProcA;
7159     cls.lpszClassName = "ShowWindowClass";
7160     if(!RegisterClassA(&cls)) return FALSE;
7161
7162     cls.lpfnWndProc = PopupMsgCheckProcA;
7163     cls.lpszClassName = "TestPopupClass";
7164     if(!RegisterClassA(&cls)) return FALSE;
7165
7166     cls.lpfnWndProc = ParentMsgCheckProcA;
7167     cls.lpszClassName = "TestParentClass";
7168     if(!RegisterClassA(&cls)) return FALSE;
7169
7170     cls.lpfnWndProc = DefWindowProcA;
7171     cls.lpszClassName = "SimpleWindowClass";
7172     if(!RegisterClassA(&cls)) return FALSE;
7173
7174     cls.lpfnWndProc = PaintLoopProcA;
7175     cls.lpszClassName = "PaintLoopWindowClass";
7176     if(!RegisterClassA(&cls)) return FALSE;
7177
7178     cls.style = CS_NOCLOSE;
7179     cls.lpszClassName = "NoCloseWindowClass";
7180     if(!RegisterClassA(&cls)) return FALSE;
7181
7182     ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
7183     cls.style = 0;
7184     cls.hInstance = GetModuleHandleA(0);
7185     cls.hbrBackground = 0;
7186     cls.lpfnWndProc = TestDlgProcA;
7187     cls.lpszClassName = "TestDialogClass";
7188     if(!RegisterClassA(&cls)) return FALSE;
7189
7190     clsW.style = 0;
7191     clsW.lpfnWndProc = MsgCheckProcW;
7192     clsW.cbClsExtra = 0;
7193     clsW.cbWndExtra = 0;
7194     clsW.hInstance = GetModuleHandleW(0);
7195     clsW.hIcon = 0;
7196     clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
7197     clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
7198     clsW.lpszMenuName = NULL;
7199     clsW.lpszClassName = testWindowClassW;
7200     RegisterClassW(&clsW);  /* ignore error, this fails on Win9x */
7201
7202     return TRUE;
7203 }
7204
7205 static BOOL is_our_logged_class(HWND hwnd)
7206 {
7207     char buf[256];
7208
7209     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7210     {
7211         if (!lstrcmpiA(buf, "TestWindowClass") ||
7212             !lstrcmpiA(buf, "ShowWindowClass") ||
7213             !lstrcmpiA(buf, "TestParentClass") ||
7214             !lstrcmpiA(buf, "TestPopupClass") ||
7215             !lstrcmpiA(buf, "SimpleWindowClass") ||
7216             !lstrcmpiA(buf, "TestDialogClass") ||
7217             !lstrcmpiA(buf, "MDI_frame_class") ||
7218             !lstrcmpiA(buf, "MDI_client_class") ||
7219             !lstrcmpiA(buf, "MDI_child_class") ||
7220             !lstrcmpiA(buf, "my_button_class") ||
7221             !lstrcmpiA(buf, "my_edit_class") ||
7222             !lstrcmpiA(buf, "static") ||
7223             !lstrcmpiA(buf, "ListBox") ||
7224             !lstrcmpiA(buf, "ComboBox") ||
7225             !lstrcmpiA(buf, "MyDialogClass") ||
7226             !lstrcmpiA(buf, "#32770") ||
7227             !lstrcmpiA(buf, "#32768"))
7228         return TRUE;
7229         trace("ignoring window class %s\n", buf);
7230     }
7231     return FALSE;
7232 }
7233
7234 static HHOOK hCBT_hook;
7235 static DWORD cbt_hook_thread_id;
7236
7237 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7238
7239     static const char * const CBT_code_name[10] = {
7240         "HCBT_MOVESIZE",
7241         "HCBT_MINMAX",
7242         "HCBT_QS",
7243         "HCBT_CREATEWND",
7244         "HCBT_DESTROYWND",
7245         "HCBT_ACTIVATE",
7246         "HCBT_CLICKSKIPPED",
7247         "HCBT_KEYSKIPPED",
7248         "HCBT_SYSCOMMAND",
7249         "HCBT_SETFOCUS" };
7250     const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
7251     HWND hwnd;
7252
7253     trace("CBT: %d (%s), %08lx, %08lx\n", nCode, code_name, wParam, lParam);
7254
7255     ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7256
7257     if (nCode == HCBT_CLICKSKIPPED)
7258     {
7259         /* ignore this event, XP sends it a lot when switching focus between windows */
7260         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7261     }
7262
7263     if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
7264     {
7265         struct message msg;
7266
7267         msg.message = nCode;
7268         msg.flags = hook|wparam|lparam;
7269         msg.wParam = wParam;
7270         msg.lParam = lParam;
7271         add_message(&msg);
7272
7273         return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7274     }
7275
7276     if (nCode == HCBT_DESTROYWND)
7277     {
7278         if (test_DestroyWindow_flag)
7279         {
7280             DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
7281             if (style & WS_CHILD)
7282                 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
7283             else if (style & WS_POPUP)
7284                 lParam = WND_POPUP_ID;
7285             else
7286                 lParam = WND_PARENT_ID;
7287         }
7288     }
7289
7290     /* Log also SetFocus(0) calls */
7291     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7292
7293     if (is_our_logged_class(hwnd))
7294     {
7295         struct message msg;
7296
7297         msg.message = nCode;
7298         msg.flags = hook|wparam|lparam;
7299         msg.wParam = wParam;
7300         msg.lParam = lParam;
7301         add_message(&msg);
7302     }
7303     return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7304 }
7305
7306 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
7307                                     DWORD event,
7308                                     HWND hwnd,
7309                                     LONG object_id,
7310                                     LONG child_id,
7311                                     DWORD thread_id,
7312                                     DWORD event_time)
7313 {
7314     trace("WEH:%p,event %08x,hwnd %p,obj %08x,id %08x,thread %08x,time %08x\n",
7315            hevent, event, hwnd, object_id, child_id, thread_id, event_time);
7316
7317     ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7318
7319     /* ignore mouse cursor events */
7320     if (object_id == OBJID_CURSOR) return;
7321
7322     if (!hwnd || is_our_logged_class(hwnd))
7323     {
7324         struct message msg;
7325
7326         msg.message = event;
7327         msg.flags = winevent_hook|wparam|lparam;
7328         msg.wParam = object_id;
7329         msg.lParam = child_id;
7330         add_message(&msg);
7331     }
7332 }
7333
7334 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
7335 static const WCHAR wszAnsi[] = {'U',0};
7336
7337 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
7338 {
7339     switch (uMsg)
7340     {
7341     case CB_FINDSTRINGEXACT:
7342         trace("String: %p\n", (LPCWSTR)lParam);
7343         if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
7344             return 1;
7345         if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
7346             return 0;
7347         return -1;
7348     }
7349     return DefWindowProcW(hwnd, uMsg, wParam, lParam);
7350 }
7351
7352 static const struct message WmGetTextLengthAfromW[] = {
7353     { WM_GETTEXTLENGTH, sent },
7354     { WM_GETTEXT, sent|optional },
7355     { 0 }
7356 };
7357
7358 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
7359
7360 /* dummy window proc for WM_GETTEXTLENGTH test */
7361 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
7362 {
7363     switch(msg)
7364     {
7365     case WM_GETTEXTLENGTH:
7366         return lstrlenW(dummy_window_text) + 37;  /* some random length */
7367     case WM_GETTEXT:
7368         lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
7369         return lstrlenW( (LPWSTR)lp );
7370     default:
7371         return DefWindowProcW( hwnd, msg, wp, lp );
7372     }
7373 }
7374
7375 static void test_message_conversion(void)
7376 {
7377     static const WCHAR wszMsgConversionClass[] =
7378         {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
7379     WNDCLASSW cls;
7380     LRESULT lRes;
7381     HWND hwnd;
7382     WNDPROC wndproc, newproc;
7383     BOOL ret;
7384
7385     cls.style = 0;
7386     cls.lpfnWndProc = MsgConversionProcW;
7387     cls.cbClsExtra = 0;
7388     cls.cbWndExtra = 0;
7389     cls.hInstance = GetModuleHandleW(NULL);
7390     cls.hIcon = NULL;
7391     cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
7392     cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
7393     cls.lpszMenuName = NULL;
7394     cls.lpszClassName = wszMsgConversionClass;
7395     /* this call will fail on Win9x, but that doesn't matter as this test is
7396      * meaningless on those platforms */
7397     if(!RegisterClassW(&cls)) return;
7398
7399     hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
7400                            100, 100, 200, 200, 0, 0, 0, NULL);
7401     ok(hwnd != NULL, "Window creation failed\n");
7402
7403     /* {W, A} -> A */
7404
7405     wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
7406     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7407     ok(lRes == 0, "String should have been converted\n");
7408     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7409     ok(lRes == 1, "String shouldn't have been converted\n");
7410
7411     /* {W, A} -> W */
7412
7413     wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
7414     lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7415     ok(lRes == 1, "String shouldn't have been converted\n");
7416     lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7417     ok(lRes == 1, "String shouldn't have been converted\n");
7418
7419     /* Synchronous messages */
7420
7421     lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7422     ok(lRes == 0, "String should have been converted\n");
7423     lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7424     ok(lRes == 1, "String shouldn't have been converted\n");
7425
7426     /* Asynchronous messages */
7427
7428     SetLastError(0);
7429     lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7430     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7431         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7432     SetLastError(0);
7433     lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7434     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7435         "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7436     SetLastError(0);
7437     lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7438     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7439         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7440     SetLastError(0);
7441     lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7442     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7443         "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7444     SetLastError(0);
7445     lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7446     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7447         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7448     SetLastError(0);
7449     lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7450     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7451         "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7452     SetLastError(0);
7453     lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7454     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7455         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7456     SetLastError(0);
7457     lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7458     ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7459         "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7460
7461     /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
7462
7463     hwnd = CreateWindowW (testWindowClassW, wszUnicode,
7464                           WS_OVERLAPPEDWINDOW,
7465                           100, 100, 200, 200, 0, 0, 0, NULL);
7466     assert(hwnd);
7467     flush_sequence();
7468     lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
7469     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7470     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7471         "got bad length %ld\n", lRes );
7472
7473     flush_sequence();
7474     lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
7475                             hwnd, WM_GETTEXTLENGTH, 0, 0);
7476     ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7477     ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7478         "got bad length %ld\n", lRes );
7479
7480     wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
7481     newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
7482     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7483     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7484                                      NULL, 0, NULL, NULL ) ||
7485         broken(lRes == lstrlenW(dummy_window_text) + 37),
7486         "got bad length %ld\n", lRes );
7487
7488     SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc );  /* restore old wnd proc */
7489     lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7490     ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7491                                      NULL, 0, NULL, NULL ) ||
7492         broken(lRes == lstrlenW(dummy_window_text) + 37),
7493         "got bad length %ld\n", lRes );
7494
7495     ret = DestroyWindow(hwnd);
7496     ok( ret, "DestroyWindow() error %d\n", GetLastError());
7497 }
7498
7499 struct timer_info
7500 {
7501     HWND hWnd;
7502     HANDLE handles[2];
7503     DWORD id;
7504 };
7505
7506 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
7507 {
7508 }
7509
7510 #define TIMER_ID  0x19
7511
7512 static DWORD WINAPI timer_thread_proc(LPVOID x)
7513 {
7514     struct timer_info *info = x;
7515     DWORD r;
7516
7517     r = KillTimer(info->hWnd, 0x19);
7518     ok(r,"KillTimer failed in thread\n");
7519     r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
7520     ok(r,"SetTimer failed in thread\n");
7521     ok(r==TIMER_ID,"SetTimer id different\n");
7522     r = SetEvent(info->handles[0]);
7523     ok(r,"SetEvent failed in thread\n");
7524     return 0;
7525 }
7526
7527 static void test_timers(void)
7528 {
7529     struct timer_info info;
7530     DWORD id;
7531
7532     info.hWnd = CreateWindow ("TestWindowClass", NULL,
7533        WS_OVERLAPPEDWINDOW ,
7534        CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7535        NULL, NULL, 0);
7536
7537     info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
7538     ok(info.id, "SetTimer failed\n");
7539     ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
7540     info.handles[0] = CreateEvent(NULL,0,0,NULL);
7541     info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
7542
7543     WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
7544
7545     WaitForSingleObject(info.handles[1], INFINITE);
7546
7547     CloseHandle(info.handles[0]);
7548     CloseHandle(info.handles[1]);
7549
7550     ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
7551
7552     ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
7553 }
7554
7555 static int count = 0;
7556 static VOID CALLBACK callback_count(
7557     HWND hwnd,
7558     UINT uMsg,
7559     UINT_PTR idEvent,
7560     DWORD dwTime
7561 )
7562 {
7563     count++;
7564 }
7565
7566 static void test_timers_no_wnd(void)
7567 {
7568     UINT_PTR id, id2;
7569     MSG msg;
7570
7571     count = 0;
7572     id = SetTimer(NULL, 0, 100, callback_count);
7573     ok(id != 0, "did not get id from SetTimer.\n");
7574     id2 = SetTimer(NULL, id, 200, callback_count);
7575     ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
7576     Sleep(150);
7577     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7578     ok(count == 0, "did not get zero count as expected (%i).\n", count);
7579     Sleep(150);
7580     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7581     ok(count == 1, "did not get one count as expected (%i).\n", count);
7582     KillTimer(NULL, id);
7583     Sleep(250);
7584     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7585     ok(count == 1, "killing replaced timer did not work (%i).\n", count);
7586 }
7587
7588 /* Various win events with arbitrary parameters */
7589 static const struct message WmWinEventsSeq[] = {
7590     { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7591     { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7592     { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7593     { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7594     { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7595     { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7596     { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7597     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7598     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7599     /* our win event hook ignores OBJID_CURSOR events */
7600     /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
7601     { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
7602     { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
7603     { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
7604     { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
7605     { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7606     { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7607     { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7608     { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7609     { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7610     { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7611     { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7612     { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7613     { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7614     { 0 }
7615 };
7616 static const struct message WmWinEventCaretSeq[] = {
7617     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7618     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7619     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
7620     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7621     { 0 }
7622 };
7623 static const struct message WmWinEventCaretSeq_2[] = {
7624     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7625     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7626     { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7627     { 0 }
7628 };
7629 static const struct message WmWinEventAlertSeq[] = {
7630     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
7631     { 0 }
7632 };
7633 static const struct message WmWinEventAlertSeq_2[] = {
7634     /* create window in the thread proc */
7635     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
7636     /* our test event */
7637     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
7638     { 0 }
7639 };
7640 static const struct message WmGlobalHookSeq_1[] = {
7641     /* create window in the thread proc */
7642     { HCBT_CREATEWND, hook|lparam, 0, 2 },
7643     /* our test events */
7644     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
7645     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
7646     { 0 }
7647 };
7648 static const struct message WmGlobalHookSeq_2[] = {
7649     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
7650     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
7651     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
7652     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
7653     { 0 }
7654 };
7655
7656 static const struct message WmMouseLLHookSeq[] = {
7657     { WM_MOUSEMOVE, hook },
7658     { WM_LBUTTONUP, hook },
7659     { WM_MOUSEMOVE, hook },
7660     { 0 }
7661 };
7662
7663 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
7664                                          DWORD event,
7665                                          HWND hwnd,
7666                                          LONG object_id,
7667                                          LONG child_id,
7668                                          DWORD thread_id,
7669                                          DWORD event_time)
7670 {
7671     char buf[256];
7672
7673     trace("WEH_2:%p,event %08x,hwnd %p,obj %08x,id %08x,thread %08x,time %08x\n",
7674            hevent, event, hwnd, object_id, child_id, thread_id, event_time);
7675
7676     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7677     {
7678         if (!lstrcmpiA(buf, "TestWindowClass") ||
7679             !lstrcmpiA(buf, "static"))
7680         {
7681             struct message msg;
7682
7683             msg.message = event;
7684             msg.flags = winevent_hook|wparam|lparam;
7685             msg.wParam = object_id;
7686             msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
7687             add_message(&msg);
7688         }
7689     }
7690 }
7691
7692 static HHOOK hCBT_global_hook;
7693 static DWORD cbt_global_hook_thread_id;
7694
7695 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) 
7696
7697     HWND hwnd;
7698     char buf[256];
7699
7700     trace("CBT_2: %d, %08lx, %08lx\n", nCode, wParam, lParam);
7701
7702     if (nCode == HCBT_SYSCOMMAND)
7703     {
7704         struct message msg;
7705
7706         msg.message = nCode;
7707         msg.flags = hook|wparam|lparam;
7708         msg.wParam = wParam;
7709         msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7710         add_message(&msg);
7711
7712         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7713     }
7714     /* WH_MOUSE_LL hook */
7715     if (nCode == HC_ACTION)
7716     {
7717         MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
7718
7719         /* we can't test for real mouse events */
7720         if (mhll->flags & LLMHF_INJECTED)
7721         {
7722             struct message msg;
7723
7724             memset (&msg, 0, sizeof (msg));
7725             msg.message = wParam;
7726             msg.flags = hook;
7727             add_message(&msg);
7728         }
7729         return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7730     }
7731
7732     /* Log also SetFocus(0) calls */
7733     hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7734
7735     if (GetClassNameA(hwnd, buf, sizeof(buf)))
7736     {
7737         if (!lstrcmpiA(buf, "TestWindowClass") ||
7738             !lstrcmpiA(buf, "static"))
7739         {
7740             struct message msg;
7741
7742             msg.message = nCode;
7743             msg.flags = hook|wparam|lparam;
7744             msg.wParam = wParam;
7745             msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 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     todo_wine { /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
8212                 /* windows sometimes a WM_MOVE */
8213         ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8214     }
8215     trace("end scroll\n");
8216     flush_sequence();
8217     flush_events();
8218     ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8219     flush_events();
8220     flush_sequence();
8221
8222     /* now scroll with ScrollWindow() */
8223     trace("start scroll with ScrollWindow\n");
8224     ScrollWindow( hwnd, 5, 5, NULL, NULL);
8225     trace("end scroll\n");
8226     flush_sequence();
8227     flush_events();
8228     ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
8229
8230     ok(DestroyWindow(hchild), "failed to destroy window\n");
8231     ok(DestroyWindow(hwnd), "failed to destroy window\n");
8232     flush_sequence();
8233 }
8234
8235 static const struct message destroy_window_with_children[] = {
8236     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8237     { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
8238     { 0x0090, sent|optional },
8239     { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
8240     { 0x0090, sent|optional },
8241     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8242     { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8243     { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8244     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8245     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
8246     { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8247     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8248     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8249     { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8250     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8251     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8252     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8253     { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8254     { 0 }
8255 };
8256
8257 static void test_DestroyWindow(void)
8258 {
8259     BOOL ret;
8260     HWND parent, child1, child2, child3, child4, test;
8261     UINT child_id = WND_CHILD_ID + 1;
8262
8263     parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8264                              100, 100, 200, 200, 0, 0, 0, NULL);
8265     assert(parent != 0);
8266     child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8267                              0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
8268     assert(child1 != 0);
8269     child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8270                              0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
8271     assert(child2 != 0);
8272     child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8273                              0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
8274     assert(child3 != 0);
8275     child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
8276                              0, 0, 50, 50, parent, 0, 0, NULL);
8277     assert(child4 != 0);
8278
8279     /* test owner/parent of child2 */
8280     test = GetParent(child2);
8281     ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8282     ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8283     if(pGetAncestor) {
8284         test = pGetAncestor(child2, GA_PARENT);
8285         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8286     }
8287     test = GetWindow(child2, GW_OWNER);
8288     ok(!test, "wrong owner %p\n", test);
8289
8290     test = SetParent(child2, parent);
8291     ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
8292
8293     /* test owner/parent of the parent */
8294     test = GetParent(parent);
8295     ok(!test, "wrong parent %p\n", test);
8296     ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
8297     if(pGetAncestor) {
8298         test = pGetAncestor(parent, GA_PARENT);
8299         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8300     }
8301     test = GetWindow(parent, GW_OWNER);
8302     ok(!test, "wrong owner %p\n", test);
8303
8304     /* test owner/parent of child1 */
8305     test = GetParent(child1);
8306     ok(test == parent, "wrong parent %p\n", test);
8307     ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
8308     if(pGetAncestor) {
8309         test = pGetAncestor(child1, GA_PARENT);
8310         ok(test == parent, "wrong parent %p\n", test);
8311     }
8312     test = GetWindow(child1, GW_OWNER);
8313     ok(!test, "wrong owner %p\n", test);
8314
8315     /* test owner/parent of child2 */
8316     test = GetParent(child2);
8317     ok(test == parent, "wrong parent %p\n", test);
8318     ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8319     if(pGetAncestor) {
8320         test = pGetAncestor(child2, GA_PARENT);
8321         ok(test == parent, "wrong parent %p\n", test);
8322     }
8323     test = GetWindow(child2, GW_OWNER);
8324     ok(!test, "wrong owner %p\n", test);
8325
8326     /* test owner/parent of child3 */
8327     test = GetParent(child3);
8328     ok(test == child1, "wrong parent %p\n", test);
8329     ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
8330     if(pGetAncestor) {
8331         test = pGetAncestor(child3, GA_PARENT);
8332         ok(test == child1, "wrong parent %p\n", test);
8333     }
8334     test = GetWindow(child3, GW_OWNER);
8335     ok(!test, "wrong owner %p\n", test);
8336
8337     /* test owner/parent of child4 */
8338     test = GetParent(child4);
8339     ok(test == parent, "wrong parent %p\n", test);
8340     ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
8341     if(pGetAncestor) {
8342         test = pGetAncestor(child4, GA_PARENT);
8343         ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8344     }
8345     test = GetWindow(child4, GW_OWNER);
8346     ok(test == parent, "wrong owner %p\n", test);
8347
8348     flush_sequence();
8349
8350     trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
8351            parent, child1, child2, child3, child4);
8352
8353     SetCapture(child4);
8354     test = GetCapture();
8355     ok(test == child4, "wrong capture window %p\n", test);
8356
8357     test_DestroyWindow_flag = TRUE;
8358     ret = DestroyWindow(parent);
8359     ok( ret, "DestroyWindow() error %d\n", GetLastError());
8360     test_DestroyWindow_flag = FALSE;
8361     ok_sequence(destroy_window_with_children, "destroy window with children", 0);
8362
8363     ok(!IsWindow(parent), "parent still exists\n");
8364     ok(!IsWindow(child1), "child1 still exists\n");
8365     ok(!IsWindow(child2), "child2 still exists\n");
8366     ok(!IsWindow(child3), "child3 still exists\n");
8367     ok(!IsWindow(child4), "child4 still exists\n");
8368
8369     test = GetCapture();
8370     ok(!test, "wrong capture window %p\n", test);
8371 }
8372
8373
8374 static const struct message WmDispatchPaint[] = {
8375     { WM_NCPAINT, sent },
8376     { WM_GETTEXT, sent|defwinproc|optional },
8377     { WM_GETTEXT, sent|defwinproc|optional },
8378     { WM_ERASEBKGND, sent },
8379     { 0 }
8380 };
8381
8382 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8383 {
8384     if (message == WM_PAINT) return 0;
8385     return MsgCheckProcA( hwnd, message, wParam, lParam );
8386 }
8387
8388 static void test_DispatchMessage(void)
8389 {
8390     RECT rect;
8391     MSG msg;
8392     int count;
8393     HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8394                                100, 100, 200, 200, 0, 0, 0, NULL);
8395     ShowWindow( hwnd, SW_SHOW );
8396     UpdateWindow( hwnd );
8397     flush_events();
8398     flush_sequence();
8399     SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
8400
8401     SetRect( &rect, -5, -5, 5, 5 );
8402     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8403     count = 0;
8404     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8405     {
8406         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8407         else
8408         {
8409             flush_sequence();
8410             DispatchMessage( &msg );
8411             /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
8412             if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8413             else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
8414             if (++count > 10) break;
8415         }
8416     }
8417     ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
8418
8419     trace("now without DispatchMessage\n");
8420     flush_sequence();
8421     RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8422     count = 0;
8423     while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8424     {
8425         if (msg.message != WM_PAINT) DispatchMessage( &msg );
8426         else
8427         {
8428             HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
8429             flush_sequence();
8430             /* this will send WM_NCCPAINT just like DispatchMessage does */
8431             GetUpdateRgn( hwnd, hrgn, TRUE );
8432             ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8433             DeleteObject( hrgn );
8434             GetClientRect( hwnd, &rect );
8435             ValidateRect( hwnd, &rect );  /* this will stop WM_PAINTs */
8436             ok( !count, "Got multiple WM_PAINTs\n" );
8437             if (++count > 10) break;
8438         }
8439     }
8440     DestroyWindow(hwnd);
8441 }
8442
8443
8444 static const struct message WmUser[] = {
8445     { WM_USER, sent },
8446     { 0 }
8447 };
8448
8449 struct sendmsg_info
8450 {
8451     HWND  hwnd;
8452     DWORD timeout;
8453     DWORD ret;
8454 };
8455
8456 static DWORD CALLBACK send_msg_thread( LPVOID arg )
8457 {
8458     struct sendmsg_info *info = arg;
8459     SetLastError( 0xdeadbeef );
8460     info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
8461     if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT ||
8462                         broken(GetLastError() == 0),  /* win9x */
8463                         "unexpected error %d\n", GetLastError());
8464     return 0;
8465 }
8466
8467 static void wait_for_thread( HANDLE thread )
8468 {
8469     while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
8470     {
8471         MSG msg;
8472         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
8473     }
8474 }
8475
8476 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8477 {
8478     if (message == WM_USER) Sleep(200);
8479     return MsgCheckProcA( hwnd, message, wParam, lParam );
8480 }
8481
8482 static void test_SendMessageTimeout(void)
8483 {
8484     HANDLE thread;
8485     struct sendmsg_info info;
8486     DWORD tid;
8487     BOOL is_win9x;
8488
8489     info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8490                                100, 100, 200, 200, 0, 0, 0, NULL);
8491     flush_events();
8492     flush_sequence();
8493
8494     info.timeout = 1000;
8495     info.ret = 0xdeadbeef;
8496     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8497     wait_for_thread( thread );
8498     CloseHandle( thread );
8499     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8500     ok_sequence( WmUser, "WmUser", FALSE );
8501
8502     info.timeout = 1;
8503     info.ret = 0xdeadbeef;
8504     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8505     Sleep(100);  /* SendMessageTimeout should time out here */
8506     wait_for_thread( thread );
8507     CloseHandle( thread );
8508     ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8509     ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8510
8511     /* 0 means infinite timeout (but not on win9x) */
8512     info.timeout = 0;
8513     info.ret = 0xdeadbeef;
8514     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8515     Sleep(100);
8516     wait_for_thread( thread );
8517     CloseHandle( thread );
8518     is_win9x = !info.ret;
8519     if (is_win9x) ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8520     else ok_sequence( WmUser, "WmUser", FALSE );
8521
8522     /* timeout is treated as signed despite the prototype (but not on win9x) */
8523     info.timeout = 0x7fffffff;
8524     info.ret = 0xdeadbeef;
8525     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8526     Sleep(100);
8527     wait_for_thread( thread );
8528     CloseHandle( thread );
8529     ok( info.ret == 1, "SendMessageTimeout failed\n" );
8530     ok_sequence( WmUser, "WmUser", FALSE );
8531
8532     info.timeout = 0x80000000;
8533     info.ret = 0xdeadbeef;
8534     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8535     Sleep(100);
8536     wait_for_thread( thread );
8537     CloseHandle( thread );
8538     if (is_win9x)
8539     {
8540         ok( info.ret == 1, "SendMessageTimeout failed\n" );
8541         ok_sequence( WmUser, "WmUser", FALSE );
8542     }
8543     else
8544     {
8545         ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8546         ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8547     }
8548
8549     /* now check for timeout during message processing */
8550     SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
8551     info.timeout = 100;
8552     info.ret = 0xdeadbeef;
8553     thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8554     wait_for_thread( thread );
8555     CloseHandle( thread );
8556     /* we should time out but still get the message */
8557     ok( info.ret == 0, "SendMessageTimeout failed\n" );
8558     ok_sequence( WmUser, "WmUser", FALSE );
8559
8560     DestroyWindow( info.hwnd );
8561 }
8562
8563
8564 /****************** edit message test *************************/
8565 #define ID_EDIT 0x1234
8566 static const struct message sl_edit_setfocus[] =
8567 {
8568     { HCBT_SETFOCUS, hook },
8569     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8570     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8571     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8572     { WM_SETFOCUS, sent|wparam, 0 },
8573     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8574     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
8575     { WM_CTLCOLOREDIT, sent|parent },
8576     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8577     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8578     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8579     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8580     { 0 }
8581 };
8582 static const struct message ml_edit_setfocus[] =
8583 {
8584     { HCBT_SETFOCUS, hook },
8585     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8586     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8587     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8588     { WM_SETFOCUS, sent|wparam, 0 },
8589     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8590     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8591     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8592     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8593     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8594     { 0 }
8595 };
8596 static const struct message sl_edit_killfocus[] =
8597 {
8598     { HCBT_SETFOCUS, hook },
8599     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8600     { WM_KILLFOCUS, sent|wparam, 0 },
8601     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8602     { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8603     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
8604     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
8605     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
8606     { 0 }
8607 };
8608 static const struct message sl_edit_lbutton_dblclk[] =
8609 {
8610     { WM_LBUTTONDBLCLK, sent },
8611     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8612     { 0 }
8613 };
8614 static const struct message sl_edit_lbutton_down[] =
8615 {
8616     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8617     { HCBT_SETFOCUS, hook },
8618     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8619     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8620     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8621     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8622     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8623     { WM_CTLCOLOREDIT, sent|parent },
8624     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8625     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8626     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8627     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8628     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8629     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8630     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8631     { WM_CTLCOLOREDIT, sent|parent|optional },
8632     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8633     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8634     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8635     { 0 }
8636 };
8637 static const struct message ml_edit_lbutton_down[] =
8638 {
8639     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8640     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8641     { HCBT_SETFOCUS, hook },
8642     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8643     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8644     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8645     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8646     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8647     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8648     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8649     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8650     { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8651     { 0 }
8652 };
8653 static const struct message sl_edit_lbutton_up[] =
8654 {
8655     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8656     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8657     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8658     { WM_CAPTURECHANGED, sent|defwinproc },
8659     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8660     { 0 }
8661 };
8662 static const struct message ml_edit_lbutton_up[] =
8663 {
8664     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8665     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8666     { WM_CAPTURECHANGED, sent|defwinproc },
8667     { 0 }
8668 };
8669
8670 static WNDPROC old_edit_proc;
8671
8672 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8673 {
8674     static long defwndproc_counter = 0;
8675     LRESULT ret;
8676     struct message msg;
8677
8678     trace("edit: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
8679
8680     /* explicitly ignore WM_GETICON message */
8681     if (message == WM_GETICON) return 0;
8682
8683     /* ignore registered messages */
8684     if (message >= 0xc000) return 0;
8685
8686     msg.message = message;
8687     msg.flags = sent|wparam|lparam;
8688     if (defwndproc_counter) msg.flags |= defwinproc;
8689     msg.wParam = wParam;
8690     msg.lParam = lParam;
8691     add_message(&msg);
8692
8693     defwndproc_counter++;
8694     ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
8695     defwndproc_counter--;
8696
8697     return ret;
8698 }
8699
8700 static void subclass_edit(void)
8701 {
8702     WNDCLASSA cls;
8703
8704     if (!GetClassInfoA(0, "edit", &cls)) assert(0);
8705
8706     old_edit_proc = cls.lpfnWndProc;
8707
8708     cls.hInstance = GetModuleHandle(0);
8709     cls.lpfnWndProc = edit_hook_proc;
8710     cls.lpszClassName = "my_edit_class";
8711     UnregisterClass(cls.lpszClassName, cls.hInstance);
8712     if (!RegisterClassA(&cls)) assert(0);
8713 }
8714
8715 static void test_edit_messages(void)
8716 {
8717     HWND hwnd, parent;
8718     DWORD dlg_code;
8719
8720     subclass_edit();
8721     log_all_parent_messages++;
8722
8723     parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8724                              100, 100, 200, 200, 0, 0, 0, NULL);
8725     ok (parent != 0, "Failed to create parent window\n");
8726
8727     /* test single line edit */
8728     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
8729                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8730     ok(hwnd != 0, "Failed to create edit window\n");
8731
8732     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8733     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
8734
8735     ShowWindow(hwnd, SW_SHOW);
8736     UpdateWindow(hwnd);
8737     SetFocus(0);
8738     flush_sequence();
8739
8740     SetFocus(hwnd);
8741     ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
8742
8743     SetFocus(0);
8744     ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
8745
8746     SetFocus(0);
8747     ReleaseCapture();
8748     flush_sequence();
8749
8750     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8751     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
8752
8753     SetFocus(0);
8754     ReleaseCapture();
8755     flush_sequence();
8756
8757     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8758     ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
8759
8760     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8761     ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
8762
8763     DestroyWindow(hwnd);
8764
8765     /* test multiline edit */
8766     hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
8767                            0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8768     ok(hwnd != 0, "Failed to create edit window\n");
8769
8770     dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8771     ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
8772        "wrong dlg_code %08x\n", dlg_code);
8773
8774     ShowWindow(hwnd, SW_SHOW);
8775     UpdateWindow(hwnd);
8776     SetFocus(0);
8777     flush_sequence();
8778
8779     SetFocus(hwnd);
8780     ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
8781
8782     SetFocus(0);
8783     ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
8784
8785     SetFocus(0);
8786     ReleaseCapture();
8787     flush_sequence();
8788
8789     SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8790     ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
8791
8792     SetFocus(0);
8793     ReleaseCapture();
8794     flush_sequence();
8795
8796     SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8797     ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
8798
8799     SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8800     ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
8801
8802     DestroyWindow(hwnd);
8803     DestroyWindow(parent);
8804
8805     log_all_parent_messages--;
8806 }
8807
8808 /**************************** End of Edit test ******************************/
8809
8810 static const struct message WmKeyDownSkippedSeq[] =
8811 {
8812     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* 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
8821 #define EV_STOP 0
8822 #define EV_SENDMSG 1
8823 #define EV_ACK 2
8824
8825 struct peekmsg_info
8826 {
8827     HWND  hwnd;
8828     HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
8829 };
8830
8831 static DWORD CALLBACK send_msg_thread_2(void *param)
8832 {
8833     DWORD ret;
8834     struct peekmsg_info *info = param;
8835
8836     trace("thread: looping\n");
8837     SetEvent(info->hevent[EV_ACK]);
8838
8839     while (1)
8840     {
8841         ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
8842
8843         switch (ret)
8844         {
8845         case WAIT_OBJECT_0 + EV_STOP:
8846             trace("thread: exiting\n");
8847             return 0;
8848
8849         case WAIT_OBJECT_0 + EV_SENDMSG:
8850             trace("thread: sending message\n");
8851             ok( SendNotifyMessageA(info->hwnd, WM_USER, 0, 0),
8852                 "SendNotifyMessageA failed error %u\n", GetLastError());
8853             SetEvent(info->hevent[EV_ACK]);
8854             break;
8855
8856         default:
8857             trace("unexpected return: %04x\n", ret);
8858             assert(0);
8859             break;
8860         }
8861     }
8862     return 0;
8863 }
8864
8865 static void test_PeekMessage(void)
8866 {
8867     MSG msg;
8868     HANDLE hthread;
8869     DWORD tid, qstatus;
8870     UINT qs_all_input = QS_ALLINPUT;
8871     UINT qs_input = QS_INPUT;
8872     UINT qs_sendmessage = 0;
8873     BOOL ret;
8874     struct peekmsg_info info;
8875
8876     info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8877                               100, 100, 200, 200, 0, 0, 0, NULL);
8878     assert(info.hwnd);
8879     ShowWindow(info.hwnd, SW_SHOW);
8880     UpdateWindow(info.hwnd);
8881     SetFocus(info.hwnd);
8882
8883     info.hevent[EV_STOP] = CreateEventA(NULL, 0, 0, NULL);
8884     info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
8885     info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
8886
8887     hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
8888     WaitForSingleObject(info.hevent[EV_ACK], 10000);
8889
8890     flush_events();
8891     flush_sequence();
8892
8893     SetLastError(0xdeadbeef);
8894     qstatus = GetQueueStatus(qs_all_input);
8895     if (GetLastError() == ERROR_INVALID_FLAGS)
8896     {
8897         trace("QS_RAWINPUT not supported on this platform\n");
8898         qs_all_input &= ~QS_RAWINPUT;
8899         qs_input &= ~QS_RAWINPUT;
8900     }
8901     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8902
8903     trace("signalling to send message\n");
8904     SetEvent(info.hevent[EV_SENDMSG]);
8905     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8906
8907     /* pass invalid QS_xxxx flags */
8908     SetLastError(0xdeadbeef);
8909     qstatus = GetQueueStatus(0xffffffff);
8910     ok(qstatus == 0, "GetQueueStatus should fail: %08x\n", qstatus);
8911     ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
8912
8913     qstatus = GetQueueStatus(qs_all_input);
8914     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
8915        "wrong qstatus %08x\n", qstatus);
8916
8917     msg.message = 0;
8918     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8919     ok(!ret,
8920        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8921         msg.message);
8922     ok_sequence(WmUser, "WmUser", FALSE);
8923
8924     qstatus = GetQueueStatus(qs_all_input);
8925     ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8926
8927     keybd_event('N', 0, 0, 0);
8928     keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
8929     qstatus = GetQueueStatus(qs_all_input);
8930     ok(qstatus == MAKELONG(QS_KEY, QS_KEY),
8931        "wrong qstatus %08x\n", qstatus);
8932
8933     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8934     qstatus = GetQueueStatus(qs_all_input);
8935     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8936        "wrong qstatus %08x\n", qstatus);
8937
8938     InvalidateRect(info.hwnd, NULL, FALSE);
8939     qstatus = GetQueueStatus(qs_all_input);
8940     ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8941        "wrong qstatus %08x\n", qstatus);
8942
8943     trace("signalling to send message\n");
8944     SetEvent(info.hevent[EV_SENDMSG]);
8945     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8946
8947     qstatus = GetQueueStatus(qs_all_input);
8948     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8949        "wrong qstatus %08x\n", qstatus);
8950
8951     msg.message = 0;
8952     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
8953     ok(!ret,
8954        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8955         msg.message);
8956     if (!sequence_cnt)  /* nt4 needs explicit PM_QS_SENDMESSAGE to process sent messages */
8957     {
8958         qs_sendmessage = QS_SENDMESSAGE;
8959         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | ((qs_input|qs_sendmessage) << 16));
8960         ok(!ret, "PeekMessageA should have returned FALSE instead of msg %04x\n", msg.message);
8961     }
8962     ok_sequence(WmUser, "WmUser", FALSE);
8963
8964     qstatus = GetQueueStatus(qs_all_input);
8965     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8966        "wrong qstatus %08x\n", qstatus);
8967
8968     trace("signalling to send message\n");
8969     SetEvent(info.hevent[EV_SENDMSG]);
8970     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8971
8972     qstatus = GetQueueStatus(qs_all_input);
8973     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8974        "wrong qstatus %08x\n", qstatus);
8975
8976     msg.message = 0;
8977     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE | (qs_sendmessage << 16) );
8978     ok(!ret,
8979        "PeekMessageA should have returned FALSE instead of msg %04x\n",
8980         msg.message);
8981     ok_sequence(WmUser, "WmUser", FALSE);
8982
8983     qstatus = GetQueueStatus(qs_all_input);
8984     ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8985        "wrong qstatus %08x\n", qstatus);
8986
8987     msg.message = 0;
8988     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8989     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8990        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8991        ret, msg.message, msg.wParam);
8992     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8993
8994     qstatus = GetQueueStatus(qs_all_input);
8995     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
8996        "wrong qstatus %08x\n", qstatus);
8997
8998     msg.message = 0;
8999     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9000     ok(!ret,
9001        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9002         msg.message);
9003     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9004
9005     qstatus = GetQueueStatus(qs_all_input);
9006     ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9007        "wrong qstatus %08x\n", qstatus);
9008
9009     msg.message = 0;
9010     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9011     ok(ret && msg.message == WM_PAINT,
9012        "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
9013     DispatchMessageA(&msg);
9014     ok_sequence(WmPaint, "WmPaint", FALSE);
9015
9016     qstatus = GetQueueStatus(qs_all_input);
9017     ok(qstatus == MAKELONG(0, QS_KEY),
9018        "wrong qstatus %08x\n", qstatus);
9019
9020     msg.message = 0;
9021     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9022     ok(!ret,
9023        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9024         msg.message);
9025     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9026
9027     qstatus = GetQueueStatus(qs_all_input);
9028     ok(qstatus == MAKELONG(0, QS_KEY),
9029        "wrong qstatus %08x\n", qstatus);
9030
9031     trace("signalling to send message\n");
9032     SetEvent(info.hevent[EV_SENDMSG]);
9033     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9034
9035     qstatus = GetQueueStatus(qs_all_input);
9036     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
9037        "wrong qstatus %08x\n", qstatus);
9038
9039     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9040
9041     qstatus = GetQueueStatus(qs_all_input);
9042     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9043        "wrong qstatus %08x\n", qstatus);
9044
9045     msg.message = 0;
9046     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9047     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9048        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9049        ret, msg.message, msg.wParam);
9050     ok_sequence(WmUser, "WmUser", FALSE);
9051
9052     qstatus = GetQueueStatus(qs_all_input);
9053     ok(qstatus == MAKELONG(0, QS_KEY),
9054        "wrong qstatus %08x\n", qstatus);
9055
9056     msg.message = 0;
9057     ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9058     ok(!ret,
9059        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9060         msg.message);
9061     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9062
9063     qstatus = GetQueueStatus(qs_all_input);
9064     ok(qstatus == MAKELONG(0, QS_KEY),
9065        "wrong qstatus %08x\n", qstatus);
9066
9067     PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9068
9069     qstatus = GetQueueStatus(qs_all_input);
9070     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9071        "wrong qstatus %08x\n", qstatus);
9072
9073     trace("signalling to send message\n");
9074     SetEvent(info.hevent[EV_SENDMSG]);
9075     WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9076
9077     qstatus = GetQueueStatus(qs_all_input);
9078     ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9079        "wrong qstatus %08x\n", qstatus);
9080
9081     msg.message = 0;
9082     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
9083     ok(!ret,
9084        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9085         msg.message);
9086     ok_sequence(WmUser, "WmUser", FALSE);
9087
9088     qstatus = GetQueueStatus(qs_all_input);
9089     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9090        "wrong qstatus %08x\n", qstatus);
9091
9092     msg.message = 0;
9093     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9094         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9095     else /* workaround for a missing QS_RAWINPUT support */
9096         ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
9097     ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9098        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9099        ret, msg.message, msg.wParam);
9100     ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9101
9102     qstatus = GetQueueStatus(qs_all_input);
9103     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9104        "wrong qstatus %08x\n", qstatus);
9105
9106     msg.message = 0;
9107     if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9108         ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9109     else /* workaround for a missing QS_RAWINPUT support */
9110         ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
9111     ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9112        "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
9113        ret, msg.message, msg.wParam);
9114     ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
9115
9116     qstatus = GetQueueStatus(qs_all_input);
9117     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9118        "wrong qstatus %08x\n", qstatus);
9119
9120     msg.message = 0;
9121     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
9122     ok(!ret,
9123        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9124         msg.message);
9125     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9126
9127     qstatus = GetQueueStatus(qs_all_input);
9128     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9129        "wrong qstatus %08x\n", qstatus);
9130
9131     msg.message = 0;
9132     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9133     ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9134        "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9135        ret, msg.message, msg.wParam);
9136     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9137
9138     qstatus = GetQueueStatus(qs_all_input);
9139     ok(qstatus == 0,
9140        "wrong qstatus %08x\n", qstatus);
9141
9142     msg.message = 0;
9143     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9144     ok(!ret,
9145        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9146         msg.message);
9147     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9148
9149     qstatus = GetQueueStatus(qs_all_input);
9150     ok(qstatus == 0,
9151        "wrong qstatus %08x\n", qstatus);
9152
9153     /* test whether presence of the quit flag in the queue affects
9154      * the queue state
9155      */
9156     PostQuitMessage(0x1234abcd);
9157
9158     qstatus = GetQueueStatus(qs_all_input);
9159     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9160        "wrong qstatus %08x\n", qstatus);
9161
9162     PostMessageA(info.hwnd, WM_USER, 0, 0);
9163
9164     qstatus = GetQueueStatus(qs_all_input);
9165     ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9166        "wrong qstatus %08x\n", qstatus);
9167
9168     msg.message = 0;
9169     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9170     ok(ret && msg.message == WM_USER,
9171        "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
9172     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9173
9174     qstatus = GetQueueStatus(qs_all_input);
9175     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9176        "wrong qstatus %08x\n", qstatus);
9177
9178     msg.message = 0;
9179     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9180     ok(ret && msg.message == WM_QUIT,
9181        "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
9182     ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
9183     ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
9184     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9185
9186     qstatus = GetQueueStatus(qs_all_input);
9187 todo_wine {
9188     ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9189        "wrong qstatus %08x\n", qstatus);
9190 }
9191
9192     msg.message = 0;
9193     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9194     ok(!ret,
9195        "PeekMessageA should have returned FALSE instead of msg %04x\n",
9196         msg.message);
9197     ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9198
9199     qstatus = GetQueueStatus(qs_all_input);
9200     ok(qstatus == 0,
9201        "wrong qstatus %08x\n", qstatus);
9202
9203     trace("signalling to exit\n");
9204     SetEvent(info.hevent[EV_STOP]);
9205
9206     WaitForSingleObject(hthread, INFINITE);
9207
9208     CloseHandle(hthread);
9209     CloseHandle(info.hevent[0]);
9210     CloseHandle(info.hevent[1]);
9211     CloseHandle(info.hevent[2]);
9212
9213     DestroyWindow(info.hwnd);
9214 }
9215
9216 static void wait_move_event(HWND hwnd, int x, int y)
9217 {
9218     MSG msg;
9219     DWORD time;
9220     BOOL  ret;
9221     int go = 0;
9222
9223     time = GetTickCount();
9224     while (GetTickCount() - time < 200 && !go) {
9225         ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9226         go  = ret && msg.pt.x > x && msg.pt.y > y;
9227     }
9228 }
9229
9230 #define STEP 20
9231 static void test_PeekMessage2(void)
9232 {
9233     HWND hwnd;
9234     BOOL ret;
9235     MSG msg;
9236     UINT message;
9237     DWORD time1, time2, time3;
9238     int x1, y1, x2, y2, x3, y3;
9239     POINT pos;
9240
9241     time1 = time2 = time3 = 0;
9242     x1 = y1 = x2 = y2 = x3 = y3 = 0;
9243
9244     /* Initialise window and make sure it is ready for events */
9245     hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
9246                         10, 10, 800, 800, NULL, NULL, NULL, NULL);
9247     assert(hwnd);
9248     trace("Window for test_PeekMessage2 %p\n", hwnd);
9249     ShowWindow(hwnd, SW_SHOW);
9250     UpdateWindow(hwnd);
9251     SetFocus(hwnd);
9252     GetCursorPos(&pos);
9253     SetCursorPos(100, 100);
9254     mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
9255     flush_events();
9256
9257     /* Do initial mousemove, wait until we can see it
9258        and then do our test peek with PM_NOREMOVE. */
9259     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9260     wait_move_event(hwnd, 80, 80);
9261
9262     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9263     ok(ret, "no message available\n");
9264     if (ret) {
9265         trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9266         message = msg.message;
9267         time1 = msg.time;
9268         x1 = msg.pt.x;
9269         y1 = msg.pt.y;
9270         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9271     }
9272
9273     /* Allow time to advance a bit, and then simulate the user moving their
9274      * mouse around. After that we peek again with PM_NOREMOVE.
9275      * Although the previous mousemove message was never removed, the
9276      * mousemove we now peek should reflect the recent mouse movements
9277      * because the input queue will merge the move events. */
9278     Sleep(2);
9279     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9280     wait_move_event(hwnd, x1, y1);
9281
9282     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9283     ok(ret, "no message available\n");
9284     if (ret) {
9285         trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9286         message = msg.message;
9287         time2 = msg.time;
9288         x2 = msg.pt.x;
9289         y2 = msg.pt.y;
9290         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9291         ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
9292         ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
9293     }
9294
9295     /* Have another go, to drive the point home */
9296     Sleep(2);
9297     mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9298     wait_move_event(hwnd, x2, y2);
9299
9300     ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9301     ok(ret, "no message available\n");
9302     if (ret) {
9303         trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9304         message = msg.message;
9305         time3 = msg.time;
9306         x3 = msg.pt.x;
9307         y3 = msg.pt.y;
9308         ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9309         ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
9310         ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
9311     }
9312
9313     DestroyWindow(hwnd);
9314     SetCursorPos(pos.x, pos.y);
9315     flush_events();
9316 }
9317
9318 static void test_quit_message(void)
9319 {
9320     MSG msg;
9321     BOOL ret;
9322
9323     /* test using PostQuitMessage */
9324     flush_events();
9325     PostQuitMessage(0xbeef);
9326
9327     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9328     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9329     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9330     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9331
9332     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9333     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9334
9335     ret = GetMessage(&msg, NULL, 0, 0);
9336     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9337     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9338
9339     /* note: WM_QUIT message received after WM_USER message */
9340     ret = GetMessage(&msg, NULL, 0, 0);
9341     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9342     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9343     ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9344
9345     ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
9346     ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
9347
9348     /* now test with PostThreadMessage - different behaviour! */
9349     PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
9350
9351     ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9352     ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9353     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9354     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9355
9356     ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9357     ok(ret, "PostMessage failed with error %d\n", GetLastError());
9358
9359     /* note: we receive the WM_QUIT message first this time */
9360     ret = GetMessage(&msg, NULL, 0, 0);
9361     ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9362     ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9363     ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9364
9365     ret = GetMessage(&msg, NULL, 0, 0);
9366     ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9367     ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9368 }
9369
9370 static const struct message WmMouseHoverSeq[] = {
9371     { WM_MOUSEACTIVATE, sent|optional },  /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
9372     { WM_MOUSEACTIVATE, sent|optional },
9373     { WM_TIMER, sent|optional }, /* XP sends it */
9374     { WM_SYSTIMER, sent },
9375     { WM_MOUSEHOVER, sent|wparam, 0 },
9376     { 0 }
9377 };
9378
9379 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
9380 {
9381     MSG msg;
9382     DWORD start_ticks, end_ticks;
9383
9384     start_ticks = GetTickCount();
9385     /* add some deviation (50%) to cover not expected delays */
9386     start_ticks += timeout / 2;
9387
9388     do
9389     {
9390         while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
9391         {
9392             /* Timer proc messages are not dispatched to the window proc,
9393              * and therefore not logged.
9394              */
9395             if (msg.message == WM_TIMER || msg.message == WM_SYSTIMER)
9396             {
9397                 struct message s_msg;
9398
9399                 s_msg.message = msg.message;
9400                 s_msg.flags = sent|wparam|lparam;
9401                 s_msg.wParam = msg.wParam;
9402                 s_msg.lParam = msg.lParam;
9403                 add_message(&s_msg);
9404             }
9405             DispatchMessage(&msg);
9406         }
9407
9408         end_ticks = GetTickCount();
9409
9410         /* inject WM_MOUSEMOVE to see how it changes tracking */
9411         if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
9412         {
9413             mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9414             mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9415
9416             inject_mouse_move = FALSE;
9417         }
9418     } while (start_ticks + timeout >= end_ticks);
9419 }
9420
9421 static void test_TrackMouseEvent(void)
9422 {
9423     TRACKMOUSEEVENT tme;
9424     BOOL ret;
9425     HWND hwnd, hchild;
9426     RECT rc_parent, rc_child;
9427     UINT default_hover_time, hover_width = 0, hover_height = 0;
9428
9429 #define track_hover(track_hwnd, track_hover_time) \
9430     tme.cbSize = sizeof(tme); \
9431     tme.dwFlags = TME_HOVER; \
9432     tme.hwndTrack = track_hwnd; \
9433     tme.dwHoverTime = track_hover_time; \
9434     SetLastError(0xdeadbeef); \
9435     ret = pTrackMouseEvent(&tme); \
9436     ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
9437
9438 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
9439     tme.cbSize = sizeof(tme); \
9440     tme.dwFlags = TME_QUERY; \
9441     tme.hwndTrack = (HWND)0xdeadbeef; \
9442     tme.dwHoverTime = 0xdeadbeef; \
9443     SetLastError(0xdeadbeef); \
9444     ret = pTrackMouseEvent(&tme); \
9445     ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
9446     ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
9447     ok(tme.dwFlags == (expected_track_flags), \
9448        "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
9449     ok(tme.hwndTrack == (expected_track_hwnd), \
9450        "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
9451     ok(tme.dwHoverTime == (expected_hover_time), \
9452        "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
9453
9454 #define track_hover_cancel(track_hwnd) \
9455     tme.cbSize = sizeof(tme); \
9456     tme.dwFlags = TME_HOVER | TME_CANCEL; \
9457     tme.hwndTrack = track_hwnd; \
9458     tme.dwHoverTime = 0xdeadbeef; \
9459     SetLastError(0xdeadbeef); \
9460     ret = pTrackMouseEvent(&tme); \
9461     ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
9462
9463     default_hover_time = 0xdeadbeef;
9464     SetLastError(0xdeadbeef);
9465     ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
9466     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9467        "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
9468     if (!ret) default_hover_time = 400;
9469     trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
9470
9471     SetLastError(0xdeadbeef);
9472     ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
9473     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9474        "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
9475     if (!ret) hover_width = 4;
9476     SetLastError(0xdeadbeef);
9477     ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
9478     ok(ret || broken(GetLastError() == 0xdeadbeef),  /* win9x */
9479        "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
9480     if (!ret) hover_height = 4;
9481     trace("hover rect is %u x %d\n", hover_width, hover_height);
9482
9483     hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
9484                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9485                           CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
9486                           NULL, NULL, 0);
9487     assert(hwnd);
9488
9489     hchild = CreateWindowEx(0, "TestWindowClass", NULL,
9490                           WS_CHILD | WS_BORDER | WS_VISIBLE,
9491                           50, 50, 200, 200, hwnd,
9492                           NULL, NULL, 0);
9493     assert(hchild);
9494
9495     SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
9496     flush_events();
9497     flush_sequence();
9498
9499     tme.cbSize = 0;
9500     tme.dwFlags = TME_QUERY;
9501     tme.hwndTrack = (HWND)0xdeadbeef;
9502     tme.dwHoverTime = 0xdeadbeef;
9503     SetLastError(0xdeadbeef);
9504     ret = pTrackMouseEvent(&tme);
9505     ok(!ret, "TrackMouseEvent should fail\n");
9506     ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef),
9507        "not expected error %u\n", GetLastError());
9508
9509     tme.cbSize = sizeof(tme);
9510     tme.dwFlags = TME_HOVER;
9511     tme.hwndTrack = (HWND)0xdeadbeef;
9512     tme.dwHoverTime = 0xdeadbeef;
9513     SetLastError(0xdeadbeef);
9514     ret = pTrackMouseEvent(&tme);
9515     ok(!ret, "TrackMouseEvent should fail\n");
9516     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
9517        "not expected error %u\n", GetLastError());
9518
9519     tme.cbSize = sizeof(tme);
9520     tme.dwFlags = TME_HOVER | TME_CANCEL;
9521     tme.hwndTrack = (HWND)0xdeadbeef;
9522     tme.dwHoverTime = 0xdeadbeef;
9523     SetLastError(0xdeadbeef);
9524     ret = pTrackMouseEvent(&tme);
9525     ok(!ret, "TrackMouseEvent should fail\n");
9526     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
9527        "not expected error %u\n", GetLastError());
9528
9529     GetWindowRect(hwnd, &rc_parent);
9530     GetWindowRect(hchild, &rc_child);
9531     SetCursorPos(rc_child.left - 10, rc_child.top - 10);
9532
9533     /* Process messages so that the system updates its internal current
9534      * window and hittest, otherwise TrackMouseEvent calls don't have any
9535      * effect.
9536      */
9537     flush_events();
9538     flush_sequence();
9539
9540     track_query(0, NULL, 0);
9541     track_hover(hchild, 0);
9542     track_query(0, NULL, 0);
9543
9544     flush_events();
9545     flush_sequence();
9546
9547     track_hover(hwnd, 0);
9548     track_query(TME_HOVER, hwnd, default_hover_time);
9549
9550     pump_msg_loop_timeout(default_hover_time, FALSE);
9551     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9552
9553     track_query(0, NULL, 0);
9554
9555     track_hover(hwnd, HOVER_DEFAULT);
9556     track_query(TME_HOVER, hwnd, default_hover_time);
9557
9558     Sleep(default_hover_time / 2);
9559     mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9560     mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9561
9562     track_query(TME_HOVER, hwnd, default_hover_time);
9563
9564     pump_msg_loop_timeout(default_hover_time / 2, FALSE);
9565     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9566
9567     track_query(0, NULL, 0);
9568
9569     track_hover(hwnd, HOVER_DEFAULT);
9570     track_query(TME_HOVER, hwnd, default_hover_time);
9571
9572     pump_msg_loop_timeout(default_hover_time, TRUE);
9573     ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9574
9575     track_query(0, NULL, 0);
9576
9577     track_hover(hwnd, HOVER_DEFAULT);
9578     track_query(TME_HOVER, hwnd, default_hover_time);
9579     track_hover_cancel(hwnd);
9580
9581     DestroyWindow(hwnd);
9582
9583 #undef track_hover
9584 #undef track_query
9585 #undef track_hover_cancel
9586 }
9587
9588
9589 static const struct message WmSetWindowRgn[] = {
9590     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9591     { WM_NCCALCSIZE, sent|wparam, 1 },
9592     { WM_NCPAINT, sent|optional }, /* wparam != 1 */
9593     { WM_GETTEXT, sent|defwinproc|optional },
9594     { WM_ERASEBKGND, sent|optional },
9595     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9596     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9597     { 0 }
9598 };
9599
9600 static const struct message WmSetWindowRgn_no_redraw[] = {
9601     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9602     { WM_NCCALCSIZE, sent|wparam, 1 },
9603     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9604     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9605     { 0 }
9606 };
9607
9608 static const struct message WmSetWindowRgn_clear[] = {
9609     { WM_WINDOWPOSCHANGING, sent/*|wparam*/, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE/*|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE only on some Windows versions */ },
9610     { WM_NCCALCSIZE, sent|wparam, 1 },
9611     { WM_NCPAINT, sent|optional },
9612     { WM_GETTEXT, sent|defwinproc|optional },
9613     { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
9614     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9615     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
9616     { WM_NCPAINT, sent|optional },
9617     { WM_GETTEXT, sent|defwinproc|optional },
9618     { WM_ERASEBKGND, sent|optional },
9619     { WM_WINDOWPOSCHANGING, sent|optional },
9620     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
9621     { WM_NCPAINT, sent|optional },
9622     { WM_GETTEXT, sent|defwinproc|optional },
9623     { WM_ERASEBKGND, sent|optional },
9624     { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9625     { WM_NCCALCSIZE, sent|optional|wparam, 1 },
9626     { WM_NCPAINT, sent|optional },
9627     { WM_GETTEXT, sent|defwinproc|optional },
9628     { WM_ERASEBKGND, sent|optional },
9629     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9630     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9631     { 0 }
9632 };
9633
9634 static void test_SetWindowRgn(void)
9635 {
9636     HRGN hrgn;
9637     HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
9638                                 100, 100, 200, 200, 0, 0, 0, NULL);
9639     ok( hwnd != 0, "Failed to create overlapped window\n" );
9640
9641     ShowWindow( hwnd, SW_SHOW );
9642     UpdateWindow( hwnd );
9643     flush_events();
9644     flush_sequence();
9645
9646     trace("testing SetWindowRgn\n");
9647     hrgn = CreateRectRgn( 0, 0, 150, 150 );
9648     SetWindowRgn( hwnd, hrgn, TRUE );
9649     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
9650
9651     hrgn = CreateRectRgn( 30, 30, 160, 160 );
9652     SetWindowRgn( hwnd, hrgn, FALSE );
9653     ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
9654
9655     hrgn = CreateRectRgn( 0, 0, 180, 180 );
9656     SetWindowRgn( hwnd, hrgn, TRUE );
9657     ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
9658
9659     SetWindowRgn( hwnd, 0, TRUE );
9660     ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
9661
9662     DestroyWindow( hwnd );
9663 }
9664
9665 /*************************** ShowWindow() test ******************************/
9666 static const struct message WmShowNormal[] = {
9667     { WM_SHOWWINDOW, sent|wparam, 1 },
9668     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9669     { HCBT_ACTIVATE, hook },
9670     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9671     { HCBT_SETFOCUS, hook },
9672     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9673     { 0 }
9674 };
9675 static const struct message WmShow[] = {
9676     { WM_SHOWWINDOW, sent|wparam, 1 },
9677     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9678     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9679     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9680     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9681     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9682     { 0 }
9683 };
9684 static const struct message WmShowNoActivate_1[] = {
9685     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9686     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
9687     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
9688     { WM_MOVE, sent|defwinproc },
9689     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9690     { 0 }
9691 };
9692 static const struct message WmShowNoActivate_2[] = {
9693     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9694     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9695     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9696     { WM_MOVE, sent|defwinproc },
9697     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9698     { HCBT_SETFOCUS, hook|optional },
9699     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9700     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9701     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9702     { 0 }
9703 };
9704 static const struct message WmShowNA_1[] = {
9705     { WM_SHOWWINDOW, sent|wparam, 1 },
9706     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9707     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9708     { 0 }
9709 };
9710 static const struct message WmShowNA_2[] = {
9711     { WM_SHOWWINDOW, sent|wparam, 1 },
9712     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9713     { 0 }
9714 };
9715 static const struct message WmRestore_1[] = {
9716     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9717     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9718     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9719     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9720     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9721     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9722     { WM_MOVE, sent|defwinproc },
9723     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9724     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9725     { 0 }
9726 };
9727 static const struct message WmRestore_2[] = {
9728     { WM_SHOWWINDOW, sent|wparam, 1 },
9729     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9730     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9731     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9732     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9733     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9734     { 0 }
9735 };
9736 static const struct message WmRestore_3[] = {
9737     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9738     { WM_GETMINMAXINFO, sent },
9739     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9740     { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9741     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9742     { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9743     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9744     { WM_MOVE, sent|defwinproc },
9745     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9746     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9747     { 0 }
9748 };
9749 static const struct message WmRestore_4[] = {
9750     { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9751     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9752     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9753     { WM_MOVE, sent|defwinproc },
9754     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9755     { 0 }
9756 };
9757 static const struct message WmRestore_5[] = {
9758     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
9759     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9760     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9761     { WM_MOVE, sent|defwinproc },
9762     { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9763     { 0 }
9764 };
9765 static const struct message WmHide_1[] = {
9766     { WM_SHOWWINDOW, sent|wparam, 0 },
9767     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9768     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9769     { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9770     { 0 }
9771 };
9772 static const struct message WmHide_2[] = {
9773     { WM_SHOWWINDOW, sent|wparam, 0 },
9774     { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9775     { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9776     { 0 }
9777 };
9778 static const struct message WmHide_3[] = {
9779     { WM_SHOWWINDOW, sent|wparam, 0 },
9780     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9781     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9782     { HCBT_SETFOCUS, hook|optional },
9783     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9784     { 0 }
9785 };
9786 static const struct message WmShowMinimized_1[] = {
9787     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9788     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9789     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9790     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9791     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9792     { WM_MOVE, sent|defwinproc },
9793     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9794     { 0 }
9795 };
9796 static const struct message WmMinimize_1[] = {
9797     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9798     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9799     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9800     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9801     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9802     { WM_MOVE, sent|defwinproc },
9803     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9804     { 0 }
9805 };
9806 static const struct message WmMinimize_2[] = {
9807     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9808     { HCBT_SETFOCUS, hook|optional },
9809     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9810     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9811     { WM_MOVE, sent|defwinproc },
9812     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9813     { 0 }
9814 };
9815 static const struct message WmMinimize_3[] = {
9816     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9817     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9818     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9819     { WM_MOVE, sent|defwinproc },
9820     { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9821     { 0 }
9822 };
9823 static const struct message WmShowMinNoActivate[] = {
9824     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9825     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9826     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9827     { 0 }
9828 };
9829 static const struct message WmMinMax_1[] = {
9830     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9831     { 0 }
9832 };
9833 static const struct message WmMinMax_2[] = {
9834     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9835     { 0 }
9836 };
9837 static const struct message WmMinMax_3[] = {
9838     { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9839     { 0 }
9840 };
9841 static const struct message WmMinMax_4[] = {
9842     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9843     { 0 }
9844 };
9845 static const struct message WmShowMaximized_1[] = {
9846     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9847     { WM_GETMINMAXINFO, sent },
9848     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9849     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9850     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9851     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9852     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9853     { WM_MOVE, sent|defwinproc },
9854     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9855     { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9856     { 0 }
9857 };
9858 static const struct message WmShowMaximized_2[] = {
9859     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9860     { WM_GETMINMAXINFO, sent },
9861     { WM_WINDOWPOSCHANGING, sent|optional },
9862     { HCBT_ACTIVATE, hook|optional },
9863     { WM_WINDOWPOSCHANGED, sent|optional },
9864     { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
9865     { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
9866     { WM_WINDOWPOSCHANGING, sent },
9867     { HCBT_SETFOCUS, hook|optional },
9868     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9869     { WM_MOVE, sent|defwinproc },
9870     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9871     { HCBT_SETFOCUS, hook|optional },
9872     { 0 }
9873 };
9874 static const struct message WmShowMaximized_3[] = {
9875     { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9876     { WM_GETMINMAXINFO, sent },
9877     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9878     { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9879     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9880     { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9881     { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9882     { WM_MOVE, sent|defwinproc },
9883     { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9884     { 0 }
9885 };
9886
9887 static void test_ShowWindow(void)
9888 {
9889     /* ShowWindow commands in random order */
9890     static const struct
9891     {
9892         INT cmd; /* ShowWindow command */
9893         LPARAM ret; /* ShowWindow return value */
9894         DWORD style; /* window style after the command */
9895         const struct message *msg; /* message sequence the command produces */
9896         BOOL todo_msg; /* message sequence doesn't match what Wine does */
9897     } sw[] =
9898     {
9899 /*  1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
9900 /*  2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9901 /*  3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
9902 /*  4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9903 /*  5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
9904 /*  6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
9905 /*  7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
9906 /*  8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
9907 /*  9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
9908 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
9909 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
9910 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
9911 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
9912 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9913 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
9914 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9915 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
9916 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9917 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
9918 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
9919 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9920 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
9921 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
9922 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9923 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
9924 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
9925 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
9926 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9927 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
9928 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
9929 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9930 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, FALSE },
9931 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9932 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE }, /* what does this mean?! */
9933 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE },
9934 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9935 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
9936 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9937 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9938 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, FALSE },
9939 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
9940 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, TRUE },
9941 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
9942 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
9943 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
9944 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
9945 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
9946 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
9947 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
9948 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
9949 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9950 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
9951 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9952 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, FALSE },
9953 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9954 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
9955 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
9956     };
9957     HWND hwnd;
9958     DWORD style;
9959     LPARAM ret;
9960     INT i;
9961
9962 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
9963     hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
9964                           120, 120, 90, 90,
9965                           0, 0, 0, NULL);
9966     assert(hwnd);
9967
9968     style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
9969     ok(style == 0, "expected style 0, got %08x\n", style);
9970
9971     flush_events();
9972     flush_sequence();
9973
9974     for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
9975     {
9976         static const char * const sw_cmd_name[13] =
9977         {
9978             "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
9979             "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
9980             "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
9981             "SW_NORMALNA" /* 0xCC */
9982         };
9983         char comment[64];
9984         INT idx; /* index into the above array of names */
9985
9986         idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
9987
9988         style = GetWindowLong(hwnd, GWL_STYLE);
9989         trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
9990         ret = ShowWindow(hwnd, sw[i].cmd);
9991         ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
9992         style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
9993         ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
9994
9995         sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
9996         ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
9997
9998         flush_events();
9999         flush_sequence();
10000     }
10001
10002     DestroyWindow(hwnd);
10003 }
10004
10005 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
10006 {
10007     struct message msg;
10008
10009     trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
10010
10011     switch (message)
10012     {
10013     case WM_WINDOWPOSCHANGING:
10014     case WM_WINDOWPOSCHANGED:
10015     {
10016         WINDOWPOS *winpos = (WINDOWPOS *)lParam;
10017
10018         trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
10019         trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x ",
10020               winpos->hwnd, winpos->hwndInsertAfter,
10021               winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
10022         dump_winpos_flags(winpos->flags);
10023
10024         /* Log only documented flags, win2k uses 0x1000 and 0x2000
10025          * in the high word for internal purposes
10026          */
10027         wParam = winpos->flags & 0xffff;
10028         /* We are not interested in the flags that don't match under XP and Win9x */
10029         wParam &= ~(SWP_NOZORDER);
10030         break;
10031     }
10032
10033     /* explicitly ignore WM_GETICON message */
10034     case WM_GETICON:
10035         return 0;
10036     }
10037
10038     msg.message = message;
10039     msg.flags = sent|wparam|lparam;
10040     msg.wParam = wParam;
10041     msg.lParam = lParam;
10042     add_message(&msg);
10043
10044     /* calling DefDlgProc leads to a recursion under XP */
10045
10046     switch (message)
10047     {
10048     case WM_INITDIALOG:
10049     case WM_GETDLGCODE:
10050         return 0;
10051     }
10052     return 1;
10053 }
10054
10055 static const struct message WmDefDlgSetFocus_1[] = {
10056     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10057     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10058     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10059     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10060     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10061     { HCBT_SETFOCUS, hook },
10062     { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
10063     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10064     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10065     { WM_SETFOCUS, sent|wparam, 0 },
10066     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
10067     { WM_CTLCOLOREDIT, sent },
10068     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
10069     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10070     { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10071     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10072     { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
10073     { 0 }
10074 };
10075 static const struct message WmDefDlgSetFocus_2[] = {
10076     { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10077     { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10078     { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10079     { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10080     { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10081     { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10082     { WM_CTLCOLOREDIT, sent|optional }, /* XP */
10083     { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10084     { 0 }
10085 };
10086 /* Creation of a dialog */
10087 static const struct message WmCreateDialogParamSeq_1[] = {
10088     { HCBT_CREATEWND, hook },
10089     { WM_NCCREATE, sent },
10090     { WM_NCCALCSIZE, sent|wparam, 0 },
10091     { WM_CREATE, sent },
10092     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10093     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10094     { WM_MOVE, sent },
10095     { WM_SETFONT, sent },
10096     { WM_INITDIALOG, sent },
10097     { WM_CHANGEUISTATE, sent|optional },
10098     { 0 }
10099 };
10100 /* Creation of a dialog */
10101 static const struct message WmCreateDialogParamSeq_2[] = {
10102     { HCBT_CREATEWND, hook },
10103     { WM_NCCREATE, sent },
10104     { WM_NCCALCSIZE, sent|wparam, 0 },
10105     { WM_CREATE, sent },
10106     { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10107     { WM_SIZE, sent|wparam, SIZE_RESTORED },
10108     { WM_MOVE, sent },
10109     { WM_CHANGEUISTATE, sent|optional },
10110     { 0 }
10111 };
10112
10113 static void test_dialog_messages(void)
10114 {
10115     WNDCLASS cls;
10116     HWND hdlg, hedit1, hedit2, hfocus;
10117     LRESULT ret;
10118
10119 #define set_selection(hctl, start, end) \
10120     ret = SendMessage(hctl, EM_SETSEL, start, end); \
10121     ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
10122
10123 #define check_selection(hctl, start, end) \
10124     ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
10125     ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
10126
10127     subclass_edit();
10128
10129     hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
10130                           WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
10131                           0, 0, 100, 100, 0, 0, 0, NULL);
10132     ok(hdlg != 0, "Failed to create custom dialog window\n");
10133
10134     hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
10135                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10136                            0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
10137     ok(hedit1 != 0, "Failed to create edit control\n");
10138     hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
10139                            WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10140                            0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
10141     ok(hedit2 != 0, "Failed to create edit control\n");
10142
10143     SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
10144     SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
10145
10146     hfocus = GetFocus();
10147     ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
10148
10149     SetFocus(hedit2);
10150     hfocus = GetFocus();
10151     ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
10152
10153     check_selection(hedit1, 0, 0);
10154     check_selection(hedit2, 0, 0);
10155
10156     set_selection(hedit2, 0, -1);
10157     check_selection(hedit2, 0, 3);
10158
10159     SetFocus(0);
10160     hfocus = GetFocus();
10161     ok(hfocus == 0, "wrong focus %p\n", hfocus);
10162
10163     flush_sequence();
10164     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10165     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10166     ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
10167
10168     hfocus = GetFocus();
10169     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10170
10171     check_selection(hedit1, 0, 5);
10172     check_selection(hedit2, 0, 3);
10173
10174     flush_sequence();
10175     ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10176     ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10177     ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
10178
10179     hfocus = GetFocus();
10180     ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10181
10182     check_selection(hedit1, 0, 5);
10183     check_selection(hedit2, 0, 3);
10184
10185     EndDialog(hdlg, 0);
10186     DestroyWindow(hedit1);
10187     DestroyWindow(hedit2);
10188     DestroyWindow(hdlg);
10189     flush_sequence();
10190
10191 #undef set_selection
10192 #undef check_selection
10193
10194     ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
10195     cls.lpszClassName = "MyDialogClass";
10196     cls.hInstance = GetModuleHandle(0);
10197     /* need a cast since a dlgproc is used as a wndproc */
10198     cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
10199     if (!RegisterClass(&cls)) assert(0);
10200
10201     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
10202     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10203     ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
10204     EndDialog(hdlg, 0);
10205     DestroyWindow(hdlg);
10206     flush_sequence();
10207
10208     hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
10209     ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10210     ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
10211     EndDialog(hdlg, 0);
10212     DestroyWindow(hdlg);
10213     flush_sequence();
10214
10215     UnregisterClass(cls.lpszClassName, cls.hInstance);
10216 }
10217
10218 static void test_nullCallback(void)
10219 {
10220     HWND hwnd;
10221
10222     hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10223                            100, 100, 200, 200, 0, 0, 0, NULL);
10224     ok (hwnd != 0, "Failed to create overlapped window\n");
10225
10226     SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
10227     flush_events();
10228     DestroyWindow(hwnd);
10229 }
10230
10231 /* SetActiveWindow( 0 ) hwnd visible */
10232 static const struct message SetActiveWindowSeq0[] =
10233 {
10234     { HCBT_ACTIVATE, hook },
10235     { WM_NCACTIVATE, sent|wparam, 0 },
10236     { WM_GETTEXT, sent|defwinproc|optional },
10237     { WM_ACTIVATE, sent|wparam, 0 },
10238     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10239     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10240     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10241     { WM_NCACTIVATE, sent|wparam, 1 },
10242     { WM_GETTEXT, sent|defwinproc|optional },
10243     { WM_ACTIVATE, sent|wparam, 1 },
10244     { HCBT_SETFOCUS, hook },
10245     { WM_KILLFOCUS, sent|defwinproc },
10246     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10247     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10248     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10249     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10250     { WM_SETFOCUS, sent|defwinproc },
10251     { WM_GETTEXT, sent|optional },
10252     { 0 }
10253 };
10254 /* SetActiveWindow( hwnd ) hwnd visible */
10255 static const struct message SetActiveWindowSeq1[] =
10256 {
10257     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10258     { 0 }
10259 };
10260 /* SetActiveWindow( popup ) hwnd visible, popup visible */
10261 static const struct message SetActiveWindowSeq2[] =
10262 {
10263     { HCBT_ACTIVATE, hook },
10264     { WM_NCACTIVATE, sent|wparam, 0 },
10265     { WM_GETTEXT, sent|defwinproc|optional },
10266     { WM_ACTIVATE, sent|wparam, 0 },
10267     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10268     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10269     { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10270     { WM_NCPAINT, sent|optional },
10271     { WM_GETTEXT, sent|defwinproc|optional },
10272     { WM_ERASEBKGND, sent|optional },
10273     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10274     { WM_NCACTIVATE, sent|wparam, 1 },
10275     { WM_GETTEXT, sent|defwinproc|optional },
10276     { WM_ACTIVATE, sent|wparam, 1 },
10277     { HCBT_SETFOCUS, hook },
10278     { WM_KILLFOCUS, sent|defwinproc },
10279     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10280     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10281     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10282     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10283     { WM_SETFOCUS, sent|defwinproc },
10284     { WM_GETTEXT, sent|optional },
10285     { 0 }
10286 };
10287
10288 /* SetActiveWindow( hwnd ) hwnd not visible */
10289 static const struct message SetActiveWindowSeq3[] =
10290 {
10291     { HCBT_ACTIVATE, hook },
10292     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10293     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10294     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10295     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10296     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10297     { WM_ACTIVATEAPP, sent|wparam, 1 },
10298     { WM_ACTIVATEAPP, sent|wparam, 1 },
10299     { WM_NCACTIVATE, sent|wparam, 1 },
10300     { WM_ACTIVATE, sent|wparam, 1 },
10301     { HCBT_SETFOCUS, hook },
10302     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10303     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10304     { WM_SETFOCUS, sent|defwinproc },
10305     { 0 }
10306 };
10307 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
10308 static const struct message SetActiveWindowSeq4[] =
10309 {
10310     { HCBT_ACTIVATE, hook },
10311     { WM_NCACTIVATE, sent|wparam, 0 },
10312     { WM_GETTEXT, sent|defwinproc|optional },
10313     { WM_ACTIVATE, sent|wparam, 0 },
10314     { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10315     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10316     { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10317     { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10318     { WM_NCACTIVATE, sent|wparam, 1 },
10319     { WM_GETTEXT, sent|defwinproc|optional },
10320     { WM_ACTIVATE, sent|wparam, 1 },
10321     { HCBT_SETFOCUS, hook },
10322     { WM_KILLFOCUS, sent|defwinproc },
10323     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10324     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10325     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10326     { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10327     { WM_SETFOCUS, sent|defwinproc },
10328     { 0 }
10329 };
10330
10331
10332 static void test_SetActiveWindow(void)
10333 {
10334     HWND hwnd, popup, ret;
10335
10336     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10337                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10338                            100, 100, 200, 200, 0, 0, 0, NULL);
10339
10340     popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10341                            WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
10342                            100, 100, 200, 200, hwnd, 0, 0, NULL);
10343
10344     ok(hwnd != 0, "Failed to create overlapped window\n");
10345     flush_sequence();
10346
10347     ok(popup != 0, "Failed to create popup window\n");
10348     flush_sequence();
10349
10350     trace("SetActiveWindow(0)\n");
10351     ret = SetActiveWindow(0);
10352     ok( ret == popup, "Failed to SetActiveWindow(0)\n");
10353     ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", TRUE);
10354     flush_sequence();
10355
10356     trace("SetActiveWindow(hwnd), hwnd visible\n");
10357     ret = SetActiveWindow(hwnd);
10358     todo_wine
10359     {
10360         ok( ret == hwnd, "Failed to SetActiveWindow(hwnd), hwnd visible\n");
10361     }
10362     ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
10363     flush_sequence();
10364
10365     trace("SetActiveWindow(popup), hwnd visible, popup visible\n");
10366     ret = SetActiveWindow(popup);
10367     ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visible\n");
10368     ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visible", FALSE);
10369     flush_sequence();
10370
10371     ShowWindow(hwnd, SW_HIDE);
10372     ShowWindow(popup, SW_HIDE);
10373     flush_sequence();
10374
10375     trace("SetActiveWindow(hwnd), hwnd not visible\n");
10376     ret = SetActiveWindow(hwnd);
10377     ok( ret == NULL, "Failed to SetActiveWindow(hwnd), hwnd not visible\n");
10378     ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
10379     flush_sequence();
10380
10381     trace("SetActiveWindow(popup), hwnd not visible, popup not visible\n");
10382     ret = SetActiveWindow(popup);
10383     ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
10384     ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visible", TRUE);
10385     flush_sequence();
10386
10387     trace("done\n");
10388
10389     DestroyWindow(hwnd);
10390 }
10391
10392 static const struct message SetForegroundWindowSeq[] =
10393 {
10394     { WM_NCACTIVATE, sent|wparam, 0 },
10395     { WM_GETTEXT, sent|defwinproc|optional },
10396     { WM_ACTIVATE, sent|wparam, 0 },
10397     { WM_ACTIVATEAPP, sent|wparam, 0 },
10398     { WM_KILLFOCUS, sent },
10399     { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
10400     { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
10401     { 0 }
10402 };
10403
10404 static void test_SetForegroundWindow(void)
10405 {
10406     HWND hwnd;
10407
10408     hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
10409                            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10410                            100, 100, 200, 200, 0, 0, 0, NULL);
10411     ok (hwnd != 0, "Failed to create overlapped window\n");
10412     flush_sequence();
10413
10414     trace("SetForegroundWindow( 0 )\n");
10415     SetForegroundWindow( 0 );
10416     ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
10417     trace("SetForegroundWindow( GetDesktopWindow() )\n");
10418     SetForegroundWindow( GetDesktopWindow() );
10419     ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
10420                                         "foreground top level window", FALSE);
10421     trace("done\n");
10422
10423     DestroyWindow(hwnd);
10424 }
10425
10426 static void test_dbcs_wm_char(void)
10427 {
10428     BYTE dbch[2];
10429     WCHAR wch, bad_wch;
10430     HWND hwnd, hwnd2;
10431     MSG msg;
10432     DWORD time;
10433     POINT pt;
10434     DWORD_PTR res;
10435     CPINFOEXA cpinfo;
10436     UINT i, j, k;
10437     struct message wmCharSeq[2];
10438
10439     if (!pGetCPInfoExA)
10440     {
10441         skip("GetCPInfoExA is not available\n");
10442         return;
10443     }
10444
10445     pGetCPInfoExA( CP_ACP, 0, &cpinfo );
10446     if (cpinfo.MaxCharSize != 2)
10447     {
10448         skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
10449         return;
10450     }
10451
10452     dbch[0] = dbch[1] = 0;
10453     wch = 0;
10454     bad_wch = cpinfo.UnicodeDefaultChar;
10455     for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
10456         for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
10457             for (k = 128; k <= 255; k++)
10458             {
10459                 char str[2];
10460                 WCHAR wstr[2];
10461                 str[0] = j;
10462                 str[1] = k;
10463                 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
10464                     WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
10465                     (BYTE)str[0] == j && (BYTE)str[1] == k &&
10466                     HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
10467                 {
10468                     dbch[0] = j;
10469                     dbch[1] = k;
10470                     wch = wstr[0];
10471                     break;
10472                 }
10473             }
10474
10475     if (!wch)
10476     {
10477         skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
10478         return;
10479     }
10480     trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
10481            dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
10482
10483     hwnd = CreateWindowExW(0, testWindowClassW, NULL,
10484                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
10485     hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
10486                            WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
10487     ok (hwnd != 0, "Failed to create overlapped window\n");
10488     ok (hwnd2 != 0, "Failed to create overlapped window\n");
10489     flush_sequence();
10490
10491     memset( wmCharSeq, 0, sizeof(wmCharSeq) );
10492     wmCharSeq[0].message = WM_CHAR;
10493     wmCharSeq[0].flags = sent|wparam;
10494     wmCharSeq[0].wParam = wch;
10495
10496     /* posted message */
10497     PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10498     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10499     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10500     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10501     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10502     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10503     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10504
10505     /* posted thread message */
10506     PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
10507     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10508     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10509     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10510     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10511     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10512     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10513
10514     /* sent message */
10515     flush_sequence();
10516     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10517     ok_sequence( WmEmptySeq, "no messages", FALSE );
10518     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10519     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10520     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10521
10522     /* sent message with timeout */
10523     flush_sequence();
10524     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10525     ok_sequence( WmEmptySeq, "no messages", FALSE );
10526     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10527     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10528     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10529
10530     /* sent message with timeout and callback */
10531     flush_sequence();
10532     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
10533     ok_sequence( WmEmptySeq, "no messages", FALSE );
10534     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10535     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10536     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10537
10538     /* sent message with callback */
10539     flush_sequence();
10540     SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10541     ok_sequence( WmEmptySeq, "no messages", FALSE );
10542     SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
10543     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10544     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10545
10546     /* direct window proc call */
10547     flush_sequence();
10548     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10549     ok_sequence( WmEmptySeq, "no messages", FALSE );
10550     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10551     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10552
10553     /* dispatch message */
10554     msg.hwnd = hwnd;
10555     msg.message = WM_CHAR;
10556     msg.wParam = dbch[0];
10557     msg.lParam = 0;
10558     DispatchMessageA( &msg );
10559     ok_sequence( WmEmptySeq, "no messages", FALSE );
10560     msg.wParam = dbch[1];
10561     DispatchMessageA( &msg );
10562     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10563
10564     /* window handle is irrelevant */
10565     flush_sequence();
10566     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10567     ok_sequence( WmEmptySeq, "no messages", FALSE );
10568     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10569     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10570     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10571
10572     /* interleaved post and send */
10573     flush_sequence();
10574     PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10575     SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
10576     ok_sequence( WmEmptySeq, "no messages", FALSE );
10577     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10578     PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10579     ok_sequence( WmEmptySeq, "no messages", FALSE );
10580     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10581     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10582     ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
10583     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10584     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10585     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10586     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10587
10588     /* interleaved sent message and winproc */
10589     flush_sequence();
10590     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10591     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10592     ok_sequence( WmEmptySeq, "no messages", FALSE );
10593     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10594     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10595     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10596     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10597
10598     /* interleaved winproc and dispatch */
10599     msg.hwnd = hwnd;
10600     msg.message = WM_CHAR;
10601     msg.wParam = dbch[0];
10602     msg.lParam = 0;
10603     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10604     DispatchMessageA( &msg );
10605     ok_sequence( WmEmptySeq, "no messages", FALSE );
10606     msg.wParam = dbch[1];
10607     DispatchMessageA( &msg );
10608     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10609     CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10610     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10611
10612     /* interleaved sends */
10613     flush_sequence();
10614     SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10615     SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
10616     ok_sequence( WmEmptySeq, "no messages", FALSE );
10617     SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10618     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10619     SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10620     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10621
10622     /* dbcs WM_CHAR */
10623     flush_sequence();
10624     SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
10625     ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10626     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10627
10628     /* other char messages are not magic */
10629     PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
10630     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10631     ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
10632     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10633     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10634     PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
10635     ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10636     ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
10637     ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10638     ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10639
10640     /* test retrieving messages */
10641
10642     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10643     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10644     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10645     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10646     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10647     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10648     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10649     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10650     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10651     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10652
10653     /* message filters */
10654     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10655     ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10656     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10657     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10658     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10659     /* message id is filtered, hwnd is not */
10660     ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
10661     ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
10662     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10663     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10664     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10665     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10666
10667     /* mixing GetMessage and PostMessage */
10668     PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
10669     ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
10670     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10671     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10672     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10673     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10674     time = msg.time;
10675     pt = msg.pt;
10676     ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
10677     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10678     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10679     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10680     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10681     ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10682     ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
10683     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 );
10684     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10685
10686     /* without PM_REMOVE */
10687     PostMessageW( hwnd, WM_CHAR, wch, 0 );
10688     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10689     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10690     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10691     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10692     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10693     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10694     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10695     ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10696     ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10697     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10698     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10699     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10700     ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10701     ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10702     ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10703     ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10704     ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10705
10706     DestroyWindow(hwnd);
10707 }
10708
10709 #define ID_LISTBOX 0x000f
10710
10711 static const struct message wm_lb_setcursel_0[] =
10712 {
10713     { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
10714     { WM_CTLCOLORLISTBOX, sent|parent },
10715     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10716     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10717     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10718     { 0 }
10719 };
10720 static const struct message wm_lb_setcursel_1[] =
10721 {
10722     { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
10723     { WM_CTLCOLORLISTBOX, sent|parent },
10724     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
10725     { WM_CTLCOLORLISTBOX, sent|parent },
10726     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
10727     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10728     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10729     { 0 }
10730 };
10731 static const struct message wm_lb_setcursel_2[] =
10732 {
10733     { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
10734     { WM_CTLCOLORLISTBOX, sent|parent },
10735     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
10736     { WM_CTLCOLORLISTBOX, sent|parent },
10737     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
10738     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10739     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10740     { 0 }
10741 };
10742 static const struct message wm_lb_click_0[] =
10743 {
10744     { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
10745     { HCBT_SETFOCUS, hook },
10746     { WM_KILLFOCUS, sent|parent },
10747     { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
10748     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10749     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10750     { WM_SETFOCUS, sent|defwinproc },
10751
10752     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
10753     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
10754     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10755     { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
10756     { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
10757
10758     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
10759     { WM_CTLCOLORLISTBOX, sent|parent },
10760     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
10761     { WM_CTLCOLORLISTBOX, sent|parent },
10762     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10763     { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
10764
10765     { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10766     { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10767
10768     { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
10769     { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
10770     { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
10771     { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
10772     { 0 }
10773 };
10774
10775 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
10776
10777 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
10778
10779 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
10780 {
10781     static long defwndproc_counter = 0;
10782     LRESULT ret;
10783     struct message msg;
10784
10785     /* do not log painting messages */
10786     if (message != WM_PAINT &&
10787         message != WM_NCPAINT &&
10788         message != WM_SYNCPAINT &&
10789         message != WM_ERASEBKGND &&
10790         message != WM_NCHITTEST &&
10791         message != WM_GETTEXT &&
10792         message != WM_GETICON &&
10793         message != WM_DEVICECHANGE)
10794     {
10795         trace("listbox: %p, %04x, %08lx, %08lx\n", hwnd, message, wp, lp);
10796
10797         msg.message = message;
10798         msg.flags = sent|wparam|lparam;
10799         if (defwndproc_counter) msg.flags |= defwinproc;
10800         msg.wParam = wp;
10801         msg.lParam = lp;
10802         add_message(&msg);
10803     }
10804
10805     defwndproc_counter++;
10806     ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
10807     defwndproc_counter--;
10808
10809     return ret;
10810 }
10811
10812 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
10813                                int caret_index, int top_index, int line)
10814 {
10815     LRESULT ret;
10816
10817     /* calling an orig proc helps to avoid unnecessary message logging */
10818     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
10819     ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
10820     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
10821     ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
10822     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
10823     ok_(__FILE__, line)(ret == caret_index, "expected caret index %d, got %ld\n", caret_index, ret);
10824     ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
10825     ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
10826 }
10827
10828 static void test_listbox_messages(void)
10829 {
10830     HWND parent, listbox;
10831     LRESULT ret;
10832
10833     parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW  | WS_VISIBLE,
10834                              100, 100, 200, 200, 0, 0, 0, NULL);
10835     listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
10836                               WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
10837                               10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
10838     listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
10839
10840     check_lb_state(listbox, 0, LB_ERR, 0, 0);
10841
10842     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
10843     ok(ret == 0, "expected 0, got %ld\n", ret);
10844     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
10845     ok(ret == 1, "expected 1, got %ld\n", ret);
10846     ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
10847     ok(ret == 2, "expected 2, got %ld\n", ret);
10848
10849     check_lb_state(listbox, 3, LB_ERR, 0, 0);
10850
10851     flush_sequence();
10852
10853     log_all_parent_messages++;
10854
10855     trace("selecting item 0\n");
10856     ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
10857     ok(ret == 0, "expected 0, got %ld\n", ret);
10858     ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
10859     check_lb_state(listbox, 3, 0, 0, 0);
10860     flush_sequence();
10861
10862     trace("selecting item 1\n");
10863     ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
10864     ok(ret == 1, "expected 1, got %ld\n", ret);
10865     ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
10866     check_lb_state(listbox, 3, 1, 1, 0);
10867
10868     trace("selecting item 2\n");
10869     ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
10870     ok(ret == 2, "expected 2, got %ld\n", ret);
10871     ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
10872     check_lb_state(listbox, 3, 2, 2, 0);
10873
10874     trace("clicking on item 0\n");
10875     ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
10876     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
10877     ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
10878     ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
10879     ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
10880     check_lb_state(listbox, 3, 0, 0, 0);
10881     flush_sequence();
10882
10883     log_all_parent_messages--;
10884
10885     DestroyWindow(listbox);
10886     DestroyWindow(parent);
10887 }
10888
10889 /*************************** Menu test ******************************/
10890 static const struct message wm_popup_menu_1[] =
10891 {
10892     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
10893     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
10894     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
10895     { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
10896     { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
10897     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
10898     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
10899     { WM_INITMENU, sent|lparam, 0, 0 },
10900     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
10901     { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
10902     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
10903     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
10904     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
10905     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
10906     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
10907     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
10908     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
10909     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
10910     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
10911     { WM_MENUCOMMAND, sent }, /* |wparam, 200 - Win9x */
10912     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
10913     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
10914     { 0 }
10915 };
10916 static const struct message wm_popup_menu_2[] =
10917 {
10918     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
10919     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
10920     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
10921     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
10922     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
10923     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
10924     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
10925     { WM_INITMENU, sent|lparam, 0, 0 },
10926     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
10927     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
10928     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
10929     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
10930     { HCBT_CREATEWND, hook },
10931     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
10932                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
10933     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
10934     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
10935     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
10936     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
10937     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
10938     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
10939     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
10940     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
10941     { HCBT_DESTROYWND, hook },
10942     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
10943     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
10944     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
10945     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
10946     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
10947     { WM_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
10948     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
10949     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
10950     { 0 }
10951 };
10952 static const struct message wm_popup_menu_3[] =
10953 {
10954     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
10955     { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
10956     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
10957     { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
10958     { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
10959     { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
10960     { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
10961     { WM_INITMENU, sent|lparam, 0, 0 },
10962     { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
10963     { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
10964     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
10965     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
10966     { HCBT_CREATEWND, hook },
10967     { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
10968                                |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
10969     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
10970     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
10971     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
10972     { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
10973     { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
10974     { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
10975     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
10976     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
10977     { HCBT_DESTROYWND, hook },
10978     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
10979     { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
10980     { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
10981     { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
10982     { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
10983     { WM_COMMAND, sent|wparam|lparam, 100, 0 },
10984     { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
10985     { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
10986     { 0 }
10987 };
10988
10989 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
10990 {
10991     if (message == WM_ENTERIDLE ||
10992         message == WM_INITMENU ||
10993         message == WM_INITMENUPOPUP ||
10994         message == WM_MENUSELECT ||
10995         message == WM_PARENTNOTIFY ||
10996         message == WM_ENTERMENULOOP ||
10997         message == WM_EXITMENULOOP ||
10998         message == WM_UNINITMENUPOPUP ||
10999         message == WM_KEYDOWN ||
11000         message == WM_KEYUP ||
11001         message == WM_CHAR ||
11002         message == WM_SYSKEYDOWN ||
11003         message == WM_SYSKEYUP ||
11004         message == WM_SYSCHAR ||
11005         message == WM_COMMAND ||
11006         message == WM_MENUCOMMAND)
11007     {
11008         struct message msg;
11009
11010         trace("parent_menu_proc: %p, %04x, %08lx, %08lx\n", hwnd, message, wp, lp);
11011
11012         msg.message = message;
11013         msg.flags = sent|wparam|lparam;
11014         msg.wParam = wp;
11015         msg.lParam = lp;
11016         add_message(&msg);
11017     }
11018
11019     return DefWindowProcA(hwnd, message, wp, lp);
11020 }
11021
11022 static void set_menu_style(HMENU hmenu, DWORD style)
11023 {
11024     MENUINFO mi;
11025     BOOL ret;
11026
11027     mi.cbSize = sizeof(mi);
11028     mi.fMask = MIM_STYLE;
11029     mi.dwStyle = style;
11030     SetLastError(0xdeadbeef);
11031     ret = pSetMenuInfo(hmenu, &mi);
11032     ok(ret, "SetMenuInfo error %u\n", GetLastError());
11033 }
11034
11035 static DWORD get_menu_style(HMENU hmenu)
11036 {
11037     MENUINFO mi;
11038     BOOL ret;
11039
11040     mi.cbSize = sizeof(mi);
11041     mi.fMask = MIM_STYLE;
11042     mi.dwStyle = 0;
11043     SetLastError(0xdeadbeef);
11044     ret = pGetMenuInfo(hmenu, &mi);
11045     ok(ret, "GetMenuInfo error %u\n", GetLastError());
11046
11047     return mi.dwStyle;
11048 }
11049
11050 static void test_menu_messages(void)
11051 {
11052     MSG msg;
11053     WNDCLASSA cls;
11054     HMENU hmenu, hmenu_popup;
11055     HWND hwnd;
11056     DWORD style;
11057
11058     if (!pGetMenuInfo || !pSetMenuInfo)
11059     {
11060         skip("GetMenuInfo and/or SetMenuInfo are not available\n");
11061         return;
11062     }
11063     cls.style = 0;
11064     cls.lpfnWndProc = parent_menu_proc;
11065     cls.cbClsExtra = 0;
11066     cls.cbWndExtra = 0;
11067     cls.hInstance = GetModuleHandleA(0);
11068     cls.hIcon = 0;
11069     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
11070     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
11071     cls.lpszMenuName = NULL;
11072     cls.lpszClassName = "TestMenuClass";
11073     UnregisterClass(cls.lpszClassName, cls.hInstance);
11074     if (!RegisterClassA(&cls)) assert(0);
11075
11076     SetLastError(0xdeadbeef);
11077     hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11078                            100, 100, 200, 200, 0, 0, 0, NULL);
11079     ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
11080
11081     SetLastError(0xdeadbeef);
11082     hmenu = LoadMenuA(GetModuleHandle(0), MAKEINTRESOURCE(1));
11083     ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
11084
11085     SetMenu(hwnd, hmenu);
11086     SetForegroundWindow( hwnd );
11087
11088     set_menu_style(hmenu, MNS_NOTIFYBYPOS);
11089     style = get_menu_style(hmenu);
11090     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11091
11092     hmenu_popup = GetSubMenu(hmenu, 0);
11093     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11094     style = get_menu_style(hmenu_popup);
11095     ok(style == 0, "expected 0, got %u\n", style);
11096
11097     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11098     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11099     style = get_menu_style(hmenu_popup);
11100     ok(style == 0, "expected 0, got %u\n", style);
11101
11102     /* Alt+E, Enter */
11103     trace("testing a popup menu command\n");
11104     flush_sequence();
11105     keybd_event(VK_MENU, 0, 0, 0);
11106     keybd_event('E', 0, 0, 0);
11107     keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
11108     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11109     keybd_event(VK_RETURN, 0, 0, 0);
11110     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11111     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11112     {
11113         TranslateMessage(&msg);
11114         DispatchMessage(&msg);
11115     }
11116     ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
11117
11118     /* Alt+F, Right, Enter */
11119     trace("testing submenu of a popup menu command\n");
11120     flush_sequence();
11121     keybd_event(VK_MENU, 0, 0, 0);
11122     keybd_event('F', 0, 0, 0);
11123     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11124     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11125     keybd_event(VK_RIGHT, 0, 0, 0);
11126     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11127     keybd_event(VK_RETURN, 0, 0, 0);
11128     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11129     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11130     {
11131         TranslateMessage(&msg);
11132         DispatchMessage(&msg);
11133     }
11134     ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
11135
11136     set_menu_style(hmenu, 0);
11137     style = get_menu_style(hmenu);
11138     ok(style == 0, "expected 0, got %u\n", style);
11139
11140     hmenu_popup = GetSubMenu(hmenu, 0);
11141     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11142     set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
11143     style = get_menu_style(hmenu_popup);
11144     ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11145
11146     hmenu_popup = GetSubMenu(hmenu_popup, 0);
11147     ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11148     style = get_menu_style(hmenu_popup);
11149     ok(style == 0, "expected 0, got %u\n", style);
11150
11151     /* Alt+F, Right, Enter */
11152     trace("testing submenu of a popup menu command\n");
11153     flush_sequence();
11154     keybd_event(VK_MENU, 0, 0, 0);
11155     keybd_event('F', 0, 0, 0);
11156     keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11157     keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11158     keybd_event(VK_RIGHT, 0, 0, 0);
11159     keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11160     keybd_event(VK_RETURN, 0, 0, 0);
11161     keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11162     while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11163     {
11164         TranslateMessage(&msg);
11165         DispatchMessage(&msg);
11166     }
11167     ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
11168
11169     DestroyWindow(hwnd);
11170     DestroyMenu(hmenu);
11171 }
11172
11173
11174 static void test_paintingloop(void)
11175 {
11176     HWND hwnd;
11177
11178     paint_loop_done = 0;
11179     hwnd = CreateWindowExA(0x0,"PaintLoopWindowClass",
11180                                "PaintLoopWindowClass",WS_OVERLAPPEDWINDOW,
11181                                 100, 100, 100, 100, 0, 0, 0, NULL );
11182     ok(hwnd != 0, "PaintLoop window error %u\n", GetLastError());
11183     ShowWindow(hwnd,SW_NORMAL);
11184     SetFocus(hwnd);
11185
11186     while (!paint_loop_done)
11187     {
11188         MSG msg;
11189         if (PeekMessageA(&msg, 0, 0, 0, 1))
11190         {
11191             TranslateMessage(&msg);
11192             DispatchMessage(&msg);
11193         }
11194     }
11195     DestroyWindow(hwnd);
11196 }
11197
11198 START_TEST(msg)
11199 {
11200     BOOL ret;
11201     FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
11202
11203     init_procs();
11204
11205     if (!RegisterWindowClasses()) assert(0);
11206
11207     if (pSetWinEventHook)
11208     {
11209         hEvent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
11210                                                       GetModuleHandleA(0),
11211                                                       win_event_proc,
11212                                                       0,
11213                                                       GetCurrentThreadId(),
11214                                                       WINEVENT_INCONTEXT);
11215         assert(hEvent_hook);
11216
11217         if (pIsWinEventHookInstalled)
11218         {
11219             UINT event;
11220             for (event = EVENT_MIN; event <= EVENT_MAX; event++)
11221                 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
11222         }
11223     }
11224
11225     cbt_hook_thread_id = GetCurrentThreadId();
11226     hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
11227     assert(hCBT_hook);
11228
11229     test_winevents();
11230
11231     /* Fix message sequences before removing 4 lines below */
11232 #if 1
11233     if (pUnhookWinEvent && hEvent_hook)
11234     {
11235         ret = pUnhookWinEvent(hEvent_hook);
11236         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
11237         pUnhookWinEvent = 0;
11238     }
11239     hEvent_hook = 0;
11240 #endif
11241
11242     test_ShowWindow();
11243     test_PeekMessage();
11244     test_PeekMessage2();
11245     test_scrollwindowex();
11246     test_messages();
11247     test_setwindowpos();
11248     test_showwindow();
11249     invisible_parent_tests();
11250     test_mdi_messages();
11251     test_button_messages();
11252     test_static_messages();
11253     test_listbox_messages();
11254     test_combobox_messages();
11255     test_wmime_keydown_message();
11256     test_paint_messages();
11257     test_interthread_messages();
11258     test_message_conversion();
11259     test_accelerators();
11260     test_timers();
11261     test_timers_no_wnd();
11262     test_set_hook();
11263     test_DestroyWindow();
11264     test_DispatchMessage();
11265     test_SendMessageTimeout();
11266     test_edit_messages();
11267     test_quit_message();
11268     test_SetActiveWindow();
11269
11270     if (!pTrackMouseEvent)
11271         skip("TrackMouseEvent is not available\n");
11272     else
11273         test_TrackMouseEvent();
11274
11275     test_SetWindowRgn();
11276     test_sys_menu();
11277     test_dialog_messages();
11278     test_nullCallback();
11279     test_dbcs_wm_char();
11280     test_menu_messages();
11281     test_paintingloop();
11282     /* keep it the last test, under Windows it tends to break the tests
11283      * which rely on active/foreground windows being correct.
11284      */
11285     test_SetForegroundWindow();
11286
11287     UnhookWindowsHookEx(hCBT_hook);
11288     if (pUnhookWinEvent)
11289     {
11290         ret = pUnhookWinEvent(hEvent_hook);
11291         ok( ret, "UnhookWinEvent error %d\n", GetLastError());
11292         SetLastError(0xdeadbeef);
11293         ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
11294         ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
11295            GetLastError() == 0xdeadbeef, /* Win9x */
11296            "unexpected error %d\n", GetLastError());
11297     }
11298     else
11299         skip("UnhookWinEvent is not available\n");
11300 }