Turn on test_accelerators.
[reactos.git] / rostests / winetests / user32 / msg.c
1 /*
2 * Unit tests for window message handling
3 *
4 * Copyright 1999 Ove Kaaven
5 * Copyright 2003 Dimitrie O. Paun
6 * Copyright 2004, 2005 Dmitry Timoshkov
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23 #define _WIN32_WINNT 0x0600 /* For WM_CHANGEUISTATE,QS_RAWINPUT,WM_DWMxxxx */
24 #define WINVER 0x0600 /* for WM_GETTITLEBARINFOEX */
25
26 #include <assert.h>
27 #include <stdarg.h>
28 #include <stdio.h>
29
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winuser.h"
34 #include "winnls.h"
35
36 #include "wine/test.h"
37
38 #define MDI_FIRST_CHILD_ID 2004
39
40 /* undocumented SWP flags - from SDK 3.1 */
41 #define SWP_NOCLIENTSIZE 0x0800
42 #define SWP_NOCLIENTMOVE 0x1000
43 #define SWP_STATECHANGED 0x8000
44
45 #define SW_NORMALNA 0xCC /* undoc. flag in MinMaximize */
46
47 #ifndef WM_KEYF1
48 #define WM_KEYF1 0x004d
49 #endif
50
51 #ifndef WM_SYSTIMER
52 #define WM_SYSTIMER 0x0118
53 #endif
54
55 #define WND_PARENT_ID 1
56 #define WND_POPUP_ID 2
57 #define WND_CHILD_ID 3
58
59 #ifndef WM_LBTRACKPOINT
60 #define WM_LBTRACKPOINT 0x0131
61 #endif
62
63 /* encoded DRAWITEMSTRUCT into an LPARAM */
64 typedef struct
65 {
66 union
67 {
68 struct
69 {
70 UINT type : 4; /* ODT_* flags */
71 UINT ctl_id : 4; /* Control ID */
72 UINT item_id : 4; /* Menu item ID */
73 UINT action : 4; /* ODA_* flags */
74 UINT state : 16; /* ODS_* flags */
75 } item;
76 LPARAM lp;
77 } u;
78 } DRAW_ITEM_STRUCT;
79
80 static BOOL test_DestroyWindow_flag;
81 static HWINEVENTHOOK hEvent_hook;
82 static HHOOK hCBT_hook;
83 static DWORD cbt_hook_thread_id;
84
85 static const WCHAR testWindowClassW[] =
86 { 'T','e','s','t','W','i','n','d','o','w','C','l','a','s','s','W',0 };
87
88 /*
89 FIXME: add tests for these
90 Window Edge Styles (Win31/Win95/98 look), in order of precedence:
91 WS_EX_DLGMODALFRAME: double border, WS_CAPTION allowed
92 WS_THICKFRAME: thick border
93 WS_DLGFRAME: double border, WS_CAPTION not allowed (but possibly shown anyway)
94 WS_BORDER (default for overlapped windows): single black border
95 none (default for child (and popup?) windows): no border
96 */
97
98 typedef enum {
99 sent=0x1,
100 posted=0x2,
101 parent=0x4,
102 wparam=0x8,
103 lparam=0x10,
104 defwinproc=0x20,
105 beginpaint=0x40,
106 optional=0x80,
107 hook=0x100,
108 winevent_hook=0x200
109 } msg_flags_t;
110
111 struct message {
112 UINT message; /* the WM_* code */
113 msg_flags_t flags; /* message props */
114 WPARAM wParam; /* expected value of wParam */
115 LPARAM lParam; /* expected value of lParam */
116 WPARAM wp_mask; /* mask for wParam checks */
117 LPARAM lp_mask; /* mask for lParam checks */
118 };
119
120 struct recvd_message {
121 UINT message; /* the WM_* code */
122 msg_flags_t flags; /* message props */
123 HWND hwnd; /* window that received the message */
124 WPARAM wParam; /* expected value of wParam */
125 LPARAM lParam; /* expected value of lParam */
126 int line; /* source line where logged */
127 const char *descr; /* description for trace output */
128 char output[512]; /* trace output */
129 };
130
131 /* Empty message sequence */
132 static const struct message WmEmptySeq[] =
133 {
134 { 0 }
135 };
136 /* CreateWindow (for overlapped window, not initially visible) (16/32) */
137 static const struct message WmCreateOverlappedSeq[] = {
138 { HCBT_CREATEWND, hook },
139 { WM_GETMINMAXINFO, sent },
140 { WM_NCCREATE, sent },
141 { WM_NCCALCSIZE, sent|wparam, 0 },
142 { 0x0093, sent|defwinproc|optional },
143 { 0x0094, sent|defwinproc|optional },
144 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
145 { WM_CREATE, sent },
146 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
147 { 0 }
148 };
149 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
150 * for a not visible overlapped window.
151 */
152 static const struct message WmSWP_ShowOverlappedSeq[] = {
153 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
154 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
155 { WM_NCPAINT, sent|wparam|optional, 1 },
156 { WM_GETTEXT, sent|defwinproc|optional },
157 { WM_ERASEBKGND, sent|optional },
158 { HCBT_ACTIVATE, hook },
159 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
160 { WM_NOTIFYFORMAT, sent|optional },
161 { WM_QUERYUISTATE, sent|optional },
162 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
163 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x: SWP_NOSENDCHANGING */
164 { WM_ACTIVATEAPP, sent|wparam, 1 },
165 { WM_NCACTIVATE, sent },
166 { WM_GETTEXT, sent|defwinproc|optional },
167 { WM_ACTIVATE, sent|wparam, 1 },
168 { HCBT_SETFOCUS, hook },
169 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
170 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
171 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
172 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
173 { WM_GETTEXT, sent|optional },
174 { WM_NCPAINT, sent|wparam|optional, 1 },
175 { WM_GETTEXT, sent|defwinproc|optional },
176 { WM_ERASEBKGND, sent|optional },
177 /* Win9x adds SWP_NOZORDER below */
178 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
179 { WM_GETTEXT, sent|optional },
180 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
181 { WM_NCPAINT, sent|wparam|optional, 1 },
182 { WM_ERASEBKGND, sent|optional },
183 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
184 { WM_SYNCPAINT, sent|optional },
185 { WM_GETTITLEBARINFOEX, sent|optional },
186 { WM_PAINT, sent|optional },
187 { WM_NCPAINT, sent|beginpaint|optional },
188 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
189 { WM_ERASEBKGND, sent|beginpaint|optional },
190 { 0 }
191 };
192 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
193 * for a visible overlapped window.
194 */
195 static const struct message WmSWP_HideOverlappedSeq[] = {
196 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
197 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
198 { HCBT_ACTIVATE, hook|optional },
199 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
200 { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
201 { WM_NCACTIVATE, sent|optional },
202 { WM_ACTIVATE, sent|optional },
203 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
204 { 0 }
205 };
206
207 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
208 * for a visible overlapped window.
209 */
210 static const struct message WmSWP_ResizeSeq[] = {
211 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
212 { WM_GETMINMAXINFO, sent|defwinproc },
213 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
214 { WM_NCPAINT, sent|optional },
215 { WM_GETTEXT, sent|defwinproc|optional },
216 { WM_ERASEBKGND, sent|optional },
217 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
218 { WM_SIZE, sent|defwinproc|optional },
219 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
220 { WM_NCPAINT, sent|optional },
221 { WM_GETTEXT, sent|defwinproc|optional },
222 { WM_ERASEBKGND, sent|optional },
223 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
224 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
225 { 0 }
226 };
227
228 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
229 * for a visible popup window.
230 */
231 static const struct message WmSWP_ResizePopupSeq[] = {
232 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
233 { WM_GETMINMAXINFO, sent|defwinproc|optional }, /* Win9x */
234 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
235 { WM_NCPAINT, sent|optional },
236 { WM_GETTEXT, sent|defwinproc|optional },
237 { WM_ERASEBKGND, sent|optional },
238 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
239 { WM_SIZE, sent|defwinproc|wparam|optional, SIZE_RESTORED },
240 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
241 { WM_NCPAINT, sent|optional },
242 { WM_GETTEXT, sent|defwinproc|optional },
243 { WM_ERASEBKGND, sent|optional },
244 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
245 { 0 }
246 };
247
248 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
249 * for a visible overlapped window.
250 */
251 static const struct message WmSWP_MoveSeq[] = {
252 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE },
253 { WM_NCPAINT, sent|optional },
254 { WM_GETTEXT, sent|defwinproc|optional },
255 { WM_ERASEBKGND, sent|optional },
256 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
257 { WM_MOVE, sent|defwinproc|wparam, 0 },
258 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
259 { 0 }
260 };
261 /* Resize with SetWindowPos(SWP_NOZORDER)
262 * for a visible overlapped window
263 * SWP_NOZORDER is stripped by the logging code
264 */
265 static const struct message WmSWP_ResizeNoZOrder[] = {
266 { WM_WINDOWPOSCHANGING, sent|wparam, /*SWP_NOZORDER|*/SWP_NOACTIVATE },
267 { WM_GETMINMAXINFO, sent|defwinproc },
268 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
269 { WM_NCPAINT, sent|optional },
270 { WM_GETTEXT, sent|defwinproc|optional },
271 { WM_ERASEBKGND, sent|optional },
272 { WM_WINDOWPOSCHANGED, sent|wparam|optional, /*SWP_NOZORDER|*/SWP_NOACTIVATE, 0,
273 SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
274 { WM_MOVE, sent|defwinproc|optional },
275 { WM_SIZE, sent|defwinproc|optional },
276 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
277 { WM_NCPAINT, sent|optional }, /* Win9x doesn't send it */
278 { WM_GETTEXT, sent|defwinproc|optional }, /* Win9x doesn't send it */
279 { WM_ERASEBKGND, sent|optional }, /* Win9x doesn't send it */
280 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
281 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
282 { 0 }
283 };
284
285 /* Switch visible mdi children */
286 static const struct message WmSwitchChild[] = {
287 /* Switch MDI child */
288 { WM_MDIACTIVATE, sent },/* in the MDI client */
289 { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 1st MDI child */
290 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
291 { WM_CHILDACTIVATE, sent },/* in the 1st MDI child */
292 /* Deactivate 2nd MDI child */
293 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
294 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
295 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
296 /* Preparing for maximize and maximaze the 1st MDI child */
297 { WM_GETMINMAXINFO, sent|defwinproc }, /* in the 1st MDI child */
298 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED }, /* in the 1st MDI child */
299 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
300 { WM_CHILDACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
301 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 1st MDI child */
302 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED }, /* in the 1st MDI child */
303 /* Lock redraw 2nd MDI child */
304 { WM_SETREDRAW, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
305 { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
306 /* Restore 2nd MDI child */
307 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },/* in the 2nd MDI child */
308 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
309 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
310 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 2nd MDI child */
311 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED }, /* in the 2nd MDI child */
312 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
313 /* Redraw 2nd MDI child */
314 { WM_SETREDRAW, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
315 /* Redraw MDI frame */
316 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },/* in MDI frame */
317 { WM_NCCALCSIZE, sent|wparam, 1 },/* in MDI frame */
318 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in MDI frame */
319 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in MDI frame */
320 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
321 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
322 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
323 { HCBT_SETFOCUS, hook },
324 { WM_KILLFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
325 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },/* in the 1st MDI child */
326 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
327 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
328 { WM_SETFOCUS, sent },/* in the MDI client */
329 { HCBT_SETFOCUS, hook },
330 { WM_KILLFOCUS, sent },/* in the MDI client */
331 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
332 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 }, /* in the 1st MDI child */
333 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
334 { WM_SETFOCUS, sent|defwinproc }, /* in the 1st MDI child */
335 { WM_MDIACTIVATE, sent|defwinproc },/* in the 1st MDI child */
336 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* in the 1st MDI child */
337 { 0 }
338 };
339
340 /* Switch visible not maximized mdi children */
341 static const struct message WmSwitchNotMaximizedChild[] = {
342 /* Switch not maximized MDI child */
343 { WM_MDIACTIVATE, sent },/* in the MDI client */
344 { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 2nd MDI child */
345 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
346 { WM_CHILDACTIVATE, sent },/* in the 2nd MDI child */
347 /* Deactivate 1st MDI child */
348 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
349 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
350 /* Activate 2nd MDI child */
351 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE}, /* in the 2nd MDI child */
352 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 2nd MDI child */
353 { HCBT_SETFOCUS, hook }, /* in the 1st MDI child */
354 { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
355 { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
356 { WM_IME_SETCONTEXT, sent|optional }, /* in the MDI client */
357 { WM_SETFOCUS, sent, 0 }, /* in the MDI client */
358 { HCBT_SETFOCUS, hook },
359 { WM_KILLFOCUS, sent }, /* in the MDI client */
360 { WM_IME_SETCONTEXT, sent|optional }, /* in the MDI client */
361 { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
362 { WM_SETFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
363 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
364 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in the 2nd MDI child */
365 { 0 }
366 };
367
368
369 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
370 SWP_NOZORDER|SWP_FRAMECHANGED)
371 * for a visible overlapped window with WS_CLIPCHILDREN style set.
372 */
373 static const struct message WmSWP_FrameChanged_clip[] = {
374 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
375 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
376 { WM_NCPAINT, sent|parent|optional }, /* wparam != 1 */
377 { WM_GETTEXT, sent|parent|defwinproc|optional },
378 { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
379 { WM_NCPAINT, sent }, /* wparam != 1 */
380 { WM_ERASEBKGND, sent },
381 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
382 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
383 { WM_PAINT, sent },
384 { 0 }
385 };
386 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|
387 SWP_NOZORDER|SWP_FRAMECHANGED)
388 * for a visible overlapped window.
389 */
390 static const struct message WmSWP_FrameChangedDeferErase[] = {
391 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
392 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
393 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
394 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
395 { WM_PAINT, sent|parent|optional },
396 { WM_NCPAINT, sent|beginpaint|parent|optional }, /* wparam != 1 */
397 { WM_GETTEXT, sent|beginpaint|parent|defwinproc|optional },
398 { WM_PAINT, sent },
399 { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
400 { WM_ERASEBKGND, sent|beginpaint|optional },
401 { 0 }
402 };
403
404 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
405 SWP_NOZORDER|SWP_FRAMECHANGED)
406 * for a visible overlapped window without WS_CLIPCHILDREN style set.
407 */
408 static const struct message WmSWP_FrameChanged_noclip[] = {
409 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
410 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
411 { WM_NCPAINT, sent|parent|optional }, /* wparam != 1 */
412 { WM_GETTEXT, sent|parent|defwinproc|optional },
413 { WM_ERASEBKGND, sent|parent|optional },
414 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
415 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
416 { WM_PAINT, sent },
417 { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
418 { WM_ERASEBKGND, sent|beginpaint|optional },
419 { 0 }
420 };
421
422 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
423 static const struct message WmShowOverlappedSeq[] = {
424 { WM_SHOWWINDOW, sent|wparam, 1 },
425 { WM_NCPAINT, sent|wparam|optional, 1 },
426 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
427 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
428 { WM_NCPAINT, sent|wparam|optional, 1 },
429 { WM_GETTEXT, sent|defwinproc|optional },
430 { WM_ERASEBKGND, sent|optional },
431 { HCBT_ACTIVATE, hook },
432 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
433 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
434 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
435 { WM_NCPAINT, sent|wparam|optional, 1 },
436 { WM_ACTIVATEAPP, sent|wparam, 1 },
437 { WM_NCACTIVATE, sent|wparam, 1 },
438 { WM_GETTEXT, sent|defwinproc|optional },
439 { WM_ACTIVATE, sent|wparam, 1 },
440 { HCBT_SETFOCUS, hook },
441 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
442 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
443 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
444 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
445 { WM_GETTEXT, sent|optional },
446 { WM_NCPAINT, sent|wparam|optional, 1 },
447 { WM_GETTEXT, sent|defwinproc|optional },
448 { WM_ERASEBKGND, sent|optional },
449 /* Win9x adds SWP_NOZORDER below */
450 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
451 { WM_NCCALCSIZE, sent|optional },
452 { WM_GETTEXT, sent|optional },
453 { WM_NCPAINT, sent|optional },
454 { WM_ERASEBKGND, sent|optional },
455 { WM_SYNCPAINT, sent|optional },
456 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
457 * messages. Does that mean that CreateWindow doesn't set initial
458 * window dimensions for overlapped windows?
459 */
460 { WM_SIZE, sent },
461 { WM_MOVE, sent },
462 #endif
463 { WM_PAINT, sent|optional },
464 { WM_NCPAINT, sent|beginpaint|optional },
465 { 0 }
466 };
467 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible overlapped window */
468 static const struct message WmShowMaxOverlappedSeq[] = {
469 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
470 { WM_GETMINMAXINFO, sent },
471 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
472 { WM_GETMINMAXINFO, sent|defwinproc },
473 { WM_NCCALCSIZE, sent|wparam, TRUE },
474 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
475 { HCBT_ACTIVATE, hook },
476 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
477 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
478 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
479 { WM_ACTIVATEAPP, sent|wparam, 1 },
480 { WM_NCACTIVATE, sent|wparam, 1 },
481 { WM_GETTEXT, sent|defwinproc|optional },
482 { WM_ACTIVATE, sent|wparam, 1 },
483 { HCBT_SETFOCUS, hook },
484 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
485 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
486 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
487 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
488 { WM_GETTEXT, sent|optional },
489 { WM_NCPAINT, sent|wparam|optional, 1 },
490 { WM_GETTEXT, sent|defwinproc|optional },
491 { WM_ERASEBKGND, sent|optional },
492 /* Win9x adds SWP_NOZORDER below */
493 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
494 { WM_MOVE, sent|defwinproc },
495 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
496 { WM_GETTEXT, sent|optional },
497 { WM_NCCALCSIZE, sent|optional },
498 { WM_NCPAINT, sent|optional },
499 { WM_ERASEBKGND, sent|optional },
500 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
501 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
502 { WM_SYNCPAINT, sent|optional },
503 { WM_GETTITLEBARINFOEX, sent|optional },
504 { WM_PAINT, sent|optional },
505 { WM_NCPAINT, sent|beginpaint|optional },
506 { WM_ERASEBKGND, sent|beginpaint|optional },
507 { 0 }
508 };
509 /* ShowWindow(SW_RESTORE) for a not visible maximized overlapped window */
510 static const struct message WmShowRestoreMaxOverlappedSeq[] = {
511 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
512 { WM_GETTEXT, sent|optional },
513 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
514 { WM_GETMINMAXINFO, sent|defwinproc },
515 { WM_NCCALCSIZE, sent|wparam, TRUE },
516 { WM_NCPAINT, sent|optional },
517 { WM_GETTEXT, sent|defwinproc|optional },
518 { WM_ERASEBKGND, sent|optional },
519 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
520 { WM_MOVE, sent|defwinproc|optional },
521 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
522 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
523 { WM_NCPAINT, sent|optional },
524 { WM_ERASEBKGND, sent|optional },
525 { WM_PAINT, sent|optional },
526 { WM_GETTITLEBARINFOEX, sent|optional },
527 { WM_NCPAINT, sent|beginpaint|optional },
528 { WM_ERASEBKGND, sent|beginpaint|optional },
529 { 0 }
530 };
531 /* ShowWindow(SW_RESTORE) for a not visible minimized overlapped window */
532 static const struct message WmShowRestoreMinOverlappedSeq[] = {
533 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
534 { WM_QUERYOPEN, sent|optional },
535 { WM_GETTEXT, sent|optional },
536 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED|SWP_NOCOPYBITS },
537 { WM_GETMINMAXINFO, sent|defwinproc },
538 { WM_NCCALCSIZE, sent|wparam, TRUE },
539 { HCBT_ACTIVATE, hook },
540 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
541 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
542 { WM_ACTIVATEAPP, sent|wparam, 1 },
543 { WM_NCACTIVATE, sent|wparam, 1 },
544 { WM_GETTEXT, sent|defwinproc|optional },
545 { WM_ACTIVATE, sent|wparam, 1 },
546 { HCBT_SETFOCUS, hook },
547 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
548 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
549 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
550 { WM_GETTEXT, sent|optional },
551 { WM_NCPAINT, sent|wparam|optional, 1 },
552 { WM_GETTEXT, sent|defwinproc|optional },
553 { WM_ERASEBKGND, sent },
554 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_STATECHANGED|SWP_FRAMECHANGED|SWP_NOCOPYBITS },
555 { WM_MOVE, sent|defwinproc },
556 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
557 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
558 { WM_NCPAINT, sent|wparam|optional, 1 },
559 { WM_ERASEBKGND, sent|optional },
560 { WM_ACTIVATE, sent|wparam, 1 },
561 { WM_GETTEXT, sent|optional },
562 { WM_PAINT, sent|optional },
563 { WM_GETTITLEBARINFOEX, sent|optional },
564 { WM_NCPAINT, sent|beginpaint|optional },
565 { WM_ERASEBKGND, sent|beginpaint|optional },
566 { 0 }
567 };
568 /* ShowWindow(SW_SHOWMINIMIZED) for a not visible overlapped window */
569 static const struct message WmShowMinOverlappedSeq[] = {
570 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
571 { HCBT_SETFOCUS, hook },
572 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
573 { WM_KILLFOCUS, sent },
574 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
575 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
576 { WM_GETTEXT, sent|optional },
577 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCOPYBITS|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
578 { WM_GETMINMAXINFO, sent|defwinproc },
579 { WM_NCCALCSIZE, sent|wparam, TRUE },
580 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
581 { WM_NCPAINT, sent|optional },
582 { WM_GETTEXT, sent|defwinproc|optional },
583 { WM_WINDOWPOSCHANGED, sent },
584 { WM_MOVE, sent|defwinproc },
585 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
586 { WM_NCCALCSIZE, sent|optional },
587 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
588 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
589 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
590 { WM_NCACTIVATE, sent|wparam, 0 },
591 { WM_GETTEXT, sent|defwinproc|optional },
592 { WM_ACTIVATE, sent },
593 { WM_ACTIVATEAPP, sent|wparam, 0 },
594
595 /* Vista sometimes restores the window right away... */
596 { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
597 { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
598 { HCBT_MINMAX, hook|optional|lparam, 0, SW_RESTORE },
599 { WM_QUERYOPEN, sent|optional },
600 { WM_WINDOWPOSCHANGING, sent|optional|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
601 { WM_GETMINMAXINFO, sent|optional|defwinproc },
602 { WM_NCCALCSIZE, sent|optional|wparam, TRUE },
603 { HCBT_ACTIVATE, hook|optional },
604 { WM_ACTIVATEAPP, sent|optional|wparam, 1 },
605 { WM_NCACTIVATE, sent|optional },
606 { WM_GETTEXT, sent|optional },
607 { WM_ACTIVATE, sent|optional|wparam, 1 },
608 { HCBT_SETFOCUS, hook|optional },
609 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
610 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
611 { WM_SETFOCUS, sent|optional },
612 { WM_NCPAINT, sent|optional },
613 { WM_GETTEXT, sent|defwinproc|optional },
614 { WM_ERASEBKGND, sent|optional },
615 { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
616 { WM_MOVE, sent|defwinproc|optional },
617 { WM_SIZE, sent|defwinproc|optional|wparam, SIZE_RESTORED },
618 { WM_ACTIVATE, sent|optional|wparam, 1 },
619 { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
620 { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
621
622 { WM_PAINT, sent|optional },
623 { WM_NCPAINT, sent|beginpaint|optional },
624 { WM_ERASEBKGND, sent|beginpaint|optional },
625 { 0 }
626 };
627 /* ShowWindow(SW_HIDE) for a visible overlapped window */
628 static const struct message WmHideOverlappedSeq[] = {
629 { WM_SHOWWINDOW, sent|wparam, 0 },
630 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
631 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
632 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
633 { WM_SIZE, sent|optional }, /* XP doesn't send it */
634 { WM_MOVE, sent|optional }, /* XP doesn't send it */
635 { WM_NCACTIVATE, sent|wparam|optional, 0 },
636 { WM_ACTIVATE, sent|wparam|optional, 0 },
637 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
638 { HCBT_SETFOCUS, hook|optional },
639 { WM_KILLFOCUS, sent|wparam, 0 },
640 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
641 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
642 { 0 }
643 };
644 /* DestroyWindow for a visible overlapped window */
645 static const struct message WmDestroyOverlappedSeq[] = {
646 { HCBT_DESTROYWND, hook },
647 { 0x0090, sent|optional },
648 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
649 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
650 { 0x0090, sent|optional },
651 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
652 { WM_NCACTIVATE, sent|optional|wparam, 0 },
653 { WM_ACTIVATE, sent|optional },
654 { WM_ACTIVATEAPP, sent|optional|wparam, 0 },
655 { WM_KILLFOCUS, sent|optional|wparam, 0 },
656 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
657 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
658 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
659 { WM_DESTROY, sent },
660 { WM_NCDESTROY, sent },
661 { 0 }
662 };
663 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
664 static const struct message WmCreateMaxPopupSeq[] = {
665 { HCBT_CREATEWND, hook },
666 { WM_NCCREATE, sent },
667 { WM_NCCALCSIZE, sent|wparam, 0 },
668 { WM_CREATE, sent },
669 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
670 { WM_SIZE, sent|wparam, SIZE_RESTORED },
671 { WM_MOVE, sent },
672 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
673 { WM_GETMINMAXINFO, sent },
674 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
675 { WM_NCCALCSIZE, sent|wparam, TRUE },
676 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
677 { WM_MOVE, sent|defwinproc },
678 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
679 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
680 { WM_SHOWWINDOW, sent|wparam, 1 },
681 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
682 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
683 { HCBT_ACTIVATE, hook },
684 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
685 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
686 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
687 { WM_NCPAINT, sent|wparam|optional, 1 },
688 { WM_ERASEBKGND, sent|optional },
689 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_NOMOVE|SWP_NOSIZE },
690 { WM_ACTIVATEAPP, sent|wparam, 1 },
691 { WM_NCACTIVATE, sent },
692 { WM_ACTIVATE, sent|wparam, 1 },
693 { HCBT_SETFOCUS, hook },
694 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
695 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
696 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
697 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
698 { WM_GETTEXT, sent|optional },
699 { WM_SYNCPAINT, sent|wparam|optional, 4 },
700 { WM_NCPAINT, sent|wparam|optional, 1 },
701 { WM_ERASEBKGND, sent|optional },
702 { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
703 { WM_ERASEBKGND, sent|defwinproc|optional },
704 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
705 { 0 }
706 };
707 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
708 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
709 { HCBT_CREATEWND, hook },
710 { WM_NCCREATE, sent },
711 { WM_NCCALCSIZE, sent|wparam, 0 },
712 { WM_CREATE, sent },
713 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
714 { WM_SIZE, sent|wparam, SIZE_RESTORED },
715 { WM_MOVE, sent },
716 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
717 { WM_GETMINMAXINFO, sent },
718 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
719 { WM_NCCALCSIZE, sent|wparam, TRUE },
720 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
721 { WM_MOVE, sent|defwinproc },
722 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
723 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
724 { 0 }
725 };
726 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
727 static const struct message WmShowMaxPopupResizedSeq[] = {
728 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
729 { WM_GETMINMAXINFO, sent },
730 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
731 { WM_NCCALCSIZE, sent|wparam, TRUE },
732 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
733 { HCBT_ACTIVATE, hook },
734 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
735 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
736 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
737 { WM_NCPAINT, sent|wparam|optional, 1 },
738 { WM_ERASEBKGND, sent|optional },
739 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
740 { WM_ACTIVATEAPP, sent|wparam, 1 },
741 { WM_NCACTIVATE, sent },
742 { WM_ACTIVATE, sent|wparam, 1 },
743 { HCBT_SETFOCUS, hook },
744 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
745 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
746 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
747 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
748 { WM_GETTEXT, sent|optional },
749 { WM_NCPAINT, sent|wparam|optional, 1 },
750 { WM_ERASEBKGND, sent|optional },
751 { WM_WINDOWPOSCHANGED, sent },
752 /* WinNT4.0 sends WM_MOVE */
753 { WM_MOVE, sent|defwinproc|optional },
754 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
755 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
756 { 0 }
757 };
758 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
759 static const struct message WmShowMaxPopupSeq[] = {
760 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
761 { WM_GETMINMAXINFO, sent },
762 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
763 { WM_NCCALCSIZE, sent|wparam, TRUE },
764 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
765 { HCBT_ACTIVATE, hook },
766 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
767 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
768 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
769 { WM_ACTIVATEAPP, sent|wparam, 1 },
770 { WM_NCACTIVATE, sent },
771 { WM_ACTIVATE, sent|wparam, 1 },
772 { HCBT_SETFOCUS, hook },
773 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
774 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
775 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
776 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
777 { WM_GETTEXT, sent|optional },
778 { WM_SYNCPAINT, sent|wparam|optional, 4 },
779 { WM_NCPAINT, sent|wparam|optional, 1 },
780 { WM_ERASEBKGND, sent|optional },
781 { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
782 { WM_ERASEBKGND, sent|defwinproc|optional },
783 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
784 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
785 { 0 }
786 };
787 /* CreateWindow(WS_VISIBLE) for popup window */
788 static const struct message WmCreatePopupSeq[] = {
789 { HCBT_CREATEWND, hook },
790 { WM_NCCREATE, sent },
791 { WM_NCCALCSIZE, sent|wparam, 0 },
792 { WM_CREATE, sent },
793 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
794 { WM_SIZE, sent|wparam, SIZE_RESTORED },
795 { WM_MOVE, sent },
796 { WM_SHOWWINDOW, sent|wparam, 1 },
797 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
798 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
799 { HCBT_ACTIVATE, hook },
800 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
801 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
802 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
803 { WM_NCPAINT, sent|wparam|optional, 1 },
804 { WM_ERASEBKGND, sent|optional },
805 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
806 { WM_ACTIVATEAPP, sent|wparam, 1 },
807 { WM_NCACTIVATE, sent },
808 { WM_ACTIVATE, sent|wparam, 1 },
809 { HCBT_SETFOCUS, hook },
810 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
811 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
812 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
813 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
814 { WM_GETTEXT, sent|optional },
815 { WM_SYNCPAINT, sent|wparam|optional, 4 },
816 { WM_NCPAINT, sent|wparam|optional, 1 },
817 { WM_ERASEBKGND, sent|optional },
818 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
819 { 0 }
820 };
821 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
822 static const struct message WmShowVisMaxPopupSeq[] = {
823 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
824 { WM_GETMINMAXINFO, sent },
825 { WM_GETTEXT, sent|optional },
826 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
827 { WM_GETTEXT, sent|optional },
828 { WM_NCCALCSIZE, sent|wparam, TRUE },
829 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
830 { WM_NCPAINT, sent|wparam|optional, 1 },
831 { WM_ERASEBKGND, sent|optional },
832 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
833 { WM_MOVE, sent|defwinproc },
834 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
835 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
836 { 0 }
837 };
838 /* CreateWindow (for a child popup window, not initially visible) */
839 static const struct message WmCreateChildPopupSeq[] = {
840 { HCBT_CREATEWND, hook },
841 { WM_NCCREATE, sent },
842 { WM_NCCALCSIZE, sent|wparam, 0 },
843 { WM_CREATE, sent },
844 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
845 { WM_SIZE, sent|wparam, SIZE_RESTORED },
846 { WM_MOVE, sent },
847 { 0 }
848 };
849 /* CreateWindow (for a popup window, not initially visible,
850 * which sets WS_VISIBLE in WM_CREATE handler)
851 */
852 static const struct message WmCreateInvisiblePopupSeq[] = {
853 { HCBT_CREATEWND, hook },
854 { WM_NCCREATE, sent },
855 { WM_NCCALCSIZE, sent|wparam, 0 },
856 { WM_CREATE, sent },
857 { WM_STYLECHANGING, sent },
858 { WM_STYLECHANGED, sent },
859 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
860 { WM_SIZE, sent|wparam, SIZE_RESTORED },
861 { WM_MOVE, sent },
862 { 0 }
863 };
864 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
865 * for a popup window with WS_VISIBLE style set
866 */
867 static const struct message WmShowVisiblePopupSeq_2[] = {
868 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
869 { 0 }
870 };
871 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
872 * for a popup window with WS_VISIBLE style set
873 */
874 static const struct message WmShowVisiblePopupSeq_3[] = {
875 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
876 { HCBT_ACTIVATE, hook },
877 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
878 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
879 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
880 { WM_NCACTIVATE, sent },
881 { WM_ACTIVATE, sent|wparam, 1 },
882 { HCBT_SETFOCUS, hook },
883 { WM_KILLFOCUS, sent|parent },
884 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
885 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
886 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
887 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
888 { WM_SETFOCUS, sent|defwinproc },
889 { WM_GETTEXT, sent|optional },
890 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_SHOWWINDOW },
891 { 0 }
892 };
893 /* CreateWindow (for child window, not initially visible) */
894 static const struct message WmCreateChildSeq[] = {
895 { HCBT_CREATEWND, hook },
896 { WM_NCCREATE, sent },
897 /* child is inserted into parent's child list after WM_NCCREATE returns */
898 { WM_NCCALCSIZE, sent|wparam, 0 },
899 { WM_CREATE, sent },
900 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
901 { WM_SIZE, sent|wparam, SIZE_RESTORED },
902 { WM_MOVE, sent },
903 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
904 { 0 }
905 };
906 /* CreateWindow (for maximized child window, not initially visible) */
907 static const struct message WmCreateMaximizedChildSeq[] = {
908 { HCBT_CREATEWND, hook },
909 { WM_NCCREATE, sent },
910 { WM_NCCALCSIZE, sent|wparam, 0 },
911 { WM_CREATE, sent },
912 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
913 { WM_SIZE, sent|wparam, SIZE_RESTORED },
914 { WM_MOVE, sent },
915 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
916 { WM_GETMINMAXINFO, sent },
917 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
918 { WM_NCCALCSIZE, sent|wparam, 1 },
919 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
920 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
921 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
922 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
923 { 0 }
924 };
925 /* CreateWindow (for a child window, initially visible) */
926 static const struct message WmCreateVisibleChildSeq[] = {
927 { HCBT_CREATEWND, hook },
928 { WM_NCCREATE, sent },
929 /* child is inserted into parent's child list after WM_NCCREATE returns */
930 { WM_NCCALCSIZE, sent|wparam, 0 },
931 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
932 { WM_CREATE, sent },
933 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
934 { WM_SIZE, sent|wparam, SIZE_RESTORED },
935 { WM_MOVE, sent },
936 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
937 { WM_SHOWWINDOW, sent|wparam, 1 },
938 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
939 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
940 { WM_ERASEBKGND, sent|parent|optional },
941 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
942 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
943 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
944 { 0 }
945 };
946 /* ShowWindow(SW_SHOW) for a not visible child window */
947 static const struct message WmShowChildSeq[] = {
948 { WM_SHOWWINDOW, sent|wparam, 1 },
949 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
950 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
951 { WM_ERASEBKGND, sent|parent|optional },
952 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
953 { 0 }
954 };
955 /* ShowWindow(SW_HIDE) for a visible child window */
956 static const struct message WmHideChildSeq[] = {
957 { WM_SHOWWINDOW, sent|wparam, 0 },
958 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
959 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
960 { WM_ERASEBKGND, sent|parent|optional },
961 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
962 { 0 }
963 };
964 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
965 static const struct message WmHideChildSeq2[] = {
966 { WM_SHOWWINDOW, sent|wparam, 0 },
967 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
968 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
969 { WM_ERASEBKGND, sent|parent|optional },
970 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
971 { 0 }
972 };
973 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
974 * for a not visible child window
975 */
976 static const struct message WmShowChildSeq_2[] = {
977 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
978 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
979 { WM_CHILDACTIVATE, sent },
980 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
981 { 0 }
982 };
983 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
984 * for a not visible child window
985 */
986 static const struct message WmShowChildSeq_3[] = {
987 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
988 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
989 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
990 { 0 }
991 };
992 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
993 * for a visible child window with a caption
994 */
995 static const struct message WmShowChildSeq_4[] = {
996 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
997 { WM_CHILDACTIVATE, sent },
998 { 0 }
999 };
1000 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
1001 static const struct message WmShowChildInvisibleParentSeq_1[] = {
1002 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
1003 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
1004 { WM_NCCALCSIZE, sent|wparam, 1 },
1005 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1006 { WM_CHILDACTIVATE, sent|optional },
1007 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
1008 { WM_MOVE, sent|defwinproc },
1009 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1010 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1011 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1012 /* FIXME: Wine creates an icon/title window while Windows doesn't */
1013 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1014 { WM_GETTEXT, sent|optional },
1015 { 0 }
1016 };
1017 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
1018 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
1019 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
1020 { 0 }
1021 };
1022 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1023 static const struct message WmShowChildInvisibleParentSeq_2[] = {
1024 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1025 { WM_GETMINMAXINFO, sent },
1026 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
1027 { WM_NCCALCSIZE, sent|wparam, 1 },
1028 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1029 { WM_CHILDACTIVATE, sent },
1030 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
1031 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
1032 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1033 { 0 }
1034 };
1035 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1036 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
1037 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1038 { 0 }
1039 };
1040 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1041 static const struct message WmShowChildInvisibleParentSeq_3[] = {
1042 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1043 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
1044 { WM_NCCALCSIZE, sent|wparam, 1 },
1045 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1046 { WM_CHILDACTIVATE, sent },
1047 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1048 { WM_MOVE, sent|defwinproc },
1049 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1050 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1051 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1052 /* FIXME: Wine creates an icon/title window while Windows doesn't */
1053 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1054 { WM_GETTEXT, sent|optional },
1055 { 0 }
1056 };
1057 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1058 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
1059 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1060 { 0 }
1061 };
1062 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1063 static const struct message WmShowChildInvisibleParentSeq_4[] = {
1064 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1065 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
1066 { WM_NCCALCSIZE, sent|wparam, 1 },
1067 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1068 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1069 { WM_MOVE, sent|defwinproc },
1070 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1071 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1072 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1073 /* FIXME: Wine creates an icon/title window while Windows doesn't */
1074 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1075 { WM_GETTEXT, sent|optional },
1076 { 0 }
1077 };
1078 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1079 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
1080 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1081 { 0 }
1082 };
1083 /* ShowWindow(SW_SHOW) for child with invisible parent */
1084 static const struct message WmShowChildInvisibleParentSeq_5[] = {
1085 { WM_SHOWWINDOW, sent|wparam, 1 },
1086 { 0 }
1087 };
1088 /* ShowWindow(SW_HIDE) for child with invisible parent */
1089 static const struct message WmHideChildInvisibleParentSeq[] = {
1090 { WM_SHOWWINDOW, sent|wparam, 0 },
1091 { 0 }
1092 };
1093 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
1094 static const struct message WmShowChildInvisibleParentSeq_6[] = {
1095 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1096 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1097 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1098 { 0 }
1099 };
1100 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
1101 static const struct message WmHideChildInvisibleParentSeq_2[] = {
1102 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1103 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1104 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1105 { 0 }
1106 };
1107 /* DestroyWindow for a visible child window */
1108 static const struct message WmDestroyChildSeq[] = {
1109 { HCBT_DESTROYWND, hook },
1110 { 0x0090, sent|optional },
1111 { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1112 { WM_SHOWWINDOW, sent|wparam, 0 },
1113 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1114 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1115 { WM_ERASEBKGND, sent|parent|optional },
1116 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1117 { HCBT_SETFOCUS, hook }, /* set focus to a parent */
1118 { WM_KILLFOCUS, sent },
1119 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1120 { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
1121 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1122 { WM_SETFOCUS, sent|parent },
1123 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1124 { WM_DESTROY, sent },
1125 { WM_DESTROY, sent|optional }, /* some other (IME?) window */
1126 { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
1127 { WM_NCDESTROY, sent },
1128 { 0 }
1129 };
1130 /* visible child window destroyed by thread exit */
1131 static const struct message WmExitThreadSeq[] = {
1132 { WM_NCDESTROY, sent }, /* actually in grandchild */
1133 { WM_PAINT, sent|parent },
1134 { WM_ERASEBKGND, sent|parent|beginpaint },
1135 { 0 }
1136 };
1137 /* DestroyWindow for a visible child window with invisible parent */
1138 static const struct message WmDestroyInvisibleChildSeq[] = {
1139 { HCBT_DESTROYWND, hook },
1140 { 0x0090, sent|optional },
1141 { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1142 { WM_SHOWWINDOW, sent|wparam, 0 },
1143 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1144 { WM_DESTROY, sent },
1145 { WM_NCDESTROY, sent },
1146 { 0 }
1147 };
1148 /* Moving the mouse in nonclient area */
1149 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
1150 { WM_NCHITTEST, sent },
1151 { WM_SETCURSOR, sent },
1152 { WM_NCMOUSEMOVE, posted },
1153 { 0 }
1154 };
1155 /* Moving the mouse in client area */
1156 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
1157 { WM_NCHITTEST, sent },
1158 { WM_SETCURSOR, sent },
1159 { WM_MOUSEMOVE, posted },
1160 { 0 }
1161 };
1162 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1163 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
1164 { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
1165 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
1166 { WM_GETMINMAXINFO, sent|defwinproc },
1167 { WM_ENTERSIZEMOVE, sent|defwinproc },
1168 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1169 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1170 { WM_MOVE, sent|defwinproc },
1171 { WM_EXITSIZEMOVE, sent|defwinproc },
1172 { 0 }
1173 };
1174 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1175 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
1176 { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
1177 { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
1178 { WM_GETMINMAXINFO, sent|defwinproc },
1179 { WM_ENTERSIZEMOVE, sent|defwinproc },
1180 { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
1181 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1182 { WM_GETMINMAXINFO, sent|defwinproc },
1183 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1184 { WM_NCPAINT, sent|defwinproc|wparam, 1 },
1185 { WM_GETTEXT, sent|defwinproc },
1186 { WM_ERASEBKGND, sent|defwinproc },
1187 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1188 { WM_MOVE, sent|defwinproc },
1189 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1190 { WM_EXITSIZEMOVE, sent|defwinproc },
1191 { 0 }
1192 };
1193 /* Resizing child window with MoveWindow (32) */
1194 static const struct message WmResizingChildWithMoveWindowSeq[] = {
1195 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1196 { WM_NCCALCSIZE, sent|wparam, 1 },
1197 { WM_ERASEBKGND, sent|parent|optional },
1198 { WM_ERASEBKGND, sent|optional },
1199 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
1200 { WM_MOVE, sent|defwinproc },
1201 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1202 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1203 { 0 }
1204 };
1205 /* Clicking on inactive button */
1206 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
1207 { WM_NCHITTEST, sent },
1208 { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
1209 { WM_MOUSEACTIVATE, sent },
1210 { WM_MOUSEACTIVATE, sent|parent|defwinproc },
1211 { WM_SETCURSOR, sent },
1212 { WM_SETCURSOR, sent|parent|defwinproc },
1213 { WM_LBUTTONDOWN, posted },
1214 { WM_KILLFOCUS, posted|parent },
1215 { WM_SETFOCUS, posted },
1216 { WM_CTLCOLORBTN, posted|parent },
1217 { BM_SETSTATE, posted },
1218 { WM_CTLCOLORBTN, posted|parent },
1219 { WM_LBUTTONUP, posted },
1220 { BM_SETSTATE, posted },
1221 { WM_CTLCOLORBTN, posted|parent },
1222 { WM_COMMAND, posted|parent },
1223 { 0 }
1224 };
1225 /* Reparenting a button (16/32) */
1226 /* The last child (button) reparented gets topmost for its new parent. */
1227 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
1228 { WM_SHOWWINDOW, sent|wparam, 0 },
1229 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1230 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1231 { WM_ERASEBKGND, sent|parent },
1232 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1233 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
1234 { WM_CHILDACTIVATE, sent },
1235 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
1236 { WM_MOVE, sent|defwinproc },
1237 { WM_SHOWWINDOW, sent|wparam, 1 },
1238 { 0 }
1239 };
1240 /* Creation of a custom dialog (32) */
1241 static const struct message WmCreateCustomDialogSeq[] = {
1242 { HCBT_CREATEWND, hook },
1243 { WM_GETMINMAXINFO, sent },
1244 { WM_NCCREATE, sent },
1245 { WM_NCCALCSIZE, sent|wparam, 0 },
1246 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1247 { WM_CREATE, sent },
1248 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1249 { WM_NOTIFYFORMAT, sent|optional },
1250 { WM_QUERYUISTATE, sent|optional },
1251 { WM_WINDOWPOSCHANGING, sent|optional },
1252 { WM_GETMINMAXINFO, sent|optional },
1253 { WM_NCCALCSIZE, sent|optional },
1254 { WM_WINDOWPOSCHANGED, sent|optional },
1255 { WM_SHOWWINDOW, sent|wparam, 1 },
1256 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1257 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1258 { HCBT_ACTIVATE, hook },
1259 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1260
1261
1262 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1263
1264 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1265
1266 { WM_NCACTIVATE, sent },
1267 { WM_GETTEXT, sent|optional|defwinproc },
1268 { WM_GETTEXT, sent|optional|defwinproc },
1269 { WM_GETTEXT, sent|optional|defwinproc },
1270 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1271 { WM_ACTIVATE, sent|wparam, 1 },
1272 { WM_GETTEXT, sent|optional },
1273 { WM_KILLFOCUS, sent|parent },
1274 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1275 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1276 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1277 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1278 { WM_SETFOCUS, sent },
1279 { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1280 { WM_NCPAINT, sent|wparam, 1 },
1281 { WM_GETTEXT, sent|optional|defwinproc },
1282 { WM_GETTEXT, sent|optional|defwinproc },
1283 { WM_ERASEBKGND, sent },
1284 { WM_CTLCOLORDLG, sent|optional|defwinproc },
1285 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1286 { WM_GETTEXT, sent|optional },
1287 { WM_GETTEXT, sent|optional },
1288 { WM_NCCALCSIZE, sent|optional },
1289 { WM_NCPAINT, sent|optional },
1290 { WM_GETTEXT, sent|optional|defwinproc },
1291 { WM_GETTEXT, sent|optional|defwinproc },
1292 { WM_ERASEBKGND, sent|optional },
1293 { WM_CTLCOLORDLG, sent|optional|defwinproc },
1294 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1295 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1296 { WM_MOVE, sent },
1297 { 0 }
1298 };
1299 /* Calling EndDialog for a custom dialog (32) */
1300 static const struct message WmEndCustomDialogSeq[] = {
1301 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1302 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1303 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1304 { WM_GETTEXT, sent|optional },
1305 { HCBT_ACTIVATE, hook },
1306 { WM_NCACTIVATE, sent|wparam, 0 },
1307 { WM_GETTEXT, sent|optional|defwinproc },
1308 { WM_GETTEXT, sent|optional|defwinproc },
1309 { WM_ACTIVATE, sent|wparam, 0 },
1310 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1311 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1312 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1313 { WM_GETTEXT, sent|optional|defwinproc },
1314 { WM_GETTEXT, sent|optional|defwinproc },
1315 { HCBT_SETFOCUS, hook },
1316 { WM_KILLFOCUS, sent },
1317 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1318 { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1319 { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1320 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1321 { WM_SETFOCUS, sent|parent|defwinproc },
1322 { 0 }
1323 };
1324 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1325 static const struct message WmShowCustomDialogSeq[] = {
1326 { WM_SHOWWINDOW, sent|wparam, 1 },
1327 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1328 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1329 { HCBT_ACTIVATE, hook },
1330 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1331
1332 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1333
1334 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1335 { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1336 { WM_NCACTIVATE, sent },
1337 { WM_ACTIVATE, sent|wparam, 1 },
1338 { WM_GETTEXT, sent|optional },
1339
1340 { WM_KILLFOCUS, sent|parent },
1341 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1342 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1343 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1344 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1345 { WM_SETFOCUS, sent },
1346 { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1347 { WM_NCPAINT, sent|wparam, 1 },
1348 { WM_ERASEBKGND, sent },
1349 { WM_CTLCOLORDLG, sent|defwinproc },
1350 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1351 { 0 }
1352 };
1353 /* Creation and destruction of a modal dialog (32) */
1354 static const struct message WmModalDialogSeq[] = {
1355 { WM_CANCELMODE, sent|parent },
1356 { HCBT_SETFOCUS, hook },
1357 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1358 { WM_KILLFOCUS, sent|parent },
1359 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1360 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1361 { WM_ENABLE, sent|parent|wparam, 0 },
1362 { HCBT_CREATEWND, hook },
1363 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1364 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1365 { WM_SETFONT, sent },
1366 { WM_INITDIALOG, sent },
1367 { WM_CHANGEUISTATE, sent|optional },
1368 { WM_UPDATEUISTATE, sent|optional },
1369 { WM_SHOWWINDOW, sent },
1370 { HCBT_ACTIVATE, hook },
1371 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1372 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1373 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1374 { WM_NCACTIVATE, sent },
1375 { WM_GETTEXT, sent|optional },
1376 { WM_ACTIVATE, sent|wparam, 1 },
1377 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1378 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1379 { WM_NCPAINT, sent|optional },
1380 { WM_GETTEXT, sent|optional },
1381 { WM_ERASEBKGND, sent|optional },
1382 { WM_CTLCOLORDLG, sent|optional },
1383 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1384 { WM_GETTEXT, sent|optional },
1385 { WM_NCCALCSIZE, sent|optional },
1386 { WM_NCPAINT, sent|optional },
1387 { WM_GETTEXT, sent|optional },
1388 { WM_ERASEBKGND, sent|optional },
1389 { WM_CTLCOLORDLG, sent|optional },
1390 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1391 { WM_PAINT, sent|optional },
1392 { WM_CTLCOLORBTN, sent|optional },
1393 { WM_GETTITLEBARINFOEX, sent|optional },
1394 { WM_ENTERIDLE, sent|parent|optional },
1395 { WM_ENTERIDLE, sent|parent|optional },
1396 { WM_ENTERIDLE, sent|parent|optional },
1397 { WM_ENTERIDLE, sent|parent|optional },
1398 { WM_ENTERIDLE, sent|parent|optional },
1399 { WM_ENTERIDLE, sent|parent|optional },
1400 { WM_ENTERIDLE, sent|parent|optional },
1401 { WM_ENTERIDLE, sent|parent|optional },
1402 { WM_ENTERIDLE, sent|parent|optional },
1403 { WM_ENTERIDLE, sent|parent|optional },
1404 { WM_ENTERIDLE, sent|parent|optional },
1405 { WM_ENTERIDLE, sent|parent|optional },
1406 { WM_ENTERIDLE, sent|parent|optional },
1407 { WM_ENTERIDLE, sent|parent|optional },
1408 { WM_ENTERIDLE, sent|parent|optional },
1409 { WM_ENTERIDLE, sent|parent|optional },
1410 { WM_ENTERIDLE, sent|parent|optional },
1411 { WM_ENTERIDLE, sent|parent|optional },
1412 { WM_ENTERIDLE, sent|parent|optional },
1413 { WM_ENTERIDLE, sent|parent|optional },
1414 { WM_TIMER, sent },
1415 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1416 { WM_ENABLE, sent|parent|wparam, 1 },
1417 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1418 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1419 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1420 { WM_GETTEXT, sent|optional },
1421 { HCBT_ACTIVATE, hook },
1422 { WM_NCACTIVATE, sent|wparam, 0 },
1423 { WM_GETTEXT, sent|optional },
1424 { WM_ACTIVATE, sent|wparam, 0 },
1425 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1426 { WM_WINDOWPOSCHANGING, sent|optional },
1427 { WM_WINDOWPOSCHANGED, sent|optional },
1428 { HCBT_SETFOCUS, hook },
1429 { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1430 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1431 { WM_SETFOCUS, sent|parent|defwinproc },
1432 { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1433 { HCBT_DESTROYWND, hook },
1434 { 0x0090, sent|optional },
1435 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1436 { WM_DESTROY, sent },
1437 { WM_NCDESTROY, sent },
1438 { 0 }
1439 };
1440 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1441 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1442 /* (inside dialog proc, handling WM_INITDIALOG) */
1443 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1444 { WM_NCCALCSIZE, sent },
1445 { WM_NCACTIVATE, sent|parent|wparam, 0 },
1446 { WM_GETTEXT, sent|defwinproc },
1447 { WM_ACTIVATE, sent|parent|wparam, 0 },
1448 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1449 { WM_WINDOWPOSCHANGING, sent|parent },
1450 { WM_NCACTIVATE, sent|wparam, 1 },
1451 { WM_ACTIVATE, sent|wparam, 1 },
1452 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1453 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1454 /* (setting focus) */
1455 { WM_SHOWWINDOW, sent|wparam, 1 },
1456 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1457 { WM_NCPAINT, sent },
1458 { WM_GETTEXT, sent|defwinproc },
1459 { WM_ERASEBKGND, sent },
1460 { WM_CTLCOLORDLG, sent|defwinproc },
1461 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1462 { WM_PAINT, sent },
1463 /* (bunch of WM_CTLCOLOR* for each control) */
1464 { WM_PAINT, sent|parent },
1465 { WM_ENTERIDLE, sent|parent|wparam, 0 },
1466 { WM_SETCURSOR, sent|parent },
1467 { 0 }
1468 };
1469 /* SetMenu for NonVisible windows with size change*/
1470 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1471 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1472 { WM_NCCALCSIZE, sent|wparam, 1 },
1473 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1474 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1475 { WM_MOVE, sent|defwinproc },
1476 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1477 { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1478 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1479 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1480 { WM_GETTEXT, sent|optional },
1481 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1482 { 0 }
1483 };
1484 /* SetMenu for NonVisible windows with no size change */
1485 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1486 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1487 { WM_NCCALCSIZE, sent|wparam, 1 },
1488 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1489 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1490 { 0 }
1491 };
1492 /* SetMenu for Visible windows with size change */
1493 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1494 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1495 { WM_NCCALCSIZE, sent|wparam, 1 },
1496 { 0x0093, sent|defwinproc|optional },
1497 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1498 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1499 { 0x0093, sent|defwinproc|optional },
1500 { 0x0093, sent|defwinproc|optional },
1501 { 0x0091, sent|defwinproc|optional },
1502 { 0x0092, sent|defwinproc|optional },
1503 { WM_GETTEXT, sent|defwinproc|optional },
1504 { WM_ERASEBKGND, sent|optional },
1505 { WM_ACTIVATE, sent|optional },
1506 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1507 { WM_MOVE, sent|defwinproc },
1508 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1509 { 0x0093, sent|optional },
1510 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1511 { 0x0093, sent|defwinproc|optional },
1512 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1513 { 0x0093, sent|defwinproc|optional },
1514 { 0x0093, sent|defwinproc|optional },
1515 { 0x0091, sent|defwinproc|optional },
1516 { 0x0092, sent|defwinproc|optional },
1517 { WM_ERASEBKGND, sent|optional },
1518 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1519 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1520 { 0 }
1521 };
1522 /* SetMenu for Visible windows with no size change */
1523 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1524 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1525 { WM_NCCALCSIZE, sent|wparam, 1 },
1526 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1527 { WM_GETTEXT, sent|defwinproc|optional },
1528 { WM_ERASEBKGND, sent|optional },
1529 { WM_ACTIVATE, sent|optional },
1530 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1531 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1532 { 0 }
1533 };
1534 /* DrawMenuBar for a visible window */
1535 static const struct message WmDrawMenuBarSeq[] =
1536 {
1537 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1538 { WM_NCCALCSIZE, sent|wparam, 1 },
1539 { 0x0093, sent|defwinproc|optional },
1540 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1541 { 0x0093, sent|defwinproc|optional },
1542 { 0x0093, sent|defwinproc|optional },
1543 { 0x0091, sent|defwinproc|optional },
1544 { 0x0092, sent|defwinproc|optional },
1545 { WM_GETTEXT, sent|defwinproc|optional },
1546 { WM_ERASEBKGND, sent|optional },
1547 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1548 { 0x0093, sent|optional },
1549 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1550 { 0 }
1551 };
1552
1553 static const struct message WmSetRedrawFalseSeq[] =
1554 {
1555 { WM_SETREDRAW, sent|wparam, 0 },
1556 { 0 }
1557 };
1558
1559 static const struct message WmSetRedrawTrueSeq[] =
1560 {
1561 { WM_SETREDRAW, sent|wparam, 1 },
1562 { 0 }
1563 };
1564
1565 static const struct message WmEnableWindowSeq_1[] =
1566 {
1567 { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1568 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1569 { HCBT_SETFOCUS, hook|optional },
1570 { WM_KILLFOCUS, sent|optional },
1571 { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1572 { 0 }
1573 };
1574
1575 static const struct message WmEnableWindowSeq_2[] =
1576 {
1577 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1578 { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1579 { 0 }
1580 };
1581
1582 static const struct message WmGetScrollRangeSeq[] =
1583 {
1584 { SBM_GETRANGE, sent },
1585 { 0 }
1586 };
1587 static const struct message WmGetScrollInfoSeq[] =
1588 {
1589 { SBM_GETSCROLLINFO, sent },
1590 { 0 }
1591 };
1592 static const struct message WmSetScrollRangeSeq[] =
1593 {
1594 /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1595 sends SBM_SETSCROLLINFO.
1596 */
1597 { SBM_SETSCROLLINFO, sent },
1598 { 0 }
1599 };
1600 /* SetScrollRange for a window without a non-client area */
1601 static const struct message WmSetScrollRangeHSeq_empty[] =
1602 {
1603 { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1604 { 0 }
1605 };
1606 static const struct message WmSetScrollRangeVSeq_empty[] =
1607 {
1608 { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1609 { 0 }
1610 };
1611 static const struct message WmSetScrollRangeHVSeq[] =
1612 {
1613 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1614 { WM_NCCALCSIZE, sent|wparam, 1 },
1615 { WM_GETTEXT, sent|defwinproc|optional },
1616 { WM_ERASEBKGND, sent|optional },
1617 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1618 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1619 { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1620 { 0 }
1621 };
1622 /* SetScrollRange for a window with a non-client area */
1623 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1624 {
1625 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1626 { WM_NCCALCSIZE, sent|wparam, 1 },
1627 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1628 { WM_NCPAINT, sent|optional },
1629 { WM_STYLECHANGING, sent|defwinproc|optional },
1630 { WM_STYLECHANGED, sent|defwinproc|optional },
1631 { WM_STYLECHANGING, sent|defwinproc|optional },
1632 { WM_STYLECHANGED, sent|defwinproc|optional },
1633 { WM_STYLECHANGING, sent|defwinproc|optional },
1634 { WM_STYLECHANGED, sent|defwinproc|optional },
1635 { WM_STYLECHANGING, sent|defwinproc|optional },
1636 { WM_STYLECHANGED, sent|defwinproc|optional },
1637 { WM_GETTEXT, sent|defwinproc|optional },
1638 { WM_GETTEXT, sent|defwinproc|optional },
1639 { WM_ERASEBKGND, sent|optional },
1640 { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1641 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOCLIENTSIZE },
1642 { WM_SIZE, sent|defwinproc|optional },
1643 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1644 { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1645 { WM_GETTEXT, sent|optional },
1646 { WM_GETTEXT, sent|optional },
1647 { WM_GETTEXT, sent|optional },
1648 { WM_GETTEXT, sent|optional },
1649 { 0 }
1650 };
1651 /* test if we receive the right sequence of messages */
1652 /* after calling ShowWindow( SW_SHOWNA) */
1653 static const struct message WmSHOWNAChildInvisParInvis[] = {
1654 { WM_SHOWWINDOW, sent|wparam, 1 },
1655 { 0 }
1656 };
1657 static const struct message WmSHOWNAChildVisParInvis[] = {
1658 { WM_SHOWWINDOW, sent|wparam, 1 },
1659 { 0 }
1660 };
1661 static const struct message WmSHOWNAChildVisParVis[] = {
1662 { WM_SHOWWINDOW, sent|wparam, 1 },
1663 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1664 { 0 }
1665 };
1666 static const struct message WmSHOWNAChildInvisParVis[] = {
1667 { WM_SHOWWINDOW, sent|wparam, 1 },
1668 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1669 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1670 { WM_ERASEBKGND, sent|optional },
1671 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1672 { 0 }
1673 };
1674 static const struct message WmSHOWNATopVisible[] = {
1675 { WM_SHOWWINDOW, sent|wparam, 1 },
1676 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1677 { WM_NCPAINT, sent|wparam|optional, 1 },
1678 { WM_GETTEXT, sent|defwinproc|optional },
1679 { WM_ERASEBKGND, sent|optional },
1680 { WM_WINDOWPOSCHANGED, sent|optional },
1681 { 0 }
1682 };
1683 static const struct message WmSHOWNATopInvisible[] = {
1684 { WM_NOTIFYFORMAT, sent|optional },
1685 { WM_QUERYUISTATE, sent|optional },
1686 { WM_WINDOWPOSCHANGING, sent|optional },
1687 { WM_GETMINMAXINFO, sent|optional },
1688 { WM_NCCALCSIZE, sent|optional },
1689 { WM_WINDOWPOSCHANGED, sent|optional },
1690 { WM_SHOWWINDOW, sent|wparam, 1 },
1691 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1692 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1693 { WM_NCPAINT, sent|wparam|optional, 1 },
1694 { WM_GETTEXT, sent|defwinproc|optional },
1695 { WM_ERASEBKGND, sent|optional },
1696 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1697 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1698 { WM_NCPAINT, sent|wparam|optional, 1 },
1699 { WM_ERASEBKGND, sent|optional },
1700 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1701 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1702 { WM_MOVE, sent },
1703 { 0 }
1704 };
1705
1706 static int after_end_dialog, test_def_id;
1707 static int sequence_cnt, sequence_size;
1708 static struct recvd_message* sequence;
1709 static int log_all_parent_messages;
1710 static int paint_loop_done;
1711
1712 /* user32 functions */
1713 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1714 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
1715 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1716 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
1717 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1718 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1719 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1720 /* kernel32 functions */
1721 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1722
1723 static void init_procs(void)
1724 {
1725 HMODULE user32 = GetModuleHandleA("user32.dll");
1726 HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1727
1728 #define GET_PROC(dll, func) \
1729 p ## func = (void*)GetProcAddress(dll, #func); \
1730 if(!p ## func) { \
1731 trace("GetProcAddress(%s) failed\n", #func); \
1732 }
1733
1734 GET_PROC(user32, GetAncestor)
1735 GET_PROC(user32, GetMenuInfo)
1736 GET_PROC(user32, NotifyWinEvent)
1737 GET_PROC(user32, SetMenuInfo)
1738 GET_PROC(user32, SetWinEventHook)
1739 GET_PROC(user32, TrackMouseEvent)
1740 GET_PROC(user32, UnhookWinEvent)
1741
1742 GET_PROC(kernel32, GetCPInfoExA)
1743
1744 #undef GET_PROC
1745 }
1746
1747 static const char *get_winpos_flags(UINT flags)
1748 {
1749 static char buffer[300];
1750
1751 buffer[0] = 0;
1752 #define DUMP(flag) do { if (flags & flag) { strcat( buffer, "|" #flag ); flags &= ~flag; } } while(0)
1753 DUMP( SWP_SHOWWINDOW );
1754 DUMP( SWP_HIDEWINDOW );
1755 DUMP( SWP_NOACTIVATE );
1756 DUMP( SWP_FRAMECHANGED );
1757 DUMP( SWP_NOCOPYBITS );
1758 DUMP( SWP_NOOWNERZORDER );
1759 DUMP( SWP_NOSENDCHANGING );
1760 DUMP( SWP_DEFERERASE );
1761 DUMP( SWP_ASYNCWINDOWPOS );
1762 DUMP( SWP_NOZORDER );
1763 DUMP( SWP_NOREDRAW );
1764 DUMP( SWP_NOSIZE );
1765 DUMP( SWP_NOMOVE );
1766 DUMP( SWP_NOCLIENTSIZE );
1767 DUMP( SWP_NOCLIENTMOVE );
1768 if (flags) sprintf(buffer + strlen(buffer),"|0x%04x", flags);
1769 return buffer + 1;
1770 #undef DUMP
1771 }
1772
1773 static BOOL ignore_message( UINT message )
1774 {
1775 /* these are always ignored */
1776 return (message >= 0xc000 ||
1777 message == WM_GETICON ||
1778 message == WM_GETOBJECT ||
1779 message == WM_TIMECHANGE ||
1780 message == WM_DISPLAYCHANGE ||
1781 message == WM_DEVICECHANGE ||
1782 message == WM_DWMNCRENDERINGCHANGED);
1783 }
1784
1785
1786 #define add_message(msg) add_message_(__LINE__,msg);
1787 static void add_message_(int line, const struct recvd_message *msg)
1788 {
1789 struct recvd_message *seq;
1790
1791 if (!sequence)
1792 {
1793 sequence_size = 10;
1794 sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof(*sequence) );
1795 }
1796 if (sequence_cnt == sequence_size)
1797 {
1798 sequence_size *= 2;
1799 sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof(*sequence) );
1800 }
1801 assert(sequence);
1802
1803 seq = &sequence[sequence_cnt];
1804 seq->hwnd = msg->hwnd;
1805 seq->message = msg->message;
1806 seq->flags = msg->flags;
1807 seq->wParam = msg->wParam;
1808 seq->lParam = msg->lParam;
1809 seq->line = line;
1810 seq->descr = msg->descr;
1811 seq->output[0] = 0;
1812
1813 if (msg->descr)
1814 {
1815 if (msg->flags & hook)
1816 {
1817 static const char * const CBT_code_name[10] =
1818 {
1819 "HCBT_MOVESIZE",
1820 "HCBT_MINMAX",
1821 "HCBT_QS",
1822 "HCBT_CREATEWND",
1823 "HCBT_DESTROYWND",
1824 "HCBT_ACTIVATE",
1825 "HCBT_CLICKSKIPPED",
1826 "HCBT_KEYSKIPPED",
1827 "HCBT_SYSCOMMAND",
1828 "HCBT_SETFOCUS"
1829 };
1830 const char *code_name = (msg->message <= HCBT_SETFOCUS) ? CBT_code_name[msg->message] : "Unknown";
1831
1832 sprintf( seq->output, "%s: hook %d (%s) wp %08lx lp %08lx",
1833 msg->descr, msg->message, code_name, msg->wParam, msg->lParam );
1834 }
1835 else if (msg->flags & winevent_hook)
1836 {
1837 sprintf( seq->output, "%s: winevent %p %08x %08lx %08lx",
1838 msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1839 }
1840 else
1841 {
1842 switch (msg->message)
1843 {
1844 case WM_WINDOWPOSCHANGING:
1845 case WM_WINDOWPOSCHANGED:
1846 {
1847 WINDOWPOS *winpos = (WINDOWPOS *)msg->lParam;
1848
1849 sprintf( seq->output, "%s: %p WM_WINDOWPOS%s wp %08lx lp %08lx after %p x %d y %d cx %d cy %d flags %s",
1850 msg->descr, msg->hwnd,
1851 (msg->message == WM_WINDOWPOSCHANGING) ? "CHANGING" : "CHANGED",
1852 msg->wParam, msg->lParam, winpos->hwndInsertAfter,
1853 winpos->x, winpos->y, winpos->cx, winpos->cy,
1854 get_winpos_flags(winpos->flags) );
1855
1856 /* Log only documented flags, win2k uses 0x1000 and 0x2000
1857 * in the high word for internal purposes
1858 */
1859 seq->wParam = winpos->flags & 0xffff;
1860 /* We are not interested in the flags that don't match under XP and Win9x */
1861 seq->wParam &= ~SWP_NOZORDER;
1862 break;
1863 }
1864
1865 case WM_DRAWITEM:
1866 {
1867 DRAW_ITEM_STRUCT di;
1868 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)msg->lParam;
1869
1870 sprintf( seq->output, "%s: %p WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x",
1871 msg->descr, msg->hwnd, dis->CtlType, dis->CtlID,
1872 dis->itemID, dis->itemAction, dis->itemState);
1873
1874 di.u.lp = 0;
1875 di.u.item.type = dis->CtlType;
1876 di.u.item.ctl_id = dis->CtlID;
1877 if (dis->CtlType == ODT_LISTBOX ||
1878 dis->CtlType == ODT_COMBOBOX ||
1879 dis->CtlType == ODT_MENU)
1880 di.u.item.item_id = dis->itemID;
1881 di.u.item.action = dis->itemAction;
1882 di.u.item.state = dis->itemState;
1883
1884 seq->lParam = di.u.lp;
1885 break;
1886 }
1887 default:
1888 if (msg->message >= 0xc000) return; /* ignore registered messages */
1889 sprintf( seq->output, "%s: %p %04x wp %08lx lp %08lx",
1890 msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1891 }
1892 if (msg->flags & (sent|posted|parent|defwinproc|beginpaint))
1893 sprintf( seq->output + strlen(seq->output), " (flags %x)", msg->flags );
1894 }
1895 }
1896
1897 sequence_cnt++;
1898 }
1899
1900 /* try to make sure pending X events have been processed before continuing */
1901 static void flush_events(void)
1902 {
1903 MSG msg;
1904 int diff = 200;
1905 int min_timeout = 100;
1906 DWORD time = GetTickCount() + diff;
1907
1908 while (diff > 0)
1909 {
1910 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1911 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1912 diff = time - GetTickCount();
1913 }
1914 }
1915
1916 static void flush_sequence(void)
1917 {
1918 HeapFree(GetProcessHeap(), 0, sequence);
1919 sequence = 0;
1920 sequence_cnt = sequence_size = 0;
1921 }
1922
1923 static void dump_sequence(const struct message *expected, const char *context, const char *file, int line)
1924 {
1925 const struct recvd_message *actual = sequence;
1926 unsigned int count = 0;
1927
1928 trace_(file, line)("Failed sequence %s:\n", context );
1929 while (expected->message && actual->message)
1930 {
1931 if (actual->output[0])
1932 {
1933 if (expected->flags & hook)
1934 {
1935 trace_(file, line)( " %u: expected: hook %04x - actual: %s\n",
1936 count, expected->message, actual->output );
1937 }
1938 else if (expected->flags & winevent_hook)
1939 {
1940 trace_(file, line)( " %u: expected: winevent %04x - actual: %s\n",
1941 count, expected->message, actual->output );
1942 }
1943 else
1944 {
1945 trace_(file, line)( " %u: expected: msg %04x - actual: %s\n",
1946 count, expected->message, actual->output );
1947 }
1948 }
1949
1950 if (expected->message == actual->message)
1951 {
1952 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) &&
1953 (expected->flags & optional))
1954 {
1955 /* don't match messages if their defwinproc status differs */
1956 expected++;
1957 }
1958 else
1959 {
1960 expected++;
1961 actual++;
1962 }
1963 }
1964 /* silently drop winevent messages if there is no support for them */
1965 else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1966 expected++;
1967 else
1968 {
1969 expected++;
1970 actual++;
1971 }
1972 count++;
1973 }
1974
1975 /* optional trailing messages */
1976 while (expected->message && ((expected->flags & optional) ||
1977 ((expected->flags & winevent_hook) && !hEvent_hook)))
1978 {
1979 trace_(file, line)( " %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1980 expected++;
1981 count++;
1982 }
1983
1984 if (expected->message)
1985 {
1986 trace_(file, line)( " %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1987 return;
1988 }
1989
1990 while (actual->message && actual->output[0])
1991 {
1992 trace_(file, line)( " %u: expected: nothing - actual: %s\n", count, actual->output );
1993 actual++;
1994 count++;
1995 }
1996 }
1997
1998 #define ok_sequence( exp, contx, todo) \
1999 ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
2000
2001
2002 static void ok_sequence_(const struct message *expected_list, const char *context, int todo,
2003 const char *file, int line)
2004 {
2005 static const struct recvd_message end_of_sequence;
2006 const struct message *expected = expected_list;
2007 const struct recvd_message *actual;
2008 int failcount = 0, dump = 0;
2009 unsigned int count = 0;
2010
2011 add_message(&end_of_sequence);
2012
2013 actual = sequence;
2014
2015 while (expected->message && actual->message)
2016 {
2017 if (expected->message == actual->message)
2018 {
2019 if (expected->flags & wparam)
2020 {
2021 if (((expected->wParam ^ actual->wParam) & ~expected->wp_mask) && todo)
2022 {
2023 todo_wine {
2024 failcount ++;
2025 if (strcmp(winetest_platform, "wine")) dump++;
2026 ok_( file, line) (FALSE,
2027 "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2028 context, count, expected->message, expected->wParam, actual->wParam);
2029 }
2030 }
2031 else
2032 {
2033 ok_( file, line)( ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) == 0,
2034 "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2035 context, count, expected->message, expected->wParam, actual->wParam);
2036 if ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) dump++;
2037 }
2038
2039 }
2040 if (expected->flags & lparam)
2041 {
2042 if (((expected->lParam ^ actual->lParam) & ~expected->lp_mask) && todo)
2043 {
2044 todo_wine {
2045 failcount ++;
2046 if (strcmp(winetest_platform, "wine")) dump++;
2047 ok_( file, line) (FALSE,
2048 "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2049 context, count, expected->message, expected->lParam, actual->lParam);
2050 }
2051 }
2052 else
2053 {
2054 ok_( file, line)(((expected->lParam ^ actual->lParam) & ~expected->lp_mask) == 0,
2055 "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2056 context, count, expected->message, expected->lParam, actual->lParam);
2057 if ((expected->lParam ^ actual->lParam) & ~expected->lp_mask) dump++;
2058 }
2059 }
2060 if ((expected->flags & optional) &&
2061 ((expected->flags ^ actual->flags) & (defwinproc|parent)))
2062 {
2063 /* don't match optional messages if their defwinproc or parent status differs */
2064 expected++;
2065 count++;
2066 continue;
2067 }
2068 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
2069 {
2070 todo_wine {
2071 failcount ++;
2072 if (strcmp(winetest_platform, "wine")) dump++;
2073 ok_( file, line) (FALSE,
2074 "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2075 context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2076 }
2077 }
2078 else
2079 {
2080 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
2081 "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2082 context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2083 if ((expected->flags & defwinproc) != (actual->flags & defwinproc)) dump++;
2084 }
2085
2086 ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
2087 "%s: %u: the msg 0x%04x should %shave been sent by BeginPaint\n",
2088 context, count, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
2089 if ((expected->flags & beginpaint) != (actual->flags & beginpaint)) dump++;
2090
2091 ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
2092 "%s: %u: the msg 0x%04x should have been %s\n",
2093 context, count, expected->message, (expected->flags & posted) ? "posted" : "sent");
2094 if ((expected->flags & (sent|posted)) != (actual->flags & (sent|posted))) dump++;
2095
2096 ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
2097 "%s: %u: the msg 0x%04x was expected in %s\n",
2098 context, count, expected->message, (expected->flags & parent) ? "parent" : "child");
2099 if ((expected->flags & parent) != (actual->flags & parent)) dump++;
2100
2101 ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
2102 "%s: %u: the msg 0x%04x should have been sent by a hook\n",
2103 context, count, expected->message);
2104 if ((expected->flags & hook) != (actual->flags & hook)) dump++;
2105
2106 ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
2107 "%s: %u: the msg 0x%04x should have been sent by a winevent hook\n",
2108 context, count, expected->message);
2109 if ((expected->flags & winevent_hook) != (actual->flags & winevent_hook)) dump++;
2110
2111 expected++;
2112 actual++;
2113 }
2114 /* silently drop hook messages if there is no support for them */
2115 else if ((expected->flags & optional) ||
2116 ((expected->flags & hook) && !hCBT_hook) ||
2117 ((expected->flags & winevent_hook) && !hEvent_hook))
2118 expected++;
2119 else if (todo)
2120 {
2121 failcount++;
2122 todo_wine {
2123 if (strcmp(winetest_platform, "wine")) dump++;
2124 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2125 context, count, expected->message, actual->message);
2126 }
2127 goto done;
2128 }
2129 else
2130 {
2131 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2132 context, count, expected->message, actual->message);
2133 dump++;
2134 expected++;
2135 actual++;
2136 }
2137 count++;
2138 }
2139
2140 /* skip all optional trailing messages */
2141 while (expected->message && ((expected->flags & optional) ||
2142 ((expected->flags & hook) && !hCBT_hook) ||
2143 ((expected->flags & winevent_hook) && !hEvent_hook)))
2144 expected++;
2145
2146 if (todo)
2147 {
2148 todo_wine {
2149 if (expected->message || actual->message) {
2150 failcount++;
2151 if (strcmp(winetest_platform, "wine")) dump++;
2152 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2153 context, count, expected->message, actual->message);
2154 }
2155 }
2156 }
2157 else
2158 {
2159 if (expected->message || actual->message)
2160 {
2161 dump++;
2162 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2163 context, count, expected->message, actual->message);
2164 }
2165 }
2166 if( todo && !failcount) /* succeeded yet marked todo */
2167 todo_wine {
2168 if (!strcmp(winetest_platform, "wine")) dump++;
2169 ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
2170 }
2171
2172 done:
2173 if (dump) dump_sequence(expected_list, context, file, line);
2174 flush_sequence();
2175 }
2176
2177 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
2178
2179 /******************************** MDI test **********************************/
2180
2181 /* CreateWindow for MDI frame window, initially visible */
2182 static const struct message WmCreateMDIframeSeq[] = {
2183 { HCBT_CREATEWND, hook },
2184 { WM_GETMINMAXINFO, sent },
2185 { WM_NCCREATE, sent },
2186 { WM_NCCALCSIZE, sent|wparam, 0 },
2187 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2188 { WM_CREATE, sent },
2189 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2190 { WM_NOTIFYFORMAT, sent|optional },
2191 { WM_QUERYUISTATE, sent|optional },
2192 { WM_WINDOWPOSCHANGING, sent|optional },
2193 { WM_GETMINMAXINFO, sent|optional },
2194 { WM_NCCALCSIZE, sent|optional },
2195 { WM_WINDOWPOSCHANGED, sent|optional },
2196 { WM_SHOWWINDOW, sent|wparam, 1 },
2197 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2198 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2199 { HCBT_ACTIVATE, hook },
2200 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
2201 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
2202 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
2203 { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
2204 { WM_NCACTIVATE, sent },
2205 { WM_GETTEXT, sent|defwinproc|optional },
2206 { WM_ACTIVATE, sent|wparam, 1 },
2207 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
2208 { HCBT_SETFOCUS, hook },
2209 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2210 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2211 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2212 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
2213 /* Win9x adds SWP_NOZORDER below */
2214 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2215 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2216 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2217 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2218 { WM_MOVE, sent },
2219 { 0 }
2220 };
2221 /* DestroyWindow for MDI frame window, initially visible */
2222 static const struct message WmDestroyMDIframeSeq[] = {
2223 { HCBT_DESTROYWND, hook },
2224 { 0x0090, sent|optional },
2225 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2226 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2227 { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2228 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2229 { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
2230 { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2231 { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
2232 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
2233 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2234 { WM_DESTROY, sent },
2235 { WM_NCDESTROY, sent },
2236 { 0 }
2237 };
2238 /* CreateWindow for MDI client window, initially visible */
2239 static const struct message WmCreateMDIclientSeq[] = {
2240 { HCBT_CREATEWND, hook },
2241 { WM_NCCREATE, sent },
2242 { WM_NCCALCSIZE, sent|wparam, 0 },
2243 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2244 { WM_CREATE, sent },
2245 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2246 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2247 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2248 { WM_MOVE, sent },
2249 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
2250 { WM_SHOWWINDOW, sent|wparam, 1 },
2251 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2252 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2253 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2254 { 0 }
2255 };
2256 /* ShowWindow(SW_SHOW) for MDI client window */
2257 static const struct message WmShowMDIclientSeq[] = {
2258 { WM_SHOWWINDOW, sent|wparam, 1 },
2259 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2260 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2261 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2262 { 0 }
2263 };
2264 /* ShowWindow(SW_HIDE) for MDI client window */
2265 static const struct message WmHideMDIclientSeq[] = {
2266 { WM_SHOWWINDOW, sent|wparam, 0 },
2267 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2268 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
2269 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
2270 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2271 { 0 }
2272 };
2273 /* DestroyWindow for MDI client window, initially visible */
2274 static const struct message WmDestroyMDIclientSeq[] = {
2275 { HCBT_DESTROYWND, hook },
2276 { 0x0090, sent|optional },
2277 { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
2278 { WM_SHOWWINDOW, sent|wparam, 0 },
2279 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2280 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2281 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2282 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2283 { WM_DESTROY, sent },
2284 { WM_NCDESTROY, sent },
2285 { 0 }
2286 };
2287 /* CreateWindow for MDI child window, initially visible */
2288 static const struct message WmCreateMDIchildVisibleSeq[] = {
2289 { HCBT_CREATEWND, hook },
2290 { WM_NCCREATE, sent },
2291 { WM_NCCALCSIZE, sent|wparam, 0 },
2292 { WM_CREATE, sent },
2293 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2294 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2295 { WM_MOVE, sent },
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 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2305 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2306 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2307 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2308 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2309 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2310
2311 /* Win9x: message sequence terminates here. */
2312
2313 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2314 { HCBT_SETFOCUS, hook }, /* in MDI client */
2315 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2316 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2317 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2318 { WM_SETFOCUS, sent }, /* in MDI client */
2319 { HCBT_SETFOCUS, hook },
2320 { WM_KILLFOCUS, sent }, /* in MDI client */
2321 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2322 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2323 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2324 { WM_SETFOCUS, sent|defwinproc },
2325 { WM_MDIACTIVATE, sent|defwinproc },
2326 { 0 }
2327 };
2328 /* CreateWindow for MDI child window with invisible parent */
2329 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
2330 { HCBT_CREATEWND, hook },
2331 { WM_GETMINMAXINFO, sent },
2332 { WM_NCCREATE, sent },
2333 { WM_NCCALCSIZE, sent|wparam, 0 },
2334 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2335 { WM_CREATE, sent },
2336 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2337 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2338 { WM_MOVE, sent },
2339 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2340 { WM_SHOWWINDOW, sent|wparam, 1 },
2341 { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2342 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2343 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2344 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2345
2346 /* Win9x: message sequence terminates here. */
2347
2348 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2349 { HCBT_SETFOCUS, hook }, /* in MDI client */
2350 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2351 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2352 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2353 { WM_SETFOCUS, sent }, /* in MDI client */
2354 { HCBT_SETFOCUS, hook },
2355 { WM_KILLFOCUS, sent }, /* in MDI client */
2356 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2357 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2358 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2359 { WM_SETFOCUS, sent|defwinproc },
2360 { WM_MDIACTIVATE, sent|defwinproc },
2361 { 0 }
2362 };
2363 /* DestroyWindow for MDI child window, initially visible */
2364 static const struct message WmDestroyMDIchildVisibleSeq[] = {
2365 { HCBT_DESTROYWND, hook },
2366 /* Win2k sends wparam set to
2367 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2368 * while Win9x doesn't bother to set child window id according to
2369 * CLIENTCREATESTRUCT.idFirstChild
2370 */
2371 { 0x0090, sent|optional },
2372 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2373 { WM_SHOWWINDOW, sent|wparam, 0 },
2374 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2375 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2376 { WM_ERASEBKGND, sent|parent|optional },
2377 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2378
2379 /* { WM_DESTROY, sent }
2380 * Win9x: message sequence terminates here.
2381 */
2382
2383 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2384 { WM_KILLFOCUS, sent },
2385 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2386 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2387 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2388 { WM_SETFOCUS, sent }, /* in MDI client */
2389
2390 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2391 { WM_KILLFOCUS, sent }, /* in MDI client */
2392 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2393 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2394 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2395 { WM_SETFOCUS, sent }, /* in MDI client */
2396
2397 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2398
2399 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2400 { WM_KILLFOCUS, sent },
2401 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2402 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2403 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2404 { WM_SETFOCUS, sent }, /* in MDI client */
2405
2406 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2407 { WM_KILLFOCUS, sent }, /* in MDI client */
2408 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2409 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2410 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2411 { WM_SETFOCUS, sent }, /* in MDI client */
2412
2413 { WM_DESTROY, sent },
2414
2415 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2416 { WM_KILLFOCUS, sent },
2417 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2418 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2419 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2420 { WM_SETFOCUS, sent }, /* in MDI client */
2421
2422 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2423 { WM_KILLFOCUS, sent }, /* in MDI client */
2424 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2425 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2426 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2427 { WM_SETFOCUS, sent }, /* in MDI client */
2428
2429 { WM_NCDESTROY, sent },
2430 { 0 }
2431 };
2432 /* CreateWindow for MDI child window, initially invisible */
2433 static const struct message WmCreateMDIchildInvisibleSeq[] = {
2434 { HCBT_CREATEWND, hook },
2435 { WM_NCCREATE, sent },
2436 { WM_NCCALCSIZE, sent|wparam, 0 },
2437 { WM_CREATE, sent },
2438 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2439 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2440 { WM_MOVE, sent },
2441 /* Win2k sends wparam set to
2442 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2443 * while Win9x doesn't bother to set child window id according to
2444 * CLIENTCREATESTRUCT.idFirstChild
2445 */
2446 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2447 { 0 }
2448 };
2449 /* DestroyWindow for MDI child window, initially invisible */
2450 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
2451 { HCBT_DESTROYWND, hook },
2452 /* Win2k sends wparam set to
2453 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2454 * while Win9x doesn't bother to set child window id according to
2455 * CLIENTCREATESTRUCT.idFirstChild
2456 */
2457 { 0x0090, sent|optional },
2458 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2459 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2460 { WM_DESTROY, sent },
2461 { WM_NCDESTROY, sent },
2462 /* FIXME: Wine destroys an icon/title window while Windows doesn't */
2463 { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
2464 { 0 }
2465 };
2466 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
2467 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
2468 { HCBT_CREATEWND, hook },
2469 { WM_NCCREATE, sent },
2470 { WM_NCCALCSIZE, sent|wparam, 0 },
2471 { WM_CREATE, sent },
2472 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2473 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2474 { WM_MOVE, sent },
2475 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2476 { WM_GETMINMAXINFO, sent },
2477 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2478 { WM_NCCALCSIZE, sent|wparam, 1 },
2479 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2480 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2481 /* in MDI frame */
2482 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2483 { WM_NCCALCSIZE, sent|wparam, 1 },
2484 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2485 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2486 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2487 /* Win2k sends wparam set to
2488 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2489 * while Win9x doesn't bother to set child window id according to
2490 * CLIENTCREATESTRUCT.idFirstChild
2491 */
2492 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2493 { WM_SHOWWINDOW, sent|wparam, 1 },
2494 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2495 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2496 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2497 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2498 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2499 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2500 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_FRAMECHANGED },
2501
2502 /* Win9x: message sequence terminates here. */
2503
2504 { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2505 { HCBT_SETFOCUS, hook|optional }, /* in MDI client */
2506 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2507 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2508 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2509 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2510 { HCBT_SETFOCUS, hook|optional },
2511 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2512 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2513 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2514 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2515 { WM_SETFOCUS, sent|defwinproc|optional },
2516 { WM_MDIACTIVATE, sent|defwinproc|optional },
2517 /* in MDI frame */
2518 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2519 { WM_NCCALCSIZE, sent|wparam, 1 },
2520 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2521 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2522 { 0 }
2523 };
2524 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2525 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2526 /* restore the 1st MDI child */
2527 { WM_SETREDRAW, sent|wparam, 0 },
2528 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2529 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2530 { WM_NCCALCSIZE, sent|wparam, 1 },
2531 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2532 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2533 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2534 /* in MDI frame */
2535 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2536 { WM_NCCALCSIZE, sent|wparam, 1 },
2537 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2538 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2539 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2540 { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2541 /* create the 2nd MDI child */
2542 { HCBT_CREATEWND, hook },
2543 { WM_NCCREATE, sent },
2544 { WM_NCCALCSIZE, sent|wparam, 0 },
2545 { WM_CREATE, sent },
2546 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2547 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2548 { WM_MOVE, sent },
2549 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2550 { WM_GETMINMAXINFO, sent },
2551 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2552 { WM_NCCALCSIZE, sent|wparam, 1 },
2553 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2554 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2555 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2556 /* in MDI frame */
2557 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2558 { WM_NCCALCSIZE, sent|wparam, 1 },
2559 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2560 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2561 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2562 /* Win2k sends wparam set to
2563 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2564 * while Win9x doesn't bother to set child window id according to
2565 * CLIENTCREATESTRUCT.idFirstChild
2566 */
2567 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2568 { WM_SHOWWINDOW, sent|wparam, 1 },
2569 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2570 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2571 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2572 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2573 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2574 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2575
2576 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2577 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2578
2579 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2580
2581 /* Win9x: message sequence terminates here. */
2582
2583 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2584 { HCBT_SETFOCUS, hook },
2585 { WM_KILLFOCUS, sent|defwinproc|optional }, /* in the 1st MDI child */
2586 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2587 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2588 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2589 { WM_SETFOCUS, sent }, /* in MDI client */
2590 { HCBT_SETFOCUS, hook },
2591 { WM_KILLFOCUS, sent }, /* in MDI client */
2592 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2593 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2594 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2595 { WM_SETFOCUS, sent|defwinproc },
2596
2597 { WM_MDIACTIVATE, sent|defwinproc },
2598 /* in MDI frame */
2599 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2600 { WM_NCCALCSIZE, sent|wparam, 1 },
2601 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2602 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2603 { 0 }
2604 };
2605 /* WM_MDICREATE MDI child window, initially visible and maximized */
2606 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2607 { WM_MDICREATE, sent },
2608 { HCBT_CREATEWND, hook },
2609 { WM_NCCREATE, sent },
2610 { WM_NCCALCSIZE, sent|wparam, 0 },
2611 { WM_CREATE, sent },
2612 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2613 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2614 { WM_MOVE, sent },
2615 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2616 { WM_GETMINMAXINFO, sent },
2617 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2618 { WM_NCCALCSIZE, sent|wparam, 1 },
2619 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2620 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2621
2622 /* in MDI frame */
2623 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2624 { WM_NCCALCSIZE, sent|wparam, 1 },
2625 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2626 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2627 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2628
2629 /* Win2k sends wparam set to
2630 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2631 * while Win9x doesn't bother to set child window id according to
2632 * CLIENTCREATESTRUCT.idFirstChild
2633 */
2634 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2635 { WM_SHOWWINDOW, sent|wparam, 1 },
2636 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2637
2638 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2639
2640 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2641 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2642 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2643
2644 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2645 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2646
2647 /* Win9x: message sequence terminates here. */
2648
2649 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2650 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2651 { HCBT_SETFOCUS, hook }, /* in MDI client */
2652 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2653 { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2654 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2655 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2656 { HCBT_SETFOCUS, hook|optional },
2657 { WM_KILLFOCUS, sent }, /* in MDI client */
2658 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2659 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2660 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2661 { WM_SETFOCUS, sent|defwinproc },
2662
2663 { WM_MDIACTIVATE, sent|defwinproc },
2664
2665 /* in MDI child */
2666 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2667 { WM_NCCALCSIZE, sent|wparam, 1 },
2668 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2669 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2670
2671 /* in MDI frame */
2672 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2673 { WM_NCCALCSIZE, sent|wparam, 1 },
2674 { 0x0093, sent|defwinproc|optional },
2675 { 0x0093, sent|defwinproc|optional },
2676 { 0x0093, sent|defwinproc|optional },
2677 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2678 { WM_MOVE, sent|defwinproc },
2679 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2680
2681 /* in MDI client */
2682 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2683 { WM_NCCALCSIZE, sent|wparam, 1 },
2684 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2685 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2686
2687 /* in MDI child */
2688 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2689 { WM_NCCALCSIZE, sent|wparam, 1 },
2690 { 0x0093, sent|optional },
2691 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2692 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2693
2694 { 0x0093, sent|optional },
2695 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2696 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2697 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2698 { 0x0093, sent|defwinproc|optional },
2699 { 0x0093, sent|defwinproc|optional },
2700 { 0x0093, sent|defwinproc|optional },
2701 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2702 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2703
2704 { 0 }
2705 };
2706 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2707 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2708 { HCBT_CREATEWND, hook },
2709 { WM_GETMINMAXINFO, sent },
2710 { WM_NCCREATE, sent },
2711 { WM_NCCALCSIZE, sent|wparam, 0 },
2712 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2713 { WM_CREATE, sent },
2714 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2715 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2716 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2717 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI frame */
2718 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2719 { WM_MOVE, sent },
2720 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2721 { WM_GETMINMAXINFO, sent },
2722 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2723 { WM_GETMINMAXINFO, sent|defwinproc },
2724 { WM_NCCALCSIZE, sent|wparam, 1 },
2725 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_STATECHANGED },
2726 { WM_MOVE, sent|defwinproc },
2727 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2728 /* in MDI frame */
2729 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2730 { WM_NCCALCSIZE, sent|wparam, 1 },
2731 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2732 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2733 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2734 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2735 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2736 /* Win2k sends wparam set to
2737 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2738 * while Win9x doesn't bother to set child window id according to
2739 * CLIENTCREATESTRUCT.idFirstChild
2740 */
2741 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2742 { 0 }
2743 };
2744 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2745 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2746 { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2747 { HCBT_SYSCOMMAND, hook },
2748 { WM_CLOSE, sent|defwinproc },
2749 { WM_MDIDESTROY, sent }, /* in MDI client */
2750
2751 /* bring the 1st MDI child to top */
2752 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2753 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2754
2755 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2756
2757 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2758 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2759 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2760
2761 /* maximize the 1st MDI child */
2762 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2763 { WM_GETMINMAXINFO, sent|defwinproc },
2764 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED },
2765 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2766 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2767 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2768 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2769
2770 /* restore the 2nd MDI child */
2771 { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2772 { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2773 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2774 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2775
2776 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2777
2778 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2779 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2780
2781 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2782
2783 { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2784 /* in MDI frame */
2785 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2786 { WM_NCCALCSIZE, sent|wparam, 1 },
2787 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2788 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2789 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2790
2791 /* bring the 1st MDI child to top */
2792 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2793 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2794 { HCBT_SETFOCUS, hook },
2795 { WM_KILLFOCUS, sent|defwinproc },
2796 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2797 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2798 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2799 { WM_SETFOCUS, sent }, /* in MDI client */
2800 { HCBT_SETFOCUS, hook },
2801 { WM_KILLFOCUS, sent }, /* in MDI client */
2802 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2803 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2804 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2805 { WM_SETFOCUS, sent|defwinproc },
2806 { WM_MDIACTIVATE, sent|defwinproc },
2807 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2808
2809 /* apparently ShowWindow(SW_SHOW) on an MDI client */
2810 { WM_SHOWWINDOW, sent|wparam, 1 },
2811 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2812 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2813 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2814 { WM_MDIREFRESHMENU, sent },
2815
2816 { HCBT_DESTROYWND, hook },
2817 /* Win2k sends wparam set to
2818 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2819 * while Win9x doesn't bother to set child window id according to
2820 * CLIENTCREATESTRUCT.idFirstChild
2821 */
2822 { 0x0090, sent|defwinproc|optional },
2823 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2824 { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2825 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2826 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2827 { WM_ERASEBKGND, sent|parent|optional },
2828 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2829
2830 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2831 { WM_DESTROY, sent|defwinproc },
2832 { WM_NCDESTROY, sent|defwinproc },
2833 { 0 }
2834 };
2835 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2836 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2837 { WM_MDIDESTROY, sent }, /* in MDI client */
2838 { WM_SHOWWINDOW, sent|wparam, 0 },
2839 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2840 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2841 { WM_ERASEBKGND, sent|parent|optional },
2842 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2843
2844 { HCBT_SETFOCUS, hook },
2845 { WM_KILLFOCUS, sent },
2846 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2847 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2848 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2849 { WM_SETFOCUS, sent }, /* in MDI client */
2850 { HCBT_SETFOCUS, hook },
2851 { WM_KILLFOCUS, sent }, /* in MDI client */
2852 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2853 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2854 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2855 { WM_SETFOCUS, sent },
2856
2857 /* in MDI child */
2858 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2859 { WM_NCCALCSIZE, sent|wparam, 1 },
2860 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2861 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2862
2863 /* in MDI frame */
2864 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2865 { WM_NCCALCSIZE, sent|wparam, 1 },
2866 { 0x0093, sent|defwinproc|optional },
2867 { 0x0093, sent|defwinproc|optional },
2868 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2869 { WM_MOVE, sent|defwinproc },
2870 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2871
2872 /* in MDI client */
2873 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2874 { WM_NCCALCSIZE, sent|wparam, 1 },
2875 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2876 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2877
2878 /* in MDI child */
2879 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2880 { WM_NCCALCSIZE, sent|wparam, 1 },
2881 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2882 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2883
2884 /* in MDI child */
2885 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2886 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2887 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2888 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2889
2890 /* in MDI frame */
2891 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2892 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2893 { 0x0093, sent|defwinproc|optional },
2894 { 0x0093, sent|defwinproc|optional },
2895 { 0x0093, sent|defwinproc|optional },
2896 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2897 { WM_MOVE, sent|defwinproc },
2898 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2899
2900 /* in MDI client */
2901 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2902 { WM_NCCALCSIZE, sent|wparam, 1 },
2903 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2904 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2905
2906 /* in MDI child */
2907 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2908 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2909 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2910 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2911 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2912 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2913
2914 { 0x0093, sent|defwinproc|optional },
2915 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2916 { 0x0093, sent|defwinproc|optional },
2917 { 0x0093, sent|defwinproc|optional },
2918 { 0x0093, sent|defwinproc|optional },
2919 { 0x0093, sent|optional },
2920
2921 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2922 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2923 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2924 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2925 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2926
2927 /* in MDI frame */
2928 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2929 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2930 { 0x0093, sent|defwinproc|optional },
2931 { 0x0093, sent|defwinproc|optional },
2932 { 0x0093, sent|defwinproc|optional },
2933 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2934 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2935 { 0x0093, sent|optional },
2936
2937 { WM_NCACTIVATE, sent|wparam, 0 },
2938 { WM_MDIACTIVATE, sent },
2939
2940 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2941 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2942 { WM_NCCALCSIZE, sent|wparam, 1 },
2943
2944 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2945
2946 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2947 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2948 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2949
2950 /* in MDI child */
2951 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2952 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2953 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2954 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2955
2956 /* in MDI frame */
2957 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2958 { WM_NCCALCSIZE, sent|wparam, 1 },
2959 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2960 { WM_MOVE, sent|defwinproc },
2961 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2962
2963 /* in MDI client */
2964 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2965 { WM_NCCALCSIZE, sent|wparam, 1 },
2966 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2967 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2968 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2969 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2970 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2971 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2972 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2973
2974 { HCBT_SETFOCUS, hook },
2975 { WM_KILLFOCUS, sent },
2976 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2977 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2978 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2979 { WM_SETFOCUS, sent }, /* in MDI client */
2980
2981 { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2982
2983 { HCBT_DESTROYWND, hook },
2984 /* Win2k sends wparam set to
2985 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2986 * while Win9x doesn't bother to set child window id according to
2987 * CLIENTCREATESTRUCT.idFirstChild
2988 */
2989 { 0x0090, sent|optional },
2990 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2991
2992 { WM_SHOWWINDOW, sent|wparam, 0 },
2993 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2994 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2995 { WM_ERASEBKGND, sent|parent|optional },
2996 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2997
2998 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2999 { WM_DESTROY, sent },
3000 { WM_NCDESTROY, sent },
3001 { 0 }
3002 };
3003 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
3004 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
3005 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3006 { WM_GETMINMAXINFO, sent },
3007 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
3008 { WM_NCCALCSIZE, sent|wparam, 1 },
3009 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3010 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3011
3012 { WM_WINDOWPOSCHANGING, sent|wparam|optional|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3013 { WM_NCACTIVATE, sent|wparam|optional|defwinproc, 1 },
3014 { HCBT_SETFOCUS, hook|optional },
3015 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3016 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3017 { WM_SETFOCUS, sent|optional }, /* in MDI client */
3018 { HCBT_SETFOCUS, hook|optional },
3019 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3020 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3021 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3022 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3023 { WM_SETFOCUS, sent|optional|defwinproc },
3024 { WM_MDIACTIVATE, sent|optional|defwinproc },
3025 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3026 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3027 /* in MDI frame */
3028 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3029 { WM_NCCALCSIZE, sent|wparam, 1 },
3030 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3031 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3032 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3033 { 0 }
3034 };
3035 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
3036 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
3037 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3038 { WM_GETMINMAXINFO, sent },
3039 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
3040 { WM_GETMINMAXINFO, sent|defwinproc },
3041 { WM_NCCALCSIZE, sent|wparam, 1 },
3042 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3043 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3044
3045 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3046 { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
3047 { HCBT_SETFOCUS, hook|optional },
3048 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3049 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3050 { WM_SETFOCUS, sent|optional }, /* in MDI client */
3051 { HCBT_SETFOCUS, hook|optional },
3052 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3053 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3054 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3055 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3056 { WM_SETFOCUS, sent|defwinproc|optional },
3057 { WM_MDIACTIVATE, sent|defwinproc|optional },
3058 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3059 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3060 { 0 }
3061 };
3062 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
3063 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
3064 { WM_MDIMAXIMIZE, sent }, /* in MDI client */
3065 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3066 { WM_GETMINMAXINFO, sent },
3067 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3068 { WM_GETMINMAXINFO, sent|defwinproc },
3069 { WM_NCCALCSIZE, sent|wparam, 1 },
3070 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
3071 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3072 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
3073 { WM_MOVE, sent|defwinproc },
3074 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3075
3076 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3077 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3078 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3079 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3080 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3081 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3082 /* in MDI frame */
3083 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3084 { WM_NCCALCSIZE, sent|wparam, 1 },
3085 { 0x0093, sent|defwinproc|optional },
3086 { 0x0094, sent|defwinproc|optional },
3087 { 0x0094, sent|defwinproc|optional },
3088 { 0x0094, sent|defwinproc|optional },
3089 { 0x0094, sent|defwinproc|optional },
3090 { 0x0093, sent|defwinproc|optional },
3091 { 0x0093, sent|defwinproc|optional },
3092 { 0x0091, sent|defwinproc|optional },
3093 { 0x0092, sent|defwinproc|optional },
3094 { 0x0092, sent|defwinproc|optional },
3095 { 0x0092, sent|defwinproc|optional },
3096 { 0x0092, sent|defwinproc|optional },
3097 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3098 { WM_MOVE, sent|defwinproc },
3099 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3100 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
3101 /* in MDI client */
3102 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
3103 { WM_NCCALCSIZE, sent|wparam, 1 },
3104 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3105 { WM_SIZE, sent|wparam, SIZE_RESTORED },
3106 /* in MDI child */
3107 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
3108 { WM_GETMINMAXINFO, sent|defwinproc },
3109 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3110 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3111 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3112 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
3113 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3114 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3115 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3116 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3117 /* in MDI frame */
3118 { 0x0093, sent|optional },
3119 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
3120 { 0x0093, sent|defwinproc|optional },
3121 { 0x0093, sent|defwinproc|optional },
3122 { 0x0093, sent|defwinproc|optional },
3123 { 0x0091, sent|defwinproc|optional },
3124 { 0x0092, sent|defwinproc|optional },
3125 { 0x0092, sent|defwinproc|optional },
3126 { 0x0092, sent|defwinproc|optional },
3127 { 0x0092, sent|defwinproc|optional },
3128 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3129 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3130 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3131 { 0 }
3132 };
3133 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
3134 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
3135 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3136 { WM_GETMINMAXINFO, sent },
3137 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3138 { WM_NCCALCSIZE, sent|wparam, 1 },
3139 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3140 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3141 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3142 /* in MDI frame */
3143 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3144 { WM_NCCALCSIZE, sent|wparam, 1 },
3145 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3146 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3147 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3148 { 0 }
3149 };
3150 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
3151 static const struct message WmRestoreMDIchildVisibleSeq[] = {
3152 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3153 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3154 { WM_NCCALCSIZE, sent|wparam, 1 },
3155 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3156 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3157 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3158 /* in MDI frame */
3159 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3160 { WM_NCCALCSIZE, sent|wparam, 1 },
3161 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3162 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3163 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3164 { 0 }
3165 };
3166 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
3167 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
3168 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3169 { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
3170 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3171 { WM_NCCALCSIZE, sent|wparam, 1 },
3172 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3173 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3174 { WM_MOVE, sent|defwinproc },
3175 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3176 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3177 { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3178 { HCBT_SETFOCUS, hook },
3179 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3180 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
3181 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3182 { WM_SETFOCUS, sent },
3183 { 0 }
3184 };
3185 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
3186 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
3187 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
3188 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3189 { WM_NCCALCSIZE, sent|wparam, 1 },
3190 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3191 { WM_MOVE, sent|defwinproc },
3192 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
3193 { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
3194 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3195 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3196 /* FIXME: Wine creates an icon/title window while Windows doesn't */
3197 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
3198 { 0 }
3199 };
3200 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
3201 static const struct message WmRestoreMDIchildInisibleSeq[] = {
3202 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3203 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
3204 { WM_NCCALCSIZE, sent|wparam, 1 },
3205 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3206 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3207 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3208 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3209 /* in MDI frame */
3210 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3211 { WM_NCCALCSIZE, sent|wparam, 1 },
3212 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3213 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3214 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3215 { 0 }
3216 };
3217
3218 static HWND mdi_client;
3219 static WNDPROC old_mdi_client_proc;
3220
3221 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3222 {
3223 struct recvd_message msg;
3224
3225 /* do not log painting messages */
3226 if (message != WM_PAINT &&
3227 message != WM_NCPAINT &&
3228 message != WM_SYNCPAINT &&
3229 message != WM_ERASEBKGND &&
3230 message != WM_NCHITTEST &&
3231 message != WM_GETTEXT &&
3232 message != WM_MDIGETACTIVE &&
3233 !ignore_message( message ))
3234 {
3235 msg.hwnd = hwnd;
3236 msg.message = message;
3237 msg.flags = sent|wparam|lparam;
3238 msg.wParam = wParam;
3239 msg.lParam = lParam;
3240 msg.descr = "mdi client";
3241 add_message(&msg);
3242 }
3243
3244 return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
3245 }
3246
3247 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3248 {
3249 static LONG defwndproc_counter = 0;
3250 LRESULT ret;
3251 struct recvd_message msg;
3252
3253 /* do not log painting messages */
3254 if (message != WM_PAINT &&
3255 message != WM_NCPAINT &&
3256 message != WM_SYNCPAINT &&
3257 message != WM_ERASEBKGND &&
3258 message != WM_NCHITTEST &&
3259 message != WM_GETTEXT &&
3260 !ignore_message( message ))
3261 {
3262 switch (message)
3263 {
3264 case WM_MDIACTIVATE:
3265 {
3266 HWND active, client = GetParent(hwnd);
3267
3268 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
3269
3270 if (hwnd == (HWND)lParam) /* if we are being activated */
3271 ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
3272 else
3273 ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
3274 break;
3275 }
3276 }
3277
3278 msg.hwnd = hwnd;
3279 msg.message = message;
3280 msg.flags = sent|wparam|lparam;
3281 if (defwndproc_counter) msg.flags |= defwinproc;
3282 msg.wParam = wParam;
3283 msg.lParam = lParam;
3284 msg.descr = "mdi child";
3285 add_message(&msg);
3286 }
3287
3288 defwndproc_counter++;
3289 ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
3290 defwndproc_counter--;
3291
3292 return ret;
3293 }
3294
3295 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3296 {
3297 static LONG defwndproc_counter = 0;
3298 LRESULT ret;
3299 struct recvd_message msg;
3300
3301 /* do not log painting messages */
3302 if (message != WM_PAINT &&
3303 message != WM_NCPAINT &&
3304 message != WM_SYNCPAINT &&
3305 message != WM_ERASEBKGND &&
3306 message != WM_NCHITTEST &&
3307 message != WM_GETTEXT &&
3308 !ignore_message( message ))
3309 {
3310 msg.hwnd = hwnd;
3311 msg.message = message;
3312 msg.flags = sent|wparam|lparam;
3313 if (defwndproc_counter) msg.flags |= defwinproc;
3314 msg.wParam = wParam;
3315 msg.lParam = lParam;
3316 msg.descr = "mdi frame";
3317 add_message(&msg);
3318 }
3319
3320 defwndproc_counter++;
3321 ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
3322 defwndproc_counter--;
3323
3324 return ret;
3325 }
3326
3327 static BOOL mdi_RegisterWindowClasses(void)
3328 {
3329 WNDCLASSA cls;
3330
3331 cls.style = 0;
3332 cls.lpfnWndProc = mdi_frame_wnd_proc;
3333 cls.cbClsExtra = 0;
3334 cls.cbWndExtra = 0;
3335 cls.hInstance = GetModuleHandleA(0);
3336 cls.hIcon = 0;
3337 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3338 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3339 cls.lpszMenuName = NULL;
3340 cls.lpszClassName = "MDI_frame_class";
3341 if (!RegisterClassA(&cls)) return FALSE;
3342
3343 cls.lpfnWndProc = mdi_child_wnd_proc;
3344 cls.lpszClassName = "MDI_child_class";
3345 if (!RegisterClassA(&cls)) return FALSE;
3346
3347 if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
3348 old_mdi_client_proc = cls.lpfnWndProc;
3349 cls.hInstance = GetModuleHandleA(0);
3350 cls.lpfnWndProc = mdi_client_hook_proc;
3351 cls.lpszClassName = "MDI_client_class";
3352 if (!RegisterClassA(&cls)) assert(0);
3353
3354 return TRUE;
3355 }
3356
3357 static void test_mdi_messages(void)
3358 {
3359 MDICREATESTRUCTA mdi_cs;
3360 CLIENTCREATESTRUCT client_cs;
3361 HWND mdi_frame, mdi_child, mdi_child2, active_child;
3362 BOOL zoomed;
3363 RECT rc;
3364 HMENU hMenu = CreateMenu();
3365
3366 assert(mdi_RegisterWindowClasses());
3367
3368 flush_sequence();
3369
3370 trace("creating MDI frame window\n");
3371 mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
3372 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3373 WS_MAXIMIZEBOX | WS_VISIBLE,
3374 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
3375 GetDesktopWindow(), hMenu,
3376 GetModuleHandleA(0), NULL);
3377 assert(mdi_frame);
3378 ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
3379
3380 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3381 ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
3382
3383 trace("creating MDI client window\n");
3384 GetClientRect(mdi_frame, &rc);
3385 client_cs.hWindowMenu = 0;
3386 client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
3387 mdi_client = CreateWindowExA(0, "MDI_client_class",
3388 NULL,
3389 WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
3390 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
3391 mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3392 assert(mdi_client);
3393 ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
3394
3395 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3396 ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
3397
3398 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3399 ok(!active_child, "wrong active MDI child %p\n", active_child);
3400 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3401
3402 SetFocus(0);
3403 flush_sequence();
3404
3405 trace("creating invisible MDI child window\n");
3406 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3407 WS_CHILD,
3408 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3409 mdi_client, 0, GetModuleHandleA(0), NULL);
3410 assert(mdi_child);
3411
3412 flush_sequence();
3413 ShowWindow(mdi_child, SW_SHOWNORMAL);
3414 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
3415
3416 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3417 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3418
3419 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3420 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3421
3422 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3423 ok(!active_child, "wrong active MDI child %p\n", active_child);
3424 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3425
3426 ShowWindow(mdi_child, SW_HIDE);
3427 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
3428 flush_sequence();
3429
3430 ShowWindow(mdi_child, SW_SHOW);
3431 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
3432
3433 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3434 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3435
3436 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3437 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3438
3439 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3440 ok(!active_child, "wrong active MDI child %p\n", active_child);
3441 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3442
3443 DestroyWindow(mdi_child);
3444 flush_sequence();
3445
3446 trace("creating visible MDI child window\n");
3447 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3448 WS_CHILD | WS_VISIBLE,
3449 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3450 mdi_client, 0, GetModuleHandleA(0), NULL);
3451 assert(mdi_child);
3452 ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
3453
3454 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3455 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3456
3457 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3458 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3459
3460 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3461 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3462 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3463 flush_sequence();
3464
3465 DestroyWindow(mdi_child);
3466 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3467
3468 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3469 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3470
3471 /* Win2k: MDI client still returns a just destroyed child as active
3472 * Win9x: MDI client returns 0
3473 */
3474 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3475 ok(active_child == mdi_child || /* win2k */
3476 !active_child, /* win9x */
3477 "wrong active MDI child %p\n", active_child);
3478 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3479
3480 flush_sequence();
3481
3482 trace("creating invisible MDI child window\n");
3483 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3484 WS_CHILD,
3485 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3486 mdi_client, 0, GetModuleHandleA(0), NULL);
3487 assert(mdi_child2);
3488 ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
3489
3490 ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
3491 ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
3492
3493 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3494 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3495
3496 /* Win2k: MDI client still returns a just destroyed child as active
3497 * Win9x: MDI client returns mdi_child2
3498 */
3499 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3500 ok(active_child == mdi_child || /* win2k */
3501 active_child == mdi_child2, /* win9x */
3502 "wrong active MDI child %p\n", active_child);
3503 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3504 flush_sequence();
3505
3506 ShowWindow(mdi_child2, SW_MAXIMIZE);
3507 ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3508
3509 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3510 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3511
3512 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3513 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3514 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3515 flush_sequence();
3516
3517 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3518 ok(GetFocus() == mdi_child2 || /* win2k */
3519 GetFocus() == 0, /* win9x */
3520 "wrong focus window %p\n", GetFocus());
3521
3522 SetFocus(0);
3523 flush_sequence();
3524
3525 ShowWindow(mdi_child2, SW_HIDE);
3526 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3527
3528 ShowWindow(mdi_child2, SW_RESTORE);
3529 ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3530 flush_sequence();
3531
3532 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3533 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3534
3535 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3536 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3537 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3538 flush_sequence();
3539
3540 SetFocus(0);
3541 flush_sequence();
3542
3543 ShowWindow(mdi_child2, SW_HIDE);
3544 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3545
3546 ShowWindow(mdi_child2, SW_SHOW);
3547 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3548
3549 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3550 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3551
3552 ShowWindow(mdi_child2, SW_MAXIMIZE);
3553 ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3554
3555 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3556 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3557
3558 ShowWindow(mdi_child2, SW_RESTORE);
3559 ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3560
3561 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3562 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3563
3564 ShowWindow(mdi_child2, SW_MINIMIZE);
3565 ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3566
3567 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3568 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3569
3570 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3571 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3572 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3573 flush_sequence();
3574
3575 ShowWindow(mdi_child2, SW_RESTORE);
3576 ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", FALSE);
3577
3578 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3579 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3580
3581 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3582 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3583 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3584 flush_sequence();
3585
3586 SetFocus(0);
3587 flush_sequence();
3588
3589 ShowWindow(mdi_child2, SW_HIDE);
3590 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3591
3592 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3593 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3594
3595 DestroyWindow(mdi_child2);
3596 ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3597
3598 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3599 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3600
3601 /* test for maximized MDI children */
3602 trace("creating maximized visible MDI child window 1\n");
3603 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3604 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3605 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3606 mdi_client, 0, GetModuleHandleA(0), NULL);
3607 assert(mdi_child);
3608 ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3609 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3610
3611 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3612 ok(GetFocus() == mdi_child || /* win2k */
3613 GetFocus() == 0, /* win9x */
3614 "wrong focus window %p\n", GetFocus());
3615
3616 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3617 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3618 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3619 flush_sequence();
3620
3621 trace("creating maximized visible MDI child window 2\n");
3622 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3623 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3624 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3625 mdi_client, 0, GetModuleHandleA(0), NULL);
3626 assert(mdi_child2);
3627 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3628 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3629 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3630
3631 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3632 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3633
3634 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3635 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3636 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3637 flush_sequence();
3638
3639 trace("destroying maximized visible MDI child window 2\n");
3640 DestroyWindow(mdi_child2);
3641 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3642
3643 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3644
3645 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3646 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3647
3648 /* Win2k: MDI client still returns a just destroyed child as active
3649 * Win9x: MDI client returns 0
3650 */
3651 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3652 ok(active_child == mdi_child2 || /* win2k */
3653 !active_child, /* win9x */
3654 "wrong active MDI child %p\n", active_child);
3655 flush_sequence();
3656
3657 ShowWindow(mdi_child, SW_MAXIMIZE);
3658 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3659 flush_sequence();
3660
3661 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3662 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3663
3664 trace("re-creating maximized visible MDI child window 2\n");
3665 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3666 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3667 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3668 mdi_client, 0, GetModuleHandleA(0), NULL);
3669 assert(mdi_child2);
3670 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3671 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3672 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3673
3674 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3675 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3676
3677 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3678 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3679 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3680 flush_sequence();
3681
3682 SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3683 ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3684 ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3685
3686 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3687 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3688 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3689
3690 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3691 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3692 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3693 flush_sequence();
3694
3695 DestroyWindow(mdi_child);
3696 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3697
3698 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3699 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3700
3701 /* Win2k: MDI client still returns a just destroyed child as active
3702 * Win9x: MDI client returns 0
3703 */
3704 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3705 ok(active_child == mdi_child || /* win2k */
3706 !active_child, /* win9x */
3707 "wrong active MDI child %p\n", active_child);
3708 flush_sequence();
3709
3710 trace("creating maximized invisible MDI child window\n");
3711 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3712 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3713 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3714 mdi_client, 0, GetModuleHandleA(0), NULL);
3715 assert(mdi_child2);
3716 ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", FALSE);
3717 ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3718 ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3719 ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3720
3721 /* Win2k: MDI client still returns a just destroyed child as active
3722 * Win9x: MDI client returns 0
3723 */
3724 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3725 ok(active_child == mdi_child || /* win2k */
3726 !active_child || active_child == mdi_child2, /* win9x */
3727 "wrong active MDI child %p\n", active_child);
3728 flush_sequence();
3729
3730 trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3731 ShowWindow(mdi_child2, SW_MAXIMIZE);
3732 ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3733 ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3734 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3735 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3736
3737 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3738 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3739 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3740 flush_sequence();
3741
3742 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3743 flush_sequence();
3744
3745 /* end of test for maximized MDI children */
3746 SetFocus(0);
3747 flush_sequence();
3748 trace("creating maximized visible MDI child window 1(Switch test)\n");
3749 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3750 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3751 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3752 mdi_client, 0, GetModuleHandleA(0), NULL);
3753 assert(mdi_child);
3754 ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3755 ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3756
3757 ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3758 ok(GetFocus() == mdi_child || /* win2k */
3759 GetFocus() == 0, /* win9x */
3760 "wrong focus window %p(Switch test)\n", GetFocus());
3761
3762 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3763 ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3764 ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3765 flush_sequence();
3766
3767 trace("creating maximized visible MDI child window 2(Switch test)\n");
3768 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3769 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3770 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3771 mdi_client, 0, GetModuleHandleA(0), NULL);
3772 assert(mdi_child2);
3773 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3774
3775 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3776 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3777
3778 ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3779 ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3780
3781 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3782 ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3783 ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3784 flush_sequence();
3785
3786 trace("Switch child window.\n");
3787 SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3788 ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3789 trace("end of test for switch maximized MDI children\n");
3790 flush_sequence();
3791
3792 /* Prepare for switching test of not maximized MDI children */
3793 ShowWindow( mdi_child, SW_NORMAL );
3794 ok(!IsZoomed(mdi_child), "wrong zoomed state for %p(Switch test)\n", mdi_child);
3795 ok(!IsZoomed(mdi_child2), "wrong zoomed state for %p(Switch test)\n", mdi_child2);
3796 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
3797 ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3798 flush_sequence();
3799
3800 SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child2, 0);
3801 ok_sequence(WmSwitchNotMaximizedChild, "Not maximized child did not switch correctly", FALSE);
3802 trace("end of test for switch not maximized MDI children\n");
3803 flush_sequence();
3804
3805 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3806 flush_sequence();
3807
3808 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3809 flush_sequence();
3810
3811 SetFocus(0);
3812 flush_sequence();
3813 /* end of tests for switch maximized/not maximized MDI children */
3814
3815 mdi_cs.szClass = "MDI_child_Class";
3816 mdi_cs.szTitle = "MDI child";
3817 mdi_cs.hOwner = GetModuleHandleA(0);
3818 mdi_cs.x = 0;
3819 mdi_cs.y = 0;
3820 mdi_cs.cx = CW_USEDEFAULT;
3821 mdi_cs.cy = CW_USEDEFAULT;
3822 mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3823 mdi_cs.lParam = 0;
3824 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3825 ok(mdi_child != 0, "MDI child creation failed\n");
3826 ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3827
3828 ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3829
3830 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3831 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3832
3833 ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3834 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3835 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3836
3837 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3838 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3839 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3840 flush_sequence();
3841
3842 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3843 ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3844
3845 ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3846 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3847 ok(!active_child, "wrong active MDI child %p\n", active_child);
3848
3849 SetFocus(0);
3850 flush_sequence();
3851
3852 DestroyWindow(mdi_client);
3853 ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3854
3855 /* test maximization of MDI child with invisible parent */
3856 client_cs.hWindowMenu = 0;
3857 mdi_client = CreateWindow("MDI_client_class",
3858 NULL,
3859 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3860 0, 0, 660, 430,
3861 mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3862 ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3863
3864 ShowWindow(mdi_client, SW_HIDE);
3865 ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3866
3867 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3868 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3869 0, 0, 650, 440,
3870 mdi_client, 0, GetModuleHandleA(0), NULL);
3871 ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3872
3873 SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3874 ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3875 zoomed = IsZoomed(mdi_child);
3876 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3877
3878 ShowWindow(mdi_client, SW_SHOW);
3879 ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3880
3881 DestroyWindow(mdi_child);
3882 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3883
3884 /* end of test for maximization of MDI child with invisible parent */
3885
3886 DestroyWindow(mdi_client);
3887 ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3888
3889 DestroyWindow(mdi_frame);
3890 ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3891 }
3892 /************************* End of MDI test **********************************/
3893
3894 static void test_WM_SETREDRAW(HWND hwnd)
3895 {
3896 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3897
3898 flush_events();
3899 flush_sequence();
3900
3901 SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3902 ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3903
3904 ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3905 ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3906
3907 flush_sequence();
3908 SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3909 ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3910
3911 ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3912 ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3913
3914 /* restore original WS_VISIBLE state */
3915 SetWindowLongA(hwnd, GWL_STYLE, style);
3916
3917 flush_events();
3918 flush_sequence();
3919 }
3920
3921 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3922 {
3923 struct recvd_message msg;
3924
3925 if (ignore_message( message )) return 0;
3926
3927 switch (message)
3928 {
3929 /* ignore */
3930 case WM_MOUSEMOVE:
3931 case WM_NCMOUSEMOVE:
3932 case WM_NCMOUSELEAVE:
3933 case WM_SETCURSOR:
3934 return 0;
3935 case WM_NCHITTEST:
3936 return HTCLIENT;
3937 }
3938
3939 msg.hwnd = hwnd;
3940 msg.message = message;
3941 msg.flags = sent|wparam|lparam;
3942 msg.wParam = wParam;
3943 msg.lParam = lParam;
3944 msg.descr = "dialog";
3945 add_message(&msg);
3946
3947 if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3948 if (message == WM_TIMER) EndDialog( hwnd, 0 );
3949 return 0;
3950 }
3951
3952 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3953 {
3954 DWORD style, exstyle;
3955 INT xmin, xmax;
3956 BOOL ret;
3957
3958 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3959 style = GetWindowLongA(hwnd, GWL_STYLE);
3960 /* do not be confused by WS_DLGFRAME set */
3961 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3962
3963 if (clear) ok(style & clear, "style %08x should be set\n", clear);
3964 if (set) ok(!(style & set), "style %08x should not be set\n", set);
3965
3966 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3967 ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3968 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3969 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3970 else
3971 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3972
3973 style = GetWindowLongA(hwnd, GWL_STYLE);
3974 if (set) ok(style & set, "style %08x should be set\n", set);
3975 if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3976
3977 /* a subsequent call should do nothing */
3978 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3979 ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3980 ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3981
3982 xmin = 0xdeadbeef;
3983 xmax = 0xdeadbeef;
3984 ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
3985 ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
3986 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3987 ok(xmin == min, "unexpected min scroll value %d\n", xmin);
3988 ok(xmax == max, "unexpected max scroll value %d\n", xmax);
3989 }
3990
3991 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3992 {
3993 DWORD style, exstyle;
3994 SCROLLINFO si;
3995 BOOL ret;
3996
3997 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3998 style = GetWindowLongA(hwnd, GWL_STYLE);
3999 /* do not be confused by WS_DLGFRAME set */
4000 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
4001
4002 if (clear) ok(style & clear, "style %08x should be set\n", clear);
4003 if (set) ok(!(style & set), "style %08x should not be set\n", set);
4004
4005 si.cbSize = sizeof(si);
4006 si.fMask = SIF_RANGE;
4007 si.nMin = min;
4008 si.nMax = max;
4009 SetScrollInfo(hwnd, ctl, &si, TRUE);
4010 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
4011 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
4012 else
4013 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
4014
4015 style = GetWindowLongA(hwnd, GWL_STYLE);
4016 if (set) ok(style & set, "style %08x should be set\n", set);
4017 if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
4018
4019 /* a subsequent call should do nothing */
4020 SetScrollInfo(hwnd, ctl, &si, TRUE);
4021 if (style & WS_HSCROLL)
4022 ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4023 else if (style & WS_VSCROLL)
4024 ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4025 else
4026 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4027
4028 si.fMask = SIF_PAGE;
4029 si.nPage = 5;
4030 SetScrollInfo(hwnd, ctl, &si, FALSE);
4031 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4032
4033 si.fMask = SIF_POS;
4034 si.nPos = max - 1;
4035 SetScrollInfo(hwnd, ctl, &si, FALSE);
4036 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4037
4038 si.fMask = SIF_RANGE;
4039 si.nMin = 0xdeadbeef;
4040 si.nMax = 0xdeadbeef;
4041 ret = GetScrollInfo(hwnd, ctl, &si);
4042 ok( ret, "GetScrollInfo error %d\n", GetLastError());
4043 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
4044 ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
4045 ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
4046 }
4047
4048 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
4049 static void test_scroll_messages(HWND hwnd)
4050 {
4051 SCROLLINFO si;
4052 INT min, max;
4053 BOOL ret;
4054
4055 flush_events();
4056 flush_sequence();
4057
4058 min = 0xdeadbeef;
4059 max = 0xdeadbeef;
4060 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4061 ok( ret, "GetScrollRange error %d\n", GetLastError());
4062 if (sequence->message != WmGetScrollRangeSeq[0].message)
4063 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4064 /* values of min and max are undefined */
4065 flush_sequence();
4066
4067 ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
4068 ok( ret, "SetScrollRange error %d\n", GetLastError());
4069 if (sequence->message != WmSetScrollRangeSeq[0].message)
4070 trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4071 flush_sequence();
4072
4073 min = 0xdeadbeef;
4074 max = 0xdeadbeef;
4075 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4076 ok( ret, "GetScrollRange error %d\n", GetLastError());
4077 if (sequence->message != WmGetScrollRangeSeq[0].message)
4078 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4079 /* values of min and max are undefined */
4080 flush_sequence();
4081
4082 si.cbSize = sizeof(si);
4083 si.fMask = SIF_RANGE;
4084 si.nMin = 20;
4085 si.nMax = 160;
4086 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4087 if (sequence->message != WmSetScrollRangeSeq[0].message)
4088 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4089 flush_sequence();
4090
4091 si.fMask = SIF_PAGE;
4092 si.nPage = 10;
4093 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4094 if (sequence->message != WmSetScrollRangeSeq[0].message)
4095 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4096 flush_sequence();
4097
4098 si.fMask = SIF_POS;
4099 si.nPos = 20;
4100 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4101 if (sequence->message != WmSetScrollRangeSeq[0].message)
4102 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4103 flush_sequence();
4104
4105 si.fMask = SIF_RANGE;
4106 si.nMin = 0xdeadbeef;
4107 si.nMax = 0xdeadbeef;
4108 ret = GetScrollInfo(hwnd, SB_CTL, &si);
4109 ok( ret, "GetScrollInfo error %d\n", GetLastError());
4110 if (sequence->message != WmGetScrollInfoSeq[0].message)
4111 trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4112 /* values of min and max are undefined */
4113 flush_sequence();
4114
4115 /* set WS_HSCROLL */
4116 test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4117 /* clear WS_HSCROLL */
4118 test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4119
4120 /* set WS_HSCROLL */
4121 test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4122 /* clear WS_HSCROLL */
4123 test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4124
4125 /* set WS_VSCROLL */
4126 test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4127 /* clear WS_VSCROLL */
4128 test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4129
4130 /* set WS_VSCROLL */
4131 test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4132 /* clear WS_VSCROLL */
4133 test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4134 }
4135
4136 static void test_showwindow(void)
4137 {
4138 HWND hwnd, hchild;
4139 RECT rc;
4140
4141 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4142 100, 100, 200, 200, 0, 0, 0, NULL);
4143 ok (hwnd != 0, "Failed to create overlapped window\n");
4144 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4145 0, 0, 10, 10, hwnd, 0, 0, NULL);
4146 ok (hchild != 0, "Failed to create child\n");
4147 flush_sequence();
4148
4149 /* ShowWindow( SW_SHOWNA) for invisible top level window */
4150 trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
4151 ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4152 ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", FALSE);
4153
4154 /* ShowWindow( SW_SHOWNA) for now visible top level window */
4155 trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
4156 ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4157 ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
4158 /* back to invisible */
4159 ShowWindow(hchild, SW_HIDE);
4160 ShowWindow(hwnd, SW_HIDE);
4161 flush_sequence();
4162 /* ShowWindow(SW_SHOWNA) with child and parent invisible */
4163 trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
4164 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4165 ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
4166 /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */
4167 ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
4168 flush_sequence();
4169 trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
4170 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4171 ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
4172 /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
4173 ShowWindow( hwnd, SW_SHOW);
4174 flush_sequence();
4175 trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
4176 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4177 ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
4178
4179 /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
4180 ShowWindow( hchild, SW_HIDE);
4181 flush_sequence();
4182 trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
4183 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4184 ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
4185
4186 SetCapture(hchild);
4187 ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
4188 DestroyWindow(hchild);
4189 ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
4190
4191 DestroyWindow(hwnd);
4192 flush_sequence();
4193
4194 /* Popup windows */
4195 /* Test 1:
4196 * 1. Create invisible maximized popup window.
4197 * 2. Move and resize it.
4198 * 3. Show it maximized.
4199 */
4200 trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4201 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4202 100, 100, 200, 200, 0, 0, 0, NULL);
4203 ok (hwnd != 0, "Failed to create popup window\n");
4204 ok(IsZoomed(hwnd), "window should be maximized\n");
4205 ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4206
4207 GetWindowRect(hwnd, &rc);
4208 ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4209 rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4210 "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
4211 rc.left, rc.top, rc.right, rc.bottom);
4212 /* Reset window's size & position */
4213 SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
4214 ok(IsZoomed(hwnd), "window should be maximized\n");
4215 flush_sequence();
4216
4217 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4218 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4219 ok(IsZoomed(hwnd), "window should be maximized\n");
4220 ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
4221
4222 GetWindowRect(hwnd, &rc);
4223 ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4224 rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4225 "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
4226 rc.left, rc.top, rc.right, rc.bottom);
4227 DestroyWindow(hwnd);
4228 flush_sequence();
4229
4230 /* Test 2:
4231 * 1. Create invisible maximized popup window.
4232 * 2. Show it maximized.
4233 */
4234 trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4235 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4236 100, 100, 200, 200, 0, 0, 0, NULL);
4237 ok (hwnd != 0, "Failed to create popup window\n");
4238 ok(IsZoomed(hwnd), "window should be maximized\n");
4239 ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4240
4241 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4242 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4243 ok(IsZoomed(hwnd), "window should be maximized\n");
4244 ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
4245 DestroyWindow(hwnd);
4246 flush_sequence();
4247
4248 /* Test 3:
4249 * 1. Create visible maximized popup window.
4250 */
4251 trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
4252 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4253 100, 100, 200, 200, 0, 0, 0, NULL);
4254 ok (hwnd != 0, "Failed to create popup window\n");
4255 ok(IsZoomed(hwnd), "window should be maximized\n");
4256 ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4257 DestroyWindow(hwnd);
4258 flush_sequence();
4259
4260 /* Test 4:
4261 * 1. Create visible popup window.
4262 * 2. Maximize it.
4263 */
4264 trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
4265 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
4266 100, 100, 200, 200, 0, 0, 0, NULL);
4267 ok (hwnd != 0, "Failed to create popup window\n");
4268 ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
4269 ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
4270
4271 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
4272 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4273 ok(IsZoomed(hwnd), "window should be maximized\n");
4274 ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
4275 DestroyWindow(hwnd);
4276 flush_sequence();
4277 }
4278
4279 static void test_sys_menu(void)
4280 {
4281 HWND hwnd;
4282 HMENU hmenu;
4283 UINT state;
4284
4285 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4286 100, 100, 200, 200, 0, 0, 0, NULL);
4287 ok (hwnd != 0, "Failed to create overlapped window\n");
4288
4289 flush_sequence();
4290
4291 /* test existing window without CS_NOCLOSE style */
4292 hmenu = GetSystemMenu(hwnd, FALSE);
4293 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4294
4295 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4296 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4297 ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4298
4299 EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
4300 ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4301
4302 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4303 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4304 ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
4305
4306 EnableMenuItem(hmenu, SC_CLOSE, 0);
4307 ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4308
4309 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4310 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4311 ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4312
4313 /* test whether removing WS_SYSMENU destroys a system menu */
4314 SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
4315 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4316 flush_sequence();
4317 hmenu = GetSystemMenu(hwnd, FALSE);
4318 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4319
4320 DestroyWindow(hwnd);
4321
4322 /* test new window with CS_NOCLOSE style */
4323 hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4324 100, 100, 200, 200, 0, 0, 0, NULL);
4325 ok (hwnd != 0, "Failed to create overlapped window\n");
4326
4327 hmenu = GetSystemMenu(hwnd, FALSE);
4328 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4329
4330 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4331 ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4332
4333 DestroyWindow(hwnd);
4334
4335 /* test new window without WS_SYSMENU style */
4336 hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
4337 100, 100, 200, 200, 0, 0, 0, NULL);
4338 ok(hwnd != 0, "Failed to create overlapped window\n");
4339
4340 hmenu = GetSystemMenu(hwnd, FALSE);
4341 ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
4342
4343 DestroyWindow(hwnd);
4344 }
4345
4346 /* For shown WS_OVERLAPPEDWINDOW */
4347 static const struct message WmSetIcon_1[] = {
4348 { WM_SETICON, sent },
4349 { 0x00AE, sent|defwinproc|optional }, /* XP */
4350 { WM_GETTEXT, sent|defwinproc|optional },
4351 { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
4352 { 0 }
4353 };
4354
4355 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
4356 static const struct message WmSetIcon_2[] = {
4357 { WM_SETICON, sent },
4358 { 0 }
4359 };
4360
4361 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4362 static const struct message WmInitEndSession[] = {
4363 { 0x003B, sent },
4364 { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4365 { 0 }
4366 };
4367
4368 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4369 static const struct message WmInitEndSession_2[] = {
4370 { 0x003B, sent },
4371 { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4372 { 0 }
4373 };
4374
4375 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4376 static const struct message WmInitEndSession_3[] = {
4377 { 0x003B, sent },
4378 { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4379 { 0 }
4380 };
4381
4382 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4383 static const struct message WmInitEndSession_4[] = {
4384 { 0x003B, sent },
4385 { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4386 { 0 }
4387 };
4388
4389 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4390 static const struct message WmInitEndSession_5[] = {
4391 { 0x003B, sent },
4392 { WM_ENDSESSION, sent|defwinproc/*|wparam*/|lparam, 1, ENDSESSION_LOGOFF },
4393 { 0 }
4394 };
4395
4396 static const struct message WmOptionalPaint[] = {
4397 { WM_PAINT, sent|optional },
4398 { WM_NCPAINT, sent|beginpaint|optional },
4399 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4400 { WM_ERASEBKGND, sent|beginpaint|optional },
4401 { 0 }
4402 };
4403
4404 static const struct message WmZOrder[] = {
4405 { WM_WINDOWPOSCHANGING, sent|wparam, 0, 0 },
4406 { WM_GETMINMAXINFO, sent|defwinproc|wparam, 0, 0 },
4407 { HCBT_ACTIVATE, hook },
4408 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
4409 { WM_WINDOWPOSCHANGING, sent|wparam, 3, 0 },
4410 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0 },
4411 { WM_GETTEXT, sent|optional },
4412 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
4413 { WM_ACTIVATEAPP, sent|wparam, 1, 0 },
4414 { WM_NCACTIVATE, sent|lparam, 1, 0 },
4415 { WM_GETTEXT, sent|defwinproc|optional },
4416 { WM_GETTEXT, sent|defwinproc|optional },
4417 { WM_ACTIVATE, sent|wparam|lparam, 1, 0 },
4418 { HCBT_SETFOCUS, hook },
4419 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4420 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4421 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4422 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
4423 { WM_GETTEXT, sent|optional },
4424 { WM_NCCALCSIZE, sent|optional },
4425 { 0 }
4426 };
4427
4428 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4429 {
4430 DWORD ret;
4431 MSG msg;
4432
4433 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4434 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4435
4436 PostMessageA(hwnd, WM_USER, 0, 0);
4437
4438 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4439 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4440
4441 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4442 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4443
4444 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4445 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4446
4447 PostMessageA(hwnd, WM_USER, 0, 0);
4448
4449 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4450 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4451
4452 ok(PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4453 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4454
4455 /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4456 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4457 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4458
4459 PostMessageA(hwnd, WM_USER, 0, 0);
4460
4461 /* new incoming message causes it to become signaled again */
4462 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4463 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4464
4465 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4466 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4467 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4468 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4469 }
4470
4471 /* test if we receive the right sequence of messages */
4472 static void test_messages(void)
4473 {
4474 HWND hwnd, hparent, hchild;
4475 HWND hchild2, hbutton;
4476 HMENU hmenu;
4477 MSG msg;
4478 LRESULT res;
4479
4480 flush_sequence();
4481
4482 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4483 100, 100, 200, 200, 0, 0, 0, NULL);
4484 ok (hwnd != 0, "Failed to create overlapped window\n");
4485 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4486
4487 /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4488 ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4489 ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4490
4491 /* test WM_SETREDRAW on a not visible top level window */
4492 test_WM_SETREDRAW(hwnd);
4493
4494 SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4495 flush_events();
4496 ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4497 ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4498
4499 ok(GetActiveWindow() == hwnd, "window should be active\n");
4500 ok(GetFocus() == hwnd, "window should have input focus\n");
4501 ShowWindow(hwnd, SW_HIDE);
4502 flush_events();
4503 ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4504
4505 ShowWindow(hwnd, SW_SHOW);
4506 flush_events();
4507 ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4508
4509 ShowWindow(hwnd, SW_HIDE);
4510 flush_events();
4511 ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4512
4513 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4514 flush_events();
4515 ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4516 flush_sequence();
4517
4518 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MAXIMIZE)
4519 {
4520 ShowWindow(hwnd, SW_RESTORE);
4521 flush_events();
4522 ok_sequence(WmShowRestoreMaxOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4523 flush_sequence();
4524 }
4525
4526 ShowWindow(hwnd, SW_MINIMIZE);
4527 flush_events();
4528 ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4529 flush_sequence();
4530
4531 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MINIMIZE)
4532 {
4533 ShowWindow(hwnd, SW_RESTORE);
4534 flush_events();
4535 ok_sequence(WmShowRestoreMinOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4536 flush_sequence();
4537 }
4538
4539 ShowWindow(hwnd, SW_SHOW);
4540 flush_events();
4541 ok_sequence(WmOptionalPaint, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4542
4543 SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4544 ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4545 ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4546 ok(GetActiveWindow() == hwnd, "window should still be active\n");
4547
4548 /* test WM_SETREDRAW on a visible top level window */
4549 ShowWindow(hwnd, SW_SHOW);
4550 flush_events();
4551 test_WM_SETREDRAW(hwnd);
4552
4553 trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4554 test_scroll_messages(hwnd);
4555
4556 /* test resizing and moving */
4557 SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4558 ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4559 flush_events();
4560 flush_sequence();
4561 SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4562 ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4563 flush_events();
4564 flush_sequence();
4565 SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER|SWP_NOACTIVATE );
4566 ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4567 flush_events();
4568 flush_sequence();
4569
4570 /* popups don't get WM_GETMINMAXINFO */
4571 SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4572 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4573 flush_sequence();
4574 SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4575 ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4576
4577 DestroyWindow(hwnd);
4578 ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4579
4580 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4581 100, 100, 200, 200, 0, 0, 0, NULL);
4582 ok (hparent != 0, "Failed to create parent window\n");
4583 flush_sequence();
4584
4585 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4586 0, 0, 10, 10, hparent, 0, 0, NULL);
4587 ok (hchild != 0, "Failed to create child window\n");
4588 ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4589 DestroyWindow(hchild);
4590 flush_sequence();
4591
4592 /* visible child window with a caption */
4593 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4594 WS_CHILD | WS_VISIBLE | WS_CAPTION,
4595 0, 0, 10, 10, hparent, 0, 0, NULL);
4596 ok (hchild != 0, "Failed to create child window\n");
4597 ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4598
4599 trace("testing scroll APIs on a visible child window %p\n", hchild);
4600 test_scroll_messages(hchild);
4601
4602 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4603 ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4604
4605 DestroyWindow(hchild);
4606 flush_sequence();
4607
4608 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4609 0, 0, 10, 10, hparent, 0, 0, NULL);
4610 ok (hchild != 0, "Failed to create child window\n");
4611 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4612
4613 hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4614 100, 100, 50, 50, hparent, 0, 0, NULL);
4615 ok (hchild2 != 0, "Failed to create child2 window\n");
4616 flush_sequence();
4617
4618 hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4619 0, 100, 50, 50, hchild, 0, 0, NULL);
4620 ok (hbutton != 0, "Failed to create button window\n");
4621
4622 /* test WM_SETREDRAW on a not visible child window */
4623 test_WM_SETREDRAW(hchild);
4624
4625 ShowWindow(hchild, SW_SHOW);
4626 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4627
4628 /* check parent messages too */
4629 log_all_parent_messages++;
4630 ShowWindow(hchild, SW_HIDE);
4631 ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4632 log_all_parent_messages--;
4633
4634 ShowWindow(hchild, SW_SHOW);
4635 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4636
4637 ShowWindow(hchild, SW_HIDE);
4638 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4639
4640 ShowWindow(hchild, SW_SHOW);
4641 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4642
4643 /* test WM_SETREDRAW on a visible child window */
4644 test_WM_SETREDRAW(hchild);
4645
4646 log_all_parent_messages++;
4647 MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4648 ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4649 log_all_parent_messages--;
4650
4651 ShowWindow(hchild, SW_HIDE);
4652 flush_sequence();
4653 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4654 ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4655
4656 ShowWindow(hchild, SW_HIDE);
4657 flush_sequence();
4658 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4659 ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4660
4661 /* DestroyWindow sequence below expects that a child has focus */
4662 SetFocus(hchild);
4663 flush_sequence();
4664
4665 DestroyWindow(hchild);
4666 ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4667 DestroyWindow(hchild2);
4668 DestroyWindow(hbutton);
4669
4670 flush_sequence();
4671 hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4672 0, 0, 100, 100, hparent, 0, 0, NULL);
4673 ok (hchild != 0, "Failed to create child popup window\n");
4674 ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4675 DestroyWindow(hchild);
4676
4677 /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4678 flush_sequence();
4679 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4680 0, 0, 100, 100, hparent, 0, 0, NULL);
4681 ok (hchild != 0, "Failed to create popup window\n");
4682 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4683 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4684 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4685 flush_sequence();
4686 ShowWindow(hchild, SW_SHOW);
4687 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4688 flush_sequence();
4689 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4690 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4691 flush_sequence();
4692 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4693 ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
4694 DestroyWindow(hchild);
4695
4696 /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4697 * changes nothing in message sequences.
4698 */
4699 flush_sequence();
4700 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4701 0, 0, 100, 100, hparent, 0, 0, NULL);
4702 ok (hchild != 0, "Failed to create popup window\n");
4703 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4704 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4705 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4706 flush_sequence();
4707 ShowWindow(hchild, SW_SHOW);
4708 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4709 flush_sequence();
4710 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4711 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4712 DestroyWindow(hchild);
4713
4714 flush_sequence();
4715 hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4716 0, 0, 100, 100, hparent, 0, 0, NULL);
4717 ok(hwnd != 0, "Failed to create custom dialog window\n");
4718 ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4719
4720 if(0) {
4721 trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4722 test_scroll_messages(hwnd);
4723 }
4724
4725 flush_sequence();
4726
4727 test_def_id = 1;
4728 SendMessage(hwnd, WM_NULL, 0, 0);
4729
4730 flush_sequence();
4731 after_end_dialog = 1;
4732 EndDialog( hwnd, 0 );
4733 ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4734
4735 DestroyWindow(hwnd);
4736 after_end_dialog = 0;
4737 test_def_id = 0;
4738
4739 hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4740 0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4741 ok(hwnd != 0, "Failed to create custom dialog window\n");
4742 flush_sequence();
4743 trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4744 ShowWindow(hwnd, SW_SHOW);
4745 ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4746 DestroyWindow(hwnd);
4747
4748 flush_sequence();
4749 DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4750 ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4751
4752 DestroyWindow(hparent);
4753 flush_sequence();
4754
4755 /* Message sequence for SetMenu */
4756 ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4757 ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4758
4759 hmenu = CreateMenu();
4760 ok (hmenu != 0, "Failed to create menu\n");
4761 ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4762 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4763 100, 100, 200, 200, 0, hmenu, 0, NULL);
4764 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4765 ok (SetMenu(hwnd, 0), "SetMenu\n");
4766 ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4767 ok (SetMenu(hwnd, 0), "SetMenu\n");
4768 ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4769 ShowWindow(hwnd, SW_SHOW);
4770 UpdateWindow( hwnd );
4771 flush_events();
4772 flush_sequence();
4773 ok (SetMenu(hwnd, 0), "SetMenu\n");
4774 ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4775 ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4776 ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4777
4778 UpdateWindow( hwnd );
4779 flush_events();
4780 flush_sequence();
4781 ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4782 flush_events();
4783 ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4784
4785 DestroyWindow(hwnd);
4786 flush_sequence();
4787
4788 /* Message sequence for EnableWindow */
4789 hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4790 100, 100, 200, 200, 0, 0, 0, NULL);
4791 ok (hparent != 0, "Failed to create parent window\n");
4792 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4793 0, 0, 10, 10, hparent, 0, 0, NULL);
4794 ok (hchild != 0, "Failed to create child window\n");
4795
4796 SetFocus(hchild);
4797 flush_events();
4798 flush_sequence();
4799
4800 EnableWindow(hparent, FALSE);
4801 ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4802
4803 EnableWindow(hparent, TRUE);
4804 ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4805
4806 flush_events();
4807 flush_sequence();
4808
4809 test_MsgWaitForMultipleObjects(hparent);
4810
4811 /* the following test causes an exception in user.exe under win9x */
4812 if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4813 {
4814 DestroyWindow(hparent);
4815 flush_sequence();
4816 return;
4817 }
4818 PostMessageW( hparent, WM_USER+1, 0, 0 );
4819 /* PeekMessage(NULL) fails, but still removes the message */
4820 SetLastError(0xdeadbeef);
4821 ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4822 ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4823 GetLastError() == 0xdeadbeef, /* NT4 */
4824 "last error is %d\n", GetLastError() );
4825 ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4826 ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4827
4828 DestroyWindow(hchild);
4829 DestroyWindow(hparent);
4830 flush_sequence();
4831
4832 /* Message sequences for WM_SETICON */
4833 trace("testing WM_SETICON\n");
4834 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4835 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4836 NULL, NULL, 0);
4837 ShowWindow(hwnd, SW_SHOW);
4838 UpdateWindow(hwnd);
4839 flush_events();
4840 flush_sequence();
4841 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4842 ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4843
4844 ShowWindow(hwnd, SW_HIDE);
4845 flush_events();
4846 flush_sequence();
4847 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4848 ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4849 DestroyWindow(hwnd);
4850 flush_sequence();
4851
4852 hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4853 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4854 NULL, NULL, 0);
4855 ShowWindow(hwnd, SW_SHOW);
4856 UpdateWindow(hwnd);
4857 flush_events();
4858 flush_sequence();
4859 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4860 ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4861
4862 ShowWindow(hwnd, SW_HIDE);
4863 flush_events();
4864 flush_sequence();
4865 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4866 ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4867
4868 flush_sequence();
4869 res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4870 if (!res)
4871 {
4872 todo_wine win_skip( "Message 0x3b not supported\n" );
4873 goto done;
4874 }
4875 ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4876 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4877 res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4878 ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4879 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4880 res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4881 ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4882 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4883
4884 flush_sequence();
4885 res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4886 ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4887 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4888 res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4889 ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4890 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4891
4892 res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4893 ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4894 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4895
4896 res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4897 ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4898 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4899
4900 done:
4901 DestroyWindow(hwnd);
4902 flush_sequence();
4903 }
4904
4905 static void test_setwindowpos(void)
4906 {
4907 HWND hwnd;
4908 RECT rc;
4909 LRESULT res;
4910 const INT winX = 100;
4911 const INT winY = 100;
4912 const INT sysX = GetSystemMetrics(SM_CXMINTRACK);
4913
4914 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
4915 0, 0, winX, winY, 0,
4916 NULL, NULL, 0);
4917
4918 GetWindowRect(hwnd, &rc);
4919 expect(sysX, rc.right);
4920 expect(winY, rc.bottom);
4921
4922 flush_events();
4923 flush_sequence();
4924 res = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, winX, winY, 0);
4925 ok_sequence(WmZOrder, "Z-Order", TRUE);
4926 ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
4927
4928 GetWindowRect(hwnd, &rc);
4929 expect(sysX, rc.right);
4930 expect(winY, rc.bottom);
4931 DestroyWindow(hwnd);
4932 }
4933
4934 static void invisible_parent_tests(void)
4935 {
4936 HWND hparent, hchild;
4937
4938 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4939 100, 100, 200, 200, 0, 0, 0, NULL);
4940 ok (hparent != 0, "Failed to create parent window\n");
4941 flush_sequence();
4942
4943 /* test showing child with hidden parent */
4944
4945 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4946 0, 0, 10, 10, hparent, 0, 0, NULL);
4947 ok (hchild != 0, "Failed to create child window\n");
4948 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4949
4950 ShowWindow( hchild, SW_MINIMIZE );
4951 ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4952 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4953 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4954
4955 /* repeat */
4956 flush_events();
4957 flush_sequence();
4958 ShowWindow( hchild, SW_MINIMIZE );
4959 ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4960
4961 DestroyWindow(hchild);
4962 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4963 0, 0, 10, 10, hparent, 0, 0, NULL);
4964 flush_sequence();
4965
4966 ShowWindow( hchild, SW_MAXIMIZE );
4967 ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4968 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4969 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4970
4971 /* repeat */
4972 flush_events();
4973 flush_sequence();
4974 ShowWindow( hchild, SW_MAXIMIZE );
4975 ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4976
4977 DestroyWindow(hchild);
4978 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4979 0, 0, 10, 10, hparent, 0, 0, NULL);
4980 flush_sequence();
4981
4982 ShowWindow( hchild, SW_RESTORE );
4983 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
4984 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4985 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4986
4987 DestroyWindow(hchild);
4988 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4989 0, 0, 10, 10, hparent, 0, 0, NULL);
4990 flush_sequence();
4991
4992 ShowWindow( hchild, SW_SHOWMINIMIZED );
4993 ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4994 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4995 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4996
4997 /* repeat */
4998 flush_events();
4999 flush_sequence();
5000 ShowWindow( hchild, SW_SHOWMINIMIZED );
5001 ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
5002
5003 DestroyWindow(hchild);
5004 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5005 0, 0, 10, 10, hparent, 0, 0, NULL);
5006 flush_sequence();
5007
5008 /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
5009 ShowWindow( hchild, SW_SHOWMAXIMIZED );
5010 ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
5011 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5012 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5013
5014 DestroyWindow(hchild);
5015 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5016 0, 0, 10, 10, hparent, 0, 0, NULL);
5017 flush_sequence();
5018
5019 ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5020 ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5021 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5022 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5023
5024 /* repeat */
5025 flush_events();
5026 flush_sequence();
5027 ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5028 ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5029
5030 DestroyWindow(hchild);
5031 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5032 0, 0, 10, 10, hparent, 0, 0, NULL);
5033 flush_sequence();
5034
5035 /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
5036 ShowWindow( hchild, SW_FORCEMINIMIZE );
5037 ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
5038 todo_wine {
5039 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5040 }
5041 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5042
5043 DestroyWindow(hchild);
5044 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5045 0, 0, 10, 10, hparent, 0, 0, NULL);
5046 flush_sequence();
5047
5048 ShowWindow( hchild, SW_SHOWNA );
5049 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5050 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5051 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5052
5053 /* repeat */
5054 flush_events();
5055 flush_sequence();
5056 ShowWindow( hchild, SW_SHOWNA );
5057 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5058
5059 DestroyWindow(hchild);
5060 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5061 0, 0, 10, 10, hparent, 0, 0, NULL);
5062 flush_sequence();
5063
5064 ShowWindow( hchild, SW_SHOW );
5065 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5066 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5067 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5068
5069 /* repeat */
5070 flush_events();
5071 flush_sequence();
5072 ShowWindow( hchild, SW_SHOW );
5073 ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5074
5075 ShowWindow( hchild, SW_HIDE );
5076 ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
5077 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5078 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5079
5080 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5081 ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
5082 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5083 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5084
5085 SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5086 ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
5087 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
5088 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5089
5090 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5091 flush_sequence();
5092 DestroyWindow(hchild);
5093 ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
5094
5095 DestroyWindow(hparent);
5096 flush_sequence();
5097 }
5098
5099 /****************** button message test *************************/
5100 #define ID_BUTTON 0x000e
5101
5102 static const struct message WmSetFocusButtonSeq[] =
5103 {
5104 { HCBT_SETFOCUS, hook },
5105 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5106 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5107 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5108 { WM_SETFOCUS, sent|wparam, 0 },
5109 { WM_CTLCOLORBTN, sent|parent },
5110 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5111 { WM_APP, sent|wparam|lparam, 0, 0 },
5112 { 0 }
5113 };
5114 static const struct message WmKillFocusButtonSeq[] =
5115 {
5116 { HCBT_SETFOCUS, hook },
5117 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5118 { WM_KILLFOCUS, sent|wparam, 0 },
5119 { WM_CTLCOLORBTN, sent|parent },
5120 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5121 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5122 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5123 { WM_APP, sent|wparam|lparam, 0, 0 },
5124 { WM_PAINT, sent },
5125 { WM_CTLCOLORBTN, sent|parent },
5126 { 0 }
5127 };
5128 static const struct message WmSetFocusStaticSeq[] =
5129 {
5130 { HCBT_SETFOCUS, hook },
5131 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5132 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5133 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5134 { WM_SETFOCUS, sent|wparam, 0 },
5135 { WM_CTLCOLORSTATIC, sent|parent },
5136 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5137 { WM_COMMAND, sent|wparam|parent|optional, MAKEWPARAM(ID_BUTTON, BN_CLICKED) }, /* radio button */
5138 { WM_APP, sent|wparam|lparam, 0, 0 },
5139 { 0 }
5140 };
5141 static const struct message WmKillFocusStaticSeq[] =
5142 {
5143 { HCBT_SETFOCUS, hook },
5144 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5145 { WM_KILLFOCUS, sent|wparam, 0 },
5146 { WM_CTLCOLORSTATIC, sent|parent },
5147 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5148 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5149 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5150 { WM_APP, sent|wparam|lparam, 0, 0 },
5151 { WM_PAINT, sent },
5152 { WM_CTLCOLORSTATIC, sent|parent },
5153 { 0 }
5154 };
5155 static const struct message WmSetFocusOwnerdrawSeq[] =
5156 {
5157 { HCBT_SETFOCUS, hook },
5158 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5159 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5160 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5161 { WM_SETFOCUS, sent|wparam, 0 },
5162 { WM_CTLCOLORBTN, sent|parent },
5163 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x001040e4 },
5164 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5165 { WM_APP, sent|wparam|lparam, 0, 0 },
5166 { 0 }
5167 };
5168 static const struct message WmKillFocusOwnerdrawSeq[] =
5169 {
5170 { HCBT_SETFOCUS, hook },
5171 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5172 { WM_KILLFOCUS, sent|wparam, 0 },
5173 { WM_CTLCOLORBTN, sent|parent },
5174 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000040e4 },
5175 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5176 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5177 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5178 { WM_APP, sent|wparam|lparam, 0, 0 },
5179 { WM_PAINT, sent },
5180 { WM_CTLCOLORBTN, sent|parent },
5181 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 },
5182 { 0 }
5183 };
5184 static const struct message WmLButtonDownSeq[] =
5185 {
5186 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
5187 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5188 { HCBT_SETFOCUS, hook },
5189 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
5190 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5191 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5192 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
5193 { WM_CTLCOLORBTN, sent|defwinproc },
5194 { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
5195 { WM_CTLCOLORBTN, sent|defwinproc },
5196 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5197 { 0 }
5198 };
5199 static const struct message WmLButtonUpSeq[] =
5200 {
5201 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
5202 { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
5203 { WM_CTLCOLORBTN, sent|defwinproc },
5204 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5205 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5206 { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
5207 { 0 }
5208 };
5209 static const struct message WmSetFontButtonSeq[] =
5210 {
5211 { WM_SETFONT, sent },
5212 { WM_PAINT, sent },
5213 { WM_ERASEBKGND, sent|defwinproc|optional },
5214 { WM_CTLCOLORBTN, sent|defwinproc },
5215 { 0 }
5216 };
5217 static const struct message WmSetStyleButtonSeq[] =
5218 {
5219 { BM_SETSTYLE, sent },
5220 { WM_APP, sent|wparam|lparam, 0, 0 },
5221 { WM_PAINT, sent },
5222 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5223 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5224 { WM_CTLCOLORBTN, sent|parent },
5225 { 0 }
5226 };
5227 static const struct message WmSetStyleStaticSeq[] =
5228 {
5229 { BM_SETSTYLE, sent },
5230 { WM_APP, sent|wparam|lparam, 0, 0 },
5231 { WM_PAINT, sent },
5232 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5233 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5234 { WM_CTLCOLORSTATIC, sent|parent },
5235 { 0 }
5236 };
5237 static const struct message WmSetStyleUserSeq[] =
5238 {
5239 { BM_SETSTYLE, sent },
5240 { WM_APP, sent|wparam|lparam, 0, 0 },
5241 { WM_PAINT, sent },
5242 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5243 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5244 { WM_CTLCOLORBTN, sent|parent },
5245 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_PAINT) },
5246 { 0 }
5247 };
5248 static const struct message WmSetStyleOwnerdrawSeq[] =
5249 {
5250 { BM_SETSTYLE, sent },
5251 { WM_APP, sent|wparam|lparam, 0, 0 },
5252 { WM_PAINT, sent },
5253 { WM_NCPAINT, sent|optional }, /* FIXME: Wine sends it */
5254 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5255 { WM_CTLCOLORBTN, sent|parent },
5256 { WM_CTLCOLORBTN, sent|parent|optional }, /* Win9x doesn't send it */
5257 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 },
5258 { 0 }
5259 };
5260 static const struct message WmSetStateButtonSeq[] =
5261 {
5262 { BM_SETSTATE, sent },
5263 { WM_CTLCOLORBTN, sent|parent },
5264 { WM_APP, sent|wparam|lparam, 0, 0 },
5265 { 0 }
5266 };
5267 static const struct message WmSetStateStaticSeq[] =
5268 {
5269 { BM_SETSTATE, sent },
5270 { WM_CTLCOLORSTATIC, sent|parent },
5271 { WM_APP, sent|wparam|lparam, 0, 0 },
5272 { 0 }
5273 };
5274 static const struct message WmSetStateUserSeq[] =
5275 {
5276 { BM_SETSTATE, sent },
5277 { WM_CTLCOLORBTN, sent|parent },
5278 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_HILITE) },
5279 { WM_APP, sent|wparam|lparam, 0, 0 },
5280 { 0 }
5281 };
5282 static const struct message WmSetStateOwnerdrawSeq[] =
5283 {
5284 { BM_SETSTATE, sent },
5285 { WM_CTLCOLORBTN, sent|parent },
5286 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000120e4 },
5287 { WM_APP, sent|wparam|lparam, 0, 0 },
5288 { 0 }
5289 };
5290 static const struct message WmClearStateButtonSeq[] =
5291 {
5292 { BM_SETSTATE, sent },
5293 { WM_CTLCOLORBTN, sent|parent },
5294 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_UNHILITE) },
5295 { WM_APP, sent|wparam|lparam, 0, 0 },
5296 { 0 }
5297 };
5298 static const struct message WmClearStateOwnerdrawSeq[] =
5299 {
5300 { BM_SETSTATE, sent },
5301 { WM_CTLCOLORBTN, sent|parent },
5302 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000020e4 },
5303 { WM_APP, sent|wparam|lparam, 0, 0 },
5304 { 0 }
5305 };
5306 static const struct message WmSetCheckIgnoredSeq[] =
5307 {
5308 { BM_SETCHECK, sent },
5309 { WM_APP, sent|wparam|lparam, 0, 0 },
5310 { 0 }
5311 };
5312 static const struct message WmSetCheckStaticSeq[] =
5313 {
5314 { BM_SETCHECK, sent },
5315 { WM_CTLCOLORSTATIC, sent|parent },
5316 { WM_APP, sent|wparam|lparam, 0, 0 },
5317 { 0 }
5318 };
5319
5320 static WNDPROC old_button_proc;
5321
5322 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5323 {
5324 static LONG defwndproc_counter = 0;
5325 LRESULT ret;
5326 struct recvd_message msg;
5327
5328 if (ignore_message( message )) return 0;
5329
5330 switch (message)
5331 {
5332 case WM_SYNCPAINT:
5333 break;
5334 case BM_SETSTATE:
5335 if (GetCapture())
5336 ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
5337 /* fall through */
5338 default:
5339 msg.hwnd = hwnd;
5340 msg.message = message;
5341 msg.flags = sent|wparam|lparam;
5342 if (defwndproc_counter) msg.flags |= defwinproc;
5343 msg.wParam = wParam;
5344 msg.lParam = lParam;
5345 msg.descr = "button";
5346 add_message(&msg);
5347 }
5348
5349 defwndproc_counter++;
5350 ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
5351 defwndproc_counter--;
5352
5353 return ret;
5354 }
5355
5356 static void subclass_button(void)
5357 {
5358 WNDCLASSA cls;
5359
5360 if (!GetClassInfoA(0, "button", &cls)) assert(0);
5361
5362 old_button_proc = cls.lpfnWndProc;
5363
5364 cls.hInstance = GetModuleHandle(0);
5365 cls.lpfnWndProc = button_hook_proc;
5366 cls.lpszClassName = "my_button_class";
5367 UnregisterClass(cls.lpszClassName, cls.hInstance);
5368 if (!RegisterClassA(&cls)) assert(0);
5369 }
5370
5371 static void test_button_messages(void)
5372 {
5373 static const struct
5374 {
5375 DWORD style;
5376 DWORD dlg_code;
5377 const struct message *setfocus;
5378 const struct message *killfocus;
5379 const struct message *setstyle;
5380 const struct message *setstate;
5381 const struct message *clearstate;
5382 const struct message *setcheck;
5383 } button[] = {
5384 { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5385 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq,
5386 WmSetStateButtonSeq, WmSetStateButtonSeq, WmSetCheckIgnoredSeq },
5387 { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
5388 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq,
5389 WmSetStateButtonSeq, WmSetStateButtonSeq, WmSetCheckIgnoredSeq },
5390 { BS_CHECKBOX, DLGC_BUTTON,
5391 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5392 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5393 { BS_AUTOCHECKBOX, DLGC_BUTTON,
5394 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5395 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5396 { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5397 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5398 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5399 { BS_3STATE, DLGC_BUTTON,
5400 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5401 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5402 { BS_AUTO3STATE, DLGC_BUTTON,
5403 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5404 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5405 { BS_GROUPBOX, DLGC_STATIC,
5406 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5407 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckIgnoredSeq },
5408 { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5409 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleUserSeq,
5410 WmSetStateUserSeq, WmClearStateButtonSeq, WmSetCheckIgnoredSeq },
5411 { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5412 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5413 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5414 { BS_OWNERDRAW, DLGC_BUTTON,
5415 WmSetFocusOwnerdrawSeq, WmKillFocusOwnerdrawSeq, WmSetStyleOwnerdrawSeq,
5416 WmSetStateOwnerdrawSeq, WmClearStateOwnerdrawSeq, WmSetCheckIgnoredSeq },
5417 };
5418 unsigned int i;
5419 HWND hwnd, parent;
5420 DWORD dlg_code;
5421 HFONT zfont;
5422
5423 /* selection with VK_SPACE should capture button window */
5424 hwnd = CreateWindowExA(0, "button", "test", BS_CHECKBOX | WS_VISIBLE | WS_POPUP,
5425 0, 0, 50, 14, 0, 0, 0, NULL);
5426 ok(hwnd != 0, "Failed to create button window\n");
5427 ReleaseCapture();
5428 SetFocus(hwnd);
5429 SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
5430 ok(GetCapture() == hwnd, "Should be captured on VK_SPACE WM_KEYDOWN\n");
5431 SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
5432 DestroyWindow(hwnd);
5433
5434 subclass_button();
5435
5436 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5437 100, 100, 200, 200, 0, 0, 0, NULL);
5438 ok(parent != 0, "Failed to create parent window\n");
5439
5440 for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
5441 {
5442 MSG msg;
5443 DWORD style, state;
5444
5445 trace("button style %08x\n", button[i].style);
5446
5447 hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_CHILD | BS_NOTIFY,
5448 0, 0, 50, 14, parent, (HMENU)ID_BUTTON, 0, NULL);
5449 ok(hwnd != 0, "Failed to create button window\n");
5450
5451 style = GetWindowLongA(hwnd, GWL_STYLE);
5452 style &= ~(WS_CHILD | BS_NOTIFY);
5453 /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
5454 if (button[i].style == BS_USERBUTTON)
5455 ok(style == BS_PUSHBUTTON, "expected style BS_PUSHBUTTON got %x\n", style);
5456 else
5457 ok(style == button[i].style, "expected style %x got %x\n", button[i].style, style);
5458
5459 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5460 ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5461
5462 ShowWindow(hwnd, SW_SHOW);
5463 UpdateWindow(hwnd);
5464 SetFocus(0);
5465 flush_events();
5466 SetFocus(0);
5467 flush_sequence();
5468
5469 log_all_parent_messages++;
5470
5471 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
5472 SetFocus(hwnd);
5473 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5474 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5475 ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
5476
5477 SetFocus(0);
5478 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5479 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5480 ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
5481
5482 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
5483
5484 SendMessage(hwnd, BM_SETSTYLE, button[i].style | BS_BOTTOM, TRUE);
5485 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5486 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5487 ok_sequence(button[i].setstyle, "BM_SETSTYLE on a button", FALSE);
5488
5489 style = GetWindowLongA(hwnd, GWL_STYLE);
5490 style &= ~(WS_VISIBLE | WS_CHILD | BS_NOTIFY);
5491 /* XP doesn't turn a BS_USERBUTTON into BS_PUSHBUTTON here! */
5492 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5493
5494 state = SendMessage(hwnd, BM_GETSTATE, 0, 0);
5495 ok(state == 0, "expected state 0, got %04x\n", state);
5496
5497 flush_sequence();
5498
5499 SendMessage(hwnd, BM_SETSTATE, TRUE, 0);
5500 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5501 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5502 ok_sequence(button[i].setstate, "BM_SETSTATE/TRUE on a button", FALSE);
5503
5504 state = SendMessage(hwnd, BM_GETSTATE, 0, 0);
5505 ok(state == 0x0004, "expected state 0x0004, got %04x\n", state);
5506
5507 style = GetWindowLongA(hwnd, GWL_STYLE);
5508 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5509 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5510
5511 flush_sequence();
5512
5513 SendMessage(hwnd, BM_SETSTATE, FALSE, 0);
5514 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5515 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5516 ok_sequence(button[i].clearstate, "BM_SETSTATE/FALSE on a button", FALSE);
5517
5518 state = SendMessage(hwnd, BM_GETSTATE, 0, 0);
5519 ok(state == 0, "expected state 0, got %04x\n", state);
5520
5521 style = GetWindowLongA(hwnd, GWL_STYLE);
5522 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5523 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5524
5525 state = SendMessage(hwnd, BM_GETCHECK, 0, 0);
5526 ok(state == BST_UNCHECKED, "expected BST_UNCHECKED, got %04x\n", state);
5527
5528 flush_sequence();
5529
5530 SendMessage(hwnd, BM_SETCHECK, BST_UNCHECKED, 0);
5531 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5532 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5533 ok_sequence(WmSetCheckIgnoredSeq, "BM_SETCHECK on a button", FALSE);
5534
5535 state = SendMessage(hwnd, BM_GETCHECK, 0, 0);
5536 ok(state == BST_UNCHECKED, "expected BST_UNCHECKED, got %04x\n", state);
5537
5538 style = GetWindowLongA(hwnd, GWL_STYLE);
5539 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5540 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5541
5542 flush_sequence();
5543
5544 SendMessage(hwnd, BM_SETCHECK, BST_CHECKED, 0);
5545 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5546 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5547 ok_sequence(button[i].setcheck, "BM_SETCHECK on a button", FALSE);
5548
5549 state = SendMessage(hwnd, BM_GETCHECK, 0, 0);
5550 if (button[i].style == BS_PUSHBUTTON ||
5551 button[i].style == BS_DEFPUSHBUTTON ||
5552 button[i].style == BS_GROUPBOX ||
5553 button[i].style == BS_USERBUTTON ||
5554 button[i].style == BS_OWNERDRAW)
5555 ok(state == BST_UNCHECKED, "expected check 0, got %04x\n", state);
5556 else
5557 ok(state == BST_CHECKED, "expected check 1, got %04x\n", state);
5558
5559 style = GetWindowLongA(hwnd, GWL_STYLE);
5560 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5561 if (button[i].style == BS_RADIOBUTTON ||
5562 button[i].style == BS_AUTORADIOBUTTON)
5563 ok(style == (button[i].style | WS_TABSTOP), "expected style %04x | WS_TABSTOP got %04x\n", button[i].style, style);
5564 else
5565 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5566
5567 log_all_parent_messages--;
5568
5569 DestroyWindow(hwnd);
5570 }
5571
5572 DestroyWindow(parent);
5573
5574 hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
5575 0, 0, 50, 14, 0, 0, 0, NULL);
5576 ok(hwnd != 0, "Failed to create button window\n");
5577
5578 SetForegroundWindow(hwnd);
5579 flush_events();
5580
5581 SetActiveWindow(hwnd);
5582 SetFocus(0);
5583 flush_sequence();
5584
5585 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
5586 ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
5587
5588 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
5589 ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
5590
5591 flush_sequence();
5592 zfont = GetStockObject(SYSTEM_FONT);
5593 SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
5594 UpdateWindow(hwnd);
5595 ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
5596
5597 DestroyWindow(hwnd);
5598 }
5599
5600 /****************** static message test *************************/
5601 static const struct message WmSetFontStaticSeq[] =
5602 {
5603 { WM_SETFONT, sent },
5604 { WM_PAINT, sent|defwinproc|optional },
5605 { WM_ERASEBKGND, sent|defwinproc|optional },
5606 { WM_CTLCOLORSTATIC, sent|defwinproc|optional },
5607 { 0 }
5608 };
5609
5610 static WNDPROC old_static_proc;
5611
5612 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5613 {
5614 static LONG defwndproc_counter = 0;
5615 LRESULT ret;
5616 struct recvd_message msg;
5617
5618 if (ignore_message( message )) return 0;
5619
5620 msg.hwnd = hwnd;
5621 msg.message = message;
5622 msg.flags = sent|wparam|lparam;
5623 if (defwndproc_counter) msg.flags |= defwinproc;
5624 msg.wParam = wParam;
5625 msg.lParam = lParam;
5626 msg.descr = "static";
5627 add_message(&msg);
5628
5629 defwndproc_counter++;
5630 ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
5631 defwndproc_counter--;
5632
5633 return ret;
5634 }
5635
5636 static void subclass_static(void)
5637 {
5638 WNDCLASSA cls;
5639
5640 if (!GetClassInfoA(0, "static", &cls)) assert(0);
5641
5642 old_static_proc = cls.lpfnWndProc;
5643
5644 cls.hInstance = GetModuleHandle(0);
5645 cls.lpfnWndProc = static_hook_proc;
5646 cls.lpszClassName = "my_static_class";
5647 UnregisterClass(cls.lpszClassName, cls.hInstance);
5648 if (!RegisterClassA(&cls)) assert(0);
5649 }
5650
5651 static void test_static_messages(void)
5652 {
5653 /* FIXME: make as comprehensive as the button message test */
5654 static const struct
5655 {
5656 DWORD style;
5657 DWORD dlg_code;
5658 const struct message *setfont;
5659 } static_ctrl[] = {
5660 { SS_LEFT, DLGC_STATIC,
5661 WmSetFontStaticSeq }
5662 };
5663 unsigned int i;
5664 HWND hwnd;
5665 DWORD dlg_code;
5666
5667 subclass_static();
5668
5669 for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
5670 {
5671 hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
5672 0, 0, 50, 14, 0, 0, 0, NULL);
5673 ok(hwnd != 0, "Failed to create static window\n");
5674
5675 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5676 ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5677
5678 ShowWindow(hwnd, SW_SHOW);
5679 UpdateWindow(hwnd);
5680 SetFocus(0);
5681 flush_sequence();
5682
5683 trace("static style %08x\n", static_ctrl[i].style);
5684 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
5685 ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
5686
5687 DestroyWindow(hwnd);
5688 }
5689 }
5690
5691 /****************** ComboBox message test *************************/
5692 #define ID_COMBOBOX 0x000f
5693
5694 static const struct message WmKeyDownComboSeq[] =
5695 {
5696 { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
5697 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
5698 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
5699 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
5700 { WM_CTLCOLOREDIT, sent|parent },
5701 { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
5702 { 0 }
5703 };
5704
5705 static WNDPROC old_combobox_proc;
5706
5707 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5708 {
5709 static LONG defwndproc_counter = 0;
5710 LRESULT ret;
5711 struct recvd_message msg;
5712
5713 /* do not log painting messages */
5714 if (message != WM_PAINT &&
5715 message != WM_NCPAINT &&
5716 message != WM_SYNCPAINT &&
5717 message != WM_ERASEBKGND &&
5718 message != WM_NCHITTEST &&
5719 message != WM_GETTEXT &&
5720 !ignore_message( message ))
5721 {
5722 msg.hwnd = hwnd;
5723 msg.message = message;
5724 msg.flags = sent|wparam|lparam;
5725 if (defwndproc_counter) msg.flags |= defwinproc;
5726 msg.wParam = wParam;
5727 msg.lParam = lParam;
5728 msg.descr = "combo";
5729 add_message(&msg);
5730 }
5731
5732 defwndproc_counter++;
5733 ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5734 defwndproc_counter--;
5735
5736 return ret;
5737 }
5738
5739 static void subclass_combobox(void)
5740 {
5741 WNDCLASSA cls;
5742
5743 if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5744
5745 old_combobox_proc = cls.lpfnWndProc;
5746
5747 cls.hInstance = GetModuleHandle(0);
5748 cls.lpfnWndProc = combobox_hook_proc;
5749 cls.lpszClassName = "my_combobox_class";
5750 UnregisterClass(cls.lpszClassName, cls.hInstance);
5751 if (!RegisterClassA(&cls)) assert(0);
5752 }
5753
5754 static void test_combobox_messages(void)
5755 {
5756 HWND parent, combo;
5757 LRESULT ret;
5758
5759 subclass_combobox();
5760
5761 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5762 100, 100, 200, 200, 0, 0, 0, NULL);
5763 ok(parent != 0, "Failed to create parent window\n");
5764 flush_sequence();
5765
5766 combo = CreateWindowEx(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5767 0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5768 ok(combo != 0, "Failed to create combobox window\n");
5769
5770 UpdateWindow(combo);
5771
5772 ret = SendMessage(combo, WM_GETDLGCODE, 0, 0);
5773 ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5774
5775 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5776 ok(ret == 0, "expected 0, got %ld\n", ret);
5777 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5778 ok(ret == 1, "expected 1, got %ld\n", ret);
5779 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5780 ok(ret == 2, "expected 2, got %ld\n", ret);
5781
5782 SendMessage(combo, CB_SETCURSEL, 0, 0);
5783 SetFocus(combo);
5784 flush_sequence();
5785
5786 log_all_parent_messages++;
5787 SendMessage(combo, WM_KEYDOWN, VK_DOWN, 0);
5788 SendMessage(combo, WM_KEYUP, VK_DOWN, 0);
5789 log_all_parent_messages--;
5790 ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5791
5792 DestroyWindow(combo);
5793 DestroyWindow(parent);
5794 }
5795
5796 /****************** WM_IME_KEYDOWN message test *******************/
5797
5798 static const struct message WmImeKeydownMsgSeq_0[] =
5799 {
5800 { WM_IME_KEYDOWN, wparam, VK_RETURN },
5801 { WM_CHAR, wparam, 'A' },
5802 { 0 }
5803 };
5804
5805 static const struct message WmImeKeydownMsgSeq_1[] =
5806 {
5807 { WM_KEYDOWN, optional|wparam, VK_RETURN },
5808 { WM_CHAR, optional|wparam, VK_RETURN },
5809 { 0 }
5810 };
5811
5812 static LRESULT WINAPI wmime_keydown_procA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5813 {
5814 struct recvd_message msg;
5815
5816 msg.hwnd = hwnd;
5817 msg.message = message;
5818 msg.flags = wparam|lparam;
5819 msg.wParam = wParam;
5820 msg.lParam = lParam;
5821 msg.descr = "wmime_keydown";
5822 add_message(&msg);
5823
5824 return DefWindowProcA(hwnd, message, wParam, lParam);
5825 }
5826
5827 static void register_wmime_keydown_class(void)
5828 {
5829 WNDCLASSA cls;
5830
5831 ZeroMemory(&cls, sizeof(WNDCLASSA));
5832 cls.lpfnWndProc = wmime_keydown_procA;
5833 cls.hInstance = GetModuleHandleA(0);
5834 cls.lpszClassName = "wmime_keydown_class";
5835 if (!RegisterClassA(&cls)) assert(0);
5836 }
5837
5838 static void test_wmime_keydown_message(void)
5839 {
5840 HWND hwnd;
5841 MSG msg;
5842
5843 trace("Message sequences by WM_IME_KEYDOWN\n");
5844
5845 register_wmime_keydown_class();
5846 hwnd = CreateWindowExA(0, "wmime_keydown_class", NULL, WS_OVERLAPPEDWINDOW,
5847 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5848 NULL, NULL, 0);
5849 flush_events();
5850 flush_sequence();
5851
5852 SendMessage(hwnd, WM_IME_KEYDOWN, VK_RETURN, 0x1c0001);
5853 SendMessage(hwnd, WM_CHAR, 'A', 1);
5854 ok_sequence(WmImeKeydownMsgSeq_0, "WM_IME_KEYDOWN 0", FALSE);
5855
5856 while ( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
5857 {
5858 TranslateMessage(&msg);
5859 DispatchMessage(&msg);
5860 }
5861 ok_sequence(WmImeKeydownMsgSeq_1, "WM_IME_KEYDOWN 1", FALSE);
5862
5863 DestroyWindow(hwnd);
5864 }
5865
5866 /************* painting message test ********************/
5867
5868 void dump_region(HRGN hrgn)
5869 {
5870 DWORD i, size;
5871 RGNDATA *data = NULL;
5872 RECT *rect;
5873
5874 if (!hrgn)
5875 {
5876 printf( "null region\n" );
5877 return;
5878 }
5879 if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5880 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5881 GetRegionData( hrgn, size, data );
5882 printf("%d rects:", data->rdh.nCount );
5883 for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5884 printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
5885 printf("\n");
5886 HeapFree( GetProcessHeap(), 0, data );
5887 }
5888
5889 static void check_update_rgn( HWND hwnd, HRGN hrgn )
5890 {
5891 INT ret;
5892 RECT r1, r2;
5893 HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
5894 HRGN update = CreateRectRgn( 0, 0, 0, 0 );
5895
5896 ret = GetUpdateRgn( hwnd, update, FALSE );
5897 ok( ret != ERROR, "GetUpdateRgn failed\n" );
5898 if (ret == NULLREGION)
5899 {
5900 ok( !hrgn, "Update region shouldn't be empty\n" );
5901 }
5902 else
5903 {
5904 if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
5905 {
5906 ok( 0, "Regions are different\n" );
5907 if (winetest_debug > 0)
5908 {
5909 printf( "Update region: " );
5910 dump_region( update );
5911 printf( "Wanted region: " );
5912 dump_region( hrgn );
5913 }
5914 }
5915 }
5916 GetRgnBox( update, &r1 );
5917 GetUpdateRect( hwnd, &r2, FALSE );
5918 ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
5919 "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
5920 r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
5921
5922 DeleteObject( tmp );
5923 DeleteObject( update );
5924 }
5925
5926 static const struct message WmInvalidateRgn[] = {
5927 { WM_NCPAINT, sent },
5928 { WM_GETTEXT, sent|defwinproc|optional },
5929 { 0 }
5930 };
5931
5932 static const struct message WmGetUpdateRect[] = {
5933 { WM_NCPAINT, sent },
5934 { WM_GETTEXT, sent|defwinproc|optional },
5935 { WM_PAINT, sent },
5936 { 0 }
5937 };
5938
5939 static const struct message WmInvalidateFull[] = {
5940 { WM_NCPAINT, sent|wparam, 1 },
5941 { WM_GETTEXT, sent|defwinproc|optional },
5942 { 0 }
5943 };
5944
5945 static const struct message WmInvalidateErase[] = {
5946 { WM_NCPAINT, sent|wparam, 1 },
5947 { WM_GETTEXT, sent|defwinproc|optional },
5948 { WM_ERASEBKGND, sent },
5949 { 0 }
5950 };
5951
5952 static const struct message WmInvalidatePaint[] = {
5953 { WM_PAINT, sent },
5954 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5955 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5956 { 0 }
5957 };
5958
5959 static const struct message WmInvalidateErasePaint[] = {
5960 { WM_PAINT, sent },
5961 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5962 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5963 { WM_ERASEBKGND, sent|beginpaint|optional },
5964 { 0 }
5965 };
5966
5967 static const struct message WmInvalidateErasePaint2[] = {
5968 { WM_PAINT, sent },
5969 { WM_NCPAINT, sent|beginpaint },
5970 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5971 { WM_ERASEBKGND, sent|beginpaint|optional },
5972 { 0 }
5973 };
5974
5975 static const struct message WmErase[] = {
5976 { WM_ERASEBKGND, sent },
5977 { 0 }
5978 };
5979
5980 static const struct message WmPaint[] = {
5981 { WM_PAINT, sent },
5982 { 0 }
5983 };
5984
5985 static const struct message WmParentOnlyPaint[] = {
5986 { WM_PAINT, sent|parent },
5987 { 0 }
5988 };
5989
5990 static const struct message WmInvalidateParent[] = {
5991 { WM_NCPAINT, sent|parent },
5992 { WM_GETTEXT, sent|defwinproc|parent|optional },
5993 { WM_ERASEBKGND, sent|parent },
5994 { 0 }
5995 };
5996
5997 static const struct message WmInvalidateParentChild[] = {
5998 { WM_NCPAINT, sent|parent },
5999 { WM_GETTEXT, sent|defwinproc|parent|optional },
6000 { WM_ERASEBKGND, sent|parent },
6001 { WM_NCPAINT, sent },
6002 { WM_GETTEXT, sent|defwinproc|optional },
6003 { WM_ERASEBKGND, sent },
6004 { 0 }
6005 };
6006
6007 static const struct message WmInvalidateParentChild2[] = {
6008 { WM_ERASEBKGND, sent|parent },
6009 { WM_NCPAINT, sent },
6010 { WM_GETTEXT, sent|defwinproc|optional },
6011 { WM_ERASEBKGND, sent },
6012 { 0 }
6013 };
6014
6015 static const struct message WmParentPaint[] = {
6016 { WM_PAINT, sent|parent },
6017 { WM_PAINT, sent },
6018 { 0 }
6019 };
6020
6021 static const struct message WmParentPaintNc[] = {
6022 { WM_PAINT, sent|parent },
6023 { WM_PAINT, sent },
6024 { WM_NCPAINT, sent|beginpaint },
6025 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6026 { WM_ERASEBKGND, sent|beginpaint|optional },
6027 { 0 }
6028 };
6029
6030 static const struct message WmChildPaintNc[] = {
6031 { WM_PAINT, sent },
6032 { WM_NCPAINT, sent|beginpaint },
6033 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6034 { WM_ERASEBKGND, sent|beginpaint|optional },
6035 { 0 }
6036 };
6037
6038 static const struct message WmParentErasePaint[] = {
6039 { WM_PAINT, sent|parent },
6040 { WM_NCPAINT, sent|parent|beginpaint },
6041 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
6042 { WM_ERASEBKGND, sent|parent|beginpaint|optional },
6043 { WM_PAINT, sent },
6044 { WM_NCPAINT, sent|beginpaint },
6045 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6046 { WM_ERASEBKGND, sent|beginpaint|optional },
6047 { 0 }
6048 };
6049
6050 static const struct message WmParentOnlyNcPaint[] = {
6051 { WM_PAINT, sent|parent },
6052 { WM_NCPAINT, sent|parent|beginpaint },
6053 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
6054 { 0 }
6055 };
6056
6057 static const struct message WmSetParentStyle[] = {
6058 { WM_STYLECHANGING, sent|parent },
6059 { WM_STYLECHANGED, sent|parent },
6060 { 0 }
6061 };
6062
6063 static void test_paint_messages(void)
6064 {
6065 BOOL ret;
6066 RECT rect;
6067 POINT pt;
6068 MSG msg;
6069 HWND hparent, hchild;
6070 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
6071 HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
6072 HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
6073 100, 100, 200, 200, 0, 0, 0, NULL);
6074 ok (hwnd != 0, "Failed to create overlapped window\n");
6075
6076 ShowWindow( hwnd, SW_SHOW );
6077 UpdateWindow( hwnd );
6078 flush_events();
6079 flush_sequence();
6080
6081 check_update_rgn( hwnd, 0 );
6082 SetRectRgn( hrgn, 10, 10, 20, 20 );
6083 ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6084 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6085 check_update_rgn( hwnd, hrgn );
6086 SetRectRgn( hrgn2, 20, 20, 30, 30 );
6087 ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
6088 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6089 CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
6090 check_update_rgn( hwnd, hrgn );
6091 /* validate everything */
6092 ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6093 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6094 check_update_rgn( hwnd, 0 );
6095
6096 /* test empty region */
6097 SetRectRgn( hrgn, 10, 10, 10, 15 );
6098 ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6099 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6100 check_update_rgn( hwnd, 0 );
6101 /* test empty rect */
6102 SetRect( &rect, 10, 10, 10, 15 );
6103 ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
6104 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6105 check_update_rgn( hwnd, 0 );
6106
6107 /* flush pending messages */
6108 flush_events();
6109 flush_sequence();
6110
6111 GetClientRect( hwnd, &rect );
6112 SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
6113 /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
6114 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
6115 */
6116 trace("testing InvalidateRect(0, NULL, FALSE)\n");
6117 SetRectEmpty( &rect );
6118 ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
6119 check_update_rgn( hwnd, hrgn );
6120 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6121 flush_events();
6122 ok_sequence( WmPaint, "Paint", FALSE );
6123 RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6124 check_update_rgn( hwnd, 0 );
6125
6126 /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
6127 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
6128 */
6129 trace("testing ValidateRect(0, NULL)\n");
6130 SetRectEmpty( &rect );
6131 if (ValidateRect(0, &rect)) /* not supported on Win9x */
6132 {
6133 check_update_rgn( hwnd, hrgn );
6134 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6135 flush_events();
6136 ok_sequence( WmPaint, "Paint", FALSE );
6137 RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6138 check_update_rgn( hwnd, 0 );
6139 }
6140
6141 trace("testing InvalidateRgn(0, NULL, FALSE)\n");
6142 SetLastError(0xdeadbeef);
6143 ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
6144 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
6145 "wrong error code %d\n", GetLastError());
6146 check_update_rgn( hwnd, 0 );
6147 flush_events();
6148 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6149
6150 trace("testing ValidateRgn(0, NULL)\n");
6151 SetLastError(0xdeadbeef);
6152 ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
6153 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
6154 broken( GetLastError() == 0xdeadbeef ) /* win9x */,
6155 "wrong error code %d\n", GetLastError());
6156 check_update_rgn( hwnd, 0 );
6157 flush_events();
6158 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6159
6160 /* now with frame */
6161 SetRectRgn( hrgn, -5, -5, 20, 20 );
6162
6163 /* flush pending messages */
6164 flush_events();
6165 flush_sequence();
6166 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6167 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
6168
6169 SetRectRgn( hrgn, 0, 0, 20, 20 ); /* GetUpdateRgn clips to client area */
6170 check_update_rgn( hwnd, hrgn );
6171
6172 flush_sequence();
6173 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
6174 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
6175
6176 flush_sequence();
6177 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
6178 ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
6179
6180 GetClientRect( hwnd, &rect );
6181 SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
6182 check_update_rgn( hwnd, hrgn );
6183
6184 flush_sequence();
6185 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
6186 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6187
6188 flush_sequence();
6189 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
6190 ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
6191 check_update_rgn( hwnd, 0 );
6192
6193 flush_sequence();
6194 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
6195 ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
6196 check_update_rgn( hwnd, 0 );
6197
6198 flush_sequence();
6199 SetRectRgn( hrgn, 0, 0, 100, 100 );
6200 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6201 SetRectRgn( hrgn, 0, 0, 50, 100 );
6202 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
6203 SetRectRgn( hrgn, 50, 0, 100, 100 );
6204 check_update_rgn( hwnd, hrgn );
6205 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
6206 ok_sequence( WmEmptySeq, "EmptySeq", FALSE ); /* must not generate messages, everything is valid */
6207 check_update_rgn( hwnd, 0 );
6208
6209 flush_sequence();
6210 SetRectRgn( hrgn, 0, 0, 100, 100 );
6211 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
6212 SetRectRgn( hrgn, 0, 0, 100, 50 );
6213 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
6214 ok_sequence( WmErase, "Erase", FALSE );
6215 SetRectRgn( hrgn, 0, 50, 100, 100 );
6216 check_update_rgn( hwnd, hrgn );
6217
6218 flush_sequence();
6219 SetRectRgn( hrgn, 0, 0, 100, 100 );
6220 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
6221 SetRectRgn( hrgn, 0, 0, 50, 50 );
6222 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
6223 ok_sequence( WmPaint, "Paint", FALSE );
6224
6225 flush_sequence();
6226 SetRectRgn( hrgn, -4, -4, -2, -2 );
6227 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6228 SetRectRgn( hrgn, -200, -200, -198, -198 );
6229 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
6230 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
6231
6232 flush_sequence();
6233 SetRectRgn( hrgn, -4, -4, -2, -2 );
6234 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6235 SetRectRgn( hrgn, -4, -4, -3, -3 );
6236 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
6237 SetRectRgn( hrgn, 0, 0, 1, 1 );
6238 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
6239 ok_sequence( WmPaint, "Paint", FALSE );
6240
6241 flush_sequence();
6242 SetRectRgn( hrgn, -4, -4, -1, -1 );
6243 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6244 RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
6245 /* make sure no WM_PAINT was generated */
6246 flush_events();
6247 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
6248
6249 flush_sequence();
6250 SetRectRgn( hrgn, -4, -4, -1, -1 );
6251 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6252 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
6253 {
6254 if (msg.hwnd == hwnd && msg.message == WM_PAINT)
6255 {
6256 /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
6257 INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
6258 ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
6259 ret = GetUpdateRect( hwnd, &rect, FALSE );
6260 ok( ret, "Invalid GetUpdateRect result %d\n", ret );
6261 /* this will send WM_NCPAINT and validate the non client area */
6262 ret = GetUpdateRect( hwnd, &rect, TRUE );
6263 ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
6264 }
6265 DispatchMessage( &msg );
6266 }
6267 ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
6268
6269 DestroyWindow( hwnd );
6270
6271 /* now test with a child window */
6272
6273 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
6274 100, 100, 200, 200, 0, 0, 0, NULL);
6275 ok (hparent != 0, "Failed to create parent window\n");
6276
6277 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
6278 10, 10, 100, 100, hparent, 0, 0, NULL);
6279 ok (hchild != 0, "Failed to create child window\n");
6280
6281 ShowWindow( hparent, SW_SHOW );
6282 UpdateWindow( hparent );
6283 UpdateWindow( hchild );
6284 flush_events();
6285 flush_sequence();
6286 log_all_parent_messages++;
6287
6288 SetRect( &rect, 0, 0, 50, 50 );
6289 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6290 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6291 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
6292
6293 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6294 pt.x = pt.y = 0;
6295 MapWindowPoints( hchild, hparent, &pt, 1 );
6296 SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
6297 check_update_rgn( hchild, hrgn );
6298 SetRectRgn( hrgn, 0, 0, 50, 50 );
6299 check_update_rgn( hparent, hrgn );
6300 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6301 ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
6302 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6303 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6304
6305 flush_events();
6306 ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
6307
6308 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6309 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6310 ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
6311 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6312 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6313
6314 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6315 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6316 ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
6317
6318 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6319 flush_sequence();
6320 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6321 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6322 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
6323
6324 /* flush all paint messages */
6325 flush_events();
6326 flush_sequence();
6327
6328 /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
6329 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6330 SetRectRgn( hrgn, 0, 0, 50, 50 );
6331 check_update_rgn( hparent, hrgn );
6332 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6333 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6334 SetRectRgn( hrgn, 0, 0, 50, 50 );
6335 check_update_rgn( hparent, hrgn );
6336
6337 /* flush all paint messages */
6338 flush_events();
6339 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6340 flush_sequence();
6341
6342 /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
6343 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6344 SetRectRgn( hrgn, 0, 0, 50, 50 );
6345 check_update_rgn( hparent, hrgn );
6346 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6347 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6348 SetRectRgn( hrgn2, 10, 10, 50, 50 );
6349 CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
6350 check_update_rgn( hparent, hrgn );
6351 /* flush all paint messages */
6352 flush_events();
6353 flush_sequence();
6354
6355 /* same as above but parent gets completely validated */
6356 SetRect( &rect, 20, 20, 30, 30 );
6357 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6358 SetRectRgn( hrgn, 20, 20, 30, 30 );
6359 check_update_rgn( hparent, hrgn );
6360 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6361 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6362 check_update_rgn( hparent, 0 ); /* no update region */
6363 flush_events();
6364 ok_sequence( WmEmptySeq, "WmEmpty", FALSE ); /* and no paint messages */
6365
6366 /* make sure RDW_VALIDATE on child doesn't have the same effect */
6367 flush_sequence();
6368 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6369 SetRectRgn( hrgn, 20, 20, 30, 30 );
6370 check_update_rgn( hparent, hrgn );
6371 RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
6372 SetRectRgn( hrgn, 20, 20, 30, 30 );
6373 check_update_rgn( hparent, hrgn );
6374
6375 /* same as above but normal WM_PAINT doesn't validate parent */
6376 flush_sequence();
6377 SetRect( &rect, 20, 20, 30, 30 );
6378 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6379 SetRectRgn( hrgn, 20, 20, 30, 30 );
6380 check_update_rgn( hparent, hrgn );
6381 /* no WM_PAINT in child while parent still pending */
6382 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6383 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6384 while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6385 ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
6386
6387 flush_sequence();
6388 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6389 /* no WM_PAINT in child while parent still pending */
6390 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6391 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6392 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
6393 /* now that parent is valid child should get WM_PAINT */
6394 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6395 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6396 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6397 ok_sequence( WmEmptySeq, "No other message", FALSE );
6398
6399 /* same thing with WS_CLIPCHILDREN in parent */
6400 flush_sequence();
6401 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6402 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6403 /* changing style invalidates non client area, but we need to invalidate something else to see it */
6404 RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
6405 ok_sequence( WmEmptySeq, "No message", FALSE );
6406 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
6407 ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
6408
6409 flush_sequence();
6410 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
6411 SetRectRgn( hrgn, 20, 20, 30, 30 );
6412 check_update_rgn( hparent, hrgn );
6413 /* no WM_PAINT in child while parent still pending */
6414 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6415 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6416 /* WM_PAINT in parent first */
6417 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6418 ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
6419
6420 /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
6421 flush_sequence();
6422 SetRect( &rect, 0, 0, 30, 30 );
6423 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
6424 SetRectRgn( hrgn, 0, 0, 30, 30 );
6425 check_update_rgn( hparent, hrgn );
6426 flush_events();
6427 ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
6428
6429 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6430 flush_sequence();
6431 SetRect( &rect, -10, 0, 30, 30 );
6432 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6433 SetRect( &rect, 0, 0, 20, 20 );
6434 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6435 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6436 ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
6437
6438 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6439 flush_sequence();
6440 SetRect( &rect, -10, 0, 30, 30 );
6441 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6442 SetRect( &rect, 0, 0, 100, 100 );
6443 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6444 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6445 ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
6446 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6447 ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
6448
6449 /* test RDW_INTERNALPAINT behavior */
6450
6451 flush_sequence();
6452 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
6453 flush_events();
6454 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6455
6456 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
6457 flush_events();
6458 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6459
6460 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6461 flush_events();
6462 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6463
6464 assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
6465 UpdateWindow( hparent );
6466 flush_events();
6467 flush_sequence();
6468 trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
6469 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6470 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6471 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6472 flush_events();
6473 ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
6474
6475 UpdateWindow( hparent );
6476 flush_events();
6477 flush_sequence();
6478 trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
6479 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6480 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6481 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6482 flush_events();
6483 ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6484
6485 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6486 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6487 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6488 flush_events();
6489 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6490
6491 assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
6492 UpdateWindow( hparent );
6493 flush_events();
6494 flush_sequence();
6495 trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
6496 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6497 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6498 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6499 flush_events();
6500 ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
6501
6502 UpdateWindow( hparent );
6503 flush_events();
6504 flush_sequence();
6505 trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
6506 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6507 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6508 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6509 flush_events();
6510 ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6511
6512 ok(GetWindowLong( hparent, GWL_STYLE ) & WS_VISIBLE, "parent should be visible\n");
6513 ok(GetWindowLong( hchild, GWL_STYLE ) & WS_VISIBLE, "child should be visible\n");
6514
6515 UpdateWindow( hparent );
6516 flush_events();
6517 flush_sequence();
6518 trace("testing SetWindowPos(-10000, -10000) on child\n");
6519 SetWindowPos( hchild, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6520 check_update_rgn( hchild, 0 );
6521 flush_events();
6522
6523 #if 0 /* this one doesn't pass under Wine yet */
6524 UpdateWindow( hparent );
6525 flush_events();
6526 flush_sequence();
6527 trace("testing ShowWindow(SW_MINIMIZE) on child\n");
6528 ShowWindow( hchild, SW_MINIMIZE );
6529 check_update_rgn( hchild, 0 );
6530 flush_events();
6531 #endif
6532
6533 UpdateWindow( hparent );
6534 flush_events();
6535 flush_sequence();
6536 trace("testing SetWindowPos(-10000, -10000) on parent\n");
6537 SetWindowPos( hparent, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6538 check_update_rgn( hparent, 0 );
6539 flush_events();
6540
6541 log_all_parent_messages--;
6542 DestroyWindow( hparent );
6543 ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6544
6545 /* tests for moving windows off-screen (needs simple WS_POPUP windows) */
6546
6547 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_POPUP | WS_VISIBLE,
6548 100, 100, 200, 200, 0, 0, 0, NULL);
6549 ok (hparent != 0, "Failed to create parent window\n");
6550
6551 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
6552 10, 10, 100, 100, hparent, 0, 0, NULL);
6553 ok (hchild != 0, "Failed to create child window\n");
6554
6555 ShowWindow( hparent, SW_SHOW );
6556 UpdateWindow( hparent );
6557 UpdateWindow( hchild );
6558 flush_events();
6559 flush_sequence();
6560
6561 /* moving child outside of parent boundaries changes update region */
6562 SetRect( &rect, 0, 0, 40, 40 );
6563 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6564 SetRectRgn( hrgn, 0, 0, 40, 40 );
6565 check_update_rgn( hchild, hrgn );
6566 MoveWindow( hchild, -10, 10, 100, 100, FALSE );
6567 SetRectRgn( hrgn, 10, 0, 40, 40 );
6568 check_update_rgn( hchild, hrgn );
6569 MoveWindow( hchild, -10, -10, 100, 100, FALSE );
6570 SetRectRgn( hrgn, 10, 10, 40, 40 );
6571 check_update_rgn( hchild, hrgn );
6572
6573 /* moving parent off-screen does too */
6574 SetRect( &rect, 0, 0, 100, 100 );
6575 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
6576 SetRectRgn( hrgn, 0, 0, 100, 100 );
6577 check_update_rgn( hparent, hrgn );
6578 SetRectRgn( hrgn, 10, 10, 40, 40 );
6579 check_update_rgn( hchild, hrgn );
6580 MoveWindow( hparent, -20, -20, 200, 200, FALSE );
6581 SetRectRgn( hrgn, 20, 20, 100, 100 );
6582 check_update_rgn( hparent, hrgn );
6583 SetRectRgn( hrgn, 30, 30, 40, 40 );
6584 check_update_rgn( hchild, hrgn );
6585
6586 /* invalidated region is cropped by the parent rects */
6587 SetRect( &rect, 0, 0, 50, 50 );
6588 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6589 SetRectRgn( hrgn, 30, 30, 50, 50 );
6590 check_update_rgn( hchild, hrgn );
6591
6592 DestroyWindow( hparent );
6593 ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6594 flush_sequence();
6595
6596 DeleteObject( hrgn );
6597 DeleteObject( hrgn2 );
6598 }
6599
6600 struct wnd_event
6601 {
6602 HWND hwnd;
6603 HANDLE grand_child;
6604 HANDLE start_event;
6605 HANDLE stop_event;
6606 };
6607
6608 static DWORD WINAPI thread_proc(void *param)
6609 {
6610 MSG msg;
6611 struct wnd_event *wnd_event = param;
6612
6613 wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
6614 100, 100, 200, 200, 0, 0, 0, NULL);
6615 ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
6616
6617 SetEvent(wnd_event->start_event);
6618
6619 while (GetMessage(&msg, 0, 0, 0))
6620 {
6621 TranslateMessage(&msg);
6622 DispatchMessage(&msg);
6623 }
6624
6625 ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
6626
6627 return 0;
6628 }
6629
6630 static DWORD CALLBACK create_grand_child_thread( void *param )
6631 {
6632 struct wnd_event *wnd_event = param;
6633 HWND hchild;
6634 MSG msg;
6635
6636 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
6637 WS_CHILD | WS_VISIBLE, 0, 0, 10, 10, wnd_event->hwnd, 0, 0, NULL);
6638 ok (hchild != 0, "Failed to create child window\n");
6639 flush_events();
6640 flush_sequence();
6641 SetEvent( wnd_event->start_event );
6642
6643 for (;;)
6644 {
6645 MsgWaitForMultipleObjects(0, NULL, FALSE, 1000, QS_ALLINPUT);
6646 if (!IsWindow( hchild )) break; /* will be destroyed when parent thread exits */
6647 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6648 }
6649 return 0;
6650 }
6651
6652 static DWORD CALLBACK create_child_thread( void *param )
6653 {
6654 struct wnd_event *wnd_event = param;
6655 struct wnd_event child_event;
6656 DWORD ret, tid;
6657 MSG msg;
6658
6659 child_event.hwnd = CreateWindowExA(0, "TestWindowClass", "Test child",
6660 WS_CHILD | WS_VISIBLE, 0, 0, 10, 10, wnd_event->hwnd, 0, 0, NULL);
6661 ok (child_event.hwnd != 0, "Failed to create child window\n");
6662 SetFocus( child_event.hwnd );
6663 flush_events();
6664 flush_sequence();
6665 child_event.start_event = wnd_event->start_event;
6666 wnd_event->grand_child = CreateThread(NULL, 0, create_grand_child_thread, &child_event, 0, &tid);
6667 for (;;)
6668 {
6669 DWORD ret = MsgWaitForMultipleObjects(1, &child_event.start_event, FALSE, 1000, QS_SENDMESSAGE);
6670 if (ret != 1) break;
6671 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6672 }
6673 ret = WaitForSingleObject( wnd_event->stop_event, 5000 );
6674 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6675 return 0;
6676 }
6677
6678 static void test_interthread_messages(void)
6679 {
6680 HANDLE hThread;
6681 DWORD tid;
6682 WNDPROC proc;
6683 MSG msg;
6684 char buf[256];
6685 int len, expected_len;
6686 struct wnd_event wnd_event;
6687 BOOL ret;
6688
6689 wnd_event.start_event = CreateEventW(NULL, 0, 0, NULL);
6690 if (!wnd_event.start_event)
6691 {
6692 win_skip("skipping interthread message test under win9x\n");
6693 return;
6694 }
6695
6696 hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
6697 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
6698
6699 ok(WaitForSingleObject(wnd_event.start_event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6700
6701 CloseHandle(wnd_event.start_event);
6702
6703 SetLastError(0xdeadbeef);
6704 ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
6705 ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
6706 "wrong error code %d\n", GetLastError());
6707
6708 proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6709 ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
6710
6711 expected_len = lstrlenA("window caption text");
6712 memset(buf, 0, sizeof(buf));
6713 SetLastError(0xdeadbeef);
6714 len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
6715 ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
6716 ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
6717
6718 msg.hwnd = wnd_event.hwnd;
6719 msg.message = WM_GETTEXT;
6720 msg.wParam = sizeof(buf);
6721 msg.lParam = (LPARAM)buf;
6722 memset(buf, 0, sizeof(buf));
6723 SetLastError(0xdeadbeef);
6724 len = DispatchMessageA(&msg);
6725 ok((!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY) || broken(len), /* nt4 */
6726 "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
6727
6728 /* the following test causes an exception in user.exe under win9x */
6729 msg.hwnd = wnd_event.hwnd;
6730 msg.message = WM_TIMER;
6731 msg.wParam = 0;
6732 msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6733 SetLastError(0xdeadbeef);
6734 len = DispatchMessageA(&msg);
6735 ok(!len && GetLastError() == 0xdeadbeef,
6736 "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
6737
6738 ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
6739 ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
6740
6741 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6742 CloseHandle(hThread);
6743
6744 ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
6745
6746 wnd_event.hwnd = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6747 100, 100, 200, 200, 0, 0, 0, NULL);
6748 ok (wnd_event.hwnd != 0, "Failed to create parent window\n");
6749 flush_sequence();
6750 log_all_parent_messages++;
6751 wnd_event.start_event = CreateEventA( NULL, TRUE, FALSE, NULL );
6752 wnd_event.stop_event = CreateEventA( NULL, TRUE, FALSE, NULL );
6753 hThread = CreateThread( NULL, 0, create_child_thread, &wnd_event, 0, &tid );
6754 for (;;)
6755 {
6756 ret = MsgWaitForMultipleObjects(1, &wnd_event.start_event, FALSE, 1000, QS_SENDMESSAGE);
6757 if (ret != 1) break;
6758 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6759 }
6760 ok( !ret, "MsgWaitForMultipleObjects failed %x\n", ret );
6761 /* now wait for the thread without processing messages; this shouldn't deadlock */
6762 SetEvent( wnd_event.stop_event );
6763 ret = WaitForSingleObject( hThread, 5000 );
6764 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6765 CloseHandle( hThread );
6766
6767 ret = WaitForSingleObject( wnd_event.grand_child, 5000 );
6768 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6769 CloseHandle( wnd_event.grand_child );
6770
6771 CloseHandle( wnd_event.start_event );
6772 CloseHandle( wnd_event.stop_event );
6773 flush_events();
6774 ok_sequence(WmExitThreadSeq, "destroy child on thread exit", FALSE);
6775 log_all_parent_messages--;
6776 DestroyWindow( wnd_event.hwnd );
6777 }
6778
6779
6780 static const struct message WmVkN[] = {
6781 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6782 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6783 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6784 { WM_CHAR, wparam|lparam, 'n', 1 },
6785 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
6786 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6787 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6788 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6789 { 0 }
6790 };
6791 static const struct message WmShiftVkN[] = {
6792 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6793 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6794 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6795 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6796 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6797 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6798 { WM_CHAR, wparam|lparam, 'N', 1 },
6799 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
6800 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6801 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6802 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6803 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6804 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6805 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6806 { 0 }
6807 };
6808 static const struct message WmCtrlVkN[] = {
6809 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6810 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6811 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6812 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6813 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6814 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6815 { WM_CHAR, wparam|lparam, 0x000e, 1 },
6816 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6817 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6818 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6819 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6820 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6821 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6822 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6823 { 0 }
6824 };
6825 static const struct message WmCtrlVkN_2[] = {
6826 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6827 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6828 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6829 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6830 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6831 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6832 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6833 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6834 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6835 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6836 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6837 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6838 { 0 }
6839 };
6840 static const struct message WmAltVkN[] = {
6841 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6842 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6843 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6844 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6845 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6846 { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6847 { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
6848 { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
6849 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
6850 { HCBT_SYSCOMMAND, hook },
6851 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6852 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6853 { 0x00AE, sent|defwinproc|optional }, /* XP */
6854 { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
6855 { WM_INITMENU, sent|defwinproc },
6856 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6857 { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
6858 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
6859 { WM_CAPTURECHANGED, sent|defwinproc },
6860 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
6861 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6862 { WM_EXITMENULOOP, sent|defwinproc },
6863 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
6864 { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
6865 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6866 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6867 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6868 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6869 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6870 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6871 { 0 }
6872 };
6873 static const struct message WmAltVkN_2[] = {
6874 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6875 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6876 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6877 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6878 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6879 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
6880 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6881 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6882 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6883 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6884 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6885 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6886 { 0 }
6887 };
6888 static const struct message WmCtrlAltVkN[] = {
6889 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6890 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6891 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6892 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6893 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6894 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6895 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6896 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6897 { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6898 { WM_CHAR, optional },
6899 { WM_CHAR, sent|optional },
6900 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6901 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6902 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6903 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6904 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6905 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6906 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6907 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6908 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6909 { 0 }
6910 };
6911 static const struct message WmCtrlShiftVkN[] = {
6912 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6913 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6914 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6915 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6916 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6917 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6918 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6919 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6920 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
6921 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6922 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6923 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6924 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6925 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6926 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6927 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6928 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6929 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6930 { 0 }
6931 };
6932 static const struct message WmCtrlAltShiftVkN[] = {
6933 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6934 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6935 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6936 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6937 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6938 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6939 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
6940 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
6941 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
6942 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6943 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6944 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
6945 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6946 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6947 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6948 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
6949 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
6950 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
6951 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6952 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6953 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6954 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6955 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6956 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6957 { 0 }
6958 };
6959 static const struct message WmAltPressRelease[] = {
6960 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6961 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6962 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6963 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6964 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6965 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6966 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
6967 { HCBT_SYSCOMMAND, hook },
6968 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6969 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6970 { WM_INITMENU, sent|defwinproc },
6971 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6972 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6973 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6974
6975 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
6976
6977 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6978 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
6979 { WM_CAPTURECHANGED, sent|defwinproc },
6980 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
6981 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6982 { WM_EXITMENULOOP, sent|defwinproc },
6983 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6984 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6985 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6986 { 0 }
6987 };
6988 static const struct message WmShiftMouseButton[] = {
6989 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6990 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6991 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6992 { WM_MOUSEMOVE, wparam|optional, 0, 0 },
6993 { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
6994 { WM_LBUTTONDOWN, wparam, MK_LBUTTON|MK_SHIFT, 0 },
6995 { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON|MK_SHIFT, 0 },
6996 { WM_LBUTTONUP, wparam, MK_SHIFT, 0 },
6997 { WM_LBUTTONUP, sent|wparam, MK_SHIFT, 0 },
6998 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6999 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
7000 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
7001 { 0 }
7002 };
7003 static const struct message WmF1Seq[] = {
7004 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
7005 { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
7006 { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
7007 { WM_KEYF1, wparam|lparam, 0, 0 },
7008 { WM_KEYF1, sent|wparam|lparam, 0, 0 },
7009 { WM_HELP, sent|defwinproc },
7010 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
7011 { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
7012 { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
7013 { 0 }
7014 };
7015 static const struct message WmVkAppsSeq[] = {
7016 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
7017 { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
7018 { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
7019 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
7020 { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
7021 { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
7022 { WM_CONTEXTMENU, lparam, /*hwnd*/0, -1 },
7023 { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, -1 },
7024 { 0 }
7025 };
7026 static const struct message WmVkF10Seq[] = {
7027 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7028 { WM_SYSKEYDOWN, wparam|lparam, VK_F10, 1 },
7029 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_F10, 0x00000001 },
7030 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7031 { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7032 { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7033 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_KEYMENU },
7034 { HCBT_SYSCOMMAND, hook },
7035 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7036 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7037 { WM_INITMENU, sent|defwinproc },
7038 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7039 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
7040 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7041
7042 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0x10000001 }, /* XP */
7043
7044 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7045 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7046 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
7047 { WM_CAPTURECHANGED, sent|defwinproc },
7048 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
7049 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7050 { WM_EXITMENULOOP, sent|defwinproc },
7051 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7052 { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7053 { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7054 { 0 }
7055 };
7056 static const struct message WmShiftF10Seq[] = {
7057 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
7058 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
7059 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x00000001 },
7060 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7061 { WM_SYSKEYDOWN, wparam|lparam, VK_F10, 1 },
7062 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_F10, 0x00000001 },
7063 { WM_CONTEXTMENU, sent|defwinproc|lparam, /*hwnd*/0, -1 },
7064 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7065 { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7066 { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7067 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_KEYMENU },
7068 { HCBT_SYSCOMMAND, hook },
7069 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7070 { WM_INITMENU, sent|defwinproc },
7071 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
7072 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xd0000001 }, /* XP */
7073 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0x10000001 }, /* XP */
7074 { WM_CAPTURECHANGED, sent|defwinproc|wparam|lparam, 0, 0 },
7075 { WM_MENUSELECT, sent|defwinproc|wparam|lparam, 0xffff0000, 0 },
7076 { WM_EXITMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7077 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0xc0000001 }, /* XP */
7078 { WM_KEYUP, wparam|lparam, VK_ESCAPE, 0xc0000001 },
7079 { WM_KEYUP, sent|wparam|lparam, VK_ESCAPE, 0xc0000001 },
7080 { 0 }
7081 };
7082
7083 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
7084 {
7085 MSG msg;
7086
7087 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
7088 {
7089 struct recvd_message log_msg;
7090
7091 /* ignore some unwanted messages */
7092 if (msg.message == WM_MOUSEMOVE ||
7093 msg.message == WM_TIMER ||
7094 ignore_message( msg.message ))
7095 continue;
7096
7097 log_msg.hwnd = msg.hwnd;
7098 log_msg.message = msg.message;
7099 log_msg.flags = wparam|lparam;
7100 log_msg.wParam = msg.wParam;
7101 log_msg.lParam = msg.lParam;
7102 log_msg.descr = "accel";
7103 add_message(&log_msg);
7104
7105 if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
7106 {
7107 TranslateMessage(&msg);
7108 DispatchMessage(&msg);
7109 }
7110 }
7111 }
7112
7113 static void test_accelerators(void)
7114 {
7115 RECT rc;
7116 POINT pt;
7117 SHORT state;
7118 HACCEL hAccel;
7119 HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7120 100, 100, 200, 200, 0, 0, 0, NULL);
7121 BOOL ret;
7122
7123 assert(hwnd != 0);
7124 UpdateWindow(hwnd);
7125 flush_events();
7126 flush_sequence();
7127
7128 SetFocus(hwnd);
7129 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
7130
7131 state = GetKeyState(VK_SHIFT);
7132 ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
7133 state = GetKeyState(VK_CAPITAL);
7134 ok(state == 0, "wrong CapsLock state %04x\n", state);
7135
7136 hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
7137 assert(hAccel != 0);
7138
7139 flush_events();
7140 pump_msg_loop(hwnd, 0);
7141 flush_sequence();
7142
7143 trace("testing VK_N press/release\n");
7144 flush_sequence();
7145 keybd_event('N', 0, 0, 0);
7146 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7147 pump_msg_loop(hwnd, hAccel);
7148 if (!sequence_cnt) /* we didn't get any message */
7149 {
7150 skip( "queuing key events not supported\n" );
7151 goto done;
7152 }
7153 ok_sequence(WmVkN, "VK_N press/release", FALSE);
7154
7155 trace("testing Shift+VK_N press/release\n");
7156 flush_sequence();
7157 keybd_event(VK_SHIFT, 0, 0, 0);
7158 keybd_event('N', 0, 0, 0);
7159 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7160 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7161 pump_msg_loop(hwnd, hAccel);
7162 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
7163
7164 trace("testing Ctrl+VK_N press/release\n");
7165 flush_sequence();
7166 keybd_event(VK_CONTROL, 0, 0, 0);
7167 keybd_event('N', 0, 0, 0);
7168 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7169 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7170 pump_msg_loop(hwnd, hAccel);
7171 ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
7172
7173 trace("testing Alt+VK_N press/release\n");
7174 flush_sequence();
7175 keybd_event(VK_MENU, 0, 0, 0);
7176 keybd_event('N', 0, 0, 0);
7177 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7178 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7179 pump_msg_loop(hwnd, hAccel);
7180 ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
7181
7182 trace("testing Ctrl+Alt+VK_N press/release 1\n");
7183 flush_sequence();
7184 keybd_event(VK_CONTROL, 0, 0, 0);
7185 keybd_event(VK_MENU, 0, 0, 0);
7186 keybd_event('N', 0, 0, 0);
7187 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7188 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7189 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7190 pump_msg_loop(hwnd, hAccel);
7191 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
7192
7193 ret = DestroyAcceleratorTable(hAccel);
7194 ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7195
7196 hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
7197 assert(hAccel != 0);
7198
7199 trace("testing VK_N press/release\n");
7200 flush_sequence();
7201 keybd_event('N', 0, 0, 0);
7202 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7203 pump_msg_loop(hwnd, hAccel);
7204 ok_sequence(WmVkN, "VK_N press/release", FALSE);
7205
7206 trace("testing Shift+VK_N press/release\n");
7207 flush_sequence();
7208 keybd_event(VK_SHIFT, 0, 0, 0);
7209 keybd_event('N', 0, 0, 0);
7210 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7211 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7212 pump_msg_loop(hwnd, hAccel);
7213 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
7214
7215 trace("testing Ctrl+VK_N press/release 2\n");
7216 flush_sequence();
7217 keybd_event(VK_CONTROL, 0, 0, 0);
7218 keybd_event('N', 0, 0, 0);
7219 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7220 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7221 pump_msg_loop(hwnd, hAccel);
7222 ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
7223
7224 trace("testing Alt+VK_N press/release 2\n");
7225 flush_sequence();
7226 keybd_event(VK_MENU, 0, 0, 0);
7227 keybd_event('N', 0, 0, 0);
7228 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7229 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7230 pump_msg_loop(hwnd, hAccel);
7231 ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
7232
7233 trace("testing Ctrl+Alt+VK_N press/release 2\n");
7234 flush_sequence();
7235 keybd_event(VK_CONTROL, 0, 0, 0);
7236 keybd_event(VK_MENU, 0, 0, 0);
7237 keybd_event('N', 0, 0, 0);
7238 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7239 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7240 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7241 pump_msg_loop(hwnd, hAccel);
7242 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
7243
7244 trace("testing Ctrl+Shift+VK_N press/release\n");
7245 flush_sequence();
7246 keybd_event(VK_CONTROL, 0, 0, 0);
7247 keybd_event(VK_SHIFT, 0, 0, 0);
7248 keybd_event('N', 0, 0, 0);
7249 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7250 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7251 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7252 pump_msg_loop(hwnd, hAccel);
7253 ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
7254
7255 trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
7256 flush_sequence();
7257 keybd_event(VK_CONTROL, 0, 0, 0);
7258 keybd_event(VK_MENU, 0, 0, 0);
7259 keybd_event(VK_SHIFT, 0, 0, 0);
7260 keybd_event('N', 0, 0, 0);
7261 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7262 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7263 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7264 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7265 pump_msg_loop(hwnd, hAccel);
7266 ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
7267
7268 ret = DestroyAcceleratorTable(hAccel);
7269 ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7270 hAccel = 0;
7271
7272 trace("testing Alt press/release\n");
7273 flush_sequence();
7274 keybd_event(VK_MENU, 0, 0, 0);
7275 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7276 keybd_event(VK_MENU, 0, 0, 0);
7277 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7278 pump_msg_loop(hwnd, 0);
7279 /* this test doesn't pass in Wine for managed windows */
7280 ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
7281
7282 trace("testing VK_F1 press/release\n");
7283 keybd_event(VK_F1, 0, 0, 0);
7284 keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
7285 pump_msg_loop(hwnd, 0);
7286 ok_sequence(WmF1Seq, "F1 press/release", FALSE);
7287
7288 trace("testing VK_APPS press/release\n");
7289 keybd_event(VK_APPS, 0, 0, 0);
7290 keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
7291 pump_msg_loop(hwnd, 0);
7292 ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
7293
7294 trace("testing VK_F10 press/release\n");
7295 keybd_event(VK_F10, 0, 0, 0);
7296 keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7297 keybd_event(VK_F10, 0, 0, 0);
7298 keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7299 pump_msg_loop(hwnd, 0);
7300 ok_sequence(WmVkF10Seq, "VK_F10 press/release", TRUE);
7301
7302 trace("testing SHIFT+F10 press/release\n");
7303 keybd_event(VK_SHIFT, 0, 0, 0);
7304 keybd_event(VK_F10, 0, 0, 0);
7305 keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7306 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7307 keybd_event(VK_ESCAPE, 0, 0, 0);
7308 keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0);
7309 pump_msg_loop(hwnd, 0);
7310 ok_sequence(WmShiftF10Seq, "SHIFT+F10 press/release", TRUE);
7311
7312 trace("testing Shift+MouseButton press/release\n");
7313 /* first, move mouse pointer inside of the window client area */
7314 GetClientRect(hwnd, &rc);
7315 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
7316 rc.left += (rc.right - rc.left)/2;
7317 rc.top += (rc.bottom - rc.top)/2;
7318 SetCursorPos(rc.left, rc.top);
7319 SetActiveWindow(hwnd);
7320
7321 flush_events();
7322 flush_sequence();
7323 GetCursorPos(&pt);
7324 if (pt.x == rc.left && pt.y == rc.top)
7325 {
7326 int i;
7327 keybd_event(VK_SHIFT, 0, 0, 0);
7328 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
7329 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7330 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7331 pump_msg_loop(hwnd, 0);
7332 for (i = 0; i < sequence_cnt; i++) if (sequence[i].message == WM_LBUTTONDOWN) break;
7333 if (i < sequence_cnt)
7334 ok_sequence(WmShiftMouseButton, "Shift+MouseButton press/release", FALSE);
7335 else
7336 skip( "Shift+MouseButton event didn't get to the window\n" );
7337 }
7338
7339 done:
7340 if (hAccel) DestroyAcceleratorTable(hAccel);
7341 DestroyWindow(hwnd);
7342 }
7343
7344 /************* window procedures ********************/
7345
7346 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message,
7347 WPARAM wParam, LPARAM lParam)
7348 {
7349 static LONG defwndproc_counter = 0;
7350 static LONG beginpaint_counter = 0;
7351 LRESULT ret;
7352 struct recvd_message msg;
7353
7354 if (ignore_message( message )) return 0;
7355
7356 switch (message)
7357 {
7358 case WM_ENABLE:
7359 {
7360 LONG style = GetWindowLongA(hwnd, GWL_STYLE);
7361 ok((BOOL)wParam == !(style & WS_DISABLED),
7362 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
7363 break;
7364 }
7365
7366 case WM_CAPTURECHANGED:
7367 if (test_DestroyWindow_flag)
7368 {
7369 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7370 if (style & WS_CHILD)
7371 lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7372 else if (style & WS_POPUP)
7373 lParam = WND_POPUP_ID;
7374 else
7375 lParam = WND_PARENT_ID;
7376 }
7377 break;
7378
7379 case WM_NCDESTROY:
7380 {
7381 HWND capture;
7382
7383 ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
7384 capture = GetCapture();
7385 if (capture)
7386 {
7387 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
7388 trace("current capture %p, releasing...\n", capture);
7389 ReleaseCapture();
7390 }
7391 }
7392 /* fall through */
7393 case WM_DESTROY:
7394 if (pGetAncestor)
7395 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
7396 if (test_DestroyWindow_flag)
7397 {
7398 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7399 if (style & WS_CHILD)
7400 lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7401 else if (style & WS_POPUP)
7402 lParam = WND_POPUP_ID;
7403 else
7404 lParam = WND_PARENT_ID;
7405 }
7406 break;
7407
7408 /* test_accelerators() depends on this */
7409 case WM_NCHITTEST:
7410 return HTCLIENT;
7411
7412 /* ignore */
7413 case WM_MOUSEMOVE:
7414 case WM_MOUSEACTIVATE:
7415 case WM_NCMOUSEMOVE:
7416 case WM_SETCURSOR:
7417 case WM_IME_SELECT:
7418 return 0;
7419 }
7420
7421 msg.hwnd = hwnd;
7422 msg.message = message;
7423 msg.flags = sent|wparam|lparam;
7424 if (defwndproc_counter) msg.flags |= defwinproc;
7425 if (beginpaint_counter) msg.flags |= beginpaint;
7426 msg.wParam = wParam;
7427 msg.lParam = lParam;
7428 msg.descr = "MsgCheckProc";
7429 add_message(&msg);
7430
7431 if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
7432 {
7433 HWND parent = GetParent(hwnd);
7434 RECT rc;
7435 MINMAXINFO *minmax = (MINMAXINFO *)lParam;
7436
7437 GetClientRect(parent, &rc);
7438 trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
7439 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
7440 minmax->ptReserved.x, minmax->ptReserved.y,
7441 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
7442 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
7443 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
7444 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
7445
7446 ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
7447 minmax->ptMaxSize.x, rc.right);
7448 ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
7449 minmax->ptMaxSize.y, rc.bottom);
7450 }
7451
7452 if (message == WM_PAINT)
7453 {
7454 PAINTSTRUCT ps;
7455 beginpaint_counter++;
7456 BeginPaint( hwnd, &ps );
7457 beginpaint_counter--;
7458 EndPaint( hwnd, &ps );
7459 return 0;
7460 }
7461
7462 defwndproc_counter++;
7463 ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam)
7464 : DefWindowProcA(hwnd, message, wParam, lParam);
7465 defwndproc_counter--;
7466
7467 return ret;
7468 }
7469
7470 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7471 {
7472 return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
7473 }
7474
7475 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7476 {
7477 return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
7478 }
7479
7480 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7481 {
7482 static LONG defwndproc_counter = 0;
7483 LRESULT ret;
7484 struct recvd_message msg;
7485
7486 if (ignore_message( message )) return 0;
7487
7488 switch (message)
7489 {
7490 case WM_QUERYENDSESSION:
7491 case WM_ENDSESSION:
7492 lParam &= ~0x01; /* Vista adds a 0x01 flag */
7493 break;
7494 }
7495
7496 msg.hwnd = hwnd;
7497 msg.message = message;
7498 msg.flags = sent|wparam|lparam;
7499 if (defwndproc_counter) msg.flags |= defwinproc;
7500 msg.wParam = wParam;
7501 msg.lParam = lParam;
7502 msg.descr = "popup";
7503 add_message(&msg);
7504
7505 if (message == WM_CREATE)
7506 {
7507 DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
7508 SetWindowLongA(hwnd, GWL_STYLE, style);
7509 }
7510
7511 defwndproc_counter++;
7512 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7513 defwndproc_counter--;
7514
7515 return ret;
7516 }
7517
7518 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7519 {
7520 static LONG defwndproc_counter = 0;
7521 static LONG beginpaint_counter = 0;
7522 LRESULT ret;
7523 struct recvd_message msg;
7524
7525 if (ignore_message( message )) return 0;
7526
7527 if (log_all_parent_messages ||
7528 message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
7529 message == WM_SETFOCUS || message == WM_KILLFOCUS ||
7530 message == WM_ENABLE || message == WM_ENTERIDLE ||
7531 message == WM_DRAWITEM || message == WM_COMMAND ||
7532 message == WM_IME_SETCONTEXT)
7533 {
7534 switch (message)
7535 {
7536 /* ignore */
7537 case WM_NCHITTEST:
7538 return HTCLIENT;
7539 case WM_SETCURSOR:
7540 case WM_MOUSEMOVE:
7541 case WM_NCMOUSEMOVE:
7542 return 0;
7543
7544 case WM_ERASEBKGND:
7545 {
7546 RECT rc;
7547 INT ret = GetClipBox((HDC)wParam, &rc);
7548
7549 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
7550 ret, rc.left, rc.top, rc.right, rc.bottom);
7551 break;
7552 }
7553 }
7554
7555 msg.hwnd = hwnd;
7556 msg.message = message;
7557 msg.flags = sent|parent|wparam|lparam;
7558 if (defwndproc_counter) msg.flags |= defwinproc;
7559 if (beginpaint_counter) msg.flags |= beginpaint;
7560 msg.wParam = wParam;
7561 msg.lParam = lParam;
7562 msg.descr = "parent";
7563 add_message(&msg);
7564 }
7565
7566 if (message == WM_PAINT)
7567 {
7568 PAINTSTRUCT ps;
7569 beginpaint_counter++;
7570 BeginPaint( hwnd, &ps );
7571 beginpaint_counter--;
7572 EndPaint( hwnd, &ps );
7573 return 0;
7574 }
7575
7576 defwndproc_counter++;
7577 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7578 defwndproc_counter--;
7579
7580 return ret;
7581 }
7582
7583 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7584 {
7585 static LONG defwndproc_counter = 0;
7586 LRESULT ret;
7587 struct recvd_message msg;
7588
7589 if (ignore_message( message )) return 0;
7590
7591 if (test_def_id)
7592 {
7593 DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
7594 ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
7595 if (after_end_dialog)
7596 ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
7597 else
7598 ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
7599 }
7600
7601 msg.hwnd = hwnd;
7602 msg.message = message;
7603 msg.flags = sent|wparam|lparam;
7604 if (defwndproc_counter) msg.flags |= defwinproc;
7605 msg.wParam = wParam;
7606 msg.lParam = lParam;
7607 msg.descr = "dialog";
7608 add_message(&msg);
7609
7610 defwndproc_counter++;
7611 ret = DefDlgProcA(hwnd, message, wParam, lParam);
7612 defwndproc_counter--;
7613
7614 return ret;
7615 }
7616
7617 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7618 {
7619 static LONG defwndproc_counter = 0;
7620 LRESULT ret;
7621 struct recvd_message msg;
7622
7623 /* log only specific messages we are interested in */
7624 switch (message)
7625 {
7626 #if 0 /* probably log these as well */
7627 case WM_ACTIVATE:
7628 case WM_SETFOCUS:
7629 case WM_KILLFOCUS:
7630 #endif
7631 case WM_SHOWWINDOW:
7632 case WM_SIZE:
7633 case WM_MOVE:
7634 case WM_GETMINMAXINFO:
7635 case WM_WINDOWPOSCHANGING:
7636 case WM_WINDOWPOSCHANGED:
7637 break;
7638
7639 default: /* ignore */
7640 /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
7641 return DefWindowProcA(hwnd, message, wParam, lParam);
7642 }
7643
7644 msg.hwnd = hwnd;
7645 msg.message = message;
7646 msg.flags = sent|wparam|lparam;
7647 if (defwndproc_counter) msg.flags |= defwinproc;
7648 msg.wParam = wParam;
7649 msg.lParam = lParam;
7650 msg.descr = "show";
7651 add_message(&msg);
7652
7653 defwndproc_counter++;
7654 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7655 defwndproc_counter--;
7656
7657 return ret;
7658 }
7659
7660 static LRESULT WINAPI PaintLoopProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
7661 {
7662 switch (msg)
7663 {
7664 case WM_CREATE: return 0;
7665 case WM_PAINT:
7666 {
7667 MSG msg2;
7668 static int i = 0;
7669
7670 if (i < 256)
7671 {
7672 i++;
7673 if (PeekMessageA(&msg2, 0, 0, 0, 1))
7674 {
7675 TranslateMessage(&msg2);
7676 DispatchMessage(&msg2);
7677 }
7678 i--;
7679 }
7680 else ok(broken(1), "infinite loop\n");
7681 if ( i == 0)
7682 paint_loop_done = 1;
7683 return DefWindowProcA(hWnd,msg,wParam,lParam);
7684 }
7685 }
7686 return DefWindowProcA(hWnd,msg,wParam,lParam);
7687 }
7688
7689 static BOOL RegisterWindowClasses(void)
7690 {
7691 WNDCLASSA cls;
7692 WNDCLASSW clsW;
7693
7694 cls.style = 0;
7695 cls.lpfnWndProc = MsgCheckProcA;
7696 cls.cbClsExtra = 0;
7697 cls.cbWndExtra = 0;
7698 cls.hInstance = GetModuleHandleA(0);
7699 cls.hIcon = 0;
7700 cls.hCursor = LoadCursorA(0, IDC_ARROW);
7701 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7702 cls.lpszMenuName = NULL;
7703 cls.lpszClassName = "TestWindowClass";
7704 if(!RegisterClassA(&cls)) return FALSE;
7705
7706 cls.lpfnWndProc = ShowWindowProcA;
7707 cls.lpszClassName = "ShowWindowClass";
7708 if(!RegisterClassA(&cls)) return FALSE;
7709
7710 cls.lpfnWndProc = PopupMsgCheckProcA;
7711 cls.lpszClassName = "TestPopupClass";
7712 if(!RegisterClassA(&cls)) return FALSE;
7713
7714 cls.lpfnWndProc = ParentMsgCheckProcA;
7715 cls.lpszClassName = "TestParentClass";
7716 if(!RegisterClassA(&cls)) return FALSE;
7717
7718 cls.lpfnWndProc = DefWindowProcA;
7719 cls.lpszClassName = "SimpleWindowClass";
7720 if(!RegisterClassA(&cls)) return FALSE;
7721
7722 cls.lpfnWndProc = PaintLoopProcA;
7723 cls.lpszClassName = "PaintLoopWindowClass";
7724 if(!RegisterClassA(&cls)) return FALSE;
7725
7726 cls.style = CS_NOCLOSE;
7727 cls.lpszClassName = "NoCloseWindowClass";
7728 if(!RegisterClassA(&cls)) return FALSE;
7729
7730 ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
7731 cls.style = 0;
7732 cls.hInstance = GetModuleHandleA(0);
7733 cls.hbrBackground = 0;
7734 cls.lpfnWndProc = TestDlgProcA;
7735 cls.lpszClassName = "TestDialogClass";
7736 if(!RegisterClassA(&cls)) return FALSE;
7737
7738 clsW.style = 0;
7739 clsW.lpfnWndProc = MsgCheckProcW;
7740 clsW.cbClsExtra = 0;
7741 clsW.cbWndExtra = 0;
7742 clsW.hInstance = GetModuleHandleW(0);
7743 clsW.hIcon = 0;
7744 clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
7745 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
7746 clsW.lpszMenuName = NULL;
7747 clsW.lpszClassName = testWindowClassW;
7748 RegisterClassW(&clsW); /* ignore error, this fails on Win9x */
7749
7750 return TRUE;
7751 }
7752
7753 static BOOL is_our_logged_class(HWND hwnd)
7754 {
7755 char buf[256];
7756
7757 if (GetClassNameA(hwnd, buf, sizeof(buf)))
7758 {
7759 if (!lstrcmpiA(buf, "TestWindowClass") ||
7760 !lstrcmpiA(buf, "ShowWindowClass") ||
7761 !lstrcmpiA(buf, "TestParentClass") ||
7762 !lstrcmpiA(buf, "TestPopupClass") ||
7763 !lstrcmpiA(buf, "SimpleWindowClass") ||
7764 !lstrcmpiA(buf, "TestDialogClass") ||
7765 !lstrcmpiA(buf, "MDI_frame_class") ||
7766 !lstrcmpiA(buf, "MDI_client_class") ||
7767 !lstrcmpiA(buf, "MDI_child_class") ||
7768 !lstrcmpiA(buf, "my_button_class") ||
7769 !lstrcmpiA(buf, "my_edit_class") ||
7770 !lstrcmpiA(buf, "static") ||
7771 !lstrcmpiA(buf, "ListBox") ||
7772 !lstrcmpiA(buf, "ComboBox") ||
7773 !lstrcmpiA(buf, "MyDialogClass") ||
7774 !lstrcmpiA(buf, "#32770") ||
7775 !lstrcmpiA(buf, "#32768"))
7776 return TRUE;
7777 }
7778 return FALSE;
7779 }
7780
7781 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
7782 {
7783 HWND hwnd;
7784
7785 ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7786
7787 if (nCode == HCBT_CLICKSKIPPED)
7788 {
7789 /* ignore this event, XP sends it a lot when switching focus between windows */
7790 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7791 }
7792
7793 if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
7794 {
7795 struct recvd_message msg;
7796
7797 msg.hwnd = 0;
7798 msg.message = nCode;
7799 msg.flags = hook|wparam|lparam;
7800 msg.wParam = wParam;
7801 msg.lParam = lParam;
7802 msg.descr = "CBT";
7803 add_message(&msg);
7804
7805 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7806 }
7807
7808 if (nCode == HCBT_DESTROYWND)
7809 {
7810 if (test_DestroyWindow_flag)
7811 {
7812 DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
7813 if (style & WS_CHILD)
7814 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
7815 else if (style & WS_POPUP)
7816 lParam = WND_POPUP_ID;
7817 else
7818 lParam = WND_PARENT_ID;
7819 }
7820 }
7821
7822 /* Log also SetFocus(0) calls */
7823 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7824
7825 if (is_our_logged_class(hwnd))
7826 {
7827 struct recvd_message msg;
7828
7829 msg.hwnd = hwnd;
7830 msg.message = nCode;
7831 msg.flags = hook|wparam|lparam;
7832 msg.wParam = wParam;
7833 msg.lParam = lParam;
7834 msg.descr = "CBT";
7835 add_message(&msg);
7836 }
7837 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7838 }
7839
7840 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
7841 DWORD event,
7842 HWND hwnd,
7843 LONG object_id,
7844 LONG child_id,
7845 DWORD thread_id,
7846 DWORD event_time)
7847 {
7848 ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7849
7850 /* ignore mouse cursor events */
7851 if (object_id == OBJID_CURSOR) return;
7852
7853 if (!hwnd || is_our_logged_class(hwnd))
7854 {
7855 struct recvd_message msg;
7856
7857 msg.hwnd = hwnd;
7858 msg.message = event;
7859 msg.flags = winevent_hook|wparam|lparam;
7860 msg.wParam = object_id;
7861 msg.lParam = child_id;
7862 msg.descr = "WEH";
7863 add_message(&msg);
7864 }
7865 }
7866
7867 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
7868 static const WCHAR wszAnsi[] = {'U',0};
7869
7870 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
7871 {
7872 switch (uMsg)
7873 {
7874 case CB_FINDSTRINGEXACT:
7875 trace("String: %p\n", (LPCWSTR)lParam);
7876 if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
7877 return 1;
7878 if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
7879 return 0;
7880 return -1;
7881 }
7882 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
7883 }
7884
7885 static const struct message WmGetTextLengthAfromW[] = {
7886 { WM_GETTEXTLENGTH, sent },
7887 { WM_GETTEXT, sent|optional },
7888 { 0 }
7889 };
7890
7891 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
7892
7893 /* dummy window proc for WM_GETTEXTLENGTH test */
7894 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
7895 {
7896 switch(msg)
7897 {
7898 case WM_GETTEXTLENGTH:
7899 return lstrlenW(dummy_window_text) + 37; /* some random length */
7900 case WM_GETTEXT:
7901 lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
7902 return lstrlenW( (LPWSTR)lp );
7903 default:
7904 return DefWindowProcW( hwnd, msg, wp, lp );
7905 }
7906 }
7907
7908 static void test_message_conversion(void)
7909 {
7910 static const WCHAR wszMsgConversionClass[] =
7911 {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
7912 WNDCLASSW cls;
7913 LRESULT lRes;
7914 HWND hwnd;
7915 WNDPROC wndproc, newproc;
7916 BOOL ret;
7917
7918 cls.style = 0;
7919 cls.lpfnWndProc = MsgConversionProcW;
7920 cls.cbClsExtra = 0;
7921 cls.cbWndExtra = 0;
7922 cls.hInstance = GetModuleHandleW(NULL);
7923 cls.hIcon = NULL;
7924 cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
7925 cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
7926 cls.lpszMenuName = NULL;
7927 cls.lpszClassName = wszMsgConversionClass;
7928 /* this call will fail on Win9x, but that doesn't matter as this test is
7929 * meaningless on those platforms */
7930 if(!RegisterClassW(&cls)) return;
7931
7932 hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
7933 100, 100, 200, 200, 0, 0, 0, NULL);
7934 ok(hwnd != NULL, "Window creation failed\n");
7935
7936 /* {W, A} -> A */
7937
7938 wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
7939 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7940 ok(lRes == 0, "String should have been converted\n");
7941 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7942 ok(lRes == 1, "String shouldn't have been converted\n");
7943
7944 /* {W, A} -> W */
7945
7946 wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
7947 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7948 ok(lRes == 1, "String shouldn't have been converted\n");
7949 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7950 ok(lRes == 1, "String shouldn't have been converted\n");
7951
7952 /* Synchronous messages */
7953
7954 lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7955 ok(lRes == 0, "String should have been converted\n");
7956 lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7957 ok(lRes == 1, "String shouldn't have been converted\n");
7958
7959 /* Asynchronous messages */
7960
7961 SetLastError(0);
7962 lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7963 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7964 "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7965 SetLastError(0);
7966 lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7967 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7968 "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7969 SetLastError(0);
7970 lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7971 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7972 "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7973 SetLastError(0);
7974 lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7975 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7976 "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7977 SetLastError(0);
7978 lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7979 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7980 "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7981 SetLastError(0);
7982 lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7983 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7984 "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7985 SetLastError(0);
7986 lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7987 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7988 "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7989 SetLastError(0);
7990 lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7991 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7992 "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7993
7994 /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
7995
7996 hwnd = CreateWindowW (testWindowClassW, wszUnicode,
7997 WS_OVERLAPPEDWINDOW,
7998 100, 100, 200, 200, 0, 0, 0, NULL);
7999 assert(hwnd);
8000 flush_sequence();
8001 lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
8002 ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
8003 ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
8004 "got bad length %ld\n", lRes );
8005
8006 flush_sequence();
8007 lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
8008 hwnd, WM_GETTEXTLENGTH, 0, 0);
8009 ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
8010 ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
8011 "got bad length %ld\n", lRes );
8012
8013 wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
8014 newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
8015 lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
8016 ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
8017 NULL, 0, NULL, NULL ) ||
8018 broken(lRes == lstrlenW(dummy_window_text) + 37),
8019 "got bad length %ld\n", lRes );
8020
8021 SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc ); /* restore old wnd proc */
8022 lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
8023 ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
8024 NULL, 0, NULL, NULL ) ||
8025 broken(lRes == lstrlenW(dummy_window_text) + 37),
8026 "got bad length %ld\n", lRes );
8027
8028 ret = DestroyWindow(hwnd);
8029 ok( ret, "DestroyWindow() error %d\n", GetLastError());
8030 }
8031
8032 struct timer_info
8033 {
8034 HWND hWnd;
8035 HANDLE handles[2];
8036 DWORD id;
8037 };
8038
8039 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
8040 {
8041 }
8042
8043 static VOID CALLBACK tfunc_crash(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
8044 {
8045 /* Crash on purpose */
8046 *(volatile int *)0 = 2;
8047 }
8048
8049 #define TIMER_ID 0x19
8050
8051 static DWORD WINAPI timer_thread_proc(LPVOID x)
8052 {
8053 struct timer_info *info = x;
8054 DWORD r;
8055
8056 r = KillTimer(info->hWnd, 0x19);
8057 ok(r,"KillTimer failed in thread\n");
8058 r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
8059 ok(r,"SetTimer failed in thread\n");
8060 ok(r==TIMER_ID,"SetTimer id different\n");
8061 r = SetEvent(info->handles[0]);
8062 ok(r,"SetEvent failed in thread\n");
8063 return 0;
8064 }
8065
8066 static void test_timers(void)
8067 {
8068 struct timer_info info;
8069 DWORD id;
8070 MSG msg;
8071
8072 info.hWnd = CreateWindow ("TestWindowClass", NULL,
8073 WS_OVERLAPPEDWINDOW ,
8074 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8075 NULL, NULL, 0);
8076
8077 info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
8078 ok(info.id, "SetTimer failed\n");
8079 ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
8080 info.handles[0] = CreateEvent(NULL,0,0,NULL);
8081 info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
8082
8083 WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
8084
8085 WaitForSingleObject(info.handles[1], INFINITE);
8086
8087 CloseHandle(info.handles[0]);
8088 CloseHandle(info.handles[1]);
8089
8090 ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
8091
8092 ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
8093
8094 /* Test timer callback with crash */
8095 SetLastError(0xdeadbeef);
8096 info.hWnd = CreateWindowW(testWindowClassW, NULL,
8097 WS_OVERLAPPEDWINDOW ,
8098 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8099 NULL, NULL, 0);
8100 if ((!info.hWnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) || /* Win9x/Me */
8101 (!pGetMenuInfo)) /* Win95/NT4 */
8102 {
8103 win_skip("Test would crash on Win9x/WinMe/NT4\n");
8104 DestroyWindow(info.hWnd);
8105 return;
8106 }
8107 info.id = SetTimer(info.hWnd, TIMER_ID, 0, tfunc_crash);
8108 ok(info.id, "SetTimer failed\n");
8109 Sleep(150);
8110 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8111
8112 ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
8113 }
8114
8115 static int count = 0;
8116 static VOID CALLBACK callback_count(
8117 HWND hwnd,
8118 UINT uMsg,
8119 UINT_PTR idEvent,
8120 DWORD dwTime
8121 )
8122 {
8123 count++;
8124 }
8125
8126 static void test_timers_no_wnd(void)
8127 {
8128 UINT_PTR id, id2;
8129 MSG msg;
8130
8131 count = 0;
8132 id = SetTimer(NULL, 0, 100, callback_count);
8133 ok(id != 0, "did not get id from SetTimer.\n");
8134 id2 = SetTimer(NULL, id, 200, callback_count);
8135 ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
8136 Sleep(150);
8137 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8138 ok(count == 0, "did not get zero count as expected (%i).\n", count);
8139 Sleep(150);
8140 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8141 ok(count == 1, "did not get one count as expected (%i).\n", count);
8142 KillTimer(NULL, id);
8143 Sleep(250);
8144 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8145 ok(count == 1, "killing replaced timer did not work (%i).\n", count);
8146 }
8147
8148 /* Various win events with arbitrary parameters */
8149 static const struct message WmWinEventsSeq[] = {
8150 { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
8151 { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
8152 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
8153 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
8154 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
8155 { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
8156 { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
8157 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
8158 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
8159 /* our win event hook ignores OBJID_CURSOR events */
8160 /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
8161 { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
8162 { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
8163 { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
8164 { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
8165 { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
8166 { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
8167 { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
8168 { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
8169 { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
8170 { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
8171 { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
8172 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
8173 { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
8174 { 0 }
8175 };
8176 static const struct message WmWinEventCaretSeq[] = {
8177 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8178 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8179 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
8180 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8181 { 0 }
8182 };
8183 static const struct message WmWinEventCaretSeq_2[] = {
8184 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8185 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8186 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8187 { 0 }
8188 };
8189 static const struct message WmWinEventAlertSeq[] = {
8190 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
8191 { 0 }
8192 };
8193 static const struct message WmWinEventAlertSeq_2[] = {
8194 /* create window in the thread proc */
8195 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
8196 /* our test event */
8197 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
8198 { 0 }
8199 };
8200 static const struct message WmGlobalHookSeq_1[] = {
8201 /* create window in the thread proc */
8202 { HCBT_CREATEWND, hook|lparam, 0, 2 },
8203 /* our test events */
8204 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
8205 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
8206 { 0 }
8207 };
8208 static const struct message WmGlobalHookSeq_2[] = {
8209 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
8210 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
8211 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
8212 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
8213 { 0 }
8214 };
8215
8216 static const struct message WmMouseLLHookSeq[] = {
8217 { WM_MOUSEMOVE, hook },
8218 { WM_LBUTTONUP, hook },
8219 { WM_MOUSEMOVE, hook },
8220 { 0 }
8221 };
8222
8223 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
8224 DWORD event,
8225 HWND hwnd,
8226 LONG object_id,
8227 LONG child_id,
8228 DWORD thread_id,
8229 DWORD event_time)
8230 {
8231 char buf[256];
8232
8233 if (GetClassNameA(hwnd, buf, sizeof(buf)))
8234 {
8235 if (!lstrcmpiA(buf, "TestWindowClass") ||
8236 !lstrcmpiA(buf, "static"))
8237 {
8238 struct recvd_message msg;
8239
8240 msg.hwnd = hwnd;
8241 msg.message = event;
8242 msg.flags = winevent_hook|wparam|lparam;
8243 msg.wParam = object_id;
8244 msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
8245 msg.descr = "WEH_2";
8246 add_message(&msg);
8247 }
8248 }
8249 }
8250
8251 static HHOOK hCBT_global_hook;
8252 static DWORD cbt_global_hook_thread_id;
8253
8254 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
8255 {
8256 HWND hwnd;
8257 char buf[256];
8258
8259 if (nCode == HCBT_SYSCOMMAND)
8260 {
8261 struct recvd_message msg;
8262
8263 msg.hwnd = 0;
8264 msg.message = nCode;
8265 msg.flags = hook|wparam|lparam;
8266 msg.wParam = wParam;
8267 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8268 msg.descr = "CBT_2";
8269 add_message(&msg);
8270
8271 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8272 }
8273 /* WH_MOUSE_LL hook */
8274 if (nCode == HC_ACTION)
8275 {
8276 MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
8277
8278 /* we can't test for real mouse events */
8279 if (mhll->flags & LLMHF_INJECTED)
8280 {
8281 struct recvd_message msg;
8282
8283 memset (&msg, 0, sizeof (msg));
8284 msg.message = wParam;
8285 msg.flags = hook;
8286 msg.descr = "CBT_2";
8287 add_message(&msg);
8288 }
8289 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8290 }
8291
8292 /* Log also SetFocus(0) calls */
8293 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
8294
8295 if (GetClassNameA(hwnd, buf, sizeof(buf)))
8296 {
8297 if (!lstrcmpiA(buf, "TestWindowClass") ||
8298 !lstrcmpiA(buf, "static"))
8299 {
8300 struct recvd_message msg;
8301
8302 msg.hwnd = hwnd;
8303 msg.message = nCode;
8304 msg.flags = hook|wparam|lparam;
8305 msg.wParam = wParam;
8306 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8307 msg.descr = "CBT_2";
8308 add_message(&msg);
8309 }
8310 }
8311 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8312 }
8313
8314 static DWORD WINAPI win_event_global_thread_proc(void *param)
8315 {
8316 HWND hwnd;
8317 MSG msg;
8318 HANDLE hevent = *(HANDLE *)param;
8319
8320 assert(pNotifyWinEvent);
8321
8322 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8323 assert(hwnd);
8324 trace("created thread window %p\n", hwnd);
8325
8326 *(HWND *)param = hwnd;
8327
8328 flush_sequence();
8329 /* this event should be received only by our new hook proc,
8330 * an old one does not expect an event from another thread.
8331 */
8332 pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
8333 SetEvent(hevent);
8334
8335 while (GetMessage(&msg, 0, 0, 0))
8336 {
8337 TranslateMessage(&msg);
8338 DispatchMessage(&msg);
8339 }
8340 return 0;
8341 }
8342
8343 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
8344 {
8345 HWND hwnd;
8346 MSG msg;
8347 HANDLE hevent = *(HANDLE *)param;
8348
8349 flush_sequence();
8350 /* these events should be received only by our new hook proc,
8351 * an old one does not expect an event from another thread.
8352 */
8353
8354 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8355 assert(hwnd);
8356 trace("created thread window %p\n", hwnd);
8357
8358 *(HWND *)param = hwnd;
8359
8360 /* Windows doesn't like when a thread plays games with the focus,
8361 that leads to all kinds of misbehaviours and failures to activate
8362 a window. So, better keep next lines commented out.
8363 SetFocus(0);
8364 SetFocus(hwnd);*/
8365
8366 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8367 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8368
8369 SetEvent(hevent);
8370
8371 while (GetMessage(&msg, 0, 0, 0))
8372 {
8373 TranslateMessage(&msg);
8374 DispatchMessage(&msg);
8375 }
8376 return 0;
8377 }
8378
8379 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
8380 {
8381 HWND hwnd;
8382 MSG msg;
8383 HANDLE hevent = *(HANDLE *)param;
8384
8385 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8386 assert(hwnd);
8387 trace("created thread window %p\n", hwnd);
8388
8389 *(HWND *)param = hwnd;
8390
8391 flush_sequence();
8392
8393 /* Windows doesn't like when a thread plays games with the focus,
8394 * that leads to all kinds of misbehaviours and failures to activate
8395 * a window. So, better don't generate a mouse click message below.
8396 */
8397 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8398 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8399 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8400
8401 SetEvent(hevent);
8402 while (GetMessage(&msg, 0, 0, 0))
8403 {
8404 TranslateMessage(&msg);
8405 DispatchMessage(&msg);
8406 }
8407 return 0;
8408 }
8409
8410 static void test_winevents(void)
8411 {
8412 BOOL ret;
8413 MSG msg;
8414 HWND hwnd, hwnd2;
8415 UINT i;
8416 HANDLE hthread, hevent;
8417 DWORD tid;
8418 HWINEVENTHOOK hhook;
8419 const struct message *events = WmWinEventsSeq;
8420
8421 hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
8422 WS_OVERLAPPEDWINDOW,
8423 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8424 NULL, NULL, 0);
8425 assert(hwnd);
8426
8427 /****** start of global hook test *************/
8428 hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8429 if (!hCBT_global_hook)
8430 {
8431 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8432 skip( "cannot set global hook\n" );
8433 return;
8434 }
8435
8436 hevent = CreateEventA(NULL, 0, 0, NULL);
8437 assert(hevent);
8438 hwnd2 = hevent;
8439
8440 hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
8441 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8442
8443 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8444
8445 ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
8446
8447 flush_sequence();
8448 /* this one should be received only by old hook proc */
8449 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8450 /* this one should be received only by old hook proc */
8451 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8452
8453 ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
8454
8455 ret = UnhookWindowsHookEx(hCBT_global_hook);
8456 ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8457
8458 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8459 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8460 CloseHandle(hthread);
8461 CloseHandle(hevent);
8462 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8463 /****** end of global hook test *************/
8464
8465 if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
8466 {
8467 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8468 return;
8469 }
8470
8471 flush_sequence();
8472
8473 if (0)
8474 {
8475 /* this test doesn't pass under Win9x */
8476 /* win2k ignores events with hwnd == 0 */
8477 SetLastError(0xdeadbeef);
8478 pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
8479 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
8480 GetLastError() == 0xdeadbeef, /* Win9x */
8481 "unexpected error %d\n", GetLastError());
8482 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8483 }
8484
8485 for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
8486 pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
8487
8488 ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
8489
8490 /****** start of event filtering test *************/
8491 hhook = pSetWinEventHook(
8492 EVENT_OBJECT_SHOW, /* 0x8002 */
8493 EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
8494 GetModuleHandleA(0), win_event_global_hook_proc,
8495 GetCurrentProcessId(), 0,
8496 WINEVENT_INCONTEXT);
8497 ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8498
8499 hevent = CreateEventA(NULL, 0, 0, NULL);
8500 assert(hevent);
8501 hwnd2 = hevent;
8502
8503 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8504 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8505
8506 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8507
8508 ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
8509
8510 flush_sequence();
8511 /* this one should be received only by old hook proc */
8512 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8513 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8514 /* this one should be received only by old hook proc */
8515 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8516
8517 ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
8518
8519 ret = pUnhookWinEvent(hhook);
8520 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8521
8522 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8523 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8524 CloseHandle(hthread);
8525 CloseHandle(hevent);
8526 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8527 /****** end of event filtering test *************/
8528
8529 /****** start of out of context event test *************/
8530 hhook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0,
8531 win_event_global_hook_proc, GetCurrentProcessId(), 0,
8532 WINEVENT_OUTOFCONTEXT);
8533 ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8534
8535 hevent = CreateEventA(NULL, 0, 0, NULL);
8536 assert(hevent);
8537 hwnd2 = hevent;
8538
8539 flush_sequence();
8540
8541 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8542 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8543
8544 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8545
8546 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8547 /* process pending winevent messages */
8548 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8549 ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
8550
8551 flush_sequence();
8552 /* this one should be received only by old hook proc */
8553 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8554 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8555 /* this one should be received only by old hook proc */
8556 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8557
8558 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
8559 /* process pending winevent messages */
8560 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8561 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
8562
8563 ret = pUnhookWinEvent(hhook);
8564 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8565
8566 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8567 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8568 CloseHandle(hthread);
8569 CloseHandle(hevent);
8570 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8571 /****** end of out of context event test *************/
8572
8573 /****** start of MOUSE_LL hook test *************/
8574 hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8575 /* WH_MOUSE_LL is not supported on Win9x platforms */
8576 if (!hCBT_global_hook)
8577 {
8578 win_skip("Skipping WH_MOUSE_LL test on this platform\n");
8579 goto skip_mouse_ll_hook_test;
8580 }
8581
8582 hevent = CreateEventA(NULL, 0, 0, NULL);
8583 assert(hevent);
8584 hwnd2 = hevent;
8585
8586 hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
8587 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8588
8589 while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
8590 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
8591
8592 ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
8593 flush_sequence();
8594
8595 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8596 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8597 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8598
8599 ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
8600
8601 ret = UnhookWindowsHookEx(hCBT_global_hook);
8602 ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8603
8604 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8605 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8606 CloseHandle(hthread);
8607 CloseHandle(hevent);
8608 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8609 /****** end of MOUSE_LL hook test *************/
8610 skip_mouse_ll_hook_test:
8611
8612 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8613 }
8614
8615 static void test_set_hook(void)
8616 {
8617 BOOL ret;
8618 HHOOK hhook;
8619 HWINEVENTHOOK hwinevent_hook;
8620
8621 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
8622 ok(hhook != 0, "local hook does not require hModule set to 0\n");
8623 UnhookWindowsHookEx(hhook);
8624
8625 if (0)
8626 {
8627 /* this test doesn't pass under Win9x: BUG! */
8628 SetLastError(0xdeadbeef);
8629 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
8630 ok(!hhook, "global hook requires hModule != 0\n");
8631 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
8632 }
8633
8634 SetLastError(0xdeadbeef);
8635 hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
8636 ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
8637 ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
8638 GetLastError() == 0xdeadbeef, /* Win9x */
8639 "unexpected error %d\n", GetLastError());
8640
8641 SetLastError(0xdeadbeef);
8642 ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
8643 ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
8644 GetLastError() == 0xdeadbeef, /* Win9x */
8645 "unexpected error %d\n", GetLastError());
8646
8647 if (!pSetWinEventHook || !pUnhookWinEvent) return;
8648
8649 /* even process local incontext hooks require hmodule */
8650 SetLastError(0xdeadbeef);
8651 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8652 GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
8653 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8654 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8655 GetLastError() == 0xdeadbeef, /* Win9x */
8656 "unexpected error %d\n", GetLastError());
8657
8658 /* even thread local incontext hooks require hmodule */
8659 SetLastError(0xdeadbeef);
8660 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8661 GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
8662 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8663 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8664 GetLastError() == 0xdeadbeef, /* Win9x */
8665 "unexpected error %d\n", GetLastError());
8666
8667 if (0)
8668 {
8669 /* these 3 tests don't pass under Win9x */
8670 SetLastError(0xdeadbeef);
8671 hwinevent_hook = pSetWinEventHook(1, 0, 0, win_event_proc,
8672 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8673 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8674 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8675
8676 SetLastError(0xdeadbeef);
8677 hwinevent_hook = pSetWinEventHook(-1, 1, 0, win_event_proc,
8678 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8679 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8680 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8681
8682 SetLastError(0xdeadbeef);
8683 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8684 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
8685 ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
8686 ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
8687 }
8688
8689 SetLastError(0xdeadbeef);
8690 hwinevent_hook = pSetWinEventHook(0, 0, 0, win_event_proc,
8691 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8692 ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8693 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8694 ret = pUnhookWinEvent(hwinevent_hook);
8695 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8696
8697 todo_wine {
8698 /* This call succeeds under win2k SP4, but fails under Wine.
8699 Does win2k test/use passed process id? */
8700 SetLastError(0xdeadbeef);
8701 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8702 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
8703 ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8704 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8705 ret = pUnhookWinEvent(hwinevent_hook);
8706 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8707 }
8708
8709 SetLastError(0xdeadbeef);
8710 ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
8711 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
8712 GetLastError() == 0xdeadbeef, /* Win9x */
8713 "unexpected error %d\n", GetLastError());
8714 }
8715
8716 static const struct message ScrollWindowPaint1[] = {
8717 { WM_PAINT, sent },
8718 { WM_ERASEBKGND, sent|beginpaint },
8719 { WM_GETTEXTLENGTH, sent|optional },
8720 { WM_PAINT, sent|optional },
8721 { WM_NCPAINT, sent|beginpaint|optional },
8722 { WM_GETTEXT, sent|beginpaint|optional },
8723 { WM_GETTEXT, sent|beginpaint|optional },
8724 { WM_GETTEXT, sent|beginpaint|optional },
8725 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
8726 { WM_ERASEBKGND, sent|beginpaint|optional },
8727 { 0 }
8728 };
8729
8730 static const struct message ScrollWindowPaint2[] = {
8731 { WM_PAINT, sent },
8732 { 0 }
8733 };
8734
8735 static void test_scrollwindowex(void)
8736 {
8737 HWND hwnd, hchild;
8738 RECT rect={0,0,130,130};
8739
8740 hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
8741 WS_VISIBLE|WS_OVERLAPPEDWINDOW,
8742 100, 100, 200, 200, 0, 0, 0, NULL);
8743 ok (hwnd != 0, "Failed to create overlapped window\n");
8744 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
8745 WS_VISIBLE|WS_CAPTION|WS_CHILD,
8746 10, 10, 150, 150, hwnd, 0, 0, NULL);
8747 ok (hchild != 0, "Failed to create child\n");
8748 UpdateWindow(hwnd);
8749 flush_events();
8750 flush_sequence();
8751
8752 /* scroll without the child window */
8753 trace("start scroll\n");
8754 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8755 SW_ERASE|SW_INVALIDATE);
8756 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8757 trace("end scroll\n");
8758 flush_sequence();
8759 flush_events();
8760 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8761 flush_events();
8762 flush_sequence();
8763
8764 /* Now without the SW_ERASE flag */
8765 trace("start scroll\n");
8766 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
8767 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8768 trace("end scroll\n");
8769 flush_sequence();
8770 flush_events();
8771 ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
8772 flush_events();
8773 flush_sequence();
8774
8775 /* now scroll the child window as well */
8776 trace("start scroll\n");
8777 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8778 SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
8779 /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
8780 /* windows sometimes a WM_MOVE */
8781 ok_sequence(WmEmptySeq, "ScrollWindowEx", TRUE);
8782 trace("end scroll\n");
8783 flush_sequence();
8784 flush_events();
8785 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8786 flush_events();
8787 flush_sequence();
8788
8789 /* now scroll with ScrollWindow() */
8790 trace("start scroll with ScrollWindow\n");
8791 ScrollWindow( hwnd, 5, 5, NULL, NULL);
8792 trace("end scroll\n");
8793 flush_sequence();
8794 flush_events();
8795 ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
8796
8797 ok(DestroyWindow(hchild), "failed to destroy window\n");
8798 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8799 flush_sequence();
8800 }
8801
8802 static const struct message destroy_window_with_children[] = {
8803 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8804 { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
8805 { 0x0090, sent|optional },
8806 { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
8807 { 0x0090, sent|optional },
8808 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8809 { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8810 { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8811 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8812 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
8813 { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8814 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8815 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8816 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8817 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8818 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8819 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8820 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8821 { 0 }
8822 };
8823
8824 static void test_DestroyWindow(void)
8825 {
8826 BOOL ret;
8827 HWND parent, child1, child2, child3, child4, test;
8828 UINT_PTR child_id = WND_CHILD_ID + 1;
8829
8830 parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8831 100, 100, 200, 200, 0, 0, 0, NULL);
8832 assert(parent != 0);
8833 child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8834 0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
8835 assert(child1 != 0);
8836 child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8837 0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
8838 assert(child2 != 0);
8839 child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8840 0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
8841 assert(child3 != 0);
8842 child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
8843 0, 0, 50, 50, parent, 0, 0, NULL);
8844 assert(child4 != 0);
8845
8846 /* test owner/parent of child2 */
8847 test = GetParent(child2);
8848 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8849 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8850 if(pGetAncestor) {
8851 test = pGetAncestor(child2, GA_PARENT);
8852 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8853 }
8854 test = GetWindow(child2, GW_OWNER);
8855 ok(!test, "wrong owner %p\n", test);
8856
8857 test = SetParent(child2, parent);
8858 ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
8859
8860 /* test owner/parent of the parent */
8861 test = GetParent(parent);
8862 ok(!test, "wrong parent %p\n", test);
8863 ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
8864 if(pGetAncestor) {
8865 test = pGetAncestor(parent, GA_PARENT);
8866 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8867 }
8868 test = GetWindow(parent, GW_OWNER);
8869 ok(!test, "wrong owner %p\n", test);
8870
8871 /* test owner/parent of child1 */
8872 test = GetParent(child1);
8873 ok(test == parent, "wrong parent %p\n", test);
8874 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
8875 if(pGetAncestor) {
8876 test = pGetAncestor(child1, GA_PARENT);
8877 ok(test == parent, "wrong parent %p\n", test);
8878 }
8879 test = GetWindow(child1, GW_OWNER);
8880 ok(!test, "wrong owner %p\n", test);
8881
8882 /* test owner/parent of child2 */
8883 test = GetParent(child2);
8884 ok(test == parent, "wrong parent %p\n", test);
8885 ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8886 if(pGetAncestor) {
8887 test = pGetAncestor(child2, GA_PARENT);
8888 ok(test == parent, "wrong parent %p\n", test);
8889 }
8890 test = GetWindow(child2, GW_OWNER);
8891 ok(!test, "wrong owner %p\n", test);
8892
8893 /* test owner/parent of child3 */
8894 test = GetParent(child3);
8895 ok(test == child1, "wrong parent %p\n", test);
8896 ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
8897 if(pGetAncestor) {
8898 test = pGetAncestor(child3, GA_PARENT);
8899 ok(test == child1, "wrong parent %p\n", test);
8900 }
8901 test = GetWindow(child3, GW_OWNER);
8902 ok(!test, "wrong owner %p\n", test);
8903
8904 /* test owner/parent of child4 */
8905 test = GetParent(child4);
8906 ok(test == parent, "wrong parent %p\n", test);
8907 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
8908 if(pGetAncestor) {
8909 test = pGetAncestor(child4, GA_PARENT);
8910 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8911 }
8912 test = GetWindow(child4, GW_OWNER);
8913 ok(test == parent, "wrong owner %p\n", test);
8914
8915 flush_sequence();
8916
8917 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
8918 parent, child1, child2, child3, child4);
8919
8920 SetCapture(child4);
8921 test = GetCapture();
8922 ok(test == child4, "wrong capture window %p\n", test);
8923
8924 test_DestroyWindow_flag = TRUE;
8925 ret = DestroyWindow(parent);
8926 ok( ret, "DestroyWindow() error %d\n", GetLastError());
8927 test_DestroyWindow_flag = FALSE;
8928 ok_sequence(destroy_window_with_children, "destroy window with children", 0);
8929
8930 ok(!IsWindow(parent), "parent still exists\n");
8931 ok(!IsWindow(child1), "child1 still exists\n");
8932 ok(!IsWindow(child2), "child2 still exists\n");
8933 ok(!IsWindow(child3), "child3 still exists\n");
8934 ok(!IsWindow(child4), "child4 still exists\n");
8935
8936 test = GetCapture();
8937 ok(!test, "wrong capture window %p\n", test);
8938 }
8939
8940
8941 static const struct message WmDispatchPaint[] = {
8942 { WM_NCPAINT, sent },
8943 { WM_GETTEXT, sent|defwinproc|optional },
8944 { WM_GETTEXT, sent|defwinproc|optional },
8945 { WM_ERASEBKGND, sent },
8946 { 0 }
8947 };
8948
8949 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8950 {
8951 if (message == WM_PAINT) return 0;
8952 return MsgCheckProcA( hwnd, message, wParam, lParam );
8953 }
8954
8955 static void test_DispatchMessage(void)
8956 {
8957 RECT rect;
8958 MSG msg;
8959 int count;
8960 HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8961 100, 100, 200, 200, 0, 0, 0, NULL);
8962 ShowWindow( hwnd, SW_SHOW );
8963 UpdateWindow( hwnd );
8964 flush_events();
8965 flush_sequence();
8966 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
8967
8968 SetRect( &rect, -5, -5, 5, 5 );
8969 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8970 count = 0;
8971 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8972 {
8973 if (msg.message != WM_PAINT) DispatchMessage( &msg );
8974 else
8975 {
8976 flush_sequence();
8977 DispatchMessage( &msg );
8978 /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
8979 if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8980 else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
8981 if (++count > 10) break;
8982 }
8983 }
8984 ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
8985
8986 trace("now without DispatchMessage\n");
8987 flush_sequence();
8988 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8989 count = 0;
8990 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8991 {
8992 if (msg.message != WM_PAINT) DispatchMessage( &msg );
8993 else
8994 {
8995 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
8996 flush_sequence();
8997 /* this will send WM_NCCPAINT just like DispatchMessage does */
8998 GetUpdateRgn( hwnd, hrgn, TRUE );
8999 ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
9000 DeleteObject( hrgn );
9001 GetClientRect( hwnd, &rect );
9002 ValidateRect( hwnd, &rect ); /* this will stop WM_PAINTs */
9003 ok( !count, "Got multiple WM_PAINTs\n" );
9004 if (++count > 10) break;
9005 }
9006 }
9007 DestroyWindow(hwnd);
9008 }
9009
9010
9011 static const struct message WmUser[] = {
9012 { WM_USER, sent },
9013 { 0 }
9014 };
9015
9016 struct sendmsg_info
9017 {
9018 HWND hwnd;
9019 DWORD timeout;
9020 DWORD ret;
9021 };
9022
9023 static DWORD CALLBACK send_msg_thread( LPVOID arg )
9024 {
9025 struct sendmsg_info *info = arg;
9026 SetLastError( 0xdeadbeef );
9027 info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
9028 if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT ||
9029 broken(GetLastError() == 0), /* win9x */
9030 "unexpected error %d\n", GetLastError());
9031 return 0;
9032 }
9033
9034 static void wait_for_thread( HANDLE thread )
9035 {
9036 while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
9037 {
9038 MSG msg;
9039 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
9040 }
9041 }
9042
9043 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9044 {
9045 if (message == WM_USER) Sleep(200);
9046 return MsgCheckProcA( hwnd, message, wParam, lParam );
9047 }
9048
9049 static void test_SendMessageTimeout(void)
9050 {
9051 HANDLE thread;
9052 struct sendmsg_info info;
9053 DWORD tid;
9054 BOOL is_win9x;
9055
9056 info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9057 100, 100, 200, 200, 0, 0, 0, NULL);
9058 flush_events();
9059 flush_sequence();
9060
9061 info.timeout = 1000;
9062 info.ret = 0xdeadbeef;
9063 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9064 wait_for_thread( thread );
9065 CloseHandle( thread );
9066 ok( info.ret == 1, "SendMessageTimeout failed\n" );
9067 ok_sequence( WmUser, "WmUser", FALSE );
9068
9069 info.timeout = 1;
9070 info.ret = 0xdeadbeef;
9071 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9072 Sleep(100); /* SendMessageTimeout should time out here */
9073 wait_for_thread( thread );
9074 CloseHandle( thread );
9075 ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
9076 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9077
9078 /* 0 means infinite timeout (but not on win9x) */
9079 info.timeout = 0;
9080 info.ret = 0xdeadbeef;
9081 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9082 Sleep(100);
9083 wait_for_thread( thread );
9084 CloseHandle( thread );
9085 is_win9x = !info.ret;
9086 if (is_win9x) ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9087 else ok_sequence( WmUser, "WmUser", FALSE );
9088
9089 /* timeout is treated as signed despite the prototype (but not on win9x) */
9090 info.timeout = 0x7fffffff;
9091 info.ret = 0xdeadbeef;
9092 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9093 Sleep(100);
9094 wait_for_thread( thread );
9095 CloseHandle( thread );
9096 ok( info.ret == 1, "SendMessageTimeout failed\n" );
9097 ok_sequence( WmUser, "WmUser", FALSE );
9098
9099 info.timeout = 0x80000000;
9100 info.ret = 0xdeadbeef;
9101 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9102 Sleep(100);
9103 wait_for_thread( thread );
9104 CloseHandle( thread );
9105 if (is_win9x)
9106 {
9107 ok( info.ret == 1, "SendMessageTimeout failed\n" );
9108 ok_sequence( WmUser, "WmUser", FALSE );
9109 }
9110 else
9111 {
9112 ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
9113 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9114 }
9115
9116 /* now check for timeout during message processing */
9117 SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
9118 info.timeout = 100;
9119 info.ret = 0xdeadbeef;
9120 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9121 wait_for_thread( thread );
9122 CloseHandle( thread );
9123 /* we should time out but still get the message */
9124 ok( info.ret == 0, "SendMessageTimeout failed\n" );
9125 ok_sequence( WmUser, "WmUser", FALSE );
9126
9127 DestroyWindow( info.hwnd );
9128 }
9129
9130
9131 /****************** edit message test *************************/
9132 #define ID_EDIT 0x1234
9133 static const struct message sl_edit_setfocus[] =
9134 {
9135 { HCBT_SETFOCUS, hook },
9136 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9137 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9138 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9139 { WM_SETFOCUS, sent|wparam, 0 },
9140 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9141 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
9142 { WM_CTLCOLOREDIT, sent|parent },
9143 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9144 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9145 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9146 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9147 { 0 }
9148 };
9149 static const struct message ml_edit_setfocus[] =
9150 {
9151 { HCBT_SETFOCUS, hook },
9152 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9153 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9154 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9155 { WM_SETFOCUS, sent|wparam, 0 },
9156 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9157 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9158 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9159 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9160 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9161 { 0 }
9162 };
9163 static const struct message sl_edit_killfocus[] =
9164 {
9165 { HCBT_SETFOCUS, hook },
9166 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9167 { WM_KILLFOCUS, sent|wparam, 0 },
9168 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9169 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9170 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
9171 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
9172 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
9173 { 0 }
9174 };
9175 static const struct message sl_edit_lbutton_dblclk[] =
9176 {
9177 { WM_LBUTTONDBLCLK, sent },
9178 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9179 { 0 }
9180 };
9181 static const struct message sl_edit_lbutton_down[] =
9182 {
9183 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
9184 { HCBT_SETFOCUS, hook },
9185 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9186 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9187 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9188 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9189 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9190 { WM_CTLCOLOREDIT, sent|parent },
9191 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9192 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9193 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9194 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9195 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9196 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9197 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9198 { WM_CTLCOLOREDIT, sent|parent|optional },
9199 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9200 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9201 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9202 { 0 }
9203 };
9204 static const struct message ml_edit_lbutton_down[] =
9205 {
9206 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
9207 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9208 { HCBT_SETFOCUS, hook },
9209 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9210 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9211 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9212 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9213 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9214 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9215 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9216 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9217 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9218 { 0 }
9219 };
9220 static const struct message sl_edit_lbutton_up[] =
9221 {
9222 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9223 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9224 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9225 { WM_CAPTURECHANGED, sent|defwinproc },
9226 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9227 { 0 }
9228 };
9229 static const struct message ml_edit_lbutton_up[] =
9230 {
9231 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9232 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9233 { WM_CAPTURECHANGED, sent|defwinproc },
9234 { 0 }
9235 };
9236
9237 static WNDPROC old_edit_proc;
9238
9239 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9240 {
9241 static LONG defwndproc_counter = 0;
9242 LRESULT ret;
9243 struct recvd_message msg;
9244
9245 if (ignore_message( message )) return 0;
9246
9247 msg.hwnd = hwnd;
9248 msg.message = message;
9249 msg.flags = sent|wparam|lparam;
9250 if (defwndproc_counter) msg.flags |= defwinproc;
9251 msg.wParam = wParam;
9252 msg.lParam = lParam;
9253 msg.descr = "edit";
9254 add_message(&msg);
9255
9256 defwndproc_counter++;
9257 ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
9258 defwndproc_counter--;
9259
9260 return ret;
9261 }
9262
9263 static void subclass_edit(void)
9264 {
9265 WNDCLASSA cls;
9266
9267 if (!GetClassInfoA(0, "edit", &cls)) assert(0);
9268
9269 old_edit_proc = cls.lpfnWndProc;
9270
9271 cls.hInstance = GetModuleHandle(0);
9272 cls.lpfnWndProc = edit_hook_proc;
9273 cls.lpszClassName = "my_edit_class";
9274 UnregisterClass(cls.lpszClassName, cls.hInstance);
9275 if (!RegisterClassA(&cls)) assert(0);
9276 }
9277
9278 static void test_edit_messages(void)
9279 {
9280 HWND hwnd, parent;
9281 DWORD dlg_code;
9282
9283 subclass_edit();
9284 log_all_parent_messages++;
9285
9286 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9287 100, 100, 200, 200, 0, 0, 0, NULL);
9288 ok (parent != 0, "Failed to create parent window\n");
9289
9290 /* test single line edit */
9291 hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
9292 0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9293 ok(hwnd != 0, "Failed to create edit window\n");
9294
9295 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9296 ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
9297
9298 ShowWindow(hwnd, SW_SHOW);
9299 UpdateWindow(hwnd);
9300 SetFocus(0);
9301 flush_sequence();
9302
9303 SetFocus(hwnd);
9304 ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
9305
9306 SetFocus(0);
9307 ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
9308
9309 SetFocus(0);
9310 ReleaseCapture();
9311 flush_sequence();
9312
9313 SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9314 ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
9315
9316 SetFocus(0);
9317 ReleaseCapture();
9318 flush_sequence();
9319
9320 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9321 ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
9322
9323 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9324 ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
9325
9326 DestroyWindow(hwnd);
9327
9328 /* test multiline edit */
9329 hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
9330 0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9331 ok(hwnd != 0, "Failed to create edit window\n");
9332
9333 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9334 ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
9335 "wrong dlg_code %08x\n", dlg_code);
9336
9337 ShowWindow(hwnd, SW_SHOW);
9338 UpdateWindow(hwnd);
9339 SetFocus(0);
9340 flush_sequence();
9341
9342 SetFocus(hwnd);
9343 ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
9344
9345 SetFocus(0);
9346 ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
9347
9348 SetFocus(0);
9349 ReleaseCapture();
9350 flush_sequence();
9351
9352 SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9353 ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
9354
9355 SetFocus(0);
9356 ReleaseCapture();
9357 flush_sequence();
9358
9359 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9360 ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
9361
9362 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9363 ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
9364
9365 DestroyWindow(hwnd);
9366 DestroyWindow(parent);
9367
9368 log_all_parent_messages--;
9369 }
9370
9371 /**************************** End of Edit test ******************************/
9372
9373 static const struct message WmKeyDownSkippedSeq[] =
9374 {
9375 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
9376 { 0 }
9377 };
9378 static const struct message WmKeyDownWasDownSkippedSeq[] =
9379 {
9380 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x40000001 }, /* XP */
9381 { 0 }
9382 };
9383 static const struct message WmKeyUpSkippedSeq[] =
9384 {
9385 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9386 { 0 }
9387 };
9388 static const struct message WmUserKeyUpSkippedSeq[] =
9389 {
9390 { WM_USER, sent },
9391 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9392 { 0 }
9393 };
9394
9395 #define EV_STOP 0
9396 #define EV_SENDMSG 1
9397 #define EV_ACK 2
9398
9399 struct peekmsg_info
9400 {
9401 HWND hwnd;
9402 HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
9403 };
9404
9405 static DWORD CALLBACK send_msg_thread_2(void *param)
9406 {
9407 DWORD ret;
9408 struct peekmsg_info *info = param;
9409
9410 trace("thread: looping\n");
9411 SetEvent(info->hevent[EV_ACK]);
9412
9413 while (1)
9414 {
9415 ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
9416
9417 switch (ret)
9418 {
9419 case WAIT_OBJECT_0 + EV_STOP:
9420 trace("thread: exiting\n");
9421 return 0;
9422
9423 case WAIT_OBJECT_0 + EV_SENDMSG:
9424 trace("thread: sending message\n");
9425 ok( SendNotifyMessageA(info->hwnd, WM_USER, 0, 0),
9426 "SendNotifyMessageA failed error %u\n", GetLastError());
9427 SetEvent(info->hevent[EV_ACK]);
9428 break;
9429
9430 default:
9431 trace("unexpected return: %04x\n", ret);
9432 assert(0);
9433 break;
9434 }
9435 }
9436 return 0;
9437 }
9438
9439 static void test_PeekMessage(void)
9440 {
9441 MSG msg;
9442 HANDLE hthread;
9443 DWORD tid, qstatus;
9444 UINT qs_all_input = QS_ALLINPUT;
9445 UINT qs_input = QS_INPUT;
9446 BOOL ret;
9447 struct peekmsg_info info;
9448
9449 info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9450 100, 100, 200, 200, 0, 0, 0, NULL);
9451 assert(info.hwnd);
9452 ShowWindow(info.hwnd, SW_SHOW);
9453 UpdateWindow(info.hwnd);
9454 SetFocus(info.hwnd);
9455
9456 info.hevent[EV_STOP] = CreateEventA(NULL, 0, 0, NULL);
9457 info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
9458 info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
9459
9460 hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
9461 WaitForSingleObject(info.hevent[EV_ACK], 10000);
9462
9463 flush_events();
9464 flush_sequence();
9465
9466 SetLastError(0xdeadbeef);
9467 qstatus = GetQueueStatus(qs_all_input);
9468 if (GetLastError() == ERROR_INVALID_FLAGS)
9469 {
9470 trace("QS_RAWINPUT not supported on this platform\n");
9471 qs_all_input &= ~QS_RAWINPUT;
9472 qs_input &= ~QS_RAWINPUT;
9473 }
9474 if (qstatus & QS_POSTMESSAGE)
9475 {
9476 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) /* nothing */ ;
9477 qstatus = GetQueueStatus(qs_all_input);
9478 }
9479 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9480
9481 trace("signalling to send message\n");
9482 SetEvent(info.hevent[EV_SENDMSG]);
9483 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9484
9485 /* pass invalid QS_xxxx flags */
9486 SetLastError(0xdeadbeef);
9487 qstatus = GetQueueStatus(0xffffffff);
9488 ok(qstatus == 0 || broken(qstatus) /* win9x */, "GetQueueStatus should fail: %08x\n", qstatus);
9489 if (!qstatus)
9490 {
9491 ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
9492 qstatus = GetQueueStatus(qs_all_input);
9493 }
9494 qstatus &= ~MAKELONG( 0x4000, 0x4000 ); /* sometimes set on Win95 */
9495 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
9496 "wrong qstatus %08x\n", qstatus);
9497
9498 msg.message = 0;
9499 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9500 ok(!ret,
9501 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9502 msg.message);
9503 ok_sequence(WmUser, "WmUser", FALSE);
9504
9505 qstatus = GetQueueStatus(qs_all_input);
9506 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9507
9508 keybd_event('N', 0, 0, 0);
9509 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9510 qstatus = GetQueueStatus(qs_all_input);
9511 if (!(qstatus & MAKELONG(QS_KEY, QS_KEY)))
9512 {
9513 skip( "queuing key events not supported\n" );
9514 goto done;
9515 }
9516 ok(qstatus == MAKELONG(QS_KEY, QS_KEY) ||
9517 /* keybd_event seems to trigger a sent message on NT4 */
9518 qstatus == MAKELONG(QS_KEY|QS_SENDMESSAGE, QS_KEY|QS_SENDMESSAGE),
9519 "wrong qstatus %08x\n", qstatus);
9520
9521 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9522 qstatus = GetQueueStatus(qs_all_input);
9523 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY) ||
9524 qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY|QS_SENDMESSAGE),
9525 "wrong qstatus %08x\n", qstatus);
9526
9527 InvalidateRect(info.hwnd, NULL, FALSE);
9528 qstatus = GetQueueStatus(qs_all_input);
9529 ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY) ||
9530 qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY|QS_SENDMESSAGE),
9531 "wrong qstatus %08x\n", qstatus);
9532
9533 trace("signalling to send message\n");
9534 SetEvent(info.hevent[EV_SENDMSG]);
9535 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9536
9537 qstatus = GetQueueStatus(qs_all_input);
9538 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9539 "wrong qstatus %08x\n", qstatus);
9540
9541 msg.message = 0;
9542 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
9543 if (ret && msg.message == WM_CHAR)
9544 {
9545 win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9546 goto done;
9547 }
9548 ok(!ret,
9549 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9550 msg.message);
9551 if (!sequence_cnt) /* nt4 doesn't fetch anything with PM_QS_* flags */
9552 {
9553 win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9554 goto done;
9555 }
9556 ok_sequence(WmUser, "WmUser", FALSE);
9557
9558 qstatus = GetQueueStatus(qs_all_input);
9559 ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9560 "wrong qstatus %08x\n", qstatus);
9561
9562 trace("signalling to send message\n");
9563 SetEvent(info.hevent[EV_SENDMSG]);
9564 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9565
9566 qstatus = GetQueueStatus(qs_all_input);
9567 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9568 "wrong qstatus %08x\n", qstatus);
9569
9570 msg.message = 0;
9571 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE );
9572 ok(!ret,
9573 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9574 msg.message);
9575 ok_sequence(WmUser, "WmUser", FALSE);
9576
9577 qstatus = GetQueueStatus(qs_all_input);
9578 ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9579 "wrong qstatus %08x\n", qstatus);
9580
9581 msg.message = 0;
9582 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9583 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9584 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9585 ret, msg.message, msg.wParam);
9586 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9587
9588 qstatus = GetQueueStatus(qs_all_input);
9589 ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9590 "wrong qstatus %08x\n", qstatus);
9591
9592 msg.message = 0;
9593 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9594 ok(!ret,
9595 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9596 msg.message);
9597 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9598
9599 qstatus = GetQueueStatus(qs_all_input);
9600 ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9601 "wrong qstatus %08x\n", qstatus);
9602
9603 msg.message = 0;
9604 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9605 ok(ret && msg.message == WM_PAINT,
9606 "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
9607 DispatchMessageA(&msg);
9608 ok_sequence(WmPaint, "WmPaint", FALSE);
9609
9610 qstatus = GetQueueStatus(qs_all_input);
9611 ok(qstatus == MAKELONG(0, QS_KEY),
9612 "wrong qstatus %08x\n", qstatus);
9613
9614 msg.message = 0;
9615 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9616 ok(!ret,
9617 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9618 msg.message);
9619 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9620
9621 qstatus = GetQueueStatus(qs_all_input);
9622 ok(qstatus == MAKELONG(0, QS_KEY),
9623 "wrong qstatus %08x\n", qstatus);
9624
9625 trace("signalling to send message\n");
9626 SetEvent(info.hevent[EV_SENDMSG]);
9627 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9628
9629 qstatus = GetQueueStatus(qs_all_input);
9630 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
9631 "wrong qstatus %08x\n", qstatus);
9632
9633 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9634
9635 qstatus = GetQueueStatus(qs_all_input);
9636 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9637 "wrong qstatus %08x\n", qstatus);
9638
9639 msg.message = 0;
9640 ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9641 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9642 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9643 ret, msg.message, msg.wParam);
9644 ok_sequence(WmUser, "WmUser", FALSE);
9645
9646 qstatus = GetQueueStatus(qs_all_input);
9647 ok(qstatus == MAKELONG(0, QS_KEY),
9648 "wrong qstatus %08x\n", qstatus);
9649
9650 msg.message = 0;
9651 ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9652 ok(!ret,
9653 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9654 msg.message);
9655 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9656
9657 qstatus = GetQueueStatus(qs_all_input);
9658 ok(qstatus == MAKELONG(0, QS_KEY),
9659 "wrong qstatus %08x\n", qstatus);
9660
9661 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9662
9663 qstatus = GetQueueStatus(qs_all_input);
9664 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9665 "wrong qstatus %08x\n", qstatus);
9666
9667 trace("signalling to send message\n");
9668 SetEvent(info.hevent[EV_SENDMSG]);
9669 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9670
9671 qstatus = GetQueueStatus(qs_all_input);
9672 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9673 "wrong qstatus %08x\n", qstatus);
9674
9675 msg.message = 0;
9676 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
9677 ok(!ret,
9678 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9679 msg.message);
9680 ok_sequence(WmUser, "WmUser", FALSE);
9681
9682 qstatus = GetQueueStatus(qs_all_input);
9683 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9684 "wrong qstatus %08x\n", qstatus);
9685
9686 msg.message = 0;
9687 if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9688 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9689 else /* workaround for a missing QS_RAWINPUT support */
9690 ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
9691 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9692 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9693 ret, msg.message, msg.wParam);
9694 ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9695
9696 qstatus = GetQueueStatus(qs_all_input);
9697 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9698 "wrong qstatus %08x\n", qstatus);
9699
9700 msg.message = 0;
9701 if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9702 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9703 else /* workaround for a missing QS_RAWINPUT support */
9704 ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
9705 ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9706 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
9707 ret, msg.message, msg.wParam);
9708 ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
9709
9710 qstatus = GetQueueStatus(qs_all_input);
9711 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9712 "wrong qstatus %08x\n", qstatus);
9713
9714 msg.message = 0;
9715 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
9716 ok(!ret,
9717 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9718 msg.message);
9719 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9720
9721 qstatus = GetQueueStatus(qs_all_input);
9722 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9723 "wrong qstatus %08x\n", qstatus);
9724
9725 msg.message = 0;
9726 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9727 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9728 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9729 ret, msg.message, msg.wParam);
9730 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9731
9732 qstatus = GetQueueStatus(qs_all_input);
9733 ok(qstatus == 0,
9734 "wrong qstatus %08x\n", qstatus);
9735
9736 msg.message = 0;
9737 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9738 ok(!ret,
9739 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9740 msg.message);
9741 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9742
9743 qstatus = GetQueueStatus(qs_all_input);
9744 ok(qstatus == 0,
9745 "wrong qstatus %08x\n", qstatus);
9746
9747 /* test whether presence of the quit flag in the queue affects
9748 * the queue state
9749 */
9750 PostQuitMessage(0x1234abcd);
9751
9752 qstatus = GetQueueStatus(qs_all_input);
9753 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9754 "wrong qstatus %08x\n", qstatus);
9755
9756 PostMessageA(info.hwnd, WM_USER, 0, 0);
9757
9758 qstatus = GetQueueStatus(qs_all_input);
9759 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9760 "wrong qstatus %08x\n", qstatus);
9761
9762 msg.message = 0;
9763 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9764 ok(ret && msg.message == WM_USER,
9765 "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
9766 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9767
9768 qstatus = GetQueueStatus(qs_all_input);
9769 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9770 "wrong qstatus %08x\n", qstatus);
9771
9772 msg.message = 0;
9773 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9774 ok(ret && msg.message == WM_QUIT,
9775 "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
9776 ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
9777 ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
9778 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9779
9780 qstatus = GetQueueStatus(qs_all_input);
9781 todo_wine {
9782 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9783 "wrong qstatus %08x\n", qstatus);
9784 }
9785
9786 msg.message = 0;
9787 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9788 ok(!ret,
9789 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9790 msg.message);
9791 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9792
9793 qstatus = GetQueueStatus(qs_all_input);
9794 ok(qstatus == 0,
9795 "wrong qstatus %08x\n", qstatus);
9796
9797 /* some GetMessage tests */
9798
9799 keybd_event('N', 0, 0, 0);
9800 qstatus = GetQueueStatus(qs_all_input);
9801 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9802
9803 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9804 qstatus = GetQueueStatus(qs_all_input);
9805 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9806
9807 if (qstatus)
9808 {
9809 ret = GetMessageA( &msg, 0, 0, 0 );
9810 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9811 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9812 ret, msg.message, msg.wParam);
9813 qstatus = GetQueueStatus(qs_all_input);
9814 ok(qstatus == MAKELONG(0, QS_KEY), "wrong qstatus %08x\n", qstatus);
9815 }
9816
9817 if (qstatus)
9818 {
9819 ret = GetMessageA( &msg, 0, 0, 0 );
9820 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9821 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9822 ret, msg.message, msg.wParam);
9823 ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9824 qstatus = GetQueueStatus(qs_all_input);
9825 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9826 }
9827
9828 keybd_event('N', 0, 0, 0);
9829 qstatus = GetQueueStatus(qs_all_input);
9830 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9831
9832 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9833 qstatus = GetQueueStatus(qs_all_input);
9834 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9835
9836 if (qstatus & (QS_KEY << 16))
9837 {
9838 ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9839 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9840 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9841 ret, msg.message, msg.wParam);
9842 ok_sequence(WmKeyDownWasDownSkippedSeq, "WmKeyDownWasDownSkippedSeq", FALSE);
9843 qstatus = GetQueueStatus(qs_all_input);
9844 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9845 }
9846
9847 if (qstatus)
9848 {
9849 ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9850 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9851 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9852 ret, msg.message, msg.wParam);
9853 qstatus = GetQueueStatus(qs_all_input);
9854 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9855 }
9856
9857 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9858 qstatus = GetQueueStatus(qs_all_input);
9859 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9860
9861 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9862 qstatus = GetQueueStatus(qs_all_input);
9863 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9864
9865 trace("signalling to send message\n");
9866 SetEvent(info.hevent[EV_SENDMSG]);
9867 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9868 qstatus = GetQueueStatus(qs_all_input);
9869 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9870 "wrong qstatus %08x\n", qstatus);
9871
9872 if (qstatus & (QS_KEY << 16))
9873 {
9874 ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9875 ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9876 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9877 ret, msg.message, msg.wParam);
9878 ok_sequence(WmUserKeyUpSkippedSeq, "WmUserKeyUpSkippedSeq", FALSE);
9879 qstatus = GetQueueStatus(qs_all_input);
9880 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9881 }
9882
9883 if (qstatus)
9884 {
9885 ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9886 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9887 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9888 ret, msg.message, msg.wParam);
9889 qstatus = GetQueueStatus(qs_all_input);
9890 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9891 }
9892 done:
9893 trace("signalling to exit\n");
9894 SetEvent(info.hevent[EV_STOP]);
9895
9896 WaitForSingleObject(hthread, INFINITE);
9897
9898 CloseHandle(hthread);
9899 CloseHandle(info.hevent[0]);
9900 CloseHandle(info.hevent[1]);
9901 CloseHandle(info.hevent[2]);
9902
9903 DestroyWindow(info.hwnd);
9904 }
9905
9906 static void wait_move_event(HWND hwnd, int x, int y)
9907 {
9908 MSG msg;
9909 DWORD time;
9910 BOOL ret;
9911 int go = 0;
9912
9913 time = GetTickCount();
9914 while (GetTickCount() - time < 200 && !go) {
9915 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9916 go = ret && msg.pt.x > x && msg.pt.y > y;
9917 if (!ret) MsgWaitForMultipleObjects( 0, NULL, FALSE, GetTickCount() - time, QS_ALLINPUT );
9918 }
9919 }
9920
9921 #define STEP 5
9922 static void test_PeekMessage2(void)
9923 {
9924 HWND hwnd;
9925 BOOL ret;
9926 MSG msg;
9927 UINT message;
9928 DWORD time1, time2, time3;
9929 int x1, y1, x2, y2, x3, y3;
9930 POINT pos;
9931
9932 time1 = time2 = time3 = 0;
9933 x1 = y1 = x2 = y2 = x3 = y3 = 0;
9934
9935 /* Initialise window and make sure it is ready for events */
9936 hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
9937 10, 10, 800, 800, NULL, NULL, NULL, NULL);
9938 assert(hwnd);
9939 trace("Window for test_PeekMessage2 %p\n", hwnd);
9940 ShowWindow(hwnd, SW_SHOW);
9941 UpdateWindow(hwnd);
9942 SetFocus(hwnd);
9943 GetCursorPos(&pos);
9944 SetCursorPos(100, 100);
9945 mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
9946 flush_events();
9947
9948 /* Do initial mousemove, wait until we can see it
9949 and then do our test peek with PM_NOREMOVE. */
9950 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9951 wait_move_event(hwnd, 100-STEP, 100-STEP);
9952
9953 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9954 if (!ret)
9955 {
9956 skip( "queuing mouse events not supported\n" );
9957 goto done;
9958 }
9959 else
9960 {
9961 trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9962 message = msg.message;
9963 time1 = msg.time;
9964 x1 = msg.pt.x;
9965 y1 = msg.pt.y;
9966 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9967 }
9968
9969 /* Allow time to advance a bit, and then simulate the user moving their
9970 * mouse around. After that we peek again with PM_NOREMOVE.
9971 * Although the previous mousemove message was never removed, the
9972 * mousemove we now peek should reflect the recent mouse movements
9973 * because the input queue will merge the move events. */
9974 Sleep(100);
9975 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9976 wait_move_event(hwnd, x1, y1);
9977
9978 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9979 ok(ret, "no message available\n");
9980 if (ret) {
9981 trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9982 message = msg.message;
9983 time2 = msg.time;
9984 x2 = msg.pt.x;
9985 y2 = msg.pt.y;
9986 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9987 ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
9988 ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
9989 }
9990
9991 /* Have another go, to drive the point home */
9992 Sleep(100);
9993 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9994 wait_move_event(hwnd, x2, y2);
9995
9996 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9997 ok(ret, "no message available\n");
9998 if (ret) {
9999 trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
10000 message = msg.message;
10001 time3 = msg.time;
10002 x3 = msg.pt.x;
10003 y3 = msg.pt.y;
10004 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
10005 ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
10006 ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
10007 }
10008
10009 done:
10010 DestroyWindow(hwnd);
10011 SetCursorPos(pos.x, pos.y);
10012 flush_events();
10013 }
10014
10015 static void test_quit_message(void)
10016 {
10017 MSG msg;
10018 BOOL ret;
10019
10020 /* test using PostQuitMessage */
10021 flush_events();
10022 PostQuitMessage(0xbeef);
10023
10024 ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
10025 ok(ret, "PeekMessage failed with error %d\n", GetLastError());
10026 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10027 ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
10028
10029 ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
10030 ok(ret, "PostMessage failed with error %d\n", GetLastError());
10031
10032 ret = GetMessage(&msg, NULL, 0, 0);
10033 ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
10034 ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
10035
10036 /* note: WM_QUIT message received after WM_USER message */
10037 ret = GetMessage(&msg, NULL, 0, 0);
10038 ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
10039 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10040 ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
10041
10042 ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
10043 ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
10044
10045 /* now test with PostThreadMessage - different behaviour! */
10046 PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
10047
10048 ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
10049 ok(ret, "PeekMessage failed with error %d\n", GetLastError());
10050 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10051 ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
10052
10053 ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
10054 ok(ret, "PostMessage failed with error %d\n", GetLastError());
10055
10056 /* note: we receive the WM_QUIT message first this time */
10057 ret = GetMessage(&msg, NULL, 0, 0);
10058 ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
10059 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10060 ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
10061
10062 ret = GetMessage(&msg, NULL, 0, 0);
10063 ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
10064 ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
10065 }
10066
10067 static const struct message WmMouseHoverSeq[] = {
10068 { WM_MOUSEACTIVATE, sent|optional }, /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
10069 { WM_MOUSEACTIVATE, sent|optional },
10070 { WM_TIMER, sent|optional }, /* XP sends it */
10071 { WM_SYSTIMER, sent },
10072 { WM_MOUSEHOVER, sent|wparam, 0 },
10073 { 0 }
10074 };
10075
10076 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
10077 {
10078 MSG msg;
10079 DWORD start_ticks, end_ticks;
10080
10081 start_ticks = GetTickCount();
10082 /* add some deviation (50%) to cover not expected delays */
10083 start_ticks += timeout / 2;
10084
10085 do
10086 {
10087 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
10088 {
10089 /* Timer proc messages are not dispatched to the window proc,
10090 * and therefore not logged.
10091 */
10092 if ((msg.message == WM_TIMER || msg.message == WM_SYSTIMER) && msg.hwnd)
10093 {
10094 struct recvd_message s_msg;
10095
10096 s_msg.hwnd = msg.hwnd;
10097 s_msg.message = msg.message;
10098 s_msg.flags = sent|wparam|lparam;
10099 s_msg.wParam = msg.wParam;
10100 s_msg.lParam = msg.lParam;
10101 s_msg.descr = "msg_loop";
10102 add_message(&s_msg);
10103 }
10104 DispatchMessage(&msg);
10105 }
10106
10107 end_ticks = GetTickCount();
10108
10109 /* inject WM_MOUSEMOVE to see how it changes tracking */
10110 if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
10111 {
10112 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
10113 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
10114
10115 inject_mouse_move = FALSE;
10116 }
10117 } while (start_ticks + timeout >= end_ticks);
10118 }
10119
10120 static void test_TrackMouseEvent(void)
10121 {
10122 TRACKMOUSEEVENT tme;
10123 BOOL ret;
10124 HWND hwnd, hchild;
10125 RECT rc_parent, rc_child;
10126 UINT default_hover_time, hover_width = 0, hover_height = 0;
10127
10128 #define track_hover(track_hwnd, track_hover_time) \
10129 tme.cbSize = sizeof(tme); \
10130 tme.dwFlags = TME_HOVER; \
10131 tme.hwndTrack = track_hwnd; \
10132 tme.dwHoverTime = track_hover_time; \
10133 SetLastError(0xdeadbeef); \
10134 ret = pTrackMouseEvent(&tme); \
10135 ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
10136
10137 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
10138 tme.cbSize = sizeof(tme); \
10139 tme.dwFlags = TME_QUERY; \
10140 tme.hwndTrack = (HWND)0xdeadbeef; \
10141 tme.dwHoverTime = 0xdeadbeef; \
10142 SetLastError(0xdeadbeef); \
10143 ret = pTrackMouseEvent(&tme); \
10144 ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
10145 ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
10146 ok(tme.dwFlags == (expected_track_flags), \
10147 "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
10148 ok(tme.hwndTrack == (expected_track_hwnd), \
10149 "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
10150 ok(tme.dwHoverTime == (expected_hover_time), \
10151 "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
10152
10153 #define track_hover_cancel(track_hwnd) \
10154 tme.cbSize = sizeof(tme); \
10155 tme.dwFlags = TME_HOVER | TME_CANCEL; \
10156 tme.hwndTrack = track_hwnd; \
10157 tme.dwHoverTime = 0xdeadbeef; \
10158 SetLastError(0xdeadbeef); \
10159 ret = pTrackMouseEvent(&tme); \
10160 ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
10161
10162 default_hover_time = 0xdeadbeef;
10163 SetLastError(0xdeadbeef);
10164 ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
10165 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
10166 "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
10167 if (!ret) default_hover_time = 400;
10168 trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
10169
10170 SetLastError(0xdeadbeef);
10171 ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
10172 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
10173 "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
10174 if (!ret) hover_width = 4;
10175 SetLastError(0xdeadbeef);
10176 ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
10177 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
10178 "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
10179 if (!ret) hover_height = 4;
10180 trace("hover rect is %u x %d\n", hover_width, hover_height);
10181
10182 hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
10183 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10184 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
10185 NULL, NULL, 0);
10186 assert(hwnd);
10187
10188 hchild = CreateWindowEx(0, "TestWindowClass", NULL,
10189 WS_CHILD | WS_BORDER | WS_VISIBLE,
10190 50, 50, 200, 200, hwnd,
10191 NULL, NULL, 0);
10192 assert(hchild);
10193
10194 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
10195 flush_events();
10196 flush_sequence();
10197
10198 tme.cbSize = 0;
10199 tme.dwFlags = TME_QUERY;
10200 tme.hwndTrack = (HWND)0xdeadbeef;
10201 tme.dwHoverTime = 0xdeadbeef;
10202 SetLastError(0xdeadbeef);
10203 ret = pTrackMouseEvent(&tme);
10204 ok(!ret, "TrackMouseEvent should fail\n");
10205 ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef),
10206 "not expected error %u\n", GetLastError());
10207
10208 tme.cbSize = sizeof(tme);
10209 tme.dwFlags = TME_HOVER;
10210 tme.hwndTrack = (HWND)0xdeadbeef;
10211 tme.dwHoverTime = 0xdeadbeef;
10212 SetLastError(0xdeadbeef);
10213 ret = pTrackMouseEvent(&tme);
10214 ok(!ret, "TrackMouseEvent should fail\n");
10215 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10216 "not expected error %u\n", GetLastError());
10217
10218 tme.cbSize = sizeof(tme);
10219 tme.dwFlags = TME_HOVER | TME_CANCEL;
10220 tme.hwndTrack = (HWND)0xdeadbeef;
10221 tme.dwHoverTime = 0xdeadbeef;
10222 SetLastError(0xdeadbeef);
10223 ret = pTrackMouseEvent(&tme);
10224 ok(!ret, "TrackMouseEvent should fail\n");
10225 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10226 "not expected error %u\n", GetLastError());
10227
10228 GetWindowRect(hwnd, &rc_parent);
10229 GetWindowRect(hchild, &rc_child);
10230 SetCursorPos(rc_child.left - 10, rc_child.top - 10);
10231
10232 /* Process messages so that the system updates its internal current
10233 * window and hittest, otherwise TrackMouseEvent calls don't have any
10234 * effect.
10235 */
10236 flush_events();
10237 flush_sequence();
10238
10239 track_query(0, NULL, 0);
10240 track_hover(hchild, 0);
10241 track_query(0, NULL, 0);
10242
10243 flush_events();
10244 flush_sequence();
10245
10246 track_hover(hwnd, 0);
10247 tme.cbSize = sizeof(tme);
10248 tme.dwFlags = TME_QUERY;
10249 tme.hwndTrack = (HWND)0xdeadbeef;
10250 tme.dwHoverTime = 0xdeadbeef;
10251 SetLastError(0xdeadbeef);
10252 ret = pTrackMouseEvent(&tme);
10253 ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());
10254 ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize);
10255 if (!tme.dwFlags)
10256 {
10257 skip( "Cursor not inside window, skipping TrackMouseEvent tests\n" );
10258 DestroyWindow( hwnd );
10259 return;
10260 }
10261 ok(tme.dwFlags == TME_HOVER, "wrong tme.dwFlags %08x, expected TME_HOVER\n", tme.dwFlags);
10262 ok(tme.hwndTrack == hwnd, "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, hwnd);
10263 ok(tme.dwHoverTime == default_hover_time, "wrong tme.dwHoverTime %u, expected %u\n",
10264 tme.dwHoverTime, default_hover_time);
10265
10266 pump_msg_loop_timeout(default_hover_time, FALSE);
10267 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10268
10269 track_query(0, NULL, 0);
10270
10271 track_hover(hwnd, HOVER_DEFAULT);
10272 track_query(TME_HOVER, hwnd, default_hover_time);
10273
10274 Sleep(default_hover_time / 2);
10275 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
10276 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
10277
10278 track_query(TME_HOVER, hwnd, default_hover_time);
10279
10280 pump_msg_loop_timeout(default_hover_time, FALSE);
10281 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10282
10283 track_query(0, NULL, 0);
10284
10285 track_hover(hwnd, HOVER_DEFAULT);
10286 track_query(TME_HOVER, hwnd, default_hover_time);
10287
10288 pump_msg_loop_timeout(default_hover_time, TRUE);
10289 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10290
10291 track_query(0, NULL, 0);
10292
10293 track_hover(hwnd, HOVER_DEFAULT);
10294 track_query(TME_HOVER, hwnd, default_hover_time);
10295 track_hover_cancel(hwnd);
10296
10297 DestroyWindow(hwnd);
10298
10299 #undef track_hover
10300 #undef track_query
10301 #undef track_hover_cancel
10302 }
10303
10304
10305 static const struct message WmSetWindowRgn[] = {
10306 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10307 { WM_NCCALCSIZE, sent|wparam, 1 },
10308 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
10309 { WM_GETTEXT, sent|defwinproc|optional },
10310 { WM_ERASEBKGND, sent|optional },
10311 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10312 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10313 { 0 }
10314 };
10315
10316 static const struct message WmSetWindowRgn_no_redraw[] = {
10317 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10318 { WM_NCCALCSIZE, sent|wparam, 1 },
10319 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10320 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10321 { 0 }
10322 };
10323
10324 static const struct message WmSetWindowRgn_clear[] = {
10325 { WM_WINDOWPOSCHANGING, sent/*|wparam*/, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE/*|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE only on some Windows versions */ },
10326 { WM_NCCALCSIZE, sent|wparam, 1 },
10327 { WM_NCPAINT, sent|optional },
10328 { WM_GETTEXT, sent|defwinproc|optional },
10329 { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
10330 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10331 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
10332 { WM_NCPAINT, sent|optional },
10333 { WM_GETTEXT, sent|defwinproc|optional },
10334 { WM_ERASEBKGND, sent|optional },
10335 { WM_WINDOWPOSCHANGING, sent|optional },
10336 { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10337 { WM_NCPAINT, sent|optional },
10338 { WM_GETTEXT, sent|defwinproc|optional },
10339 { WM_ERASEBKGND, sent|optional },
10340 { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10341 { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10342 { WM_NCPAINT, sent|optional },
10343 { WM_GETTEXT, sent|defwinproc|optional },
10344 { WM_ERASEBKGND, sent|optional },
10345 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10346 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10347 { 0 }
10348 };
10349
10350 static void test_SetWindowRgn(void)
10351 {
10352 HRGN hrgn;
10353 HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10354 100, 100, 200, 200, 0, 0, 0, NULL);
10355 ok( hwnd != 0, "Failed to create overlapped window\n" );
10356
10357 ShowWindow( hwnd, SW_SHOW );
10358 UpdateWindow( hwnd );
10359 flush_events();
10360 flush_sequence();
10361
10362 trace("testing SetWindowRgn\n");
10363 hrgn = CreateRectRgn( 0, 0, 150, 150 );
10364 SetWindowRgn( hwnd, hrgn, TRUE );
10365 ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
10366
10367 hrgn = CreateRectRgn( 30, 30, 160, 160 );
10368 SetWindowRgn( hwnd, hrgn, FALSE );
10369 ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
10370
10371 hrgn = CreateRectRgn( 0, 0, 180, 180 );
10372 SetWindowRgn( hwnd, hrgn, TRUE );
10373 ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
10374
10375 SetWindowRgn( hwnd, 0, TRUE );
10376 ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
10377
10378 DestroyWindow( hwnd );
10379 }
10380
10381 /*************************** ShowWindow() test ******************************/
10382 static const struct message WmShowNormal[] = {
10383 { WM_SHOWWINDOW, sent|wparam, 1 },
10384 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10385 { HCBT_ACTIVATE, hook },
10386 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10387 { HCBT_SETFOCUS, hook },
10388 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10389 { 0 }
10390 };
10391 static const struct message WmShow[] = {
10392 { WM_SHOWWINDOW, sent|wparam, 1 },
10393 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10394 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10395 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10396 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10397 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10398 { 0 }
10399 };
10400 static const struct message WmShowNoActivate_1[] = {
10401 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10402 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10403 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10404 { WM_MOVE, sent|defwinproc|optional },
10405 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10406 { 0 }
10407 };
10408 static const struct message WmShowNoActivate_2[] = {
10409 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10410 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10411 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10412 { WM_MOVE, sent|defwinproc },
10413 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10414 { HCBT_SETFOCUS, hook|optional },
10415 { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10416 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10417 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10418 { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10419 { 0 }
10420 };
10421 static const struct message WmShowNA_1[] = {
10422 { WM_SHOWWINDOW, sent|wparam, 1 },
10423 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10424 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10425 { 0 }
10426 };
10427 static const struct message WmShowNA_2[] = {
10428 { WM_SHOWWINDOW, sent|wparam, 1 },
10429 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10430 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10431 { 0 }
10432 };
10433 static const struct message WmRestore_1[] = {
10434 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10435 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10436 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10437 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10438 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10439 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10440 { WM_MOVE, sent|defwinproc },
10441 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10442 { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10443 { 0 }
10444 };
10445 static const struct message WmRestore_2[] = {
10446 { WM_SHOWWINDOW, sent|wparam, 1 },
10447 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10448 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10449 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10450 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10451 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10452 { 0 }
10453 };
10454 static const struct message WmRestore_3[] = {
10455 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10456 { WM_GETMINMAXINFO, sent },
10457 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10458 { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10459 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10460 { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10461 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10462 { WM_MOVE, sent|defwinproc },
10463 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10464 { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10465 { 0 }
10466 };
10467 static const struct message WmRestore_4[] = {
10468 { HCBT_MINMAX, hook|lparam|optional, 0, SW_RESTORE },
10469 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10470 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10471 { WM_MOVE, sent|defwinproc|optional },
10472 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10473 { 0 }
10474 };
10475 static const struct message WmRestore_5[] = {
10476 { HCBT_MINMAX, hook|lparam|optional, 0, SW_SHOWNORMAL },
10477 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10478 { HCBT_ACTIVATE, hook|optional },
10479 { HCBT_SETFOCUS, hook|optional },
10480 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10481 { WM_MOVE, sent|defwinproc|optional },
10482 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10483 { 0 }
10484 };
10485 static const struct message WmHide_1[] = {
10486 { WM_SHOWWINDOW, sent|wparam, 0 },
10487 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOACTIVATE },
10488 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOACTIVATE },
10489 { HCBT_ACTIVATE, hook|optional },
10490 { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10491 { 0 }
10492 };
10493 static const struct message WmHide_2[] = {
10494 { WM_SHOWWINDOW, sent|wparam, 0 },
10495 { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10496 { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10497 { HCBT_ACTIVATE, hook|optional },
10498 { 0 }
10499 };
10500 static const struct message WmHide_3[] = {
10501 { WM_SHOWWINDOW, sent|wparam, 0 },
10502 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10503 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10504 { HCBT_SETFOCUS, hook|optional },
10505 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10506 { 0 }
10507 };
10508 static const struct message WmShowMinimized_1[] = {
10509 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10510 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10511 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10512 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10513 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10514 { WM_MOVE, sent|defwinproc },
10515 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10516 { 0 }
10517 };
10518 static const struct message WmMinimize_1[] = {
10519 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10520 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10521 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10522 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10523 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10524 { WM_MOVE, sent|defwinproc },
10525 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10526 { 0 }
10527 };
10528 static const struct message WmMinimize_2[] = {
10529 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10530 { HCBT_SETFOCUS, hook|optional },
10531 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10532 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10533 { WM_MOVE, sent|defwinproc },
10534 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10535 { 0 }
10536 };
10537 static const struct message WmMinimize_3[] = {
10538 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10539 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10540 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10541 { WM_MOVE, sent|defwinproc },
10542 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10543 { 0 }
10544 };
10545 static const struct message WmShowMinNoActivate[] = {
10546 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10547 { WM_WINDOWPOSCHANGING, sent },
10548 { WM_WINDOWPOSCHANGED, sent },
10549 { WM_MOVE, sent|defwinproc|optional },
10550 { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
10551 { 0 }
10552 };
10553 static const struct message WmMinMax_1[] = {
10554 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10555 { 0 }
10556 };
10557 static const struct message WmMinMax_2[] = {
10558 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10559 { WM_GETMINMAXINFO, sent|optional },
10560 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED },
10561 { HCBT_ACTIVATE, hook|optional },
10562 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10563 { HCBT_SETFOCUS, hook|optional },
10564 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10565 { WM_MOVE, sent|defwinproc|optional },
10566 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MAXIMIZED },
10567 { HCBT_SETFOCUS, hook|optional },
10568 { 0 }
10569 };
10570 static const struct message WmMinMax_3[] = {
10571 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10572 { HCBT_SETFOCUS, hook|optional },
10573 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10574 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10575 { WM_MOVE, sent|defwinproc|optional },
10576 { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
10577 { 0 }
10578 };
10579 static const struct message WmMinMax_4[] = {
10580 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10581 { 0 }
10582 };
10583 static const struct message WmShowMaximized_1[] = {
10584 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10585 { WM_GETMINMAXINFO, sent },
10586 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10587 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10588 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10589 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10590 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10591 { WM_MOVE, sent|defwinproc },
10592 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10593 { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10594 { 0 }
10595 };
10596 static const struct message WmShowMaximized_2[] = {
10597 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10598 { WM_GETMINMAXINFO, sent },
10599 { WM_WINDOWPOSCHANGING, sent|optional },
10600 { HCBT_ACTIVATE, hook|optional },
10601 { WM_WINDOWPOSCHANGED, sent|optional },
10602 { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
10603 { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
10604 { WM_WINDOWPOSCHANGING, sent|optional },
10605 { HCBT_SETFOCUS, hook|optional },
10606 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10607 { WM_MOVE, sent|defwinproc },
10608 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10609 { HCBT_SETFOCUS, hook|optional },
10610 { 0 }
10611 };
10612 static const struct message WmShowMaximized_3[] = {
10613 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10614 { WM_GETMINMAXINFO, sent|optional },
10615 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10616 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10617 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10618 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10619 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10620 { WM_MOVE, sent|defwinproc|optional },
10621 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10622 { 0 }
10623 };
10624
10625 static void test_ShowWindow(void)
10626 {
10627 /* ShowWindow commands in random order */
10628 static const struct
10629 {
10630 INT cmd; /* ShowWindow command */
10631 LPARAM ret; /* ShowWindow return value */
10632 DWORD style; /* window style after the command */
10633 const struct message *msg; /* message sequence the command produces */
10634 BOOL todo_msg; /* message sequence doesn't match what Wine does */
10635 } sw[] =
10636 {
10637 /* 1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
10638 /* 2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10639 /* 3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10640 /* 4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10641 /* 5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
10642 /* 6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
10643 /* 7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
10644 /* 8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10645 /* 9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
10646 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10647 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
10648 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
10649 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
10650 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10651 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
10652 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10653 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
10654 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10655 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10656 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10657 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10658 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
10659 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
10660 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10661 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10662 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
10663 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
10664 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10665 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10666 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
10667 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10668 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, FALSE },
10669 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10670 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE }, /* what does this mean?! */
10671 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE },
10672 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10673 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
10674 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10675 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10676 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, FALSE },
10677 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10678 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, FALSE },
10679 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10680 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10681 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10682 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
10683 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
10684 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
10685 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
10686 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
10687 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
10688 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10689 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10690 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, FALSE },
10691 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10692 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
10693 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
10694 };
10695 HWND hwnd;
10696 DWORD style;
10697 LPARAM ret;
10698 INT i;
10699
10700 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
10701 hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
10702 120, 120, 90, 90,
10703 0, 0, 0, NULL);
10704 assert(hwnd);
10705
10706 style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10707 ok(style == 0, "expected style 0, got %08x\n", style);
10708
10709 flush_events();
10710 flush_sequence();
10711
10712 for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
10713 {
10714 static const char * const sw_cmd_name[13] =
10715 {
10716 "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
10717 "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
10718 "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
10719 "SW_NORMALNA" /* 0xCC */
10720 };
10721 char comment[64];
10722 INT idx; /* index into the above array of names */
10723
10724 idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
10725
10726 style = GetWindowLong(hwnd, GWL_STYLE);
10727 trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
10728 ret = ShowWindow(hwnd, sw[i].cmd);
10729 ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
10730 style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10731 ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
10732
10733 sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
10734 ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
10735
10736 flush_events();
10737 flush_sequence();
10738 }
10739
10740 DestroyWindow(hwnd);
10741 }
10742
10743 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
10744 {
10745 struct recvd_message msg;
10746
10747 if (ignore_message( message )) return 0;
10748
10749 msg.hwnd = hwnd;
10750 msg.message = message;
10751 msg.flags = sent|wparam|lparam;
10752 msg.wParam = wParam;
10753 msg.lParam = lParam;
10754 msg.descr = "dialog";
10755 add_message(&msg);
10756
10757 /* calling DefDlgProc leads to a recursion under XP */
10758
10759 switch (message)
10760 {
10761 case WM_INITDIALOG:
10762 case WM_GETDLGCODE:
10763 return 0;
10764 }
10765 return 1;
10766 }
10767
10768 static const struct message WmDefDlgSetFocus_1[] = {
10769 { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10770 { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10771 { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10772 { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10773 { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10774 { HCBT_SETFOCUS, hook },
10775 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
10776 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10777 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10778 { WM_SETFOCUS, sent|wparam, 0 },
10779 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
10780 { WM_CTLCOLOREDIT, sent },
10781 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
10782 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10783 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10784 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10785 { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
10786 { 0 }
10787 };
10788 static const struct message WmDefDlgSetFocus_2[] = {
10789 { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10790 { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10791 { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10792 { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10793 { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10794 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10795 { WM_CTLCOLOREDIT, sent|optional }, /* XP */
10796 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10797 { 0 }
10798 };
10799 /* Creation of a dialog */
10800 static const struct message WmCreateDialogParamSeq_1[] = {
10801 { HCBT_CREATEWND, hook },
10802 { WM_NCCREATE, sent },
10803 { WM_NCCALCSIZE, sent|wparam, 0 },
10804 { WM_CREATE, sent },
10805 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10806 { WM_SIZE, sent|wparam, SIZE_RESTORED },
10807 { WM_MOVE, sent },
10808 { WM_SETFONT, sent },
10809 { WM_INITDIALOG, sent },
10810 { WM_CHANGEUISTATE, sent|optional },
10811 { 0 }
10812 };
10813 /* Creation of a dialog */
10814 static const struct message WmCreateDialogParamSeq_2[] = {
10815 { HCBT_CREATEWND, hook },
10816 { WM_NCCREATE, sent },
10817 { WM_NCCALCSIZE, sent|wparam, 0 },
10818 { WM_CREATE, sent },
10819 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10820 { WM_SIZE, sent|wparam, SIZE_RESTORED },
10821 { WM_MOVE, sent },
10822 { WM_CHANGEUISTATE, sent|optional },
10823 { 0 }
10824 };
10825
10826 static void test_dialog_messages(void)
10827 {
10828 WNDCLASS cls;
10829 HWND hdlg, hedit1, hedit2, hfocus;
10830 LRESULT ret;
10831
10832 #define set_selection(hctl, start, end) \
10833 ret = SendMessage(hctl, EM_SETSEL, start, end); \
10834 ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
10835
10836 #define check_selection(hctl, start, end) \
10837 ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
10838 ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
10839
10840 subclass_edit();
10841
10842 hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
10843 WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
10844 0, 0, 100, 100, 0, 0, 0, NULL);
10845 ok(hdlg != 0, "Failed to create custom dialog window\n");
10846
10847 hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
10848 WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10849 0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
10850 ok(hedit1 != 0, "Failed to create edit control\n");
10851 hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
10852 WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10853 0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
10854 ok(hedit2 != 0, "Failed to create edit control\n");
10855
10856 SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
10857 SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
10858
10859 hfocus = GetFocus();
10860 ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
10861
10862 SetFocus(hedit2);
10863 hfocus = GetFocus();
10864 ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
10865
10866 check_selection(hedit1, 0, 0);
10867 check_selection(hedit2, 0, 0);
10868
10869 set_selection(hedit2, 0, -1);
10870 check_selection(hedit2, 0, 3);
10871
10872 SetFocus(0);
10873 hfocus = GetFocus();
10874 ok(hfocus == 0, "wrong focus %p\n", hfocus);
10875
10876 flush_sequence();
10877 ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10878 ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10879 ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
10880
10881 hfocus = GetFocus();
10882 ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10883
10884 check_selection(hedit1, 0, 5);
10885 check_selection(hedit2, 0, 3);
10886
10887 flush_sequence();
10888 ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10889 ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10890 ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
10891
10892 hfocus = GetFocus();
10893 ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10894
10895 check_selection(hedit1, 0, 5);
10896 check_selection(hedit2, 0, 3);
10897
10898 EndDialog(hdlg, 0);
10899 DestroyWindow(hedit1);
10900 DestroyWindow(hedit2);
10901 DestroyWindow(hdlg);
10902 flush_sequence();
10903
10904 #undef set_selection
10905 #undef check_selection
10906
10907 ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
10908 cls.lpszClassName = "MyDialogClass";
10909 cls.hInstance = GetModuleHandle(0);
10910 /* need a cast since a dlgproc is used as a wndproc */
10911 cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
10912 if (!RegisterClass(&cls)) assert(0);
10913
10914 hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
10915 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10916 ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
10917 EndDialog(hdlg, 0);
10918 DestroyWindow(hdlg);
10919 flush_sequence();
10920
10921 hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
10922 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10923 ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
10924 EndDialog(hdlg, 0);
10925 DestroyWindow(hdlg);
10926 flush_sequence();
10927
10928 UnregisterClass(cls.lpszClassName, cls.hInstance);
10929 }
10930
10931 static void test_nullCallback(void)
10932 {
10933 HWND hwnd;
10934
10935 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10936 100, 100, 200, 200, 0, 0, 0, NULL);
10937 ok (hwnd != 0, "Failed to create overlapped window\n");
10938
10939 SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
10940 flush_events();
10941 DestroyWindow(hwnd);
10942 }
10943
10944 /* SetActiveWindow( 0 ) hwnd visible */
10945 static const struct message SetActiveWindowSeq0[] =
10946 {
10947 { HCBT_ACTIVATE, hook|optional },
10948 { WM_NCACTIVATE, sent|wparam, 0 },
10949 { WM_GETTEXT, sent|defwinproc|optional },
10950 { WM_ACTIVATE, sent|wparam, 0 },
10951 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
10952 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
10953 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10954 { WM_KILLFOCUS, sent|optional },
10955 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10956 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10957 { WM_NCACTIVATE, sent|wparam|optional, 1 },
10958 { WM_GETTEXT, sent|defwinproc|optional },
10959 { WM_ACTIVATE, sent|wparam|optional, 1 },
10960 { HCBT_SETFOCUS, hook|optional },
10961 { WM_KILLFOCUS, sent|defwinproc|optional },
10962 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
10963 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
10964 { WM_IME_SETCONTEXT, sent|optional },
10965 { WM_IME_SETCONTEXT, sent|optional },
10966 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10967 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10968 { WM_SETFOCUS, sent|defwinproc|optional },
10969 { WM_GETTEXT, sent|optional },
10970 { 0 }
10971 };
10972 /* SetActiveWindow( hwnd ) hwnd visible */
10973 static const struct message SetActiveWindowSeq1[] =
10974 {
10975 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10976 { 0 }
10977 };
10978 /* SetActiveWindow( popup ) hwnd visible, popup visible */
10979 static const struct message SetActiveWindowSeq2[] =
10980 {
10981 { HCBT_ACTIVATE, hook },
10982 { WM_NCACTIVATE, sent|wparam, 0 },
10983 { WM_GETTEXT, sent|defwinproc|optional },
10984 { WM_ACTIVATE, sent|wparam, 0 },
10985 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10986 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10987 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10988 { WM_NCPAINT, sent|optional },
10989 { WM_GETTEXT, sent|defwinproc|optional },
10990 { WM_ERASEBKGND, sent|optional },
10991 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10992 { WM_NCACTIVATE, sent|wparam, 1 },
10993 { WM_GETTEXT, sent|defwinproc|optional },
10994 { WM_ACTIVATE, sent|wparam, 1 },
10995 { HCBT_SETFOCUS, hook },
10996 { WM_KILLFOCUS, sent|defwinproc },
10997 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10998 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10999 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
11000 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11001 { WM_SETFOCUS, sent|defwinproc },
11002 { WM_GETTEXT, sent|optional },
11003 { 0 }
11004 };
11005
11006 /* SetActiveWindow( hwnd ) hwnd not visible */
11007 static const struct message SetActiveWindowSeq3[] =
11008 {
11009 { HCBT_ACTIVATE, hook },
11010 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11011 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11012 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
11013 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11014 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11015 { WM_ACTIVATEAPP, sent|wparam, 1 },
11016 { WM_ACTIVATEAPP, sent|wparam, 1 },
11017 { WM_NCACTIVATE, sent|wparam, 1 },
11018 { WM_ACTIVATE, sent|wparam, 1 },
11019 { HCBT_SETFOCUS, hook },
11020 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11021 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11022 { WM_SETFOCUS, sent|defwinproc },
11023 { 0 }
11024 };
11025 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
11026 static const struct message SetActiveWindowSeq4[] =
11027 {
11028 { HCBT_ACTIVATE, hook },
11029 { WM_NCACTIVATE, sent|wparam, 0 },
11030 { WM_GETTEXT, sent|defwinproc|optional },
11031 { WM_ACTIVATE, sent|wparam, 0 },
11032 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11033 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
11034 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11035 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11036 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11037 { WM_NCACTIVATE, sent|wparam, 1 },
11038 { WM_GETTEXT, sent|defwinproc|optional },
11039 { WM_ACTIVATE, sent|wparam, 1 },
11040 { HCBT_SETFOCUS, hook },
11041 { WM_KILLFOCUS, sent|defwinproc },
11042 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
11043 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11044 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
11045 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11046 { WM_SETFOCUS, sent|defwinproc },
11047 { 0 }
11048 };
11049
11050
11051 static void test_SetActiveWindow(void)
11052 {
11053 HWND hwnd, popup, ret;
11054
11055 hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
11056 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11057 100, 100, 200, 200, 0, 0, 0, NULL);
11058
11059 popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
11060 WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
11061 100, 100, 200, 200, hwnd, 0, 0, NULL);
11062
11063 ok(hwnd != 0, "Failed to create overlapped window\n");
11064 ok(popup != 0, "Failed to create popup window\n");
11065 SetForegroundWindow( popup );
11066 flush_sequence();
11067
11068 trace("SetActiveWindow(0)\n");
11069 ret = SetActiveWindow(0);
11070 ok( ret == popup, "Failed to SetActiveWindow(0)\n");
11071 ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", FALSE);
11072 flush_sequence();
11073
11074 trace("SetActiveWindow(hwnd), hwnd visible\n");
11075 ret = SetActiveWindow(hwnd);
11076 if (ret == hwnd) ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
11077 flush_sequence();
11078
11079 trace("SetActiveWindow(popup), hwnd visible, popup visible\n");
11080 ret = SetActiveWindow(popup);
11081 ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visible\n");
11082 ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visible", FALSE);
11083 flush_sequence();
11084
11085 ShowWindow(hwnd, SW_HIDE);
11086 ShowWindow(popup, SW_HIDE);
11087 flush_sequence();
11088
11089 trace("SetActiveWindow(hwnd), hwnd not visible\n");
11090 ret = SetActiveWindow(hwnd);
11091 ok( ret == NULL, "SetActiveWindow(hwnd), hwnd not visible, previous is %p\n", ret );
11092 ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
11093 flush_sequence();
11094
11095 trace("SetActiveWindow(popup), hwnd not visible, popup not visible\n");
11096 ret = SetActiveWindow(popup);
11097 ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
11098 ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visible", TRUE);
11099 flush_sequence();
11100
11101 trace("done\n");
11102
11103 DestroyWindow(hwnd);
11104 }
11105
11106 static const struct message SetForegroundWindowSeq[] =
11107 {
11108 { WM_NCACTIVATE, sent|wparam, 0 },
11109 { WM_GETTEXT, sent|defwinproc|optional },
11110 { WM_ACTIVATE, sent|wparam, 0 },
11111 { WM_ACTIVATEAPP, sent|wparam, 0 },
11112 { WM_KILLFOCUS, sent },
11113 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
11114 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
11115 { 0 }
11116 };
11117
11118 static void test_SetForegroundWindow(void)
11119 {
11120 HWND hwnd;
11121
11122 hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
11123 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11124 100, 100, 200, 200, 0, 0, 0, NULL);
11125 ok (hwnd != 0, "Failed to create overlapped window\n");
11126 SetForegroundWindow( hwnd );
11127 flush_sequence();
11128
11129 trace("SetForegroundWindow( 0 )\n");
11130 SetForegroundWindow( 0 );
11131 ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
11132 trace("SetForegroundWindow( GetDesktopWindow() )\n");
11133 SetForegroundWindow( GetDesktopWindow() );
11134 ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
11135 "foreground top level window", FALSE);
11136 trace("done\n");
11137
11138 DestroyWindow(hwnd);
11139 }
11140
11141 static void test_dbcs_wm_char(void)
11142 {
11143 BYTE dbch[2];
11144 WCHAR wch, bad_wch;
11145 HWND hwnd, hwnd2;
11146 MSG msg;
11147 DWORD time;
11148 POINT pt;
11149 DWORD_PTR res;
11150 CPINFOEXA cpinfo;
11151 UINT i, j, k;
11152 struct message wmCharSeq[2];
11153
11154 if (!pGetCPInfoExA)
11155 {
11156 win_skip("GetCPInfoExA is not available\n");
11157 return;
11158 }
11159
11160 pGetCPInfoExA( CP_ACP, 0, &cpinfo );
11161 if (cpinfo.MaxCharSize != 2)
11162 {
11163 skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
11164 return;
11165 }
11166
11167 dbch[0] = dbch[1] = 0;
11168 wch = 0;
11169 bad_wch = cpinfo.UnicodeDefaultChar;
11170 for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
11171 for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
11172 for (k = 128; k <= 255; k++)
11173 {
11174 char str[2];
11175 WCHAR wstr[2];
11176 str[0] = j;
11177 str[1] = k;
11178 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
11179 WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
11180 (BYTE)str[0] == j && (BYTE)str[1] == k &&
11181 HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
11182 {
11183 dbch[0] = j;
11184 dbch[1] = k;
11185 wch = wstr[0];
11186 break;
11187 }
11188 }
11189
11190 if (!wch)
11191 {
11192 skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
11193 return;
11194 }
11195 trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
11196 dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
11197
11198 hwnd = CreateWindowExW(0, testWindowClassW, NULL,
11199 WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11200 hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
11201 WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11202 ok (hwnd != 0, "Failed to create overlapped window\n");
11203 ok (hwnd2 != 0, "Failed to create overlapped window\n");
11204 flush_sequence();
11205
11206 memset( wmCharSeq, 0, sizeof(wmCharSeq) );
11207 wmCharSeq[0].message = WM_CHAR;
11208 wmCharSeq[0].flags = sent|wparam;
11209 wmCharSeq[0].wParam = wch;
11210
11211 /* posted message */
11212 PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11213 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11214 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11215 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11216 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11217 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11218 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11219
11220 /* posted thread message */
11221 PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
11222 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11223 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11224 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11225 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11226 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11227 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11228
11229 /* sent message */
11230 flush_sequence();
11231 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11232 ok_sequence( WmEmptySeq, "no messages", FALSE );
11233 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11234 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11235 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11236
11237 /* sent message with timeout */
11238 flush_sequence();
11239 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11240 ok_sequence( WmEmptySeq, "no messages", FALSE );
11241 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11242 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11243 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11244
11245 /* sent message with timeout and callback */
11246 flush_sequence();
11247 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11248 ok_sequence( WmEmptySeq, "no messages", FALSE );
11249 SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11250 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11251 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11252
11253 /* sent message with callback */
11254 flush_sequence();
11255 SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11256 ok_sequence( WmEmptySeq, "no messages", FALSE );
11257 SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11258 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11259 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11260
11261 /* direct window proc call */
11262 flush_sequence();
11263 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11264 ok_sequence( WmEmptySeq, "no messages", FALSE );
11265 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11266 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11267
11268 /* dispatch message */
11269 msg.hwnd = hwnd;
11270 msg.message = WM_CHAR;
11271 msg.wParam = dbch[0];
11272 msg.lParam = 0;
11273 DispatchMessageA( &msg );
11274 ok_sequence( WmEmptySeq, "no messages", FALSE );
11275 msg.wParam = dbch[1];
11276 DispatchMessageA( &msg );
11277 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11278
11279 /* window handle is irrelevant */
11280 flush_sequence();
11281 SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11282 ok_sequence( WmEmptySeq, "no messages", FALSE );
11283 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11284 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11285 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11286
11287 /* interleaved post and send */
11288 flush_sequence();
11289 PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11290 SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11291 ok_sequence( WmEmptySeq, "no messages", FALSE );
11292 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11293 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11294 ok_sequence( WmEmptySeq, "no messages", FALSE );
11295 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11296 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11297 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11298 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11299 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11300 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11301 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11302
11303 /* interleaved sent message and winproc */
11304 flush_sequence();
11305 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11306 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11307 ok_sequence( WmEmptySeq, "no messages", FALSE );
11308 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11309 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11310 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11311 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11312
11313 /* interleaved winproc and dispatch */
11314 msg.hwnd = hwnd;
11315 msg.message = WM_CHAR;
11316 msg.wParam = dbch[0];
11317 msg.lParam = 0;
11318 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11319 DispatchMessageA( &msg );
11320 ok_sequence( WmEmptySeq, "no messages", FALSE );
11321 msg.wParam = dbch[1];
11322 DispatchMessageA( &msg );
11323 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11324 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11325 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11326
11327 /* interleaved sends */
11328 flush_sequence();
11329 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11330 SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
11331 ok_sequence( WmEmptySeq, "no messages", FALSE );
11332 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11333 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11334 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11335 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11336
11337 /* dbcs WM_CHAR */
11338 flush_sequence();
11339 SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
11340 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11341 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11342
11343 /* other char messages are not magic */
11344 PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
11345 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11346 ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
11347 ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
11348 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11349 PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
11350 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11351 ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
11352 ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
11353 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11354
11355 /* test retrieving messages */
11356
11357 PostMessageW( hwnd, WM_CHAR, wch, 0 );
11358 ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11359 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11360 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11361 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11362 ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11363 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11364 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11365 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11366 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11367
11368 /* message filters */
11369 PostMessageW( hwnd, WM_CHAR, wch, 0 );
11370 ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11371 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11372 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11373 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11374 /* message id is filtered, hwnd is not */
11375 ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
11376 ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
11377 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11378 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11379 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11380 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11381
11382 /* mixing GetMessage and PostMessage */
11383 PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
11384 ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
11385 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11386 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11387 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11388 ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
11389 time = msg.time;
11390 pt = msg.pt;
11391 ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
11392 ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11393 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11394 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11395 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11396 ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
11397 ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
11398 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 );
11399 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11400
11401 /* without PM_REMOVE */
11402 PostMessageW( hwnd, WM_CHAR, wch, 0 );
11403 ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
11404 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11405 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11406 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11407 ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11408 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11409 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11410 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11411 ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
11412 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11413 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11414 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11415 ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11416 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11417 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11418 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11419 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11420
11421 DestroyWindow(hwnd);
11422 }
11423
11424 #define ID_LISTBOX 0x000f
11425
11426 static const struct message wm_lb_setcursel_0[] =
11427 {
11428 { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
11429 { WM_CTLCOLORLISTBOX, sent|parent },
11430 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
11431 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11432 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11433 { 0 }
11434 };
11435 static const struct message wm_lb_setcursel_1[] =
11436 {
11437 { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
11438 { WM_CTLCOLORLISTBOX, sent|parent },
11439 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
11440 { WM_CTLCOLORLISTBOX, sent|parent },
11441 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
11442 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
11443 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
11444 { 0 }
11445 };
11446 static const struct message wm_lb_setcursel_2[] =
11447 {
11448 { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
11449 { WM_CTLCOLORLISTBOX, sent|parent },
11450 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
11451 { WM_CTLCOLORLISTBOX, sent|parent },
11452 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
11453 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11454 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11455 { 0 }
11456 };
11457 static const struct message wm_lb_click_0[] =
11458 {
11459 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
11460 { HCBT_SETFOCUS, hook },
11461 { WM_KILLFOCUS, sent|parent },
11462 { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
11463 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11464 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
11465 { WM_SETFOCUS, sent|defwinproc },
11466
11467 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
11468 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
11469 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11470 { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
11471 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
11472
11473 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
11474 { WM_CTLCOLORLISTBOX, sent|parent },
11475 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
11476 { WM_CTLCOLORLISTBOX, sent|parent },
11477 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
11478 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
11479
11480 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11481 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11482
11483 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
11484 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
11485 { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
11486 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
11487 { 0 }
11488 };
11489 static const struct message wm_lb_deletestring[] =
11490 {
11491 { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
11492 { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
11493 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11494 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11495 { 0 }
11496 };
11497 static const struct message wm_lb_deletestring_reset[] =
11498 {
11499 { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
11500 { LB_RESETCONTENT, sent|wparam|lparam|defwinproc|optional, 0, 0 },
11501 { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
11502 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11503 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11504 { 0 }
11505 };
11506
11507 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
11508
11509 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
11510
11511 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11512 {
11513 static LONG defwndproc_counter = 0;
11514 LRESULT ret;
11515 struct recvd_message msg;
11516
11517 /* do not log painting messages */
11518 if (message != WM_PAINT &&
11519 message != WM_NCPAINT &&
11520 message != WM_SYNCPAINT &&
11521 message != WM_ERASEBKGND &&
11522 message != WM_NCHITTEST &&
11523 message != WM_GETTEXT &&
11524 !ignore_message( message ))
11525 {
11526 msg.hwnd = hwnd;
11527 msg.message = message;
11528 msg.flags = sent|wparam|lparam;
11529 if (defwndproc_counter) msg.flags |= defwinproc;
11530 msg.wParam = wp;
11531 msg.lParam = lp;
11532 msg.descr = "listbox";
11533 add_message(&msg);
11534 }
11535
11536 defwndproc_counter++;
11537 ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
11538 defwndproc_counter--;
11539
11540 return ret;
11541 }
11542
11543 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
11544 int caret_index, int top_index, int line)
11545 {
11546 LRESULT ret;
11547
11548 /* calling an orig proc helps to avoid unnecessary message logging */
11549 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
11550 ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
11551 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
11552 ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
11553 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
11554 ok_(__FILE__, line)(ret == caret_index ||
11555 broken(cur_sel == -1 && caret_index == 0 && ret == -1), /* nt4 */
11556 "expected caret index %d, got %ld\n", caret_index, ret);
11557 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
11558 ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
11559 }
11560
11561 static void test_listbox_messages(void)
11562 {
11563 HWND parent, listbox;
11564 LRESULT ret;
11565
11566 parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11567 100, 100, 200, 200, 0, 0, 0, NULL);
11568 listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
11569 WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
11570 10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
11571 listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
11572
11573 check_lb_state(listbox, 0, LB_ERR, 0, 0);
11574
11575 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
11576 ok(ret == 0, "expected 0, got %ld\n", ret);
11577 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
11578 ok(ret == 1, "expected 1, got %ld\n", ret);
11579 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
11580 ok(ret == 2, "expected 2, got %ld\n", ret);
11581
11582 check_lb_state(listbox, 3, LB_ERR, 0, 0);
11583
11584 flush_sequence();
11585
11586 log_all_parent_messages++;
11587
11588 trace("selecting item 0\n");
11589 ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
11590 ok(ret == 0, "expected 0, got %ld\n", ret);
11591 ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
11592 check_lb_state(listbox, 3, 0, 0, 0);
11593 flush_sequence();
11594
11595 trace("selecting item 1\n");
11596 ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
11597 ok(ret == 1, "expected 1, got %ld\n", ret);
11598 ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
11599 check_lb_state(listbox, 3, 1, 1, 0);
11600
11601 trace("selecting item 2\n");
11602 ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
11603 ok(ret == 2, "expected 2, got %ld\n", ret);
11604 ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
11605 check_lb_state(listbox, 3, 2, 2, 0);
11606
11607 trace("clicking on item 0\n");
11608 ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
11609 ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11610 ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
11611 ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11612 ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
11613 check_lb_state(listbox, 3, 0, 0, 0);
11614 flush_sequence();
11615
11616 trace("deleting item 0\n");
11617 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11618 ok(ret == 2, "expected 2, got %ld\n", ret);
11619 ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
11620 check_lb_state(listbox, 2, -1, 0, 0);
11621 flush_sequence();
11622
11623 trace("deleting item 0\n");
11624 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11625 ok(ret == 1, "expected 1, got %ld\n", ret);
11626 ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
11627 check_lb_state(listbox, 1, -1, 0, 0);
11628 flush_sequence();
11629
11630 trace("deleting item 0\n");
11631 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11632 ok(ret == 0, "expected 0, got %ld\n", ret);
11633 ok_sequence(wm_lb_deletestring_reset, "LB_DELETESTRING 0", FALSE );
11634 check_lb_state(listbox, 0, -1, 0, 0);
11635 flush_sequence();
11636
11637 trace("deleting item 0\n");
11638 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11639 ok(ret == LB_ERR, "expected LB_ERR, got %ld\n", ret);
11640 check_lb_state(listbox, 0, -1, 0, 0);
11641 flush_sequence();
11642
11643 log_all_parent_messages--;
11644
11645 DestroyWindow(listbox);
11646 DestroyWindow(parent);
11647 }
11648
11649 /*************************** Menu test ******************************/
11650 static const struct message wm_popup_menu_1[] =
11651 {
11652 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11653 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11654 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
11655 { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
11656 { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
11657 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
11658 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11659 { WM_INITMENU, sent|lparam, 0, 0 },
11660 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
11661 { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
11662 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
11663 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
11664 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
11665 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11666 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001, 0, 0x40000000 },
11667 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
11668 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11669 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11670 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11671 { WM_MENUCOMMAND, sent }, /* |wparam, 200 - Win9x */
11672 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11673 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11674 { 0 }
11675 };
11676 static const struct message wm_popup_menu_2[] =
11677 {
11678 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11679 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11680 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11681 { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11682 { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11683 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11684 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11685 { WM_INITMENU, sent|lparam, 0, 0 },
11686 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11687 { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11688 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11689 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11690 { HCBT_CREATEWND, hook },
11691 { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11692 |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11693 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11694 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11695 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11696 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11697 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11698 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11699 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11700 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11701 { HCBT_DESTROYWND, hook },
11702 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11703 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11704 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11705 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11706 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11707 { WM_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
11708 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11709 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11710 { 0 }
11711 };
11712 static const struct message wm_popup_menu_3[] =
11713 {
11714 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11715 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11716 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11717 { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11718 { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11719 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11720 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11721 { WM_INITMENU, sent|lparam, 0, 0 },
11722 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11723 { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11724 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11725 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11726 { HCBT_CREATEWND, hook },
11727 { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11728 |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11729 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11730 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11731 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11732 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11733 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11734 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11735 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11736 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11737 { HCBT_DESTROYWND, hook },
11738 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11739 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11740 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11741 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11742 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11743 { WM_COMMAND, sent|wparam|lparam, 100, 0 },
11744 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11745 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11746 { 0 }
11747 };
11748
11749 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11750 {
11751 if (message == WM_ENTERIDLE ||
11752 message == WM_INITMENU ||
11753 message == WM_INITMENUPOPUP ||
11754 message == WM_MENUSELECT ||
11755 message == WM_PARENTNOTIFY ||
11756 message == WM_ENTERMENULOOP ||
11757 message == WM_EXITMENULOOP ||
11758 message == WM_UNINITMENUPOPUP ||
11759 message == WM_KEYDOWN ||
11760 message == WM_KEYUP ||
11761 message == WM_CHAR ||
11762 message == WM_SYSKEYDOWN ||
11763 message == WM_SYSKEYUP ||
11764 message == WM_SYSCHAR ||
11765 message == WM_COMMAND ||
11766 message == WM_MENUCOMMAND)
11767 {
11768 struct recvd_message msg;
11769
11770 msg.hwnd = hwnd;
11771 msg.message = message;
11772 msg.flags = sent|wparam|lparam;
11773 msg.wParam = wp;
11774 msg.lParam = lp;
11775 msg.descr = "parent_menu_proc";
11776 add_message(&msg);
11777 }
11778
11779 return DefWindowProcA(hwnd, message, wp, lp);
11780 }
11781
11782 static void set_menu_style(HMENU hmenu, DWORD style)
11783 {
11784 MENUINFO mi;
11785 BOOL ret;
11786
11787 mi.cbSize = sizeof(mi);
11788 mi.fMask = MIM_STYLE;
11789 mi.dwStyle = style;
11790 SetLastError(0xdeadbeef);
11791 ret = pSetMenuInfo(hmenu, &mi);
11792 ok(ret, "SetMenuInfo error %u\n", GetLastError());
11793 }
11794
11795 static DWORD get_menu_style(HMENU hmenu)
11796 {
11797 MENUINFO mi;
11798 BOOL ret;
11799
11800 mi.cbSize = sizeof(mi);
11801 mi.fMask = MIM_STYLE;
11802 mi.dwStyle = 0;
11803 SetLastError(0xdeadbeef);
11804 ret = pGetMenuInfo(hmenu, &mi);
11805 ok(ret, "GetMenuInfo error %u\n", GetLastError());
11806
11807 return mi.dwStyle;
11808 }
11809
11810 static void test_menu_messages(void)
11811 {
11812 MSG msg;
11813 WNDCLASSA cls;
11814 HMENU hmenu, hmenu_popup;
11815 HWND hwnd;
11816 DWORD style;
11817
11818 if (!pGetMenuInfo || !pSetMenuInfo)
11819 {
11820 win_skip("GetMenuInfo and/or SetMenuInfo are not available\n");
11821 return;
11822 }
11823 cls.style = 0;
11824 cls.lpfnWndProc = parent_menu_proc;
11825 cls.cbClsExtra = 0;
11826 cls.cbWndExtra = 0;
11827 cls.hInstance = GetModuleHandleA(0);
11828 cls.hIcon = 0;
11829 cls.hCursor = LoadCursorA(0, IDC_ARROW);
11830 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
11831 cls.lpszMenuName = NULL;
11832 cls.lpszClassName = "TestMenuClass";
11833 UnregisterClass(cls.lpszClassName, cls.hInstance);
11834 if (!RegisterClassA(&cls)) assert(0);
11835
11836 SetLastError(0xdeadbeef);
11837 hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11838 100, 100, 200, 200, 0, 0, 0, NULL);
11839 ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
11840
11841 SetLastError(0xdeadbeef);
11842 hmenu = LoadMenuA(GetModuleHandle(0), MAKEINTRESOURCE(1));
11843 ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
11844
11845 SetMenu(hwnd, hmenu);
11846 SetForegroundWindow( hwnd );
11847
11848 set_menu_style(hmenu, MNS_NOTIFYBYPOS);
11849 style = get_menu_style(hmenu);
11850 ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11851
11852 hmenu_popup = GetSubMenu(hmenu, 0);
11853 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11854 style = get_menu_style(hmenu_popup);
11855 ok(style == 0, "expected 0, got %u\n", style);
11856
11857 hmenu_popup = GetSubMenu(hmenu_popup, 0);
11858 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11859 style = get_menu_style(hmenu_popup);
11860 ok(style == 0, "expected 0, got %u\n", style);
11861
11862 /* Alt+E, Enter */
11863 trace("testing a popup menu command\n");
11864 flush_sequence();
11865 keybd_event(VK_MENU, 0, 0, 0);
11866 keybd_event('E', 0, 0, 0);
11867 keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
11868 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11869 keybd_event(VK_RETURN, 0, 0, 0);
11870 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11871 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11872 {
11873 TranslateMessage(&msg);
11874 DispatchMessage(&msg);
11875 }
11876 if (!sequence_cnt) /* we didn't get any message */
11877 {
11878 skip( "queuing key events not supported\n" );
11879 goto done;
11880 }
11881 /* win98 queues only a WM_KEYUP and doesn't start menu tracking */
11882 if (sequence[0].message == WM_KEYUP && sequence[0].wParam == VK_MENU)
11883 {
11884 win_skip( "menu tracking through VK_MENU not supported\n" );
11885 goto done;
11886 }
11887 ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
11888
11889 /* Alt+F, Right, Enter */
11890 trace("testing submenu of a popup menu command\n");
11891 flush_sequence();
11892 keybd_event(VK_MENU, 0, 0, 0);
11893 keybd_event('F', 0, 0, 0);
11894 keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11895 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11896 keybd_event(VK_RIGHT, 0, 0, 0);
11897 keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11898 keybd_event(VK_RETURN, 0, 0, 0);
11899 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11900 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11901 {
11902 TranslateMessage(&msg);
11903 DispatchMessage(&msg);
11904 }
11905 ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
11906
11907 set_menu_style(hmenu, 0);
11908 style = get_menu_style(hmenu);
11909 ok(style == 0, "expected 0, got %u\n", style);
11910
11911 hmenu_popup = GetSubMenu(hmenu, 0);
11912 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11913 set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
11914 style = get_menu_style(hmenu_popup);
11915 ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11916
11917 hmenu_popup = GetSubMenu(hmenu_popup, 0);
11918 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11919 style = get_menu_style(hmenu_popup);
11920 ok(style == 0, "expected 0, got %u\n", style);
11921
11922 /* Alt+F, Right, Enter */
11923 trace("testing submenu of a popup menu command\n");
11924 flush_sequence();
11925 keybd_event(VK_MENU, 0, 0, 0);
11926 keybd_event('F', 0, 0, 0);
11927 keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11928 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11929 keybd_event(VK_RIGHT, 0, 0, 0);
11930 keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11931 keybd_event(VK_RETURN, 0, 0, 0);
11932 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11933 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11934 {
11935 TranslateMessage(&msg);
11936 DispatchMessage(&msg);
11937 }
11938 ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
11939
11940 done:
11941 DestroyWindow(hwnd);
11942 DestroyMenu(hmenu);
11943 }
11944
11945
11946 static void test_paintingloop(void)
11947 {
11948 HWND hwnd;
11949
11950 paint_loop_done = 0;
11951 hwnd = CreateWindowExA(0x0,"PaintLoopWindowClass",
11952 "PaintLoopWindowClass",WS_OVERLAPPEDWINDOW,
11953 100, 100, 100, 100, 0, 0, 0, NULL );
11954 ok(hwnd != 0, "PaintLoop window error %u\n", GetLastError());
11955 ShowWindow(hwnd,SW_NORMAL);
11956 SetFocus(hwnd);
11957
11958 while (!paint_loop_done)
11959 {
11960 MSG msg;
11961 if (PeekMessageA(&msg, 0, 0, 0, 1))
11962 {
11963 TranslateMessage(&msg);
11964 DispatchMessage(&msg);
11965 }
11966 }
11967 DestroyWindow(hwnd);
11968 }
11969
11970 static void test_defwinproc(void)
11971 {
11972 HWND hwnd;
11973 MSG msg;
11974 int gotwmquit = FALSE;
11975 hwnd = CreateWindowExA(0, "static", "test_defwndproc", WS_POPUP, 0,0,0,0,0,0,0, NULL);
11976 assert(hwnd);
11977 DefWindowProcA( hwnd, WM_ENDSESSION, 1, 0);
11978 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) {
11979 if( msg.message == WM_QUIT) gotwmquit = TRUE;
11980 DispatchMessageA( &msg );
11981 }
11982 ok( gotwmquit == FALSE, "Unexpected WM_QUIT message!\n");
11983 DestroyWindow( hwnd);
11984 }
11985
11986 #define clear_clipboard(hwnd) clear_clipboard_(__LINE__, (hwnd))
11987 static void clear_clipboard_(int line, HWND hWnd)
11988 {
11989 BOOL succ;
11990 succ = OpenClipboard(hWnd);
11991 ok_(__FILE__, line)(succ, "OpenClipboard failed, err=%u\n", GetLastError());
11992 succ = EmptyClipboard();
11993 ok_(__FILE__, line)(succ, "EmptyClipboard failed, err=%u\n", GetLastError());
11994 succ = CloseClipboard();
11995 ok_(__FILE__, line)(succ, "CloseClipboard failed, err=%u\n", GetLastError());
11996 }
11997
11998 #define expect_HWND(expected, got) expect_HWND_(__LINE__, (expected), (got))
11999 static void expect_HWND_(int line, HWND expected, HWND got)
12000 {
12001 ok_(__FILE__, line)(got==expected, "Expected %p, got %p\n", expected, got);
12002 }
12003
12004 static WNDPROC pOldViewerProc;
12005
12006 static LRESULT CALLBACK recursive_viewer_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
12007 {
12008 static BOOL recursion_guard;
12009
12010 if (message == WM_DRAWCLIPBOARD && !recursion_guard)
12011 {
12012 recursion_guard = TRUE;
12013 clear_clipboard(hWnd);
12014 recursion_guard = FALSE;
12015 }
12016 return CallWindowProcA(pOldViewerProc, hWnd, message, wParam, lParam);
12017 }
12018
12019 static void test_clipboard_viewers(void)
12020 {
12021 static struct message wm_change_cb_chain[] =
12022 {
12023 { WM_CHANGECBCHAIN, sent|wparam|lparam, 0, 0 },
12024 { 0 }
12025 };
12026 static const struct message wm_clipboard_destroyed[] =
12027 {
12028 { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
12029 { 0 }
12030 };
12031 static struct message wm_clipboard_changed[] =
12032 {
12033 { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
12034 { 0 }
12035 };
12036 static struct message wm_clipboard_changed_and_owned[] =
12037 {
12038 { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
12039 { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
12040 { 0 }
12041 };
12042
12043 HINSTANCE hInst = GetModuleHandleA(NULL);
12044 HWND hWnd1, hWnd2, hWnd3;
12045 HWND hOrigViewer;
12046 HWND hRet;
12047
12048 hWnd1 = CreateWindowExA(0, "TestWindowClass", "Clipboard viewer test wnd 1",
12049 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12050 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12051 GetDesktopWindow(), NULL, hInst, NULL);
12052 hWnd2 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 2",
12053 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12054 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12055 GetDesktopWindow(), NULL, hInst, NULL);
12056 hWnd3 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 3",
12057 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12058 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12059 GetDesktopWindow(), NULL, hInst, NULL);
12060 trace("clipbd viewers: hWnd1=%p, hWnd2=%p, hWnd3=%p\n", hWnd1, hWnd2, hWnd3);
12061 assert(hWnd1 && hWnd2 && hWnd3);
12062
12063 flush_sequence();
12064
12065 /* Test getting the clipboard viewer and setting the viewer to NULL. */
12066 hOrigViewer = GetClipboardViewer();
12067 hRet = SetClipboardViewer(NULL);
12068 ok_sequence(WmEmptySeq, "set viewer to NULL", FALSE);
12069 expect_HWND(hOrigViewer, hRet);
12070 expect_HWND(NULL, GetClipboardViewer());
12071
12072 /* Test registering hWnd1 as a viewer. */
12073 hRet = SetClipboardViewer(hWnd1);
12074 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12075 ok_sequence(wm_clipboard_changed, "set viewer NULL->1", FALSE);
12076 expect_HWND(NULL, hRet);
12077 expect_HWND(hWnd1, GetClipboardViewer());
12078
12079 /* Test that changing the clipboard actually refreshes the registered viewer. */
12080 clear_clipboard(hWnd1);
12081 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12082 ok_sequence(wm_clipboard_changed, "clear clipbd (viewer=owner=1)", FALSE);
12083
12084 /* Again, but with different owner. */
12085 clear_clipboard(hWnd2);
12086 wm_clipboard_changed_and_owned[1].wParam = (WPARAM) GetClipboardOwner();
12087 ok_sequence(wm_clipboard_changed_and_owned, "clear clipbd (viewer=1, owner=2)", FALSE);
12088
12089 /* Test re-registering same window. */
12090 hRet = SetClipboardViewer(hWnd1);
12091 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12092 ok_sequence(wm_clipboard_changed, "set viewer 1->1", FALSE);
12093 expect_HWND(hWnd1, hRet);
12094 expect_HWND(hWnd1, GetClipboardViewer());
12095
12096 /* Test ChangeClipboardChain. */
12097 ChangeClipboardChain(hWnd2, hWnd3);
12098 wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
12099 wm_change_cb_chain[0].lParam = (LPARAM) hWnd3;
12100 ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=3)", FALSE);
12101 expect_HWND(hWnd1, GetClipboardViewer());
12102
12103 ChangeClipboardChain(hWnd2, NULL);
12104 wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
12105 wm_change_cb_chain[0].lParam = 0;
12106 ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=NULL)", FALSE);
12107 expect_HWND(hWnd1, GetClipboardViewer());
12108
12109 ChangeClipboardChain(NULL, hWnd2);
12110 ok_sequence(WmEmptySeq, "change chain (viewer=1, remove=NULL, next=2)", TRUE);
12111 expect_HWND(hWnd1, GetClipboardViewer());
12112
12113 /* Actually change clipboard viewer with ChangeClipboardChain. */
12114 ChangeClipboardChain(hWnd1, hWnd2);
12115 ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=2)", FALSE);
12116 expect_HWND(hWnd2, GetClipboardViewer());
12117
12118 /* Test that no refresh messages are sent when viewer has unregistered. */
12119 clear_clipboard(hWnd2);
12120 ok_sequence(WmEmptySeq, "clear clipd (viewer=2, owner=1)", FALSE);
12121
12122 /* Register hWnd1 again. */
12123 ChangeClipboardChain(hWnd2, hWnd1);
12124 ok_sequence(WmEmptySeq, "change chain (viewer=remove=2, next=1)", FALSE);
12125 expect_HWND(hWnd1, GetClipboardViewer());
12126
12127 /* Subclass hWnd1 so that when it receives a WM_DRAWCLIPBOARD message, it
12128 * changes the clipboard. When this happens, the system shouldn't send
12129 * another WM_DRAWCLIPBOARD (as this could cause an infinite loop).
12130 */
12131 pOldViewerProc = (WNDPROC) SetWindowLongPtrA(hWnd1, GWLP_WNDPROC, (LONG_PTR) recursive_viewer_proc);
12132 clear_clipboard(hWnd2);
12133 /* The clipboard owner is changed in recursive_viewer_proc: */
12134 wm_clipboard_changed[0].wParam = (WPARAM) hWnd2;
12135 ok_sequence(wm_clipboard_changed, "recursive clear clipbd (viewer=1, owner=2)", TRUE);
12136
12137 /* Test unregistering. */
12138 ChangeClipboardChain(hWnd1, NULL);
12139 ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=NULL)", FALSE);
12140 expect_HWND(NULL, GetClipboardViewer());
12141
12142 clear_clipboard(hWnd1);
12143 ok_sequence(wm_clipboard_destroyed, "clear clipbd (no viewer, owner=1)", FALSE);
12144
12145 DestroyWindow(hWnd1);
12146 DestroyWindow(hWnd2);
12147 DestroyWindow(hWnd3);
12148 SetClipboardViewer(hOrigViewer);
12149 }
12150
12151 static void test_PostMessage(void)
12152 {
12153 static const struct
12154 {
12155 HWND hwnd;
12156 BOOL ret;
12157 } data[] =
12158 {
12159 { HWND_TOP /* 0 */, TRUE },
12160 { HWND_BROADCAST, TRUE },
12161 { HWND_BOTTOM, TRUE },
12162 { HWND_TOPMOST, TRUE },
12163 { HWND_NOTOPMOST, FALSE },
12164 { HWND_MESSAGE, FALSE },
12165 { (HWND)0xdeadbeef, FALSE }
12166 };
12167 int i;
12168 HWND hwnd;
12169 BOOL ret;
12170 MSG msg;
12171 static const WCHAR staticW[] = {'s','t','a','t','i','c',0};
12172
12173 SetLastError(0xdeadbeef);
12174 hwnd = CreateWindowExW(0, staticW, NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
12175 if (!hwnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
12176 {
12177 win_skip("Skipping some PostMessage tests on Win9x/WinMe\n");
12178 return;
12179 }
12180 assert(hwnd);
12181
12182 flush_events();
12183
12184 PostMessage(hwnd, WM_USER+1, 0x1234, 0x5678);
12185 PostMessage(0, WM_USER+2, 0x5678, 0x1234);
12186
12187 for (i = 0; i < sizeof(data)/sizeof(data[0]); i++)
12188 {
12189 memset(&msg, 0xab, sizeof(msg));
12190 ret = PeekMessageA(&msg, data[i].hwnd, 0, 0, PM_NOREMOVE);
12191 ok(ret == data[i].ret, "%d: hwnd %p expected %d, got %d\n", i, data[i].hwnd, data[i].ret, ret);
12192 if (data[i].ret)
12193 {
12194 if (data[i].hwnd)
12195 ok(ret && msg.hwnd == 0 && msg.message == WM_USER+2 &&
12196 msg.wParam == 0x5678 && msg.lParam == 0x1234,
12197 "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/0/WM_USER+2/0x5678/0x1234\n",
12198 i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam);
12199 else
12200 ok(ret && msg.hwnd == hwnd && msg.message == WM_USER+1 &&
12201 msg.wParam == 0x1234 && msg.lParam == 0x5678,
12202 "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/%p/WM_USER+1/0x1234/0x5678\n",
12203 i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam, msg.hwnd);
12204 }
12205 }
12206
12207 DestroyWindow(hwnd);
12208 flush_events();
12209 }
12210
12211 static const struct
12212 {
12213 DWORD exp, broken;
12214 BOOL todo;
12215 } wait_idle_expect[] =
12216 {
12217 /* 0 */ { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12218 { WAIT_TIMEOUT, 0, FALSE },
12219 { WAIT_TIMEOUT, 0, FALSE },
12220 { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12221 { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12222 /* 5 */ { WAIT_TIMEOUT, 0, FALSE },
12223 { WAIT_TIMEOUT, 0, FALSE },
12224 { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12225 { 0, 0, FALSE },
12226 { 0, 0, FALSE },
12227 /* 10 */ { 0, 0, FALSE },
12228 { 0, 0, FALSE },
12229 { 0, WAIT_TIMEOUT, FALSE },
12230 { 0, 0, FALSE },
12231 { 0, 0, FALSE },
12232 /* 15 */ { 0, 0, FALSE },
12233 { WAIT_TIMEOUT, 0, FALSE },
12234 { WAIT_TIMEOUT, 0, FALSE },
12235 { WAIT_TIMEOUT, 0, FALSE },
12236 { WAIT_TIMEOUT, 0, FALSE },
12237 /* 20 */ { WAIT_TIMEOUT, 0, FALSE },
12238 };
12239
12240 static DWORD CALLBACK do_wait_idle_child_thread( void *arg )
12241 {
12242 MSG msg;
12243
12244 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12245 Sleep( 200 );
12246 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12247 return 0;
12248 }
12249
12250 static void do_wait_idle_child( int arg )
12251 {
12252 WNDCLASS cls;
12253 MSG msg;
12254 HWND hwnd = 0;
12255 HANDLE thread;
12256 DWORD id;
12257 HANDLE start_event = OpenEventA( EVENT_ALL_ACCESS, FALSE, "test_WaitForInputIdle_start" );
12258 HANDLE end_event = OpenEventA( EVENT_ALL_ACCESS, FALSE, "test_WaitForInputIdle_end" );
12259
12260 memset( &cls, 0, sizeof(cls) );
12261 cls.lpfnWndProc = DefWindowProc;
12262 cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
12263 cls.hCursor = LoadCursor(0, IDC_ARROW);
12264 cls.lpszClassName = "TestClass";
12265 RegisterClass( &cls );
12266
12267 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ); /* create the msg queue */
12268
12269 ok( start_event != 0, "failed to create start event, error %u\n", GetLastError() );
12270 ok( end_event != 0, "failed to create end event, error %u\n", GetLastError() );
12271
12272 switch (arg)
12273 {
12274 case 0:
12275 SetEvent( start_event );
12276 break;
12277 case 1:
12278 SetEvent( start_event );
12279 Sleep( 200 );
12280 PeekMessage( &msg, 0, 0, 0, PM_REMOVE );
12281 break;
12282 case 2:
12283 SetEvent( start_event );
12284 Sleep( 200 );
12285 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12286 PostThreadMessage( GetCurrentThreadId(), WM_COMMAND, 0x1234, 0xabcd );
12287 PeekMessage( &msg, 0, 0, 0, PM_REMOVE );
12288 break;
12289 case 3:
12290 SetEvent( start_event );
12291 Sleep( 200 );
12292 SendMessage( HWND_BROADCAST, WM_WININICHANGE, 0, 0 );
12293 break;
12294 case 4:
12295 SetEvent( start_event );
12296 Sleep( 200 );
12297 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12298 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessage( &msg );
12299 break;
12300 case 5:
12301 SetEvent( start_event );
12302 Sleep( 200 );
12303 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12304 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12305 break;
12306 case 6:
12307 SetEvent( start_event );
12308 Sleep( 200 );
12309 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12310 while (PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ))
12311 {
12312 GetMessage( &msg, 0, 0, 0 );
12313 DispatchMessage( &msg );
12314 }
12315 break;
12316 case 7:
12317 SetEvent( start_event );
12318 Sleep( 200 );
12319 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12320 SetTimer( hwnd, 3, 1, NULL );
12321 Sleep( 200 );
12322 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessage( &msg );
12323 break;
12324 case 8:
12325 SetEvent( start_event );
12326 Sleep( 200 );
12327 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12328 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12329 break;
12330 case 9:
12331 SetEvent( start_event );
12332 Sleep( 200 );
12333 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12334 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12335 for (;;) GetMessage( &msg, 0, 0, 0 );
12336 break;
12337 case 10:
12338 SetEvent( start_event );
12339 Sleep( 200 );
12340 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12341 SetTimer( hwnd, 3, 1, NULL );
12342 Sleep( 200 );
12343 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12344 break;
12345 case 11:
12346 SetEvent( start_event );
12347 Sleep( 200 );
12348 return; /* exiting the process makes WaitForInputIdle return success too */
12349 case 12:
12350 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12351 Sleep( 200 );
12352 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12353 SetEvent( start_event );
12354 break;
12355 case 13:
12356 SetEvent( start_event );
12357 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12358 Sleep( 200 );
12359 thread = CreateThread( NULL, 0, do_wait_idle_child_thread, NULL, 0, &id );
12360 WaitForSingleObject( thread, 10000 );
12361 CloseHandle( thread );
12362 break;
12363 case 14:
12364 SetEvent( start_event );
12365 Sleep( 200 );
12366 PeekMessage( &msg, HWND_TOPMOST, 0, 0, PM_NOREMOVE );
12367 break;
12368 case 15:
12369 SetEvent( start_event );
12370 Sleep( 200 );
12371 PeekMessage( &msg, HWND_BROADCAST, 0, 0, PM_NOREMOVE );
12372 break;
12373 case 16:
12374 SetEvent( start_event );
12375 Sleep( 200 );
12376 PeekMessage( &msg, HWND_BOTTOM, 0, 0, PM_NOREMOVE );
12377 break;
12378 case 17:
12379 SetEvent( start_event );
12380 Sleep( 200 );
12381 PeekMessage( &msg, (HWND)0xdeadbeef, 0, 0, PM_NOREMOVE );
12382 break;
12383 case 18:
12384 SetEvent( start_event );
12385 Sleep( 200 );
12386 PeekMessage( &msg, HWND_NOTOPMOST, 0, 0, PM_NOREMOVE );
12387 break;
12388 case 19:
12389 SetEvent( start_event );
12390 Sleep( 200 );
12391 PeekMessage( &msg, HWND_MESSAGE, 0, 0, PM_NOREMOVE );
12392 break;
12393 case 20:
12394 SetEvent( start_event );
12395 Sleep( 200 );
12396 PeekMessage( &msg, GetDesktopWindow(), 0, 0, PM_NOREMOVE );
12397 break;
12398 }
12399 WaitForSingleObject( end_event, 2000 );
12400 CloseHandle( start_event );
12401 CloseHandle( end_event );
12402 if (hwnd) DestroyWindow( hwnd );
12403 }
12404
12405 static LRESULT CALLBACK wait_idle_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
12406 {
12407 if (msg == WM_WININICHANGE) Sleep( 200 ); /* make sure the child waits */
12408 return DefWindowProcA( hwnd, msg, wp, lp );
12409 }
12410
12411 static DWORD CALLBACK wait_idle_thread( void *arg )
12412 {
12413 WNDCLASS cls;
12414 MSG msg;
12415 HWND hwnd;
12416
12417 memset( &cls, 0, sizeof(cls) );
12418 cls.lpfnWndProc = wait_idle_proc;
12419 cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
12420 cls.hCursor = LoadCursor(0, IDC_ARROW);
12421 cls.lpszClassName = "TestClass";
12422 RegisterClass( &cls );
12423
12424 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
12425 while (GetMessage( &msg, 0, 0, 0 )) DispatchMessage( &msg );
12426 DestroyWindow(hwnd);
12427 return 0;
12428 }
12429
12430 static void test_WaitForInputIdle( char *argv0 )
12431 {
12432 char path[MAX_PATH];
12433 PROCESS_INFORMATION pi;
12434 STARTUPINFOA startup;
12435 BOOL ret;
12436 HANDLE start_event, end_event, thread;
12437 unsigned int i;
12438 DWORD id;
12439 const IMAGE_DOS_HEADER *dos = (const IMAGE_DOS_HEADER *)GetModuleHandleA(0);
12440 const IMAGE_NT_HEADERS *nt = (const IMAGE_NT_HEADERS *)((const char *)dos + dos->e_lfanew);
12441 BOOL console_app = (nt->OptionalHeader.Subsystem != IMAGE_SUBSYSTEM_WINDOWS_GUI);
12442
12443 if (console_app) /* build the test with -mwindows for better coverage */
12444 trace( "not built as a GUI app, WaitForInputIdle may not be fully tested\n" );
12445
12446 start_event = CreateEventA(NULL, 0, 0, "test_WaitForInputIdle_start");
12447 end_event = CreateEventA(NULL, 0, 0, "test_WaitForInputIdle_end");
12448 ok(start_event != 0, "failed to create start event, error %u\n", GetLastError());
12449 ok(end_event != 0, "failed to create end event, error %u\n", GetLastError());
12450
12451 memset( &startup, 0, sizeof(startup) );
12452 startup.cb = sizeof(startup);
12453 startup.dwFlags = STARTF_USESHOWWINDOW;
12454 startup.wShowWindow = SW_SHOWNORMAL;
12455
12456 thread = CreateThread( NULL, 0, wait_idle_thread, NULL, 0, &id );
12457
12458 for (i = 0; i < sizeof(wait_idle_expect)/sizeof(wait_idle_expect[0]); i++)
12459 {
12460 ResetEvent( start_event );
12461 ResetEvent( end_event );
12462 sprintf( path, "%s msg %u", argv0, i );
12463 ret = CreateProcessA( NULL, path, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &pi );
12464 ok( ret, "CreateProcess '%s' failed err %u.\n", path, GetLastError() );
12465 if (ret)
12466 {
12467 ret = WaitForSingleObject( start_event, 5000 );
12468 ok( ret == WAIT_OBJECT_0, "%u: WaitForSingleObject failed\n", i );
12469 if (ret == WAIT_OBJECT_0)
12470 {
12471 ret = WaitForInputIdle( pi.hProcess, 1000 );
12472 if (ret == WAIT_FAILED)
12473 ok( console_app ||
12474 ret == wait_idle_expect[i].exp ||
12475 broken(ret == wait_idle_expect[i].broken),
12476 "%u: WaitForInputIdle error %08x expected %08x\n",
12477 i, ret, wait_idle_expect[i].exp );
12478 else if (wait_idle_expect[i].todo)
12479 todo_wine
12480 ok( ret == wait_idle_expect[i].exp || broken(ret == wait_idle_expect[i].broken),
12481 "%u: WaitForInputIdle error %08x expected %08x\n",
12482 i, ret, wait_idle_expect[i].exp );
12483 else
12484 ok( ret == wait_idle_expect[i].exp || broken(ret == wait_idle_expect[i].broken),
12485 "%u: WaitForInputIdle error %08x expected %08x\n",
12486 i, ret, wait_idle_expect[i].exp );
12487 SetEvent( end_event );
12488 WaitForSingleObject( pi.hProcess, 1000 ); /* give it a chance to exit on its own */
12489 }
12490 TerminateProcess( pi.hProcess, 0 ); /* just in case */
12491 winetest_wait_child_process( pi.hProcess );
12492 ret = WaitForInputIdle( pi.hProcess, 100 );
12493 ok( ret == WAIT_FAILED, "%u: WaitForInputIdle after exit error %08x\n", i, ret );
12494 CloseHandle( pi.hProcess );
12495 CloseHandle( pi.hThread );
12496 }
12497 }
12498 CloseHandle( start_event );
12499 PostThreadMessage( id, WM_QUIT, 0, 0 );
12500 WaitForSingleObject( thread, 10000 );
12501 CloseHandle( thread );
12502 }
12503
12504 START_TEST(msg)
12505 {
12506 char **test_argv;
12507 BOOL ret;
12508 BOOL (WINAPI *pIsWinEventHookInstalled)(DWORD)= 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
12509
12510 int argc = winetest_get_mainargs( &test_argv );
12511 if (argc >= 3)
12512 {
12513 unsigned int arg;
12514 /* Child process. */
12515 sscanf (test_argv[2], "%d", (unsigned int *) &arg);
12516 do_wait_idle_child( arg );
12517 return;
12518 }
12519
12520 init_procs();
12521
12522 if (!RegisterWindowClasses()) assert(0);
12523
12524 if (pSetWinEventHook)
12525 {
12526 hEvent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX,
12527 GetModuleHandleA(0), win_event_proc,
12528 0, GetCurrentThreadId(),
12529 WINEVENT_INCONTEXT);
12530 if (pIsWinEventHookInstalled && hEvent_hook)
12531 {
12532 UINT event;
12533 for (event = EVENT_MIN; event <= EVENT_MAX; event++)
12534 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
12535 }
12536 }
12537 if (!hEvent_hook) win_skip( "no win event hook support\n" );
12538
12539 cbt_hook_thread_id = GetCurrentThreadId();
12540 hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
12541 if (!hCBT_hook) win_skip( "cannot set global hook, will skip hook tests\n" );
12542
12543 test_winevents();
12544
12545 /* Fix message sequences before removing 4 lines below */
12546 #if 1
12547 if (pUnhookWinEvent && hEvent_hook)
12548 {
12549 ret = pUnhookWinEvent(hEvent_hook);
12550 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
12551 pUnhookWinEvent = 0;
12552 }
12553 hEvent_hook = 0;
12554 #endif
12555
12556 test_PostMessage();
12557 test_ShowWindow();
12558 test_PeekMessage();
12559 test_PeekMessage2();
12560 test_WaitForInputIdle( test_argv[0] );
12561 test_scrollwindowex();
12562 test_messages();
12563 test_setwindowpos();
12564 test_showwindow();
12565 invisible_parent_tests();
12566 test_mdi_messages();
12567 test_button_messages();
12568 test_static_messages();
12569 test_listbox_messages();
12570 test_combobox_messages();
12571 test_wmime_keydown_message();
12572 test_paint_messages();
12573 test_interthread_messages();
12574 test_message_conversion();
12575 test_accelerators();
12576 test_timers();
12577 test_timers_no_wnd();
12578 if (hCBT_hook) test_set_hook();
12579 test_DestroyWindow();
12580 test_DispatchMessage();
12581 test_SendMessageTimeout();
12582 test_edit_messages();
12583 test_quit_message();
12584 test_SetActiveWindow();
12585
12586 if (!pTrackMouseEvent)
12587 win_skip("TrackMouseEvent is not available\n");
12588 else
12589 test_TrackMouseEvent();
12590
12591 test_SetWindowRgn();
12592 test_sys_menu();
12593 test_dialog_messages();
12594 test_nullCallback();
12595 test_dbcs_wm_char();
12596 if(!winetest_interactive)
12597 skip("skipping test_menu_messages, that hangs on reactos\n");
12598 else
12599 test_menu_messages();
12600 test_paintingloop();
12601 test_defwinproc();
12602 test_clipboard_viewers();
12603 /* keep it the last test, under Windows it tends to break the tests
12604 * which rely on active/foreground windows being correct.
12605 */
12606 test_SetForegroundWindow();
12607
12608 UnhookWindowsHookEx(hCBT_hook);
12609 if (pUnhookWinEvent && hEvent_hook)
12610 {
12611 ret = pUnhookWinEvent(hEvent_hook);
12612 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
12613 SetLastError(0xdeadbeef);
12614 ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
12615 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
12616 GetLastError() == 0xdeadbeef, /* Win9x */
12617 "unexpected error %d\n", GetLastError());
12618 }
12619 }