If an MDI child becomes active restore previously maximized MDI
[wine.git] / dlls / user / tests / msg.c
bloba05b04fd7eb1a073bfcd6ec03e0a10d4ab0aa747
1 /*
2 * Unit tests for window message handling
4 * Copyright 1999 Ove Kaaven
5 * Copyright 2003 Dimitrie O. Paun
6 * Copyright 2004, 2005 Dmitry Timoshkov
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.
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.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <assert.h>
24 #include <stdarg.h>
25 #include <stdio.h>
27 #define _WIN32_WINNT 0x0500 /* For WM_CHANGEUISTATE */
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
34 #include "wine/test.h"
36 #define MDI_FIRST_CHILD_ID 2004
38 /* undocumented SWP flags - from SDK 3.1 */
39 #define SWP_NOCLIENTSIZE 0x0800
40 #define SWP_NOCLIENTMOVE 0x1000
42 #define WND_PARENT_ID 1
43 #define WND_POPUP_ID 2
44 #define WND_CHILD_ID 3
46 static BOOL test_DestroyWindow_flag;
47 static HWINEVENTHOOK hEvent_hook;
49 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
52 FIXME: add tests for these
53 Window Edge Styles (Win31/Win95/98 look), in order of precedence:
54 WS_EX_DLGMODALFRAME: double border, WS_CAPTION allowed
55 WS_THICKFRAME: thick border
56 WS_DLGFRAME: double border, WS_CAPTION not allowed (but possibly shown anyway)
57 WS_BORDER (default for overlapped windows): single black border
58 none (default for child (and popup?) windows): no border
61 typedef enum {
62 sent=0x1,
63 posted=0x2,
64 parent=0x4,
65 wparam=0x8,
66 lparam=0x10,
67 defwinproc=0x20,
68 beginpaint=0x40,
69 optional=0x80,
70 hook=0x100,
71 winevent_hook=0x200
72 } msg_flags_t;
74 struct message {
75 UINT message; /* the WM_* code */
76 msg_flags_t flags; /* message props */
77 WPARAM wParam; /* expected value of wParam */
78 LPARAM lParam; /* expected value of lParam */
81 /* Empty message sequence */
82 static const struct message WmEmptySeq[] =
84 { 0 }
86 /* CreateWindow (for overlapped window, not initially visible) (16/32) */
87 static const struct message WmCreateOverlappedSeq[] = {
88 { HCBT_CREATEWND, hook },
89 { WM_GETMINMAXINFO, sent },
90 { WM_NCCREATE, sent },
91 { WM_NCCALCSIZE, sent|wparam, 0 },
92 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
93 { WM_CREATE, sent },
94 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
95 { 0 }
97 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
98 * for a not visible overlapped window.
100 static const struct message WmSWP_ShowOverlappedSeq[] = {
101 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
102 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
103 { WM_NCPAINT, sent|wparam|optional, 1 },
104 { WM_GETTEXT, sent|defwinproc|optional },
105 { WM_ERASEBKGND, sent|optional },
106 { HCBT_ACTIVATE, hook },
107 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
108 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
109 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x: SWP_NOSENDCHANGING */
110 { WM_ACTIVATEAPP, sent|wparam, 1 },
111 { WM_NCACTIVATE, sent|wparam, 1 },
112 { WM_GETTEXT, sent|defwinproc|optional },
113 { WM_ACTIVATE, sent|wparam, 1 },
114 { HCBT_SETFOCUS, hook },
115 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
116 { WM_IME_NOTIFY, sent|defwinproc|optional },
117 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
118 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
119 { WM_NCPAINT, sent|wparam|optional, 1 },
120 { WM_GETTEXT, sent|defwinproc|optional },
121 { WM_ERASEBKGND, sent|optional },
122 /* Win9x adds SWP_NOZORDER below */
123 { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
124 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
125 { WM_NCPAINT, sent|wparam|optional, 1 },
126 { WM_ERASEBKGND, sent|optional },
127 { 0 }
129 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
130 * for a visible overlapped window.
132 static const struct message WmSWP_HideOverlappedSeq[] = {
133 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
134 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
135 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
136 { 0 }
139 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
140 * for a visible overlapped window.
142 static const struct message WmSWP_ResizeSeq[] = {
143 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE },
144 { WM_GETMINMAXINFO, sent|defwinproc },
145 { WM_NCCALCSIZE, sent|wparam, TRUE },
146 { WM_NCPAINT, sent|optional },
147 { WM_GETTEXT, sent|defwinproc|optional },
148 { WM_ERASEBKGND, sent|optional },
149 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
150 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
151 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
152 { WM_NCPAINT, sent|optional },
153 { WM_GETTEXT, sent|defwinproc|optional },
154 { WM_ERASEBKGND, sent|optional },
155 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
156 { 0 }
159 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
160 * for a visible popup window.
162 static const struct message WmSWP_ResizePopupSeq[] = {
163 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE },
164 { WM_NCCALCSIZE, sent|wparam, TRUE },
165 { WM_NCPAINT, sent|optional },
166 { WM_GETTEXT, sent|defwinproc|optional },
167 { WM_ERASEBKGND, sent|optional },
168 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
169 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
170 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
171 { WM_NCPAINT, sent|optional },
172 { WM_GETTEXT, sent|defwinproc|optional },
173 { WM_ERASEBKGND, sent|optional },
174 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
175 { 0 }
178 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
179 * for a visible overlapped window.
181 static const struct message WmSWP_MoveSeq[] = {
182 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE },
183 { WM_NCPAINT, sent|optional },
184 { WM_GETTEXT, sent|defwinproc|optional },
185 { WM_ERASEBKGND, sent|optional },
186 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER|SWP_NOCLIENTSIZE },
187 { WM_MOVE, sent|defwinproc|wparam, 0 },
188 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
189 { 0 }
192 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
193 static const struct message WmShowOverlappedSeq[] = {
194 { WM_SHOWWINDOW, sent|wparam, 1 },
195 { WM_NCPAINT, sent|wparam|optional, 1 },
196 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
197 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
198 { WM_NCPAINT, sent|wparam|optional, 1 },
199 { WM_GETTEXT, sent|defwinproc|optional },
200 { WM_ERASEBKGND, sent|optional },
201 { HCBT_ACTIVATE, hook },
202 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
203 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
204 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
205 { WM_ACTIVATEAPP, sent|wparam, 1 },
206 { WM_NCACTIVATE, sent|wparam, 1 },
207 { WM_GETTEXT, sent|defwinproc|optional },
208 { WM_ACTIVATE, sent|wparam, 1 },
209 { HCBT_SETFOCUS, hook },
210 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
211 { WM_IME_NOTIFY, sent|defwinproc|optional },
212 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
213 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
214 { WM_NCPAINT, sent|wparam|optional, 1 },
215 { WM_GETTEXT, sent|defwinproc|optional },
216 { WM_ERASEBKGND, sent|optional },
217 /* Win9x adds SWP_NOZORDER below */
218 { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
219 { WM_NCCALCSIZE, sent|optional },
220 { WM_NCPAINT, sent|optional },
221 { WM_ERASEBKGND, sent|optional },
222 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
223 * messages. Does that mean that CreateWindow doesn't set initial
224 * window dimensions for overlapped windows?
226 { WM_SIZE, sent },
227 { WM_MOVE, sent },
228 #endif
229 { 0 }
231 /* ShowWindow(SW_HIDE) for a visible overlapped window */
232 static const struct message WmHideOverlappedSeq[] = {
233 { WM_SHOWWINDOW, sent|wparam, 0 },
234 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
235 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
236 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
237 { WM_SIZE, sent },
238 { WM_MOVE, sent },
239 { WM_NCACTIVATE, sent|wparam, 0 },
240 { WM_ACTIVATE, sent|wparam, 0 },
241 { WM_ACTIVATEAPP, sent|wparam, 0 },
242 { WM_KILLFOCUS, sent|wparam, 0 },
243 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
244 { WM_IME_NOTIFY, sent|optional|defwinproc },
245 { 0 }
247 /* DestroyWindow for a visible overlapped window */
248 static const struct message WmDestroyOverlappedSeq[] = {
249 { HCBT_DESTROYWND, hook },
250 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
251 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
252 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
253 { WM_NCACTIVATE, sent|wparam, 0 },
254 { WM_ACTIVATE, sent|wparam, 0 },
255 { WM_ACTIVATEAPP, sent|wparam, 0 },
256 { WM_KILLFOCUS, sent|wparam, 0 },
257 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
258 { WM_IME_NOTIFY, sent|optional|defwinproc },
259 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
260 { WM_DESTROY, sent },
261 { WM_NCDESTROY, sent },
262 { 0 }
264 /* CreateWindow (for a child popup window, not initially visible) */
265 static const struct message WmCreateChildPopupSeq[] = {
266 { HCBT_CREATEWND, hook },
267 { WM_NCCREATE, sent },
268 { WM_NCCALCSIZE, sent|wparam, 0 },
269 { WM_CREATE, sent },
270 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
271 { WM_SIZE, sent },
272 { WM_MOVE, sent },
273 { 0 }
275 /* CreateWindow (for a popup window, not initially visible,
276 * which sets WS_VISIBLE in WM_CREATE handler)
278 static const struct message WmCreateInvisiblePopupSeq[] = {
279 { HCBT_CREATEWND, hook },
280 { WM_NCCREATE, sent },
281 { WM_NCCALCSIZE, sent|wparam, 0 },
282 { WM_CREATE, sent },
283 { WM_STYLECHANGING, sent },
284 { WM_STYLECHANGED, sent },
285 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
286 { WM_SIZE, sent },
287 { WM_MOVE, sent },
288 { 0 }
290 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
291 * for a popup window with WS_VISIBLE style set
293 static const struct message WmShowVisiblePopupSeq_2[] = {
294 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
295 { 0 }
297 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
298 * for a popup window with WS_VISIBLE style set
300 static const struct message WmShowVisiblePopupSeq_3[] = {
301 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
302 { HCBT_ACTIVATE, hook },
303 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
304 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
305 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
306 { WM_NCACTIVATE, sent|wparam, 1 },
307 { WM_ACTIVATE, sent|wparam, 1 },
308 { HCBT_SETFOCUS, hook },
309 { WM_KILLFOCUS, sent|parent },
310 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
311 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
312 { WM_IME_NOTIFY, sent|defwinproc|optional },
313 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
314 { WM_SETFOCUS, sent|defwinproc },
315 { 0 }
317 /* CreateWindow (for child window, not initially visible) */
318 static const struct message WmCreateChildSeq[] = {
319 { HCBT_CREATEWND, hook },
320 { WM_NCCREATE, sent },
321 /* child is inserted into parent's child list after WM_NCCREATE returns */
322 { WM_NCCALCSIZE, sent|wparam, 0 },
323 { WM_CREATE, sent },
324 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
325 { WM_SIZE, sent },
326 { WM_MOVE, sent },
327 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
328 { 0 }
330 /* CreateWindow (for maximized child window, not initially visible) */
331 static const struct message WmCreateMaximizedChildSeq[] = {
332 { HCBT_CREATEWND, hook },
333 { WM_NCCREATE, sent },
334 { WM_NCCALCSIZE, sent|wparam, 0 },
335 { WM_CREATE, sent },
336 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
337 { WM_SIZE, sent },
338 { WM_MOVE, sent },
339 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
340 { WM_GETMINMAXINFO, sent },
341 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
342 { WM_NCCALCSIZE, sent|wparam, 1 },
343 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTMOVE|0x8000 },
344 { WM_SIZE, sent|defwinproc },
345 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
346 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
347 { 0 }
349 /* CreateWindow (for a child window, initially visible) */
350 static const struct message WmCreateVisibleChildSeq[] = {
351 { HCBT_CREATEWND, hook },
352 { WM_NCCREATE, sent },
353 /* child is inserted into parent's child list after WM_NCCREATE returns */
354 { WM_NCCALCSIZE, sent|wparam, 0 },
355 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
356 { WM_CREATE, sent },
357 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
358 { WM_SIZE, sent },
359 { WM_MOVE, sent },
360 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
361 { WM_SHOWWINDOW, sent|wparam, 1 },
362 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER },
363 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
364 { WM_ERASEBKGND, sent|parent|optional },
365 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
366 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
367 { 0 }
369 /* ShowWindow(SW_SHOW) for a not visible child window */
370 static const struct message WmShowChildSeq[] = {
371 { WM_SHOWWINDOW, sent|wparam, 1 },
372 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
373 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
374 { WM_ERASEBKGND, sent|parent|optional },
375 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
376 { 0 }
378 /* ShowWindow(SW_HIDE) for a visible child window */
379 static const struct message WmHideChildSeq[] = {
380 { WM_SHOWWINDOW, sent|wparam, 0 },
381 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
382 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
383 { WM_ERASEBKGND, sent|parent|optional },
384 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
385 { 0 }
387 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
388 * for a not visible child window
390 static const struct message WmShowChildSeq_2[] = {
391 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
392 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
393 { WM_CHILDACTIVATE, sent },
394 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
395 { 0 }
397 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
398 * for a not visible child window
400 static const struct message WmShowChildSeq_3[] = {
401 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
402 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
403 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
404 { 0 }
406 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
407 * for a visible child window with a caption
409 static const struct message WmShowChildSeq_4[] = {
410 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
411 { WM_CHILDACTIVATE, sent },
412 { 0 }
414 /* ShowWindow(SW_SHOW) for child with invisible parent */
415 static const struct message WmShowChildInvisibleParentSeq[] = {
416 { WM_SHOWWINDOW, sent|wparam, 1 },
417 { 0 }
419 /* ShowWindow(SW_HIDE) for child with invisible parent */
420 static const struct message WmHideChildInvisibleParentSeq[] = {
421 { WM_SHOWWINDOW, sent|wparam, 0 },
422 { 0 }
424 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
425 static const struct message WmShowChildInvisibleParentSeq_2[] = {
426 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER },
427 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
428 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
429 { 0 }
431 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
432 static const struct message WmHideChildInvisibleParentSeq_2[] = {
433 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
434 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
435 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
436 { 0 }
438 /* DestroyWindow for a visible child window */
439 static const struct message WmDestroyChildSeq[] = {
440 { HCBT_DESTROYWND, hook },
441 { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
442 { WM_SHOWWINDOW, sent|wparam, 0 },
443 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
444 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
445 { WM_ERASEBKGND, sent|parent|optional },
446 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
447 { HCBT_SETFOCUS, hook }, /* set focus to a parent */
448 { WM_KILLFOCUS, sent },
449 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
450 { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
451 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
452 { WM_SETFOCUS, sent|parent },
453 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
454 { WM_DESTROY, sent },
455 { WM_DESTROY, sent|optional }, /* some other (IME?) window */
456 { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
457 { WM_NCDESTROY, sent },
458 { 0 }
460 /* Moving the mouse in nonclient area */
461 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
462 { WM_NCHITTEST, sent },
463 { WM_SETCURSOR, sent },
464 { WM_NCMOUSEMOVE, posted },
465 { 0 }
467 /* Moving the mouse in client area */
468 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
469 { WM_NCHITTEST, sent },
470 { WM_SETCURSOR, sent },
471 { WM_MOUSEMOVE, posted },
472 { 0 }
474 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
475 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
476 { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
477 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
478 { WM_GETMINMAXINFO, sent|defwinproc },
479 { WM_ENTERSIZEMOVE, sent|defwinproc },
480 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
481 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
482 { WM_MOVE, sent|defwinproc },
483 { WM_EXITSIZEMOVE, sent|defwinproc },
484 { 0 }
486 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
487 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
488 { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
489 { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
490 { WM_GETMINMAXINFO, sent|defwinproc },
491 { WM_ENTERSIZEMOVE, sent|defwinproc },
492 { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
493 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
494 { WM_GETMINMAXINFO, sent|defwinproc },
495 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
496 { WM_NCPAINT, sent|defwinproc|wparam, 1 },
497 { WM_GETTEXT, sent|defwinproc },
498 { WM_ERASEBKGND, sent|defwinproc },
499 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
500 { WM_MOVE, sent|defwinproc },
501 { WM_SIZE, sent|defwinproc },
502 { WM_EXITSIZEMOVE, sent|defwinproc },
503 { 0 }
505 /* Resizing child window with MoveWindow (32) */
506 static const struct message WmResizingChildWithMoveWindowSeq[] = {
507 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
508 { WM_NCCALCSIZE, sent|wparam, 1 },
509 { WM_ERASEBKGND, sent|optional },
510 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
511 { WM_MOVE, sent|defwinproc },
512 { WM_SIZE, sent|defwinproc },
513 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
514 { 0 }
516 /* Clicking on inactive button */
517 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
518 { WM_NCHITTEST, sent },
519 { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
520 { WM_MOUSEACTIVATE, sent },
521 { WM_MOUSEACTIVATE, sent|parent|defwinproc },
522 { WM_SETCURSOR, sent },
523 { WM_SETCURSOR, sent|parent|defwinproc },
524 { WM_LBUTTONDOWN, posted },
525 { WM_KILLFOCUS, posted|parent },
526 { WM_SETFOCUS, posted },
527 { WM_CTLCOLORBTN, posted|parent },
528 { BM_SETSTATE, posted },
529 { WM_CTLCOLORBTN, posted|parent },
530 { WM_LBUTTONUP, posted },
531 { BM_SETSTATE, posted },
532 { WM_CTLCOLORBTN, posted|parent },
533 { WM_COMMAND, posted|parent },
534 { 0 }
536 /* Reparenting a button (16/32) */
537 /* The last child (button) reparented gets topmost for its new parent. */
538 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
539 { WM_SHOWWINDOW, sent|wparam, 0 },
540 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER },
541 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
542 { WM_ERASEBKGND, sent|parent },
543 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER },
544 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOZORDER },
545 { WM_CHILDACTIVATE, sent },
546 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER },
547 { WM_MOVE, sent|defwinproc },
548 { WM_SHOWWINDOW, sent|wparam, 1 },
549 { 0 }
551 /* Creation of a custom dialog (32) */
552 static const struct message WmCreateCustomDialogSeq[] = {
553 { HCBT_CREATEWND, hook },
554 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
555 { WM_GETMINMAXINFO, sent },
556 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
557 { WM_NCCREATE, sent },
558 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
559 { WM_NCCALCSIZE, sent|wparam, 0 },
560 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
561 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
562 { WM_CREATE, sent },
563 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
564 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
565 { WM_SHOWWINDOW, sent|wparam, 1 },
566 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
567 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
568 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
569 { HCBT_ACTIVATE, hook },
570 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
572 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
574 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
575 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
577 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
579 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
580 { WM_NCACTIVATE, sent|wparam, 1 },
581 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
582 { WM_GETTEXT, sent|optional|defwinproc },
583 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
584 { WM_GETICON, sent|optional|defwinproc },
585 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
586 { WM_GETICON, sent|optional|defwinproc },
587 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
588 { WM_GETICON, sent|optional|defwinproc },
589 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
590 { WM_GETTEXT, sent|optional|defwinproc },
591 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
592 { WM_ACTIVATE, sent|wparam, 1 },
593 { WM_KILLFOCUS, sent|parent },
594 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
595 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
596 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
597 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
598 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
599 { WM_IME_NOTIFY, sent|optional|defwinproc },
600 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
601 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
602 { WM_SETFOCUS, sent },
603 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
604 { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
605 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
606 { WM_NCPAINT, sent|wparam, 1 },
607 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
608 { WM_GETTEXT, sent|optional|defwinproc },
609 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
610 { WM_GETICON, sent|optional|defwinproc },
611 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
612 { WM_GETICON, sent|optional|defwinproc },
613 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
614 { WM_GETICON, sent|optional|defwinproc },
615 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
616 { WM_GETTEXT, sent|optional|defwinproc },
617 { WM_ERASEBKGND, sent },
618 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
619 { WM_CTLCOLORDLG, sent|defwinproc },
620 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
621 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
622 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
623 { WM_GETTEXT, sent|optional },
624 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
625 { WM_GETICON, sent|optional },
626 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
627 { WM_GETICON, sent|optional },
628 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
629 { WM_GETICON, sent|optional },
630 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
631 { WM_GETTEXT, sent|optional },
632 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
633 { WM_NCCALCSIZE, sent|optional },
634 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
635 { WM_NCPAINT, sent|optional },
636 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
637 { WM_GETTEXT, sent|optional|defwinproc },
638 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
639 { WM_GETICON, sent|optional|defwinproc },
640 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
641 { WM_GETICON, sent|optional|defwinproc },
642 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
643 { WM_GETICON, sent|optional|defwinproc },
644 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
645 { WM_GETTEXT, sent|optional|defwinproc },
646 { WM_ERASEBKGND, sent|optional },
647 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
648 { WM_CTLCOLORDLG, sent|optional|defwinproc },
649 { WM_SIZE, sent },
650 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
651 { WM_MOVE, sent },
652 { 0 }
654 /* Calling EndDialog for a custom dialog (32) */
655 static const struct message WmEndCustomDialogSeq[] = {
656 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
657 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
658 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
659 { WM_GETTEXT, sent|optional },
660 { WM_GETICON, sent|optional },
661 { WM_GETICON, sent|optional },
662 { WM_GETICON, sent|optional },
663 { HCBT_ACTIVATE, hook },
664 { WM_NCACTIVATE, sent|wparam, 0 },
665 { WM_GETTEXT, sent|optional|defwinproc },
666 { WM_GETICON, sent|optional|defwinproc },
667 { WM_GETICON, sent|optional|defwinproc },
668 { WM_GETICON, sent|optional|defwinproc },
669 { WM_GETTEXT, sent|optional|defwinproc },
670 { WM_ACTIVATE, sent|wparam, 0 },
671 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
672 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
673 { HCBT_SETFOCUS, hook },
674 { WM_KILLFOCUS, sent },
675 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
676 { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
677 { WM_IME_NOTIFY, sent|optional },
678 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
679 { WM_SETFOCUS, sent|parent|defwinproc },
680 { 0 }
682 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
683 static const struct message WmShowCustomDialogSeq[] = {
684 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
685 { WM_SHOWWINDOW, sent|wparam, 1 },
686 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
687 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
688 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
689 { HCBT_ACTIVATE, hook },
690 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
692 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
693 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
695 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
696 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
697 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
698 { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
699 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
700 { WM_NCACTIVATE, sent|wparam, 1 },
701 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
702 { WM_ACTIVATE, sent|wparam, 1 },
704 { WM_KILLFOCUS, sent|parent },
705 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
706 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
707 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
708 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
709 { WM_IME_NOTIFY, sent|optional|defwinproc },
710 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
711 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
712 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
713 { WM_SETFOCUS, sent },
714 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
715 { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
716 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
717 { WM_NCPAINT, sent|wparam, 1 },
718 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
719 { WM_ERASEBKGND, sent },
720 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
721 { WM_CTLCOLORDLG, sent|defwinproc },
723 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
724 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
725 { 0 }
727 /* Creation and destruction of a modal dialog (32) */
728 static const struct message WmModalDialogSeq[] = {
729 { WM_CANCELMODE, sent|parent },
730 { HCBT_SETFOCUS, hook },
731 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
732 { WM_KILLFOCUS, sent|parent },
733 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
734 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
735 { WM_ENABLE, sent|parent|wparam, 0 },
736 { HCBT_CREATEWND, hook },
737 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
738 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
739 { WM_SETFONT, sent },
740 { WM_INITDIALOG, sent },
741 { WM_CHANGEUISTATE, sent|optional },
742 { WM_SHOWWINDOW, sent },
743 { HCBT_ACTIVATE, hook },
744 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
745 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
746 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
747 { WM_NCACTIVATE, sent|wparam, 1 },
748 { WM_GETICON, sent|optional },
749 { WM_GETICON, sent|optional },
750 { WM_GETICON, sent|optional },
751 { WM_GETTEXT, sent|optional },
752 { WM_ACTIVATE, sent|wparam, 1 },
753 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE },
754 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
755 { WM_NCPAINT, sent },
756 { WM_GETICON, sent|optional },
757 { WM_GETICON, sent|optional },
758 { WM_GETICON, sent|optional },
759 { WM_GETTEXT, sent|optional },
760 { WM_ERASEBKGND, sent },
761 { WM_CTLCOLORDLG, sent },
762 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
763 { WM_GETICON, sent|optional },
764 { WM_GETICON, sent|optional },
765 { WM_GETICON, sent|optional },
766 { WM_GETTEXT, sent|optional },
767 { WM_NCCALCSIZE, sent|optional },
768 { WM_NCPAINT, sent|optional },
769 { WM_GETICON, sent|optional },
770 { WM_GETICON, sent|optional },
771 { WM_GETICON, sent|optional },
772 { WM_GETTEXT, sent|optional },
773 { WM_ERASEBKGND, sent|optional },
774 { WM_CTLCOLORDLG, sent|optional },
775 { WM_PAINT, sent|optional },
776 { WM_CTLCOLORBTN, sent },
777 { WM_ENTERIDLE, sent|parent|optional },
778 { WM_ENTERIDLE, sent|parent|optional },
779 { WM_ENTERIDLE, sent|parent|optional },
780 { WM_ENTERIDLE, sent|parent|optional },
781 { WM_ENTERIDLE, sent|parent|optional },
782 { WM_ENTERIDLE, sent|parent|optional },
783 { WM_ENTERIDLE, sent|parent|optional },
784 { WM_ENTERIDLE, sent|parent|optional },
785 { WM_ENTERIDLE, sent|parent|optional },
786 { WM_ENTERIDLE, sent|parent|optional },
787 { WM_ENTERIDLE, sent|parent|optional },
788 { WM_ENTERIDLE, sent|parent|optional },
789 { WM_ENTERIDLE, sent|parent|optional },
790 { WM_ENTERIDLE, sent|parent|optional },
791 { WM_ENTERIDLE, sent|parent|optional },
792 { WM_ENTERIDLE, sent|parent|optional },
793 { WM_ENTERIDLE, sent|parent|optional },
794 { WM_ENTERIDLE, sent|parent|optional },
795 { WM_ENTERIDLE, sent|parent|optional },
796 { WM_ENTERIDLE, sent|parent|optional },
797 { WM_GETICON, sent|parent|optional },
798 { WM_GETICON, sent|parent|optional },
799 { WM_GETICON, sent|parent|optional },
800 { WM_TIMER, sent },
801 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
802 { WM_ENABLE, sent|parent|wparam, 1 },
803 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE },
804 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
805 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
806 { WM_GETICON, sent|optional },
807 { WM_GETICON, sent|optional },
808 { WM_GETICON, sent|optional },
809 { WM_GETTEXT, sent|optional },
810 { HCBT_ACTIVATE, hook },
811 { WM_NCACTIVATE, sent|wparam, 0 },
812 { WM_GETICON, sent|optional },
813 { WM_GETICON, sent|optional },
814 { WM_GETICON, sent|optional },
815 { WM_GETTEXT, sent|optional },
816 { WM_ACTIVATE, sent|wparam, 0 },
817 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
818 { WM_WINDOWPOSCHANGING, sent|optional },
819 { HCBT_SETFOCUS, hook },
820 { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
821 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
822 { WM_SETFOCUS, sent|parent|defwinproc },
823 { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
824 { HCBT_DESTROYWND, hook },
825 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
826 { WM_DESTROY, sent },
827 { WM_NCDESTROY, sent },
828 { 0 }
830 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
831 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
832 /* (inside dialog proc, handling WM_INITDIALOG) */
833 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
834 { WM_NCCALCSIZE, sent },
835 { WM_NCACTIVATE, sent|parent|wparam, 0 },
836 { WM_GETTEXT, sent|defwinproc },
837 { WM_ACTIVATE, sent|parent|wparam, 0 },
838 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
839 { WM_WINDOWPOSCHANGING, sent|parent },
840 { WM_NCACTIVATE, sent|wparam, 1 },
841 { WM_ACTIVATE, sent|wparam, 1 },
842 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
843 { WM_SIZE, sent|defwinproc },
844 /* (setting focus) */
845 { WM_SHOWWINDOW, sent|wparam, 1 },
846 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
847 { WM_NCPAINT, sent },
848 { WM_GETTEXT, sent|defwinproc },
849 { WM_ERASEBKGND, sent },
850 { WM_CTLCOLORDLG, sent|defwinproc },
851 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
852 { WM_PAINT, sent },
853 /* (bunch of WM_CTLCOLOR* for each control) */
854 { WM_PAINT, sent|parent },
855 { WM_ENTERIDLE, sent|parent|wparam, 0 },
856 { WM_SETCURSOR, sent|parent },
857 { 0 }
859 /* SetMenu for NonVisible windows with size change*/
860 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
861 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
862 { WM_NCCALCSIZE, sent|wparam, 1 },
863 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
864 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW },
865 { WM_MOVE, sent|defwinproc },
866 { WM_SIZE, sent|defwinproc },
867 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
868 { WM_GETICON, sent|optional },
869 { WM_GETICON, sent|optional },
870 { WM_GETICON, sent|optional },
871 { WM_GETTEXT, sent|optional },
872 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
873 { 0 }
875 /* SetMenu for NonVisible windows with no size change */
876 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
877 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
878 { WM_NCCALCSIZE, sent|wparam, 1 },
879 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
880 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
881 { 0 }
883 /* SetMenu for Visible windows with size change */
884 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
885 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
886 { WM_NCCALCSIZE, sent|wparam, 1 },
887 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
888 { WM_NCPAINT, sent|wparam, 1 },
889 { WM_GETTEXT, sent|defwinproc|optional },
890 { WM_ERASEBKGND, sent|optional },
891 { WM_ACTIVATE, sent|optional },
892 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
893 { WM_MOVE, sent|defwinproc },
894 { WM_SIZE, sent|defwinproc },
895 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
896 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
897 { WM_NCPAINT, sent|wparam|optional, 1 },
898 { WM_ERASEBKGND, sent|optional },
899 { 0 }
901 /* SetMenu for Visible windows with no size change */
902 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
903 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
904 { WM_NCCALCSIZE, sent|wparam, 1 },
905 { WM_NCPAINT, sent|wparam, 1 },
906 { WM_GETTEXT, sent|defwinproc|optional },
907 { WM_ERASEBKGND, sent|optional },
908 { WM_ACTIVATE, sent|optional },
909 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
910 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
911 { 0 }
913 /* DrawMenuBar for a visible window */
914 static const struct message WmDrawMenuBarSeq[] =
916 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
917 { WM_NCCALCSIZE, sent|wparam, 1 },
918 { WM_NCPAINT, sent|wparam, 1 },
919 { WM_GETTEXT, sent|defwinproc|optional },
920 { WM_ERASEBKGND, sent|optional },
921 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
922 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
923 { 0 }
926 static const struct message WmSetRedrawFalseSeq[] =
928 { WM_SETREDRAW, sent|wparam, 0 },
929 { 0 }
932 static const struct message WmSetRedrawTrueSeq[] =
934 { WM_SETREDRAW, sent|wparam, 1 },
935 { 0 }
938 static const struct message WmEnableWindowSeq[] =
940 { WM_CANCELMODE, sent },
941 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
942 { WM_ENABLE, sent },
943 { 0 }
946 static const struct message WmGetScrollRangeSeq[] =
948 { SBM_GETRANGE, sent },
949 { 0 }
951 static const struct message WmGetScrollInfoSeq[] =
953 { SBM_GETSCROLLINFO, sent },
954 { 0 }
956 static const struct message WmSetScrollRangeSeq[] =
958 /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
959 sends SBM_SETSCROLLINFO.
961 { SBM_SETSCROLLINFO, sent },
962 { 0 }
964 /* SetScrollRange for a window without a non-client area */
965 static const struct message WmSetScrollRangeHSeq_empty[] =
967 { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
968 { 0 }
970 static const struct message WmSetScrollRangeVSeq_empty[] =
972 { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
973 { 0 }
975 static const struct message WmSetScrollRangeHVSeq[] =
977 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER },
978 { WM_NCCALCSIZE, sent|wparam, 1 },
979 { WM_GETTEXT, sent|defwinproc|optional },
980 { WM_ERASEBKGND, sent|optional },
981 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
982 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
983 { 0 }
985 /* SetScrollRange for a window with a non-client area */
986 static const struct message WmSetScrollRangeHV_NC_Seq[] =
988 { WM_WINDOWPOSCHANGING, sent, /*|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER*/ },
989 { WM_NCCALCSIZE, sent|wparam, 1 },
990 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
991 { WM_NCPAINT, sent|optional },
992 { WM_GETTEXT, sent|defwinproc|optional },
993 { WM_GETICON, sent|optional|defwinproc },
994 { WM_GETICON, sent|optional|defwinproc },
995 { WM_GETICON, sent|optional|defwinproc },
996 { WM_GETTEXT, sent|defwinproc|optional },
997 { WM_ERASEBKGND, sent|optional },
998 { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
999 { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|0x1000*/ },
1000 { WM_SIZE, sent|defwinproc },
1001 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1002 { WM_GETTEXT, sent|optional },
1003 { WM_GETICON, sent|optional },
1004 { WM_GETICON, sent|optional },
1005 { WM_GETICON, sent|optional },
1006 { WM_GETTEXT, sent|optional },
1007 { WM_GETICON, sent|optional },
1008 { WM_GETICON, sent|optional },
1009 { WM_GETICON, sent|optional },
1010 { WM_GETTEXT, sent|optional },
1011 { WM_GETICON, sent|optional },
1012 { WM_GETICON, sent|optional },
1013 { WM_GETICON, sent|optional },
1014 { WM_GETTEXT, sent|optional },
1015 { 0 }
1017 /* test if we receive the right sequence of messages */
1018 /* after calling ShowWindow( SW_SHOWNA) */
1019 static const struct message WmSHOWNAChildInvisParInvis[] = {
1020 { WM_SHOWWINDOW, sent|wparam, 1 },
1021 { 0 }
1023 static const struct message WmSHOWNAChildVisParInvis[] = {
1024 { WM_SHOWWINDOW, sent|wparam, 1 },
1025 { 0 }
1027 static const struct message WmSHOWNAChildVisParVis[] = {
1028 { WM_SHOWWINDOW, sent|wparam, 1 },
1029 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER },
1030 { 0 }
1032 static const struct message WmSHOWNAChildInvisParVis[] = {
1033 { WM_SHOWWINDOW, sent|wparam, 1 },
1034 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER},
1035 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1036 { WM_ERASEBKGND, sent|optional },
1037 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
1038 { 0 }
1040 static const struct message WmSHOWNATopVisible[] = {
1041 { WM_SHOWWINDOW, sent|wparam, 1 },
1042 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1043 { 0 }
1045 static const struct message WmSHOWNATopInvisible[] = {
1046 { WM_SHOWWINDOW, sent|wparam, 1 },
1047 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1048 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1049 { WM_NCPAINT, sent|wparam, 1 },
1050 { WM_GETICON, sent|optional },
1051 { WM_GETICON, sent|optional },
1052 { WM_GETICON, sent|optional },
1053 { WM_GETTEXT, sent|defwinproc|optional },
1054 { WM_ERASEBKGND, sent|optional },
1055 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1056 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1057 { WM_NCPAINT, sent|wparam|optional, 1 },
1058 { WM_ERASEBKGND, sent|optional },
1059 { WM_SIZE, sent },
1060 { WM_MOVE, sent },
1061 { 0 }
1064 static int after_end_dialog;
1065 static int sequence_cnt, sequence_size;
1066 static struct message* sequence;
1067 static int log_all_parent_messages;
1069 static void add_message(const struct message *msg)
1071 if (!sequence)
1073 sequence_size = 10;
1074 sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof (struct message) );
1076 if (sequence_cnt == sequence_size)
1078 sequence_size *= 2;
1079 sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof (struct message) );
1081 assert(sequence);
1083 sequence[sequence_cnt].message = msg->message;
1084 sequence[sequence_cnt].flags = msg->flags;
1085 sequence[sequence_cnt].wParam = msg->wParam;
1086 sequence[sequence_cnt].lParam = msg->lParam;
1088 sequence_cnt++;
1091 static void flush_sequence()
1093 HeapFree(GetProcessHeap(), 0, sequence);
1094 sequence = 0;
1095 sequence_cnt = sequence_size = 0;
1098 #define ok_sequence( exp, contx, todo) \
1099 ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
1102 static void ok_sequence_(const struct message *expected, const char *context, int todo,
1103 const char *file, int line)
1105 static const struct message end_of_sequence = { 0, 0, 0, 0 };
1106 const struct message *actual;
1107 int failcount = 0;
1109 add_message(&end_of_sequence);
1111 actual = sequence;
1113 while (expected->message && actual->message)
1115 trace_( file, line)("expected %04x - actual %04x\n", expected->message, actual->message);
1117 if (expected->message == actual->message)
1119 if (expected->flags & wparam)
1121 if (expected->wParam != actual->wParam && todo)
1123 todo_wine {
1124 failcount ++;
1125 ok_( file, line) (FALSE,
1126 "%s: in msg 0x%04x expecting wParam 0x%x got 0x%x\n",
1127 context, expected->message, expected->wParam, actual->wParam);
1130 else
1131 ok_( file, line) (expected->wParam == actual->wParam,
1132 "%s: in msg 0x%04x expecting wParam 0x%x got 0x%x\n",
1133 context, expected->message, expected->wParam, actual->wParam);
1135 if (expected->flags & lparam)
1136 ok_( file, line) (expected->lParam == actual->lParam,
1137 "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1138 context, expected->message, expected->lParam, actual->lParam);
1139 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
1140 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1141 context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1142 ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
1143 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
1144 context, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
1145 ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
1146 "%s: the msg 0x%04x should have been %s\n",
1147 context, expected->message, (expected->flags & posted) ? "posted" : "sent");
1148 ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
1149 "%s: the msg 0x%04x was expected in %s\n",
1150 context, expected->message, (expected->flags & parent) ? "parent" : "child");
1151 ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
1152 "%s: the msg 0x%04x should have been sent by a hook\n",
1153 context, expected->message);
1154 ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
1155 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
1156 context, expected->message);
1157 expected++;
1158 actual++;
1160 /* silently drop winevent messages if there is no support for them */
1161 else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1162 expected++;
1163 else if (todo)
1165 failcount++;
1166 todo_wine {
1167 ok_( file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
1168 context, expected->message, actual->message);
1170 flush_sequence();
1171 return;
1173 else
1175 ok_( file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
1176 context, expected->message, actual->message);
1177 expected++;
1178 actual++;
1182 /* skip all optional trailing messages */
1183 while (expected->message && ((expected->flags & optional) ||
1184 ((expected->flags & winevent_hook) && !hEvent_hook)))
1185 expected++;
1187 if (todo)
1189 todo_wine {
1190 if (expected->message || actual->message) {
1191 failcount++;
1192 ok_( file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
1193 context, expected->message, actual->message);
1197 else
1199 if (expected->message || actual->message)
1200 ok_( file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
1201 context, expected->message, actual->message);
1203 if( todo && !failcount) /* succeeded yet marked todo */
1204 todo_wine {
1205 ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
1208 flush_sequence();
1211 /******************************** MDI test **********************************/
1213 /* CreateWindow for MDI frame window, initially visible */
1214 static const struct message WmCreateMDIframeSeq[] = {
1215 { HCBT_CREATEWND, hook },
1216 { WM_GETMINMAXINFO, sent },
1217 { WM_NCCREATE, sent },
1218 { WM_NCCALCSIZE, sent|wparam, 0 },
1219 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1220 { WM_CREATE, sent },
1221 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1222 { WM_SHOWWINDOW, sent|wparam, 1 },
1223 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1224 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1225 { HCBT_ACTIVATE, hook },
1226 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1227 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1228 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1229 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* Win9x */
1230 { WM_ACTIVATEAPP, sent|wparam, 1 },
1231 { WM_NCACTIVATE, sent|wparam, 1 },
1232 { WM_GETTEXT, sent|defwinproc|optional },
1233 { WM_GETICON, sent|defwinproc|optional },
1234 { WM_GETICON, sent|defwinproc|optional },
1235 { WM_ACTIVATE, sent|wparam, 1 },
1236 { HCBT_SETFOCUS, hook },
1237 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1238 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1239 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
1240 /* Win9x adds SWP_NOZORDER below */
1241 { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
1242 { WM_SIZE, sent },
1243 { WM_MOVE, sent },
1244 { 0 }
1246 /* DestroyWindow for MDI frame window, initially visible */
1247 static const struct message WmDestroyMDIframeSeq[] = {
1248 { HCBT_DESTROYWND, hook },
1249 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1250 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1251 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1252 { WM_NCACTIVATE, sent|wparam, 0 },
1253 { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
1254 { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
1255 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
1256 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1257 { WM_DESTROY, sent },
1258 { WM_NCDESTROY, sent },
1259 { 0 }
1261 /* CreateWindow for MDI client window, initially visible */
1262 static const struct message WmCreateMDIclientSeq[] = {
1263 { HCBT_CREATEWND, hook },
1264 { WM_NCCREATE, sent },
1265 { WM_NCCALCSIZE, sent|wparam, 0 },
1266 { WM_CREATE, sent },
1267 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1268 { WM_SIZE, sent },
1269 { WM_MOVE, sent },
1270 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
1271 { WM_SHOWWINDOW, sent|wparam, 1 },
1272 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE|SWP_NOMOVE },
1273 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1274 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1275 { 0 }
1277 /* DestroyWindow for MDI client window, initially visible */
1278 static const struct message WmDestroyMDIclientSeq[] = {
1279 { HCBT_DESTROYWND, hook },
1280 { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
1281 { WM_SHOWWINDOW, sent|wparam, 0 },
1282 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1283 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1284 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1285 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1286 { WM_DESTROY, sent },
1287 { WM_NCDESTROY, sent },
1288 { 0 }
1290 /* CreateWindow for MDI child window, initially visible */
1291 static const struct message WmCreateMDIchildVisibleSeq[] = {
1292 { HCBT_CREATEWND, hook },
1293 { WM_NCCREATE, sent },
1294 { WM_NCCALCSIZE, sent|wparam, 0 },
1295 { WM_CREATE, sent },
1296 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1297 { WM_SIZE, sent },
1298 { WM_MOVE, sent },
1299 /* Win2k sends wparam set to
1300 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1301 * while Win9x doesn't bother to set child window id according to
1302 * CLIENTCREATESTRUCT.idFirstChild
1304 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1305 { WM_SHOWWINDOW, sent|wparam, 1 },
1306 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1307 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1308 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1309 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1310 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1311 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1312 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1314 /* Win9x: message sequence terminates here. */
1316 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1317 { HCBT_SETFOCUS, hook }, /* in MDI client */
1318 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1319 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1320 { WM_SETFOCUS, sent }, /* in MDI client */
1321 { HCBT_SETFOCUS, hook },
1322 { WM_KILLFOCUS, sent }, /* in MDI client */
1323 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1324 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1325 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1326 { WM_SETFOCUS, sent|defwinproc },
1327 { WM_MDIACTIVATE, sent|defwinproc },
1328 { 0 }
1330 /* DestroyWindow for MDI child window, initially visible */
1331 static const struct message WmDestroyMDIchildVisibleSeq[] = {
1332 { HCBT_DESTROYWND, hook },
1333 /* Win2k sends wparam set to
1334 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1335 * while Win9x doesn't bother to set child window id according to
1336 * CLIENTCREATESTRUCT.idFirstChild
1338 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1339 { WM_SHOWWINDOW, sent|wparam, 0 },
1340 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1341 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1342 { WM_ERASEBKGND, sent|parent|optional },
1343 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1345 /* { WM_DESTROY, sent }
1346 * Win9x: message sequence terminates here.
1349 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1350 { WM_KILLFOCUS, sent },
1351 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1352 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1353 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1354 { WM_SETFOCUS, sent }, /* in MDI client */
1356 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1357 { WM_KILLFOCUS, sent }, /* in MDI client */
1358 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1359 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1360 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1361 { WM_SETFOCUS, sent }, /* in MDI client */
1363 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1365 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1366 { WM_KILLFOCUS, sent },
1367 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1368 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1369 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1370 { WM_SETFOCUS, sent }, /* in MDI client */
1372 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1373 { WM_KILLFOCUS, sent }, /* in MDI client */
1374 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1375 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1376 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1377 { WM_SETFOCUS, sent }, /* in MDI client */
1379 { WM_DESTROY, sent },
1381 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1382 { WM_KILLFOCUS, sent },
1383 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1384 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1385 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1386 { WM_SETFOCUS, sent }, /* in MDI client */
1388 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1389 { WM_KILLFOCUS, sent }, /* in MDI client */
1390 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1391 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1392 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1393 { WM_SETFOCUS, sent }, /* in MDI client */
1395 { WM_NCDESTROY, sent },
1396 { 0 }
1398 /* CreateWindow for MDI child window, initially invisible */
1399 static const struct message WmCreateMDIchildInvisibleSeq[] = {
1400 { HCBT_CREATEWND, hook },
1401 { WM_NCCREATE, sent },
1402 { WM_NCCALCSIZE, sent|wparam, 0 },
1403 { WM_CREATE, sent },
1404 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1405 { WM_SIZE, sent },
1406 { WM_MOVE, sent },
1407 /* Win2k sends wparam set to
1408 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1409 * while Win9x doesn't bother to set child window id according to
1410 * CLIENTCREATESTRUCT.idFirstChild
1412 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1413 { 0 }
1415 /* DestroyWindow for MDI child window, initially invisible */
1416 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
1417 { HCBT_DESTROYWND, hook },
1418 /* Win2k sends wparam set to
1419 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1420 * while Win9x doesn't bother to set child window id according to
1421 * CLIENTCREATESTRUCT.idFirstChild
1423 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1424 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1425 { WM_DESTROY, sent },
1426 { WM_NCDESTROY, sent },
1427 { 0 }
1429 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
1430 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
1431 { HCBT_CREATEWND, hook },
1432 { WM_NCCREATE, sent },
1433 { WM_NCCALCSIZE, sent|wparam, 0 },
1434 { WM_CREATE, sent },
1435 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1436 { WM_SIZE, sent },
1437 { WM_MOVE, sent },
1438 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1439 { WM_GETMINMAXINFO, sent },
1440 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
1441 { WM_NCCALCSIZE, sent|wparam, 1 },
1442 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1443 { WM_SIZE, sent|defwinproc },
1444 /* in MDI frame */
1445 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1446 { WM_NCCALCSIZE, sent|wparam, 1 },
1447 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1448 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1449 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1450 /* Win2k sends wparam set to
1451 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1452 * while Win9x doesn't bother to set child window id according to
1453 * CLIENTCREATESTRUCT.idFirstChild
1455 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1456 { WM_SHOWWINDOW, sent|wparam, 1 },
1457 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1458 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1459 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1460 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1461 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1462 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1463 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1465 /* Win9x: message sequence terminates here. */
1467 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1468 { HCBT_SETFOCUS, hook }, /* in MDI client */
1469 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1470 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1471 { WM_SETFOCUS, sent }, /* in MDI client */
1472 { HCBT_SETFOCUS, hook },
1473 { WM_KILLFOCUS, sent }, /* in MDI client */
1474 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1475 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1476 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1477 { WM_SETFOCUS, sent|defwinproc },
1478 { WM_MDIACTIVATE, sent|defwinproc },
1479 /* in MDI frame */
1480 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1481 { WM_NCCALCSIZE, sent|wparam, 1 },
1482 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1483 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1484 { 0 }
1486 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
1487 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
1488 /* restore the 1st MDI child */
1489 { WM_SETREDRAW, sent|wparam, 0 },
1490 { HCBT_MINMAX, hook },
1491 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
1492 { WM_NCCALCSIZE, sent|wparam, 1 },
1493 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1494 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1495 { WM_SIZE, sent|defwinproc },
1496 /* in MDI frame */
1497 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1498 { WM_NCCALCSIZE, sent|wparam, 1 },
1499 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1500 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1501 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1502 { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
1503 /* create the 2nd MDI child */
1504 { HCBT_CREATEWND, hook },
1505 { WM_NCCREATE, sent },
1506 { WM_NCCALCSIZE, sent|wparam, 0 },
1507 { WM_CREATE, sent },
1508 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1509 { WM_SIZE, sent },
1510 { WM_MOVE, sent },
1511 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1512 { WM_GETMINMAXINFO, sent },
1513 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
1514 { WM_NCCALCSIZE, sent|wparam, 1 },
1515 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1516 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1517 { WM_SIZE, sent|defwinproc },
1518 /* in MDI frame */
1519 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1520 { WM_NCCALCSIZE, sent|wparam, 1 },
1521 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1522 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1523 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1524 /* Win2k sends wparam set to
1525 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1526 * while Win9x doesn't bother to set child window id according to
1527 * CLIENTCREATESTRUCT.idFirstChild
1529 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1530 { WM_SHOWWINDOW, sent|wparam, 1 },
1531 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1532 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1533 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1534 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1535 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1536 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1538 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
1539 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
1541 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1543 /* Win9x: message sequence terminates here. */
1545 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1546 { HCBT_SETFOCUS, hook },
1547 { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
1548 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
1549 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1550 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1551 { WM_SETFOCUS, sent }, /* in MDI client */
1552 { HCBT_SETFOCUS, hook },
1553 { WM_KILLFOCUS, sent }, /* in MDI client */
1554 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1555 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1556 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1557 { WM_SETFOCUS, sent|defwinproc },
1559 { WM_MDIACTIVATE, sent|defwinproc },
1560 /* in MDI frame */
1561 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1562 { WM_NCCALCSIZE, sent|wparam, 1 },
1563 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1564 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1565 { 0 }
1567 /* WM_MDICREATE MDI child window, initially visible and maximized */
1568 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
1569 { WM_MDICREATE, sent },
1570 { HCBT_CREATEWND, hook },
1571 { WM_NCCREATE, sent },
1572 { WM_NCCALCSIZE, sent|wparam, 0 },
1573 { WM_CREATE, sent },
1574 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1575 { WM_SIZE, sent },
1576 { WM_MOVE, sent },
1577 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1578 { WM_GETMINMAXINFO, sent },
1579 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
1580 { WM_NCCALCSIZE, sent|wparam, 1 },
1581 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1582 { WM_SIZE, sent|defwinproc },
1584 /* in MDI frame */
1585 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1586 { WM_NCCALCSIZE, sent|wparam, 1 },
1587 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1588 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1589 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1591 /* Win2k sends wparam set to
1592 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1593 * while Win9x doesn't bother to set child window id according to
1594 * CLIENTCREATESTRUCT.idFirstChild
1596 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1597 { WM_SHOWWINDOW, sent|wparam, 1 },
1598 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1600 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1602 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1603 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1604 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1606 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1607 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1609 /* Win9x: message sequence terminates here. */
1611 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1612 { HCBT_SETFOCUS, hook }, /* in MDI client */
1613 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1614 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1615 { WM_SETFOCUS, sent }, /* in MDI client */
1616 { HCBT_SETFOCUS, hook },
1617 { WM_KILLFOCUS, sent }, /* in MDI client */
1618 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1619 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1620 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1621 { WM_SETFOCUS, sent|defwinproc },
1623 { WM_MDIACTIVATE, sent|defwinproc },
1625 /* in MDI child */
1626 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1627 { WM_NCCALCSIZE, sent|wparam, 1 },
1628 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1629 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1631 /* in MDI frame */
1632 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1633 { WM_NCCALCSIZE, sent|wparam, 1 },
1634 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1635 { WM_MOVE, sent|defwinproc },
1636 { WM_SIZE, sent|defwinproc },
1638 /* in MDI client */
1639 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
1640 { WM_NCCALCSIZE, sent|wparam, 1 },
1641 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
1642 { WM_SIZE, sent },
1644 /* in MDI child */
1645 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
1646 { WM_NCCALCSIZE, sent|wparam, 1 },
1647 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
1648 { WM_SIZE, sent|defwinproc },
1650 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1651 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
1652 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1654 { 0 }
1656 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
1657 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
1658 { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
1659 { HCBT_SYSCOMMAND, hook },
1660 { WM_CLOSE, sent|defwinproc },
1661 { WM_MDIDESTROY, sent }, /* in MDI client */
1663 /* bring the 1st MDI child to top */
1664 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
1665 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
1667 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1669 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
1670 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
1671 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
1673 /* maximize the 1st MDI child */
1674 { HCBT_MINMAX, hook },
1675 { WM_GETMINMAXINFO, sent|defwinproc },
1676 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|0x8000 },
1677 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1678 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
1679 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1680 { WM_SIZE, sent|defwinproc },
1682 /* restore the 2nd MDI child */
1683 { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
1684 { HCBT_MINMAX, hook },
1685 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOZORDER|0x8000 },
1686 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1688 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1690 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1691 { WM_SIZE, sent|defwinproc },
1693 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1695 { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
1696 /* in MDI frame */
1697 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1698 { WM_NCCALCSIZE, sent|wparam, 1 },
1699 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1700 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1701 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1703 /* bring the 1st MDI child to top */
1704 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1705 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1706 { HCBT_SETFOCUS, hook },
1707 { WM_KILLFOCUS, sent|defwinproc },
1708 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
1709 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1710 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1711 { WM_SETFOCUS, sent }, /* in MDI client */
1712 { HCBT_SETFOCUS, hook },
1713 { WM_KILLFOCUS, sent }, /* in MDI client */
1714 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1715 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1716 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1717 { WM_SETFOCUS, sent|defwinproc },
1718 { WM_MDIACTIVATE, sent|defwinproc },
1719 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1721 /* apparently ShowWindow(SW_SHOW) on an MDI client */
1722 { WM_SHOWWINDOW, sent|wparam, 1 },
1723 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1724 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1725 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1726 { WM_MDIREFRESHMENU, sent },
1728 { HCBT_DESTROYWND, hook },
1729 /* Win2k sends wparam set to
1730 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1731 * while Win9x doesn't bother to set child window id according to
1732 * CLIENTCREATESTRUCT.idFirstChild
1734 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1735 { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
1736 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1737 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1738 { WM_ERASEBKGND, sent|parent|optional },
1739 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1741 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1742 { WM_DESTROY, sent|defwinproc },
1743 { WM_NCDESTROY, sent|defwinproc },
1744 { 0 }
1746 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
1747 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
1748 { WM_MDIDESTROY, sent }, /* in MDI client */
1749 { WM_SHOWWINDOW, sent|wparam, 0 },
1750 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1751 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1752 { WM_ERASEBKGND, sent|parent|optional },
1753 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1755 { HCBT_SETFOCUS, hook },
1756 { WM_KILLFOCUS, sent },
1757 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1758 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1759 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1760 { WM_SETFOCUS, sent }, /* in MDI client */
1761 { HCBT_SETFOCUS, hook },
1762 { WM_KILLFOCUS, sent }, /* in MDI client */
1763 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1764 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1765 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1766 { WM_SETFOCUS, sent },
1768 /* in MDI child */
1769 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1770 { WM_NCCALCSIZE, sent|wparam, 1 },
1771 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1772 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1774 /* in MDI frame */
1775 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1776 { WM_NCCALCSIZE, sent|wparam, 1 },
1777 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1778 { WM_MOVE, sent|defwinproc },
1779 { WM_SIZE, sent|defwinproc },
1781 /* in MDI client */
1782 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
1783 { WM_NCCALCSIZE, sent|wparam, 1 },
1784 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
1785 { WM_SIZE, sent },
1787 /* in MDI child */
1788 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
1789 { WM_NCCALCSIZE, sent|wparam, 1 },
1790 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
1791 { WM_SIZE, sent|defwinproc },
1793 /* in MDI child */
1794 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1795 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
1796 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1797 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1799 /* in MDI frame */
1800 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1801 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
1802 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1803 { WM_MOVE, sent|defwinproc },
1804 { WM_SIZE, sent|defwinproc },
1806 /* in MDI client */
1807 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
1808 { WM_NCCALCSIZE, sent|wparam, 1 },
1809 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
1810 { WM_SIZE, sent },
1812 /* in MDI child */
1813 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOZORDER },
1814 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
1815 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
1816 { WM_SIZE, sent|defwinproc },
1817 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1818 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
1819 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1820 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1821 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
1822 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1824 /* in MDI frame */
1825 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1826 { WM_NCCALCSIZE, sent|wparam, 1 },
1827 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1828 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1830 { WM_NCACTIVATE, sent|wparam, 0 },
1831 { WM_MDIACTIVATE, sent },
1833 { HCBT_MINMAX, hook },
1834 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|0x8000 },
1835 { WM_NCCALCSIZE, sent|wparam, 1 },
1837 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1839 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1840 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE|0x8000 },
1841 { WM_SIZE, sent|defwinproc },
1843 /* in MDI child */
1844 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1845 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
1846 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1847 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1849 /* in MDI frame */
1850 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1851 { WM_NCCALCSIZE, sent|wparam, 1 },
1852 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1853 { WM_MOVE, sent|defwinproc },
1854 { WM_SIZE, sent|defwinproc },
1856 /* in MDI client */
1857 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
1858 { WM_NCCALCSIZE, sent|wparam, 1 },
1859 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
1860 { WM_SIZE, sent },
1861 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1862 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
1863 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1865 { HCBT_SETFOCUS, hook },
1866 { WM_KILLFOCUS, sent },
1867 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1868 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1869 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1870 { WM_SETFOCUS, sent }, /* in MDI client */
1872 { WM_MDIREFRESHMENU, sent }, /* in MDI client */
1874 { HCBT_DESTROYWND, hook },
1875 /* Win2k sends wparam set to
1876 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1877 * while Win9x doesn't bother to set child window id according to
1878 * CLIENTCREATESTRUCT.idFirstChild
1880 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1882 { WM_SHOWWINDOW, sent|wparam, 0 },
1883 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1884 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1885 { WM_ERASEBKGND, sent|parent|optional },
1886 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1888 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1889 { WM_DESTROY, sent },
1890 { WM_NCDESTROY, sent },
1891 { 0 }
1893 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
1894 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
1895 { HCBT_MINMAX, hook },
1896 { WM_GETMINMAXINFO, sent },
1897 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
1898 { WM_NCCALCSIZE, sent|wparam, 1 },
1899 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1900 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1902 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1903 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1904 { HCBT_SETFOCUS, hook },
1905 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1906 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1907 { WM_SETFOCUS, sent }, /* in MDI client */
1908 { HCBT_SETFOCUS, hook },
1909 { WM_KILLFOCUS, sent }, /* in MDI client */
1910 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1911 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1912 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1913 { WM_SETFOCUS, sent|defwinproc },
1914 { WM_MDIACTIVATE, sent|defwinproc },
1915 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1916 { WM_SIZE, sent|defwinproc },
1917 /* in MDI frame */
1918 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1919 { WM_NCCALCSIZE, sent|wparam, 1 },
1920 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1921 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1922 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1923 { 0 }
1925 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
1926 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
1927 { HCBT_MINMAX, hook },
1928 { WM_GETMINMAXINFO, sent },
1929 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
1930 { WM_NCCALCSIZE, sent|wparam, 1 },
1931 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1932 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1933 { WM_SIZE, sent|defwinproc },
1934 /* in MDI frame */
1935 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1936 { WM_NCCALCSIZE, sent|wparam, 1 },
1937 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1938 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1939 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1940 { 0 }
1942 /* ShowWindow(SW_RESTORE) for a visible MDI child window */
1943 static const struct message WmRestoreMDIchildVisibleSeq[] = {
1944 { HCBT_MINMAX, hook },
1945 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
1946 { WM_NCCALCSIZE, sent|wparam, 1 },
1947 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1948 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1949 { WM_SIZE, sent|defwinproc },
1950 /* in MDI frame */
1951 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1952 { WM_NCCALCSIZE, sent|wparam, 1 },
1953 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1954 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1955 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1956 { 0 }
1958 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
1959 static const struct message WmRestoreMDIchildInisibleSeq[] = {
1960 { HCBT_MINMAX, hook },
1961 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
1962 { WM_NCCALCSIZE, sent|wparam, 1 },
1963 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1964 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1965 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1966 { WM_SIZE, sent|defwinproc },
1967 /* in MDI frame */
1968 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1969 { WM_NCCALCSIZE, sent|wparam, 1 },
1970 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1971 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1972 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1973 { 0 }
1976 static HWND mdi_client;
1977 static WNDPROC old_mdi_client_proc;
1979 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
1981 struct message msg;
1983 /* do not log painting messages */
1984 if (message != WM_PAINT &&
1985 message != WM_ERASEBKGND &&
1986 message != WM_NCPAINT &&
1987 message != WM_NCHITTEST &&
1988 message != WM_GETTEXT &&
1989 message != WM_MDIGETACTIVE &&
1990 message != WM_DEVICECHANGE)
1992 trace("mdi client: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
1994 switch (message)
1996 case WM_WINDOWPOSCHANGING:
1997 case WM_WINDOWPOSCHANGED:
1999 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2001 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2002 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2003 winpos->hwnd, winpos->hwndInsertAfter,
2004 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2006 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2007 * in the high word for internal purposes
2009 wParam = winpos->flags & 0xffff;
2010 break;
2014 msg.message = message;
2015 msg.flags = sent|wparam|lparam;
2016 msg.wParam = wParam;
2017 msg.lParam = lParam;
2018 add_message(&msg);
2021 return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
2024 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2026 static long defwndproc_counter = 0;
2027 LRESULT ret;
2028 struct message msg;
2030 /* do not log painting messages */
2031 if (message != WM_PAINT &&
2032 message != WM_ERASEBKGND &&
2033 message != WM_NCPAINT &&
2034 message != WM_NCHITTEST &&
2035 message != WM_GETTEXT &&
2036 message != WM_DEVICECHANGE)
2038 trace("mdi child: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
2040 switch (message)
2042 case WM_WINDOWPOSCHANGING:
2043 case WM_WINDOWPOSCHANGED:
2045 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2047 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2048 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2049 winpos->hwnd, winpos->hwndInsertAfter,
2050 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2052 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2053 * in the high word for internal purposes
2055 wParam = winpos->flags & 0xffff;
2056 break;
2059 case WM_MDIACTIVATE:
2061 HWND active, client = GetParent(hwnd);
2063 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
2065 if (hwnd == (HWND)lParam) /* if we are being activated */
2066 ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
2067 else
2068 ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
2069 break;
2073 msg.message = message;
2074 msg.flags = sent|wparam|lparam;
2075 if (defwndproc_counter) msg.flags |= defwinproc;
2076 msg.wParam = wParam;
2077 msg.lParam = lParam;
2078 add_message(&msg);
2081 defwndproc_counter++;
2082 ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
2083 defwndproc_counter--;
2085 return ret;
2088 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2090 static long defwndproc_counter = 0;
2091 LRESULT ret;
2092 struct message msg;
2094 /* do not log painting messages */
2095 if (message != WM_PAINT &&
2096 message != WM_ERASEBKGND &&
2097 message != WM_NCPAINT &&
2098 message != WM_NCHITTEST &&
2099 message != WM_GETTEXT &&
2100 message != WM_DEVICECHANGE)
2102 trace("mdi frame: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
2104 switch (message)
2106 case WM_WINDOWPOSCHANGING:
2107 case WM_WINDOWPOSCHANGED:
2109 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2111 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2112 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2113 winpos->hwnd, winpos->hwndInsertAfter,
2114 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2116 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2117 * in the high word for internal purposes
2119 wParam = winpos->flags & 0xffff;
2120 break;
2124 msg.message = message;
2125 msg.flags = sent|wparam|lparam;
2126 if (defwndproc_counter) msg.flags |= defwinproc;
2127 msg.wParam = wParam;
2128 msg.lParam = lParam;
2129 add_message(&msg);
2132 defwndproc_counter++;
2133 ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
2134 defwndproc_counter--;
2136 return ret;
2139 static BOOL mdi_RegisterWindowClasses(void)
2141 WNDCLASSA cls;
2143 cls.style = 0;
2144 cls.lpfnWndProc = mdi_frame_wnd_proc;
2145 cls.cbClsExtra = 0;
2146 cls.cbWndExtra = 0;
2147 cls.hInstance = GetModuleHandleA(0);
2148 cls.hIcon = 0;
2149 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
2150 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
2151 cls.lpszMenuName = NULL;
2152 cls.lpszClassName = "MDI_frame_class";
2153 if (!RegisterClassA(&cls)) return FALSE;
2155 cls.lpfnWndProc = mdi_child_wnd_proc;
2156 cls.lpszClassName = "MDI_child_class";
2157 if (!RegisterClassA(&cls)) return FALSE;
2159 if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
2160 old_mdi_client_proc = cls.lpfnWndProc;
2161 cls.hInstance = GetModuleHandleA(0);
2162 cls.lpfnWndProc = mdi_client_hook_proc;
2163 cls.lpszClassName = "MDI_client_class";
2164 if (!RegisterClassA(&cls)) assert(0);
2166 return TRUE;
2169 static void test_mdi_messages(void)
2171 MDICREATESTRUCTA mdi_cs;
2172 CLIENTCREATESTRUCT client_cs;
2173 HWND mdi_frame, mdi_child, mdi_child2, active_child;
2174 BOOL zoomed;
2175 HMENU hMenu = CreateMenu();
2177 assert(mdi_RegisterWindowClasses());
2179 flush_sequence();
2181 trace("creating MDI frame window\n");
2182 mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
2183 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2184 WS_MAXIMIZEBOX | WS_VISIBLE,
2185 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
2186 GetDesktopWindow(), hMenu,
2187 GetModuleHandleA(0), NULL);
2188 assert(mdi_frame);
2189 ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", TRUE);
2191 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2192 ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
2194 trace("creating MDI client window\n");
2195 client_cs.hWindowMenu = 0;
2196 client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
2197 mdi_client = CreateWindowExA(0, "MDI_client_class",
2198 NULL,
2199 WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
2200 0, 0, 0, 0,
2201 mdi_frame, 0, GetModuleHandleA(0), &client_cs);
2202 assert(mdi_client);
2203 ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
2205 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2206 ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
2208 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2209 ok(!active_child, "wrong active MDI child %p\n", active_child);
2210 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2212 SetFocus(0);
2213 flush_sequence();
2215 trace("creating invisible MDI child window\n");
2216 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2217 WS_CHILD,
2218 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2219 mdi_client, 0, GetModuleHandleA(0), NULL);
2220 assert(mdi_child);
2222 flush_sequence();
2223 ShowWindow(mdi_child, SW_SHOWNORMAL);
2224 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
2226 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2227 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
2229 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2230 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2232 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2233 ok(!active_child, "wrong active MDI child %p\n", active_child);
2234 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2236 ShowWindow(mdi_child, SW_HIDE);
2237 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
2238 flush_sequence();
2240 ShowWindow(mdi_child, SW_SHOW);
2241 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
2243 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2244 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
2246 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2247 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2249 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2250 ok(!active_child, "wrong active MDI child %p\n", active_child);
2251 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2253 DestroyWindow(mdi_child);
2254 flush_sequence();
2256 trace("creating visible MDI child window\n");
2257 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2258 WS_CHILD | WS_VISIBLE,
2259 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2260 mdi_client, 0, GetModuleHandleA(0), NULL);
2261 assert(mdi_child);
2262 ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
2264 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2265 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
2267 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2268 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
2270 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2271 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
2272 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2273 flush_sequence();
2275 DestroyWindow(mdi_child);
2276 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
2278 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2279 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2281 /* Win2k: MDI client still returns a just destroyed child as active
2282 * Win9x: MDI client returns 0
2284 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2285 ok(active_child == mdi_child || /* win2k */
2286 !active_child, /* win9x */
2287 "wrong active MDI child %p\n", active_child);
2288 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2290 flush_sequence();
2292 trace("creating invisible MDI child window\n");
2293 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2294 WS_CHILD,
2295 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2296 mdi_client, 0, GetModuleHandleA(0), NULL);
2297 assert(mdi_child2);
2298 ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
2300 ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
2301 ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
2303 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2304 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2306 /* Win2k: MDI client still returns a just destroyed child as active
2307 * Win9x: MDI client returns mdi_child2
2309 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2310 ok(active_child == mdi_child || /* win2k */
2311 active_child == mdi_child2, /* win9x */
2312 "wrong active MDI child %p\n", active_child);
2313 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2314 flush_sequence();
2316 ShowWindow(mdi_child2, SW_MAXIMIZE);
2317 ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", TRUE);
2319 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2320 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
2322 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2323 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
2324 ok(zoomed, "wrong zoomed state %d\n", zoomed);
2325 flush_sequence();
2327 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2328 ok(GetFocus() == mdi_child2 || /* win2k */
2329 GetFocus() == 0, /* win9x */
2330 "wrong focus window %p\n", GetFocus());
2332 SetFocus(0);
2333 flush_sequence();
2335 ShowWindow(mdi_child2, SW_HIDE);
2336 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
2338 ShowWindow(mdi_child2, SW_RESTORE);
2339 ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", TRUE);
2340 flush_sequence();
2342 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2343 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
2345 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2346 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
2347 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2348 flush_sequence();
2350 SetFocus(0);
2351 flush_sequence();
2353 ShowWindow(mdi_child2, SW_HIDE);
2354 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
2356 ShowWindow(mdi_child2, SW_SHOW);
2357 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
2359 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2360 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2362 ShowWindow(mdi_child2, SW_MAXIMIZE);
2363 ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", TRUE);
2365 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2366 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2368 ShowWindow(mdi_child2, SW_RESTORE);
2369 ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):MDI child", TRUE);
2371 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2372 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2374 SetFocus(0);
2375 flush_sequence();
2377 ShowWindow(mdi_child2, SW_HIDE);
2378 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
2380 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2381 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2383 DestroyWindow(mdi_child2);
2384 ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
2386 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2387 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2389 /* test for maximized MDI children */
2390 trace("creating maximized visible MDI child window 1\n");
2391 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2392 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
2393 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2394 mdi_client, 0, GetModuleHandleA(0), NULL);
2395 assert(mdi_child);
2396 ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
2397 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
2399 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2400 ok(GetFocus() == mdi_child || /* win2k */
2401 GetFocus() == 0, /* win9x */
2402 "wrong focus window %p\n", GetFocus());
2404 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2405 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
2406 ok(zoomed, "wrong zoomed state %d\n", zoomed);
2407 flush_sequence();
2409 trace("creating maximized visible MDI child window 2\n");
2410 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2411 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
2412 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2413 mdi_client, 0, GetModuleHandleA(0), NULL);
2414 assert(mdi_child2);
2415 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
2416 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
2417 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
2419 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2420 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
2422 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2423 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
2424 ok(zoomed, "wrong zoomed state %d\n", zoomed);
2425 flush_sequence();
2427 trace("destroying maximized visible MDI child window 2\n");
2428 DestroyWindow(mdi_child2);
2429 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
2431 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
2433 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2434 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2436 /* Win2k: MDI client still returns a just destroyed child as active
2437 * Win9x: MDI client returns 0
2439 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2440 ok(active_child == mdi_child2 || /* win2k */
2441 !active_child, /* win9x */
2442 "wrong active MDI child %p\n", active_child);
2443 flush_sequence();
2445 ShowWindow(mdi_child, SW_MAXIMIZE);
2446 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
2447 flush_sequence();
2449 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2450 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
2452 trace("re-creating maximized visible MDI child window 2\n");
2453 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2454 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
2455 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2456 mdi_client, 0, GetModuleHandleA(0), NULL);
2457 assert(mdi_child2);
2458 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
2459 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
2460 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
2462 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2463 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
2465 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2466 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
2467 ok(zoomed, "wrong zoomed state %d\n", zoomed);
2468 flush_sequence();
2470 SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
2471 ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
2472 ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
2474 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
2475 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2476 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
2478 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2479 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
2480 ok(zoomed, "wrong zoomed state %d\n", zoomed);
2481 flush_sequence();
2483 DestroyWindow(mdi_child);
2484 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
2486 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2487 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2489 /* Win2k: MDI client still returns a just destroyed child as active
2490 * Win9x: MDI client returns 0
2492 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2493 ok(active_child == mdi_child || /* win2k */
2494 !active_child, /* win9x */
2495 "wrong active MDI child %p\n", active_child);
2496 flush_sequence();
2497 /* end of test for maximized MDI children */
2499 mdi_cs.szClass = "MDI_child_Class";
2500 mdi_cs.szTitle = "MDI child";
2501 mdi_cs.hOwner = GetModuleHandleA(0);
2502 mdi_cs.x = 0;
2503 mdi_cs.y = 0;
2504 mdi_cs.cx = CW_USEDEFAULT;
2505 mdi_cs.cy = CW_USEDEFAULT;
2506 mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
2507 mdi_cs.lParam = 0;
2508 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
2509 ok(mdi_child != 0, "MDI child creation failed\n");
2510 ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
2512 ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
2514 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2515 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
2517 ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
2518 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2519 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
2521 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2522 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
2523 ok(zoomed, "wrong zoomed state %d\n", zoomed);
2524 flush_sequence();
2526 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
2527 ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
2529 ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
2530 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2531 ok(!active_child, "wrong active MDI child %p\n", active_child);
2533 SetFocus(0);
2534 flush_sequence();
2536 DestroyWindow(mdi_client);
2537 ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
2539 DestroyWindow(mdi_frame);
2540 ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
2542 /************************* End of MDI test **********************************/
2544 static void test_WM_SETREDRAW(HWND hwnd)
2546 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
2548 flush_sequence();
2550 SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
2551 ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
2553 ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
2554 ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
2556 flush_sequence();
2557 SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
2558 ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
2560 ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
2561 ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
2563 /* restore original WS_VISIBLE state */
2564 SetWindowLongA(hwnd, GWL_STYLE, style);
2566 flush_sequence();
2569 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2571 struct message msg;
2573 trace("dialog: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
2575 switch (message)
2577 case WM_WINDOWPOSCHANGING:
2578 case WM_WINDOWPOSCHANGED:
2580 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2582 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2583 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2584 winpos->hwnd, winpos->hwndInsertAfter,
2585 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2587 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2588 * in the high word for internal purposes
2590 wParam = winpos->flags & 0xffff;
2591 break;
2595 msg.message = message;
2596 msg.flags = sent|wparam|lparam;
2597 msg.wParam = wParam;
2598 msg.lParam = lParam;
2599 add_message(&msg);
2601 if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
2602 if (message == WM_TIMER) EndDialog( hwnd, 0 );
2603 return 0;
2606 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
2608 DWORD style, exstyle;
2609 INT xmin, xmax;
2610 BOOL ret;
2612 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
2613 style = GetWindowLongA(hwnd, GWL_STYLE);
2614 /* do not be confused by WS_DLGFRAME set */
2615 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
2617 if (clear) ok(style & clear, "style %08lx should be set\n", clear);
2618 if (set) ok(!(style & set), "style %08lx should not be set\n", set);
2620 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
2621 ok( ret, "SetScrollRange(%d) error %ld\n", ctl, GetLastError());
2622 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
2623 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
2624 else
2625 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
2627 style = GetWindowLongA(hwnd, GWL_STYLE);
2628 if (set) ok(style & set, "style %08lx should be set\n", set);
2629 if (clear) ok(!(style & clear), "style %08lx should not be set\n", clear);
2631 /* a subsequent call should do nothing */
2632 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
2633 ok( ret, "SetScrollRange(%d) error %ld\n", ctl, GetLastError());
2634 ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
2636 xmin = 0xdeadbeef;
2637 xmax = 0xdeadbeef;
2638 trace("Ignore GetScrollRange error below if you are on Win9x\n");
2639 ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
2640 ok( ret, "GetScrollRange(%d) error %ld\n", ctl, GetLastError());
2641 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
2642 ok(xmin == min, "unexpected min scroll value %d\n", xmin);
2643 ok(xmax == max, "unexpected max scroll value %d\n", xmax);
2646 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
2648 DWORD style, exstyle;
2649 SCROLLINFO si;
2650 BOOL ret;
2652 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
2653 style = GetWindowLongA(hwnd, GWL_STYLE);
2654 /* do not be confused by WS_DLGFRAME set */
2655 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
2657 if (clear) ok(style & clear, "style %08lx should be set\n", clear);
2658 if (set) ok(!(style & set), "style %08lx should not be set\n", set);
2660 si.cbSize = sizeof(si);
2661 si.fMask = SIF_RANGE;
2662 si.nMin = min;
2663 si.nMax = max;
2664 SetScrollInfo(hwnd, ctl, &si, TRUE);
2665 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
2666 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
2667 else
2668 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
2670 style = GetWindowLongA(hwnd, GWL_STYLE);
2671 if (set) ok(style & set, "style %08lx should be set\n", set);
2672 if (clear) ok(!(style & clear), "style %08lx should not be set\n", clear);
2674 /* a subsequent call should do nothing */
2675 SetScrollInfo(hwnd, ctl, &si, TRUE);
2676 if (style & WS_HSCROLL)
2677 ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
2678 else if (style & WS_VSCROLL)
2679 ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
2680 else
2681 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
2683 si.fMask = SIF_PAGE;
2684 si.nPage = 5;
2685 SetScrollInfo(hwnd, ctl, &si, FALSE);
2686 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
2688 si.fMask = SIF_POS;
2689 si.nPos = max - 1;
2690 SetScrollInfo(hwnd, ctl, &si, FALSE);
2691 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
2693 si.fMask = SIF_RANGE;
2694 si.nMin = 0xdeadbeef;
2695 si.nMax = 0xdeadbeef;
2696 ret = GetScrollInfo(hwnd, ctl, &si);
2697 ok( ret, "GetScrollInfo error %ld\n", GetLastError());
2698 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
2699 ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
2700 ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
2703 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
2704 static void test_scroll_messages(HWND hwnd)
2706 SCROLLINFO si;
2707 INT min, max;
2708 BOOL ret;
2710 min = 0xdeadbeef;
2711 max = 0xdeadbeef;
2712 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
2713 ok( ret, "GetScrollRange error %ld\n", GetLastError());
2714 if (sequence->message != WmGetScrollRangeSeq[0].message)
2715 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
2716 /* values of min and max are undefined */
2717 flush_sequence();
2719 ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
2720 ok( ret, "SetScrollRange error %ld\n", GetLastError());
2721 if (sequence->message != WmSetScrollRangeSeq[0].message)
2722 trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
2723 flush_sequence();
2725 min = 0xdeadbeef;
2726 max = 0xdeadbeef;
2727 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
2728 ok( ret, "GetScrollRange error %ld\n", GetLastError());
2729 if (sequence->message != WmGetScrollRangeSeq[0].message)
2730 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
2731 /* values of min and max are undefined */
2732 flush_sequence();
2734 si.cbSize = sizeof(si);
2735 si.fMask = SIF_RANGE;
2736 si.nMin = 20;
2737 si.nMax = 160;
2738 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
2739 if (sequence->message != WmSetScrollRangeSeq[0].message)
2740 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
2741 flush_sequence();
2743 si.fMask = SIF_PAGE;
2744 si.nPage = 10;
2745 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
2746 if (sequence->message != WmSetScrollRangeSeq[0].message)
2747 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
2748 flush_sequence();
2750 si.fMask = SIF_POS;
2751 si.nPos = 20;
2752 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
2753 if (sequence->message != WmSetScrollRangeSeq[0].message)
2754 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
2755 flush_sequence();
2757 si.fMask = SIF_RANGE;
2758 si.nMin = 0xdeadbeef;
2759 si.nMax = 0xdeadbeef;
2760 ret = GetScrollInfo(hwnd, SB_CTL, &si);
2761 ok( ret, "GetScrollInfo error %ld\n", GetLastError());
2762 if (sequence->message != WmGetScrollInfoSeq[0].message)
2763 trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
2764 /* values of min and max are undefined */
2765 flush_sequence();
2767 /* set WS_HSCROLL */
2768 test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
2769 /* clear WS_HSCROLL */
2770 test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
2772 /* set WS_HSCROLL */
2773 test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
2774 /* clear WS_HSCROLL */
2775 test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
2777 /* set WS_VSCROLL */
2778 test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
2779 /* clear WS_VSCROLL */
2780 test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
2782 /* set WS_VSCROLL */
2783 test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
2784 /* clear WS_VSCROLL */
2785 test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
2788 static void test_showwindow(void)
2790 HWND hwnd, hchild;
2792 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
2793 100, 100, 200, 200, 0, 0, 0, NULL);
2794 ok (hwnd != 0, "Failed to create overlapped window\n");
2795 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
2796 0, 0, 10, 10, hwnd, 0, 0, NULL);
2797 ok (hchild != 0, "Failed to create child\n");
2798 flush_sequence();
2800 /* ShowWindow( SW_SHOWNA) for invisible top level window */
2801 trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
2802 ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
2803 ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", TRUE);
2804 trace("done\n");
2806 /* ShowWindow( SW_SHOWNA) for now visible top level window */
2807 trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
2808 ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
2809 ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
2810 trace("done\n");
2811 /* back to invisible */
2812 ShowWindow(hchild, SW_HIDE);
2813 ShowWindow(hwnd, SW_HIDE);
2814 flush_sequence();
2815 /* ShowWindow(SW_SHOWNA) with child and parent invisible */
2816 trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
2817 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
2818 ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", TRUE);
2819 trace("done\n");
2820 /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */
2821 ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
2822 flush_sequence();
2823 trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
2824 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
2825 ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", TRUE);
2826 trace("done\n");
2827 /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
2828 ShowWindow( hwnd, SW_SHOW);
2829 flush_sequence();
2830 trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
2831 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
2832 ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
2833 trace("done\n");
2835 /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
2836 ShowWindow( hchild, SW_HIDE);
2837 flush_sequence();
2838 trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
2839 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
2840 ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
2841 trace("done\n");
2843 SetCapture(hchild);
2844 ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
2845 DestroyWindow(hchild);
2846 ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
2848 DestroyWindow(hwnd);
2849 flush_sequence();
2852 /* test if we receive the right sequence of messages */
2853 static void test_messages(void)
2855 HWND hwnd, hparent, hchild;
2856 HWND hchild2, hbutton;
2857 HMENU hmenu;
2858 MSG msg;
2860 flush_sequence();
2862 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
2863 100, 100, 200, 200, 0, 0, 0, NULL);
2864 ok (hwnd != 0, "Failed to create overlapped window\n");
2865 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
2867 /* test ShowWindow(SW_HIDE) on a newly created invisible window */
2868 ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
2869 ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
2871 /* test WM_SETREDRAW on a not visible top level window */
2872 test_WM_SETREDRAW(hwnd);
2874 SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
2875 ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
2876 ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
2878 ok(GetActiveWindow() == hwnd, "window should be active\n");
2879 ok(GetFocus() == hwnd, "window should have input focus\n");
2880 ShowWindow(hwnd, SW_HIDE);
2881 ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", TRUE);
2883 ShowWindow(hwnd, SW_SHOW);
2884 ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
2886 ShowWindow(hwnd, SW_SHOW);
2887 ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
2889 ok(GetActiveWindow() == hwnd, "window should be active\n");
2890 ok(GetFocus() == hwnd, "window should have input focus\n");
2891 SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
2892 ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
2893 ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
2895 /* test WM_SETREDRAW on a visible top level window */
2896 ShowWindow(hwnd, SW_SHOW);
2897 test_WM_SETREDRAW(hwnd);
2899 trace("testing scroll APIs on a visible top level window %p\n", hwnd);
2900 test_scroll_messages(hwnd);
2902 /* test resizing and moving */
2903 SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE );
2904 ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
2905 SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE );
2906 ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
2908 /* popups don't get WM_GETMINMAXINFO */
2909 SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
2910 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
2911 flush_sequence();
2912 SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE );
2913 ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
2915 DestroyWindow(hwnd);
2916 ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
2918 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
2919 100, 100, 200, 200, 0, 0, 0, NULL);
2920 ok (hparent != 0, "Failed to create parent window\n");
2921 flush_sequence();
2923 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
2924 0, 0, 10, 10, hparent, 0, 0, NULL);
2925 ok (hchild != 0, "Failed to create child window\n");
2926 ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", TRUE);
2927 DestroyWindow(hchild);
2928 flush_sequence();
2930 /* visible child window with a caption */
2931 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
2932 WS_CHILD | WS_VISIBLE | WS_CAPTION,
2933 0, 0, 10, 10, hparent, 0, 0, NULL);
2934 ok (hchild != 0, "Failed to create child window\n");
2935 ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
2937 trace("testing scroll APIs on a visible child window %p\n", hchild);
2938 test_scroll_messages(hchild);
2940 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
2941 ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
2943 DestroyWindow(hchild);
2944 flush_sequence();
2946 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
2947 0, 0, 10, 10, hparent, 0, 0, NULL);
2948 ok (hchild != 0, "Failed to create child window\n");
2949 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
2951 hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
2952 100, 100, 50, 50, hparent, 0, 0, NULL);
2953 ok (hchild2 != 0, "Failed to create child2 window\n");
2954 flush_sequence();
2956 hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
2957 0, 100, 50, 50, hchild, 0, 0, NULL);
2958 ok (hbutton != 0, "Failed to create button window\n");
2960 /* test WM_SETREDRAW on a not visible child window */
2961 test_WM_SETREDRAW(hchild);
2963 ShowWindow(hchild, SW_SHOW);
2964 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
2966 ShowWindow(hchild, SW_HIDE);
2967 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
2969 ShowWindow(hchild, SW_SHOW);
2970 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
2972 /* test WM_SETREDRAW on a visible child window */
2973 test_WM_SETREDRAW(hchild);
2975 MoveWindow(hchild, 10, 10, 20, 20, TRUE);
2976 ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
2978 ShowWindow(hchild, SW_HIDE);
2979 flush_sequence();
2980 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
2981 ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
2983 ShowWindow(hchild, SW_HIDE);
2984 flush_sequence();
2985 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2986 ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
2988 /* DestroyWindow sequence below expects that a child has focus */
2989 SetFocus(hchild);
2990 flush_sequence();
2992 DestroyWindow(hchild);
2993 ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
2994 DestroyWindow(hchild2);
2995 DestroyWindow(hbutton);
2997 flush_sequence();
2998 hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
2999 0, 0, 100, 100, hparent, 0, 0, NULL);
3000 ok (hchild != 0, "Failed to create child popup window\n");
3001 ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
3002 DestroyWindow(hchild);
3004 /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
3005 flush_sequence();
3006 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
3007 0, 0, 100, 100, hparent, 0, 0, NULL);
3008 ok (hchild != 0, "Failed to create popup window\n");
3009 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
3010 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3011 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
3012 flush_sequence();
3013 ShowWindow(hchild, SW_SHOW);
3014 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
3015 flush_sequence();
3016 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
3017 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
3018 flush_sequence();
3019 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
3020 ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
3021 DestroyWindow(hchild);
3023 /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
3024 * changes nothing in message sequences.
3026 flush_sequence();
3027 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
3028 0, 0, 100, 100, hparent, 0, 0, NULL);
3029 ok (hchild != 0, "Failed to create popup window\n");
3030 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
3031 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3032 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
3033 flush_sequence();
3034 ShowWindow(hchild, SW_SHOW);
3035 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
3036 flush_sequence();
3037 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
3038 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
3039 DestroyWindow(hchild);
3041 flush_sequence();
3042 hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
3043 0, 0, 100, 100, hparent, 0, 0, NULL);
3044 ok(hwnd != 0, "Failed to create custom dialog window\n");
3045 ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
3048 trace("testing scroll APIs on a visible dialog %p\n", hwnd);
3049 test_scroll_messages(hwnd);
3052 flush_sequence();
3053 after_end_dialog = 1;
3054 EndDialog( hwnd, 0 );
3055 ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
3057 DestroyWindow(hwnd);
3058 after_end_dialog = 0;
3060 hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
3061 0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
3062 ok(hwnd != 0, "Failed to create custom dialog window\n");
3063 flush_sequence();
3064 trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
3065 ShowWindow(hwnd, SW_SHOW);
3066 ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
3067 DestroyWindow(hwnd);
3069 flush_sequence();
3070 DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
3071 ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
3073 /* test showing child with hidden parent */
3074 ShowWindow( hparent, SW_HIDE );
3075 flush_sequence();
3077 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
3078 0, 0, 10, 10, hparent, 0, 0, NULL);
3079 ok (hchild != 0, "Failed to create child window\n");
3080 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
3082 ShowWindow( hchild, SW_SHOW );
3083 ok_sequence(WmShowChildInvisibleParentSeq, "ShowWindow:show child with invisible parent", TRUE);
3084 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3085 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
3087 ShowWindow( hchild, SW_HIDE );
3088 ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", TRUE);
3089 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
3090 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
3092 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
3093 ok_sequence(WmShowChildInvisibleParentSeq_2, "SetWindowPos:show child with invisible parent", FALSE);
3094 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3095 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
3097 SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
3098 ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
3099 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
3100 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
3102 DestroyWindow(hchild);
3103 DestroyWindow(hparent);
3104 flush_sequence();
3106 /* Message sequence for SetMenu */
3107 ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
3108 ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
3110 hmenu = CreateMenu();
3111 ok (hmenu != 0, "Failed to create menu\n");
3112 ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
3113 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
3114 100, 100, 200, 200, 0, hmenu, 0, NULL);
3115 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
3116 ok (SetMenu(hwnd, 0), "SetMenu\n");
3117 ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
3118 ok (SetMenu(hwnd, 0), "SetMenu\n");
3119 ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
3120 ShowWindow(hwnd, SW_SHOW);
3121 flush_sequence();
3122 ok (SetMenu(hwnd, 0), "SetMenu\n");
3123 ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", TRUE);
3124 ok (SetMenu(hwnd, hmenu), "SetMenu\n");
3125 ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", TRUE);
3127 ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
3128 ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", TRUE);
3130 DestroyWindow(hwnd);
3131 flush_sequence();
3133 /* Message sequence for EnableWindow */
3134 hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3135 100, 100, 200, 200, 0, 0, 0, NULL);
3136 ok (hparent != 0, "Failed to create parent window\n");
3137 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
3138 0, 0, 10, 10, hparent, 0, 0, NULL);
3139 ok (hchild != 0, "Failed to create child window\n");
3141 SetFocus(hchild);
3142 flush_sequence();
3144 EnableWindow(hparent, FALSE);
3145 ok_sequence(WmEnableWindowSeq, "EnableWindow", FALSE);
3147 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3148 flush_sequence();
3150 /* the following test causes an exception in user.exe under win9x */
3151 if (!PostMessageW( hparent, WM_USER, 0, 0 )) return;
3152 PostMessageW( hparent, WM_USER+1, 0, 0 );
3153 /* PeekMessage(NULL) fails, but still removes the message */
3154 SetLastError(0xdeadbeef);
3155 ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
3156 ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
3157 GetLastError() == 0xdeadbeef, /* NT4 */
3158 "last error is %ld\n", GetLastError() );
3159 ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
3160 ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
3162 DestroyWindow(hchild);
3163 DestroyWindow(hparent);
3164 flush_sequence();
3166 test_showwindow();
3169 /****************** button message test *************************/
3170 static const struct message WmSetFocusButtonSeq[] =
3172 { HCBT_SETFOCUS, hook },
3173 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3174 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3175 { WM_SETFOCUS, sent|wparam, 0 },
3176 { WM_CTLCOLORBTN, sent|defwinproc },
3177 { 0 }
3179 static const struct message WmKillFocusButtonSeq[] =
3181 { HCBT_SETFOCUS, hook },
3182 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3183 { WM_KILLFOCUS, sent|wparam, 0 },
3184 { WM_CTLCOLORBTN, sent|defwinproc },
3185 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
3186 { 0 }
3188 static const struct message WmSetFocusStaticSeq[] =
3190 { HCBT_SETFOCUS, hook },
3191 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3192 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3193 { WM_SETFOCUS, sent|wparam, 0 },
3194 { WM_CTLCOLORSTATIC, sent|defwinproc },
3195 { 0 }
3197 static const struct message WmKillFocusStaticSeq[] =
3199 { HCBT_SETFOCUS, hook },
3200 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3201 { WM_KILLFOCUS, sent|wparam, 0 },
3202 { WM_CTLCOLORSTATIC, sent|defwinproc },
3203 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
3204 { 0 }
3206 static const struct message WmLButtonDownSeq[] =
3208 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
3209 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
3210 { HCBT_SETFOCUS, hook },
3211 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3212 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3213 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
3214 { WM_CTLCOLORBTN, sent|defwinproc },
3215 { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
3216 { WM_CTLCOLORBTN, sent|defwinproc },
3217 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3218 { 0 }
3220 static const struct message WmLButtonUpSeq[] =
3222 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
3223 { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
3224 { WM_CTLCOLORBTN, sent|defwinproc },
3225 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3226 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
3227 { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
3228 { 0 }
3231 static WNDPROC old_button_proc;
3233 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3235 static long defwndproc_counter = 0;
3236 LRESULT ret;
3237 struct message msg;
3239 trace("button: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
3241 msg.message = message;
3242 msg.flags = sent|wparam|lparam;
3243 if (defwndproc_counter) msg.flags |= defwinproc;
3244 msg.wParam = wParam;
3245 msg.lParam = lParam;
3246 add_message(&msg);
3248 if (message == BM_SETSTATE)
3249 ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
3251 defwndproc_counter++;
3252 ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
3253 defwndproc_counter--;
3255 return ret;
3258 static void subclass_button(void)
3260 WNDCLASSA cls;
3262 if (!GetClassInfoA(0, "button", &cls)) assert(0);
3264 old_button_proc = cls.lpfnWndProc;
3266 cls.hInstance = GetModuleHandle(0);
3267 cls.lpfnWndProc = button_hook_proc;
3268 cls.lpszClassName = "my_button_class";
3269 if (!RegisterClassA(&cls)) assert(0);
3272 static void test_button_messages(void)
3274 static const struct
3276 DWORD style;
3277 DWORD dlg_code;
3278 const struct message *setfocus;
3279 const struct message *killfocus;
3280 } button[] = {
3281 { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
3282 WmSetFocusButtonSeq, WmKillFocusButtonSeq },
3283 { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
3284 WmSetFocusButtonSeq, WmKillFocusButtonSeq },
3285 { BS_CHECKBOX, DLGC_BUTTON,
3286 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3287 { BS_AUTOCHECKBOX, DLGC_BUTTON,
3288 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3289 { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
3290 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3291 { BS_3STATE, DLGC_BUTTON,
3292 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3293 { BS_AUTO3STATE, DLGC_BUTTON,
3294 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3295 { BS_GROUPBOX, DLGC_STATIC,
3296 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3297 { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
3298 WmSetFocusButtonSeq, WmKillFocusButtonSeq },
3299 { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
3300 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3301 { BS_OWNERDRAW, DLGC_BUTTON,
3302 WmSetFocusButtonSeq, WmKillFocusButtonSeq }
3304 unsigned int i;
3305 HWND hwnd;
3306 DWORD dlg_code;
3308 subclass_button();
3310 for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
3312 hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_POPUP,
3313 0, 0, 50, 14, 0, 0, 0, NULL);
3314 ok(hwnd != 0, "Failed to create button window\n");
3316 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
3317 ok(dlg_code == button[i].dlg_code, "%d: wrong dlg_code %08lx\n", i, dlg_code);
3319 ShowWindow(hwnd, SW_SHOW);
3320 UpdateWindow(hwnd);
3321 SetFocus(0);
3322 flush_sequence();
3324 trace("button style %08lx\n", button[i].style);
3325 SetFocus(hwnd);
3326 ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
3328 SetFocus(0);
3329 ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
3331 DestroyWindow(hwnd);
3334 hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
3335 0, 0, 50, 14, 0, 0, 0, NULL);
3336 ok(hwnd != 0, "Failed to create button window\n");
3338 SetFocus(0);
3339 flush_sequence();
3341 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
3342 ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
3344 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
3345 ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
3346 DestroyWindow(hwnd);
3349 /************* painting message test ********************/
3351 static void dump_region(HRGN hrgn)
3353 DWORD i, size;
3354 RGNDATA *data = NULL;
3355 RECT *rect;
3357 if (!hrgn)
3359 printf( "null region\n" );
3360 return;
3362 if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
3363 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
3364 GetRegionData( hrgn, size, data );
3365 printf("%ld rects:", data->rdh.nCount );
3366 for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
3367 printf( " (%ld,%ld)-(%ld,%ld)", rect->left, rect->top, rect->right, rect->bottom );
3368 printf("\n");
3369 HeapFree( GetProcessHeap(), 0, data );
3372 static void check_update_rgn( HWND hwnd, HRGN hrgn )
3374 INT ret;
3375 RECT r1, r2;
3376 HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
3377 HRGN update = CreateRectRgn( 0, 0, 0, 0 );
3379 ret = GetUpdateRgn( hwnd, update, FALSE );
3380 ok( ret != ERROR, "GetUpdateRgn failed\n" );
3381 if (ret == NULLREGION)
3383 ok( !hrgn, "Update region shouldn't be empty\n" );
3385 else
3387 if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
3389 ok( 0, "Regions are different\n" );
3390 if (winetest_debug > 0)
3392 printf( "Update region: " );
3393 dump_region( update );
3394 printf( "Wanted region: " );
3395 dump_region( hrgn );
3399 GetRgnBox( update, &r1 );
3400 GetUpdateRect( hwnd, &r2, FALSE );
3401 ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
3402 "Rectangles are different: %ld,%ld-%ld,%ld / %ld,%ld-%ld,%ld\n",
3403 r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
3405 DeleteObject( tmp );
3406 DeleteObject( update );
3409 static const struct message WmInvalidateRgn[] = {
3410 { WM_NCPAINT, sent },
3411 { WM_GETTEXT, sent|defwinproc|optional },
3412 { 0 }
3415 static const struct message WmGetUpdateRect[] = {
3416 { WM_NCPAINT, sent },
3417 { WM_GETTEXT, sent|defwinproc|optional },
3418 { WM_PAINT, sent },
3419 { 0 }
3422 static const struct message WmInvalidateFull[] = {
3423 { WM_NCPAINT, sent|wparam, 1 },
3424 { WM_GETTEXT, sent|defwinproc|optional },
3425 { 0 }
3428 static const struct message WmInvalidateErase[] = {
3429 { WM_NCPAINT, sent|wparam, 1 },
3430 { WM_GETTEXT, sent|defwinproc|optional },
3431 { WM_ERASEBKGND, sent },
3432 { 0 }
3435 static const struct message WmInvalidatePaint[] = {
3436 { WM_PAINT, sent },
3437 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
3438 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
3439 { 0 }
3442 static const struct message WmInvalidateErasePaint[] = {
3443 { WM_PAINT, sent },
3444 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
3445 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
3446 { WM_ERASEBKGND, sent|beginpaint },
3447 { 0 }
3450 static const struct message WmInvalidateErasePaint2[] = {
3451 { WM_PAINT, sent },
3452 { WM_NCPAINT, sent|beginpaint },
3453 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
3454 { WM_ERASEBKGND, sent|beginpaint },
3455 { 0 }
3458 static const struct message WmErase[] = {
3459 { WM_ERASEBKGND, sent },
3460 { 0 }
3463 static const struct message WmPaint[] = {
3464 { WM_PAINT, sent },
3465 { 0 }
3468 static const struct message WmParentOnlyPaint[] = {
3469 { WM_PAINT, sent|parent },
3470 { 0 }
3473 static const struct message WmInvalidateParent[] = {
3474 { WM_NCPAINT, sent|parent },
3475 { WM_GETTEXT, sent|defwinproc|parent|optional },
3476 { WM_ERASEBKGND, sent|parent },
3477 { 0 }
3480 static const struct message WmInvalidateParentChild[] = {
3481 { WM_NCPAINT, sent|parent },
3482 { WM_GETTEXT, sent|defwinproc|parent|optional },
3483 { WM_ERASEBKGND, sent|parent },
3484 { WM_NCPAINT, sent },
3485 { WM_GETTEXT, sent|defwinproc|optional },
3486 { WM_ERASEBKGND, sent },
3487 { 0 }
3490 static const struct message WmInvalidateParentChild2[] = {
3491 { WM_ERASEBKGND, sent|parent },
3492 { WM_NCPAINT, sent },
3493 { WM_GETTEXT, sent|defwinproc|optional },
3494 { WM_ERASEBKGND, sent },
3495 { 0 }
3498 static const struct message WmParentPaint[] = {
3499 { WM_PAINT, sent|parent },
3500 { WM_PAINT, sent },
3501 { 0 }
3504 static const struct message WmParentPaintNc[] = {
3505 { WM_PAINT, sent|parent },
3506 { WM_PAINT, sent },
3507 { WM_NCPAINT, sent|beginpaint },
3508 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
3509 { WM_ERASEBKGND, sent|beginpaint },
3510 { 0 }
3513 static const struct message WmChildPaintNc[] = {
3514 { WM_PAINT, sent },
3515 { WM_NCPAINT, sent|beginpaint },
3516 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
3517 { WM_ERASEBKGND, sent|beginpaint },
3518 { 0 }
3521 static const struct message WmParentErasePaint[] = {
3522 { WM_PAINT, sent|parent },
3523 { WM_NCPAINT, sent|parent|beginpaint },
3524 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
3525 { WM_ERASEBKGND, sent|parent|beginpaint },
3526 { WM_PAINT, sent },
3527 { WM_NCPAINT, sent|beginpaint },
3528 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
3529 { WM_ERASEBKGND, sent|beginpaint },
3530 { 0 }
3533 static const struct message WmParentOnlyNcPaint[] = {
3534 { WM_PAINT, sent|parent },
3535 { WM_NCPAINT, sent|parent|beginpaint },
3536 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
3537 { 0 }
3540 static const struct message WmSetParentStyle[] = {
3541 { WM_STYLECHANGING, sent|parent },
3542 { WM_STYLECHANGED, sent|parent },
3543 { 0 }
3546 static void test_paint_messages(void)
3548 RECT rect;
3549 POINT pt;
3550 MSG msg;
3551 HWND hparent, hchild;
3552 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3553 HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
3554 HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
3555 100, 100, 200, 200, 0, 0, 0, NULL);
3556 ok (hwnd != 0, "Failed to create overlapped window\n");
3558 ShowWindow( hwnd, SW_SHOW );
3559 UpdateWindow( hwnd );
3561 /* try to flush pending X expose events */
3562 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
3563 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3565 check_update_rgn( hwnd, 0 );
3566 SetRectRgn( hrgn, 10, 10, 20, 20 );
3567 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
3568 check_update_rgn( hwnd, hrgn );
3569 SetRectRgn( hrgn2, 20, 20, 30, 30 );
3570 RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
3571 CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
3572 check_update_rgn( hwnd, hrgn );
3573 /* validate everything */
3574 RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
3575 check_update_rgn( hwnd, 0 );
3576 /* now with frame */
3577 SetRectRgn( hrgn, -5, -5, 20, 20 );
3579 /* flush pending messages */
3580 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3582 flush_sequence();
3583 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
3584 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
3586 SetRectRgn( hrgn, 0, 0, 20, 20 ); /* GetUpdateRgn clips to client area */
3587 check_update_rgn( hwnd, hrgn );
3589 flush_sequence();
3590 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
3591 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
3593 flush_sequence();
3594 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
3595 ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
3597 GetClientRect( hwnd, &rect );
3598 SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
3599 check_update_rgn( hwnd, hrgn );
3601 flush_sequence();
3602 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
3603 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
3605 flush_sequence();
3606 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
3607 ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
3608 check_update_rgn( hwnd, 0 );
3610 flush_sequence();
3611 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
3612 ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
3613 check_update_rgn( hwnd, 0 );
3615 flush_sequence();
3616 SetRectRgn( hrgn, 0, 0, 100, 100 );
3617 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
3618 SetRectRgn( hrgn, 0, 0, 50, 100 );
3619 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
3620 SetRectRgn( hrgn, 50, 0, 100, 100 );
3621 check_update_rgn( hwnd, hrgn );
3622 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
3623 ok_sequence( WmEmptySeq, "EmptySeq", FALSE ); /* must not generate messages, everything is valid */
3624 check_update_rgn( hwnd, 0 );
3626 flush_sequence();
3627 SetRectRgn( hrgn, 0, 0, 100, 100 );
3628 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
3629 SetRectRgn( hrgn, 0, 0, 100, 50 );
3630 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
3631 ok_sequence( WmErase, "Erase", FALSE );
3632 SetRectRgn( hrgn, 0, 50, 100, 100 );
3633 check_update_rgn( hwnd, hrgn );
3635 flush_sequence();
3636 SetRectRgn( hrgn, 0, 0, 100, 100 );
3637 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
3638 SetRectRgn( hrgn, 0, 0, 50, 50 );
3639 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
3640 ok_sequence( WmPaint, "Paint", FALSE );
3642 flush_sequence();
3643 SetRectRgn( hrgn, -4, -4, -2, -2 );
3644 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
3645 SetRectRgn( hrgn, -200, -200, -198, -198 );
3646 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
3647 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
3649 flush_sequence();
3650 SetRectRgn( hrgn, -4, -4, -2, -2 );
3651 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
3652 SetRectRgn( hrgn, -4, -4, -3, -3 );
3653 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
3654 SetRectRgn( hrgn, 0, 0, 1, 1 );
3655 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
3656 ok_sequence( WmPaint, "Paint", FALSE );
3658 flush_sequence();
3659 SetRectRgn( hrgn, -4, -4, -1, -1 );
3660 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
3661 RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
3662 /* make sure no WM_PAINT was generated */
3663 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3664 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
3666 flush_sequence();
3667 SetRectRgn( hrgn, -4, -4, -1, -1 );
3668 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
3669 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
3671 if (msg.hwnd == hwnd && msg.message == WM_PAINT)
3673 /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
3674 INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
3675 ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
3676 ret = GetUpdateRect( hwnd, &rect, FALSE );
3677 ok( ret, "Invalid GetUpdateRect result %d\n", ret );
3678 /* this will send WM_NCPAINT and validate the non client area */
3679 ret = GetUpdateRect( hwnd, &rect, TRUE );
3680 ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
3682 DispatchMessage( &msg );
3684 ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
3686 DestroyWindow( hwnd );
3688 /* now test with a child window */
3690 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
3691 100, 100, 200, 200, 0, 0, 0, NULL);
3692 ok (hparent != 0, "Failed to create parent window\n");
3694 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
3695 10, 10, 100, 100, hparent, 0, 0, NULL);
3696 ok (hchild != 0, "Failed to create child window\n");
3698 ShowWindow( hparent, SW_SHOW );
3699 UpdateWindow( hparent );
3700 UpdateWindow( hchild );
3701 /* try to flush pending X expose events */
3702 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
3703 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3705 flush_sequence();
3706 log_all_parent_messages++;
3708 SetRect( &rect, 0, 0, 50, 50 );
3709 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
3710 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
3711 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
3713 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
3714 pt.x = pt.y = 0;
3715 MapWindowPoints( hchild, hparent, &pt, 1 );
3716 SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
3717 check_update_rgn( hchild, hrgn );
3718 SetRectRgn( hrgn, 0, 0, 50, 50 );
3719 check_update_rgn( hparent, hrgn );
3720 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
3721 ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
3722 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
3723 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
3725 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3726 ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
3728 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
3729 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
3730 ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
3731 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
3732 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
3734 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
3735 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
3736 ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
3738 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
3739 flush_sequence();
3740 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
3741 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
3742 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
3744 /* flush all paint messages */
3745 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3746 flush_sequence();
3748 /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
3749 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
3750 SetRectRgn( hrgn, 0, 0, 50, 50 );
3751 check_update_rgn( hparent, hrgn );
3752 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
3753 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
3754 SetRectRgn( hrgn, 0, 0, 50, 50 );
3755 check_update_rgn( hparent, hrgn );
3757 /* flush all paint messages */
3758 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3759 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
3760 flush_sequence();
3762 /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
3763 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
3764 SetRectRgn( hrgn, 0, 0, 50, 50 );
3765 check_update_rgn( hparent, hrgn );
3766 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
3767 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
3768 SetRectRgn( hrgn2, 10, 10, 50, 50 );
3769 CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
3770 check_update_rgn( hparent, hrgn );
3771 /* flush all paint messages */
3772 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3773 flush_sequence();
3775 /* same as above but parent gets completely validated */
3776 SetRect( &rect, 20, 20, 30, 30 );
3777 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
3778 SetRectRgn( hrgn, 20, 20, 30, 30 );
3779 check_update_rgn( hparent, hrgn );
3780 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
3781 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
3782 check_update_rgn( hparent, 0 ); /* no update region */
3783 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3784 ok_sequence( WmEmptySeq, "WmEmpty", FALSE ); /* and no paint messages */
3786 /* make sure RDW_VALIDATE on child doesn't have the same effect */
3787 flush_sequence();
3788 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
3789 SetRectRgn( hrgn, 20, 20, 30, 30 );
3790 check_update_rgn( hparent, hrgn );
3791 RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
3792 SetRectRgn( hrgn, 20, 20, 30, 30 );
3793 check_update_rgn( hparent, hrgn );
3795 /* same as above but normal WM_PAINT doesn't validate parent */
3796 flush_sequence();
3797 SetRect( &rect, 20, 20, 30, 30 );
3798 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
3799 SetRectRgn( hrgn, 20, 20, 30, 30 );
3800 check_update_rgn( hparent, hrgn );
3801 /* no WM_PAINT in child while parent still pending */
3802 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3803 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
3804 while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3805 ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
3807 flush_sequence();
3808 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
3809 /* no WM_PAINT in child while parent still pending */
3810 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3811 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
3812 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
3813 /* now that parent is valid child should get WM_PAINT */
3814 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3815 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
3816 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3817 ok_sequence( WmEmptySeq, "No other message", FALSE );
3819 /* same thing with WS_CLIPCHILDREN in parent */
3820 flush_sequence();
3821 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
3822 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
3823 /* changing style invalidates non client area, but we need to invalidate something else to see it */
3824 RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
3825 ok_sequence( WmEmptySeq, "No message", FALSE );
3826 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
3827 ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
3829 flush_sequence();
3830 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
3831 SetRectRgn( hrgn, 20, 20, 30, 30 );
3832 check_update_rgn( hparent, hrgn );
3833 /* no WM_PAINT in child while parent still pending */
3834 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3835 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
3836 /* WM_PAINT in parent first */
3837 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3838 ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
3840 /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
3841 flush_sequence();
3842 SetRect( &rect, 0, 0, 30, 30 );
3843 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
3844 SetRectRgn( hrgn, 0, 0, 30, 30 );
3845 check_update_rgn( hparent, hrgn );
3846 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3847 ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
3849 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
3850 flush_sequence();
3851 SetRect( &rect, -10, 0, 30, 30 );
3852 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
3853 SetRect( &rect, 0, 0, 20, 20 );
3854 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
3855 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
3856 ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
3858 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
3859 flush_sequence();
3860 SetRect( &rect, -10, 0, 30, 30 );
3861 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
3862 SetRect( &rect, 0, 0, 100, 100 );
3863 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
3864 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
3865 ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
3866 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
3867 ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
3869 /* test RDW_INTERNALPAINT behavior */
3871 flush_sequence();
3872 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
3873 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3874 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
3876 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
3877 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3878 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
3880 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
3881 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3882 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
3884 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
3885 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
3886 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
3887 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3888 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
3890 log_all_parent_messages--;
3891 DestroyWindow( hparent );
3892 ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
3894 DeleteObject( hrgn );
3895 DeleteObject( hrgn2 );
3898 struct wnd_event
3900 HWND hwnd;
3901 HANDLE event;
3904 static DWORD WINAPI thread_proc(void *param)
3906 MSG msg;
3907 struct wnd_event *wnd_event = (struct wnd_event *)param;
3909 wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
3910 100, 100, 200, 200, 0, 0, 0, NULL);
3911 ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
3913 SetEvent(wnd_event->event);
3915 while (GetMessage(&msg, 0, 0, 0))
3917 TranslateMessage(&msg);
3918 DispatchMessage(&msg);
3921 ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
3923 return 0;
3926 static void test_interthread_messages(void)
3928 HANDLE hThread;
3929 DWORD tid;
3930 WNDPROC proc;
3931 MSG msg;
3932 char buf[256];
3933 int len, expected_len;
3934 struct wnd_event wnd_event;
3935 BOOL ret;
3937 wnd_event.event = CreateEventW(NULL, 0, 0, NULL);
3938 if (!wnd_event.event)
3940 trace("skipping interthread message test under win9x\n");
3941 return;
3944 hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
3945 ok(hThread != NULL, "CreateThread failed, error %ld\n", GetLastError());
3947 ok(WaitForSingleObject(wnd_event.event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
3949 CloseHandle(wnd_event.event);
3951 SetLastError(0xdeadbeef);
3952 ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
3953 ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error code %ld\n", GetLastError());
3955 proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
3956 ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %ld\n", GetLastError());
3958 expected_len = lstrlenA("window caption text");
3959 memset(buf, 0, sizeof(buf));
3960 SetLastError(0xdeadbeef);
3961 len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
3962 ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %ld, len %d, expected len %d\n", GetLastError(), len, expected_len);
3963 ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
3965 msg.hwnd = wnd_event.hwnd;
3966 msg.message = WM_GETTEXT;
3967 msg.wParam = sizeof(buf);
3968 msg.lParam = (LPARAM)buf;
3969 memset(buf, 0, sizeof(buf));
3970 SetLastError(0xdeadbeef);
3971 len = DispatchMessageA(&msg);
3972 ok(!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY,
3973 "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %ld\n", len, GetLastError());
3975 /* the following test causes an exception in user.exe under win9x */
3976 msg.hwnd = wnd_event.hwnd;
3977 msg.message = WM_TIMER;
3978 msg.wParam = 0;
3979 msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
3980 SetLastError(0xdeadbeef);
3981 len = DispatchMessageA(&msg);
3982 ok(!len && GetLastError() == 0xdeadbeef,
3983 "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %ld\n", len, GetLastError());
3985 ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
3986 ok( ret, "PostMessageA(WM_QUIT) error %ld\n", GetLastError());
3988 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
3989 CloseHandle(hThread);
3991 ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
3995 static const struct message WmVkN[] = {
3996 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
3997 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
3998 { WM_CHAR, wparam|lparam, 'n', 1 },
3999 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
4000 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
4001 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
4002 { 0 }
4004 static const struct message WmShiftVkN[] = {
4005 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
4006 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
4007 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
4008 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
4009 { WM_CHAR, wparam|lparam, 'N', 1 },
4010 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
4011 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
4012 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
4013 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
4014 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
4015 { 0 }
4017 static const struct message WmCtrlVkN[] = {
4018 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
4019 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
4020 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
4021 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
4022 { WM_CHAR, wparam|lparam, 0x000e, 1 },
4023 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
4024 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
4025 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
4026 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
4027 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
4028 { 0 }
4030 static const struct message WmCtrlVkN_2[] = {
4031 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
4032 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
4033 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
4034 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
4035 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
4036 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
4037 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
4038 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
4039 { 0 }
4041 static const struct message WmAltVkN[] = {
4042 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
4043 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
4044 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
4045 { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
4046 { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
4047 { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
4048 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
4049 { HCBT_SYSCOMMAND, hook },
4050 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
4051 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
4052 { WM_INITMENU, sent|defwinproc },
4053 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
4054 { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
4055 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
4056 { WM_CAPTURECHANGED, sent|defwinproc },
4057 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
4058 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
4059 { WM_EXITMENULOOP, sent|defwinproc },
4060 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
4061 { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
4062 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
4063 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
4064 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4065 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4066 { 0 }
4068 static const struct message WmAltVkN_2[] = {
4069 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
4070 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
4071 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
4072 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
4073 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
4074 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
4075 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4076 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4077 { 0 }
4079 static const struct message WmCtrlAltVkN[] = {
4080 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
4081 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
4082 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
4083 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
4084 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
4085 { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
4086 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
4087 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
4088 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4089 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4090 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
4091 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
4092 { 0 }
4094 static const struct message WmCtrlShiftVkN[] = {
4095 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
4096 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
4097 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
4098 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
4099 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
4100 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
4101 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
4102 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
4103 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
4104 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
4105 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
4106 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
4107 { 0 }
4109 static const struct message WmCtrlAltShiftVkN[] = {
4110 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
4111 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
4112 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
4113 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
4114 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
4115 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
4116 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
4117 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
4118 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
4119 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
4120 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
4121 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
4122 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4123 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4124 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
4125 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
4126 { 0 }
4128 static const struct message WmAltPressRelease[] = {
4129 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
4130 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
4131 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4132 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4133 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
4134 { HCBT_SYSCOMMAND, hook },
4135 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
4136 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
4137 { WM_INITMENU, sent|defwinproc },
4138 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
4139 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
4140 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
4142 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
4143 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
4144 { WM_CAPTURECHANGED, sent|defwinproc },
4145 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
4146 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
4147 { WM_EXITMENULOOP, sent|defwinproc },
4148 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4149 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4150 { 0 }
4152 static const struct message WmAltMouseButton[] = {
4153 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
4154 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
4155 { WM_MOUSEMOVE, wparam|optional, 0, 0 },
4156 { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
4157 { WM_LBUTTONDOWN, wparam, MK_LBUTTON, 0 },
4158 { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON, 0 },
4159 { WM_LBUTTONUP, wparam, 0, 0 },
4160 { WM_LBUTTONUP, sent|wparam, 0, 0 },
4161 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4162 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4163 { 0 }
4166 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
4168 MSG msg;
4170 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
4172 struct message log_msg;
4174 trace("accel: %p, %04x, %08x, %08lx\n", msg.hwnd, msg.message, msg.wParam, msg.lParam);
4176 /* ignore some unwanted messages */
4177 if (msg.message == WM_MOUSEMOVE ||
4178 msg.message == WM_DEVICECHANGE)
4179 continue;
4181 log_msg.message = msg.message;
4182 log_msg.flags = wparam|lparam;
4183 log_msg.wParam = msg.wParam;
4184 log_msg.lParam = msg.lParam;
4185 add_message(&log_msg);
4187 if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
4189 TranslateMessage(&msg);
4190 DispatchMessage(&msg);
4195 static void test_accelerators(void)
4197 RECT rc;
4198 SHORT state;
4199 HACCEL hAccel;
4200 HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4201 100, 100, 200, 200, 0, 0, 0, NULL);
4202 BOOL ret;
4204 assert(hwnd != 0);
4205 UpdateWindow(hwnd);
4206 SetFocus(hwnd);
4207 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
4209 state = GetKeyState(VK_SHIFT);
4210 ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
4211 state = GetKeyState(VK_CAPITAL);
4212 ok(state == 0, "wrong CapsLock state %04x\n", state);
4214 hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
4215 assert(hAccel != 0);
4217 pump_msg_loop(hwnd, 0);
4218 flush_sequence();
4220 trace("testing VK_N press/release\n");
4221 flush_sequence();
4222 keybd_event('N', 0, 0, 0);
4223 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4224 pump_msg_loop(hwnd, hAccel);
4225 ok_sequence(WmVkN, "VK_N press/release", FALSE);
4227 trace("testing Shift+VK_N press/release\n");
4228 flush_sequence();
4229 keybd_event(VK_SHIFT, 0, 0, 0);
4230 keybd_event('N', 0, 0, 0);
4231 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4232 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
4233 pump_msg_loop(hwnd, hAccel);
4234 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
4236 trace("testing Ctrl+VK_N press/release\n");
4237 flush_sequence();
4238 keybd_event(VK_CONTROL, 0, 0, 0);
4239 keybd_event('N', 0, 0, 0);
4240 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4241 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
4242 pump_msg_loop(hwnd, hAccel);
4243 ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
4245 trace("testing Alt+VK_N press/release\n");
4246 flush_sequence();
4247 keybd_event(VK_MENU, 0, 0, 0);
4248 keybd_event('N', 0, 0, 0);
4249 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4250 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4251 pump_msg_loop(hwnd, hAccel);
4252 ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
4254 trace("testing Ctrl+Alt+VK_N press/release 1\n");
4255 flush_sequence();
4256 keybd_event(VK_CONTROL, 0, 0, 0);
4257 keybd_event(VK_MENU, 0, 0, 0);
4258 keybd_event('N', 0, 0, 0);
4259 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4260 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4261 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
4262 pump_msg_loop(hwnd, hAccel);
4263 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
4265 ret = DestroyAcceleratorTable(hAccel);
4266 ok( ret, "DestroyAcceleratorTable error %ld\n", GetLastError());
4268 hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
4269 assert(hAccel != 0);
4271 trace("testing VK_N press/release\n");
4272 flush_sequence();
4273 keybd_event('N', 0, 0, 0);
4274 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4275 pump_msg_loop(hwnd, hAccel);
4276 ok_sequence(WmVkN, "VK_N press/release", FALSE);
4278 trace("testing Shift+VK_N press/release\n");
4279 flush_sequence();
4280 keybd_event(VK_SHIFT, 0, 0, 0);
4281 keybd_event('N', 0, 0, 0);
4282 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4283 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
4284 pump_msg_loop(hwnd, hAccel);
4285 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
4287 trace("testing Ctrl+VK_N press/release 2\n");
4288 flush_sequence();
4289 keybd_event(VK_CONTROL, 0, 0, 0);
4290 keybd_event('N', 0, 0, 0);
4291 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4292 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
4293 pump_msg_loop(hwnd, hAccel);
4294 ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
4296 trace("testing Alt+VK_N press/release 2\n");
4297 flush_sequence();
4298 keybd_event(VK_MENU, 0, 0, 0);
4299 keybd_event('N', 0, 0, 0);
4300 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4301 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4302 pump_msg_loop(hwnd, hAccel);
4303 ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
4305 trace("testing Ctrl+Alt+VK_N press/release 2\n");
4306 flush_sequence();
4307 keybd_event(VK_CONTROL, 0, 0, 0);
4308 keybd_event(VK_MENU, 0, 0, 0);
4309 keybd_event('N', 0, 0, 0);
4310 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4311 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4312 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
4313 pump_msg_loop(hwnd, hAccel);
4314 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
4316 trace("testing Ctrl+Shift+VK_N press/release\n");
4317 flush_sequence();
4318 keybd_event(VK_CONTROL, 0, 0, 0);
4319 keybd_event(VK_SHIFT, 0, 0, 0);
4320 keybd_event('N', 0, 0, 0);
4321 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4322 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
4323 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
4324 pump_msg_loop(hwnd, hAccel);
4325 ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
4327 trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
4328 flush_sequence();
4329 keybd_event(VK_CONTROL, 0, 0, 0);
4330 keybd_event(VK_MENU, 0, 0, 0);
4331 keybd_event(VK_SHIFT, 0, 0, 0);
4332 keybd_event('N', 0, 0, 0);
4333 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4334 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
4335 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4336 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
4337 pump_msg_loop(hwnd, hAccel);
4338 ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
4340 ret = DestroyAcceleratorTable(hAccel);
4341 ok( ret, "DestroyAcceleratorTable error %ld\n", GetLastError());
4343 trace("testing Alt press/release\n");
4344 flush_sequence();
4345 keybd_event(VK_MENU, 0, 0, 0);
4346 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4347 keybd_event(VK_MENU, 0, 0, 0);
4348 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4349 pump_msg_loop(hwnd, 0);
4350 /* this test doesn't pass in Wine for managed windows */
4351 ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
4353 trace("testing Alt+MouseButton press/release\n");
4354 /* first, move mouse pointer inside of the window client area */
4355 GetClientRect(hwnd, &rc);
4356 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
4357 rc.left += (rc.right - rc.left)/2;
4358 rc.top += (rc.bottom - rc.top)/2;
4359 SetCursorPos(rc.left, rc.top);
4361 pump_msg_loop(hwnd, 0);
4362 flush_sequence();
4363 keybd_event(VK_MENU, 0, 0, 0);
4364 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
4365 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
4366 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4367 pump_msg_loop(hwnd, 0);
4368 ok_sequence(WmAltMouseButton, "Alt+MouseButton press/release", FALSE);
4370 DestroyWindow(hwnd);
4373 /************* window procedures ********************/
4375 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4377 static long defwndproc_counter = 0;
4378 static long beginpaint_counter = 0;
4379 LRESULT ret;
4380 struct message msg;
4382 trace("%p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
4384 switch (message)
4386 case WM_CAPTURECHANGED:
4387 if (test_DestroyWindow_flag)
4389 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
4390 if (style & WS_CHILD)
4391 lParam = GetWindowLongA(hwnd, GWL_ID);
4392 else if (style & WS_POPUP)
4393 lParam = WND_POPUP_ID;
4394 else
4395 lParam = WND_PARENT_ID;
4397 break;
4399 case WM_NCDESTROY:
4401 HWND capture;
4403 ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
4404 capture = GetCapture();
4405 if (capture)
4407 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
4408 trace("current capture %p, releasing...\n", capture);
4409 ReleaseCapture();
4412 /* fall through */
4413 case WM_DESTROY:
4414 if (pGetAncestor)
4415 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
4416 if (test_DestroyWindow_flag)
4418 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
4419 if (style & WS_CHILD)
4420 lParam = GetWindowLongA(hwnd, GWL_ID);
4421 else if (style & WS_POPUP)
4422 lParam = WND_POPUP_ID;
4423 else
4424 lParam = WND_PARENT_ID;
4426 break;
4428 /* test_accelerators() depends on this */
4429 case WM_NCHITTEST:
4430 return HTCLIENT;
4432 /* ignore */
4433 case WM_MOUSEMOVE:
4434 case WM_SETCURSOR:
4435 case WM_DEVICECHANGE:
4436 return 0;
4438 case WM_WINDOWPOSCHANGING:
4439 case WM_WINDOWPOSCHANGED:
4441 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
4443 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
4444 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
4445 winpos->hwnd, winpos->hwndInsertAfter,
4446 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
4448 /* Log only documented flags, win2k uses 0x1000 and 0x2000
4449 * in the high word for internal purposes
4451 wParam = winpos->flags & 0xffff;
4452 break;
4456 msg.message = message;
4457 msg.flags = sent|wparam|lparam;
4458 if (defwndproc_counter) msg.flags |= defwinproc;
4459 if (beginpaint_counter) msg.flags |= beginpaint;
4460 msg.wParam = wParam;
4461 msg.lParam = lParam;
4462 add_message(&msg);
4464 if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
4466 HWND parent = GetParent(hwnd);
4467 RECT rc;
4468 MINMAXINFO *minmax = (MINMAXINFO *)lParam;
4470 GetClientRect(parent, &rc);
4471 trace("parent %p client size = (%ld x %ld)\n", parent, rc.right, rc.bottom);
4473 trace("ptReserved = (%ld,%ld)\n"
4474 "ptMaxSize = (%ld,%ld)\n"
4475 "ptMaxPosition = (%ld,%ld)\n"
4476 "ptMinTrackSize = (%ld,%ld)\n"
4477 "ptMaxTrackSize = (%ld,%ld)\n",
4478 minmax->ptReserved.x, minmax->ptReserved.y,
4479 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
4480 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
4481 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
4482 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
4484 ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %ld != %ld\n",
4485 minmax->ptMaxSize.x, rc.right);
4486 ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %ld != %ld\n",
4487 minmax->ptMaxSize.y, rc.bottom);
4490 if (message == WM_PAINT)
4492 PAINTSTRUCT ps;
4493 beginpaint_counter++;
4494 BeginPaint( hwnd, &ps );
4495 beginpaint_counter--;
4496 EndPaint( hwnd, &ps );
4497 return 0;
4500 defwndproc_counter++;
4501 ret = DefWindowProcA(hwnd, message, wParam, lParam);
4502 defwndproc_counter--;
4504 return ret;
4507 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4509 static long defwndproc_counter = 0;
4510 LRESULT ret;
4511 struct message msg;
4513 trace("popup: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
4515 msg.message = message;
4516 msg.flags = sent|wparam|lparam;
4517 if (defwndproc_counter) msg.flags |= defwinproc;
4518 msg.wParam = wParam;
4519 msg.lParam = lParam;
4520 add_message(&msg);
4522 if (message == WM_CREATE)
4524 DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
4525 SetWindowLongA(hwnd, GWL_STYLE, style);
4528 defwndproc_counter++;
4529 ret = DefWindowProcA(hwnd, message, wParam, lParam);
4530 defwndproc_counter--;
4532 return ret;
4535 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4537 static long defwndproc_counter = 0;
4538 static long beginpaint_counter = 0;
4539 LRESULT ret;
4540 struct message msg;
4542 trace("parent: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
4544 if (log_all_parent_messages ||
4545 message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
4546 message == WM_SETFOCUS || message == WM_KILLFOCUS ||
4547 message == WM_ENABLE || message == WM_ENTERIDLE ||
4548 message == WM_IME_SETCONTEXT)
4550 msg.message = message;
4551 msg.flags = sent|parent|wparam|lparam;
4552 if (defwndproc_counter) msg.flags |= defwinproc;
4553 if (beginpaint_counter) msg.flags |= beginpaint;
4554 msg.wParam = wParam;
4555 msg.lParam = lParam;
4556 add_message(&msg);
4559 if (message == WM_PAINT)
4561 PAINTSTRUCT ps;
4562 beginpaint_counter++;
4563 BeginPaint( hwnd, &ps );
4564 beginpaint_counter--;
4565 EndPaint( hwnd, &ps );
4566 return 0;
4569 defwndproc_counter++;
4570 ret = DefWindowProcA(hwnd, message, wParam, lParam);
4571 defwndproc_counter--;
4573 return ret;
4576 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4578 static long defwndproc_counter = 0;
4579 LRESULT ret;
4580 struct message msg;
4582 trace("dialog: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
4584 DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
4585 ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
4586 if (after_end_dialog)
4587 ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
4588 else
4589 ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
4591 switch (message)
4593 case WM_WINDOWPOSCHANGING:
4594 case WM_WINDOWPOSCHANGED:
4596 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
4598 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
4599 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
4600 winpos->hwnd, winpos->hwndInsertAfter,
4601 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
4603 /* Log only documented flags, win2k uses 0x1000 and 0x2000
4604 * in the high word for internal purposes
4606 wParam = winpos->flags & 0xffff;
4607 break;
4611 msg.message = message;
4612 msg.flags = sent|wparam|lparam;
4613 if (defwndproc_counter) msg.flags |= defwinproc;
4614 msg.wParam = wParam;
4615 msg.lParam = lParam;
4616 add_message(&msg);
4618 defwndproc_counter++;
4619 ret = DefDlgProcA(hwnd, message, wParam, lParam);
4620 defwndproc_counter--;
4622 return ret;
4625 static BOOL RegisterWindowClasses(void)
4627 WNDCLASSA cls;
4629 cls.style = 0;
4630 cls.lpfnWndProc = MsgCheckProcA;
4631 cls.cbClsExtra = 0;
4632 cls.cbWndExtra = 0;
4633 cls.hInstance = GetModuleHandleA(0);
4634 cls.hIcon = 0;
4635 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
4636 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4637 cls.lpszMenuName = NULL;
4638 cls.lpszClassName = "TestWindowClass";
4639 if(!RegisterClassA(&cls)) return FALSE;
4641 cls.lpfnWndProc = PopupMsgCheckProcA;
4642 cls.lpszClassName = "TestPopupClass";
4643 if(!RegisterClassA(&cls)) return FALSE;
4645 cls.lpfnWndProc = ParentMsgCheckProcA;
4646 cls.lpszClassName = "TestParentClass";
4647 if(!RegisterClassA(&cls)) return FALSE;
4649 cls.lpfnWndProc = DefWindowProcA;
4650 cls.lpszClassName = "SimpleWindowClass";
4651 if(!RegisterClassA(&cls)) return FALSE;
4653 ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
4654 cls.style = 0;
4655 cls.hInstance = GetModuleHandleA(0);
4656 cls.hbrBackground = 0;
4657 cls.lpfnWndProc = TestDlgProcA;
4658 cls.lpszClassName = "TestDialogClass";
4659 if(!RegisterClassA(&cls)) return FALSE;
4661 return TRUE;
4664 static HHOOK hCBT_hook;
4665 static DWORD cbt_hook_thread_id;
4667 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
4669 static const char *CBT_code_name[10] = {
4670 "HCBT_MOVESIZE",
4671 "HCBT_MINMAX",
4672 "HCBT_QS",
4673 "HCBT_CREATEWND",
4674 "HCBT_DESTROYWND",
4675 "HCBT_ACTIVATE",
4676 "HCBT_CLICKSKIPPED",
4677 "HCBT_KEYSKIPPED",
4678 "HCBT_SYSCOMMAND",
4679 "HCBT_SETFOCUS" };
4680 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
4681 HWND hwnd;
4682 char buf[256];
4684 trace("CBT: %d (%s), %08x, %08lx\n", nCode, code_name, wParam, lParam);
4686 ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
4688 if (nCode == HCBT_SYSCOMMAND)
4690 struct message msg;
4692 msg.message = nCode;
4693 msg.flags = hook|wparam|lparam;
4694 msg.wParam = wParam;
4695 msg.lParam = lParam;
4696 add_message(&msg);
4698 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
4701 if (nCode == HCBT_DESTROYWND)
4703 if (test_DestroyWindow_flag)
4705 DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
4706 if (style & WS_CHILD)
4707 lParam = GetWindowLongA((HWND)wParam, GWL_ID);
4708 else if (style & WS_POPUP)
4709 lParam = WND_POPUP_ID;
4710 else
4711 lParam = WND_PARENT_ID;
4715 /* Log also SetFocus(0) calls */
4716 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
4718 if (GetClassNameA(hwnd, buf, sizeof(buf)))
4720 if (!lstrcmpiA(buf, "TestWindowClass") ||
4721 !lstrcmpiA(buf, "TestParentClass") ||
4722 !lstrcmpiA(buf, "TestPopupClass") ||
4723 !lstrcmpiA(buf, "SimpleWindowClass") ||
4724 !lstrcmpiA(buf, "TestDialogClass") ||
4725 !lstrcmpiA(buf, "MDI_frame_class") ||
4726 !lstrcmpiA(buf, "MDI_client_class") ||
4727 !lstrcmpiA(buf, "MDI_child_class") ||
4728 !lstrcmpiA(buf, "my_button_class") ||
4729 !lstrcmpiA(buf, "static") ||
4730 !lstrcmpiA(buf, "#32770"))
4732 struct message msg;
4734 msg.message = nCode;
4735 msg.flags = hook|wparam|lparam;
4736 msg.wParam = wParam;
4737 msg.lParam = lParam;
4738 add_message(&msg);
4741 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
4744 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
4745 DWORD event,
4746 HWND hwnd,
4747 LONG object_id,
4748 LONG child_id,
4749 DWORD thread_id,
4750 DWORD event_time)
4752 char buf[256];
4754 trace("WEH:%p,event %08lx,hwnd %p,obj %08lx,id %08lx,thread %08lx,time %08lx\n",
4755 hevent, event, hwnd, object_id, child_id, thread_id, event_time);
4757 ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
4759 /* ignore mouse cursor events */
4760 if (object_id == OBJID_CURSOR) return;
4762 if (!hwnd || GetClassNameA(hwnd, buf, sizeof(buf)))
4764 if (!hwnd ||
4765 !lstrcmpiA(buf, "TestWindowClass") ||
4766 !lstrcmpiA(buf, "TestParentClass") ||
4767 !lstrcmpiA(buf, "TestPopupClass") ||
4768 !lstrcmpiA(buf, "SimpleWindowClass") ||
4769 !lstrcmpiA(buf, "TestDialogClass") ||
4770 !lstrcmpiA(buf, "MDI_frame_class") ||
4771 !lstrcmpiA(buf, "MDI_client_class") ||
4772 !lstrcmpiA(buf, "MDI_child_class") ||
4773 !lstrcmpiA(buf, "my_button_class") ||
4774 !lstrcmpiA(buf, "static") ||
4775 !lstrcmpiA(buf, "#32770"))
4777 struct message msg;
4779 msg.message = event;
4780 msg.flags = winevent_hook|wparam|lparam;
4781 msg.wParam = object_id;
4782 msg.lParam = child_id;
4783 add_message(&msg);
4788 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
4789 static const WCHAR wszAnsi[] = {'U',0};
4791 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4793 switch (uMsg)
4795 case CB_FINDSTRINGEXACT:
4796 trace("String: %p\n", (LPCWSTR)lParam);
4797 if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
4798 return 1;
4799 if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
4800 return 0;
4801 return -1;
4803 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
4806 static void test_message_conversion(void)
4808 static const WCHAR wszMsgConversionClass[] =
4809 {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
4810 WNDCLASSW cls;
4811 LRESULT lRes;
4812 HWND hwnd;
4813 WNDPROC wndproc;
4815 cls.style = 0;
4816 cls.lpfnWndProc = MsgConversionProcW;
4817 cls.cbClsExtra = 0;
4818 cls.cbWndExtra = 0;
4819 cls.hInstance = GetModuleHandleW(NULL);
4820 cls.hIcon = NULL;
4821 cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
4822 cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
4823 cls.lpszMenuName = NULL;
4824 cls.lpszClassName = wszMsgConversionClass;
4825 /* this call will fail on Win9x, but that doesn't matter as this test is
4826 * meaningless on those platforms */
4827 if(!RegisterClassW(&cls)) return;
4829 hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
4830 100, 100, 200, 200, 0, 0, 0, NULL);
4831 ok(hwnd != NULL, "Window creation failed\n");
4833 /* {W, A} -> A */
4835 wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
4836 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4837 ok(lRes == 0, "String should have been converted\n");
4838 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4839 ok(lRes == 1, "String shouldn't have been converted\n");
4841 /* {W, A} -> W */
4843 wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
4844 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4845 ok(lRes == 1, "String shouldn't have been converted\n");
4846 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4847 ok(lRes == 1, "String shouldn't have been converted\n");
4849 /* Synchronous messages */
4851 lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4852 ok(lRes == 0, "String should have been converted\n");
4853 lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4854 ok(lRes == 1, "String shouldn't have been converted\n");
4856 /* Asynchronous messages */
4858 SetLastError(0);
4859 lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4860 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
4861 "PostMessage on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
4862 SetLastError(0);
4863 lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4864 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
4865 "PostMessage on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
4866 SetLastError(0);
4867 lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4868 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
4869 "PosThreadtMessage on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
4870 SetLastError(0);
4871 lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4872 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
4873 "PosThreadtMessage on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
4874 SetLastError(0);
4875 lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4876 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
4877 "SendNotifyMessage on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
4878 SetLastError(0);
4879 lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4880 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
4881 "SendNotifyMessage on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
4882 SetLastError(0);
4883 lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
4884 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
4885 "SendMessageCallback on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
4886 SetLastError(0);
4887 lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
4888 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
4889 "SendMessageCallback on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
4892 typedef struct _thread_info
4894 HWND hWnd;
4895 HANDLE handles[2];
4896 DWORD id;
4897 } thread_info;
4899 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT id, DWORD dwTime)
4903 #define TIMER_ID 0x19
4905 static DWORD WINAPI timer_thread_proc(LPVOID x)
4907 thread_info *info = x;
4908 DWORD r;
4910 r = KillTimer(info->hWnd, 0x19);
4911 ok(r,"KillTimer failed in thread\n");
4912 r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
4913 ok(r,"SetTimer failed in thread\n");
4914 ok(r==TIMER_ID,"SetTimer id different\n");
4915 r = SetEvent(info->handles[0]);
4916 ok(r,"SetEvent failed in thread\n");
4917 return 0;
4920 static void test_timers(void)
4922 thread_info info;
4923 DWORD id;
4925 info.hWnd = CreateWindow ("TestWindowClass", NULL,
4926 WS_OVERLAPPEDWINDOW ,
4927 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4928 NULL, NULL, 0);
4930 info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
4931 ok(info.id, "SetTimer failed\n");
4932 ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
4933 info.handles[0] = CreateEvent(NULL,0,0,NULL);
4934 info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
4936 WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
4938 WaitForSingleObject(info.handles[1], INFINITE);
4940 CloseHandle(info.handles[0]);
4941 CloseHandle(info.handles[1]);
4943 ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
4945 ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
4948 /* Various win events with arbitrary parameters */
4949 static const struct message WmWinEventsSeq[] = {
4950 { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
4951 { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
4952 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
4953 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
4954 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
4955 { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
4956 { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
4957 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
4958 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
4959 /* our win event hook ignores OBJID_CURSOR events */
4960 /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
4961 { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
4962 { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
4963 { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
4964 { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
4965 { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
4966 { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
4967 { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
4968 { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
4969 { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
4970 { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
4971 { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
4972 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
4973 { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
4974 { 0 }
4976 static const struct message WmWinEventCaretSeq[] = {
4977 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
4978 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
4979 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
4980 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
4981 { 0 }
4983 static const struct message WmWinEventCaretSeq_2[] = {
4984 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
4985 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
4986 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
4987 { 0 }
4989 static const struct message WmWinEventAlertSeq[] = {
4990 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
4991 { 0 }
4993 static const struct message WmWinEventAlertSeq_2[] = {
4994 /* create window in the thread proc */
4995 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
4996 /* our test event */
4997 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
4998 { 0 }
5000 static const struct message WmGlobalHookSeq_1[] = {
5001 /* create window in the thread proc */
5002 { HCBT_CREATEWND, hook|lparam, 0, 2 },
5003 /* our test events */
5004 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
5005 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
5006 { 0 }
5008 static const struct message WmGlobalHookSeq_2[] = {
5009 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
5010 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
5011 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
5012 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
5013 { 0 }
5016 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
5017 DWORD event,
5018 HWND hwnd,
5019 LONG object_id,
5020 LONG child_id,
5021 DWORD thread_id,
5022 DWORD event_time)
5024 char buf[256];
5026 trace("WEH_2:%p,event %08lx,hwnd %p,obj %08lx,id %08lx,thread %08lx,time %08lx\n",
5027 hevent, event, hwnd, object_id, child_id, thread_id, event_time);
5029 if (GetClassNameA(hwnd, buf, sizeof(buf)))
5031 if (!lstrcmpiA(buf, "TestWindowClass") ||
5032 !lstrcmpiA(buf, "static"))
5034 struct message msg;
5036 msg.message = event;
5037 msg.flags = winevent_hook|wparam|lparam;
5038 msg.wParam = object_id;
5039 msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
5040 add_message(&msg);
5045 static HHOOK hCBT_global_hook;
5046 static DWORD cbt_global_hook_thread_id;
5048 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
5050 HWND hwnd;
5051 char buf[256];
5053 trace("CBT_2: %d, %08x, %08lx\n", nCode, wParam, lParam);
5055 if (nCode == HCBT_SYSCOMMAND)
5057 struct message msg;
5059 msg.message = nCode;
5060 msg.flags = hook|wparam|lparam;
5061 msg.wParam = wParam;
5062 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
5063 add_message(&msg);
5065 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
5068 /* Log also SetFocus(0) calls */
5069 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
5071 if (GetClassNameA(hwnd, buf, sizeof(buf)))
5073 if (!lstrcmpiA(buf, "TestWindowClass") ||
5074 !lstrcmpiA(buf, "static"))
5076 struct message msg;
5078 msg.message = nCode;
5079 msg.flags = hook|wparam|lparam;
5080 msg.wParam = wParam;
5081 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
5082 add_message(&msg);
5085 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
5088 static DWORD WINAPI win_event_global_thread_proc(void *param)
5090 HWND hwnd;
5091 MSG msg;
5092 HANDLE hevent = *(HANDLE *)param;
5093 HMODULE user32 = GetModuleHandleA("user32.dll");
5094 FARPROC pNotifyWinEvent = GetProcAddress(user32, "NotifyWinEvent");
5096 assert(pNotifyWinEvent);
5098 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
5099 assert(hwnd);
5100 trace("created thread window %p\n", hwnd);
5102 *(HWND *)param = hwnd;
5104 flush_sequence();
5105 /* this event should be received only by our new hook proc,
5106 * an old one does not expect an event from another thread.
5108 pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
5109 SetEvent(hevent);
5111 while (GetMessage(&msg, 0, 0, 0))
5113 TranslateMessage(&msg);
5114 DispatchMessage(&msg);
5116 return 0;
5119 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
5121 HWND hwnd;
5122 MSG msg;
5123 HANDLE hevent = *(HANDLE *)param;
5125 flush_sequence();
5126 /* these events should be received only by our new hook proc,
5127 * an old one does not expect an event from another thread.
5130 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
5131 assert(hwnd);
5132 trace("created thread window %p\n", hwnd);
5134 *(HWND *)param = hwnd;
5136 /* Windows doesn't like when a thread plays games with the focus,
5137 that leads to all kinds of misbehaviours and failures to activate
5138 a window. So, better keep next lines commented out.
5139 SetFocus(0);
5140 SetFocus(hwnd);*/
5142 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
5143 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
5145 SetEvent(hevent);
5147 while (GetMessage(&msg, 0, 0, 0))
5149 TranslateMessage(&msg);
5150 DispatchMessage(&msg);
5152 return 0;
5155 static void test_winevents(void)
5157 MSG msg;
5158 HWND hwnd, hwnd2;
5159 UINT i;
5160 HANDLE hthread, hevent;
5161 DWORD tid;
5162 HWINEVENTHOOK hhook;
5163 const struct message *events = WmWinEventsSeq;
5164 HMODULE user32 = GetModuleHandleA("user32.dll");
5165 FARPROC pSetWinEventHook = GetProcAddress(user32, "SetWinEventHook");
5166 FARPROC pUnhookWinEvent = GetProcAddress(user32, "UnhookWinEvent");
5167 FARPROC pNotifyWinEvent = GetProcAddress(user32, "NotifyWinEvent");
5169 hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
5170 WS_OVERLAPPEDWINDOW,
5171 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5172 NULL, NULL, 0);
5173 assert(hwnd);
5175 /****** start of global hook test *************/
5176 hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
5177 assert(hCBT_global_hook);
5179 hevent = CreateEventA(NULL, 0, 0, NULL);
5180 assert(hevent);
5181 hwnd2 = (HWND)hevent;
5183 hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
5184 ok(hthread != NULL, "CreateThread failed, error %ld\n", GetLastError());
5186 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5188 ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
5190 flush_sequence();
5191 /* this one should be received only by old hook proc */
5192 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
5193 /* this one should be received only by old hook proc */
5194 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
5196 ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
5198 ok(UnhookWindowsHookEx(hCBT_global_hook), "UnhookWindowsHookEx error %ld", GetLastError());
5200 PostThreadMessageA(tid, WM_QUIT, 0, 0);
5201 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5202 CloseHandle(hthread);
5203 CloseHandle(hevent);
5204 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
5205 /****** end of global hook test *************/
5207 if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
5209 ok(DestroyWindow(hwnd), "failed to destroy window\n");
5210 return;
5213 flush_sequence();
5215 #if 0 /* this test doesn't pass under Win9x */
5216 /* win2k ignores events with hwnd == 0 */
5217 SetLastError(0xdeadbeef);
5218 pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
5219 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
5220 GetLastError() == 0xdeadbeef, /* Win9x */
5221 "unexpected error %ld\n", GetLastError());
5222 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
5223 #endif
5225 for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
5226 pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
5228 ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
5230 /****** start of event filtering test *************/
5231 hhook = (HWINEVENTHOOK)pSetWinEventHook(
5232 EVENT_OBJECT_SHOW, /* 0x8002 */
5233 EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
5234 GetModuleHandleA(0), win_event_global_hook_proc,
5235 GetCurrentProcessId(), 0,
5236 WINEVENT_INCONTEXT);
5237 ok(hhook != 0, "SetWinEventHook error %ld\n", GetLastError());
5239 hevent = CreateEventA(NULL, 0, 0, NULL);
5240 assert(hevent);
5241 hwnd2 = (HWND)hevent;
5243 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
5244 ok(hthread != NULL, "CreateThread failed, error %ld\n", GetLastError());
5246 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5248 ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
5250 flush_sequence();
5251 /* this one should be received only by old hook proc */
5252 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
5253 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
5254 /* this one should be received only by old hook proc */
5255 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
5257 ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
5259 ok(pUnhookWinEvent(hhook), "UnhookWinEvent error %ld\n", GetLastError());
5261 PostThreadMessageA(tid, WM_QUIT, 0, 0);
5262 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5263 CloseHandle(hthread);
5264 CloseHandle(hevent);
5265 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
5266 /****** end of event filtering test *************/
5268 /****** start of out of context event test *************/
5269 hhook = (HWINEVENTHOOK)pSetWinEventHook(
5270 EVENT_MIN, EVENT_MAX,
5271 0, win_event_global_hook_proc,
5272 GetCurrentProcessId(), 0,
5273 WINEVENT_OUTOFCONTEXT);
5274 ok(hhook != 0, "SetWinEventHook error %ld\n", GetLastError());
5276 hevent = CreateEventA(NULL, 0, 0, NULL);
5277 assert(hevent);
5278 hwnd2 = (HWND)hevent;
5280 flush_sequence();
5282 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
5283 ok(hthread != NULL, "CreateThread failed, error %ld\n", GetLastError());
5285 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5287 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
5288 /* process pending winevent messages */
5289 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
5290 ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
5292 flush_sequence();
5293 /* this one should be received only by old hook proc */
5294 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
5295 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
5296 /* this one should be received only by old hook proc */
5297 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
5299 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
5300 /* process pending winevent messages */
5301 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
5302 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
5304 ok(pUnhookWinEvent(hhook), "UnhookWinEvent error %ld\n", GetLastError());
5306 PostThreadMessageA(tid, WM_QUIT, 0, 0);
5307 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5308 CloseHandle(hthread);
5309 CloseHandle(hevent);
5310 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
5311 /****** end of out of context event test *************/
5313 ok(DestroyWindow(hwnd), "failed to destroy window\n");
5316 static void test_set_hook(void)
5318 HHOOK hhook;
5319 HWINEVENTHOOK hwinevent_hook;
5320 HMODULE user32 = GetModuleHandleA("user32.dll");
5321 FARPROC pSetWinEventHook = GetProcAddress(user32, "SetWinEventHook");
5322 FARPROC pUnhookWinEvent = GetProcAddress(user32, "UnhookWinEvent");
5324 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
5325 ok(hhook != 0, "local hook does not require hModule set to 0\n");
5326 UnhookWindowsHookEx(hhook);
5328 #if 0 /* this test doesn't pass under Win9x: BUG! */
5329 SetLastError(0xdeadbeef);
5330 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
5331 ok(!hhook, "global hook requires hModule != 0\n");
5332 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %ld\n", GetLastError());
5333 #endif
5335 SetLastError(0xdeadbeef);
5336 hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
5337 ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
5338 ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
5339 GetLastError() == 0xdeadbeef, /* Win9x */
5340 "unexpected error %ld\n", GetLastError());
5342 SetLastError(0xdeadbeef);
5343 ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
5344 ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
5345 GetLastError() == 0xdeadbeef, /* Win9x */
5346 "unexpected error %ld\n", GetLastError());
5348 if (!pSetWinEventHook || !pUnhookWinEvent) return;
5350 /* even process local incontext hooks require hmodule */
5351 SetLastError(0xdeadbeef);
5352 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
5353 0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
5354 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
5355 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
5356 GetLastError() == 0xdeadbeef, /* Win9x */
5357 "unexpected error %ld\n", GetLastError());
5359 /* even thread local incontext hooks require hmodule */
5360 SetLastError(0xdeadbeef);
5361 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
5362 0, win_event_proc, GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
5363 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
5364 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
5365 GetLastError() == 0xdeadbeef, /* Win9x */
5366 "unexpected error %ld\n", GetLastError());
5368 #if 0 /* these 3 tests don't pass under Win9x */
5369 SetLastError(0xdeadbeef);
5370 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(1, 0,
5371 0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
5372 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
5373 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %ld\n", GetLastError());
5375 SetLastError(0xdeadbeef);
5376 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(-1, 1,
5377 0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
5378 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
5379 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %ld\n", GetLastError());
5381 SetLastError(0xdeadbeef);
5382 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
5383 0, win_event_proc, 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
5384 ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
5385 ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %ld\n", GetLastError());
5386 #endif
5388 SetLastError(0xdeadbeef);
5389 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(0, 0,
5390 0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
5391 ok(hwinevent_hook != 0, "SetWinEventHook error %ld\n", GetLastError());
5392 ok(GetLastError() == 0xdeadbeef, "unexpected error %ld\n", GetLastError());
5393 ok(pUnhookWinEvent(hwinevent_hook), "UnhookWinEvent error %ld\n", GetLastError());
5395 todo_wine {
5396 /* This call succeeds under win2k SP4, but fails under Wine.
5397 Does win2k test/use passed process id? */
5398 SetLastError(0xdeadbeef);
5399 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
5400 0, win_event_proc, 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
5401 ok(hwinevent_hook != 0, "SetWinEventHook error %ld\n", GetLastError());
5402 ok(GetLastError() == 0xdeadbeef, "unexpected error %ld\n", GetLastError());
5403 ok(pUnhookWinEvent(hwinevent_hook), "UnhookWinEvent error %ld\n", GetLastError());
5406 SetLastError(0xdeadbeef);
5407 ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
5408 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
5409 GetLastError() == 0xdeadbeef, /* Win9x */
5410 "unexpected error %ld\n", GetLastError());
5413 static const struct message ScrollWindowPaint1[] = {
5414 { WM_PAINT, sent },
5415 { WM_ERASEBKGND, sent|beginpaint },
5416 { 0 }
5419 static const struct message ScrollWindowPaint2[] = {
5420 { WM_PAINT, sent },
5421 { 0 }
5424 static void test_scrollwindowex(void)
5426 HWND hwnd, hchild;
5427 RECT rect={0,0,130,130};
5428 MSG msg;
5430 hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
5431 WS_VISIBLE|WS_OVERLAPPEDWINDOW,
5432 100, 100, 200, 200, 0, 0, 0, NULL);
5433 ok (hwnd != 0, "Failed to create overlapped window\n");
5434 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
5435 WS_VISIBLE|WS_CAPTION|WS_CHILD,
5436 10, 10, 150, 150, hwnd, 0, 0, NULL);
5437 ok (hchild != 0, "Failed to create child\n");
5438 UpdateWindow(hwnd);
5439 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5440 flush_sequence();
5442 /* scroll without the child window */
5443 trace("start scroll\n");
5444 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
5445 SW_ERASE|SW_INVALIDATE);
5446 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
5447 trace("end scroll\n");
5448 flush_sequence();
5449 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5450 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
5452 /* Now without the SW_ERASE flag */
5453 trace("start scroll\n");
5454 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
5455 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
5456 trace("end scroll\n");
5457 flush_sequence();
5458 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5459 ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
5461 /* now scroll the child window as well */
5462 trace("start scroll\n");
5463 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
5464 SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
5465 todo_wine { /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
5466 /* windows sometimes a WM_MOVE */
5467 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
5469 trace("end scroll\n");
5470 flush_sequence();
5471 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5472 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
5474 ok(DestroyWindow(hchild), "failed to destroy window\n");
5475 ok(DestroyWindow(hwnd), "failed to destroy window\n");
5476 flush_sequence();
5479 static const struct message destroy_window_with_children[] = {
5480 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
5481 { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
5482 { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
5483 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
5484 { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
5485 { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
5486 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
5487 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
5488 { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
5489 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
5490 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
5491 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
5492 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
5493 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
5494 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
5495 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
5496 { 0 }
5499 static void test_DestroyWindow(void)
5501 HWND parent, child1, child2, child3, child4, test;
5502 UINT child_id = WND_CHILD_ID + 1;
5504 parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
5505 100, 100, 200, 200, 0, 0, 0, NULL);
5506 assert(parent != 0);
5507 child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
5508 0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
5509 assert(child1 != 0);
5510 child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
5511 0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
5512 assert(child2 != 0);
5513 child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
5514 0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
5515 assert(child3 != 0);
5516 child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
5517 0, 0, 50, 50, parent, 0, 0, NULL);
5518 assert(child4 != 0);
5520 /* test owner/parent of child2 */
5521 test = GetParent(child2);
5522 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
5523 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
5524 if(pGetAncestor) {
5525 test = pGetAncestor(child2, GA_PARENT);
5526 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
5528 test = GetWindow(child2, GW_OWNER);
5529 ok(!test, "wrong owner %p\n", test);
5531 test = SetParent(child2, parent);
5532 ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
5534 /* test owner/parent of the parent */
5535 test = GetParent(parent);
5536 ok(!test, "wrong parent %p\n", test);
5537 todo_wine {
5538 ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
5540 if(pGetAncestor) {
5541 test = pGetAncestor(parent, GA_PARENT);
5542 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
5544 test = GetWindow(parent, GW_OWNER);
5545 ok(!test, "wrong owner %p\n", test);
5547 /* test owner/parent of child1 */
5548 test = GetParent(child1);
5549 ok(test == parent, "wrong parent %p\n", test);
5550 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
5551 if(pGetAncestor) {
5552 test = pGetAncestor(child1, GA_PARENT);
5553 ok(test == parent, "wrong parent %p\n", test);
5555 test = GetWindow(child1, GW_OWNER);
5556 ok(!test, "wrong owner %p\n", test);
5558 /* test owner/parent of child2 */
5559 test = GetParent(child2);
5560 ok(test == parent, "wrong parent %p\n", test);
5561 ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
5562 if(pGetAncestor) {
5563 test = pGetAncestor(child2, GA_PARENT);
5564 ok(test == parent, "wrong parent %p\n", test);
5566 test = GetWindow(child2, GW_OWNER);
5567 ok(!test, "wrong owner %p\n", test);
5569 /* test owner/parent of child3 */
5570 test = GetParent(child3);
5571 ok(test == child1, "wrong parent %p\n", test);
5572 ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
5573 if(pGetAncestor) {
5574 test = pGetAncestor(child3, GA_PARENT);
5575 ok(test == child1, "wrong parent %p\n", test);
5577 test = GetWindow(child3, GW_OWNER);
5578 ok(!test, "wrong owner %p\n", test);
5580 /* test owner/parent of child4 */
5581 test = GetParent(child4);
5582 ok(test == parent, "wrong parent %p\n", test);
5583 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
5584 if(pGetAncestor) {
5585 test = pGetAncestor(child4, GA_PARENT);
5586 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
5588 test = GetWindow(child4, GW_OWNER);
5589 ok(test == parent, "wrong owner %p\n", test);
5591 flush_sequence();
5593 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
5594 parent, child1, child2, child3, child4);
5596 SetCapture(child4);
5597 test = GetCapture();
5598 ok(test == child4, "wrong capture window %p\n", test);
5600 test_DestroyWindow_flag = TRUE;
5601 ok(DestroyWindow(parent), "DestroyWindow() error %ld\n", GetLastError());
5602 test_DestroyWindow_flag = FALSE;
5603 ok_sequence(destroy_window_with_children, "destroy window with children", 0);
5605 ok(!IsWindow(parent), "parent still exists\n");
5606 ok(!IsWindow(child1), "child1 still exists\n");
5607 ok(!IsWindow(child2), "child2 still exists\n");
5608 ok(!IsWindow(child3), "child3 still exists\n");
5609 ok(!IsWindow(child4), "child4 still exists\n");
5611 test = GetCapture();
5612 ok(!test, "wrong capture window %p\n", test);
5616 static const struct message WmDispatchPaint[] = {
5617 { WM_NCPAINT, sent },
5618 { WM_GETTEXT, sent|defwinproc|optional },
5619 { WM_GETTEXT, sent|defwinproc|optional },
5620 { WM_ERASEBKGND, sent },
5621 { 0 }
5624 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5626 if (message == WM_PAINT)
5628 trace( "Got WM_PAINT, ignoring\n" );
5629 return 0;
5631 return MsgCheckProcA( hwnd, message, wParam, lParam );
5634 static void test_DispatchMessage(void)
5636 RECT rect;
5637 MSG msg;
5638 int count;
5639 HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
5640 100, 100, 200, 200, 0, 0, 0, NULL);
5641 ShowWindow( hwnd, SW_SHOW );
5642 UpdateWindow( hwnd );
5643 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5644 flush_sequence();
5645 SetWindowLongPtrA( hwnd, GWL_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
5647 SetRect( &rect, -5, -5, 5, 5 );
5648 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
5649 count = 0;
5650 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
5652 if (msg.message != WM_PAINT) DispatchMessage( &msg );
5653 else
5655 flush_sequence();
5656 DispatchMessage( &msg );
5657 /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
5658 if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
5659 else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
5660 if (++count > 10) break;
5663 ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
5665 trace("now without DispatchMessage\n");
5666 flush_sequence();
5667 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
5668 count = 0;
5669 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
5671 if (msg.message != WM_PAINT) DispatchMessage( &msg );
5672 else
5674 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
5675 flush_sequence();
5676 /* this will send WM_NCCPAINT just like DispatchMessage does */
5677 GetUpdateRgn( hwnd, hrgn, TRUE );
5678 ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
5679 DeleteObject( hrgn );
5680 GetClientRect( hwnd, &rect );
5681 ValidateRect( hwnd, &rect ); /* this will stop WM_PAINTs */
5682 ok( !count, "Got multiple WM_PAINTs\n" );
5683 if (++count > 10) break;
5689 START_TEST(msg)
5691 HMODULE user32 = GetModuleHandleA("user32.dll");
5692 FARPROC pSetWinEventHook = GetProcAddress(user32, "SetWinEventHook");
5693 FARPROC pUnhookWinEvent = GetProcAddress(user32, "UnhookWinEvent");
5694 FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
5695 pGetAncestor = (void*) GetProcAddress(user32, "GetAncestor");
5697 if (!RegisterWindowClasses()) assert(0);
5699 if (pSetWinEventHook)
5701 hEvent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
5702 GetModuleHandleA(0),
5703 win_event_proc,
5705 GetCurrentThreadId(),
5706 WINEVENT_INCONTEXT);
5707 assert(hEvent_hook);
5709 if (pIsWinEventHookInstalled)
5711 UINT event;
5712 for (event = EVENT_MIN; event <= EVENT_MAX; event++)
5713 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
5717 cbt_hook_thread_id = GetCurrentThreadId();
5718 hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
5719 assert(hCBT_hook);
5721 test_winevents();
5723 /* Fix message sequences before removing 3 lines below */
5724 ok(pUnhookWinEvent(hEvent_hook), "UnhookWinEvent error %ld\n", GetLastError());
5725 pUnhookWinEvent = 0;
5726 hEvent_hook = 0;
5728 test_scrollwindowex();
5729 test_messages();
5730 test_mdi_messages();
5731 test_button_messages();
5732 test_paint_messages();
5733 test_interthread_messages();
5734 test_message_conversion();
5735 test_accelerators();
5736 test_timers();
5737 test_set_hook();
5738 test_DestroyWindow();
5739 test_DispatchMessage();
5741 UnhookWindowsHookEx(hCBT_hook);
5742 if (pUnhookWinEvent)
5744 ok(pUnhookWinEvent(hEvent_hook), "UnhookWinEvent error %ld\n", GetLastError());
5745 SetLastError(0xdeadbeef);
5746 ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
5747 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
5748 GetLastError() == 0xdeadbeef, /* Win9x */
5749 "unexpected error %ld\n", GetLastError());