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
27 #define _WIN32_WINNT 0x0500 /* For WM_CHANGEUISTATE */
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
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[] =
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 },
94 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 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 },
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 },
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 },
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 },
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 },
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?
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 },
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 },
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 },
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 },
270 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 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 },
283 { WM_STYLECHANGING, sent },
284 { WM_STYLECHANGED, sent },
285 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 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 },
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 },
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 },
324 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
327 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
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 },
336 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
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 },
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 },
357 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
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 */
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 },
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 },
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 },
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 },
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 },
414 /* ShowWindow(SW_SHOW) for child with invisible parent */
415 static const struct message WmShowChildInvisibleParentSeq[] = {
416 { WM_SHOWWINDOW, sent|wparam, 1 },
419 /* ShowWindow(SW_HIDE) for child with invisible parent */
420 static const struct message WmHideChildInvisibleParentSeq[] = {
421 { WM_SHOWWINDOW, sent|wparam, 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 },
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 },
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 },
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 },
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 },
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 },
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 },
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 },
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 },
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 },
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 },
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 },
650 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 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 },
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 },
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 },
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 },
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 },
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 },
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 },
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 },
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 },
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 },
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 },
926 static const struct message WmSetRedrawFalseSeq[] =
928 { WM_SETREDRAW, sent|wparam, 0 },
932 static const struct message WmSetRedrawTrueSeq[] =
934 { WM_SETREDRAW, sent|wparam, 1 },
938 static const struct message WmEnableWindowSeq_1[] =
940 { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
941 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
942 { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
946 static const struct message WmEnableWindowSeq_2[] =
948 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
949 { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
953 static const struct message WmGetScrollRangeSeq[] =
955 { SBM_GETRANGE, sent },
958 static const struct message WmGetScrollInfoSeq[] =
960 { SBM_GETSCROLLINFO, sent },
963 static const struct message WmSetScrollRangeSeq[] =
965 /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
966 sends SBM_SETSCROLLINFO.
968 { SBM_SETSCROLLINFO, sent },
971 /* SetScrollRange for a window without a non-client area */
972 static const struct message WmSetScrollRangeHSeq_empty[] =
974 { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
977 static const struct message WmSetScrollRangeVSeq_empty[] =
979 { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
982 static const struct message WmSetScrollRangeHVSeq[] =
984 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER },
985 { WM_NCCALCSIZE, sent|wparam, 1 },
986 { WM_GETTEXT, sent|defwinproc|optional },
987 { WM_ERASEBKGND, sent|optional },
988 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
989 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
992 /* SetScrollRange for a window with a non-client area */
993 static const struct message WmSetScrollRangeHV_NC_Seq[] =
995 { WM_WINDOWPOSCHANGING, sent, /*|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER*/ },
996 { WM_NCCALCSIZE, sent|wparam, 1 },
997 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
998 { WM_NCPAINT, sent|optional },
999 { WM_GETTEXT, sent|defwinproc|optional },
1000 { WM_GETICON, sent|optional|defwinproc },
1001 { WM_GETICON, sent|optional|defwinproc },
1002 { WM_GETICON, sent|optional|defwinproc },
1003 { WM_GETTEXT, sent|defwinproc|optional },
1004 { WM_ERASEBKGND, sent|optional },
1005 { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1006 { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|0x1000*/ },
1007 { WM_SIZE, sent|defwinproc },
1008 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1009 { WM_GETTEXT, sent|optional },
1010 { WM_GETICON, sent|optional },
1011 { WM_GETICON, sent|optional },
1012 { WM_GETICON, sent|optional },
1013 { WM_GETTEXT, sent|optional },
1014 { WM_GETICON, sent|optional },
1015 { WM_GETICON, sent|optional },
1016 { WM_GETICON, sent|optional },
1017 { WM_GETTEXT, sent|optional },
1018 { WM_GETICON, sent|optional },
1019 { WM_GETICON, sent|optional },
1020 { WM_GETICON, sent|optional },
1021 { WM_GETTEXT, sent|optional },
1024 /* test if we receive the right sequence of messages */
1025 /* after calling ShowWindow( SW_SHOWNA) */
1026 static const struct message WmSHOWNAChildInvisParInvis[] = {
1027 { WM_SHOWWINDOW, sent|wparam, 1 },
1030 static const struct message WmSHOWNAChildVisParInvis[] = {
1031 { WM_SHOWWINDOW, sent|wparam, 1 },
1034 static const struct message WmSHOWNAChildVisParVis[] = {
1035 { WM_SHOWWINDOW, sent|wparam, 1 },
1036 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER },
1039 static const struct message WmSHOWNAChildInvisParVis[] = {
1040 { WM_SHOWWINDOW, sent|wparam, 1 },
1041 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER},
1042 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1043 { WM_ERASEBKGND, sent|optional },
1044 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
1047 static const struct message WmSHOWNATopVisible[] = {
1048 { WM_SHOWWINDOW, sent|wparam, 1 },
1049 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1052 static const struct message WmSHOWNATopInvisible[] = {
1053 { WM_SHOWWINDOW, sent|wparam, 1 },
1054 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1055 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1056 { WM_NCPAINT, sent|wparam, 1 },
1057 { WM_GETICON, sent|optional },
1058 { WM_GETICON, sent|optional },
1059 { WM_GETICON, sent|optional },
1060 { WM_GETTEXT, sent|defwinproc|optional },
1061 { WM_ERASEBKGND, sent|optional },
1062 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1063 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1064 { WM_NCPAINT, sent|wparam|optional, 1 },
1065 { WM_ERASEBKGND, sent|optional },
1071 static int after_end_dialog;
1072 static int sequence_cnt, sequence_size;
1073 static struct message* sequence;
1074 static int log_all_parent_messages;
1076 static void add_message(const struct message *msg)
1081 sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof (struct message) );
1083 if (sequence_cnt == sequence_size)
1086 sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof (struct message) );
1090 sequence[sequence_cnt].message = msg->message;
1091 sequence[sequence_cnt].flags = msg->flags;
1092 sequence[sequence_cnt].wParam = msg->wParam;
1093 sequence[sequence_cnt].lParam = msg->lParam;
1098 static void flush_sequence(void)
1100 HeapFree(GetProcessHeap(), 0, sequence);
1102 sequence_cnt = sequence_size = 0;
1105 #define ok_sequence( exp, contx, todo) \
1106 ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
1109 static void ok_sequence_(const struct message *expected, const char *context, int todo,
1110 const char *file, int line)
1112 static const struct message end_of_sequence = { 0, 0, 0, 0 };
1113 const struct message *actual;
1116 add_message(&end_of_sequence);
1120 while (expected->message && actual->message)
1122 trace_( file, line)("expected %04x - actual %04x\n", expected->message, actual->message);
1124 if (expected->message == actual->message)
1126 if (expected->flags & wparam)
1128 if (expected->wParam != actual->wParam && todo)
1132 ok_( file, line) (FALSE,
1133 "%s: in msg 0x%04x expecting wParam 0x%x got 0x%x\n",
1134 context, expected->message, expected->wParam, actual->wParam);
1138 ok_( file, line) (expected->wParam == actual->wParam,
1139 "%s: in msg 0x%04x expecting wParam 0x%x got 0x%x\n",
1140 context, expected->message, expected->wParam, actual->wParam);
1142 if (expected->flags & lparam)
1143 ok_( file, line) (expected->lParam == actual->lParam,
1144 "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1145 context, expected->message, expected->lParam, actual->lParam);
1146 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
1147 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1148 context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1149 ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
1150 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
1151 context, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
1152 ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
1153 "%s: the msg 0x%04x should have been %s\n",
1154 context, expected->message, (expected->flags & posted) ? "posted" : "sent");
1155 ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
1156 "%s: the msg 0x%04x was expected in %s\n",
1157 context, expected->message, (expected->flags & parent) ? "parent" : "child");
1158 ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
1159 "%s: the msg 0x%04x should have been sent by a hook\n",
1160 context, expected->message);
1161 ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
1162 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
1163 context, expected->message);
1167 /* silently drop winevent messages if there is no support for them */
1168 else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1174 ok_( file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
1175 context, expected->message, actual->message);
1182 ok_( file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
1183 context, expected->message, actual->message);
1189 /* skip all optional trailing messages */
1190 while (expected->message && ((expected->flags & optional) ||
1191 ((expected->flags & winevent_hook) && !hEvent_hook)))
1197 if (expected->message || actual->message) {
1199 ok_( file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
1200 context, expected->message, actual->message);
1206 if (expected->message || actual->message)
1207 ok_( file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
1208 context, expected->message, actual->message);
1210 if( todo && !failcount) /* succeeded yet marked todo */
1212 ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
1218 /******************************** MDI test **********************************/
1220 /* CreateWindow for MDI frame window, initially visible */
1221 static const struct message WmCreateMDIframeSeq[] = {
1222 { HCBT_CREATEWND, hook },
1223 { WM_GETMINMAXINFO, sent },
1224 { WM_NCCREATE, sent },
1225 { WM_NCCALCSIZE, sent|wparam, 0 },
1226 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1227 { WM_CREATE, sent },
1228 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1229 { WM_SHOWWINDOW, sent|wparam, 1 },
1230 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1231 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1232 { HCBT_ACTIVATE, hook },
1233 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1234 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1235 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1236 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* Win9x */
1237 { WM_ACTIVATEAPP, sent|wparam, 1 },
1238 { WM_NCACTIVATE, sent|wparam, 1 },
1239 { WM_GETTEXT, sent|defwinproc|optional },
1240 { WM_GETICON, sent|defwinproc|optional },
1241 { WM_GETICON, sent|defwinproc|optional },
1242 { WM_ACTIVATE, sent|wparam, 1 },
1243 { HCBT_SETFOCUS, hook },
1244 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1245 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1246 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
1247 /* Win9x adds SWP_NOZORDER below */
1248 { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
1253 /* DestroyWindow for MDI frame window, initially visible */
1254 static const struct message WmDestroyMDIframeSeq[] = {
1255 { HCBT_DESTROYWND, hook },
1256 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1257 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1258 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1259 { WM_NCACTIVATE, sent|wparam, 0 },
1260 { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
1261 { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
1262 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
1263 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1264 { WM_DESTROY, sent },
1265 { WM_NCDESTROY, sent },
1268 /* CreateWindow for MDI client window, initially visible */
1269 static const struct message WmCreateMDIclientSeq[] = {
1270 { HCBT_CREATEWND, hook },
1271 { WM_NCCREATE, sent },
1272 { WM_NCCALCSIZE, sent|wparam, 0 },
1273 { WM_CREATE, sent },
1274 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1277 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
1278 { WM_SHOWWINDOW, sent|wparam, 1 },
1279 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE|SWP_NOMOVE },
1280 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1281 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1284 /* DestroyWindow for MDI client window, initially visible */
1285 static const struct message WmDestroyMDIclientSeq[] = {
1286 { HCBT_DESTROYWND, hook },
1287 { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
1288 { WM_SHOWWINDOW, sent|wparam, 0 },
1289 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1290 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1291 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1292 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1293 { WM_DESTROY, sent },
1294 { WM_NCDESTROY, sent },
1297 /* CreateWindow for MDI child window, initially visible */
1298 static const struct message WmCreateMDIchildVisibleSeq[] = {
1299 { HCBT_CREATEWND, hook },
1300 { WM_NCCREATE, sent },
1301 { WM_NCCALCSIZE, sent|wparam, 0 },
1302 { WM_CREATE, sent },
1303 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1306 /* Win2k sends wparam set to
1307 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1308 * while Win9x doesn't bother to set child window id according to
1309 * CLIENTCREATESTRUCT.idFirstChild
1311 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1312 { WM_SHOWWINDOW, sent|wparam, 1 },
1313 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1314 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1315 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1316 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1317 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1318 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1319 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1321 /* Win9x: message sequence terminates here. */
1323 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1324 { HCBT_SETFOCUS, hook }, /* in MDI client */
1325 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1326 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1327 { WM_SETFOCUS, sent }, /* in MDI client */
1328 { HCBT_SETFOCUS, hook },
1329 { WM_KILLFOCUS, sent }, /* in MDI client */
1330 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1331 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1332 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1333 { WM_SETFOCUS, sent|defwinproc },
1334 { WM_MDIACTIVATE, sent|defwinproc },
1337 /* DestroyWindow for MDI child window, initially visible */
1338 static const struct message WmDestroyMDIchildVisibleSeq[] = {
1339 { HCBT_DESTROYWND, hook },
1340 /* Win2k sends wparam set to
1341 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1342 * while Win9x doesn't bother to set child window id according to
1343 * CLIENTCREATESTRUCT.idFirstChild
1345 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1346 { WM_SHOWWINDOW, sent|wparam, 0 },
1347 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1348 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1349 { WM_ERASEBKGND, sent|parent|optional },
1350 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1352 /* { WM_DESTROY, sent }
1353 * Win9x: message sequence terminates here.
1356 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1357 { WM_KILLFOCUS, sent },
1358 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1359 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1360 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1361 { WM_SETFOCUS, sent }, /* in MDI client */
1363 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1364 { WM_KILLFOCUS, sent }, /* in MDI client */
1365 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1366 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1367 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1368 { WM_SETFOCUS, sent }, /* in MDI client */
1370 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1372 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1373 { WM_KILLFOCUS, sent },
1374 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1375 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1376 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1377 { WM_SETFOCUS, sent }, /* in MDI client */
1379 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1380 { WM_KILLFOCUS, sent }, /* in MDI client */
1381 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1382 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1383 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1384 { WM_SETFOCUS, sent }, /* in MDI client */
1386 { WM_DESTROY, sent },
1388 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1389 { WM_KILLFOCUS, sent },
1390 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1391 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1392 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1393 { WM_SETFOCUS, sent }, /* in MDI client */
1395 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1396 { WM_KILLFOCUS, sent }, /* in MDI client */
1397 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1398 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1399 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1400 { WM_SETFOCUS, sent }, /* in MDI client */
1402 { WM_NCDESTROY, sent },
1405 /* CreateWindow for MDI child window, initially invisible */
1406 static const struct message WmCreateMDIchildInvisibleSeq[] = {
1407 { HCBT_CREATEWND, hook },
1408 { WM_NCCREATE, sent },
1409 { WM_NCCALCSIZE, sent|wparam, 0 },
1410 { WM_CREATE, sent },
1411 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1414 /* Win2k sends wparam set to
1415 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1416 * while Win9x doesn't bother to set child window id according to
1417 * CLIENTCREATESTRUCT.idFirstChild
1419 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1422 /* DestroyWindow for MDI child window, initially invisible */
1423 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
1424 { HCBT_DESTROYWND, hook },
1425 /* Win2k sends wparam set to
1426 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1427 * while Win9x doesn't bother to set child window id according to
1428 * CLIENTCREATESTRUCT.idFirstChild
1430 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1431 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1432 { WM_DESTROY, sent },
1433 { WM_NCDESTROY, sent },
1436 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
1437 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
1438 { HCBT_CREATEWND, hook },
1439 { WM_NCCREATE, sent },
1440 { WM_NCCALCSIZE, sent|wparam, 0 },
1441 { WM_CREATE, sent },
1442 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1445 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1446 { WM_GETMINMAXINFO, sent },
1447 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
1448 { WM_NCCALCSIZE, sent|wparam, 1 },
1449 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1450 { WM_SIZE, sent|defwinproc },
1452 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1453 { WM_NCCALCSIZE, sent|wparam, 1 },
1454 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1455 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1456 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1457 /* Win2k sends wparam set to
1458 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1459 * while Win9x doesn't bother to set child window id according to
1460 * CLIENTCREATESTRUCT.idFirstChild
1462 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1463 { WM_SHOWWINDOW, sent|wparam, 1 },
1464 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1465 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1466 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1467 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1468 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1469 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1470 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1472 /* Win9x: message sequence terminates here. */
1474 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1475 { HCBT_SETFOCUS, hook }, /* in MDI client */
1476 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1477 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1478 { WM_SETFOCUS, sent }, /* in MDI client */
1479 { HCBT_SETFOCUS, hook },
1480 { WM_KILLFOCUS, sent }, /* in MDI client */
1481 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1482 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1483 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1484 { WM_SETFOCUS, sent|defwinproc },
1485 { WM_MDIACTIVATE, sent|defwinproc },
1487 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1488 { WM_NCCALCSIZE, sent|wparam, 1 },
1489 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1490 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1493 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
1494 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
1495 /* restore the 1st MDI child */
1496 { WM_SETREDRAW, sent|wparam, 0 },
1497 { HCBT_MINMAX, hook },
1498 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
1499 { WM_NCCALCSIZE, sent|wparam, 1 },
1500 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1501 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1502 { WM_SIZE, sent|defwinproc },
1504 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1505 { WM_NCCALCSIZE, sent|wparam, 1 },
1506 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1507 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1508 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1509 { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
1510 /* create the 2nd MDI child */
1511 { HCBT_CREATEWND, hook },
1512 { WM_NCCREATE, sent },
1513 { WM_NCCALCSIZE, sent|wparam, 0 },
1514 { WM_CREATE, sent },
1515 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1518 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1519 { WM_GETMINMAXINFO, sent },
1520 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
1521 { WM_NCCALCSIZE, sent|wparam, 1 },
1522 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1523 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1524 { WM_SIZE, sent|defwinproc },
1526 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1527 { WM_NCCALCSIZE, sent|wparam, 1 },
1528 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1529 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1530 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1531 /* Win2k sends wparam set to
1532 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1533 * while Win9x doesn't bother to set child window id according to
1534 * CLIENTCREATESTRUCT.idFirstChild
1536 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1537 { WM_SHOWWINDOW, sent|wparam, 1 },
1538 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1539 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1540 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1541 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1542 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1543 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1545 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
1546 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
1548 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1550 /* Win9x: message sequence terminates here. */
1552 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1553 { HCBT_SETFOCUS, hook },
1554 { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
1555 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
1556 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1557 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1558 { WM_SETFOCUS, sent }, /* in MDI client */
1559 { HCBT_SETFOCUS, hook },
1560 { WM_KILLFOCUS, sent }, /* in MDI client */
1561 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1562 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1563 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1564 { WM_SETFOCUS, sent|defwinproc },
1566 { WM_MDIACTIVATE, sent|defwinproc },
1568 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1569 { WM_NCCALCSIZE, sent|wparam, 1 },
1570 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1571 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1574 /* WM_MDICREATE MDI child window, initially visible and maximized */
1575 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
1576 { WM_MDICREATE, sent },
1577 { HCBT_CREATEWND, hook },
1578 { WM_NCCREATE, sent },
1579 { WM_NCCALCSIZE, sent|wparam, 0 },
1580 { WM_CREATE, sent },
1581 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1584 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1585 { WM_GETMINMAXINFO, sent },
1586 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|0x8000 },
1587 { WM_NCCALCSIZE, sent|wparam, 1 },
1588 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1589 { WM_SIZE, sent|defwinproc },
1592 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1593 { WM_NCCALCSIZE, sent|wparam, 1 },
1594 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1595 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1596 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1598 /* Win2k sends wparam set to
1599 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1600 * while Win9x doesn't bother to set child window id according to
1601 * CLIENTCREATESTRUCT.idFirstChild
1603 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1604 { WM_SHOWWINDOW, sent|wparam, 1 },
1605 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1607 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1609 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1610 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1611 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1613 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1614 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1616 /* Win9x: message sequence terminates here. */
1618 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1619 { HCBT_SETFOCUS, hook }, /* in MDI client */
1620 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1621 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1622 { WM_SETFOCUS, sent }, /* in MDI client */
1623 { HCBT_SETFOCUS, hook },
1624 { WM_KILLFOCUS, sent }, /* in MDI client */
1625 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1626 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1627 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1628 { WM_SETFOCUS, sent|defwinproc },
1630 { WM_MDIACTIVATE, sent|defwinproc },
1633 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1634 { WM_NCCALCSIZE, sent|wparam, 1 },
1635 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1636 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1639 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1640 { WM_NCCALCSIZE, sent|wparam, 1 },
1641 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1642 { WM_MOVE, sent|defwinproc },
1643 { WM_SIZE, sent|defwinproc },
1646 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
1647 { WM_NCCALCSIZE, sent|wparam, 1 },
1648 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
1652 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
1653 { WM_NCCALCSIZE, sent|wparam, 1 },
1654 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
1655 { WM_SIZE, sent|defwinproc },
1657 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1658 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
1659 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1663 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
1664 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
1665 { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
1666 { HCBT_SYSCOMMAND, hook },
1667 { WM_CLOSE, sent|defwinproc },
1668 { WM_MDIDESTROY, sent }, /* in MDI client */
1670 /* bring the 1st MDI child to top */
1671 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
1672 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
1674 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1676 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
1677 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
1678 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
1680 /* maximize the 1st MDI child */
1681 { HCBT_MINMAX, hook },
1682 { WM_GETMINMAXINFO, sent|defwinproc },
1683 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|0x8000 },
1684 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1685 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
1686 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1687 { WM_SIZE, sent|defwinproc },
1689 /* restore the 2nd MDI child */
1690 { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
1691 { HCBT_MINMAX, hook },
1692 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOZORDER|0x8000 },
1693 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1695 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1697 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1698 { WM_SIZE, sent|defwinproc },
1700 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1702 { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
1704 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1705 { WM_NCCALCSIZE, sent|wparam, 1 },
1706 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1707 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1708 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1710 /* bring the 1st MDI child to top */
1711 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1712 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1713 { HCBT_SETFOCUS, hook },
1714 { WM_KILLFOCUS, sent|defwinproc },
1715 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
1716 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1717 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1718 { WM_SETFOCUS, sent }, /* in MDI client */
1719 { HCBT_SETFOCUS, hook },
1720 { WM_KILLFOCUS, sent }, /* in MDI client */
1721 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1722 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1723 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1724 { WM_SETFOCUS, sent|defwinproc },
1725 { WM_MDIACTIVATE, sent|defwinproc },
1726 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1728 /* apparently ShowWindow(SW_SHOW) on an MDI client */
1729 { WM_SHOWWINDOW, sent|wparam, 1 },
1730 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1731 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1732 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1733 { WM_MDIREFRESHMENU, sent },
1735 { HCBT_DESTROYWND, hook },
1736 /* Win2k sends wparam set to
1737 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1738 * while Win9x doesn't bother to set child window id according to
1739 * CLIENTCREATESTRUCT.idFirstChild
1741 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1742 { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
1743 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1744 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1745 { WM_ERASEBKGND, sent|parent|optional },
1746 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1748 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1749 { WM_DESTROY, sent|defwinproc },
1750 { WM_NCDESTROY, sent|defwinproc },
1753 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
1754 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
1755 { WM_MDIDESTROY, sent }, /* in MDI client */
1756 { WM_SHOWWINDOW, sent|wparam, 0 },
1757 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1758 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1759 { WM_ERASEBKGND, sent|parent|optional },
1760 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1762 { HCBT_SETFOCUS, hook },
1763 { WM_KILLFOCUS, sent },
1764 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1765 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1766 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1767 { WM_SETFOCUS, sent }, /* in MDI client */
1768 { HCBT_SETFOCUS, hook },
1769 { WM_KILLFOCUS, sent }, /* in MDI client */
1770 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1771 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1772 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1773 { WM_SETFOCUS, sent },
1776 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1777 { WM_NCCALCSIZE, sent|wparam, 1 },
1778 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1779 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1782 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1783 { WM_NCCALCSIZE, sent|wparam, 1 },
1784 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1785 { WM_MOVE, sent|defwinproc },
1786 { WM_SIZE, sent|defwinproc },
1789 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
1790 { WM_NCCALCSIZE, sent|wparam, 1 },
1791 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
1795 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
1796 { WM_NCCALCSIZE, sent|wparam, 1 },
1797 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
1798 { WM_SIZE, sent|defwinproc },
1801 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1802 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
1803 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1804 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1807 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1808 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
1809 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1810 { WM_MOVE, sent|defwinproc },
1811 { WM_SIZE, sent|defwinproc },
1814 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
1815 { WM_NCCALCSIZE, sent|wparam, 1 },
1816 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
1820 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOZORDER },
1821 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
1822 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
1823 { WM_SIZE, sent|defwinproc },
1824 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1825 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
1826 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1827 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1828 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
1829 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1832 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1833 { WM_NCCALCSIZE, sent|wparam, 1 },
1834 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1835 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1837 { WM_NCACTIVATE, sent|wparam, 0 },
1838 { WM_MDIACTIVATE, sent },
1840 { HCBT_MINMAX, hook },
1841 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|0x8000 },
1842 { WM_NCCALCSIZE, sent|wparam, 1 },
1844 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1846 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1847 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE|0x8000 },
1848 { WM_SIZE, sent|defwinproc },
1851 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1852 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
1853 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1854 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1857 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1858 { WM_NCCALCSIZE, sent|wparam, 1 },
1859 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1860 { WM_MOVE, sent|defwinproc },
1861 { WM_SIZE, sent|defwinproc },
1864 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOZORDER },
1865 { WM_NCCALCSIZE, sent|wparam, 1 },
1866 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTMOVE },
1868 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1869 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
1870 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1872 { HCBT_SETFOCUS, hook },
1873 { WM_KILLFOCUS, sent },
1874 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1875 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1876 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1877 { WM_SETFOCUS, sent }, /* in MDI client */
1879 { WM_MDIREFRESHMENU, sent }, /* in MDI client */
1881 { HCBT_DESTROYWND, hook },
1882 /* Win2k sends wparam set to
1883 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1884 * while Win9x doesn't bother to set child window id according to
1885 * CLIENTCREATESTRUCT.idFirstChild
1887 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1889 { WM_SHOWWINDOW, sent|wparam, 0 },
1890 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1891 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1892 { WM_ERASEBKGND, sent|parent|optional },
1893 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1895 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1896 { WM_DESTROY, sent },
1897 { WM_NCDESTROY, sent },
1900 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
1901 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
1902 { HCBT_MINMAX, hook },
1903 { WM_GETMINMAXINFO, sent },
1904 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
1905 { WM_NCCALCSIZE, sent|wparam, 1 },
1906 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1907 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1909 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1910 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1911 { HCBT_SETFOCUS, hook },
1912 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1913 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1914 { WM_SETFOCUS, sent }, /* in MDI client */
1915 { HCBT_SETFOCUS, hook },
1916 { WM_KILLFOCUS, sent }, /* in MDI client */
1917 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1918 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1919 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1920 { WM_SETFOCUS, sent|defwinproc },
1921 { WM_MDIACTIVATE, sent|defwinproc },
1922 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1923 { WM_SIZE, sent|defwinproc },
1925 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1926 { WM_NCCALCSIZE, sent|wparam, 1 },
1927 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1928 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1929 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1932 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
1933 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
1934 { HCBT_MINMAX, hook },
1935 { WM_GETMINMAXINFO, sent },
1936 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
1937 { WM_NCCALCSIZE, sent|wparam, 1 },
1938 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1939 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1940 { WM_SIZE, sent|defwinproc },
1942 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1943 { WM_NCCALCSIZE, sent|wparam, 1 },
1944 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1945 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1946 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1949 /* ShowWindow(SW_RESTORE) for a visible MDI child window */
1950 static const struct message WmRestoreMDIchildVisibleSeq[] = {
1951 { HCBT_MINMAX, hook },
1952 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|0x8000 },
1953 { WM_NCCALCSIZE, sent|wparam, 1 },
1954 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1955 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1956 { WM_SIZE, sent|defwinproc },
1958 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1959 { WM_NCCALCSIZE, sent|wparam, 1 },
1960 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1961 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1962 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1965 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
1966 static const struct message WmRestoreMDIchildInisibleSeq[] = {
1967 { HCBT_MINMAX, hook },
1968 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|0x8000 },
1969 { WM_NCCALCSIZE, sent|wparam, 1 },
1970 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1971 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1972 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|0x8000 },
1973 { WM_SIZE, sent|defwinproc },
1975 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER },
1976 { WM_NCCALCSIZE, sent|wparam, 1 },
1977 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1978 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
1979 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
1983 static HWND mdi_client;
1984 static WNDPROC old_mdi_client_proc;
1986 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
1990 /* do not log painting messages */
1991 if (message != WM_PAINT &&
1992 message != WM_ERASEBKGND &&
1993 message != WM_NCPAINT &&
1994 message != WM_NCHITTEST &&
1995 message != WM_GETTEXT &&
1996 message != WM_MDIGETACTIVE &&
1997 message != WM_DEVICECHANGE)
1999 trace("mdi client: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
2003 case WM_WINDOWPOSCHANGING:
2004 case WM_WINDOWPOSCHANGED:
2006 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2008 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2009 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2010 winpos->hwnd, winpos->hwndInsertAfter,
2011 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2013 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2014 * in the high word for internal purposes
2016 wParam = winpos->flags & 0xffff;
2021 msg.message = message;
2022 msg.flags = sent|wparam|lparam;
2023 msg.wParam = wParam;
2024 msg.lParam = lParam;
2028 return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
2031 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2033 static long defwndproc_counter = 0;
2037 /* do not log painting messages */
2038 if (message != WM_PAINT &&
2039 message != WM_ERASEBKGND &&
2040 message != WM_NCPAINT &&
2041 message != WM_NCHITTEST &&
2042 message != WM_GETTEXT &&
2043 message != WM_DEVICECHANGE)
2045 trace("mdi child: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
2049 case WM_WINDOWPOSCHANGING:
2050 case WM_WINDOWPOSCHANGED:
2052 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2054 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2055 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2056 winpos->hwnd, winpos->hwndInsertAfter,
2057 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2059 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2060 * in the high word for internal purposes
2062 wParam = winpos->flags & 0xffff;
2066 case WM_MDIACTIVATE:
2068 HWND active, client = GetParent(hwnd);
2070 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
2072 if (hwnd == (HWND)lParam) /* if we are being activated */
2073 ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
2075 ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
2080 msg.message = message;
2081 msg.flags = sent|wparam|lparam;
2082 if (defwndproc_counter) msg.flags |= defwinproc;
2083 msg.wParam = wParam;
2084 msg.lParam = lParam;
2088 defwndproc_counter++;
2089 ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
2090 defwndproc_counter--;
2095 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2097 static long defwndproc_counter = 0;
2101 /* do not log painting messages */
2102 if (message != WM_PAINT &&
2103 message != WM_ERASEBKGND &&
2104 message != WM_NCPAINT &&
2105 message != WM_NCHITTEST &&
2106 message != WM_GETTEXT &&
2107 message != WM_DEVICECHANGE)
2109 trace("mdi frame: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
2113 case WM_WINDOWPOSCHANGING:
2114 case WM_WINDOWPOSCHANGED:
2116 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2118 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2119 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2120 winpos->hwnd, winpos->hwndInsertAfter,
2121 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2123 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2124 * in the high word for internal purposes
2126 wParam = winpos->flags & 0xffff;
2131 msg.message = message;
2132 msg.flags = sent|wparam|lparam;
2133 if (defwndproc_counter) msg.flags |= defwinproc;
2134 msg.wParam = wParam;
2135 msg.lParam = lParam;
2139 defwndproc_counter++;
2140 ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
2141 defwndproc_counter--;
2146 static BOOL mdi_RegisterWindowClasses(void)
2151 cls.lpfnWndProc = mdi_frame_wnd_proc;
2154 cls.hInstance = GetModuleHandleA(0);
2156 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
2157 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
2158 cls.lpszMenuName = NULL;
2159 cls.lpszClassName = "MDI_frame_class";
2160 if (!RegisterClassA(&cls)) return FALSE;
2162 cls.lpfnWndProc = mdi_child_wnd_proc;
2163 cls.lpszClassName = "MDI_child_class";
2164 if (!RegisterClassA(&cls)) return FALSE;
2166 if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
2167 old_mdi_client_proc = cls.lpfnWndProc;
2168 cls.hInstance = GetModuleHandleA(0);
2169 cls.lpfnWndProc = mdi_client_hook_proc;
2170 cls.lpszClassName = "MDI_client_class";
2171 if (!RegisterClassA(&cls)) assert(0);
2176 static void test_mdi_messages(void)
2178 MDICREATESTRUCTA mdi_cs;
2179 CLIENTCREATESTRUCT client_cs;
2180 HWND mdi_frame, mdi_child, mdi_child2, active_child;
2182 HMENU hMenu = CreateMenu();
2184 assert(mdi_RegisterWindowClasses());
2188 trace("creating MDI frame window\n");
2189 mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
2190 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2191 WS_MAXIMIZEBOX | WS_VISIBLE,
2192 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
2193 GetDesktopWindow(), hMenu,
2194 GetModuleHandleA(0), NULL);
2196 ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", TRUE);
2198 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2199 ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
2201 trace("creating MDI client window\n");
2202 client_cs.hWindowMenu = 0;
2203 client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
2204 mdi_client = CreateWindowExA(0, "MDI_client_class",
2206 WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
2208 mdi_frame, 0, GetModuleHandleA(0), &client_cs);
2210 ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
2212 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2213 ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
2215 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2216 ok(!active_child, "wrong active MDI child %p\n", active_child);
2217 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2222 trace("creating invisible MDI child window\n");
2223 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2225 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2226 mdi_client, 0, GetModuleHandleA(0), NULL);
2230 ShowWindow(mdi_child, SW_SHOWNORMAL);
2231 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
2233 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2234 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
2236 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2237 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2239 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2240 ok(!active_child, "wrong active MDI child %p\n", active_child);
2241 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2243 ShowWindow(mdi_child, SW_HIDE);
2244 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
2247 ShowWindow(mdi_child, SW_SHOW);
2248 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
2250 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2251 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
2253 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2254 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2256 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2257 ok(!active_child, "wrong active MDI child %p\n", active_child);
2258 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2260 DestroyWindow(mdi_child);
2263 trace("creating visible MDI child window\n");
2264 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2265 WS_CHILD | WS_VISIBLE,
2266 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2267 mdi_client, 0, GetModuleHandleA(0), NULL);
2269 ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
2271 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2272 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
2274 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2275 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
2277 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2278 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
2279 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2282 DestroyWindow(mdi_child);
2283 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
2285 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2286 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2288 /* Win2k: MDI client still returns a just destroyed child as active
2289 * Win9x: MDI client returns 0
2291 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2292 ok(active_child == mdi_child || /* win2k */
2293 !active_child, /* win9x */
2294 "wrong active MDI child %p\n", active_child);
2295 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2299 trace("creating invisible MDI child window\n");
2300 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2302 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2303 mdi_client, 0, GetModuleHandleA(0), NULL);
2305 ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
2307 ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
2308 ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
2310 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2311 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2313 /* Win2k: MDI client still returns a just destroyed child as active
2314 * Win9x: MDI client returns mdi_child2
2316 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2317 ok(active_child == mdi_child || /* win2k */
2318 active_child == mdi_child2, /* win9x */
2319 "wrong active MDI child %p\n", active_child);
2320 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2323 ShowWindow(mdi_child2, SW_MAXIMIZE);
2324 ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", TRUE);
2326 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2327 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
2329 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2330 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
2331 ok(zoomed, "wrong zoomed state %d\n", zoomed);
2334 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2335 ok(GetFocus() == mdi_child2 || /* win2k */
2336 GetFocus() == 0, /* win9x */
2337 "wrong focus window %p\n", GetFocus());
2342 ShowWindow(mdi_child2, SW_HIDE);
2343 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
2345 ShowWindow(mdi_child2, SW_RESTORE);
2346 ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", TRUE);
2349 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
2350 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
2352 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2353 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
2354 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
2360 ShowWindow(mdi_child2, SW_HIDE);
2361 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
2363 ShowWindow(mdi_child2, SW_SHOW);
2364 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
2366 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2367 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2369 ShowWindow(mdi_child2, SW_MAXIMIZE);
2370 ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", TRUE);
2372 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2373 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2375 ShowWindow(mdi_child2, SW_RESTORE);
2376 ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):MDI child", TRUE);
2378 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2379 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2384 ShowWindow(mdi_child2, SW_HIDE);
2385 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
2387 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2388 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2390 DestroyWindow(mdi_child2);
2391 ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
2393 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2394 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2396 /* test for maximized MDI children */
2397 trace("creating maximized visible MDI child window 1\n");
2398 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2399 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
2400 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2401 mdi_client, 0, GetModuleHandleA(0), NULL);
2403 ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
2404 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
2406 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2407 ok(GetFocus() == mdi_child || /* win2k */
2408 GetFocus() == 0, /* win9x */
2409 "wrong focus window %p\n", GetFocus());
2411 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2412 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
2413 ok(zoomed, "wrong zoomed state %d\n", zoomed);
2416 trace("creating maximized visible MDI child window 2\n");
2417 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2418 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
2419 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2420 mdi_client, 0, GetModuleHandleA(0), NULL);
2422 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
2423 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
2424 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
2426 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2427 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
2429 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2430 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
2431 ok(zoomed, "wrong zoomed state %d\n", zoomed);
2434 trace("destroying maximized visible MDI child window 2\n");
2435 DestroyWindow(mdi_child2);
2436 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
2438 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
2440 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2441 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2443 /* Win2k: MDI client still returns a just destroyed child as active
2444 * Win9x: MDI client returns 0
2446 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2447 ok(active_child == mdi_child2 || /* win2k */
2448 !active_child, /* win9x */
2449 "wrong active MDI child %p\n", active_child);
2452 ShowWindow(mdi_child, SW_MAXIMIZE);
2453 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
2456 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2457 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
2459 trace("re-creating maximized visible MDI child window 2\n");
2460 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
2461 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
2462 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
2463 mdi_client, 0, GetModuleHandleA(0), NULL);
2465 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
2466 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
2467 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
2469 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2470 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
2472 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2473 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
2474 ok(zoomed, "wrong zoomed state %d\n", zoomed);
2477 SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
2478 ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
2479 ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
2481 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
2482 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2483 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
2485 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2486 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
2487 ok(zoomed, "wrong zoomed state %d\n", zoomed);
2490 DestroyWindow(mdi_child);
2491 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
2493 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2494 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2496 /* Win2k: MDI client still returns a just destroyed child as active
2497 * Win9x: MDI client returns 0
2499 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2500 ok(active_child == mdi_child || /* win2k */
2501 !active_child, /* win9x */
2502 "wrong active MDI child %p\n", active_child);
2504 /* end of test for maximized MDI children */
2506 mdi_cs.szClass = "MDI_child_Class";
2507 mdi_cs.szTitle = "MDI child";
2508 mdi_cs.hOwner = GetModuleHandleA(0);
2511 mdi_cs.cx = CW_USEDEFAULT;
2512 mdi_cs.cy = CW_USEDEFAULT;
2513 mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
2515 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
2516 ok(mdi_child != 0, "MDI child creation failed\n");
2517 ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
2519 ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
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);
2524 ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
2525 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2526 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
2528 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2529 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
2530 ok(zoomed, "wrong zoomed state %d\n", zoomed);
2533 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
2534 ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
2536 ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
2537 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
2538 ok(!active_child, "wrong active MDI child %p\n", active_child);
2543 DestroyWindow(mdi_client);
2544 ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
2546 DestroyWindow(mdi_frame);
2547 ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
2549 /************************* End of MDI test **********************************/
2551 static void test_WM_SETREDRAW(HWND hwnd)
2553 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
2557 SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
2558 ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
2560 ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
2561 ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
2564 SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
2565 ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
2567 ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
2568 ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
2570 /* restore original WS_VISIBLE state */
2571 SetWindowLongA(hwnd, GWL_STYLE, style);
2576 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2580 trace("dialog: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
2584 case WM_WINDOWPOSCHANGING:
2585 case WM_WINDOWPOSCHANGED:
2587 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2589 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2590 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2591 winpos->hwnd, winpos->hwndInsertAfter,
2592 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2594 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2595 * in the high word for internal purposes
2597 wParam = winpos->flags & 0xffff;
2602 msg.message = message;
2603 msg.flags = sent|wparam|lparam;
2604 msg.wParam = wParam;
2605 msg.lParam = lParam;
2608 if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
2609 if (message == WM_TIMER) EndDialog( hwnd, 0 );
2613 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
2615 DWORD style, exstyle;
2619 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
2620 style = GetWindowLongA(hwnd, GWL_STYLE);
2621 /* do not be confused by WS_DLGFRAME set */
2622 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
2624 if (clear) ok(style & clear, "style %08lx should be set\n", clear);
2625 if (set) ok(!(style & set), "style %08lx should not be set\n", set);
2627 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
2628 ok( ret, "SetScrollRange(%d) error %ld\n", ctl, GetLastError());
2629 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
2630 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
2632 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
2634 style = GetWindowLongA(hwnd, GWL_STYLE);
2635 if (set) ok(style & set, "style %08lx should be set\n", set);
2636 if (clear) ok(!(style & clear), "style %08lx should not be set\n", clear);
2638 /* a subsequent call should do nothing */
2639 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
2640 ok( ret, "SetScrollRange(%d) error %ld\n", ctl, GetLastError());
2641 ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
2645 trace("Ignore GetScrollRange error below if you are on Win9x\n");
2646 ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
2647 ok( ret, "GetScrollRange(%d) error %ld\n", ctl, GetLastError());
2648 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
2649 ok(xmin == min, "unexpected min scroll value %d\n", xmin);
2650 ok(xmax == max, "unexpected max scroll value %d\n", xmax);
2653 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
2655 DWORD style, exstyle;
2659 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
2660 style = GetWindowLongA(hwnd, GWL_STYLE);
2661 /* do not be confused by WS_DLGFRAME set */
2662 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
2664 if (clear) ok(style & clear, "style %08lx should be set\n", clear);
2665 if (set) ok(!(style & set), "style %08lx should not be set\n", set);
2667 si.cbSize = sizeof(si);
2668 si.fMask = SIF_RANGE;
2671 SetScrollInfo(hwnd, ctl, &si, TRUE);
2672 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
2673 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
2675 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
2677 style = GetWindowLongA(hwnd, GWL_STYLE);
2678 if (set) ok(style & set, "style %08lx should be set\n", set);
2679 if (clear) ok(!(style & clear), "style %08lx should not be set\n", clear);
2681 /* a subsequent call should do nothing */
2682 SetScrollInfo(hwnd, ctl, &si, TRUE);
2683 if (style & WS_HSCROLL)
2684 ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
2685 else if (style & WS_VSCROLL)
2686 ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
2688 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
2690 si.fMask = SIF_PAGE;
2692 SetScrollInfo(hwnd, ctl, &si, FALSE);
2693 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
2697 SetScrollInfo(hwnd, ctl, &si, FALSE);
2698 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
2700 si.fMask = SIF_RANGE;
2701 si.nMin = 0xdeadbeef;
2702 si.nMax = 0xdeadbeef;
2703 ret = GetScrollInfo(hwnd, ctl, &si);
2704 ok( ret, "GetScrollInfo error %ld\n", GetLastError());
2705 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
2706 ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
2707 ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
2710 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
2711 static void test_scroll_messages(HWND hwnd)
2719 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
2720 ok( ret, "GetScrollRange error %ld\n", GetLastError());
2721 if (sequence->message != WmGetScrollRangeSeq[0].message)
2722 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
2723 /* values of min and max are undefined */
2726 ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
2727 ok( ret, "SetScrollRange error %ld\n", GetLastError());
2728 if (sequence->message != WmSetScrollRangeSeq[0].message)
2729 trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
2734 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
2735 ok( ret, "GetScrollRange error %ld\n", GetLastError());
2736 if (sequence->message != WmGetScrollRangeSeq[0].message)
2737 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
2738 /* values of min and max are undefined */
2741 si.cbSize = sizeof(si);
2742 si.fMask = SIF_RANGE;
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);
2750 si.fMask = SIF_PAGE;
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);
2759 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
2760 if (sequence->message != WmSetScrollRangeSeq[0].message)
2761 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
2764 si.fMask = SIF_RANGE;
2765 si.nMin = 0xdeadbeef;
2766 si.nMax = 0xdeadbeef;
2767 ret = GetScrollInfo(hwnd, SB_CTL, &si);
2768 ok( ret, "GetScrollInfo error %ld\n", GetLastError());
2769 if (sequence->message != WmGetScrollInfoSeq[0].message)
2770 trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
2771 /* values of min and max are undefined */
2774 /* set WS_HSCROLL */
2775 test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
2776 /* clear WS_HSCROLL */
2777 test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
2779 /* set WS_HSCROLL */
2780 test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
2781 /* clear WS_HSCROLL */
2782 test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
2784 /* set WS_VSCROLL */
2785 test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
2786 /* clear WS_VSCROLL */
2787 test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
2789 /* set WS_VSCROLL */
2790 test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
2791 /* clear WS_VSCROLL */
2792 test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
2795 static void test_showwindow(void)
2799 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
2800 100, 100, 200, 200, 0, 0, 0, NULL);
2801 ok (hwnd != 0, "Failed to create overlapped window\n");
2802 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
2803 0, 0, 10, 10, hwnd, 0, 0, NULL);
2804 ok (hchild != 0, "Failed to create child\n");
2807 /* ShowWindow( SW_SHOWNA) for invisible top level window */
2808 trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
2809 ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
2810 ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", TRUE);
2813 /* ShowWindow( SW_SHOWNA) for now visible top level window */
2814 trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
2815 ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
2816 ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
2818 /* back to invisible */
2819 ShowWindow(hchild, SW_HIDE);
2820 ShowWindow(hwnd, SW_HIDE);
2822 /* ShowWindow(SW_SHOWNA) with child and parent invisible */
2823 trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
2824 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
2825 ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", TRUE);
2827 /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */
2828 ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
2830 trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
2831 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
2832 ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", TRUE);
2834 /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
2835 ShowWindow( hwnd, SW_SHOW);
2837 trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
2838 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
2839 ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
2842 /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
2843 ShowWindow( hchild, SW_HIDE);
2845 trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
2846 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
2847 ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
2851 ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
2852 DestroyWindow(hchild);
2853 ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
2855 DestroyWindow(hwnd);
2859 static void test_sys_menu(HWND hwnd)
2864 /* test existing window without CS_NOCLOSE style */
2865 hmenu = GetSystemMenu(hwnd, FALSE);
2866 ok(hmenu != 0, "GetSystemMenu error %ld\n", GetLastError());
2868 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
2869 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
2870 ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
2872 EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
2873 ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
2875 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
2876 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
2877 ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
2879 EnableMenuItem(hmenu, SC_CLOSE, 0);
2880 ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
2882 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
2883 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
2884 ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
2886 /* test new window with CS_NOCLOSE style */
2887 hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
2888 100, 100, 200, 200, 0, 0, 0, NULL);
2889 ok (hwnd != 0, "Failed to create overlapped window\n");
2891 hmenu = GetSystemMenu(hwnd, FALSE);
2892 ok(hmenu != 0, "GetSystemMenu error %ld\n", GetLastError());
2894 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
2895 ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
2897 DestroyWindow(hwnd);
2900 /* test if we receive the right sequence of messages */
2901 static void test_messages(void)
2903 HWND hwnd, hparent, hchild;
2904 HWND hchild2, hbutton;
2911 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
2912 100, 100, 200, 200, 0, 0, 0, NULL);
2913 ok (hwnd != 0, "Failed to create overlapped window\n");
2914 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
2916 /* test ShowWindow(SW_HIDE) on a newly created invisible window */
2917 ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
2918 ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
2920 /* test WM_SETREDRAW on a not visible top level window */
2921 test_WM_SETREDRAW(hwnd);
2923 SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
2924 ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
2925 ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
2927 ok(GetActiveWindow() == hwnd, "window should be active\n");
2928 ok(GetFocus() == hwnd, "window should have input focus\n");
2929 ShowWindow(hwnd, SW_HIDE);
2930 ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", TRUE);
2932 ShowWindow(hwnd, SW_SHOW);
2933 ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
2935 ShowWindow(hwnd, SW_SHOW);
2936 ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
2938 ok(GetActiveWindow() == hwnd, "window should be active\n");
2939 ok(GetFocus() == hwnd, "window should have input focus\n");
2940 SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
2941 ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
2942 ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
2943 ok(GetActiveWindow() == hwnd, "window should still be active\n");
2945 /* test WM_SETREDRAW on a visible top level window */
2946 ShowWindow(hwnd, SW_SHOW);
2947 test_WM_SETREDRAW(hwnd);
2949 trace("testing scroll APIs on a visible top level window %p\n", hwnd);
2950 test_scroll_messages(hwnd);
2952 /* test resizing and moving */
2953 SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE );
2954 ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
2955 SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE );
2956 ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
2958 /* popups don't get WM_GETMINMAXINFO */
2959 SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
2960 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
2962 SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE );
2963 ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
2965 test_sys_menu(hwnd);
2968 DestroyWindow(hwnd);
2969 ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
2971 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
2972 100, 100, 200, 200, 0, 0, 0, NULL);
2973 ok (hparent != 0, "Failed to create parent window\n");
2976 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
2977 0, 0, 10, 10, hparent, 0, 0, NULL);
2978 ok (hchild != 0, "Failed to create child window\n");
2979 ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", TRUE);
2980 DestroyWindow(hchild);
2983 /* visible child window with a caption */
2984 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
2985 WS_CHILD | WS_VISIBLE | WS_CAPTION,
2986 0, 0, 10, 10, hparent, 0, 0, NULL);
2987 ok (hchild != 0, "Failed to create child window\n");
2988 ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
2990 trace("testing scroll APIs on a visible child window %p\n", hchild);
2991 test_scroll_messages(hchild);
2993 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
2994 ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
2996 DestroyWindow(hchild);
2999 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
3000 0, 0, 10, 10, hparent, 0, 0, NULL);
3001 ok (hchild != 0, "Failed to create child window\n");
3002 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
3004 hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
3005 100, 100, 50, 50, hparent, 0, 0, NULL);
3006 ok (hchild2 != 0, "Failed to create child2 window\n");
3009 hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
3010 0, 100, 50, 50, hchild, 0, 0, NULL);
3011 ok (hbutton != 0, "Failed to create button window\n");
3013 /* test WM_SETREDRAW on a not visible child window */
3014 test_WM_SETREDRAW(hchild);
3016 ShowWindow(hchild, SW_SHOW);
3017 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
3019 ShowWindow(hchild, SW_HIDE);
3020 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
3022 ShowWindow(hchild, SW_SHOW);
3023 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
3025 /* test WM_SETREDRAW on a visible child window */
3026 test_WM_SETREDRAW(hchild);
3028 MoveWindow(hchild, 10, 10, 20, 20, TRUE);
3029 ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
3031 ShowWindow(hchild, SW_HIDE);
3033 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
3034 ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
3036 ShowWindow(hchild, SW_HIDE);
3038 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
3039 ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
3041 /* DestroyWindow sequence below expects that a child has focus */
3045 DestroyWindow(hchild);
3046 ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
3047 DestroyWindow(hchild2);
3048 DestroyWindow(hbutton);
3051 hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
3052 0, 0, 100, 100, hparent, 0, 0, NULL);
3053 ok (hchild != 0, "Failed to create child popup window\n");
3054 ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
3055 DestroyWindow(hchild);
3057 /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
3059 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
3060 0, 0, 100, 100, hparent, 0, 0, NULL);
3061 ok (hchild != 0, "Failed to create popup window\n");
3062 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
3063 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3064 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
3066 ShowWindow(hchild, SW_SHOW);
3067 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
3069 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
3070 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
3072 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
3073 ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
3074 DestroyWindow(hchild);
3076 /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
3077 * changes nothing in message sequences.
3080 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
3081 0, 0, 100, 100, hparent, 0, 0, NULL);
3082 ok (hchild != 0, "Failed to create popup window\n");
3083 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
3084 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3085 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
3087 ShowWindow(hchild, SW_SHOW);
3088 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
3090 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
3091 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
3092 DestroyWindow(hchild);
3095 hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
3096 0, 0, 100, 100, hparent, 0, 0, NULL);
3097 ok(hwnd != 0, "Failed to create custom dialog window\n");
3098 ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
3101 trace("testing scroll APIs on a visible dialog %p\n", hwnd);
3102 test_scroll_messages(hwnd);
3106 after_end_dialog = 1;
3107 EndDialog( hwnd, 0 );
3108 ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
3110 DestroyWindow(hwnd);
3111 after_end_dialog = 0;
3113 hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
3114 0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
3115 ok(hwnd != 0, "Failed to create custom dialog window\n");
3117 trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
3118 ShowWindow(hwnd, SW_SHOW);
3119 ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
3120 DestroyWindow(hwnd);
3123 DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
3124 ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
3126 /* test showing child with hidden parent */
3127 ShowWindow( hparent, SW_HIDE );
3130 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
3131 0, 0, 10, 10, hparent, 0, 0, NULL);
3132 ok (hchild != 0, "Failed to create child window\n");
3133 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
3135 ShowWindow( hchild, SW_SHOW );
3136 ok_sequence(WmShowChildInvisibleParentSeq, "ShowWindow:show child with invisible parent", TRUE);
3137 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3138 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
3140 ShowWindow( hchild, SW_HIDE );
3141 ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", TRUE);
3142 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
3143 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
3145 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
3146 ok_sequence(WmShowChildInvisibleParentSeq_2, "SetWindowPos:show child with invisible parent", FALSE);
3147 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3148 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
3150 SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
3151 ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
3152 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
3153 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
3155 DestroyWindow(hchild);
3156 DestroyWindow(hparent);
3159 /* Message sequence for SetMenu */
3160 ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
3161 ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
3163 hmenu = CreateMenu();
3164 ok (hmenu != 0, "Failed to create menu\n");
3165 ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
3166 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
3167 100, 100, 200, 200, 0, hmenu, 0, NULL);
3168 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
3169 ok (SetMenu(hwnd, 0), "SetMenu\n");
3170 ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
3171 ok (SetMenu(hwnd, 0), "SetMenu\n");
3172 ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
3173 ShowWindow(hwnd, SW_SHOW);
3175 ok (SetMenu(hwnd, 0), "SetMenu\n");
3176 ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", TRUE);
3177 ok (SetMenu(hwnd, hmenu), "SetMenu\n");
3178 ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", TRUE);
3180 ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
3181 ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", TRUE);
3183 DestroyWindow(hwnd);
3186 /* Message sequence for EnableWindow */
3187 hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3188 100, 100, 200, 200, 0, 0, 0, NULL);
3189 ok (hparent != 0, "Failed to create parent window\n");
3190 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
3191 0, 0, 10, 10, hparent, 0, 0, NULL);
3192 ok (hchild != 0, "Failed to create child window\n");
3197 EnableWindow(hparent, FALSE);
3198 ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
3200 EnableWindow(hparent, TRUE);
3201 ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
3203 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3206 /* MsgWaitForMultipleObjects test */
3207 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3208 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %lx\n", ret);
3210 PostMessageA(hparent, WM_USER, 0, 0);
3212 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3213 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %lx\n", ret);
3215 ok(PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
3216 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
3218 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
3219 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %lx\n", ret);
3220 /* end of MsgWaitForMultipleObjects test */
3222 /* the following test causes an exception in user.exe under win9x */
3223 if (!PostMessageW( hparent, WM_USER, 0, 0 )) return;
3224 PostMessageW( hparent, WM_USER+1, 0, 0 );
3225 /* PeekMessage(NULL) fails, but still removes the message */
3226 SetLastError(0xdeadbeef);
3227 ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
3228 ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
3229 GetLastError() == 0xdeadbeef, /* NT4 */
3230 "last error is %ld\n", GetLastError() );
3231 ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
3232 ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
3234 DestroyWindow(hchild);
3235 DestroyWindow(hparent);
3241 /****************** button message test *************************/
3242 static const struct message WmSetFocusButtonSeq[] =
3244 { HCBT_SETFOCUS, hook },
3245 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3246 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3247 { WM_SETFOCUS, sent|wparam, 0 },
3248 { WM_CTLCOLORBTN, sent|defwinproc },
3251 static const struct message WmKillFocusButtonSeq[] =
3253 { HCBT_SETFOCUS, hook },
3254 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3255 { WM_KILLFOCUS, sent|wparam, 0 },
3256 { WM_CTLCOLORBTN, sent|defwinproc },
3257 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
3260 static const struct message WmSetFocusStaticSeq[] =
3262 { HCBT_SETFOCUS, hook },
3263 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3264 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3265 { WM_SETFOCUS, sent|wparam, 0 },
3266 { WM_CTLCOLORSTATIC, sent|defwinproc },
3269 static const struct message WmKillFocusStaticSeq[] =
3271 { HCBT_SETFOCUS, hook },
3272 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3273 { WM_KILLFOCUS, sent|wparam, 0 },
3274 { WM_CTLCOLORSTATIC, sent|defwinproc },
3275 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
3278 static const struct message WmLButtonDownSeq[] =
3280 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
3281 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
3282 { HCBT_SETFOCUS, hook },
3283 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3284 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3285 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
3286 { WM_CTLCOLORBTN, sent|defwinproc },
3287 { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
3288 { WM_CTLCOLORBTN, sent|defwinproc },
3289 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3292 static const struct message WmLButtonUpSeq[] =
3294 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
3295 { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
3296 { WM_CTLCOLORBTN, sent|defwinproc },
3297 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3298 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
3299 { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
3303 static WNDPROC old_button_proc;
3305 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3307 static long defwndproc_counter = 0;
3311 trace("button: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
3313 msg.message = message;
3314 msg.flags = sent|wparam|lparam;
3315 if (defwndproc_counter) msg.flags |= defwinproc;
3316 msg.wParam = wParam;
3317 msg.lParam = lParam;
3320 if (message == BM_SETSTATE)
3321 ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
3323 defwndproc_counter++;
3324 ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
3325 defwndproc_counter--;
3330 static void subclass_button(void)
3334 if (!GetClassInfoA(0, "button", &cls)) assert(0);
3336 old_button_proc = cls.lpfnWndProc;
3338 cls.hInstance = GetModuleHandle(0);
3339 cls.lpfnWndProc = button_hook_proc;
3340 cls.lpszClassName = "my_button_class";
3341 if (!RegisterClassA(&cls)) assert(0);
3344 static void test_button_messages(void)
3350 const struct message *setfocus;
3351 const struct message *killfocus;
3353 { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
3354 WmSetFocusButtonSeq, WmKillFocusButtonSeq },
3355 { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
3356 WmSetFocusButtonSeq, WmKillFocusButtonSeq },
3357 { BS_CHECKBOX, DLGC_BUTTON,
3358 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3359 { BS_AUTOCHECKBOX, DLGC_BUTTON,
3360 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3361 { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
3362 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3363 { BS_3STATE, DLGC_BUTTON,
3364 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3365 { BS_AUTO3STATE, DLGC_BUTTON,
3366 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3367 { BS_GROUPBOX, DLGC_STATIC,
3368 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3369 { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
3370 WmSetFocusButtonSeq, WmKillFocusButtonSeq },
3371 { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
3372 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
3373 { BS_OWNERDRAW, DLGC_BUTTON,
3374 WmSetFocusButtonSeq, WmKillFocusButtonSeq }
3382 for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
3384 hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_POPUP,
3385 0, 0, 50, 14, 0, 0, 0, NULL);
3386 ok(hwnd != 0, "Failed to create button window\n");
3388 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
3389 ok(dlg_code == button[i].dlg_code, "%d: wrong dlg_code %08lx\n", i, dlg_code);
3391 ShowWindow(hwnd, SW_SHOW);
3396 trace("button style %08lx\n", button[i].style);
3398 ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
3401 ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
3403 DestroyWindow(hwnd);
3406 hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
3407 0, 0, 50, 14, 0, 0, 0, NULL);
3408 ok(hwnd != 0, "Failed to create button window\n");
3413 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
3414 ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
3416 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
3417 ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
3418 DestroyWindow(hwnd);
3421 /************* painting message test ********************/
3423 void dump_region(HRGN hrgn)
3426 RGNDATA *data = NULL;
3431 printf( "null region\n" );
3434 if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
3435 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
3436 GetRegionData( hrgn, size, data );
3437 printf("%ld rects:", data->rdh.nCount );
3438 for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
3439 printf( " (%ld,%ld)-(%ld,%ld)", rect->left, rect->top, rect->right, rect->bottom );
3441 HeapFree( GetProcessHeap(), 0, data );
3444 static void check_update_rgn( HWND hwnd, HRGN hrgn )
3448 HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
3449 HRGN update = CreateRectRgn( 0, 0, 0, 0 );
3451 ret = GetUpdateRgn( hwnd, update, FALSE );
3452 ok( ret != ERROR, "GetUpdateRgn failed\n" );
3453 if (ret == NULLREGION)
3455 ok( !hrgn, "Update region shouldn't be empty\n" );
3459 if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
3461 ok( 0, "Regions are different\n" );
3462 if (winetest_debug > 0)
3464 printf( "Update region: " );
3465 dump_region( update );
3466 printf( "Wanted region: " );
3467 dump_region( hrgn );
3471 GetRgnBox( update, &r1 );
3472 GetUpdateRect( hwnd, &r2, FALSE );
3473 ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
3474 "Rectangles are different: %ld,%ld-%ld,%ld / %ld,%ld-%ld,%ld\n",
3475 r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
3477 DeleteObject( tmp );
3478 DeleteObject( update );
3481 static const struct message WmInvalidateRgn[] = {
3482 { WM_NCPAINT, sent },
3483 { WM_GETTEXT, sent|defwinproc|optional },
3487 static const struct message WmGetUpdateRect[] = {
3488 { WM_NCPAINT, sent },
3489 { WM_GETTEXT, sent|defwinproc|optional },
3494 static const struct message WmInvalidateFull[] = {
3495 { WM_NCPAINT, sent|wparam, 1 },
3496 { WM_GETTEXT, sent|defwinproc|optional },
3500 static const struct message WmInvalidateErase[] = {
3501 { WM_NCPAINT, sent|wparam, 1 },
3502 { WM_GETTEXT, sent|defwinproc|optional },
3503 { WM_ERASEBKGND, sent },
3507 static const struct message WmInvalidatePaint[] = {
3509 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
3510 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
3514 static const struct message WmInvalidateErasePaint[] = {
3516 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
3517 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
3518 { WM_ERASEBKGND, sent|beginpaint },
3522 static const struct message WmInvalidateErasePaint2[] = {
3524 { WM_NCPAINT, sent|beginpaint },
3525 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
3526 { WM_ERASEBKGND, sent|beginpaint },
3530 static const struct message WmErase[] = {
3531 { WM_ERASEBKGND, sent },
3535 static const struct message WmPaint[] = {
3540 static const struct message WmParentOnlyPaint[] = {
3541 { WM_PAINT, sent|parent },
3545 static const struct message WmInvalidateParent[] = {
3546 { WM_NCPAINT, sent|parent },
3547 { WM_GETTEXT, sent|defwinproc|parent|optional },
3548 { WM_ERASEBKGND, sent|parent },
3552 static const struct message WmInvalidateParentChild[] = {
3553 { WM_NCPAINT, sent|parent },
3554 { WM_GETTEXT, sent|defwinproc|parent|optional },
3555 { WM_ERASEBKGND, sent|parent },
3556 { WM_NCPAINT, sent },
3557 { WM_GETTEXT, sent|defwinproc|optional },
3558 { WM_ERASEBKGND, sent },
3562 static const struct message WmInvalidateParentChild2[] = {
3563 { WM_ERASEBKGND, sent|parent },
3564 { WM_NCPAINT, sent },
3565 { WM_GETTEXT, sent|defwinproc|optional },
3566 { WM_ERASEBKGND, sent },
3570 static const struct message WmParentPaint[] = {
3571 { WM_PAINT, sent|parent },
3576 static const struct message WmParentPaintNc[] = {
3577 { WM_PAINT, sent|parent },
3579 { WM_NCPAINT, sent|beginpaint },
3580 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
3581 { WM_ERASEBKGND, sent|beginpaint },
3585 static const struct message WmChildPaintNc[] = {
3587 { WM_NCPAINT, sent|beginpaint },
3588 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
3589 { WM_ERASEBKGND, sent|beginpaint },
3593 static const struct message WmParentErasePaint[] = {
3594 { WM_PAINT, sent|parent },
3595 { WM_NCPAINT, sent|parent|beginpaint },
3596 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
3597 { WM_ERASEBKGND, sent|parent|beginpaint },
3599 { WM_NCPAINT, sent|beginpaint },
3600 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
3601 { WM_ERASEBKGND, sent|beginpaint },
3605 static const struct message WmParentOnlyNcPaint[] = {
3606 { WM_PAINT, sent|parent },
3607 { WM_NCPAINT, sent|parent|beginpaint },
3608 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
3612 static const struct message WmSetParentStyle[] = {
3613 { WM_STYLECHANGING, sent|parent },
3614 { WM_STYLECHANGED, sent|parent },
3618 static void test_paint_messages(void)
3623 HWND hparent, hchild;
3624 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3625 HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
3626 HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
3627 100, 100, 200, 200, 0, 0, 0, NULL);
3628 ok (hwnd != 0, "Failed to create overlapped window\n");
3630 ShowWindow( hwnd, SW_SHOW );
3631 UpdateWindow( hwnd );
3633 /* try to flush pending X expose events */
3634 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
3635 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3637 check_update_rgn( hwnd, 0 );
3638 SetRectRgn( hrgn, 10, 10, 20, 20 );
3639 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
3640 check_update_rgn( hwnd, hrgn );
3641 SetRectRgn( hrgn2, 20, 20, 30, 30 );
3642 RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
3643 CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
3644 check_update_rgn( hwnd, hrgn );
3645 /* validate everything */
3646 RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
3647 check_update_rgn( hwnd, 0 );
3648 /* now with frame */
3649 SetRectRgn( hrgn, -5, -5, 20, 20 );
3651 /* flush pending messages */
3652 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3655 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
3656 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
3658 SetRectRgn( hrgn, 0, 0, 20, 20 ); /* GetUpdateRgn clips to client area */
3659 check_update_rgn( hwnd, hrgn );
3662 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
3663 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
3666 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
3667 ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
3669 GetClientRect( hwnd, &rect );
3670 SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
3671 check_update_rgn( hwnd, hrgn );
3674 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
3675 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
3678 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
3679 ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
3680 check_update_rgn( hwnd, 0 );
3683 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
3684 ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
3685 check_update_rgn( hwnd, 0 );
3688 SetRectRgn( hrgn, 0, 0, 100, 100 );
3689 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
3690 SetRectRgn( hrgn, 0, 0, 50, 100 );
3691 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
3692 SetRectRgn( hrgn, 50, 0, 100, 100 );
3693 check_update_rgn( hwnd, hrgn );
3694 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
3695 ok_sequence( WmEmptySeq, "EmptySeq", FALSE ); /* must not generate messages, everything is valid */
3696 check_update_rgn( hwnd, 0 );
3699 SetRectRgn( hrgn, 0, 0, 100, 100 );
3700 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
3701 SetRectRgn( hrgn, 0, 0, 100, 50 );
3702 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
3703 ok_sequence( WmErase, "Erase", FALSE );
3704 SetRectRgn( hrgn, 0, 50, 100, 100 );
3705 check_update_rgn( hwnd, hrgn );
3708 SetRectRgn( hrgn, 0, 0, 100, 100 );
3709 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
3710 SetRectRgn( hrgn, 0, 0, 50, 50 );
3711 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
3712 ok_sequence( WmPaint, "Paint", FALSE );
3715 SetRectRgn( hrgn, -4, -4, -2, -2 );
3716 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
3717 SetRectRgn( hrgn, -200, -200, -198, -198 );
3718 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
3719 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
3722 SetRectRgn( hrgn, -4, -4, -2, -2 );
3723 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
3724 SetRectRgn( hrgn, -4, -4, -3, -3 );
3725 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
3726 SetRectRgn( hrgn, 0, 0, 1, 1 );
3727 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
3728 ok_sequence( WmPaint, "Paint", FALSE );
3731 SetRectRgn( hrgn, -4, -4, -1, -1 );
3732 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
3733 RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
3734 /* make sure no WM_PAINT was generated */
3735 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3736 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
3739 SetRectRgn( hrgn, -4, -4, -1, -1 );
3740 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
3741 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
3743 if (msg.hwnd == hwnd && msg.message == WM_PAINT)
3745 /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
3746 INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
3747 ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
3748 ret = GetUpdateRect( hwnd, &rect, FALSE );
3749 ok( ret, "Invalid GetUpdateRect result %d\n", ret );
3750 /* this will send WM_NCPAINT and validate the non client area */
3751 ret = GetUpdateRect( hwnd, &rect, TRUE );
3752 ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
3754 DispatchMessage( &msg );
3756 ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
3758 DestroyWindow( hwnd );
3760 /* now test with a child window */
3762 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
3763 100, 100, 200, 200, 0, 0, 0, NULL);
3764 ok (hparent != 0, "Failed to create parent window\n");
3766 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
3767 10, 10, 100, 100, hparent, 0, 0, NULL);
3768 ok (hchild != 0, "Failed to create child window\n");
3770 ShowWindow( hparent, SW_SHOW );
3771 UpdateWindow( hparent );
3772 UpdateWindow( hchild );
3773 /* try to flush pending X expose events */
3774 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
3775 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3778 log_all_parent_messages++;
3780 SetRect( &rect, 0, 0, 50, 50 );
3781 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
3782 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
3783 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
3785 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
3787 MapWindowPoints( hchild, hparent, &pt, 1 );
3788 SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
3789 check_update_rgn( hchild, hrgn );
3790 SetRectRgn( hrgn, 0, 0, 50, 50 );
3791 check_update_rgn( hparent, hrgn );
3792 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
3793 ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
3794 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
3795 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
3797 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3798 ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
3800 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
3801 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
3802 ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
3803 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
3804 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
3806 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
3807 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
3808 ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
3810 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
3812 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
3813 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
3814 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
3816 /* flush all paint messages */
3817 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3820 /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
3821 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
3822 SetRectRgn( hrgn, 0, 0, 50, 50 );
3823 check_update_rgn( hparent, hrgn );
3824 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
3825 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
3826 SetRectRgn( hrgn, 0, 0, 50, 50 );
3827 check_update_rgn( hparent, hrgn );
3829 /* flush all paint messages */
3830 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3831 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
3834 /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
3835 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
3836 SetRectRgn( hrgn, 0, 0, 50, 50 );
3837 check_update_rgn( hparent, hrgn );
3838 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
3839 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
3840 SetRectRgn( hrgn2, 10, 10, 50, 50 );
3841 CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
3842 check_update_rgn( hparent, hrgn );
3843 /* flush all paint messages */
3844 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3847 /* same as above but parent gets completely validated */
3848 SetRect( &rect, 20, 20, 30, 30 );
3849 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
3850 SetRectRgn( hrgn, 20, 20, 30, 30 );
3851 check_update_rgn( hparent, hrgn );
3852 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
3853 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
3854 check_update_rgn( hparent, 0 ); /* no update region */
3855 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3856 ok_sequence( WmEmptySeq, "WmEmpty", FALSE ); /* and no paint messages */
3858 /* make sure RDW_VALIDATE on child doesn't have the same effect */
3860 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
3861 SetRectRgn( hrgn, 20, 20, 30, 30 );
3862 check_update_rgn( hparent, hrgn );
3863 RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
3864 SetRectRgn( hrgn, 20, 20, 30, 30 );
3865 check_update_rgn( hparent, hrgn );
3867 /* same as above but normal WM_PAINT doesn't validate parent */
3869 SetRect( &rect, 20, 20, 30, 30 );
3870 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
3871 SetRectRgn( hrgn, 20, 20, 30, 30 );
3872 check_update_rgn( hparent, hrgn );
3873 /* no WM_PAINT in child while parent still pending */
3874 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3875 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
3876 while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3877 ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
3880 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
3881 /* no WM_PAINT in child while parent still pending */
3882 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3883 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
3884 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
3885 /* now that parent is valid child should get WM_PAINT */
3886 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3887 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
3888 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3889 ok_sequence( WmEmptySeq, "No other message", FALSE );
3891 /* same thing with WS_CLIPCHILDREN in parent */
3893 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
3894 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
3895 /* changing style invalidates non client area, but we need to invalidate something else to see it */
3896 RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
3897 ok_sequence( WmEmptySeq, "No message", FALSE );
3898 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
3899 ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
3902 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
3903 SetRectRgn( hrgn, 20, 20, 30, 30 );
3904 check_update_rgn( hparent, hrgn );
3905 /* no WM_PAINT in child while parent still pending */
3906 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3907 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
3908 /* WM_PAINT in parent first */
3909 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3910 ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
3912 /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
3914 SetRect( &rect, 0, 0, 30, 30 );
3915 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
3916 SetRectRgn( hrgn, 0, 0, 30, 30 );
3917 check_update_rgn( hparent, hrgn );
3918 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3919 ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
3921 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
3923 SetRect( &rect, -10, 0, 30, 30 );
3924 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
3925 SetRect( &rect, 0, 0, 20, 20 );
3926 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
3927 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
3928 ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
3930 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
3932 SetRect( &rect, -10, 0, 30, 30 );
3933 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
3934 SetRect( &rect, 0, 0, 100, 100 );
3935 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
3936 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
3937 ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
3938 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
3939 ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
3941 /* test RDW_INTERNALPAINT behavior */
3944 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
3945 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3946 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
3948 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
3949 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3950 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
3952 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
3953 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3954 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
3956 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
3957 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
3958 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
3959 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
3960 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
3962 log_all_parent_messages--;
3963 DestroyWindow( hparent );
3964 ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
3966 DeleteObject( hrgn );
3967 DeleteObject( hrgn2 );
3976 static DWORD WINAPI thread_proc(void *param)
3979 struct wnd_event *wnd_event = (struct wnd_event *)param;
3981 wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
3982 100, 100, 200, 200, 0, 0, 0, NULL);
3983 ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
3985 SetEvent(wnd_event->event);
3987 while (GetMessage(&msg, 0, 0, 0))
3989 TranslateMessage(&msg);
3990 DispatchMessage(&msg);
3993 ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
3998 static void test_interthread_messages(void)
4005 int len, expected_len;
4006 struct wnd_event wnd_event;
4009 wnd_event.event = CreateEventW(NULL, 0, 0, NULL);
4010 if (!wnd_event.event)
4012 trace("skipping interthread message test under win9x\n");
4016 hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
4017 ok(hThread != NULL, "CreateThread failed, error %ld\n", GetLastError());
4019 ok(WaitForSingleObject(wnd_event.event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
4021 CloseHandle(wnd_event.event);
4023 SetLastError(0xdeadbeef);
4024 ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
4025 ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error code %ld\n", GetLastError());
4027 proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
4028 ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %ld\n", GetLastError());
4030 expected_len = lstrlenA("window caption text");
4031 memset(buf, 0, sizeof(buf));
4032 SetLastError(0xdeadbeef);
4033 len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
4034 ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %ld, len %d, expected len %d\n", GetLastError(), len, expected_len);
4035 ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
4037 msg.hwnd = wnd_event.hwnd;
4038 msg.message = WM_GETTEXT;
4039 msg.wParam = sizeof(buf);
4040 msg.lParam = (LPARAM)buf;
4041 memset(buf, 0, sizeof(buf));
4042 SetLastError(0xdeadbeef);
4043 len = DispatchMessageA(&msg);
4044 ok(!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY,
4045 "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %ld\n", len, GetLastError());
4047 /* the following test causes an exception in user.exe under win9x */
4048 msg.hwnd = wnd_event.hwnd;
4049 msg.message = WM_TIMER;
4051 msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
4052 SetLastError(0xdeadbeef);
4053 len = DispatchMessageA(&msg);
4054 ok(!len && GetLastError() == 0xdeadbeef,
4055 "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %ld\n", len, GetLastError());
4057 ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
4058 ok( ret, "PostMessageA(WM_QUIT) error %ld\n", GetLastError());
4060 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
4061 CloseHandle(hThread);
4063 ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
4067 static const struct message WmVkN[] = {
4068 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
4069 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
4070 { WM_CHAR, wparam|lparam, 'n', 1 },
4071 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
4072 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
4073 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
4076 static const struct message WmShiftVkN[] = {
4077 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
4078 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
4079 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
4080 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
4081 { WM_CHAR, wparam|lparam, 'N', 1 },
4082 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
4083 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
4084 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
4085 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
4086 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
4089 static const struct message WmCtrlVkN[] = {
4090 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
4091 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
4092 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
4093 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
4094 { WM_CHAR, wparam|lparam, 0x000e, 1 },
4095 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
4096 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
4097 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
4098 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
4099 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
4102 static const struct message WmCtrlVkN_2[] = {
4103 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
4104 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
4105 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
4106 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
4107 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
4108 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
4109 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
4110 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
4113 static const struct message WmAltVkN[] = {
4114 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
4115 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
4116 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
4117 { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
4118 { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
4119 { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
4120 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
4121 { HCBT_SYSCOMMAND, hook },
4122 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
4123 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
4124 { WM_INITMENU, sent|defwinproc },
4125 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
4126 { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
4127 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
4128 { WM_CAPTURECHANGED, sent|defwinproc },
4129 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
4130 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
4131 { WM_EXITMENULOOP, sent|defwinproc },
4132 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
4133 { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
4134 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
4135 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
4136 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4137 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4140 static const struct message WmAltVkN_2[] = {
4141 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
4142 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
4143 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
4144 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
4145 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
4146 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
4147 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4148 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4151 static const struct message WmCtrlAltVkN[] = {
4152 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
4153 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
4154 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
4155 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
4156 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
4157 { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
4158 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
4159 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
4160 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4161 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4162 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
4163 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
4166 static const struct message WmCtrlShiftVkN[] = {
4167 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
4168 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
4169 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
4170 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
4171 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
4172 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
4173 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
4174 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
4175 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
4176 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
4177 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
4178 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
4181 static const struct message WmCtrlAltShiftVkN[] = {
4182 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
4183 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
4184 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
4185 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
4186 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
4187 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
4188 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
4189 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
4190 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
4191 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
4192 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
4193 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
4194 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4195 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4196 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
4197 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
4200 static const struct message WmAltPressRelease[] = {
4201 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
4202 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
4203 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4204 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4205 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
4206 { HCBT_SYSCOMMAND, hook },
4207 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
4208 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
4209 { WM_INITMENU, sent|defwinproc },
4210 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
4211 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
4212 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
4214 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
4215 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
4216 { WM_CAPTURECHANGED, sent|defwinproc },
4217 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
4218 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
4219 { WM_EXITMENULOOP, sent|defwinproc },
4220 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4221 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4224 static const struct message WmAltMouseButton[] = {
4225 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
4226 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
4227 { WM_MOUSEMOVE, wparam|optional, 0, 0 },
4228 { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
4229 { WM_LBUTTONDOWN, wparam, MK_LBUTTON, 0 },
4230 { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON, 0 },
4231 { WM_LBUTTONUP, wparam, 0, 0 },
4232 { WM_LBUTTONUP, sent|wparam, 0, 0 },
4233 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
4234 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
4238 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
4242 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
4244 struct message log_msg;
4246 trace("accel: %p, %04x, %08x, %08lx\n", msg.hwnd, msg.message, msg.wParam, msg.lParam);
4248 /* ignore some unwanted messages */
4249 if (msg.message == WM_MOUSEMOVE ||
4250 msg.message == WM_DEVICECHANGE)
4253 log_msg.message = msg.message;
4254 log_msg.flags = wparam|lparam;
4255 log_msg.wParam = msg.wParam;
4256 log_msg.lParam = msg.lParam;
4257 add_message(&log_msg);
4259 if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
4261 TranslateMessage(&msg);
4262 DispatchMessage(&msg);
4267 static void test_accelerators(void)
4272 HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4273 100, 100, 200, 200, 0, 0, 0, NULL);
4279 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
4281 state = GetKeyState(VK_SHIFT);
4282 ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
4283 state = GetKeyState(VK_CAPITAL);
4284 ok(state == 0, "wrong CapsLock state %04x\n", state);
4286 hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
4287 assert(hAccel != 0);
4289 pump_msg_loop(hwnd, 0);
4292 trace("testing VK_N press/release\n");
4294 keybd_event('N', 0, 0, 0);
4295 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4296 pump_msg_loop(hwnd, hAccel);
4297 ok_sequence(WmVkN, "VK_N press/release", FALSE);
4299 trace("testing Shift+VK_N press/release\n");
4301 keybd_event(VK_SHIFT, 0, 0, 0);
4302 keybd_event('N', 0, 0, 0);
4303 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4304 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
4305 pump_msg_loop(hwnd, hAccel);
4306 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
4308 trace("testing Ctrl+VK_N press/release\n");
4310 keybd_event(VK_CONTROL, 0, 0, 0);
4311 keybd_event('N', 0, 0, 0);
4312 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4313 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
4314 pump_msg_loop(hwnd, hAccel);
4315 ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
4317 trace("testing Alt+VK_N press/release\n");
4319 keybd_event(VK_MENU, 0, 0, 0);
4320 keybd_event('N', 0, 0, 0);
4321 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4322 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4323 pump_msg_loop(hwnd, hAccel);
4324 ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
4326 trace("testing Ctrl+Alt+VK_N press/release 1\n");
4328 keybd_event(VK_CONTROL, 0, 0, 0);
4329 keybd_event(VK_MENU, 0, 0, 0);
4330 keybd_event('N', 0, 0, 0);
4331 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4332 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4333 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
4334 pump_msg_loop(hwnd, hAccel);
4335 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
4337 ret = DestroyAcceleratorTable(hAccel);
4338 ok( ret, "DestroyAcceleratorTable error %ld\n", GetLastError());
4340 hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
4341 assert(hAccel != 0);
4343 trace("testing VK_N press/release\n");
4345 keybd_event('N', 0, 0, 0);
4346 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4347 pump_msg_loop(hwnd, hAccel);
4348 ok_sequence(WmVkN, "VK_N press/release", FALSE);
4350 trace("testing Shift+VK_N press/release\n");
4352 keybd_event(VK_SHIFT, 0, 0, 0);
4353 keybd_event('N', 0, 0, 0);
4354 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4355 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
4356 pump_msg_loop(hwnd, hAccel);
4357 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
4359 trace("testing Ctrl+VK_N press/release 2\n");
4361 keybd_event(VK_CONTROL, 0, 0, 0);
4362 keybd_event('N', 0, 0, 0);
4363 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4364 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
4365 pump_msg_loop(hwnd, hAccel);
4366 ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
4368 trace("testing Alt+VK_N press/release 2\n");
4370 keybd_event(VK_MENU, 0, 0, 0);
4371 keybd_event('N', 0, 0, 0);
4372 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4373 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4374 pump_msg_loop(hwnd, hAccel);
4375 ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
4377 trace("testing Ctrl+Alt+VK_N press/release 2\n");
4379 keybd_event(VK_CONTROL, 0, 0, 0);
4380 keybd_event(VK_MENU, 0, 0, 0);
4381 keybd_event('N', 0, 0, 0);
4382 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4383 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4384 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
4385 pump_msg_loop(hwnd, hAccel);
4386 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
4388 trace("testing Ctrl+Shift+VK_N press/release\n");
4390 keybd_event(VK_CONTROL, 0, 0, 0);
4391 keybd_event(VK_SHIFT, 0, 0, 0);
4392 keybd_event('N', 0, 0, 0);
4393 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4394 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
4395 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
4396 pump_msg_loop(hwnd, hAccel);
4397 ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
4399 trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
4401 keybd_event(VK_CONTROL, 0, 0, 0);
4402 keybd_event(VK_MENU, 0, 0, 0);
4403 keybd_event(VK_SHIFT, 0, 0, 0);
4404 keybd_event('N', 0, 0, 0);
4405 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
4406 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
4407 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4408 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
4409 pump_msg_loop(hwnd, hAccel);
4410 ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
4412 ret = DestroyAcceleratorTable(hAccel);
4413 ok( ret, "DestroyAcceleratorTable error %ld\n", GetLastError());
4415 trace("testing Alt press/release\n");
4417 keybd_event(VK_MENU, 0, 0, 0);
4418 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4419 keybd_event(VK_MENU, 0, 0, 0);
4420 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4421 pump_msg_loop(hwnd, 0);
4422 /* this test doesn't pass in Wine for managed windows */
4423 ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
4425 trace("testing Alt+MouseButton press/release\n");
4426 /* first, move mouse pointer inside of the window client area */
4427 GetClientRect(hwnd, &rc);
4428 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
4429 rc.left += (rc.right - rc.left)/2;
4430 rc.top += (rc.bottom - rc.top)/2;
4431 SetCursorPos(rc.left, rc.top);
4433 pump_msg_loop(hwnd, 0);
4435 keybd_event(VK_MENU, 0, 0, 0);
4436 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
4437 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
4438 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
4439 pump_msg_loop(hwnd, 0);
4440 ok_sequence(WmAltMouseButton, "Alt+MouseButton press/release", FALSE);
4442 DestroyWindow(hwnd);
4445 /************* window procedures ********************/
4447 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4449 static long defwndproc_counter = 0;
4450 static long beginpaint_counter = 0;
4454 trace("%p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
4460 LONG style = GetWindowLongA(hwnd, GWL_STYLE);
4461 ok((BOOL)wParam == !(style & WS_DISABLED),
4462 "wrong WS_DISABLED state: %d != %d\n", wParam, !(style & WS_DISABLED));
4466 case WM_CAPTURECHANGED:
4467 if (test_DestroyWindow_flag)
4469 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
4470 if (style & WS_CHILD)
4471 lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
4472 else if (style & WS_POPUP)
4473 lParam = WND_POPUP_ID;
4475 lParam = WND_PARENT_ID;
4483 ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
4484 capture = GetCapture();
4487 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
4488 trace("current capture %p, releasing...\n", capture);
4495 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
4496 if (test_DestroyWindow_flag)
4498 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
4499 if (style & WS_CHILD)
4500 lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
4501 else if (style & WS_POPUP)
4502 lParam = WND_POPUP_ID;
4504 lParam = WND_PARENT_ID;
4508 /* test_accelerators() depends on this */
4515 case WM_DEVICECHANGE:
4518 case WM_WINDOWPOSCHANGING:
4519 case WM_WINDOWPOSCHANGED:
4521 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
4523 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
4524 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
4525 winpos->hwnd, winpos->hwndInsertAfter,
4526 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
4528 /* Log only documented flags, win2k uses 0x1000 and 0x2000
4529 * in the high word for internal purposes
4531 wParam = winpos->flags & 0xffff;
4536 msg.message = message;
4537 msg.flags = sent|wparam|lparam;
4538 if (defwndproc_counter) msg.flags |= defwinproc;
4539 if (beginpaint_counter) msg.flags |= beginpaint;
4540 msg.wParam = wParam;
4541 msg.lParam = lParam;
4544 if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
4546 HWND parent = GetParent(hwnd);
4548 MINMAXINFO *minmax = (MINMAXINFO *)lParam;
4550 GetClientRect(parent, &rc);
4551 trace("parent %p client size = (%ld x %ld)\n", parent, rc.right, rc.bottom);
4553 trace("ptReserved = (%ld,%ld)\n"
4554 "ptMaxSize = (%ld,%ld)\n"
4555 "ptMaxPosition = (%ld,%ld)\n"
4556 "ptMinTrackSize = (%ld,%ld)\n"
4557 "ptMaxTrackSize = (%ld,%ld)\n",
4558 minmax->ptReserved.x, minmax->ptReserved.y,
4559 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
4560 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
4561 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
4562 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
4564 ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %ld != %ld\n",
4565 minmax->ptMaxSize.x, rc.right);
4566 ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %ld != %ld\n",
4567 minmax->ptMaxSize.y, rc.bottom);
4570 if (message == WM_PAINT)
4573 beginpaint_counter++;
4574 BeginPaint( hwnd, &ps );
4575 beginpaint_counter--;
4576 EndPaint( hwnd, &ps );
4580 defwndproc_counter++;
4581 ret = DefWindowProcA(hwnd, message, wParam, lParam);
4582 defwndproc_counter--;
4587 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4589 static long defwndproc_counter = 0;
4593 trace("popup: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
4595 msg.message = message;
4596 msg.flags = sent|wparam|lparam;
4597 if (defwndproc_counter) msg.flags |= defwinproc;
4598 msg.wParam = wParam;
4599 msg.lParam = lParam;
4602 if (message == WM_CREATE)
4604 DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
4605 SetWindowLongA(hwnd, GWL_STYLE, style);
4608 defwndproc_counter++;
4609 ret = DefWindowProcA(hwnd, message, wParam, lParam);
4610 defwndproc_counter--;
4615 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4617 static long defwndproc_counter = 0;
4618 static long beginpaint_counter = 0;
4622 trace("parent: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
4624 if (log_all_parent_messages ||
4625 message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
4626 message == WM_SETFOCUS || message == WM_KILLFOCUS ||
4627 message == WM_ENABLE || message == WM_ENTERIDLE ||
4628 message == WM_IME_SETCONTEXT)
4630 msg.message = message;
4631 msg.flags = sent|parent|wparam|lparam;
4632 if (defwndproc_counter) msg.flags |= defwinproc;
4633 if (beginpaint_counter) msg.flags |= beginpaint;
4634 msg.wParam = wParam;
4635 msg.lParam = lParam;
4639 if (message == WM_PAINT)
4642 beginpaint_counter++;
4643 BeginPaint( hwnd, &ps );
4644 beginpaint_counter--;
4645 EndPaint( hwnd, &ps );
4649 defwndproc_counter++;
4650 ret = DefWindowProcA(hwnd, message, wParam, lParam);
4651 defwndproc_counter--;
4656 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4658 static long defwndproc_counter = 0;
4662 trace("dialog: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
4664 DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
4665 ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
4666 if (after_end_dialog)
4667 ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
4669 ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
4673 case WM_WINDOWPOSCHANGING:
4674 case WM_WINDOWPOSCHANGED:
4676 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
4678 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
4679 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
4680 winpos->hwnd, winpos->hwndInsertAfter,
4681 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
4683 /* Log only documented flags, win2k uses 0x1000 and 0x2000
4684 * in the high word for internal purposes
4686 wParam = winpos->flags & 0xffff;
4691 msg.message = message;
4692 msg.flags = sent|wparam|lparam;
4693 if (defwndproc_counter) msg.flags |= defwinproc;
4694 msg.wParam = wParam;
4695 msg.lParam = lParam;
4698 defwndproc_counter++;
4699 ret = DefDlgProcA(hwnd, message, wParam, lParam);
4700 defwndproc_counter--;
4705 static BOOL RegisterWindowClasses(void)
4710 cls.lpfnWndProc = MsgCheckProcA;
4713 cls.hInstance = GetModuleHandleA(0);
4715 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
4716 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4717 cls.lpszMenuName = NULL;
4718 cls.lpszClassName = "TestWindowClass";
4719 if(!RegisterClassA(&cls)) return FALSE;
4721 cls.lpfnWndProc = PopupMsgCheckProcA;
4722 cls.lpszClassName = "TestPopupClass";
4723 if(!RegisterClassA(&cls)) return FALSE;
4725 cls.lpfnWndProc = ParentMsgCheckProcA;
4726 cls.lpszClassName = "TestParentClass";
4727 if(!RegisterClassA(&cls)) return FALSE;
4729 cls.lpfnWndProc = DefWindowProcA;
4730 cls.lpszClassName = "SimpleWindowClass";
4731 if(!RegisterClassA(&cls)) return FALSE;
4733 cls.style = CS_NOCLOSE;
4734 cls.lpszClassName = "NoCloseWindowClass";
4735 if(!RegisterClassA(&cls)) return FALSE;
4737 ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
4739 cls.hInstance = GetModuleHandleA(0);
4740 cls.hbrBackground = 0;
4741 cls.lpfnWndProc = TestDlgProcA;
4742 cls.lpszClassName = "TestDialogClass";
4743 if(!RegisterClassA(&cls)) return FALSE;
4748 static HHOOK hCBT_hook;
4749 static DWORD cbt_hook_thread_id;
4751 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
4753 static const char *CBT_code_name[10] = {
4760 "HCBT_CLICKSKIPPED",
4764 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
4768 trace("CBT: %d (%s), %08x, %08lx\n", nCode, code_name, wParam, lParam);
4770 ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
4772 if (nCode == HCBT_SYSCOMMAND)
4776 msg.message = nCode;
4777 msg.flags = hook|wparam|lparam;
4778 msg.wParam = wParam;
4779 msg.lParam = lParam;
4782 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
4785 if (nCode == HCBT_DESTROYWND)
4787 if (test_DestroyWindow_flag)
4789 DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
4790 if (style & WS_CHILD)
4791 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
4792 else if (style & WS_POPUP)
4793 lParam = WND_POPUP_ID;
4795 lParam = WND_PARENT_ID;
4799 /* Log also SetFocus(0) calls */
4800 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
4802 if (GetClassNameA(hwnd, buf, sizeof(buf)))
4804 if (!lstrcmpiA(buf, "TestWindowClass") ||
4805 !lstrcmpiA(buf, "TestParentClass") ||
4806 !lstrcmpiA(buf, "TestPopupClass") ||
4807 !lstrcmpiA(buf, "SimpleWindowClass") ||
4808 !lstrcmpiA(buf, "TestDialogClass") ||
4809 !lstrcmpiA(buf, "MDI_frame_class") ||
4810 !lstrcmpiA(buf, "MDI_client_class") ||
4811 !lstrcmpiA(buf, "MDI_child_class") ||
4812 !lstrcmpiA(buf, "my_button_class") ||
4813 !lstrcmpiA(buf, "static") ||
4814 !lstrcmpiA(buf, "#32770"))
4818 msg.message = nCode;
4819 msg.flags = hook|wparam|lparam;
4820 msg.wParam = wParam;
4821 msg.lParam = lParam;
4825 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
4828 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
4838 trace("WEH:%p,event %08lx,hwnd %p,obj %08lx,id %08lx,thread %08lx,time %08lx\n",
4839 hevent, event, hwnd, object_id, child_id, thread_id, event_time);
4841 ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
4843 /* ignore mouse cursor events */
4844 if (object_id == OBJID_CURSOR) return;
4846 if (!hwnd || GetClassNameA(hwnd, buf, sizeof(buf)))
4849 !lstrcmpiA(buf, "TestWindowClass") ||
4850 !lstrcmpiA(buf, "TestParentClass") ||
4851 !lstrcmpiA(buf, "TestPopupClass") ||
4852 !lstrcmpiA(buf, "SimpleWindowClass") ||
4853 !lstrcmpiA(buf, "TestDialogClass") ||
4854 !lstrcmpiA(buf, "MDI_frame_class") ||
4855 !lstrcmpiA(buf, "MDI_client_class") ||
4856 !lstrcmpiA(buf, "MDI_child_class") ||
4857 !lstrcmpiA(buf, "my_button_class") ||
4858 !lstrcmpiA(buf, "static") ||
4859 !lstrcmpiA(buf, "#32770"))
4863 msg.message = event;
4864 msg.flags = winevent_hook|wparam|lparam;
4865 msg.wParam = object_id;
4866 msg.lParam = child_id;
4872 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
4873 static const WCHAR wszAnsi[] = {'U',0};
4875 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4879 case CB_FINDSTRINGEXACT:
4880 trace("String: %p\n", (LPCWSTR)lParam);
4881 if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
4883 if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
4887 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
4890 static void test_message_conversion(void)
4892 static const WCHAR wszMsgConversionClass[] =
4893 {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
4900 cls.lpfnWndProc = MsgConversionProcW;
4903 cls.hInstance = GetModuleHandleW(NULL);
4905 cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
4906 cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
4907 cls.lpszMenuName = NULL;
4908 cls.lpszClassName = wszMsgConversionClass;
4909 /* this call will fail on Win9x, but that doesn't matter as this test is
4910 * meaningless on those platforms */
4911 if(!RegisterClassW(&cls)) return;
4913 hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
4914 100, 100, 200, 200, 0, 0, 0, NULL);
4915 ok(hwnd != NULL, "Window creation failed\n");
4919 wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
4920 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4921 ok(lRes == 0, "String should have been converted\n");
4922 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4923 ok(lRes == 1, "String shouldn't have been converted\n");
4927 wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
4928 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4929 ok(lRes == 1, "String shouldn't have been converted\n");
4930 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4931 ok(lRes == 1, "String shouldn't have been converted\n");
4933 /* Synchronous messages */
4935 lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4936 ok(lRes == 0, "String should have been converted\n");
4937 lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4938 ok(lRes == 1, "String shouldn't have been converted\n");
4940 /* Asynchronous messages */
4943 lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4944 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
4945 "PostMessage on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
4947 lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4948 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
4949 "PostMessage on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
4951 lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4952 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
4953 "PosThreadtMessage on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
4955 lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4956 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
4957 "PosThreadtMessage on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
4959 lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4960 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
4961 "SendNotifyMessage on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
4963 lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
4964 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
4965 "SendNotifyMessage on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
4967 lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
4968 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
4969 "SendMessageCallback on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
4971 lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
4972 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
4973 "SendMessageCallback on sync only message returned %ld, last error %ld\n", lRes, GetLastError());
4976 typedef struct _thread_info
4983 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT id, DWORD dwTime)
4987 #define TIMER_ID 0x19
4989 static DWORD WINAPI timer_thread_proc(LPVOID x)
4991 thread_info *info = x;
4994 r = KillTimer(info->hWnd, 0x19);
4995 ok(r,"KillTimer failed in thread\n");
4996 r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
4997 ok(r,"SetTimer failed in thread\n");
4998 ok(r==TIMER_ID,"SetTimer id different\n");
4999 r = SetEvent(info->handles[0]);
5000 ok(r,"SetEvent failed in thread\n");
5004 static void test_timers(void)
5009 info.hWnd = CreateWindow ("TestWindowClass", NULL,
5010 WS_OVERLAPPEDWINDOW ,
5011 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5014 info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
5015 ok(info.id, "SetTimer failed\n");
5016 ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
5017 info.handles[0] = CreateEvent(NULL,0,0,NULL);
5018 info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
5020 WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
5022 WaitForSingleObject(info.handles[1], INFINITE);
5024 CloseHandle(info.handles[0]);
5025 CloseHandle(info.handles[1]);
5027 ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
5029 ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
5032 /* Various win events with arbitrary parameters */
5033 static const struct message WmWinEventsSeq[] = {
5034 { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
5035 { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
5036 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
5037 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
5038 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
5039 { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
5040 { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
5041 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
5042 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
5043 /* our win event hook ignores OBJID_CURSOR events */
5044 /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
5045 { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
5046 { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
5047 { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
5048 { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
5049 { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
5050 { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
5051 { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
5052 { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
5053 { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
5054 { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
5055 { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
5056 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
5057 { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
5060 static const struct message WmWinEventCaretSeq[] = {
5061 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
5062 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
5063 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
5064 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
5067 static const struct message WmWinEventCaretSeq_2[] = {
5068 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
5069 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
5070 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
5073 static const struct message WmWinEventAlertSeq[] = {
5074 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
5077 static const struct message WmWinEventAlertSeq_2[] = {
5078 /* create window in the thread proc */
5079 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
5080 /* our test event */
5081 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
5084 static const struct message WmGlobalHookSeq_1[] = {
5085 /* create window in the thread proc */
5086 { HCBT_CREATEWND, hook|lparam, 0, 2 },
5087 /* our test events */
5088 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
5089 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
5092 static const struct message WmGlobalHookSeq_2[] = {
5093 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
5094 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
5095 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
5096 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
5100 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
5110 trace("WEH_2:%p,event %08lx,hwnd %p,obj %08lx,id %08lx,thread %08lx,time %08lx\n",
5111 hevent, event, hwnd, object_id, child_id, thread_id, event_time);
5113 if (GetClassNameA(hwnd, buf, sizeof(buf)))
5115 if (!lstrcmpiA(buf, "TestWindowClass") ||
5116 !lstrcmpiA(buf, "static"))
5120 msg.message = event;
5121 msg.flags = winevent_hook|wparam|lparam;
5122 msg.wParam = object_id;
5123 msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
5129 static HHOOK hCBT_global_hook;
5130 static DWORD cbt_global_hook_thread_id;
5132 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
5137 trace("CBT_2: %d, %08x, %08lx\n", nCode, wParam, lParam);
5139 if (nCode == HCBT_SYSCOMMAND)
5143 msg.message = nCode;
5144 msg.flags = hook|wparam|lparam;
5145 msg.wParam = wParam;
5146 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
5149 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
5152 /* Log also SetFocus(0) calls */
5153 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
5155 if (GetClassNameA(hwnd, buf, sizeof(buf)))
5157 if (!lstrcmpiA(buf, "TestWindowClass") ||
5158 !lstrcmpiA(buf, "static"))
5162 msg.message = nCode;
5163 msg.flags = hook|wparam|lparam;
5164 msg.wParam = wParam;
5165 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
5169 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
5172 static DWORD WINAPI win_event_global_thread_proc(void *param)
5176 HANDLE hevent = *(HANDLE *)param;
5177 HMODULE user32 = GetModuleHandleA("user32.dll");
5178 FARPROC pNotifyWinEvent = GetProcAddress(user32, "NotifyWinEvent");
5180 assert(pNotifyWinEvent);
5182 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
5184 trace("created thread window %p\n", hwnd);
5186 *(HWND *)param = hwnd;
5189 /* this event should be received only by our new hook proc,
5190 * an old one does not expect an event from another thread.
5192 pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
5195 while (GetMessage(&msg, 0, 0, 0))
5197 TranslateMessage(&msg);
5198 DispatchMessage(&msg);
5203 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
5207 HANDLE hevent = *(HANDLE *)param;
5210 /* these events should be received only by our new hook proc,
5211 * an old one does not expect an event from another thread.
5214 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
5216 trace("created thread window %p\n", hwnd);
5218 *(HWND *)param = hwnd;
5220 /* Windows doesn't like when a thread plays games with the focus,
5221 that leads to all kinds of misbehaviours and failures to activate
5222 a window. So, better keep next lines commented out.
5226 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
5227 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
5231 while (GetMessage(&msg, 0, 0, 0))
5233 TranslateMessage(&msg);
5234 DispatchMessage(&msg);
5239 static void test_winevents(void)
5245 HANDLE hthread, hevent;
5247 HWINEVENTHOOK hhook;
5248 const struct message *events = WmWinEventsSeq;
5249 HMODULE user32 = GetModuleHandleA("user32.dll");
5250 FARPROC pSetWinEventHook = GetProcAddress(user32, "SetWinEventHook");
5251 FARPROC pUnhookWinEvent = GetProcAddress(user32, "UnhookWinEvent");
5252 FARPROC pNotifyWinEvent = GetProcAddress(user32, "NotifyWinEvent");
5254 hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
5255 WS_OVERLAPPEDWINDOW,
5256 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5260 /****** start of global hook test *************/
5261 hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
5262 assert(hCBT_global_hook);
5264 hevent = CreateEventA(NULL, 0, 0, NULL);
5266 hwnd2 = (HWND)hevent;
5268 hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
5269 ok(hthread != NULL, "CreateThread failed, error %ld\n", GetLastError());
5271 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5273 ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
5276 /* this one should be received only by old hook proc */
5277 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
5278 /* this one should be received only by old hook proc */
5279 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
5281 ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
5283 ret = UnhookWindowsHookEx(hCBT_global_hook);
5284 ok( ret, "UnhookWindowsHookEx error %ld\n", GetLastError());
5286 PostThreadMessageA(tid, WM_QUIT, 0, 0);
5287 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5288 CloseHandle(hthread);
5289 CloseHandle(hevent);
5290 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
5291 /****** end of global hook test *************/
5293 if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
5295 ok(DestroyWindow(hwnd), "failed to destroy window\n");
5301 #if 0 /* this test doesn't pass under Win9x */
5302 /* win2k ignores events with hwnd == 0 */
5303 SetLastError(0xdeadbeef);
5304 pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
5305 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
5306 GetLastError() == 0xdeadbeef, /* Win9x */
5307 "unexpected error %ld\n", GetLastError());
5308 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
5311 for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
5312 pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
5314 ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
5316 /****** start of event filtering test *************/
5317 hhook = (HWINEVENTHOOK)pSetWinEventHook(
5318 EVENT_OBJECT_SHOW, /* 0x8002 */
5319 EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
5320 GetModuleHandleA(0), win_event_global_hook_proc,
5321 GetCurrentProcessId(), 0,
5322 WINEVENT_INCONTEXT);
5323 ok(hhook != 0, "SetWinEventHook error %ld\n", GetLastError());
5325 hevent = CreateEventA(NULL, 0, 0, NULL);
5327 hwnd2 = (HWND)hevent;
5329 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
5330 ok(hthread != NULL, "CreateThread failed, error %ld\n", GetLastError());
5332 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5334 ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
5337 /* this one should be received only by old hook proc */
5338 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
5339 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
5340 /* this one should be received only by old hook proc */
5341 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
5343 ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
5345 ret = pUnhookWinEvent(hhook);
5346 ok( ret, "UnhookWinEvent error %ld\n", GetLastError());
5348 PostThreadMessageA(tid, WM_QUIT, 0, 0);
5349 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5350 CloseHandle(hthread);
5351 CloseHandle(hevent);
5352 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
5353 /****** end of event filtering test *************/
5355 /****** start of out of context event test *************/
5356 hhook = (HWINEVENTHOOK)pSetWinEventHook(
5357 EVENT_MIN, EVENT_MAX,
5358 0, win_event_global_hook_proc,
5359 GetCurrentProcessId(), 0,
5360 WINEVENT_OUTOFCONTEXT);
5361 ok(hhook != 0, "SetWinEventHook error %ld\n", GetLastError());
5363 hevent = CreateEventA(NULL, 0, 0, NULL);
5365 hwnd2 = (HWND)hevent;
5369 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
5370 ok(hthread != NULL, "CreateThread failed, error %ld\n", GetLastError());
5372 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5374 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
5375 /* process pending winevent messages */
5376 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
5377 ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
5380 /* this one should be received only by old hook proc */
5381 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
5382 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
5383 /* this one should be received only by old hook proc */
5384 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
5386 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
5387 /* process pending winevent messages */
5388 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
5389 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
5391 ret = pUnhookWinEvent(hhook);
5392 ok( ret, "UnhookWinEvent error %ld\n", GetLastError());
5394 PostThreadMessageA(tid, WM_QUIT, 0, 0);
5395 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5396 CloseHandle(hthread);
5397 CloseHandle(hevent);
5398 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
5399 /****** end of out of context event test *************/
5401 ok(DestroyWindow(hwnd), "failed to destroy window\n");
5404 static void test_set_hook(void)
5408 HWINEVENTHOOK hwinevent_hook;
5409 HMODULE user32 = GetModuleHandleA("user32.dll");
5410 FARPROC pSetWinEventHook = GetProcAddress(user32, "SetWinEventHook");
5411 FARPROC pUnhookWinEvent = GetProcAddress(user32, "UnhookWinEvent");
5413 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
5414 ok(hhook != 0, "local hook does not require hModule set to 0\n");
5415 UnhookWindowsHookEx(hhook);
5417 #if 0 /* this test doesn't pass under Win9x: BUG! */
5418 SetLastError(0xdeadbeef);
5419 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
5420 ok(!hhook, "global hook requires hModule != 0\n");
5421 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %ld\n", GetLastError());
5424 SetLastError(0xdeadbeef);
5425 hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
5426 ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
5427 ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
5428 GetLastError() == 0xdeadbeef, /* Win9x */
5429 "unexpected error %ld\n", GetLastError());
5431 SetLastError(0xdeadbeef);
5432 ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
5433 ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
5434 GetLastError() == 0xdeadbeef, /* Win9x */
5435 "unexpected error %ld\n", GetLastError());
5437 if (!pSetWinEventHook || !pUnhookWinEvent) return;
5439 /* even process local incontext hooks require hmodule */
5440 SetLastError(0xdeadbeef);
5441 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
5442 0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
5443 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
5444 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
5445 GetLastError() == 0xdeadbeef, /* Win9x */
5446 "unexpected error %ld\n", GetLastError());
5448 /* even thread local incontext hooks require hmodule */
5449 SetLastError(0xdeadbeef);
5450 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
5451 0, win_event_proc, GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
5452 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
5453 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
5454 GetLastError() == 0xdeadbeef, /* Win9x */
5455 "unexpected error %ld\n", GetLastError());
5457 #if 0 /* these 3 tests don't pass under Win9x */
5458 SetLastError(0xdeadbeef);
5459 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(1, 0,
5460 0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
5461 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
5462 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %ld\n", GetLastError());
5464 SetLastError(0xdeadbeef);
5465 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(-1, 1,
5466 0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
5467 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
5468 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %ld\n", GetLastError());
5470 SetLastError(0xdeadbeef);
5471 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
5472 0, win_event_proc, 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
5473 ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
5474 ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %ld\n", GetLastError());
5477 SetLastError(0xdeadbeef);
5478 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(0, 0,
5479 0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
5480 ok(hwinevent_hook != 0, "SetWinEventHook error %ld\n", GetLastError());
5481 ok(GetLastError() == 0xdeadbeef, "unexpected error %ld\n", GetLastError());
5482 ret = pUnhookWinEvent(hwinevent_hook);
5483 ok( ret, "UnhookWinEvent error %ld\n", GetLastError());
5486 /* This call succeeds under win2k SP4, but fails under Wine.
5487 Does win2k test/use passed process id? */
5488 SetLastError(0xdeadbeef);
5489 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
5490 0, win_event_proc, 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
5491 ok(hwinevent_hook != 0, "SetWinEventHook error %ld\n", GetLastError());
5492 ok(GetLastError() == 0xdeadbeef, "unexpected error %ld\n", GetLastError());
5493 ret = pUnhookWinEvent(hwinevent_hook);
5494 ok( ret, "UnhookWinEvent error %ld\n", GetLastError());
5497 SetLastError(0xdeadbeef);
5498 ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
5499 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
5500 GetLastError() == 0xdeadbeef, /* Win9x */
5501 "unexpected error %ld\n", GetLastError());
5504 static const struct message ScrollWindowPaint1[] = {
5506 { WM_ERASEBKGND, sent|beginpaint },
5510 static const struct message ScrollWindowPaint2[] = {
5515 static void test_scrollwindowex(void)
5518 RECT rect={0,0,130,130};
5521 hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
5522 WS_VISIBLE|WS_OVERLAPPEDWINDOW,
5523 100, 100, 200, 200, 0, 0, 0, NULL);
5524 ok (hwnd != 0, "Failed to create overlapped window\n");
5525 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
5526 WS_VISIBLE|WS_CAPTION|WS_CHILD,
5527 10, 10, 150, 150, hwnd, 0, 0, NULL);
5528 ok (hchild != 0, "Failed to create child\n");
5530 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5533 /* scroll without the child window */
5534 trace("start scroll\n");
5535 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
5536 SW_ERASE|SW_INVALIDATE);
5537 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
5538 trace("end scroll\n");
5540 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5541 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
5543 /* Now without the SW_ERASE flag */
5544 trace("start scroll\n");
5545 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
5546 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
5547 trace("end scroll\n");
5549 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5550 ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
5552 /* now scroll the child window as well */
5553 trace("start scroll\n");
5554 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
5555 SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
5556 todo_wine { /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
5557 /* windows sometimes a WM_MOVE */
5558 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
5560 trace("end scroll\n");
5562 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5563 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
5565 /* now scroll with ScrollWindow() */
5566 trace("start scroll with ScrollWindow\n");
5567 ScrollWindow( hwnd, 5, 5, NULL, NULL);
5568 trace("end scroll\n");
5570 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5571 ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
5573 ok(DestroyWindow(hchild), "failed to destroy window\n");
5574 ok(DestroyWindow(hwnd), "failed to destroy window\n");
5578 static const struct message destroy_window_with_children[] = {
5579 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
5580 { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
5581 { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
5582 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
5583 { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
5584 { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
5585 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
5586 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
5587 { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
5588 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
5589 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
5590 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
5591 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
5592 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
5593 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
5594 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
5598 static void test_DestroyWindow(void)
5601 HWND parent, child1, child2, child3, child4, test;
5602 UINT child_id = WND_CHILD_ID + 1;
5604 parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
5605 100, 100, 200, 200, 0, 0, 0, NULL);
5606 assert(parent != 0);
5607 child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
5608 0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
5609 assert(child1 != 0);
5610 child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
5611 0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
5612 assert(child2 != 0);
5613 child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
5614 0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
5615 assert(child3 != 0);
5616 child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
5617 0, 0, 50, 50, parent, 0, 0, NULL);
5618 assert(child4 != 0);
5620 /* test owner/parent of child2 */
5621 test = GetParent(child2);
5622 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
5623 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
5625 test = pGetAncestor(child2, GA_PARENT);
5626 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
5628 test = GetWindow(child2, GW_OWNER);
5629 ok(!test, "wrong owner %p\n", test);
5631 test = SetParent(child2, parent);
5632 ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
5634 /* test owner/parent of the parent */
5635 test = GetParent(parent);
5636 ok(!test, "wrong parent %p\n", test);
5638 ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
5641 test = pGetAncestor(parent, GA_PARENT);
5642 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
5644 test = GetWindow(parent, GW_OWNER);
5645 ok(!test, "wrong owner %p\n", test);
5647 /* test owner/parent of child1 */
5648 test = GetParent(child1);
5649 ok(test == parent, "wrong parent %p\n", test);
5650 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
5652 test = pGetAncestor(child1, GA_PARENT);
5653 ok(test == parent, "wrong parent %p\n", test);
5655 test = GetWindow(child1, GW_OWNER);
5656 ok(!test, "wrong owner %p\n", test);
5658 /* test owner/parent of child2 */
5659 test = GetParent(child2);
5660 ok(test == parent, "wrong parent %p\n", test);
5661 ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
5663 test = pGetAncestor(child2, GA_PARENT);
5664 ok(test == parent, "wrong parent %p\n", test);
5666 test = GetWindow(child2, GW_OWNER);
5667 ok(!test, "wrong owner %p\n", test);
5669 /* test owner/parent of child3 */
5670 test = GetParent(child3);
5671 ok(test == child1, "wrong parent %p\n", test);
5672 ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
5674 test = pGetAncestor(child3, GA_PARENT);
5675 ok(test == child1, "wrong parent %p\n", test);
5677 test = GetWindow(child3, GW_OWNER);
5678 ok(!test, "wrong owner %p\n", test);
5680 /* test owner/parent of child4 */
5681 test = GetParent(child4);
5682 ok(test == parent, "wrong parent %p\n", test);
5683 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
5685 test = pGetAncestor(child4, GA_PARENT);
5686 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
5688 test = GetWindow(child4, GW_OWNER);
5689 ok(test == parent, "wrong owner %p\n", test);
5693 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
5694 parent, child1, child2, child3, child4);
5697 test = GetCapture();
5698 ok(test == child4, "wrong capture window %p\n", test);
5700 test_DestroyWindow_flag = TRUE;
5701 ret = DestroyWindow(parent);
5702 ok( ret, "DestroyWindow() error %ld\n", GetLastError());
5703 test_DestroyWindow_flag = FALSE;
5704 ok_sequence(destroy_window_with_children, "destroy window with children", 0);
5706 ok(!IsWindow(parent), "parent still exists\n");
5707 ok(!IsWindow(child1), "child1 still exists\n");
5708 ok(!IsWindow(child2), "child2 still exists\n");
5709 ok(!IsWindow(child3), "child3 still exists\n");
5710 ok(!IsWindow(child4), "child4 still exists\n");
5712 test = GetCapture();
5713 ok(!test, "wrong capture window %p\n", test);
5717 static const struct message WmDispatchPaint[] = {
5718 { WM_NCPAINT, sent },
5719 { WM_GETTEXT, sent|defwinproc|optional },
5720 { WM_GETTEXT, sent|defwinproc|optional },
5721 { WM_ERASEBKGND, sent },
5725 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5727 if (message == WM_PAINT)
5729 trace( "Got WM_PAINT, ignoring\n" );
5732 return MsgCheckProcA( hwnd, message, wParam, lParam );
5735 static void test_DispatchMessage(void)
5740 HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
5741 100, 100, 200, 200, 0, 0, 0, NULL);
5742 ShowWindow( hwnd, SW_SHOW );
5743 UpdateWindow( hwnd );
5744 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5746 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
5748 SetRect( &rect, -5, -5, 5, 5 );
5749 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
5751 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
5753 if (msg.message != WM_PAINT) DispatchMessage( &msg );
5757 DispatchMessage( &msg );
5758 /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
5759 if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
5760 else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
5761 if (++count > 10) break;
5764 ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
5766 trace("now without DispatchMessage\n");
5768 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
5770 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
5772 if (msg.message != WM_PAINT) DispatchMessage( &msg );
5775 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
5777 /* this will send WM_NCCPAINT just like DispatchMessage does */
5778 GetUpdateRgn( hwnd, hrgn, TRUE );
5779 ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
5780 DeleteObject( hrgn );
5781 GetClientRect( hwnd, &rect );
5782 ValidateRect( hwnd, &rect ); /* this will stop WM_PAINTs */
5783 ok( !count, "Got multiple WM_PAINTs\n" );
5784 if (++count > 10) break;
5793 HMODULE user32 = GetModuleHandleA("user32.dll");
5794 FARPROC pSetWinEventHook = GetProcAddress(user32, "SetWinEventHook");
5795 FARPROC pUnhookWinEvent = GetProcAddress(user32, "UnhookWinEvent");
5796 FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
5797 pGetAncestor = (void*) GetProcAddress(user32, "GetAncestor");
5799 if (!RegisterWindowClasses()) assert(0);
5801 if (pSetWinEventHook)
5803 hEvent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
5804 GetModuleHandleA(0),
5807 GetCurrentThreadId(),
5808 WINEVENT_INCONTEXT);
5809 assert(hEvent_hook);
5811 if (pIsWinEventHookInstalled)
5814 for (event = EVENT_MIN; event <= EVENT_MAX; event++)
5815 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
5819 cbt_hook_thread_id = GetCurrentThreadId();
5820 hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
5825 /* Fix message sequences before removing 3 lines below */
5826 ret = pUnhookWinEvent(hEvent_hook);
5827 ok( ret, "UnhookWinEvent error %ld\n", GetLastError());
5828 pUnhookWinEvent = 0;
5831 test_scrollwindowex();
5833 test_mdi_messages();
5834 test_button_messages();
5835 test_paint_messages();
5836 test_interthread_messages();
5837 test_message_conversion();
5838 test_accelerators();
5841 test_DestroyWindow();
5842 test_DispatchMessage();
5844 UnhookWindowsHookEx(hCBT_hook);
5845 if (pUnhookWinEvent)
5847 ret = pUnhookWinEvent(hEvent_hook);
5848 ok( ret, "UnhookWinEvent error %ld\n", GetLastError());
5849 SetLastError(0xdeadbeef);
5850 ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
5851 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
5852 GetLastError() == 0xdeadbeef, /* Win9x */
5853 "unexpected error %ld\n", GetLastError());