mshtml: Fixed status text cache implementation.
[wine/multimedia.git] / dlls / user32 / tests / msg.c
blob27a54766ad54d6e356c3a50233edd00d4f486519
1 /*
2 * Unit tests for window message handling
4 * Copyright 1999 Ove Kaaven
5 * Copyright 2003 Dimitrie O. Paun
6 * Copyright 2004, 2005 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define _WIN32_WINNT 0x0600 /* For WM_CHANGEUISTATE,QS_RAWINPUT,WM_DWMxxxx */
24 #define WINVER 0x0600 /* for WM_GETTITLEBARINFOEX */
26 #include <assert.h>
27 #include <stdarg.h>
28 #include <stdio.h>
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winuser.h"
34 #include "winnls.h"
36 #include "wine/test.h"
38 #define MDI_FIRST_CHILD_ID 2004
40 /* undocumented SWP flags - from SDK 3.1 */
41 #define SWP_NOCLIENTSIZE 0x0800
42 #define SWP_NOCLIENTMOVE 0x1000
43 #define SWP_STATECHANGED 0x8000
45 #define SW_NORMALNA 0xCC /* undoc. flag in MinMaximize */
47 #ifndef WM_KEYF1
48 #define WM_KEYF1 0x004d
49 #endif
51 #ifndef WM_SYSTIMER
52 #define WM_SYSTIMER 0x0118
53 #endif
55 #define WND_PARENT_ID 1
56 #define WND_POPUP_ID 2
57 #define WND_CHILD_ID 3
59 #ifndef WM_LBTRACKPOINT
60 #define WM_LBTRACKPOINT 0x0131
61 #endif
63 /* encoded DRAWITEMSTRUCT into an LPARAM */
64 typedef struct
66 union
68 struct
70 UINT type : 4; /* ODT_* flags */
71 UINT ctl_id : 4; /* Control ID */
72 UINT item_id : 4; /* Menu item ID */
73 UINT action : 4; /* ODA_* flags */
74 UINT state : 16; /* ODS_* flags */
75 } item;
76 LPARAM lp;
77 } u;
78 } DRAW_ITEM_STRUCT;
80 static BOOL test_DestroyWindow_flag;
81 static HWINEVENTHOOK hEvent_hook;
82 static HHOOK hKBD_hook;
83 static HHOOK hCBT_hook;
84 static DWORD cbt_hook_thread_id;
86 static const WCHAR testWindowClassW[] =
87 { 'T','e','s','t','W','i','n','d','o','w','C','l','a','s','s','W',0 };
90 FIXME: add tests for these
91 Window Edge Styles (Win31/Win95/98 look), in order of precedence:
92 WS_EX_DLGMODALFRAME: double border, WS_CAPTION allowed
93 WS_THICKFRAME: thick border
94 WS_DLGFRAME: double border, WS_CAPTION not allowed (but possibly shown anyway)
95 WS_BORDER (default for overlapped windows): single black border
96 none (default for child (and popup?) windows): no border
99 typedef enum {
100 sent=0x1,
101 posted=0x2,
102 parent=0x4,
103 wparam=0x8,
104 lparam=0x10,
105 defwinproc=0x20,
106 beginpaint=0x40,
107 optional=0x80,
108 hook=0x100,
109 winevent_hook=0x200,
110 kbd_hook=0x400
111 } msg_flags_t;
113 struct message {
114 UINT message; /* the WM_* code */
115 msg_flags_t flags; /* message props */
116 WPARAM wParam; /* expected value of wParam */
117 LPARAM lParam; /* expected value of lParam */
118 WPARAM wp_mask; /* mask for wParam checks */
119 LPARAM lp_mask; /* mask for lParam checks */
122 struct recvd_message {
123 UINT message; /* the WM_* code */
124 msg_flags_t flags; /* message props */
125 HWND hwnd; /* window that received the message */
126 WPARAM wParam; /* expected value of wParam */
127 LPARAM lParam; /* expected value of lParam */
128 int line; /* source line where logged */
129 const char *descr; /* description for trace output */
130 char output[512]; /* trace output */
133 /* Empty message sequence */
134 static const struct message WmEmptySeq[] =
136 { 0 }
138 /* CreateWindow (for overlapped window, not initially visible) (16/32) */
139 static const struct message WmCreateOverlappedSeq[] = {
140 { HCBT_CREATEWND, hook },
141 { WM_GETMINMAXINFO, sent },
142 { WM_NCCREATE, sent },
143 { WM_NCCALCSIZE, sent|wparam, 0 },
144 { 0x0093, sent|defwinproc|optional },
145 { 0x0094, sent|defwinproc|optional },
146 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
147 { WM_CREATE, sent },
148 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
149 { 0 }
151 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
152 * for a not visible overlapped window.
154 static const struct message WmSWP_ShowOverlappedSeq[] = {
155 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
156 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
157 { WM_NCPAINT, sent|wparam|optional, 1 },
158 { WM_GETTEXT, sent|defwinproc|optional },
159 { WM_ERASEBKGND, sent|optional },
160 { HCBT_ACTIVATE, hook },
161 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
162 { WM_NOTIFYFORMAT, sent|optional },
163 { WM_QUERYUISTATE, sent|optional },
164 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
165 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x: SWP_NOSENDCHANGING */
166 { WM_ACTIVATEAPP, sent|wparam, 1 },
167 { WM_NCACTIVATE, sent },
168 { WM_GETTEXT, sent|defwinproc|optional },
169 { WM_ACTIVATE, sent|wparam, 1 },
170 { HCBT_SETFOCUS, hook },
171 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
172 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
173 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
174 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
175 { WM_GETTEXT, sent|optional },
176 { WM_NCPAINT, sent|wparam|optional, 1 },
177 { WM_GETTEXT, sent|defwinproc|optional },
178 { WM_ERASEBKGND, sent|optional },
179 /* Win9x adds SWP_NOZORDER below */
180 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
181 { WM_GETTEXT, sent|optional },
182 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
183 { WM_NCPAINT, sent|wparam|optional, 1 },
184 { WM_ERASEBKGND, sent|optional },
185 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
186 { WM_SYNCPAINT, sent|optional },
187 { WM_GETTITLEBARINFOEX, sent|optional },
188 { WM_PAINT, sent|optional },
189 { WM_NCPAINT, sent|beginpaint|optional },
190 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
191 { WM_ERASEBKGND, sent|beginpaint|optional },
192 { 0 }
194 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
195 * for a visible overlapped window.
197 static const struct message WmSWP_HideOverlappedSeq[] = {
198 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
199 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
200 { HCBT_ACTIVATE, hook|optional },
201 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
202 { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
203 { WM_NCACTIVATE, sent|optional },
204 { WM_ACTIVATE, sent|optional },
205 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
206 { 0 }
209 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
210 * for a visible overlapped window.
212 static const struct message WmSWP_ResizeSeq[] = {
213 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
214 { WM_GETMINMAXINFO, sent|defwinproc },
215 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
216 { WM_NCPAINT, sent|optional },
217 { WM_GETTEXT, sent|defwinproc|optional },
218 { WM_ERASEBKGND, sent|optional },
219 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
220 { WM_SIZE, sent|defwinproc|optional },
221 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
222 { WM_NCPAINT, sent|optional },
223 { WM_GETTEXT, sent|defwinproc|optional },
224 { WM_ERASEBKGND, sent|optional },
225 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
226 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
227 { 0 }
230 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
231 * for a visible popup window.
233 static const struct message WmSWP_ResizePopupSeq[] = {
234 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
235 { WM_GETMINMAXINFO, sent|defwinproc|optional }, /* Win9x */
236 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
237 { WM_NCPAINT, sent|optional },
238 { WM_GETTEXT, sent|defwinproc|optional },
239 { WM_ERASEBKGND, sent|optional },
240 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
241 { WM_SIZE, sent|defwinproc|wparam|optional, SIZE_RESTORED },
242 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
243 { WM_NCPAINT, sent|optional },
244 { WM_GETTEXT, sent|defwinproc|optional },
245 { WM_ERASEBKGND, sent|optional },
246 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
247 { 0 }
250 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
251 * for a visible overlapped window.
253 static const struct message WmSWP_MoveSeq[] = {
254 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE },
255 { WM_NCPAINT, sent|optional },
256 { WM_GETTEXT, sent|defwinproc|optional },
257 { WM_ERASEBKGND, sent|optional },
258 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
259 { WM_MOVE, sent|defwinproc|wparam, 0 },
260 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
261 { 0 }
263 /* Resize with SetWindowPos(SWP_NOZORDER)
264 * for a visible overlapped window
265 * SWP_NOZORDER is stripped by the logging code
267 static const struct message WmSWP_ResizeNoZOrder[] = {
268 { WM_WINDOWPOSCHANGING, sent|wparam, /*SWP_NOZORDER|*/SWP_NOACTIVATE },
269 { WM_GETMINMAXINFO, sent|defwinproc },
270 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
271 { WM_NCPAINT, sent|optional },
272 { WM_GETTEXT, sent|defwinproc|optional },
273 { WM_ERASEBKGND, sent|optional },
274 { WM_WINDOWPOSCHANGED, sent|wparam|optional, /*SWP_NOZORDER|*/SWP_NOACTIVATE, 0,
275 SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
276 { WM_MOVE, sent|defwinproc|optional },
277 { WM_SIZE, sent|defwinproc|optional },
278 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
279 { WM_NCPAINT, sent|optional }, /* Win9x doesn't send it */
280 { WM_GETTEXT, sent|defwinproc|optional }, /* Win9x doesn't send it */
281 { WM_ERASEBKGND, sent|optional }, /* Win9x doesn't send it */
282 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
283 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
284 { 0 }
287 /* Switch visible mdi children */
288 static const struct message WmSwitchChild[] = {
289 /* Switch MDI child */
290 { WM_MDIACTIVATE, sent },/* in the MDI client */
291 { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 1st MDI child */
292 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
293 { WM_CHILDACTIVATE, sent },/* in the 1st MDI child */
294 /* Deactivate 2nd MDI child */
295 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
296 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
297 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
298 /* Preparing for maximize and maximize the 1st MDI child */
299 { WM_GETMINMAXINFO, sent|defwinproc }, /* in the 1st MDI child */
300 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED }, /* in the 1st MDI child */
301 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
302 { WM_CHILDACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
303 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 1st MDI child */
304 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED }, /* in the 1st MDI child */
305 /* Lock redraw 2nd MDI child */
306 { WM_SETREDRAW, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
307 { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
308 /* Restore 2nd MDI child */
309 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },/* in the 2nd MDI child */
310 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
311 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
312 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 2nd MDI child */
313 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED }, /* in the 2nd MDI child */
314 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
315 /* Redraw 2nd MDI child */
316 { WM_SETREDRAW, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
317 /* Redraw MDI frame */
318 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },/* in MDI frame */
319 { WM_NCCALCSIZE, sent|wparam, 1 },/* in MDI frame */
320 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in MDI frame */
321 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in MDI frame */
322 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
323 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
324 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
325 { HCBT_SETFOCUS, hook },
326 { WM_KILLFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
327 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },/* in the 1st MDI child */
328 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
329 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
330 { WM_SETFOCUS, sent },/* in the MDI client */
331 { HCBT_SETFOCUS, hook },
332 { WM_KILLFOCUS, sent },/* in the MDI client */
333 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
334 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 }, /* in the 1st MDI child */
335 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
336 { WM_SETFOCUS, sent|defwinproc }, /* in the 1st MDI child */
337 { WM_MDIACTIVATE, sent|defwinproc },/* in the 1st MDI child */
338 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* in the 1st MDI child */
339 { 0 }
342 /* Switch visible not maximized mdi children */
343 static const struct message WmSwitchNotMaximizedChild[] = {
344 /* Switch not maximized MDI child */
345 { WM_MDIACTIVATE, sent },/* in the MDI client */
346 { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 2nd MDI child */
347 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
348 { WM_CHILDACTIVATE, sent },/* in the 2nd MDI child */
349 /* Deactivate 1st MDI child */
350 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
351 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
352 /* Activate 2nd MDI child */
353 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE}, /* in the 2nd MDI child */
354 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 2nd MDI child */
355 { HCBT_SETFOCUS, hook }, /* in the 1st MDI child */
356 { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
357 { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
358 { WM_IME_SETCONTEXT, sent|optional }, /* in the MDI client */
359 { WM_SETFOCUS, sent, 0 }, /* in the MDI client */
360 { HCBT_SETFOCUS, hook },
361 { WM_KILLFOCUS, sent }, /* in the MDI client */
362 { WM_IME_SETCONTEXT, sent|optional }, /* in the MDI client */
363 { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
364 { WM_SETFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
365 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
366 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in the 2nd MDI child */
367 { 0 }
371 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
372 SWP_NOZORDER|SWP_FRAMECHANGED)
373 * for a visible overlapped window with WS_CLIPCHILDREN style set.
375 static const struct message WmSWP_FrameChanged_clip[] = {
376 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
377 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
378 { WM_NCPAINT, sent|parent|optional }, /* wparam != 1 */
379 { WM_GETTEXT, sent|parent|defwinproc|optional },
380 { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
381 { WM_NCPAINT, sent }, /* wparam != 1 */
382 { WM_ERASEBKGND, sent },
383 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
384 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
385 { WM_PAINT, sent },
386 { 0 }
388 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|
389 SWP_NOZORDER|SWP_FRAMECHANGED)
390 * for a visible overlapped window.
392 static const struct message WmSWP_FrameChangedDeferErase[] = {
393 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
394 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
395 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
396 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
397 { WM_PAINT, sent|parent|optional },
398 { WM_NCPAINT, sent|beginpaint|parent|optional }, /* wparam != 1 */
399 { WM_GETTEXT, sent|beginpaint|parent|defwinproc|optional },
400 { WM_PAINT, sent },
401 { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
402 { WM_ERASEBKGND, sent|beginpaint|optional },
403 { 0 }
406 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
407 SWP_NOZORDER|SWP_FRAMECHANGED)
408 * for a visible overlapped window without WS_CLIPCHILDREN style set.
410 static const struct message WmSWP_FrameChanged_noclip[] = {
411 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
412 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
413 { WM_NCPAINT, sent|parent|optional }, /* wparam != 1 */
414 { WM_GETTEXT, sent|parent|defwinproc|optional },
415 { WM_ERASEBKGND, sent|parent|optional },
416 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
417 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
418 { WM_PAINT, sent },
419 { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
420 { WM_ERASEBKGND, sent|beginpaint|optional },
421 { 0 }
424 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
425 static const struct message WmShowOverlappedSeq[] = {
426 { WM_SHOWWINDOW, sent|wparam, 1 },
427 { WM_NCPAINT, sent|wparam|optional, 1 },
428 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
429 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
430 { WM_NCPAINT, sent|wparam|optional, 1 },
431 { WM_GETTEXT, sent|defwinproc|optional },
432 { WM_ERASEBKGND, sent|optional },
433 { HCBT_ACTIVATE, hook },
434 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
435 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
436 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
437 { WM_NCPAINT, sent|wparam|optional, 1 },
438 { WM_ACTIVATEAPP, sent|wparam, 1 },
439 { WM_NCACTIVATE, sent|wparam, 1 },
440 { WM_GETTEXT, sent|defwinproc|optional },
441 { WM_ACTIVATE, sent|wparam, 1 },
442 { HCBT_SETFOCUS, hook },
443 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
444 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
445 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
446 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
447 { WM_GETTEXT, sent|optional },
448 { WM_NCPAINT, sent|wparam|optional, 1 },
449 { WM_GETTEXT, sent|defwinproc|optional },
450 { WM_ERASEBKGND, sent|optional },
451 /* Win9x adds SWP_NOZORDER below */
452 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
453 { WM_NCCALCSIZE, sent|optional },
454 { WM_GETTEXT, sent|optional },
455 { WM_NCPAINT, sent|optional },
456 { WM_ERASEBKGND, sent|optional },
457 { WM_SYNCPAINT, sent|optional },
458 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
459 * messages. Does that mean that CreateWindow doesn't set initial
460 * window dimensions for overlapped windows?
462 { WM_SIZE, sent },
463 { WM_MOVE, sent },
464 #endif
465 { WM_PAINT, sent|optional },
466 { WM_NCPAINT, sent|beginpaint|optional },
467 { 0 }
469 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible overlapped window */
470 static const struct message WmShowMaxOverlappedSeq[] = {
471 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
472 { WM_GETMINMAXINFO, sent },
473 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
474 { WM_GETMINMAXINFO, sent|defwinproc },
475 { WM_NCCALCSIZE, sent|wparam, TRUE },
476 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
477 { HCBT_ACTIVATE, hook },
478 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
479 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
480 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
481 { WM_ACTIVATEAPP, sent|wparam, 1 },
482 { WM_NCACTIVATE, sent|wparam, 1 },
483 { WM_GETTEXT, sent|defwinproc|optional },
484 { WM_ACTIVATE, sent|wparam, 1 },
485 { HCBT_SETFOCUS, hook },
486 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
487 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
488 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
489 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
490 { WM_GETTEXT, sent|optional },
491 { WM_NCPAINT, sent|wparam|optional, 1 },
492 { WM_GETTEXT, sent|defwinproc|optional },
493 { WM_ERASEBKGND, sent|optional },
494 /* Win9x adds SWP_NOZORDER below */
495 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
496 { WM_MOVE, sent|defwinproc },
497 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
498 { WM_GETTEXT, sent|optional },
499 { WM_NCCALCSIZE, sent|optional },
500 { WM_NCPAINT, sent|optional },
501 { WM_ERASEBKGND, sent|optional },
502 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
503 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
504 { WM_SYNCPAINT, sent|optional },
505 { WM_GETTITLEBARINFOEX, sent|optional },
506 { WM_PAINT, sent|optional },
507 { WM_NCPAINT, sent|beginpaint|optional },
508 { WM_ERASEBKGND, sent|beginpaint|optional },
509 { 0 }
511 /* ShowWindow(SW_RESTORE) for a not visible maximized overlapped window */
512 static const struct message WmShowRestoreMaxOverlappedSeq[] = {
513 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
514 { WM_GETTEXT, sent|optional },
515 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
516 { WM_GETMINMAXINFO, sent|defwinproc },
517 { WM_NCCALCSIZE, sent|wparam, TRUE },
518 { WM_NCPAINT, sent|optional },
519 { WM_GETTEXT, sent|defwinproc|optional },
520 { WM_ERASEBKGND, sent|optional },
521 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
522 { WM_MOVE, sent|defwinproc|optional },
523 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
524 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
525 { WM_NCPAINT, sent|optional },
526 { WM_ERASEBKGND, sent|optional },
527 { WM_PAINT, sent|optional },
528 { WM_GETTITLEBARINFOEX, sent|optional },
529 { WM_NCPAINT, sent|beginpaint|optional },
530 { WM_ERASEBKGND, sent|beginpaint|optional },
531 { 0 }
533 /* ShowWindow(SW_RESTORE) for a not visible minimized overlapped window */
534 static const struct message WmShowRestoreMinOverlappedSeq[] = {
535 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
536 { WM_QUERYOPEN, sent|optional },
537 { WM_GETTEXT, sent|optional },
538 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED|SWP_NOCOPYBITS },
539 { WM_GETMINMAXINFO, sent|defwinproc },
540 { WM_NCCALCSIZE, sent|wparam, TRUE },
541 { HCBT_ACTIVATE, hook },
542 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
543 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
544 { WM_ACTIVATEAPP, sent|wparam, 1 },
545 { WM_NCACTIVATE, sent|wparam, 1 },
546 { WM_GETTEXT, sent|defwinproc|optional },
547 { WM_ACTIVATE, sent|wparam, 1 },
548 { HCBT_SETFOCUS, hook },
549 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
550 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
551 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
552 { WM_GETTEXT, sent|optional },
553 { WM_NCPAINT, sent|wparam|optional, 1 },
554 { WM_GETTEXT, sent|defwinproc|optional },
555 { WM_ERASEBKGND, sent },
556 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_STATECHANGED|SWP_FRAMECHANGED|SWP_NOCOPYBITS },
557 { WM_MOVE, sent|defwinproc },
558 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
559 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
560 { WM_NCPAINT, sent|wparam|optional, 1 },
561 { WM_ERASEBKGND, sent|optional },
562 { WM_ACTIVATE, sent|wparam, 1 },
563 { WM_GETTEXT, sent|optional },
564 { WM_PAINT, sent|optional },
565 { WM_GETTITLEBARINFOEX, sent|optional },
566 { WM_NCPAINT, sent|beginpaint|optional },
567 { WM_ERASEBKGND, sent|beginpaint|optional },
568 { 0 }
570 /* ShowWindow(SW_SHOWMINIMIZED) for a not visible overlapped window */
571 static const struct message WmShowMinOverlappedSeq[] = {
572 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
573 { HCBT_SETFOCUS, hook },
574 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
575 { WM_KILLFOCUS, sent },
576 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
577 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
578 { WM_GETTEXT, sent|optional },
579 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCOPYBITS|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
580 { WM_GETMINMAXINFO, sent|defwinproc },
581 { WM_NCCALCSIZE, sent|wparam, TRUE },
582 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
583 { WM_NCPAINT, sent|optional },
584 { WM_GETTEXT, sent|defwinproc|optional },
585 { WM_WINDOWPOSCHANGED, sent },
586 { WM_MOVE, sent|defwinproc },
587 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
588 { WM_NCCALCSIZE, sent|optional },
589 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
590 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
591 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
592 { WM_NCACTIVATE, sent|wparam, 0 },
593 { WM_GETTEXT, sent|defwinproc|optional },
594 { WM_ACTIVATE, sent },
595 { WM_ACTIVATEAPP, sent|wparam, 0 },
597 /* Vista sometimes restores the window right away... */
598 { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
599 { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
600 { HCBT_MINMAX, hook|optional|lparam, 0, SW_RESTORE },
601 { WM_QUERYOPEN, sent|optional },
602 { WM_WINDOWPOSCHANGING, sent|optional|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
603 { WM_GETMINMAXINFO, sent|optional|defwinproc },
604 { WM_NCCALCSIZE, sent|optional|wparam, TRUE },
605 { HCBT_ACTIVATE, hook|optional },
606 { WM_ACTIVATEAPP, sent|optional|wparam, 1 },
607 { WM_NCACTIVATE, sent|optional },
608 { WM_GETTEXT, sent|optional },
609 { WM_ACTIVATE, sent|optional|wparam, 1 },
610 { HCBT_SETFOCUS, hook|optional },
611 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
612 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
613 { WM_SETFOCUS, sent|optional },
614 { WM_NCPAINT, sent|optional },
615 { WM_GETTEXT, sent|defwinproc|optional },
616 { WM_ERASEBKGND, sent|optional },
617 { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
618 { WM_MOVE, sent|defwinproc|optional },
619 { WM_SIZE, sent|defwinproc|optional|wparam, SIZE_RESTORED },
620 { WM_ACTIVATE, sent|optional|wparam, 1 },
621 { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
622 { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
624 { WM_PAINT, sent|optional },
625 { WM_NCPAINT, sent|beginpaint|optional },
626 { WM_ERASEBKGND, sent|beginpaint|optional },
627 { 0 }
629 /* ShowWindow(SW_HIDE) for a visible overlapped window */
630 static const struct message WmHideOverlappedSeq[] = {
631 { WM_SHOWWINDOW, sent|wparam, 0 },
632 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
633 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
634 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
635 { WM_SIZE, sent|optional }, /* XP doesn't send it */
636 { WM_MOVE, sent|optional }, /* XP doesn't send it */
637 { WM_NCACTIVATE, sent|wparam|optional, 0 },
638 { WM_ACTIVATE, sent|wparam|optional, 0 },
639 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
640 { HCBT_SETFOCUS, hook|optional },
641 { WM_KILLFOCUS, sent|wparam, 0 },
642 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
643 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
644 { 0 }
646 /* DestroyWindow for a visible overlapped window */
647 static const struct message WmDestroyOverlappedSeq[] = {
648 { HCBT_DESTROYWND, hook },
649 { 0x0090, sent|optional },
650 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
651 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
652 { 0x0090, sent|optional },
653 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
654 { WM_NCACTIVATE, sent|optional|wparam, 0 },
655 { WM_ACTIVATE, sent|optional },
656 { WM_ACTIVATEAPP, sent|optional|wparam, 0 },
657 { WM_KILLFOCUS, sent|optional|wparam, 0 },
658 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
659 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
660 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
661 { WM_DESTROY, sent },
662 { WM_NCDESTROY, sent },
663 { 0 }
665 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
666 static const struct message WmCreateMaxPopupSeq[] = {
667 { HCBT_CREATEWND, hook },
668 { WM_NCCREATE, sent },
669 { WM_NCCALCSIZE, sent|wparam, 0 },
670 { WM_CREATE, sent },
671 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
672 { WM_SIZE, sent|wparam, SIZE_RESTORED },
673 { WM_MOVE, sent },
674 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
675 { WM_GETMINMAXINFO, sent },
676 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
677 { WM_NCCALCSIZE, sent|wparam, TRUE },
678 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
679 { WM_MOVE, sent|defwinproc },
680 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
681 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
682 { WM_SHOWWINDOW, sent|wparam, 1 },
683 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
684 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
685 { HCBT_ACTIVATE, hook },
686 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
687 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
688 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
689 { WM_NCPAINT, sent|wparam|optional, 1 },
690 { WM_ERASEBKGND, sent|optional },
691 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_NOMOVE|SWP_NOSIZE },
692 { WM_ACTIVATEAPP, sent|wparam, 1 },
693 { WM_NCACTIVATE, sent },
694 { WM_ACTIVATE, sent|wparam, 1 },
695 { HCBT_SETFOCUS, hook },
696 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
697 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
698 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
699 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
700 { WM_GETTEXT, sent|optional },
701 { WM_SYNCPAINT, sent|wparam|optional, 4 },
702 { WM_NCPAINT, sent|wparam|optional, 1 },
703 { WM_ERASEBKGND, sent|optional },
704 { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
705 { WM_ERASEBKGND, sent|defwinproc|optional },
706 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
707 { 0 }
709 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
710 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
711 { HCBT_CREATEWND, hook },
712 { WM_NCCREATE, sent },
713 { WM_NCCALCSIZE, sent|wparam, 0 },
714 { WM_CREATE, sent },
715 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
716 { WM_SIZE, sent|wparam, SIZE_RESTORED },
717 { WM_MOVE, sent },
718 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
719 { WM_GETMINMAXINFO, sent },
720 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
721 { WM_NCCALCSIZE, sent|wparam, TRUE },
722 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
723 { WM_MOVE, sent|defwinproc },
724 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
725 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
726 { 0 }
728 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
729 static const struct message WmShowMaxPopupResizedSeq[] = {
730 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
731 { WM_GETMINMAXINFO, sent },
732 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
733 { WM_NCCALCSIZE, sent|wparam, TRUE },
734 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
735 { HCBT_ACTIVATE, hook },
736 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
737 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
738 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
739 { WM_NCPAINT, sent|wparam|optional, 1 },
740 { WM_ERASEBKGND, sent|optional },
741 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
742 { WM_ACTIVATEAPP, sent|wparam, 1 },
743 { WM_NCACTIVATE, sent },
744 { WM_ACTIVATE, sent|wparam, 1 },
745 { HCBT_SETFOCUS, hook },
746 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
747 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
748 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
749 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
750 { WM_GETTEXT, sent|optional },
751 { WM_NCPAINT, sent|wparam|optional, 1 },
752 { WM_ERASEBKGND, sent|optional },
753 { WM_WINDOWPOSCHANGED, sent },
754 /* WinNT4.0 sends WM_MOVE */
755 { WM_MOVE, sent|defwinproc|optional },
756 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
757 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
758 { 0 }
760 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
761 static const struct message WmShowMaxPopupSeq[] = {
762 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
763 { WM_GETMINMAXINFO, sent },
764 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
765 { WM_NCCALCSIZE, sent|wparam, TRUE },
766 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
767 { HCBT_ACTIVATE, hook },
768 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
769 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
770 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
771 { WM_ACTIVATEAPP, sent|wparam, 1 },
772 { WM_NCACTIVATE, sent },
773 { WM_ACTIVATE, sent|wparam, 1 },
774 { HCBT_SETFOCUS, hook },
775 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
776 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
777 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
778 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
779 { WM_GETTEXT, sent|optional },
780 { WM_SYNCPAINT, sent|wparam|optional, 4 },
781 { WM_NCPAINT, sent|wparam|optional, 1 },
782 { WM_ERASEBKGND, sent|optional },
783 { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
784 { WM_ERASEBKGND, sent|defwinproc|optional },
785 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
786 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
787 { 0 }
789 /* CreateWindow(WS_VISIBLE) for popup window */
790 static const struct message WmCreatePopupSeq[] = {
791 { HCBT_CREATEWND, hook },
792 { WM_NCCREATE, sent },
793 { WM_NCCALCSIZE, sent|wparam, 0 },
794 { WM_CREATE, sent },
795 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
796 { WM_SIZE, sent|wparam, SIZE_RESTORED },
797 { WM_MOVE, sent },
798 { WM_SHOWWINDOW, sent|wparam, 1 },
799 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
800 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
801 { HCBT_ACTIVATE, hook },
802 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
803 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
804 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
805 { WM_NCPAINT, sent|wparam|optional, 1 },
806 { WM_ERASEBKGND, sent|optional },
807 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
808 { WM_ACTIVATEAPP, sent|wparam, 1 },
809 { WM_NCACTIVATE, sent },
810 { WM_ACTIVATE, sent|wparam, 1 },
811 { HCBT_SETFOCUS, hook },
812 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
813 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
814 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
815 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
816 { WM_GETTEXT, sent|optional },
817 { WM_SYNCPAINT, sent|wparam|optional, 4 },
818 { WM_NCPAINT, sent|wparam|optional, 1 },
819 { WM_ERASEBKGND, sent|optional },
820 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
821 { 0 }
823 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
824 static const struct message WmShowVisMaxPopupSeq[] = {
825 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
826 { WM_GETMINMAXINFO, sent },
827 { WM_GETTEXT, sent|optional },
828 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
829 { WM_GETTEXT, sent|optional },
830 { WM_NCCALCSIZE, sent|wparam, TRUE },
831 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
832 { WM_NCPAINT, sent|wparam|optional, 1 },
833 { WM_ERASEBKGND, sent|optional },
834 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
835 { WM_MOVE, sent|defwinproc },
836 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
837 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
838 { 0 }
840 /* CreateWindow (for a child popup window, not initially visible) */
841 static const struct message WmCreateChildPopupSeq[] = {
842 { HCBT_CREATEWND, hook },
843 { WM_NCCREATE, sent },
844 { WM_NCCALCSIZE, sent|wparam, 0 },
845 { WM_CREATE, sent },
846 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
847 { WM_SIZE, sent|wparam, SIZE_RESTORED },
848 { WM_MOVE, sent },
849 { 0 }
851 /* CreateWindow (for a popup window, not initially visible,
852 * which sets WS_VISIBLE in WM_CREATE handler)
854 static const struct message WmCreateInvisiblePopupSeq[] = {
855 { HCBT_CREATEWND, hook },
856 { WM_NCCREATE, sent },
857 { WM_NCCALCSIZE, sent|wparam, 0 },
858 { WM_CREATE, sent },
859 { WM_STYLECHANGING, sent },
860 { WM_STYLECHANGED, sent },
861 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
862 { WM_SIZE, sent|wparam, SIZE_RESTORED },
863 { WM_MOVE, sent },
864 { 0 }
866 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
867 * for a popup window with WS_VISIBLE style set
869 static const struct message WmShowVisiblePopupSeq_2[] = {
870 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
871 { 0 }
873 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
874 * for a popup window with WS_VISIBLE style set
876 static const struct message WmShowVisiblePopupSeq_3[] = {
877 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
878 { HCBT_ACTIVATE, hook },
879 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
880 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
881 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
882 { WM_NCACTIVATE, sent },
883 { WM_ACTIVATE, sent|wparam, 1 },
884 { HCBT_SETFOCUS, hook },
885 { WM_KILLFOCUS, sent|parent },
886 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
887 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
888 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
889 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
890 { WM_SETFOCUS, sent|defwinproc },
891 { WM_GETTEXT, sent|optional },
892 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_SHOWWINDOW },
893 { 0 }
895 /* CreateWindow (for child window, not initially visible) */
896 static const struct message WmCreateChildSeq[] = {
897 { HCBT_CREATEWND, hook },
898 { WM_NCCREATE, sent },
899 /* child is inserted into parent's child list after WM_NCCREATE returns */
900 { WM_NCCALCSIZE, sent|wparam, 0 },
901 { WM_CREATE, sent },
902 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
903 { WM_SIZE, sent|wparam, SIZE_RESTORED },
904 { WM_MOVE, sent },
905 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
906 { 0 }
908 /* CreateWindow (for maximized child window, not initially visible) */
909 static const struct message WmCreateMaximizedChildSeq[] = {
910 { HCBT_CREATEWND, hook },
911 { WM_NCCREATE, sent },
912 { WM_NCCALCSIZE, sent|wparam, 0 },
913 { WM_CREATE, sent },
914 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
915 { WM_SIZE, sent|wparam, SIZE_RESTORED },
916 { WM_MOVE, sent },
917 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
918 { WM_GETMINMAXINFO, sent },
919 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
920 { WM_NCCALCSIZE, sent|wparam, 1 },
921 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
922 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
923 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
924 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
925 { 0 }
927 /* CreateWindow (for a child window, initially visible) */
928 static const struct message WmCreateVisibleChildSeq[] = {
929 { HCBT_CREATEWND, hook },
930 { WM_NCCREATE, sent },
931 /* child is inserted into parent's child list after WM_NCCREATE returns */
932 { WM_NCCALCSIZE, sent|wparam, 0 },
933 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
934 { WM_CREATE, sent },
935 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
936 { WM_SIZE, sent|wparam, SIZE_RESTORED },
937 { WM_MOVE, sent },
938 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
939 { WM_SHOWWINDOW, sent|wparam, 1 },
940 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
941 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
942 { WM_ERASEBKGND, sent|parent|optional },
943 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
944 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
945 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
946 { 0 }
948 /* ShowWindow(SW_SHOW) for a not visible child window */
949 static const struct message WmShowChildSeq[] = {
950 { WM_SHOWWINDOW, sent|wparam, 1 },
951 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
952 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
953 { WM_ERASEBKGND, sent|parent|optional },
954 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
955 { 0 }
957 /* ShowWindow(SW_HIDE) for a visible child window */
958 static const struct message WmHideChildSeq[] = {
959 { WM_SHOWWINDOW, sent|wparam, 0 },
960 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
961 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
962 { WM_ERASEBKGND, sent|parent|optional },
963 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
964 { 0 }
966 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
967 static const struct message WmHideChildSeq2[] = {
968 { WM_SHOWWINDOW, sent|wparam, 0 },
969 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
970 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
971 { WM_ERASEBKGND, sent|parent|optional },
972 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
973 { 0 }
975 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
976 * for a not visible child window
978 static const struct message WmShowChildSeq_2[] = {
979 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
980 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
981 { WM_CHILDACTIVATE, sent },
982 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
983 { 0 }
985 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
986 * for a not visible child window
988 static const struct message WmShowChildSeq_3[] = {
989 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
990 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
991 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
992 { 0 }
994 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
995 * for a visible child window with a caption
997 static const struct message WmShowChildSeq_4[] = {
998 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
999 { WM_CHILDACTIVATE, sent },
1000 { 0 }
1002 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
1003 static const struct message WmShowChildInvisibleParentSeq_1[] = {
1004 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
1005 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
1006 { WM_NCCALCSIZE, sent|wparam, 1 },
1007 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1008 { WM_CHILDACTIVATE, sent|optional },
1009 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
1010 { WM_MOVE, sent|defwinproc },
1011 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1012 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1013 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1014 /* FIXME: Wine creates an icon/title window while Windows doesn't */
1015 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1016 { WM_GETTEXT, sent|optional },
1017 { 0 }
1019 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
1020 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
1021 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
1022 { 0 }
1024 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1025 static const struct message WmShowChildInvisibleParentSeq_2[] = {
1026 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1027 { WM_GETMINMAXINFO, sent },
1028 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
1029 { WM_NCCALCSIZE, sent|wparam, 1 },
1030 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1031 { WM_CHILDACTIVATE, sent },
1032 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
1033 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
1034 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1035 { 0 }
1037 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1038 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
1039 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1040 { 0 }
1042 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1043 static const struct message WmShowChildInvisibleParentSeq_3[] = {
1044 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1045 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
1046 { WM_NCCALCSIZE, sent|wparam, 1 },
1047 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1048 { WM_CHILDACTIVATE, sent },
1049 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1050 { WM_MOVE, sent|defwinproc },
1051 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1052 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1053 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1054 /* FIXME: Wine creates an icon/title window while Windows doesn't */
1055 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1056 { WM_GETTEXT, sent|optional },
1057 { 0 }
1059 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1060 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
1061 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1062 { 0 }
1064 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1065 static const struct message WmShowChildInvisibleParentSeq_4[] = {
1066 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1067 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
1068 { WM_NCCALCSIZE, sent|wparam, 1 },
1069 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1070 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1071 { WM_MOVE, sent|defwinproc },
1072 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1073 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1074 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1075 /* FIXME: Wine creates an icon/title window while Windows doesn't */
1076 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1077 { WM_GETTEXT, sent|optional },
1078 { 0 }
1080 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1081 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
1082 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1083 { 0 }
1085 /* ShowWindow(SW_SHOW) for child with invisible parent */
1086 static const struct message WmShowChildInvisibleParentSeq_5[] = {
1087 { WM_SHOWWINDOW, sent|wparam, 1 },
1088 { 0 }
1090 /* ShowWindow(SW_HIDE) for child with invisible parent */
1091 static const struct message WmHideChildInvisibleParentSeq[] = {
1092 { WM_SHOWWINDOW, sent|wparam, 0 },
1093 { 0 }
1095 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
1096 static const struct message WmShowChildInvisibleParentSeq_6[] = {
1097 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1098 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1099 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1100 { 0 }
1102 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
1103 static const struct message WmHideChildInvisibleParentSeq_2[] = {
1104 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1105 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1106 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1107 { 0 }
1109 /* DestroyWindow for a visible child window */
1110 static const struct message WmDestroyChildSeq[] = {
1111 { HCBT_DESTROYWND, hook },
1112 { 0x0090, sent|optional },
1113 { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1114 { WM_SHOWWINDOW, sent|wparam, 0 },
1115 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1116 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1117 { WM_ERASEBKGND, sent|parent|optional },
1118 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1119 { HCBT_SETFOCUS, hook }, /* set focus to a parent */
1120 { WM_KILLFOCUS, sent },
1121 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1122 { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
1123 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1124 { WM_SETFOCUS, sent|parent },
1125 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1126 { WM_DESTROY, sent },
1127 { WM_DESTROY, sent|optional }, /* some other (IME?) window */
1128 { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
1129 { WM_NCDESTROY, sent },
1130 { 0 }
1132 /* visible child window destroyed by thread exit */
1133 static const struct message WmExitThreadSeq[] = {
1134 { WM_NCDESTROY, sent }, /* actually in grandchild */
1135 { WM_PAINT, sent|parent },
1136 { WM_ERASEBKGND, sent|parent|beginpaint },
1137 { 0 }
1139 /* DestroyWindow for a visible child window with invisible parent */
1140 static const struct message WmDestroyInvisibleChildSeq[] = {
1141 { HCBT_DESTROYWND, hook },
1142 { 0x0090, sent|optional },
1143 { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1144 { WM_SHOWWINDOW, sent|wparam, 0 },
1145 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1146 { WM_DESTROY, sent },
1147 { WM_NCDESTROY, sent },
1148 { 0 }
1150 /* Moving the mouse in nonclient area */
1151 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
1152 { WM_NCHITTEST, sent },
1153 { WM_SETCURSOR, sent },
1154 { WM_NCMOUSEMOVE, posted },
1155 { 0 }
1157 /* Moving the mouse in client area */
1158 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
1159 { WM_NCHITTEST, sent },
1160 { WM_SETCURSOR, sent },
1161 { WM_MOUSEMOVE, posted },
1162 { 0 }
1164 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1165 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
1166 { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
1167 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
1168 { WM_GETMINMAXINFO, sent|defwinproc },
1169 { WM_ENTERSIZEMOVE, sent|defwinproc },
1170 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1171 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1172 { WM_MOVE, sent|defwinproc },
1173 { WM_EXITSIZEMOVE, sent|defwinproc },
1174 { 0 }
1176 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1177 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
1178 { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
1179 { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
1180 { WM_GETMINMAXINFO, sent|defwinproc },
1181 { WM_ENTERSIZEMOVE, sent|defwinproc },
1182 { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
1183 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1184 { WM_GETMINMAXINFO, sent|defwinproc },
1185 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1186 { WM_NCPAINT, sent|defwinproc|wparam, 1 },
1187 { WM_GETTEXT, sent|defwinproc },
1188 { WM_ERASEBKGND, sent|defwinproc },
1189 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1190 { WM_MOVE, sent|defwinproc },
1191 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1192 { WM_EXITSIZEMOVE, sent|defwinproc },
1193 { 0 }
1195 /* Resizing child window with MoveWindow (32) */
1196 static const struct message WmResizingChildWithMoveWindowSeq[] = {
1197 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1198 { WM_NCCALCSIZE, sent|wparam, 1 },
1199 { WM_ERASEBKGND, sent|parent|optional },
1200 { WM_ERASEBKGND, sent|optional },
1201 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
1202 { WM_MOVE, sent|defwinproc },
1203 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1204 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1205 { 0 }
1207 /* Clicking on inactive button */
1208 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
1209 { WM_NCHITTEST, sent },
1210 { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
1211 { WM_MOUSEACTIVATE, sent },
1212 { WM_MOUSEACTIVATE, sent|parent|defwinproc },
1213 { WM_SETCURSOR, sent },
1214 { WM_SETCURSOR, sent|parent|defwinproc },
1215 { WM_LBUTTONDOWN, posted },
1216 { WM_KILLFOCUS, posted|parent },
1217 { WM_SETFOCUS, posted },
1218 { WM_CTLCOLORBTN, posted|parent },
1219 { BM_SETSTATE, posted },
1220 { WM_CTLCOLORBTN, posted|parent },
1221 { WM_LBUTTONUP, posted },
1222 { BM_SETSTATE, posted },
1223 { WM_CTLCOLORBTN, posted|parent },
1224 { WM_COMMAND, posted|parent },
1225 { 0 }
1227 /* Reparenting a button (16/32) */
1228 /* The last child (button) reparented gets topmost for its new parent. */
1229 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
1230 { WM_SHOWWINDOW, sent|wparam, 0 },
1231 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1232 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1233 { WM_ERASEBKGND, sent|parent },
1234 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1235 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
1236 { WM_CHILDACTIVATE, sent },
1237 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
1238 { WM_MOVE, sent|defwinproc },
1239 { WM_SHOWWINDOW, sent|wparam, 1 },
1240 { 0 }
1242 /* Creation of a custom dialog (32) */
1243 static const struct message WmCreateCustomDialogSeq[] = {
1244 { HCBT_CREATEWND, hook },
1245 { WM_GETMINMAXINFO, sent },
1246 { WM_NCCREATE, sent },
1247 { WM_NCCALCSIZE, sent|wparam, 0 },
1248 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1249 { WM_CREATE, sent },
1250 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1251 { WM_NOTIFYFORMAT, sent|optional },
1252 { WM_QUERYUISTATE, sent|optional },
1253 { WM_WINDOWPOSCHANGING, sent|optional },
1254 { WM_GETMINMAXINFO, sent|optional },
1255 { WM_NCCALCSIZE, sent|optional },
1256 { WM_WINDOWPOSCHANGED, sent|optional },
1257 { WM_SHOWWINDOW, sent|wparam, 1 },
1258 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1259 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1260 { HCBT_ACTIVATE, hook },
1261 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1264 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1266 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1268 { WM_NCACTIVATE, sent },
1269 { WM_GETTEXT, sent|optional|defwinproc },
1270 { WM_GETTEXT, sent|optional|defwinproc },
1271 { WM_GETTEXT, sent|optional|defwinproc },
1272 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1273 { WM_ACTIVATE, sent|wparam, 1 },
1274 { WM_GETTEXT, sent|optional },
1275 { WM_KILLFOCUS, sent|parent },
1276 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1277 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1278 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1279 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1280 { WM_SETFOCUS, sent },
1281 { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1282 { WM_NCPAINT, sent|wparam, 1 },
1283 { WM_GETTEXT, sent|optional|defwinproc },
1284 { WM_GETTEXT, sent|optional|defwinproc },
1285 { WM_ERASEBKGND, sent },
1286 { WM_CTLCOLORDLG, sent|optional|defwinproc },
1287 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1288 { WM_GETTEXT, sent|optional },
1289 { WM_GETTEXT, sent|optional },
1290 { WM_NCCALCSIZE, sent|optional },
1291 { WM_NCPAINT, sent|optional },
1292 { WM_GETTEXT, sent|optional|defwinproc },
1293 { WM_GETTEXT, sent|optional|defwinproc },
1294 { WM_ERASEBKGND, sent|optional },
1295 { WM_CTLCOLORDLG, sent|optional|defwinproc },
1296 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1297 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1298 { WM_MOVE, sent },
1299 { 0 }
1301 /* Calling EndDialog for a custom dialog (32) */
1302 static const struct message WmEndCustomDialogSeq[] = {
1303 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1304 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1305 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1306 { WM_GETTEXT, sent|optional },
1307 { HCBT_ACTIVATE, hook },
1308 { WM_NCACTIVATE, sent|wparam, 0 },
1309 { WM_GETTEXT, sent|optional|defwinproc },
1310 { WM_GETTEXT, sent|optional|defwinproc },
1311 { WM_ACTIVATE, sent|wparam, 0 },
1312 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1313 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1314 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1315 { WM_GETTEXT, sent|optional|defwinproc },
1316 { WM_GETTEXT, sent|optional|defwinproc },
1317 { HCBT_SETFOCUS, hook },
1318 { WM_KILLFOCUS, sent },
1319 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1320 { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1321 { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1322 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1323 { WM_SETFOCUS, sent|parent|defwinproc },
1324 { 0 }
1326 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1327 static const struct message WmShowCustomDialogSeq[] = {
1328 { WM_SHOWWINDOW, sent|wparam, 1 },
1329 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1330 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1331 { HCBT_ACTIVATE, hook },
1332 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1334 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1336 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1337 { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1338 { WM_NCACTIVATE, sent },
1339 { WM_ACTIVATE, sent|wparam, 1 },
1340 { WM_GETTEXT, sent|optional },
1342 { WM_KILLFOCUS, sent|parent },
1343 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1344 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1345 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1346 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1347 { WM_SETFOCUS, sent },
1348 { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1349 { WM_NCPAINT, sent|wparam, 1 },
1350 { WM_ERASEBKGND, sent },
1351 { WM_CTLCOLORDLG, sent|defwinproc },
1352 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1353 { 0 }
1355 /* Creation and destruction of a modal dialog (32) */
1356 static const struct message WmModalDialogSeq[] = {
1357 { WM_CANCELMODE, sent|parent },
1358 { HCBT_SETFOCUS, hook },
1359 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1360 { WM_KILLFOCUS, sent|parent },
1361 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1362 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1363 { WM_ENABLE, sent|parent|wparam, 0 },
1364 { HCBT_CREATEWND, hook },
1365 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1366 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1367 { WM_SETFONT, sent },
1368 { WM_INITDIALOG, sent },
1369 { WM_CHANGEUISTATE, sent|optional },
1370 { WM_UPDATEUISTATE, sent|optional },
1371 { WM_SHOWWINDOW, sent },
1372 { HCBT_ACTIVATE, hook },
1373 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1374 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1375 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1376 { WM_NCACTIVATE, sent },
1377 { WM_GETTEXT, sent|optional },
1378 { WM_ACTIVATE, sent|wparam, 1 },
1379 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1380 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1381 { WM_NCPAINT, sent|optional },
1382 { WM_GETTEXT, sent|optional },
1383 { WM_ERASEBKGND, sent|optional },
1384 { WM_CTLCOLORDLG, sent|optional },
1385 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1386 { WM_GETTEXT, sent|optional },
1387 { WM_NCCALCSIZE, sent|optional },
1388 { WM_NCPAINT, sent|optional },
1389 { WM_GETTEXT, sent|optional },
1390 { WM_ERASEBKGND, sent|optional },
1391 { WM_CTLCOLORDLG, sent|optional },
1392 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1393 { WM_PAINT, sent|optional },
1394 { WM_CTLCOLORBTN, sent|optional },
1395 { WM_GETTITLEBARINFOEX, sent|optional },
1396 { WM_ENTERIDLE, sent|parent|optional },
1397 { WM_ENTERIDLE, sent|parent|optional },
1398 { WM_ENTERIDLE, sent|parent|optional },
1399 { WM_ENTERIDLE, sent|parent|optional },
1400 { WM_ENTERIDLE, sent|parent|optional },
1401 { WM_ENTERIDLE, sent|parent|optional },
1402 { WM_ENTERIDLE, sent|parent|optional },
1403 { WM_ENTERIDLE, sent|parent|optional },
1404 { WM_ENTERIDLE, sent|parent|optional },
1405 { WM_ENTERIDLE, sent|parent|optional },
1406 { WM_ENTERIDLE, sent|parent|optional },
1407 { WM_ENTERIDLE, sent|parent|optional },
1408 { WM_ENTERIDLE, sent|parent|optional },
1409 { WM_ENTERIDLE, sent|parent|optional },
1410 { WM_ENTERIDLE, sent|parent|optional },
1411 { WM_ENTERIDLE, sent|parent|optional },
1412 { WM_ENTERIDLE, sent|parent|optional },
1413 { WM_ENTERIDLE, sent|parent|optional },
1414 { WM_ENTERIDLE, sent|parent|optional },
1415 { WM_ENTERIDLE, sent|parent|optional },
1416 { WM_TIMER, sent },
1417 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1418 { WM_ENABLE, sent|parent|wparam, 1 },
1419 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1420 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1421 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1422 { WM_GETTEXT, sent|optional },
1423 { HCBT_ACTIVATE, hook },
1424 { WM_NCACTIVATE, sent|wparam, 0 },
1425 { WM_GETTEXT, sent|optional },
1426 { WM_ACTIVATE, sent|wparam, 0 },
1427 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1428 { WM_WINDOWPOSCHANGING, sent|optional },
1429 { WM_WINDOWPOSCHANGED, sent|optional },
1430 { HCBT_SETFOCUS, hook },
1431 { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1432 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1433 { WM_SETFOCUS, sent|parent|defwinproc },
1434 { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1435 { HCBT_DESTROYWND, hook },
1436 { 0x0090, sent|optional },
1437 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1438 { WM_DESTROY, sent },
1439 { WM_NCDESTROY, sent },
1440 { 0 }
1442 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1443 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1444 /* (inside dialog proc, handling WM_INITDIALOG) */
1445 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1446 { WM_NCCALCSIZE, sent },
1447 { WM_NCACTIVATE, sent|parent|wparam, 0 },
1448 { WM_GETTEXT, sent|defwinproc },
1449 { WM_ACTIVATE, sent|parent|wparam, 0 },
1450 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1451 { WM_WINDOWPOSCHANGING, sent|parent },
1452 { WM_NCACTIVATE, sent|wparam, 1 },
1453 { WM_ACTIVATE, sent|wparam, 1 },
1454 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1455 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1456 /* (setting focus) */
1457 { WM_SHOWWINDOW, sent|wparam, 1 },
1458 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1459 { WM_NCPAINT, sent },
1460 { WM_GETTEXT, sent|defwinproc },
1461 { WM_ERASEBKGND, sent },
1462 { WM_CTLCOLORDLG, sent|defwinproc },
1463 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1464 { WM_PAINT, sent },
1465 /* (bunch of WM_CTLCOLOR* for each control) */
1466 { WM_PAINT, sent|parent },
1467 { WM_ENTERIDLE, sent|parent|wparam, 0 },
1468 { WM_SETCURSOR, sent|parent },
1469 { 0 }
1471 /* SetMenu for NonVisible windows with size change*/
1472 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1473 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1474 { WM_NCCALCSIZE, sent|wparam, 1 },
1475 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1476 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1477 { WM_MOVE, sent|defwinproc },
1478 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1479 { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1480 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1481 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1482 { WM_GETTEXT, sent|optional },
1483 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1484 { 0 }
1486 /* SetMenu for NonVisible windows with no size change */
1487 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1488 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1489 { WM_NCCALCSIZE, sent|wparam, 1 },
1490 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1491 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1492 { 0 }
1494 /* SetMenu for Visible windows with size change */
1495 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1496 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1497 { WM_NCCALCSIZE, sent|wparam, 1 },
1498 { 0x0093, sent|defwinproc|optional },
1499 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1500 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1501 { 0x0093, sent|defwinproc|optional },
1502 { 0x0093, sent|defwinproc|optional },
1503 { 0x0091, sent|defwinproc|optional },
1504 { 0x0092, sent|defwinproc|optional },
1505 { WM_GETTEXT, sent|defwinproc|optional },
1506 { WM_ERASEBKGND, sent|optional },
1507 { WM_ACTIVATE, sent|optional },
1508 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1509 { WM_MOVE, sent|defwinproc },
1510 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1511 { 0x0093, sent|optional },
1512 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1513 { 0x0093, sent|defwinproc|optional },
1514 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1515 { 0x0093, sent|defwinproc|optional },
1516 { 0x0093, sent|defwinproc|optional },
1517 { 0x0091, sent|defwinproc|optional },
1518 { 0x0092, sent|defwinproc|optional },
1519 { WM_ERASEBKGND, sent|optional },
1520 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1521 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1522 { 0 }
1524 /* SetMenu for Visible windows with no size change */
1525 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1526 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1527 { WM_NCCALCSIZE, sent|wparam, 1 },
1528 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1529 { WM_GETTEXT, sent|defwinproc|optional },
1530 { WM_ERASEBKGND, sent|optional },
1531 { WM_ACTIVATE, sent|optional },
1532 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1533 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1534 { 0 }
1536 /* DrawMenuBar for a visible window */
1537 static const struct message WmDrawMenuBarSeq[] =
1539 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1540 { WM_NCCALCSIZE, sent|wparam, 1 },
1541 { 0x0093, sent|defwinproc|optional },
1542 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1543 { 0x0093, sent|defwinproc|optional },
1544 { 0x0093, sent|defwinproc|optional },
1545 { 0x0091, sent|defwinproc|optional },
1546 { 0x0092, sent|defwinproc|optional },
1547 { WM_GETTEXT, sent|defwinproc|optional },
1548 { WM_ERASEBKGND, sent|optional },
1549 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1550 { 0x0093, sent|optional },
1551 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1552 { 0 }
1555 static const struct message WmSetRedrawFalseSeq[] =
1557 { WM_SETREDRAW, sent|wparam, 0 },
1558 { 0 }
1561 static const struct message WmSetRedrawTrueSeq[] =
1563 { WM_SETREDRAW, sent|wparam, 1 },
1564 { 0 }
1567 static const struct message WmEnableWindowSeq_1[] =
1569 { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1570 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1571 { HCBT_SETFOCUS, hook|optional },
1572 { WM_KILLFOCUS, sent|optional },
1573 { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1574 { 0 }
1577 static const struct message WmEnableWindowSeq_2[] =
1579 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1580 { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1581 { 0 }
1584 static const struct message WmGetScrollRangeSeq[] =
1586 { SBM_GETRANGE, sent },
1587 { 0 }
1589 static const struct message WmGetScrollInfoSeq[] =
1591 { SBM_GETSCROLLINFO, sent },
1592 { 0 }
1594 static const struct message WmSetScrollRangeSeq[] =
1596 /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1597 sends SBM_SETSCROLLINFO.
1599 { SBM_SETSCROLLINFO, sent },
1600 { 0 }
1602 /* SetScrollRange for a window without a non-client area */
1603 static const struct message WmSetScrollRangeHSeq_empty[] =
1605 { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1606 { 0 }
1608 static const struct message WmSetScrollRangeVSeq_empty[] =
1610 { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1611 { 0 }
1613 static const struct message WmSetScrollRangeHVSeq[] =
1615 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1616 { WM_NCCALCSIZE, sent|wparam, 1 },
1617 { WM_GETTEXT, sent|defwinproc|optional },
1618 { WM_ERASEBKGND, sent|optional },
1619 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1620 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1621 { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1622 { 0 }
1624 /* SetScrollRange for a window with a non-client area */
1625 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1627 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1628 { WM_NCCALCSIZE, sent|wparam, 1 },
1629 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1630 { WM_NCPAINT, sent|optional },
1631 { WM_STYLECHANGING, sent|defwinproc|optional },
1632 { WM_STYLECHANGED, sent|defwinproc|optional },
1633 { WM_STYLECHANGING, sent|defwinproc|optional },
1634 { WM_STYLECHANGED, sent|defwinproc|optional },
1635 { WM_STYLECHANGING, sent|defwinproc|optional },
1636 { WM_STYLECHANGED, sent|defwinproc|optional },
1637 { WM_STYLECHANGING, sent|defwinproc|optional },
1638 { WM_STYLECHANGED, sent|defwinproc|optional },
1639 { WM_GETTEXT, sent|defwinproc|optional },
1640 { WM_GETTEXT, sent|defwinproc|optional },
1641 { WM_ERASEBKGND, sent|optional },
1642 { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1643 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOCLIENTSIZE },
1644 { WM_SIZE, sent|defwinproc|optional },
1645 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1646 { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1647 { WM_GETTEXT, sent|optional },
1648 { WM_GETTEXT, sent|optional },
1649 { WM_GETTEXT, sent|optional },
1650 { WM_GETTEXT, sent|optional },
1651 { 0 }
1653 /* test if we receive the right sequence of messages */
1654 /* after calling ShowWindow( SW_SHOWNA) */
1655 static const struct message WmSHOWNAChildInvisParInvis[] = {
1656 { WM_SHOWWINDOW, sent|wparam, 1 },
1657 { 0 }
1659 static const struct message WmSHOWNAChildVisParInvis[] = {
1660 { WM_SHOWWINDOW, sent|wparam, 1 },
1661 { 0 }
1663 static const struct message WmSHOWNAChildVisParVis[] = {
1664 { WM_SHOWWINDOW, sent|wparam, 1 },
1665 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1666 { 0 }
1668 static const struct message WmSHOWNAChildInvisParVis[] = {
1669 { WM_SHOWWINDOW, sent|wparam, 1 },
1670 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1671 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1672 { WM_ERASEBKGND, sent|optional },
1673 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1674 { 0 }
1676 static const struct message WmSHOWNATopVisible[] = {
1677 { WM_SHOWWINDOW, sent|wparam, 1 },
1678 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1679 { WM_NCPAINT, sent|wparam|optional, 1 },
1680 { WM_GETTEXT, sent|defwinproc|optional },
1681 { WM_ERASEBKGND, sent|optional },
1682 { WM_WINDOWPOSCHANGED, sent|optional },
1683 { 0 }
1685 static const struct message WmSHOWNATopInvisible[] = {
1686 { WM_NOTIFYFORMAT, sent|optional },
1687 { WM_QUERYUISTATE, sent|optional },
1688 { WM_WINDOWPOSCHANGING, sent|optional },
1689 { WM_GETMINMAXINFO, sent|optional },
1690 { WM_NCCALCSIZE, sent|optional },
1691 { WM_WINDOWPOSCHANGED, sent|optional },
1692 { WM_SHOWWINDOW, sent|wparam, 1 },
1693 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1694 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1695 { WM_NCPAINT, sent|wparam|optional, 1 },
1696 { WM_GETTEXT, sent|defwinproc|optional },
1697 { WM_ERASEBKGND, sent|optional },
1698 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1699 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1700 { WM_NCPAINT, sent|wparam|optional, 1 },
1701 { WM_ERASEBKGND, sent|optional },
1702 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1703 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1704 { WM_MOVE, sent },
1705 { 0 }
1708 static int after_end_dialog, test_def_id;
1709 static int sequence_cnt, sequence_size;
1710 static struct recvd_message* sequence;
1711 static int log_all_parent_messages;
1712 static int paint_loop_done;
1714 /* user32 functions */
1715 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1716 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
1717 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1718 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
1719 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1720 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1721 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1722 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
1723 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
1724 /* kernel32 functions */
1725 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1727 static void init_procs(void)
1729 HMODULE user32 = GetModuleHandleA("user32.dll");
1730 HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1732 #define GET_PROC(dll, func) \
1733 p ## func = (void*)GetProcAddress(dll, #func); \
1734 if(!p ## func) { \
1735 trace("GetProcAddress(%s) failed\n", #func); \
1738 GET_PROC(user32, GetAncestor)
1739 GET_PROC(user32, GetMenuInfo)
1740 GET_PROC(user32, NotifyWinEvent)
1741 GET_PROC(user32, SetMenuInfo)
1742 GET_PROC(user32, SetWinEventHook)
1743 GET_PROC(user32, TrackMouseEvent)
1744 GET_PROC(user32, UnhookWinEvent)
1745 GET_PROC(user32, GetMonitorInfoA)
1746 GET_PROC(user32, MonitorFromPoint)
1748 GET_PROC(kernel32, GetCPInfoExA)
1750 #undef GET_PROC
1753 static const char *get_winpos_flags(UINT flags)
1755 static char buffer[300];
1757 buffer[0] = 0;
1758 #define DUMP(flag) do { if (flags & flag) { strcat( buffer, "|" #flag ); flags &= ~flag; } } while(0)
1759 DUMP( SWP_SHOWWINDOW );
1760 DUMP( SWP_HIDEWINDOW );
1761 DUMP( SWP_NOACTIVATE );
1762 DUMP( SWP_FRAMECHANGED );
1763 DUMP( SWP_NOCOPYBITS );
1764 DUMP( SWP_NOOWNERZORDER );
1765 DUMP( SWP_NOSENDCHANGING );
1766 DUMP( SWP_DEFERERASE );
1767 DUMP( SWP_ASYNCWINDOWPOS );
1768 DUMP( SWP_NOZORDER );
1769 DUMP( SWP_NOREDRAW );
1770 DUMP( SWP_NOSIZE );
1771 DUMP( SWP_NOMOVE );
1772 DUMP( SWP_NOCLIENTSIZE );
1773 DUMP( SWP_NOCLIENTMOVE );
1774 if (flags) sprintf(buffer + strlen(buffer),"|0x%04x", flags);
1775 return buffer + 1;
1776 #undef DUMP
1779 static BOOL ignore_message( UINT message )
1781 /* these are always ignored */
1782 return (message >= 0xc000 ||
1783 message == WM_GETICON ||
1784 message == WM_GETOBJECT ||
1785 message == WM_TIMECHANGE ||
1786 message == WM_DISPLAYCHANGE ||
1787 message == WM_DEVICECHANGE ||
1788 message == WM_DWMNCRENDERINGCHANGED);
1792 #define add_message(msg) add_message_(__LINE__,msg);
1793 static void add_message_(int line, const struct recvd_message *msg)
1795 struct recvd_message *seq;
1797 if (!sequence)
1799 sequence_size = 10;
1800 sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof(*sequence) );
1802 if (sequence_cnt == sequence_size)
1804 sequence_size *= 2;
1805 sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof(*sequence) );
1807 assert(sequence);
1809 seq = &sequence[sequence_cnt];
1810 seq->hwnd = msg->hwnd;
1811 seq->message = msg->message;
1812 seq->flags = msg->flags;
1813 seq->wParam = msg->wParam;
1814 seq->lParam = msg->lParam;
1815 seq->line = line;
1816 seq->descr = msg->descr;
1817 seq->output[0] = 0;
1819 if (msg->descr)
1821 if (msg->flags & hook)
1823 static const char * const CBT_code_name[10] =
1825 "HCBT_MOVESIZE",
1826 "HCBT_MINMAX",
1827 "HCBT_QS",
1828 "HCBT_CREATEWND",
1829 "HCBT_DESTROYWND",
1830 "HCBT_ACTIVATE",
1831 "HCBT_CLICKSKIPPED",
1832 "HCBT_KEYSKIPPED",
1833 "HCBT_SYSCOMMAND",
1834 "HCBT_SETFOCUS"
1836 const char *code_name = (msg->message <= HCBT_SETFOCUS) ? CBT_code_name[msg->message] : "Unknown";
1838 sprintf( seq->output, "%s: hook %d (%s) wp %08lx lp %08lx",
1839 msg->descr, msg->message, code_name, msg->wParam, msg->lParam );
1841 else if (msg->flags & winevent_hook)
1843 sprintf( seq->output, "%s: winevent %p %08x %08lx %08lx",
1844 msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1846 else
1848 switch (msg->message)
1850 case WM_WINDOWPOSCHANGING:
1851 case WM_WINDOWPOSCHANGED:
1853 WINDOWPOS *winpos = (WINDOWPOS *)msg->lParam;
1855 sprintf( seq->output, "%s: %p WM_WINDOWPOS%s wp %08lx lp %08lx after %p x %d y %d cx %d cy %d flags %s",
1856 msg->descr, msg->hwnd,
1857 (msg->message == WM_WINDOWPOSCHANGING) ? "CHANGING" : "CHANGED",
1858 msg->wParam, msg->lParam, winpos->hwndInsertAfter,
1859 winpos->x, winpos->y, winpos->cx, winpos->cy,
1860 get_winpos_flags(winpos->flags) );
1862 /* Log only documented flags, win2k uses 0x1000 and 0x2000
1863 * in the high word for internal purposes
1865 seq->wParam = winpos->flags & 0xffff;
1866 /* We are not interested in the flags that don't match under XP and Win9x */
1867 seq->wParam &= ~SWP_NOZORDER;
1868 break;
1871 case WM_DRAWITEM:
1873 DRAW_ITEM_STRUCT di;
1874 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)msg->lParam;
1876 sprintf( seq->output, "%s: %p WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x",
1877 msg->descr, msg->hwnd, dis->CtlType, dis->CtlID,
1878 dis->itemID, dis->itemAction, dis->itemState);
1880 di.u.lp = 0;
1881 di.u.item.type = dis->CtlType;
1882 di.u.item.ctl_id = dis->CtlID;
1883 if (dis->CtlType == ODT_LISTBOX ||
1884 dis->CtlType == ODT_COMBOBOX ||
1885 dis->CtlType == ODT_MENU)
1886 di.u.item.item_id = dis->itemID;
1887 di.u.item.action = dis->itemAction;
1888 di.u.item.state = dis->itemState;
1890 seq->lParam = di.u.lp;
1891 break;
1893 default:
1894 if (msg->message >= 0xc000) return; /* ignore registered messages */
1895 sprintf( seq->output, "%s: %p %04x wp %08lx lp %08lx",
1896 msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1898 if (msg->flags & (sent|posted|parent|defwinproc|beginpaint))
1899 sprintf( seq->output + strlen(seq->output), " (flags %x)", msg->flags );
1903 sequence_cnt++;
1906 /* try to make sure pending X events have been processed before continuing */
1907 static void flush_events(void)
1909 MSG msg;
1910 int diff = 200;
1911 int min_timeout = 100;
1912 DWORD time = GetTickCount() + diff;
1914 while (diff > 0)
1916 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1917 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1918 diff = time - GetTickCount();
1922 static void flush_sequence(void)
1924 HeapFree(GetProcessHeap(), 0, sequence);
1925 sequence = 0;
1926 sequence_cnt = sequence_size = 0;
1929 static void dump_sequence(const struct message *expected, const char *context, const char *file, int line)
1931 const struct recvd_message *actual = sequence;
1932 unsigned int count = 0;
1934 trace_(file, line)("Failed sequence %s:\n", context );
1935 while (expected->message && actual->message)
1937 if (actual->output[0])
1939 if (expected->flags & hook)
1941 trace_(file, line)( " %u: expected: hook %04x - actual: %s\n",
1942 count, expected->message, actual->output );
1944 else if (expected->flags & winevent_hook)
1946 trace_(file, line)( " %u: expected: winevent %04x - actual: %s\n",
1947 count, expected->message, actual->output );
1949 else if (expected->flags & kbd_hook)
1951 trace_(file, line)( " %u: expected: kbd %04x - actual: %s\n",
1952 count, expected->message, actual->output );
1954 else
1956 trace_(file, line)( " %u: expected: msg %04x - actual: %s\n",
1957 count, expected->message, actual->output );
1961 if (expected->message == actual->message)
1963 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) &&
1964 (expected->flags & optional))
1966 /* don't match messages if their defwinproc status differs */
1967 expected++;
1969 else
1971 expected++;
1972 actual++;
1975 /* silently drop winevent messages if there is no support for them */
1976 else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1977 expected++;
1978 else
1980 expected++;
1981 actual++;
1983 count++;
1986 /* optional trailing messages */
1987 while (expected->message && ((expected->flags & optional) ||
1988 ((expected->flags & winevent_hook) && !hEvent_hook)))
1990 trace_(file, line)( " %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1991 expected++;
1992 count++;
1995 if (expected->message)
1997 trace_(file, line)( " %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1998 return;
2001 while (actual->message && actual->output[0])
2003 trace_(file, line)( " %u: expected: nothing - actual: %s\n", count, actual->output );
2004 actual++;
2005 count++;
2009 #define ok_sequence( exp, contx, todo) \
2010 ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
2013 static void ok_sequence_(const struct message *expected_list, const char *context, int todo,
2014 const char *file, int line)
2016 static const struct recvd_message end_of_sequence;
2017 const struct message *expected = expected_list;
2018 const struct recvd_message *actual;
2019 int failcount = 0, dump = 0;
2020 unsigned int count = 0;
2022 add_message(&end_of_sequence);
2024 actual = sequence;
2026 while (expected->message && actual->message)
2028 if (expected->message == actual->message &&
2029 !((expected->flags ^ actual->flags) & (hook|winevent_hook|kbd_hook)))
2031 if (expected->flags & wparam)
2033 if (((expected->wParam ^ actual->wParam) & ~expected->wp_mask) && todo)
2035 todo_wine {
2036 failcount ++;
2037 if (strcmp(winetest_platform, "wine")) dump++;
2038 ok_( file, line) (FALSE,
2039 "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2040 context, count, expected->message, expected->wParam, actual->wParam);
2043 else
2045 ok_( file, line)( ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) == 0,
2046 "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2047 context, count, expected->message, expected->wParam, actual->wParam);
2048 if ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) dump++;
2052 if (expected->flags & lparam)
2054 if (((expected->lParam ^ actual->lParam) & ~expected->lp_mask) && todo)
2056 todo_wine {
2057 failcount ++;
2058 if (strcmp(winetest_platform, "wine")) dump++;
2059 ok_( file, line) (FALSE,
2060 "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2061 context, count, expected->message, expected->lParam, actual->lParam);
2064 else
2066 ok_( file, line)(((expected->lParam ^ actual->lParam) & ~expected->lp_mask) == 0,
2067 "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2068 context, count, expected->message, expected->lParam, actual->lParam);
2069 if ((expected->lParam ^ actual->lParam) & ~expected->lp_mask) dump++;
2072 if ((expected->flags & optional) &&
2073 ((expected->flags ^ actual->flags) & (defwinproc|parent)))
2075 /* don't match optional messages if their defwinproc or parent status differs */
2076 expected++;
2077 count++;
2078 continue;
2080 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
2082 todo_wine {
2083 failcount ++;
2084 if (strcmp(winetest_platform, "wine")) dump++;
2085 ok_( file, line) (FALSE,
2086 "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2087 context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2090 else
2092 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
2093 "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2094 context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2095 if ((expected->flags & defwinproc) != (actual->flags & defwinproc)) dump++;
2098 ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
2099 "%s: %u: the msg 0x%04x should %shave been sent by BeginPaint\n",
2100 context, count, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
2101 if ((expected->flags & beginpaint) != (actual->flags & beginpaint)) dump++;
2103 ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
2104 "%s: %u: the msg 0x%04x should have been %s\n",
2105 context, count, expected->message, (expected->flags & posted) ? "posted" : "sent");
2106 if ((expected->flags & (sent|posted)) != (actual->flags & (sent|posted))) dump++;
2108 ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
2109 "%s: %u: the msg 0x%04x was expected in %s\n",
2110 context, count, expected->message, (expected->flags & parent) ? "parent" : "child");
2111 if ((expected->flags & parent) != (actual->flags & parent)) dump++;
2113 ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
2114 "%s: %u: the msg 0x%04x should have been sent by a hook\n",
2115 context, count, expected->message);
2116 if ((expected->flags & hook) != (actual->flags & hook)) dump++;
2118 ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
2119 "%s: %u: the msg 0x%04x should have been sent by a winevent hook\n",
2120 context, count, expected->message);
2121 if ((expected->flags & winevent_hook) != (actual->flags & winevent_hook)) dump++;
2123 ok_( file, line) ((expected->flags & kbd_hook) == (actual->flags & kbd_hook),
2124 "%s: %u: the msg 0x%04x should have been sent by a keyboard hook\n",
2125 context, count, expected->message);
2126 if ((expected->flags & kbd_hook) != (actual->flags & kbd_hook)) dump++;
2128 expected++;
2129 actual++;
2131 /* silently drop hook messages if there is no support for them */
2132 else if ((expected->flags & optional) ||
2133 ((expected->flags & hook) && !hCBT_hook) ||
2134 ((expected->flags & winevent_hook) && !hEvent_hook) ||
2135 ((expected->flags & kbd_hook) && !hKBD_hook))
2136 expected++;
2137 else if (todo)
2139 failcount++;
2140 todo_wine {
2141 if (strcmp(winetest_platform, "wine")) dump++;
2142 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2143 context, count, expected->message, actual->message);
2145 goto done;
2147 else
2149 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2150 context, count, expected->message, actual->message);
2151 dump++;
2152 expected++;
2153 actual++;
2155 count++;
2158 /* skip all optional trailing messages */
2159 while (expected->message && ((expected->flags & optional) ||
2160 ((expected->flags & hook) && !hCBT_hook) ||
2161 ((expected->flags & winevent_hook) && !hEvent_hook)))
2162 expected++;
2164 if (todo)
2166 todo_wine {
2167 if (expected->message || actual->message) {
2168 failcount++;
2169 if (strcmp(winetest_platform, "wine")) dump++;
2170 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2171 context, count, expected->message, actual->message);
2175 else
2177 if (expected->message || actual->message)
2179 dump++;
2180 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2181 context, count, expected->message, actual->message);
2184 if( todo && !failcount) /* succeeded yet marked todo */
2185 todo_wine {
2186 if (!strcmp(winetest_platform, "wine")) dump++;
2187 ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
2190 done:
2191 if (dump) dump_sequence(expected_list, context, file, line);
2192 flush_sequence();
2195 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
2197 /******************************** MDI test **********************************/
2199 /* CreateWindow for MDI frame window, initially visible */
2200 static const struct message WmCreateMDIframeSeq[] = {
2201 { HCBT_CREATEWND, hook },
2202 { WM_GETMINMAXINFO, sent },
2203 { WM_NCCREATE, sent },
2204 { WM_NCCALCSIZE, sent|wparam, 0 },
2205 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2206 { WM_CREATE, sent },
2207 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2208 { WM_NOTIFYFORMAT, sent|optional },
2209 { WM_QUERYUISTATE, sent|optional },
2210 { WM_WINDOWPOSCHANGING, sent|optional },
2211 { WM_GETMINMAXINFO, sent|optional },
2212 { WM_NCCALCSIZE, sent|optional },
2213 { WM_WINDOWPOSCHANGED, sent|optional },
2214 { WM_SHOWWINDOW, sent|wparam, 1 },
2215 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2216 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2217 { HCBT_ACTIVATE, hook },
2218 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
2219 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
2220 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
2221 { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
2222 { WM_NCACTIVATE, sent },
2223 { WM_GETTEXT, sent|defwinproc|optional },
2224 { WM_ACTIVATE, sent|wparam, 1 },
2225 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
2226 { HCBT_SETFOCUS, hook },
2227 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2228 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2229 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2230 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
2231 /* Win9x adds SWP_NOZORDER below */
2232 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2233 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2234 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2235 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2236 { WM_MOVE, sent },
2237 { 0 }
2239 /* DestroyWindow for MDI frame window, initially visible */
2240 static const struct message WmDestroyMDIframeSeq[] = {
2241 { HCBT_DESTROYWND, hook },
2242 { 0x0090, sent|optional },
2243 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2244 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2245 { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2246 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2247 { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
2248 { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2249 { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
2250 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
2251 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2252 { WM_DESTROY, sent },
2253 { WM_NCDESTROY, sent },
2254 { 0 }
2256 /* CreateWindow for MDI client window, initially visible */
2257 static const struct message WmCreateMDIclientSeq[] = {
2258 { HCBT_CREATEWND, hook },
2259 { WM_NCCREATE, sent },
2260 { WM_NCCALCSIZE, sent|wparam, 0 },
2261 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2262 { WM_CREATE, sent },
2263 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2264 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2265 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2266 { WM_MOVE, sent },
2267 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
2268 { WM_SHOWWINDOW, sent|wparam, 1 },
2269 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2270 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2271 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2272 { 0 }
2274 /* ShowWindow(SW_SHOW) for MDI client window */
2275 static const struct message WmShowMDIclientSeq[] = {
2276 { WM_SHOWWINDOW, sent|wparam, 1 },
2277 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2278 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2279 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2280 { 0 }
2282 /* ShowWindow(SW_HIDE) for MDI client window */
2283 static const struct message WmHideMDIclientSeq[] = {
2284 { WM_SHOWWINDOW, sent|wparam, 0 },
2285 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2286 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
2287 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
2288 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2289 { 0 }
2291 /* DestroyWindow for MDI client window, initially visible */
2292 static const struct message WmDestroyMDIclientSeq[] = {
2293 { HCBT_DESTROYWND, hook },
2294 { 0x0090, sent|optional },
2295 { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
2296 { WM_SHOWWINDOW, sent|wparam, 0 },
2297 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2298 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2299 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2300 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2301 { WM_DESTROY, sent },
2302 { WM_NCDESTROY, sent },
2303 { 0 }
2305 /* CreateWindow for MDI child window, initially visible */
2306 static const struct message WmCreateMDIchildVisibleSeq[] = {
2307 { HCBT_CREATEWND, hook },
2308 { WM_NCCREATE, sent },
2309 { WM_NCCALCSIZE, sent|wparam, 0 },
2310 { WM_CREATE, sent },
2311 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2312 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2313 { WM_MOVE, sent },
2314 /* Win2k sends wparam set to
2315 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2316 * while Win9x doesn't bother to set child window id according to
2317 * CLIENTCREATESTRUCT.idFirstChild
2319 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2320 { WM_SHOWWINDOW, sent|wparam, 1 },
2321 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2322 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2323 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2324 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2325 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2326 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2327 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2329 /* Win9x: message sequence terminates here. */
2331 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2332 { HCBT_SETFOCUS, hook }, /* in MDI client */
2333 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2334 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2335 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2336 { WM_SETFOCUS, sent }, /* in MDI client */
2337 { HCBT_SETFOCUS, hook },
2338 { WM_KILLFOCUS, sent }, /* in MDI client */
2339 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2340 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2341 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2342 { WM_SETFOCUS, sent|defwinproc },
2343 { WM_MDIACTIVATE, sent|defwinproc },
2344 { 0 }
2346 /* CreateWindow for MDI child window with invisible parent */
2347 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
2348 { HCBT_CREATEWND, hook },
2349 { WM_GETMINMAXINFO, sent },
2350 { WM_NCCREATE, sent },
2351 { WM_NCCALCSIZE, sent|wparam, 0 },
2352 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2353 { WM_CREATE, sent },
2354 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2355 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2356 { WM_MOVE, sent },
2357 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2358 { WM_SHOWWINDOW, sent|wparam, 1 },
2359 { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2360 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2361 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2362 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2364 /* Win9x: message sequence terminates here. */
2366 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2367 { HCBT_SETFOCUS, hook }, /* in MDI client */
2368 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2369 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2370 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2371 { WM_SETFOCUS, sent }, /* in MDI client */
2372 { HCBT_SETFOCUS, hook },
2373 { WM_KILLFOCUS, sent }, /* in MDI client */
2374 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2375 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2376 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2377 { WM_SETFOCUS, sent|defwinproc },
2378 { WM_MDIACTIVATE, sent|defwinproc },
2379 { 0 }
2381 /* DestroyWindow for MDI child window, initially visible */
2382 static const struct message WmDestroyMDIchildVisibleSeq[] = {
2383 { HCBT_DESTROYWND, hook },
2384 /* Win2k sends wparam set to
2385 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2386 * while Win9x doesn't bother to set child window id according to
2387 * CLIENTCREATESTRUCT.idFirstChild
2389 { 0x0090, sent|optional },
2390 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2391 { WM_SHOWWINDOW, sent|wparam, 0 },
2392 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2393 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2394 { WM_ERASEBKGND, sent|parent|optional },
2395 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2397 /* { WM_DESTROY, sent }
2398 * Win9x: message sequence terminates here.
2401 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2402 { WM_KILLFOCUS, sent },
2403 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2404 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2405 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2406 { WM_SETFOCUS, sent }, /* in MDI client */
2408 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2409 { WM_KILLFOCUS, sent }, /* in MDI client */
2410 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2411 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2412 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2413 { WM_SETFOCUS, sent }, /* in MDI client */
2415 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2417 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2418 { WM_KILLFOCUS, sent },
2419 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2420 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2421 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2422 { WM_SETFOCUS, sent }, /* in MDI client */
2424 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2425 { WM_KILLFOCUS, sent }, /* in MDI client */
2426 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2427 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2428 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2429 { WM_SETFOCUS, sent }, /* in MDI client */
2431 { WM_DESTROY, sent },
2433 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2434 { WM_KILLFOCUS, sent },
2435 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2436 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2437 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2438 { WM_SETFOCUS, sent }, /* in MDI client */
2440 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2441 { WM_KILLFOCUS, sent }, /* in MDI client */
2442 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2443 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2444 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2445 { WM_SETFOCUS, sent }, /* in MDI client */
2447 { WM_NCDESTROY, sent },
2448 { 0 }
2450 /* CreateWindow for MDI child window, initially invisible */
2451 static const struct message WmCreateMDIchildInvisibleSeq[] = {
2452 { HCBT_CREATEWND, hook },
2453 { WM_NCCREATE, sent },
2454 { WM_NCCALCSIZE, sent|wparam, 0 },
2455 { WM_CREATE, sent },
2456 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2457 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2458 { WM_MOVE, sent },
2459 /* Win2k sends wparam set to
2460 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2461 * while Win9x doesn't bother to set child window id according to
2462 * CLIENTCREATESTRUCT.idFirstChild
2464 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2465 { 0 }
2467 /* DestroyWindow for MDI child window, initially invisible */
2468 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
2469 { HCBT_DESTROYWND, hook },
2470 /* Win2k sends wparam set to
2471 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2472 * while Win9x doesn't bother to set child window id according to
2473 * CLIENTCREATESTRUCT.idFirstChild
2475 { 0x0090, sent|optional },
2476 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2477 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2478 { WM_DESTROY, sent },
2479 { WM_NCDESTROY, sent },
2480 /* FIXME: Wine destroys an icon/title window while Windows doesn't */
2481 { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
2482 { 0 }
2484 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
2485 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
2486 { HCBT_CREATEWND, hook },
2487 { WM_NCCREATE, sent },
2488 { WM_NCCALCSIZE, sent|wparam, 0 },
2489 { WM_CREATE, sent },
2490 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2491 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2492 { WM_MOVE, sent },
2493 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2494 { WM_GETMINMAXINFO, sent },
2495 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2496 { WM_NCCALCSIZE, sent|wparam, 1 },
2497 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2498 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2499 /* in MDI frame */
2500 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2501 { WM_NCCALCSIZE, sent|wparam, 1 },
2502 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2503 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2504 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2505 /* Win2k sends wparam set to
2506 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2507 * while Win9x doesn't bother to set child window id according to
2508 * CLIENTCREATESTRUCT.idFirstChild
2510 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2511 { WM_SHOWWINDOW, sent|wparam, 1 },
2512 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2513 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2514 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2515 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2516 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2517 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2518 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_FRAMECHANGED },
2520 /* Win9x: message sequence terminates here. */
2522 { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2523 { HCBT_SETFOCUS, hook|optional }, /* in MDI client */
2524 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2525 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2526 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2527 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2528 { HCBT_SETFOCUS, hook|optional },
2529 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2530 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2531 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2532 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2533 { WM_SETFOCUS, sent|defwinproc|optional },
2534 { WM_MDIACTIVATE, sent|defwinproc|optional },
2535 /* in MDI frame */
2536 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2537 { WM_NCCALCSIZE, sent|wparam, 1 },
2538 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2539 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2540 { 0 }
2542 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2543 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2544 /* restore the 1st MDI child */
2545 { WM_SETREDRAW, sent|wparam, 0 },
2546 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2547 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2548 { WM_NCCALCSIZE, sent|wparam, 1 },
2549 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2550 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2551 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2552 /* in MDI frame */
2553 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2554 { WM_NCCALCSIZE, sent|wparam, 1 },
2555 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2556 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2557 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2558 { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2559 /* create the 2nd MDI child */
2560 { HCBT_CREATEWND, hook },
2561 { WM_NCCREATE, sent },
2562 { WM_NCCALCSIZE, sent|wparam, 0 },
2563 { WM_CREATE, sent },
2564 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2565 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2566 { WM_MOVE, sent },
2567 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2568 { WM_GETMINMAXINFO, sent },
2569 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2570 { WM_NCCALCSIZE, sent|wparam, 1 },
2571 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2572 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2573 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2574 /* in MDI frame */
2575 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2576 { WM_NCCALCSIZE, sent|wparam, 1 },
2577 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2578 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2579 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2580 /* Win2k sends wparam set to
2581 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2582 * while Win9x doesn't bother to set child window id according to
2583 * CLIENTCREATESTRUCT.idFirstChild
2585 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2586 { WM_SHOWWINDOW, sent|wparam, 1 },
2587 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2588 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2589 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2590 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2591 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2592 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2594 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2595 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2597 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2599 /* Win9x: message sequence terminates here. */
2601 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2602 { HCBT_SETFOCUS, hook },
2603 { WM_KILLFOCUS, sent|defwinproc|optional }, /* in the 1st MDI child */
2604 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2605 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2606 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2607 { WM_SETFOCUS, sent }, /* in MDI client */
2608 { HCBT_SETFOCUS, hook },
2609 { WM_KILLFOCUS, sent }, /* in MDI client */
2610 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2611 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2612 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2613 { WM_SETFOCUS, sent|defwinproc },
2615 { WM_MDIACTIVATE, sent|defwinproc },
2616 /* in MDI frame */
2617 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2618 { WM_NCCALCSIZE, sent|wparam, 1 },
2619 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2620 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2621 { 0 }
2623 /* WM_MDICREATE MDI child window, initially visible and maximized */
2624 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2625 { WM_MDICREATE, sent },
2626 { HCBT_CREATEWND, hook },
2627 { WM_NCCREATE, sent },
2628 { WM_NCCALCSIZE, sent|wparam, 0 },
2629 { WM_CREATE, sent },
2630 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2631 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2632 { WM_MOVE, sent },
2633 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2634 { WM_GETMINMAXINFO, sent },
2635 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2636 { WM_NCCALCSIZE, sent|wparam, 1 },
2637 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2638 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2640 /* in MDI frame */
2641 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2642 { WM_NCCALCSIZE, sent|wparam, 1 },
2643 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2644 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2645 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2647 /* Win2k sends wparam set to
2648 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2649 * while Win9x doesn't bother to set child window id according to
2650 * CLIENTCREATESTRUCT.idFirstChild
2652 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2653 { WM_SHOWWINDOW, sent|wparam, 1 },
2654 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2656 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2658 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2659 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2660 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2662 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2663 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2665 /* Win9x: message sequence terminates here. */
2667 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2668 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2669 { HCBT_SETFOCUS, hook }, /* in MDI client */
2670 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2671 { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2672 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2673 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2674 { HCBT_SETFOCUS, hook|optional },
2675 { WM_KILLFOCUS, sent }, /* in MDI client */
2676 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2677 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2678 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2679 { WM_SETFOCUS, sent|defwinproc },
2681 { WM_MDIACTIVATE, sent|defwinproc },
2683 /* in MDI child */
2684 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2685 { WM_NCCALCSIZE, sent|wparam, 1 },
2686 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2687 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2689 /* in MDI frame */
2690 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2691 { WM_NCCALCSIZE, sent|wparam, 1 },
2692 { 0x0093, sent|defwinproc|optional },
2693 { 0x0093, sent|defwinproc|optional },
2694 { 0x0093, sent|defwinproc|optional },
2695 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2696 { WM_MOVE, sent|defwinproc },
2697 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2699 /* in MDI client */
2700 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2701 { WM_NCCALCSIZE, sent|wparam, 1 },
2702 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2703 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2705 /* in MDI child */
2706 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2707 { WM_NCCALCSIZE, sent|wparam, 1 },
2708 { 0x0093, sent|optional },
2709 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2710 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2712 { 0x0093, sent|optional },
2713 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2714 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2715 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2716 { 0x0093, sent|defwinproc|optional },
2717 { 0x0093, sent|defwinproc|optional },
2718 { 0x0093, sent|defwinproc|optional },
2719 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2720 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2722 { 0 }
2724 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2725 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2726 { HCBT_CREATEWND, hook },
2727 { WM_GETMINMAXINFO, sent },
2728 { WM_NCCREATE, sent },
2729 { WM_NCCALCSIZE, sent|wparam, 0 },
2730 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2731 { WM_CREATE, sent },
2732 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2733 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2734 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2735 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI frame */
2736 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2737 { WM_MOVE, sent },
2738 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2739 { WM_GETMINMAXINFO, sent },
2740 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2741 { WM_GETMINMAXINFO, sent|defwinproc },
2742 { WM_NCCALCSIZE, sent|wparam, 1 },
2743 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_STATECHANGED },
2744 { WM_MOVE, sent|defwinproc },
2745 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2746 /* in MDI frame */
2747 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2748 { WM_NCCALCSIZE, sent|wparam, 1 },
2749 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2750 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2751 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2752 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2753 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2754 /* Win2k sends wparam set to
2755 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2756 * while Win9x doesn't bother to set child window id according to
2757 * CLIENTCREATESTRUCT.idFirstChild
2759 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2760 { 0 }
2762 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2763 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2764 { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2765 { HCBT_SYSCOMMAND, hook },
2766 { WM_CLOSE, sent|defwinproc },
2767 { WM_MDIDESTROY, sent }, /* in MDI client */
2769 /* bring the 1st MDI child to top */
2770 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2771 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2773 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2775 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2776 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2777 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2779 /* maximize the 1st MDI child */
2780 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2781 { WM_GETMINMAXINFO, sent|defwinproc },
2782 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED },
2783 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2784 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2785 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2786 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2788 /* restore the 2nd MDI child */
2789 { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2790 { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2791 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2792 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2794 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2796 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2797 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2799 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2801 { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2802 /* in MDI frame */
2803 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2804 { WM_NCCALCSIZE, sent|wparam, 1 },
2805 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2806 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2807 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2809 /* bring the 1st MDI child to top */
2810 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2811 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2812 { HCBT_SETFOCUS, hook },
2813 { WM_KILLFOCUS, sent|defwinproc },
2814 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2815 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2816 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2817 { WM_SETFOCUS, sent }, /* in MDI client */
2818 { HCBT_SETFOCUS, hook },
2819 { WM_KILLFOCUS, sent }, /* in MDI client */
2820 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2821 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2822 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2823 { WM_SETFOCUS, sent|defwinproc },
2824 { WM_MDIACTIVATE, sent|defwinproc },
2825 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2827 /* apparently ShowWindow(SW_SHOW) on an MDI client */
2828 { WM_SHOWWINDOW, sent|wparam, 1 },
2829 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2830 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2831 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2832 { WM_MDIREFRESHMENU, sent },
2834 { HCBT_DESTROYWND, hook },
2835 /* Win2k sends wparam set to
2836 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2837 * while Win9x doesn't bother to set child window id according to
2838 * CLIENTCREATESTRUCT.idFirstChild
2840 { 0x0090, sent|defwinproc|optional },
2841 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2842 { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2843 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2844 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2845 { WM_ERASEBKGND, sent|parent|optional },
2846 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2848 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2849 { WM_DESTROY, sent|defwinproc },
2850 { WM_NCDESTROY, sent|defwinproc },
2851 { 0 }
2853 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2854 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2855 { WM_MDIDESTROY, sent }, /* in MDI client */
2856 { WM_SHOWWINDOW, sent|wparam, 0 },
2857 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2858 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2859 { WM_ERASEBKGND, sent|parent|optional },
2860 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2862 { HCBT_SETFOCUS, hook },
2863 { WM_KILLFOCUS, sent },
2864 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2865 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2866 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2867 { WM_SETFOCUS, sent }, /* in MDI client */
2868 { HCBT_SETFOCUS, hook },
2869 { WM_KILLFOCUS, sent }, /* in MDI client */
2870 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2871 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2872 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2873 { WM_SETFOCUS, sent },
2875 /* in MDI child */
2876 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2877 { WM_NCCALCSIZE, sent|wparam, 1 },
2878 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2879 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2881 /* in MDI frame */
2882 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2883 { WM_NCCALCSIZE, sent|wparam, 1 },
2884 { 0x0093, sent|defwinproc|optional },
2885 { 0x0093, sent|defwinproc|optional },
2886 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2887 { WM_MOVE, sent|defwinproc },
2888 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2890 /* in MDI client */
2891 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2892 { WM_NCCALCSIZE, sent|wparam, 1 },
2893 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2894 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2896 /* in MDI child */
2897 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2898 { WM_NCCALCSIZE, sent|wparam, 1 },
2899 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2900 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2902 /* in MDI child */
2903 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2904 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2905 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2906 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2908 /* in MDI frame */
2909 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2910 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2911 { 0x0093, sent|defwinproc|optional },
2912 { 0x0093, sent|defwinproc|optional },
2913 { 0x0093, sent|defwinproc|optional },
2914 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2915 { WM_MOVE, sent|defwinproc },
2916 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2918 /* in MDI client */
2919 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2920 { WM_NCCALCSIZE, sent|wparam, 1 },
2921 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2922 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2924 /* in MDI child */
2925 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2926 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2927 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2928 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2929 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2930 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2932 { 0x0093, sent|defwinproc|optional },
2933 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2934 { 0x0093, sent|defwinproc|optional },
2935 { 0x0093, sent|defwinproc|optional },
2936 { 0x0093, sent|defwinproc|optional },
2937 { 0x0093, sent|optional },
2939 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2940 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2941 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2942 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2943 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2945 /* in MDI frame */
2946 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2947 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2948 { 0x0093, sent|defwinproc|optional },
2949 { 0x0093, sent|defwinproc|optional },
2950 { 0x0093, sent|defwinproc|optional },
2951 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2952 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2953 { 0x0093, sent|optional },
2955 { WM_NCACTIVATE, sent|wparam, 0 },
2956 { WM_MDIACTIVATE, sent },
2958 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2959 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2960 { WM_NCCALCSIZE, sent|wparam, 1 },
2962 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2964 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2965 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2966 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2968 /* in MDI child */
2969 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2970 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2971 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2972 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2974 /* in MDI frame */
2975 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2976 { WM_NCCALCSIZE, sent|wparam, 1 },
2977 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2978 { WM_MOVE, sent|defwinproc },
2979 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2981 /* in MDI client */
2982 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2983 { WM_NCCALCSIZE, sent|wparam, 1 },
2984 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2985 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2986 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2987 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2988 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2989 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2990 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2992 { HCBT_SETFOCUS, hook },
2993 { WM_KILLFOCUS, sent },
2994 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2995 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2996 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2997 { WM_SETFOCUS, sent }, /* in MDI client */
2999 { WM_MDIREFRESHMENU, sent }, /* in MDI client */
3001 { HCBT_DESTROYWND, hook },
3002 /* Win2k sends wparam set to
3003 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
3004 * while Win9x doesn't bother to set child window id according to
3005 * CLIENTCREATESTRUCT.idFirstChild
3007 { 0x0090, sent|optional },
3008 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
3010 { WM_SHOWWINDOW, sent|wparam, 0 },
3011 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3012 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
3013 { WM_ERASEBKGND, sent|parent|optional },
3014 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3016 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
3017 { WM_DESTROY, sent },
3018 { WM_NCDESTROY, sent },
3019 { 0 }
3021 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
3022 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
3023 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3024 { WM_GETMINMAXINFO, sent },
3025 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
3026 { WM_NCCALCSIZE, sent|wparam, 1 },
3027 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3028 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3030 { WM_WINDOWPOSCHANGING, sent|wparam|optional|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3031 { WM_NCACTIVATE, sent|wparam|optional|defwinproc, 1 },
3032 { HCBT_SETFOCUS, hook|optional },
3033 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3034 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3035 { WM_SETFOCUS, sent|optional }, /* in MDI client */
3036 { HCBT_SETFOCUS, hook|optional },
3037 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3038 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3039 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3040 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3041 { WM_SETFOCUS, sent|optional|defwinproc },
3042 { WM_MDIACTIVATE, sent|optional|defwinproc },
3043 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3044 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3045 /* in MDI frame */
3046 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3047 { WM_NCCALCSIZE, sent|wparam, 1 },
3048 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3049 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3050 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3051 { 0 }
3053 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
3054 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
3055 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3056 { WM_GETMINMAXINFO, sent },
3057 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
3058 { WM_GETMINMAXINFO, sent|defwinproc },
3059 { WM_NCCALCSIZE, sent|wparam, 1 },
3060 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3061 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3063 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3064 { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
3065 { HCBT_SETFOCUS, hook|optional },
3066 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3067 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3068 { WM_SETFOCUS, sent|optional }, /* in MDI client */
3069 { HCBT_SETFOCUS, hook|optional },
3070 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3071 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3072 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3073 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3074 { WM_SETFOCUS, sent|defwinproc|optional },
3075 { WM_MDIACTIVATE, sent|defwinproc|optional },
3076 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3077 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3078 { 0 }
3080 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
3081 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
3082 { WM_MDIMAXIMIZE, sent }, /* in MDI client */
3083 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3084 { WM_GETMINMAXINFO, sent },
3085 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3086 { WM_GETMINMAXINFO, sent|defwinproc },
3087 { WM_NCCALCSIZE, sent|wparam, 1 },
3088 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
3089 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3090 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
3091 { WM_MOVE, sent|defwinproc },
3092 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3094 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3095 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3096 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3097 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3098 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3099 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3100 /* in MDI frame */
3101 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3102 { WM_NCCALCSIZE, sent|wparam, 1 },
3103 { 0x0093, sent|defwinproc|optional },
3104 { 0x0094, sent|defwinproc|optional },
3105 { 0x0094, sent|defwinproc|optional },
3106 { 0x0094, sent|defwinproc|optional },
3107 { 0x0094, sent|defwinproc|optional },
3108 { 0x0093, sent|defwinproc|optional },
3109 { 0x0093, sent|defwinproc|optional },
3110 { 0x0091, sent|defwinproc|optional },
3111 { 0x0092, sent|defwinproc|optional },
3112 { 0x0092, sent|defwinproc|optional },
3113 { 0x0092, sent|defwinproc|optional },
3114 { 0x0092, sent|defwinproc|optional },
3115 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3116 { WM_MOVE, sent|defwinproc },
3117 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3118 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
3119 /* in MDI client */
3120 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
3121 { WM_NCCALCSIZE, sent|wparam, 1 },
3122 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3123 { WM_SIZE, sent|wparam, SIZE_RESTORED },
3124 /* in MDI child */
3125 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
3126 { WM_GETMINMAXINFO, sent|defwinproc },
3127 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3128 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3129 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3130 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
3131 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3132 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3133 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3134 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3135 /* in MDI frame */
3136 { 0x0093, sent|optional },
3137 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
3138 { 0x0093, sent|defwinproc|optional },
3139 { 0x0093, sent|defwinproc|optional },
3140 { 0x0093, sent|defwinproc|optional },
3141 { 0x0091, sent|defwinproc|optional },
3142 { 0x0092, sent|defwinproc|optional },
3143 { 0x0092, sent|defwinproc|optional },
3144 { 0x0092, sent|defwinproc|optional },
3145 { 0x0092, sent|defwinproc|optional },
3146 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3147 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3148 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3149 { 0 }
3151 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
3152 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
3153 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3154 { WM_GETMINMAXINFO, sent },
3155 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3156 { WM_NCCALCSIZE, sent|wparam, 1 },
3157 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3158 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3159 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3160 /* in MDI frame */
3161 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3162 { WM_NCCALCSIZE, sent|wparam, 1 },
3163 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3164 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3165 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3166 { 0 }
3168 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
3169 static const struct message WmRestoreMDIchildVisibleSeq[] = {
3170 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3171 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3172 { WM_NCCALCSIZE, sent|wparam, 1 },
3173 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3174 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3175 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3176 /* in MDI frame */
3177 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3178 { WM_NCCALCSIZE, sent|wparam, 1 },
3179 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3180 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3181 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3182 { 0 }
3184 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
3185 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
3186 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3187 { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
3188 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3189 { WM_NCCALCSIZE, sent|wparam, 1 },
3190 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3191 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3192 { WM_MOVE, sent|defwinproc },
3193 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3194 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3195 { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3196 { HCBT_SETFOCUS, hook },
3197 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3198 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
3199 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3200 { WM_SETFOCUS, sent },
3201 { 0 }
3203 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
3204 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
3205 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
3206 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3207 { WM_NCCALCSIZE, sent|wparam, 1 },
3208 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3209 { WM_MOVE, sent|defwinproc },
3210 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
3211 { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
3212 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3213 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3214 /* FIXME: Wine creates an icon/title window while Windows doesn't */
3215 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
3216 { 0 }
3218 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
3219 static const struct message WmRestoreMDIchildInisibleSeq[] = {
3220 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3221 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
3222 { WM_NCCALCSIZE, sent|wparam, 1 },
3223 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3224 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3225 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3226 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3227 /* in MDI frame */
3228 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3229 { WM_NCCALCSIZE, sent|wparam, 1 },
3230 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3231 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3232 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3233 { 0 }
3236 static HWND mdi_client;
3237 static WNDPROC old_mdi_client_proc;
3239 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3241 struct recvd_message msg;
3243 /* do not log painting messages */
3244 if (message != WM_PAINT &&
3245 message != WM_NCPAINT &&
3246 message != WM_SYNCPAINT &&
3247 message != WM_ERASEBKGND &&
3248 message != WM_NCHITTEST &&
3249 message != WM_GETTEXT &&
3250 message != WM_MDIGETACTIVE &&
3251 !ignore_message( message ))
3253 msg.hwnd = hwnd;
3254 msg.message = message;
3255 msg.flags = sent|wparam|lparam;
3256 msg.wParam = wParam;
3257 msg.lParam = lParam;
3258 msg.descr = "mdi client";
3259 add_message(&msg);
3262 return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
3265 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3267 static LONG defwndproc_counter = 0;
3268 LRESULT ret;
3269 struct recvd_message msg;
3271 /* do not log painting messages */
3272 if (message != WM_PAINT &&
3273 message != WM_NCPAINT &&
3274 message != WM_SYNCPAINT &&
3275 message != WM_ERASEBKGND &&
3276 message != WM_NCHITTEST &&
3277 message != WM_GETTEXT &&
3278 !ignore_message( message ))
3280 switch (message)
3282 case WM_MDIACTIVATE:
3284 HWND active, client = GetParent(hwnd);
3286 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
3288 if (hwnd == (HWND)lParam) /* if we are being activated */
3289 ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
3290 else
3291 ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
3292 break;
3296 msg.hwnd = hwnd;
3297 msg.message = message;
3298 msg.flags = sent|wparam|lparam;
3299 if (defwndproc_counter) msg.flags |= defwinproc;
3300 msg.wParam = wParam;
3301 msg.lParam = lParam;
3302 msg.descr = "mdi child";
3303 add_message(&msg);
3306 defwndproc_counter++;
3307 ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
3308 defwndproc_counter--;
3310 return ret;
3313 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3315 static LONG defwndproc_counter = 0;
3316 LRESULT ret;
3317 struct recvd_message msg;
3319 /* do not log painting messages */
3320 if (message != WM_PAINT &&
3321 message != WM_NCPAINT &&
3322 message != WM_SYNCPAINT &&
3323 message != WM_ERASEBKGND &&
3324 message != WM_NCHITTEST &&
3325 message != WM_GETTEXT &&
3326 !ignore_message( message ))
3328 msg.hwnd = hwnd;
3329 msg.message = message;
3330 msg.flags = sent|wparam|lparam;
3331 if (defwndproc_counter) msg.flags |= defwinproc;
3332 msg.wParam = wParam;
3333 msg.lParam = lParam;
3334 msg.descr = "mdi frame";
3335 add_message(&msg);
3338 defwndproc_counter++;
3339 ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
3340 defwndproc_counter--;
3342 return ret;
3345 static BOOL mdi_RegisterWindowClasses(void)
3347 WNDCLASSA cls;
3349 cls.style = 0;
3350 cls.lpfnWndProc = mdi_frame_wnd_proc;
3351 cls.cbClsExtra = 0;
3352 cls.cbWndExtra = 0;
3353 cls.hInstance = GetModuleHandleA(0);
3354 cls.hIcon = 0;
3355 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3356 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3357 cls.lpszMenuName = NULL;
3358 cls.lpszClassName = "MDI_frame_class";
3359 if (!RegisterClassA(&cls)) return FALSE;
3361 cls.lpfnWndProc = mdi_child_wnd_proc;
3362 cls.lpszClassName = "MDI_child_class";
3363 if (!RegisterClassA(&cls)) return FALSE;
3365 if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
3366 old_mdi_client_proc = cls.lpfnWndProc;
3367 cls.hInstance = GetModuleHandleA(0);
3368 cls.lpfnWndProc = mdi_client_hook_proc;
3369 cls.lpszClassName = "MDI_client_class";
3370 if (!RegisterClassA(&cls)) assert(0);
3372 return TRUE;
3375 static void test_mdi_messages(void)
3377 MDICREATESTRUCTA mdi_cs;
3378 CLIENTCREATESTRUCT client_cs;
3379 HWND mdi_frame, mdi_child, mdi_child2, active_child;
3380 BOOL zoomed;
3381 RECT rc;
3382 HMENU hMenu = CreateMenu();
3384 if (!mdi_RegisterWindowClasses()) assert(0);
3386 flush_sequence();
3388 trace("creating MDI frame window\n");
3389 mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
3390 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3391 WS_MAXIMIZEBOX | WS_VISIBLE,
3392 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
3393 GetDesktopWindow(), hMenu,
3394 GetModuleHandleA(0), NULL);
3395 assert(mdi_frame);
3396 ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
3398 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3399 ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
3401 trace("creating MDI client window\n");
3402 GetClientRect(mdi_frame, &rc);
3403 client_cs.hWindowMenu = 0;
3404 client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
3405 mdi_client = CreateWindowExA(0, "MDI_client_class",
3406 NULL,
3407 WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
3408 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
3409 mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3410 assert(mdi_client);
3411 ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
3413 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3414 ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
3416 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3417 ok(!active_child, "wrong active MDI child %p\n", active_child);
3418 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3420 SetFocus(0);
3421 flush_sequence();
3423 trace("creating invisible MDI child window\n");
3424 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3425 WS_CHILD,
3426 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3427 mdi_client, 0, GetModuleHandleA(0), NULL);
3428 assert(mdi_child);
3430 flush_sequence();
3431 ShowWindow(mdi_child, SW_SHOWNORMAL);
3432 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
3434 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3435 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3437 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3438 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3440 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3441 ok(!active_child, "wrong active MDI child %p\n", active_child);
3442 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3444 ShowWindow(mdi_child, SW_HIDE);
3445 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
3446 flush_sequence();
3448 ShowWindow(mdi_child, SW_SHOW);
3449 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
3451 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3452 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3454 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3455 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3457 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3458 ok(!active_child, "wrong active MDI child %p\n", active_child);
3459 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3461 DestroyWindow(mdi_child);
3462 flush_sequence();
3464 trace("creating visible MDI child window\n");
3465 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3466 WS_CHILD | WS_VISIBLE,
3467 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3468 mdi_client, 0, GetModuleHandleA(0), NULL);
3469 assert(mdi_child);
3470 ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
3472 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3473 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3475 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3476 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3478 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3479 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3480 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3481 flush_sequence();
3483 DestroyWindow(mdi_child);
3484 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3486 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3487 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3489 /* Win2k: MDI client still returns a just destroyed child as active
3490 * Win9x: MDI client returns 0
3492 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3493 ok(active_child == mdi_child || /* win2k */
3494 !active_child, /* win9x */
3495 "wrong active MDI child %p\n", active_child);
3496 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3498 flush_sequence();
3500 trace("creating invisible MDI child window\n");
3501 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3502 WS_CHILD,
3503 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3504 mdi_client, 0, GetModuleHandleA(0), NULL);
3505 assert(mdi_child2);
3506 ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
3508 ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
3509 ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
3511 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3512 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3514 /* Win2k: MDI client still returns a just destroyed child as active
3515 * Win9x: MDI client returns mdi_child2
3517 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3518 ok(active_child == mdi_child || /* win2k */
3519 active_child == mdi_child2, /* win9x */
3520 "wrong active MDI child %p\n", active_child);
3521 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3522 flush_sequence();
3524 ShowWindow(mdi_child2, SW_MAXIMIZE);
3525 ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3527 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3528 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3530 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3531 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3532 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3533 flush_sequence();
3535 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3536 ok(GetFocus() == mdi_child2 || /* win2k */
3537 GetFocus() == 0, /* win9x */
3538 "wrong focus window %p\n", GetFocus());
3540 SetFocus(0);
3541 flush_sequence();
3543 ShowWindow(mdi_child2, SW_HIDE);
3544 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3546 ShowWindow(mdi_child2, SW_RESTORE);
3547 ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3548 flush_sequence();
3550 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3551 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3553 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3554 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3555 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3556 flush_sequence();
3558 SetFocus(0);
3559 flush_sequence();
3561 ShowWindow(mdi_child2, SW_HIDE);
3562 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3564 ShowWindow(mdi_child2, SW_SHOW);
3565 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3567 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3568 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3570 ShowWindow(mdi_child2, SW_MAXIMIZE);
3571 ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3573 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3574 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3576 ShowWindow(mdi_child2, SW_RESTORE);
3577 ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3579 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3580 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3582 ShowWindow(mdi_child2, SW_MINIMIZE);
3583 ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3585 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3586 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3588 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3589 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3590 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3591 flush_sequence();
3593 ShowWindow(mdi_child2, SW_RESTORE);
3594 ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", FALSE);
3596 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3597 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3599 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3600 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3601 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3602 flush_sequence();
3604 SetFocus(0);
3605 flush_sequence();
3607 ShowWindow(mdi_child2, SW_HIDE);
3608 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3610 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3611 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3613 DestroyWindow(mdi_child2);
3614 ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3616 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3617 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3619 /* test for maximized MDI children */
3620 trace("creating maximized visible MDI child window 1\n");
3621 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3622 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3623 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3624 mdi_client, 0, GetModuleHandleA(0), NULL);
3625 assert(mdi_child);
3626 ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3627 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3629 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3630 ok(GetFocus() == mdi_child || /* win2k */
3631 GetFocus() == 0, /* win9x */
3632 "wrong focus window %p\n", GetFocus());
3634 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3635 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3636 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3637 flush_sequence();
3639 trace("creating maximized visible MDI child window 2\n");
3640 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3641 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3642 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3643 mdi_client, 0, GetModuleHandleA(0), NULL);
3644 assert(mdi_child2);
3645 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3646 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3647 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3649 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3650 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3652 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3653 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3654 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3655 flush_sequence();
3657 trace("destroying maximized visible MDI child window 2\n");
3658 DestroyWindow(mdi_child2);
3659 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3661 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3663 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3664 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3666 /* Win2k: MDI client still returns a just destroyed child as active
3667 * Win9x: MDI client returns 0
3669 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3670 ok(active_child == mdi_child2 || /* win2k */
3671 !active_child, /* win9x */
3672 "wrong active MDI child %p\n", active_child);
3673 flush_sequence();
3675 ShowWindow(mdi_child, SW_MAXIMIZE);
3676 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3677 flush_sequence();
3679 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3680 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3682 trace("re-creating maximized visible MDI child window 2\n");
3683 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3684 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3685 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3686 mdi_client, 0, GetModuleHandleA(0), NULL);
3687 assert(mdi_child2);
3688 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3689 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3690 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3692 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3693 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3695 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3696 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3697 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3698 flush_sequence();
3700 SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3701 ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3702 ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3704 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3705 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3706 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3708 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3709 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3710 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3711 flush_sequence();
3713 DestroyWindow(mdi_child);
3714 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3716 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3717 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3719 /* Win2k: MDI client still returns a just destroyed child as active
3720 * Win9x: MDI client returns 0
3722 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3723 ok(active_child == mdi_child || /* win2k */
3724 !active_child, /* win9x */
3725 "wrong active MDI child %p\n", active_child);
3726 flush_sequence();
3728 trace("creating maximized invisible MDI child window\n");
3729 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3730 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3731 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3732 mdi_client, 0, GetModuleHandleA(0), NULL);
3733 assert(mdi_child2);
3734 ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", FALSE);
3735 ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3736 ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3737 ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3739 /* Win2k: MDI client still returns a just destroyed child as active
3740 * Win9x: MDI client returns 0
3742 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3743 ok(active_child == mdi_child || /* win2k */
3744 !active_child || active_child == mdi_child2, /* win9x */
3745 "wrong active MDI child %p\n", active_child);
3746 flush_sequence();
3748 trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3749 ShowWindow(mdi_child2, SW_MAXIMIZE);
3750 ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3751 ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3752 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3753 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3755 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3756 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3757 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3758 flush_sequence();
3760 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3761 flush_sequence();
3763 /* end of test for maximized MDI children */
3764 SetFocus(0);
3765 flush_sequence();
3766 trace("creating maximized visible MDI child window 1(Switch test)\n");
3767 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3768 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3769 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3770 mdi_client, 0, GetModuleHandleA(0), NULL);
3771 assert(mdi_child);
3772 ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3773 ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3775 ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3776 ok(GetFocus() == mdi_child || /* win2k */
3777 GetFocus() == 0, /* win9x */
3778 "wrong focus window %p(Switch test)\n", GetFocus());
3780 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3781 ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3782 ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3783 flush_sequence();
3785 trace("creating maximized visible MDI child window 2(Switch test)\n");
3786 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3787 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3788 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3789 mdi_client, 0, GetModuleHandleA(0), NULL);
3790 assert(mdi_child2);
3791 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3793 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3794 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3796 ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3797 ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3799 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3800 ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3801 ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3802 flush_sequence();
3804 trace("Switch child window.\n");
3805 SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3806 ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3807 trace("end of test for switch maximized MDI children\n");
3808 flush_sequence();
3810 /* Prepare for switching test of not maximized MDI children */
3811 ShowWindow( mdi_child, SW_NORMAL );
3812 ok(!IsZoomed(mdi_child), "wrong zoomed state for %p(Switch test)\n", mdi_child);
3813 ok(!IsZoomed(mdi_child2), "wrong zoomed state for %p(Switch test)\n", mdi_child2);
3814 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
3815 ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3816 flush_sequence();
3818 SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child2, 0);
3819 ok_sequence(WmSwitchNotMaximizedChild, "Not maximized child did not switch correctly", FALSE);
3820 trace("end of test for switch not maximized MDI children\n");
3821 flush_sequence();
3823 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3824 flush_sequence();
3826 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3827 flush_sequence();
3829 SetFocus(0);
3830 flush_sequence();
3831 /* end of tests for switch maximized/not maximized MDI children */
3833 mdi_cs.szClass = "MDI_child_Class";
3834 mdi_cs.szTitle = "MDI child";
3835 mdi_cs.hOwner = GetModuleHandleA(0);
3836 mdi_cs.x = 0;
3837 mdi_cs.y = 0;
3838 mdi_cs.cx = CW_USEDEFAULT;
3839 mdi_cs.cy = CW_USEDEFAULT;
3840 mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3841 mdi_cs.lParam = 0;
3842 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3843 ok(mdi_child != 0, "MDI child creation failed\n");
3844 ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3846 ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3848 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3849 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3851 ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3852 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3853 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3855 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3856 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3857 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3858 flush_sequence();
3860 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3861 ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3863 ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3864 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3865 ok(!active_child, "wrong active MDI child %p\n", active_child);
3867 SetFocus(0);
3868 flush_sequence();
3870 DestroyWindow(mdi_client);
3871 ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3873 /* test maximization of MDI child with invisible parent */
3874 client_cs.hWindowMenu = 0;
3875 mdi_client = CreateWindow("MDI_client_class",
3876 NULL,
3877 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3878 0, 0, 660, 430,
3879 mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3880 ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3882 ShowWindow(mdi_client, SW_HIDE);
3883 ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3885 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3886 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3887 0, 0, 650, 440,
3888 mdi_client, 0, GetModuleHandleA(0), NULL);
3889 ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3891 SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3892 ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3893 zoomed = IsZoomed(mdi_child);
3894 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3896 ShowWindow(mdi_client, SW_SHOW);
3897 ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3899 DestroyWindow(mdi_child);
3900 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3902 /* end of test for maximization of MDI child with invisible parent */
3904 DestroyWindow(mdi_client);
3905 ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3907 DestroyWindow(mdi_frame);
3908 ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3910 /************************* End of MDI test **********************************/
3912 static void test_WM_SETREDRAW(HWND hwnd)
3914 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3916 flush_events();
3917 flush_sequence();
3919 SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3920 ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3922 ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3923 ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3925 flush_sequence();
3926 SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3927 ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3929 ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3930 ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3932 /* restore original WS_VISIBLE state */
3933 SetWindowLongA(hwnd, GWL_STYLE, style);
3935 flush_events();
3936 flush_sequence();
3939 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3941 struct recvd_message msg;
3943 if (ignore_message( message )) return 0;
3945 switch (message)
3947 /* ignore */
3948 case WM_MOUSEMOVE:
3949 case WM_NCMOUSEMOVE:
3950 case WM_NCMOUSELEAVE:
3951 case WM_SETCURSOR:
3952 return 0;
3953 case WM_NCHITTEST:
3954 return HTCLIENT;
3957 msg.hwnd = hwnd;
3958 msg.message = message;
3959 msg.flags = sent|wparam|lparam;
3960 msg.wParam = wParam;
3961 msg.lParam = lParam;
3962 msg.descr = "dialog";
3963 add_message(&msg);
3965 if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3966 if (message == WM_TIMER) EndDialog( hwnd, 0 );
3967 return 0;
3970 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3972 DWORD style, exstyle;
3973 INT xmin, xmax;
3974 BOOL ret;
3976 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3977 style = GetWindowLongA(hwnd, GWL_STYLE);
3978 /* do not be confused by WS_DLGFRAME set */
3979 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3981 if (clear) ok(style & clear, "style %08x should be set\n", clear);
3982 if (set) ok(!(style & set), "style %08x should not be set\n", set);
3984 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3985 ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3986 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3987 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3988 else
3989 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3991 style = GetWindowLongA(hwnd, GWL_STYLE);
3992 if (set) ok(style & set, "style %08x should be set\n", set);
3993 if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3995 /* a subsequent call should do nothing */
3996 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3997 ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3998 ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
4000 xmin = 0xdeadbeef;
4001 xmax = 0xdeadbeef;
4002 ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
4003 ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
4004 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
4005 ok(xmin == min, "unexpected min scroll value %d\n", xmin);
4006 ok(xmax == max, "unexpected max scroll value %d\n", xmax);
4009 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
4011 DWORD style, exstyle;
4012 SCROLLINFO si;
4013 BOOL ret;
4015 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
4016 style = GetWindowLongA(hwnd, GWL_STYLE);
4017 /* do not be confused by WS_DLGFRAME set */
4018 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
4020 if (clear) ok(style & clear, "style %08x should be set\n", clear);
4021 if (set) ok(!(style & set), "style %08x should not be set\n", set);
4023 si.cbSize = sizeof(si);
4024 si.fMask = SIF_RANGE;
4025 si.nMin = min;
4026 si.nMax = max;
4027 SetScrollInfo(hwnd, ctl, &si, TRUE);
4028 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
4029 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
4030 else
4031 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
4033 style = GetWindowLongA(hwnd, GWL_STYLE);
4034 if (set) ok(style & set, "style %08x should be set\n", set);
4035 if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
4037 /* a subsequent call should do nothing */
4038 SetScrollInfo(hwnd, ctl, &si, TRUE);
4039 if (style & WS_HSCROLL)
4040 ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4041 else if (style & WS_VSCROLL)
4042 ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4043 else
4044 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4046 si.fMask = SIF_PAGE;
4047 si.nPage = 5;
4048 SetScrollInfo(hwnd, ctl, &si, FALSE);
4049 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4051 si.fMask = SIF_POS;
4052 si.nPos = max - 1;
4053 SetScrollInfo(hwnd, ctl, &si, FALSE);
4054 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4056 si.fMask = SIF_RANGE;
4057 si.nMin = 0xdeadbeef;
4058 si.nMax = 0xdeadbeef;
4059 ret = GetScrollInfo(hwnd, ctl, &si);
4060 ok( ret, "GetScrollInfo error %d\n", GetLastError());
4061 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
4062 ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
4063 ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
4066 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
4067 static void test_scroll_messages(HWND hwnd)
4069 SCROLLINFO si;
4070 INT min, max;
4071 BOOL ret;
4073 flush_events();
4074 flush_sequence();
4076 min = 0xdeadbeef;
4077 max = 0xdeadbeef;
4078 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4079 ok( ret, "GetScrollRange error %d\n", GetLastError());
4080 if (sequence->message != WmGetScrollRangeSeq[0].message)
4081 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4082 /* values of min and max are undefined */
4083 flush_sequence();
4085 ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
4086 ok( ret, "SetScrollRange error %d\n", GetLastError());
4087 if (sequence->message != WmSetScrollRangeSeq[0].message)
4088 trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4089 flush_sequence();
4091 min = 0xdeadbeef;
4092 max = 0xdeadbeef;
4093 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4094 ok( ret, "GetScrollRange error %d\n", GetLastError());
4095 if (sequence->message != WmGetScrollRangeSeq[0].message)
4096 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4097 /* values of min and max are undefined */
4098 flush_sequence();
4100 si.cbSize = sizeof(si);
4101 si.fMask = SIF_RANGE;
4102 si.nMin = 20;
4103 si.nMax = 160;
4104 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4105 if (sequence->message != WmSetScrollRangeSeq[0].message)
4106 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4107 flush_sequence();
4109 si.fMask = SIF_PAGE;
4110 si.nPage = 10;
4111 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4112 if (sequence->message != WmSetScrollRangeSeq[0].message)
4113 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4114 flush_sequence();
4116 si.fMask = SIF_POS;
4117 si.nPos = 20;
4118 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4119 if (sequence->message != WmSetScrollRangeSeq[0].message)
4120 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4121 flush_sequence();
4123 si.fMask = SIF_RANGE;
4124 si.nMin = 0xdeadbeef;
4125 si.nMax = 0xdeadbeef;
4126 ret = GetScrollInfo(hwnd, SB_CTL, &si);
4127 ok( ret, "GetScrollInfo error %d\n", GetLastError());
4128 if (sequence->message != WmGetScrollInfoSeq[0].message)
4129 trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4130 /* values of min and max are undefined */
4131 flush_sequence();
4133 /* set WS_HSCROLL */
4134 test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4135 /* clear WS_HSCROLL */
4136 test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4138 /* set WS_HSCROLL */
4139 test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4140 /* clear WS_HSCROLL */
4141 test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4143 /* set WS_VSCROLL */
4144 test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4145 /* clear WS_VSCROLL */
4146 test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4148 /* set WS_VSCROLL */
4149 test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4150 /* clear WS_VSCROLL */
4151 test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4154 static void test_showwindow(void)
4156 HWND hwnd, hchild;
4157 RECT rc;
4159 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4160 100, 100, 200, 200, 0, 0, 0, NULL);
4161 ok (hwnd != 0, "Failed to create overlapped window\n");
4162 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4163 0, 0, 10, 10, hwnd, 0, 0, NULL);
4164 ok (hchild != 0, "Failed to create child\n");
4165 flush_sequence();
4167 /* ShowWindow( SW_SHOWNA) for invisible top level window */
4168 trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
4169 ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4170 ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", FALSE);
4172 /* ShowWindow( SW_SHOWNA) for now visible top level window */
4173 trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
4174 ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4175 ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
4176 /* back to invisible */
4177 ShowWindow(hchild, SW_HIDE);
4178 ShowWindow(hwnd, SW_HIDE);
4179 flush_sequence();
4180 /* ShowWindow(SW_SHOWNA) with child and parent invisible */
4181 trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
4182 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4183 ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
4184 /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */
4185 ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
4186 flush_sequence();
4187 trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
4188 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4189 ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
4190 /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
4191 ShowWindow( hwnd, SW_SHOW);
4192 flush_sequence();
4193 trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
4194 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4195 ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
4197 /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
4198 ShowWindow( hchild, SW_HIDE);
4199 flush_sequence();
4200 trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
4201 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4202 ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
4204 SetCapture(hchild);
4205 ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
4206 DestroyWindow(hchild);
4207 ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
4209 DestroyWindow(hwnd);
4210 flush_sequence();
4212 /* Popup windows */
4213 /* Test 1:
4214 * 1. Create invisible maximized popup window.
4215 * 2. Move and resize it.
4216 * 3. Show it maximized.
4218 trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4219 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4220 100, 100, 200, 200, 0, 0, 0, NULL);
4221 ok (hwnd != 0, "Failed to create popup window\n");
4222 ok(IsZoomed(hwnd), "window should be maximized\n");
4223 ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4225 GetWindowRect(hwnd, &rc);
4226 ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4227 rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4228 "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
4229 rc.left, rc.top, rc.right, rc.bottom);
4230 /* Reset window's size & position */
4231 SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
4232 ok(IsZoomed(hwnd), "window should be maximized\n");
4233 flush_sequence();
4235 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4236 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4237 ok(IsZoomed(hwnd), "window should be maximized\n");
4238 ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
4240 GetWindowRect(hwnd, &rc);
4241 ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4242 rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4243 "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
4244 rc.left, rc.top, rc.right, rc.bottom);
4245 DestroyWindow(hwnd);
4246 flush_sequence();
4248 /* Test 2:
4249 * 1. Create invisible maximized popup window.
4250 * 2. Show it maximized.
4252 trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4253 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4254 100, 100, 200, 200, 0, 0, 0, NULL);
4255 ok (hwnd != 0, "Failed to create popup window\n");
4256 ok(IsZoomed(hwnd), "window should be maximized\n");
4257 ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4259 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4260 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4261 ok(IsZoomed(hwnd), "window should be maximized\n");
4262 ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
4263 DestroyWindow(hwnd);
4264 flush_sequence();
4266 /* Test 3:
4267 * 1. Create visible maximized popup window.
4269 trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
4270 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4271 100, 100, 200, 200, 0, 0, 0, NULL);
4272 ok (hwnd != 0, "Failed to create popup window\n");
4273 ok(IsZoomed(hwnd), "window should be maximized\n");
4274 ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4275 DestroyWindow(hwnd);
4276 flush_sequence();
4278 /* Test 4:
4279 * 1. Create visible popup window.
4280 * 2. Maximize it.
4282 trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
4283 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
4284 100, 100, 200, 200, 0, 0, 0, NULL);
4285 ok (hwnd != 0, "Failed to create popup window\n");
4286 ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
4287 ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
4289 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
4290 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4291 ok(IsZoomed(hwnd), "window should be maximized\n");
4292 ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
4293 DestroyWindow(hwnd);
4294 flush_sequence();
4297 static void test_sys_menu(void)
4299 HWND hwnd;
4300 HMENU hmenu;
4301 UINT state;
4303 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4304 100, 100, 200, 200, 0, 0, 0, NULL);
4305 ok (hwnd != 0, "Failed to create overlapped window\n");
4307 flush_sequence();
4309 /* test existing window without CS_NOCLOSE style */
4310 hmenu = GetSystemMenu(hwnd, FALSE);
4311 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4313 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4314 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4315 ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4317 EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
4318 ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4320 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4321 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4322 ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
4324 EnableMenuItem(hmenu, SC_CLOSE, 0);
4325 ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4327 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4328 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4329 ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4331 /* test whether removing WS_SYSMENU destroys a system menu */
4332 SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
4333 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4334 flush_sequence();
4335 hmenu = GetSystemMenu(hwnd, FALSE);
4336 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4338 DestroyWindow(hwnd);
4340 /* test new window with CS_NOCLOSE style */
4341 hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4342 100, 100, 200, 200, 0, 0, 0, NULL);
4343 ok (hwnd != 0, "Failed to create overlapped window\n");
4345 hmenu = GetSystemMenu(hwnd, FALSE);
4346 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4348 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4349 ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4351 DestroyWindow(hwnd);
4353 /* test new window without WS_SYSMENU style */
4354 hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
4355 100, 100, 200, 200, 0, 0, 0, NULL);
4356 ok(hwnd != 0, "Failed to create overlapped window\n");
4358 hmenu = GetSystemMenu(hwnd, FALSE);
4359 ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
4361 DestroyWindow(hwnd);
4364 /* For shown WS_OVERLAPPEDWINDOW */
4365 static const struct message WmSetIcon_1[] = {
4366 { WM_SETICON, sent },
4367 { 0x00AE, sent|defwinproc|optional }, /* XP */
4368 { WM_GETTEXT, sent|defwinproc|optional },
4369 { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
4370 { 0 }
4373 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
4374 static const struct message WmSetIcon_2[] = {
4375 { WM_SETICON, sent },
4376 { 0 }
4379 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4380 static const struct message WmInitEndSession[] = {
4381 { 0x003B, sent },
4382 { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4383 { 0 }
4386 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4387 static const struct message WmInitEndSession_2[] = {
4388 { 0x003B, sent },
4389 { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4390 { 0 }
4393 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4394 static const struct message WmInitEndSession_3[] = {
4395 { 0x003B, sent },
4396 { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4397 { 0 }
4400 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4401 static const struct message WmInitEndSession_4[] = {
4402 { 0x003B, sent },
4403 { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4404 { 0 }
4407 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4408 static const struct message WmInitEndSession_5[] = {
4409 { 0x003B, sent },
4410 { WM_ENDSESSION, sent|defwinproc/*|wparam*/|lparam, 1, ENDSESSION_LOGOFF },
4411 { 0 }
4414 static const struct message WmOptionalPaint[] = {
4415 { WM_PAINT, sent|optional },
4416 { WM_NCPAINT, sent|beginpaint|optional },
4417 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4418 { WM_ERASEBKGND, sent|beginpaint|optional },
4419 { 0 }
4422 static const struct message WmZOrder[] = {
4423 { WM_WINDOWPOSCHANGING, sent|wparam, 0, 0 },
4424 { WM_GETMINMAXINFO, sent|defwinproc|wparam, 0, 0 },
4425 { HCBT_ACTIVATE, hook },
4426 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
4427 { WM_WINDOWPOSCHANGING, sent|wparam, 3, 0 },
4428 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0 },
4429 { WM_GETTEXT, sent|optional },
4430 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
4431 { WM_ACTIVATEAPP, sent|wparam, 1, 0 },
4432 { WM_NCACTIVATE, sent|lparam, 1, 0 },
4433 { WM_GETTEXT, sent|defwinproc|optional },
4434 { WM_GETTEXT, sent|defwinproc|optional },
4435 { WM_ACTIVATE, sent|wparam|lparam, 1, 0 },
4436 { HCBT_SETFOCUS, hook },
4437 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4438 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4439 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4440 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
4441 { WM_GETTEXT, sent|optional },
4442 { WM_NCCALCSIZE, sent|optional },
4443 { 0 }
4446 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4448 DWORD ret;
4449 MSG msg;
4451 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4452 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4454 PostMessageA(hwnd, WM_USER, 0, 0);
4456 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4457 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4459 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4460 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4462 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4463 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4465 PostMessageA(hwnd, WM_USER, 0, 0);
4467 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4468 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4470 ok(PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4471 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4473 /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4474 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4475 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4477 PostMessageA(hwnd, WM_USER, 0, 0);
4479 /* new incoming message causes it to become signaled again */
4480 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4481 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4483 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4484 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4485 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4486 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4489 /* test if we receive the right sequence of messages */
4490 static void test_messages(void)
4492 HWND hwnd, hparent, hchild;
4493 HWND hchild2, hbutton;
4494 HMENU hmenu;
4495 MSG msg;
4496 LRESULT res;
4498 flush_sequence();
4500 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4501 100, 100, 200, 200, 0, 0, 0, NULL);
4502 ok (hwnd != 0, "Failed to create overlapped window\n");
4503 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4505 /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4506 ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4507 ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4509 /* test WM_SETREDRAW on a not visible top level window */
4510 test_WM_SETREDRAW(hwnd);
4512 SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4513 flush_events();
4514 ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4515 ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4517 ok(GetActiveWindow() == hwnd, "window should be active\n");
4518 ok(GetFocus() == hwnd, "window should have input focus\n");
4519 ShowWindow(hwnd, SW_HIDE);
4520 flush_events();
4521 ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4523 ShowWindow(hwnd, SW_SHOW);
4524 flush_events();
4525 ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4527 ShowWindow(hwnd, SW_HIDE);
4528 flush_events();
4529 ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4531 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4532 flush_events();
4533 ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4534 flush_sequence();
4536 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MAXIMIZE)
4538 ShowWindow(hwnd, SW_RESTORE);
4539 flush_events();
4540 ok_sequence(WmShowRestoreMaxOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4541 flush_sequence();
4544 ShowWindow(hwnd, SW_MINIMIZE);
4545 flush_events();
4546 ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4547 flush_sequence();
4549 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MINIMIZE)
4551 ShowWindow(hwnd, SW_RESTORE);
4552 flush_events();
4553 ok_sequence(WmShowRestoreMinOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4554 flush_sequence();
4557 ShowWindow(hwnd, SW_SHOW);
4558 flush_events();
4559 ok_sequence(WmOptionalPaint, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4561 SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4562 ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4563 ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4564 ok(GetActiveWindow() == hwnd, "window should still be active\n");
4566 /* test WM_SETREDRAW on a visible top level window */
4567 ShowWindow(hwnd, SW_SHOW);
4568 flush_events();
4569 test_WM_SETREDRAW(hwnd);
4571 trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4572 test_scroll_messages(hwnd);
4574 /* test resizing and moving */
4575 SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4576 ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4577 flush_events();
4578 flush_sequence();
4579 SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4580 ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4581 flush_events();
4582 flush_sequence();
4583 SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER|SWP_NOACTIVATE );
4584 ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4585 flush_events();
4586 flush_sequence();
4588 /* popups don't get WM_GETMINMAXINFO */
4589 SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4590 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4591 flush_sequence();
4592 SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4593 ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4595 DestroyWindow(hwnd);
4596 ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4598 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4599 100, 100, 200, 200, 0, 0, 0, NULL);
4600 ok (hparent != 0, "Failed to create parent window\n");
4601 flush_sequence();
4603 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4604 0, 0, 10, 10, hparent, 0, 0, NULL);
4605 ok (hchild != 0, "Failed to create child window\n");
4606 ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4607 DestroyWindow(hchild);
4608 flush_sequence();
4610 /* visible child window with a caption */
4611 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4612 WS_CHILD | WS_VISIBLE | WS_CAPTION,
4613 0, 0, 10, 10, hparent, 0, 0, NULL);
4614 ok (hchild != 0, "Failed to create child window\n");
4615 ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4617 trace("testing scroll APIs on a visible child window %p\n", hchild);
4618 test_scroll_messages(hchild);
4620 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4621 ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4623 DestroyWindow(hchild);
4624 flush_sequence();
4626 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4627 0, 0, 10, 10, hparent, 0, 0, NULL);
4628 ok (hchild != 0, "Failed to create child window\n");
4629 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4631 hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4632 100, 100, 50, 50, hparent, 0, 0, NULL);
4633 ok (hchild2 != 0, "Failed to create child2 window\n");
4634 flush_sequence();
4636 hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4637 0, 100, 50, 50, hchild, 0, 0, NULL);
4638 ok (hbutton != 0, "Failed to create button window\n");
4640 /* test WM_SETREDRAW on a not visible child window */
4641 test_WM_SETREDRAW(hchild);
4643 ShowWindow(hchild, SW_SHOW);
4644 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4646 /* check parent messages too */
4647 log_all_parent_messages++;
4648 ShowWindow(hchild, SW_HIDE);
4649 ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4650 log_all_parent_messages--;
4652 ShowWindow(hchild, SW_SHOW);
4653 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4655 ShowWindow(hchild, SW_HIDE);
4656 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4658 ShowWindow(hchild, SW_SHOW);
4659 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4661 /* test WM_SETREDRAW on a visible child window */
4662 test_WM_SETREDRAW(hchild);
4664 log_all_parent_messages++;
4665 MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4666 ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4667 log_all_parent_messages--;
4669 ShowWindow(hchild, SW_HIDE);
4670 flush_sequence();
4671 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4672 ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4674 ShowWindow(hchild, SW_HIDE);
4675 flush_sequence();
4676 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4677 ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4679 /* DestroyWindow sequence below expects that a child has focus */
4680 SetFocus(hchild);
4681 flush_sequence();
4683 DestroyWindow(hchild);
4684 ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4685 DestroyWindow(hchild2);
4686 DestroyWindow(hbutton);
4688 flush_sequence();
4689 hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4690 0, 0, 100, 100, hparent, 0, 0, NULL);
4691 ok (hchild != 0, "Failed to create child popup window\n");
4692 ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4693 DestroyWindow(hchild);
4695 /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4696 flush_sequence();
4697 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4698 0, 0, 100, 100, hparent, 0, 0, NULL);
4699 ok (hchild != 0, "Failed to create popup window\n");
4700 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4701 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4702 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4703 flush_sequence();
4704 ShowWindow(hchild, SW_SHOW);
4705 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4706 flush_sequence();
4707 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4708 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4709 flush_sequence();
4710 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4711 ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
4712 DestroyWindow(hchild);
4714 /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4715 * changes nothing in message sequences.
4717 flush_sequence();
4718 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4719 0, 0, 100, 100, hparent, 0, 0, NULL);
4720 ok (hchild != 0, "Failed to create popup window\n");
4721 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4722 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4723 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4724 flush_sequence();
4725 ShowWindow(hchild, SW_SHOW);
4726 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4727 flush_sequence();
4728 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4729 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4730 DestroyWindow(hchild);
4732 flush_sequence();
4733 hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4734 0, 0, 100, 100, hparent, 0, 0, NULL);
4735 ok(hwnd != 0, "Failed to create custom dialog window\n");
4736 ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4738 if(0) {
4739 trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4740 test_scroll_messages(hwnd);
4743 flush_sequence();
4745 test_def_id = 1;
4746 SendMessage(hwnd, WM_NULL, 0, 0);
4748 flush_sequence();
4749 after_end_dialog = 1;
4750 EndDialog( hwnd, 0 );
4751 ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4753 DestroyWindow(hwnd);
4754 after_end_dialog = 0;
4755 test_def_id = 0;
4757 hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4758 0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4759 ok(hwnd != 0, "Failed to create custom dialog window\n");
4760 flush_sequence();
4761 trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4762 ShowWindow(hwnd, SW_SHOW);
4763 ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4764 DestroyWindow(hwnd);
4766 flush_sequence();
4767 DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4768 ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4770 DestroyWindow(hparent);
4771 flush_sequence();
4773 /* Message sequence for SetMenu */
4774 ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4775 ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4777 hmenu = CreateMenu();
4778 ok (hmenu != 0, "Failed to create menu\n");
4779 ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4780 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4781 100, 100, 200, 200, 0, hmenu, 0, NULL);
4782 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4783 ok (SetMenu(hwnd, 0), "SetMenu\n");
4784 ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4785 ok (SetMenu(hwnd, 0), "SetMenu\n");
4786 ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4787 ShowWindow(hwnd, SW_SHOW);
4788 UpdateWindow( hwnd );
4789 flush_events();
4790 flush_sequence();
4791 ok (SetMenu(hwnd, 0), "SetMenu\n");
4792 ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4793 ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4794 ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4796 UpdateWindow( hwnd );
4797 flush_events();
4798 flush_sequence();
4799 ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4800 flush_events();
4801 ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4803 DestroyWindow(hwnd);
4804 flush_sequence();
4806 /* Message sequence for EnableWindow */
4807 hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4808 100, 100, 200, 200, 0, 0, 0, NULL);
4809 ok (hparent != 0, "Failed to create parent window\n");
4810 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4811 0, 0, 10, 10, hparent, 0, 0, NULL);
4812 ok (hchild != 0, "Failed to create child window\n");
4814 SetFocus(hchild);
4815 flush_events();
4816 flush_sequence();
4818 EnableWindow(hparent, FALSE);
4819 ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4821 EnableWindow(hparent, TRUE);
4822 ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4824 flush_events();
4825 flush_sequence();
4827 test_MsgWaitForMultipleObjects(hparent);
4829 /* the following test causes an exception in user.exe under win9x */
4830 if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4832 DestroyWindow(hparent);
4833 flush_sequence();
4834 return;
4836 PostMessageW( hparent, WM_USER+1, 0, 0 );
4837 /* PeekMessage(NULL) fails, but still removes the message */
4838 SetLastError(0xdeadbeef);
4839 ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4840 ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4841 GetLastError() == 0xdeadbeef, /* NT4 */
4842 "last error is %d\n", GetLastError() );
4843 ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4844 ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4846 DestroyWindow(hchild);
4847 DestroyWindow(hparent);
4848 flush_sequence();
4850 /* Message sequences for WM_SETICON */
4851 trace("testing WM_SETICON\n");
4852 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4853 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4854 NULL, NULL, 0);
4855 ShowWindow(hwnd, SW_SHOW);
4856 UpdateWindow(hwnd);
4857 flush_events();
4858 flush_sequence();
4859 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4860 ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4862 ShowWindow(hwnd, SW_HIDE);
4863 flush_events();
4864 flush_sequence();
4865 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4866 ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4867 DestroyWindow(hwnd);
4868 flush_sequence();
4870 hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4871 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4872 NULL, NULL, 0);
4873 ShowWindow(hwnd, SW_SHOW);
4874 UpdateWindow(hwnd);
4875 flush_events();
4876 flush_sequence();
4877 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4878 ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4880 ShowWindow(hwnd, SW_HIDE);
4881 flush_events();
4882 flush_sequence();
4883 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4884 ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4886 flush_sequence();
4887 res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4888 if (!res)
4890 todo_wine win_skip( "Message 0x3b not supported\n" );
4891 goto done;
4893 ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4894 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4895 res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4896 ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4897 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4898 res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4899 ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4900 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4902 flush_sequence();
4903 res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4904 ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4905 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4906 res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4907 ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4908 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4910 res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4911 ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4912 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4914 res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4915 ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4916 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4918 done:
4919 DestroyWindow(hwnd);
4920 flush_sequence();
4923 static void test_setwindowpos(void)
4925 HWND hwnd;
4926 RECT rc;
4927 LRESULT res;
4928 const INT winX = 100;
4929 const INT winY = 100;
4930 const INT sysX = GetSystemMetrics(SM_CXMINTRACK);
4932 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
4933 0, 0, winX, winY, 0,
4934 NULL, NULL, 0);
4936 GetWindowRect(hwnd, &rc);
4937 expect(sysX, rc.right);
4938 expect(winY, rc.bottom);
4940 flush_events();
4941 flush_sequence();
4942 res = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, winX, winY, 0);
4943 ok_sequence(WmZOrder, "Z-Order", TRUE);
4944 ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
4946 GetWindowRect(hwnd, &rc);
4947 expect(sysX, rc.right);
4948 expect(winY, rc.bottom);
4949 DestroyWindow(hwnd);
4952 static void invisible_parent_tests(void)
4954 HWND hparent, hchild;
4956 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4957 100, 100, 200, 200, 0, 0, 0, NULL);
4958 ok (hparent != 0, "Failed to create parent window\n");
4959 flush_sequence();
4961 /* test showing child with hidden parent */
4963 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4964 0, 0, 10, 10, hparent, 0, 0, NULL);
4965 ok (hchild != 0, "Failed to create child window\n");
4966 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4968 ShowWindow( hchild, SW_MINIMIZE );
4969 ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4970 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4971 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4973 /* repeat */
4974 flush_events();
4975 flush_sequence();
4976 ShowWindow( hchild, SW_MINIMIZE );
4977 ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4979 DestroyWindow(hchild);
4980 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4981 0, 0, 10, 10, hparent, 0, 0, NULL);
4982 flush_sequence();
4984 ShowWindow( hchild, SW_MAXIMIZE );
4985 ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4986 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4987 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4989 /* repeat */
4990 flush_events();
4991 flush_sequence();
4992 ShowWindow( hchild, SW_MAXIMIZE );
4993 ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4995 DestroyWindow(hchild);
4996 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4997 0, 0, 10, 10, hparent, 0, 0, NULL);
4998 flush_sequence();
5000 ShowWindow( hchild, SW_RESTORE );
5001 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
5002 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5003 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5005 DestroyWindow(hchild);
5006 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5007 0, 0, 10, 10, hparent, 0, 0, NULL);
5008 flush_sequence();
5010 ShowWindow( hchild, SW_SHOWMINIMIZED );
5011 ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
5012 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5013 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5015 /* repeat */
5016 flush_events();
5017 flush_sequence();
5018 ShowWindow( hchild, SW_SHOWMINIMIZED );
5019 ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
5021 DestroyWindow(hchild);
5022 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5023 0, 0, 10, 10, hparent, 0, 0, NULL);
5024 flush_sequence();
5026 /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
5027 ShowWindow( hchild, SW_SHOWMAXIMIZED );
5028 ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
5029 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5030 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5032 DestroyWindow(hchild);
5033 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5034 0, 0, 10, 10, hparent, 0, 0, NULL);
5035 flush_sequence();
5037 ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5038 ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5039 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5040 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5042 /* repeat */
5043 flush_events();
5044 flush_sequence();
5045 ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5046 ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5048 DestroyWindow(hchild);
5049 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5050 0, 0, 10, 10, hparent, 0, 0, NULL);
5051 flush_sequence();
5053 /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
5054 ShowWindow( hchild, SW_FORCEMINIMIZE );
5055 ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
5056 todo_wine {
5057 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5059 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5061 DestroyWindow(hchild);
5062 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5063 0, 0, 10, 10, hparent, 0, 0, NULL);
5064 flush_sequence();
5066 ShowWindow( hchild, SW_SHOWNA );
5067 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5068 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5069 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5071 /* repeat */
5072 flush_events();
5073 flush_sequence();
5074 ShowWindow( hchild, SW_SHOWNA );
5075 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5077 DestroyWindow(hchild);
5078 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5079 0, 0, 10, 10, hparent, 0, 0, NULL);
5080 flush_sequence();
5082 ShowWindow( hchild, SW_SHOW );
5083 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5084 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5085 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5087 /* repeat */
5088 flush_events();
5089 flush_sequence();
5090 ShowWindow( hchild, SW_SHOW );
5091 ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5093 ShowWindow( hchild, SW_HIDE );
5094 ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
5095 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5096 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5098 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5099 ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
5100 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5101 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5103 SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5104 ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
5105 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
5106 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5108 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5109 flush_sequence();
5110 DestroyWindow(hchild);
5111 ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
5113 DestroyWindow(hparent);
5114 flush_sequence();
5117 /****************** button message test *************************/
5118 #define ID_BUTTON 0x000e
5120 static const struct message WmSetFocusButtonSeq[] =
5122 { HCBT_SETFOCUS, hook },
5123 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5124 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5125 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5126 { WM_SETFOCUS, sent|wparam, 0 },
5127 { WM_CTLCOLORBTN, sent|parent },
5128 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5129 { WM_APP, sent|wparam|lparam, 0, 0 },
5130 { 0 }
5132 static const struct message WmKillFocusButtonSeq[] =
5134 { HCBT_SETFOCUS, hook },
5135 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5136 { WM_KILLFOCUS, sent|wparam, 0 },
5137 { WM_CTLCOLORBTN, sent|parent },
5138 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5139 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5140 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5141 { WM_APP, sent|wparam|lparam, 0, 0 },
5142 { WM_PAINT, sent },
5143 { WM_CTLCOLORBTN, sent|parent },
5144 { 0 }
5146 static const struct message WmSetFocusStaticSeq[] =
5148 { HCBT_SETFOCUS, hook },
5149 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5150 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5151 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5152 { WM_SETFOCUS, sent|wparam, 0 },
5153 { WM_CTLCOLORSTATIC, sent|parent },
5154 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5155 { WM_COMMAND, sent|wparam|parent|optional, MAKEWPARAM(ID_BUTTON, BN_CLICKED) }, /* radio button */
5156 { WM_APP, sent|wparam|lparam, 0, 0 },
5157 { 0 }
5159 static const struct message WmKillFocusStaticSeq[] =
5161 { HCBT_SETFOCUS, hook },
5162 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5163 { WM_KILLFOCUS, sent|wparam, 0 },
5164 { WM_CTLCOLORSTATIC, sent|parent },
5165 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5166 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5167 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5168 { WM_APP, sent|wparam|lparam, 0, 0 },
5169 { WM_PAINT, sent },
5170 { WM_CTLCOLORSTATIC, sent|parent },
5171 { 0 }
5173 static const struct message WmSetFocusOwnerdrawSeq[] =
5175 { HCBT_SETFOCUS, hook },
5176 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5177 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5178 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5179 { WM_SETFOCUS, sent|wparam, 0 },
5180 { WM_CTLCOLORBTN, sent|parent },
5181 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x001040e4 },
5182 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5183 { WM_APP, sent|wparam|lparam, 0, 0 },
5184 { 0 }
5186 static const struct message WmKillFocusOwnerdrawSeq[] =
5188 { HCBT_SETFOCUS, hook },
5189 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5190 { WM_KILLFOCUS, sent|wparam, 0 },
5191 { WM_CTLCOLORBTN, sent|parent },
5192 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000040e4 },
5193 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5194 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5195 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5196 { WM_APP, sent|wparam|lparam, 0, 0 },
5197 { WM_PAINT, sent },
5198 { WM_CTLCOLORBTN, sent|parent },
5199 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 },
5200 { 0 }
5202 static const struct message WmLButtonDownSeq[] =
5204 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
5205 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5206 { HCBT_SETFOCUS, hook },
5207 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
5208 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5209 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5210 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
5211 { WM_CTLCOLORBTN, sent|defwinproc },
5212 { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
5213 { WM_CTLCOLORBTN, sent|defwinproc },
5214 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5215 { 0 }
5217 static const struct message WmLButtonUpSeq[] =
5219 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
5220 { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
5221 { WM_CTLCOLORBTN, sent|defwinproc },
5222 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5223 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5224 { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
5225 { 0 }
5227 static const struct message WmSetFontButtonSeq[] =
5229 { WM_SETFONT, sent },
5230 { WM_PAINT, sent },
5231 { WM_ERASEBKGND, sent|defwinproc|optional },
5232 { WM_CTLCOLORBTN, sent|defwinproc },
5233 { 0 }
5235 static const struct message WmSetStyleButtonSeq[] =
5237 { BM_SETSTYLE, sent },
5238 { WM_APP, sent|wparam|lparam, 0, 0 },
5239 { WM_PAINT, sent },
5240 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5241 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5242 { WM_CTLCOLORBTN, sent|parent },
5243 { 0 }
5245 static const struct message WmSetStyleStaticSeq[] =
5247 { BM_SETSTYLE, sent },
5248 { WM_APP, sent|wparam|lparam, 0, 0 },
5249 { WM_PAINT, sent },
5250 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5251 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5252 { WM_CTLCOLORSTATIC, sent|parent },
5253 { 0 }
5255 static const struct message WmSetStyleUserSeq[] =
5257 { BM_SETSTYLE, sent },
5258 { WM_APP, sent|wparam|lparam, 0, 0 },
5259 { WM_PAINT, sent },
5260 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5261 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5262 { WM_CTLCOLORBTN, sent|parent },
5263 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_PAINT) },
5264 { 0 }
5266 static const struct message WmSetStyleOwnerdrawSeq[] =
5268 { BM_SETSTYLE, sent },
5269 { WM_APP, sent|wparam|lparam, 0, 0 },
5270 { WM_PAINT, sent },
5271 { WM_NCPAINT, sent|optional }, /* FIXME: Wine sends it */
5272 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5273 { WM_CTLCOLORBTN, sent|parent },
5274 { WM_CTLCOLORBTN, sent|parent|optional }, /* Win9x doesn't send it */
5275 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 },
5276 { 0 }
5278 static const struct message WmSetStateButtonSeq[] =
5280 { BM_SETSTATE, sent },
5281 { WM_CTLCOLORBTN, sent|parent },
5282 { WM_APP, sent|wparam|lparam, 0, 0 },
5283 { 0 }
5285 static const struct message WmSetStateStaticSeq[] =
5287 { BM_SETSTATE, sent },
5288 { WM_CTLCOLORSTATIC, sent|parent },
5289 { WM_APP, sent|wparam|lparam, 0, 0 },
5290 { 0 }
5292 static const struct message WmSetStateUserSeq[] =
5294 { BM_SETSTATE, sent },
5295 { WM_CTLCOLORBTN, sent|parent },
5296 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_HILITE) },
5297 { WM_APP, sent|wparam|lparam, 0, 0 },
5298 { 0 }
5300 static const struct message WmSetStateOwnerdrawSeq[] =
5302 { BM_SETSTATE, sent },
5303 { WM_CTLCOLORBTN, sent|parent },
5304 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000120e4 },
5305 { WM_APP, sent|wparam|lparam, 0, 0 },
5306 { 0 }
5308 static const struct message WmClearStateButtonSeq[] =
5310 { BM_SETSTATE, sent },
5311 { WM_CTLCOLORBTN, sent|parent },
5312 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_UNHILITE) },
5313 { WM_APP, sent|wparam|lparam, 0, 0 },
5314 { 0 }
5316 static const struct message WmClearStateOwnerdrawSeq[] =
5318 { BM_SETSTATE, sent },
5319 { WM_CTLCOLORBTN, sent|parent },
5320 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000020e4 },
5321 { WM_APP, sent|wparam|lparam, 0, 0 },
5322 { 0 }
5324 static const struct message WmSetCheckIgnoredSeq[] =
5326 { BM_SETCHECK, sent },
5327 { WM_APP, sent|wparam|lparam, 0, 0 },
5328 { 0 }
5330 static const struct message WmSetCheckStaticSeq[] =
5332 { BM_SETCHECK, sent },
5333 { WM_CTLCOLORSTATIC, sent|parent },
5334 { WM_APP, sent|wparam|lparam, 0, 0 },
5335 { 0 }
5338 static WNDPROC old_button_proc;
5340 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5342 static LONG defwndproc_counter = 0;
5343 LRESULT ret;
5344 struct recvd_message msg;
5346 if (ignore_message( message )) return 0;
5348 switch (message)
5350 case WM_SYNCPAINT:
5351 break;
5352 case BM_SETSTATE:
5353 if (GetCapture())
5354 ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
5355 /* fall through */
5356 default:
5357 msg.hwnd = hwnd;
5358 msg.message = message;
5359 msg.flags = sent|wparam|lparam;
5360 if (defwndproc_counter) msg.flags |= defwinproc;
5361 msg.wParam = wParam;
5362 msg.lParam = lParam;
5363 msg.descr = "button";
5364 add_message(&msg);
5367 defwndproc_counter++;
5368 ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
5369 defwndproc_counter--;
5371 return ret;
5374 static void subclass_button(void)
5376 WNDCLASSA cls;
5378 if (!GetClassInfoA(0, "button", &cls)) assert(0);
5380 old_button_proc = cls.lpfnWndProc;
5382 cls.hInstance = GetModuleHandle(0);
5383 cls.lpfnWndProc = button_hook_proc;
5384 cls.lpszClassName = "my_button_class";
5385 UnregisterClass(cls.lpszClassName, cls.hInstance);
5386 if (!RegisterClassA(&cls)) assert(0);
5389 static void test_button_messages(void)
5391 static const struct
5393 DWORD style;
5394 DWORD dlg_code;
5395 const struct message *setfocus;
5396 const struct message *killfocus;
5397 const struct message *setstyle;
5398 const struct message *setstate;
5399 const struct message *clearstate;
5400 const struct message *setcheck;
5401 } button[] = {
5402 { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5403 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq,
5404 WmSetStateButtonSeq, WmSetStateButtonSeq, WmSetCheckIgnoredSeq },
5405 { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
5406 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq,
5407 WmSetStateButtonSeq, WmSetStateButtonSeq, WmSetCheckIgnoredSeq },
5408 { BS_CHECKBOX, DLGC_BUTTON,
5409 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5410 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5411 { BS_AUTOCHECKBOX, DLGC_BUTTON,
5412 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5413 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5414 { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5415 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5416 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5417 { BS_3STATE, DLGC_BUTTON,
5418 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5419 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5420 { BS_AUTO3STATE, DLGC_BUTTON,
5421 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5422 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5423 { BS_GROUPBOX, DLGC_STATIC,
5424 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5425 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckIgnoredSeq },
5426 { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5427 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleUserSeq,
5428 WmSetStateUserSeq, WmClearStateButtonSeq, WmSetCheckIgnoredSeq },
5429 { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5430 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5431 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5432 { BS_OWNERDRAW, DLGC_BUTTON,
5433 WmSetFocusOwnerdrawSeq, WmKillFocusOwnerdrawSeq, WmSetStyleOwnerdrawSeq,
5434 WmSetStateOwnerdrawSeq, WmClearStateOwnerdrawSeq, WmSetCheckIgnoredSeq },
5436 unsigned int i;
5437 HWND hwnd, parent;
5438 DWORD dlg_code;
5439 HFONT zfont;
5441 /* selection with VK_SPACE should capture button window */
5442 hwnd = CreateWindowExA(0, "button", "test", BS_CHECKBOX | WS_VISIBLE | WS_POPUP,
5443 0, 0, 50, 14, 0, 0, 0, NULL);
5444 ok(hwnd != 0, "Failed to create button window\n");
5445 ReleaseCapture();
5446 SetFocus(hwnd);
5447 SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
5448 ok(GetCapture() == hwnd, "Should be captured on VK_SPACE WM_KEYDOWN\n");
5449 SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
5450 DestroyWindow(hwnd);
5452 subclass_button();
5454 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5455 100, 100, 200, 200, 0, 0, 0, NULL);
5456 ok(parent != 0, "Failed to create parent window\n");
5458 for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
5460 MSG msg;
5461 DWORD style, state;
5463 trace("button style %08x\n", button[i].style);
5465 hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_CHILD | BS_NOTIFY,
5466 0, 0, 50, 14, parent, (HMENU)ID_BUTTON, 0, NULL);
5467 ok(hwnd != 0, "Failed to create button window\n");
5469 style = GetWindowLongA(hwnd, GWL_STYLE);
5470 style &= ~(WS_CHILD | BS_NOTIFY);
5471 /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
5472 if (button[i].style == BS_USERBUTTON)
5473 ok(style == BS_PUSHBUTTON, "expected style BS_PUSHBUTTON got %x\n", style);
5474 else
5475 ok(style == button[i].style, "expected style %x got %x\n", button[i].style, style);
5477 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5478 ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5480 ShowWindow(hwnd, SW_SHOW);
5481 UpdateWindow(hwnd);
5482 SetFocus(0);
5483 flush_events();
5484 SetFocus(0);
5485 flush_sequence();
5487 log_all_parent_messages++;
5489 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
5490 SetFocus(hwnd);
5491 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5492 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5493 ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
5495 SetFocus(0);
5496 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5497 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5498 ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
5500 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
5502 SendMessage(hwnd, BM_SETSTYLE, button[i].style | BS_BOTTOM, TRUE);
5503 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5504 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5505 ok_sequence(button[i].setstyle, "BM_SETSTYLE on a button", FALSE);
5507 style = GetWindowLongA(hwnd, GWL_STYLE);
5508 style &= ~(WS_VISIBLE | WS_CHILD | BS_NOTIFY);
5509 /* XP doesn't turn a BS_USERBUTTON into BS_PUSHBUTTON here! */
5510 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5512 state = SendMessage(hwnd, BM_GETSTATE, 0, 0);
5513 ok(state == 0, "expected state 0, got %04x\n", state);
5515 flush_sequence();
5517 SendMessage(hwnd, BM_SETSTATE, TRUE, 0);
5518 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5519 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5520 ok_sequence(button[i].setstate, "BM_SETSTATE/TRUE on a button", FALSE);
5522 state = SendMessage(hwnd, BM_GETSTATE, 0, 0);
5523 ok(state == 0x0004, "expected state 0x0004, got %04x\n", state);
5525 style = GetWindowLongA(hwnd, GWL_STYLE);
5526 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5527 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5529 flush_sequence();
5531 SendMessage(hwnd, BM_SETSTATE, FALSE, 0);
5532 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5533 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5534 ok_sequence(button[i].clearstate, "BM_SETSTATE/FALSE on a button", FALSE);
5536 state = SendMessage(hwnd, BM_GETSTATE, 0, 0);
5537 ok(state == 0, "expected state 0, got %04x\n", state);
5539 style = GetWindowLongA(hwnd, GWL_STYLE);
5540 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5541 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5543 state = SendMessage(hwnd, BM_GETCHECK, 0, 0);
5544 ok(state == BST_UNCHECKED, "expected BST_UNCHECKED, got %04x\n", state);
5546 flush_sequence();
5548 SendMessage(hwnd, BM_SETCHECK, BST_UNCHECKED, 0);
5549 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5550 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5551 ok_sequence(WmSetCheckIgnoredSeq, "BM_SETCHECK on a button", FALSE);
5553 state = SendMessage(hwnd, BM_GETCHECK, 0, 0);
5554 ok(state == BST_UNCHECKED, "expected BST_UNCHECKED, got %04x\n", state);
5556 style = GetWindowLongA(hwnd, GWL_STYLE);
5557 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5558 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5560 flush_sequence();
5562 SendMessage(hwnd, BM_SETCHECK, BST_CHECKED, 0);
5563 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5564 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5565 ok_sequence(button[i].setcheck, "BM_SETCHECK on a button", FALSE);
5567 state = SendMessage(hwnd, BM_GETCHECK, 0, 0);
5568 if (button[i].style == BS_PUSHBUTTON ||
5569 button[i].style == BS_DEFPUSHBUTTON ||
5570 button[i].style == BS_GROUPBOX ||
5571 button[i].style == BS_USERBUTTON ||
5572 button[i].style == BS_OWNERDRAW)
5573 ok(state == BST_UNCHECKED, "expected check 0, got %04x\n", state);
5574 else
5575 ok(state == BST_CHECKED, "expected check 1, got %04x\n", state);
5577 style = GetWindowLongA(hwnd, GWL_STYLE);
5578 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5579 if (button[i].style == BS_RADIOBUTTON ||
5580 button[i].style == BS_AUTORADIOBUTTON)
5581 ok(style == (button[i].style | WS_TABSTOP), "expected style %04x | WS_TABSTOP got %04x\n", button[i].style, style);
5582 else
5583 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5585 log_all_parent_messages--;
5587 DestroyWindow(hwnd);
5590 DestroyWindow(parent);
5592 hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
5593 0, 0, 50, 14, 0, 0, 0, NULL);
5594 ok(hwnd != 0, "Failed to create button window\n");
5596 SetForegroundWindow(hwnd);
5597 flush_events();
5599 SetActiveWindow(hwnd);
5600 SetFocus(0);
5601 flush_sequence();
5603 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
5604 ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
5606 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
5607 ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
5609 flush_sequence();
5610 zfont = GetStockObject(SYSTEM_FONT);
5611 SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
5612 UpdateWindow(hwnd);
5613 ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
5615 DestroyWindow(hwnd);
5618 /****************** static message test *************************/
5619 static const struct message WmSetFontStaticSeq[] =
5621 { WM_SETFONT, sent },
5622 { WM_PAINT, sent|defwinproc|optional },
5623 { WM_ERASEBKGND, sent|defwinproc|optional },
5624 { WM_CTLCOLORSTATIC, sent|defwinproc|optional },
5625 { 0 }
5628 static WNDPROC old_static_proc;
5630 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5632 static LONG defwndproc_counter = 0;
5633 LRESULT ret;
5634 struct recvd_message msg;
5636 if (ignore_message( message )) return 0;
5638 msg.hwnd = hwnd;
5639 msg.message = message;
5640 msg.flags = sent|wparam|lparam;
5641 if (defwndproc_counter) msg.flags |= defwinproc;
5642 msg.wParam = wParam;
5643 msg.lParam = lParam;
5644 msg.descr = "static";
5645 add_message(&msg);
5647 defwndproc_counter++;
5648 ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
5649 defwndproc_counter--;
5651 return ret;
5654 static void subclass_static(void)
5656 WNDCLASSA cls;
5658 if (!GetClassInfoA(0, "static", &cls)) assert(0);
5660 old_static_proc = cls.lpfnWndProc;
5662 cls.hInstance = GetModuleHandle(0);
5663 cls.lpfnWndProc = static_hook_proc;
5664 cls.lpszClassName = "my_static_class";
5665 UnregisterClass(cls.lpszClassName, cls.hInstance);
5666 if (!RegisterClassA(&cls)) assert(0);
5669 static void test_static_messages(void)
5671 /* FIXME: make as comprehensive as the button message test */
5672 static const struct
5674 DWORD style;
5675 DWORD dlg_code;
5676 const struct message *setfont;
5677 } static_ctrl[] = {
5678 { SS_LEFT, DLGC_STATIC,
5679 WmSetFontStaticSeq }
5681 unsigned int i;
5682 HWND hwnd;
5683 DWORD dlg_code;
5685 subclass_static();
5687 for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
5689 hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
5690 0, 0, 50, 14, 0, 0, 0, NULL);
5691 ok(hwnd != 0, "Failed to create static window\n");
5693 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5694 ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5696 ShowWindow(hwnd, SW_SHOW);
5697 UpdateWindow(hwnd);
5698 SetFocus(0);
5699 flush_sequence();
5701 trace("static style %08x\n", static_ctrl[i].style);
5702 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
5703 ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
5705 DestroyWindow(hwnd);
5709 /****************** ComboBox message test *************************/
5710 #define ID_COMBOBOX 0x000f
5712 static const struct message WmKeyDownComboSeq[] =
5714 { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
5715 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
5716 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
5717 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
5718 { WM_CTLCOLOREDIT, sent|parent },
5719 { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
5720 { 0 }
5723 static WNDPROC old_combobox_proc;
5725 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5727 static LONG defwndproc_counter = 0;
5728 LRESULT ret;
5729 struct recvd_message msg;
5731 /* do not log painting messages */
5732 if (message != WM_PAINT &&
5733 message != WM_NCPAINT &&
5734 message != WM_SYNCPAINT &&
5735 message != WM_ERASEBKGND &&
5736 message != WM_NCHITTEST &&
5737 message != WM_GETTEXT &&
5738 !ignore_message( message ))
5740 msg.hwnd = hwnd;
5741 msg.message = message;
5742 msg.flags = sent|wparam|lparam;
5743 if (defwndproc_counter) msg.flags |= defwinproc;
5744 msg.wParam = wParam;
5745 msg.lParam = lParam;
5746 msg.descr = "combo";
5747 add_message(&msg);
5750 defwndproc_counter++;
5751 ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5752 defwndproc_counter--;
5754 return ret;
5757 static void subclass_combobox(void)
5759 WNDCLASSA cls;
5761 if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5763 old_combobox_proc = cls.lpfnWndProc;
5765 cls.hInstance = GetModuleHandle(0);
5766 cls.lpfnWndProc = combobox_hook_proc;
5767 cls.lpszClassName = "my_combobox_class";
5768 UnregisterClass(cls.lpszClassName, cls.hInstance);
5769 if (!RegisterClassA(&cls)) assert(0);
5772 static void test_combobox_messages(void)
5774 HWND parent, combo;
5775 LRESULT ret;
5777 subclass_combobox();
5779 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5780 100, 100, 200, 200, 0, 0, 0, NULL);
5781 ok(parent != 0, "Failed to create parent window\n");
5782 flush_sequence();
5784 combo = CreateWindowEx(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5785 0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5786 ok(combo != 0, "Failed to create combobox window\n");
5788 UpdateWindow(combo);
5790 ret = SendMessage(combo, WM_GETDLGCODE, 0, 0);
5791 ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5793 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5794 ok(ret == 0, "expected 0, got %ld\n", ret);
5795 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5796 ok(ret == 1, "expected 1, got %ld\n", ret);
5797 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5798 ok(ret == 2, "expected 2, got %ld\n", ret);
5800 SendMessage(combo, CB_SETCURSEL, 0, 0);
5801 SetFocus(combo);
5802 flush_sequence();
5804 log_all_parent_messages++;
5805 SendMessage(combo, WM_KEYDOWN, VK_DOWN, 0);
5806 SendMessage(combo, WM_KEYUP, VK_DOWN, 0);
5807 log_all_parent_messages--;
5808 ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5810 DestroyWindow(combo);
5811 DestroyWindow(parent);
5814 /****************** WM_IME_KEYDOWN message test *******************/
5816 static const struct message WmImeKeydownMsgSeq_0[] =
5818 { WM_IME_KEYDOWN, wparam, VK_RETURN },
5819 { WM_CHAR, wparam, 'A' },
5820 { 0 }
5823 static const struct message WmImeKeydownMsgSeq_1[] =
5825 { WM_KEYDOWN, optional|wparam, VK_RETURN },
5826 { WM_CHAR, optional|wparam, VK_RETURN },
5827 { 0 }
5830 static LRESULT WINAPI wmime_keydown_procA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5832 struct recvd_message msg;
5834 msg.hwnd = hwnd;
5835 msg.message = message;
5836 msg.flags = wparam|lparam;
5837 msg.wParam = wParam;
5838 msg.lParam = lParam;
5839 msg.descr = "wmime_keydown";
5840 add_message(&msg);
5842 return DefWindowProcA(hwnd, message, wParam, lParam);
5845 static void register_wmime_keydown_class(void)
5847 WNDCLASSA cls;
5849 ZeroMemory(&cls, sizeof(WNDCLASSA));
5850 cls.lpfnWndProc = wmime_keydown_procA;
5851 cls.hInstance = GetModuleHandleA(0);
5852 cls.lpszClassName = "wmime_keydown_class";
5853 if (!RegisterClassA(&cls)) assert(0);
5856 static void test_wmime_keydown_message(void)
5858 HWND hwnd;
5859 MSG msg;
5861 trace("Message sequences by WM_IME_KEYDOWN\n");
5863 register_wmime_keydown_class();
5864 hwnd = CreateWindowExA(0, "wmime_keydown_class", NULL, WS_OVERLAPPEDWINDOW,
5865 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5866 NULL, NULL, 0);
5867 flush_events();
5868 flush_sequence();
5870 SendMessage(hwnd, WM_IME_KEYDOWN, VK_RETURN, 0x1c0001);
5871 SendMessage(hwnd, WM_CHAR, 'A', 1);
5872 ok_sequence(WmImeKeydownMsgSeq_0, "WM_IME_KEYDOWN 0", FALSE);
5874 while ( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
5876 TranslateMessage(&msg);
5877 DispatchMessage(&msg);
5879 ok_sequence(WmImeKeydownMsgSeq_1, "WM_IME_KEYDOWN 1", FALSE);
5881 DestroyWindow(hwnd);
5884 /************* painting message test ********************/
5886 void dump_region(HRGN hrgn)
5888 DWORD i, size;
5889 RGNDATA *data = NULL;
5890 RECT *rect;
5892 if (!hrgn)
5894 printf( "null region\n" );
5895 return;
5897 if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5898 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5899 GetRegionData( hrgn, size, data );
5900 printf("%d rects:", data->rdh.nCount );
5901 for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5902 printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
5903 printf("\n");
5904 HeapFree( GetProcessHeap(), 0, data );
5907 static void check_update_rgn( HWND hwnd, HRGN hrgn )
5909 INT ret;
5910 RECT r1, r2;
5911 HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
5912 HRGN update = CreateRectRgn( 0, 0, 0, 0 );
5914 ret = GetUpdateRgn( hwnd, update, FALSE );
5915 ok( ret != ERROR, "GetUpdateRgn failed\n" );
5916 if (ret == NULLREGION)
5918 ok( !hrgn, "Update region shouldn't be empty\n" );
5920 else
5922 if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
5924 ok( 0, "Regions are different\n" );
5925 if (winetest_debug > 0)
5927 printf( "Update region: " );
5928 dump_region( update );
5929 printf( "Wanted region: " );
5930 dump_region( hrgn );
5934 GetRgnBox( update, &r1 );
5935 GetUpdateRect( hwnd, &r2, FALSE );
5936 ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
5937 "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
5938 r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
5940 DeleteObject( tmp );
5941 DeleteObject( update );
5944 static const struct message WmInvalidateRgn[] = {
5945 { WM_NCPAINT, sent },
5946 { WM_GETTEXT, sent|defwinproc|optional },
5947 { 0 }
5950 static const struct message WmGetUpdateRect[] = {
5951 { WM_NCPAINT, sent },
5952 { WM_GETTEXT, sent|defwinproc|optional },
5953 { WM_PAINT, sent },
5954 { 0 }
5957 static const struct message WmInvalidateFull[] = {
5958 { WM_NCPAINT, sent|wparam, 1 },
5959 { WM_GETTEXT, sent|defwinproc|optional },
5960 { 0 }
5963 static const struct message WmInvalidateErase[] = {
5964 { WM_NCPAINT, sent|wparam, 1 },
5965 { WM_GETTEXT, sent|defwinproc|optional },
5966 { WM_ERASEBKGND, sent },
5967 { 0 }
5970 static const struct message WmInvalidatePaint[] = {
5971 { WM_PAINT, sent },
5972 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5973 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5974 { 0 }
5977 static const struct message WmInvalidateErasePaint[] = {
5978 { WM_PAINT, sent },
5979 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5980 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5981 { WM_ERASEBKGND, sent|beginpaint|optional },
5982 { 0 }
5985 static const struct message WmInvalidateErasePaint2[] = {
5986 { WM_PAINT, sent },
5987 { WM_NCPAINT, sent|beginpaint },
5988 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5989 { WM_ERASEBKGND, sent|beginpaint|optional },
5990 { 0 }
5993 static const struct message WmErase[] = {
5994 { WM_ERASEBKGND, sent },
5995 { 0 }
5998 static const struct message WmPaint[] = {
5999 { WM_PAINT, sent },
6000 { 0 }
6003 static const struct message WmParentOnlyPaint[] = {
6004 { WM_PAINT, sent|parent },
6005 { 0 }
6008 static const struct message WmInvalidateParent[] = {
6009 { WM_NCPAINT, sent|parent },
6010 { WM_GETTEXT, sent|defwinproc|parent|optional },
6011 { WM_ERASEBKGND, sent|parent },
6012 { 0 }
6015 static const struct message WmInvalidateParentChild[] = {
6016 { WM_NCPAINT, sent|parent },
6017 { WM_GETTEXT, sent|defwinproc|parent|optional },
6018 { WM_ERASEBKGND, sent|parent },
6019 { WM_NCPAINT, sent },
6020 { WM_GETTEXT, sent|defwinproc|optional },
6021 { WM_ERASEBKGND, sent },
6022 { 0 }
6025 static const struct message WmInvalidateParentChild2[] = {
6026 { WM_ERASEBKGND, sent|parent },
6027 { WM_NCPAINT, sent },
6028 { WM_GETTEXT, sent|defwinproc|optional },
6029 { WM_ERASEBKGND, sent },
6030 { 0 }
6033 static const struct message WmParentPaint[] = {
6034 { WM_PAINT, sent|parent },
6035 { WM_PAINT, sent },
6036 { 0 }
6039 static const struct message WmParentPaintNc[] = {
6040 { WM_PAINT, sent|parent },
6041 { WM_PAINT, sent },
6042 { WM_NCPAINT, sent|beginpaint },
6043 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6044 { WM_ERASEBKGND, sent|beginpaint|optional },
6045 { 0 }
6048 static const struct message WmChildPaintNc[] = {
6049 { WM_PAINT, sent },
6050 { WM_NCPAINT, sent|beginpaint },
6051 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6052 { WM_ERASEBKGND, sent|beginpaint|optional },
6053 { 0 }
6056 static const struct message WmParentErasePaint[] = {
6057 { WM_PAINT, sent|parent },
6058 { WM_NCPAINT, sent|parent|beginpaint },
6059 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
6060 { WM_ERASEBKGND, sent|parent|beginpaint|optional },
6061 { WM_PAINT, sent },
6062 { WM_NCPAINT, sent|beginpaint },
6063 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6064 { WM_ERASEBKGND, sent|beginpaint|optional },
6065 { 0 }
6068 static const struct message WmParentOnlyNcPaint[] = {
6069 { WM_PAINT, sent|parent },
6070 { WM_NCPAINT, sent|parent|beginpaint },
6071 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
6072 { 0 }
6075 static const struct message WmSetParentStyle[] = {
6076 { WM_STYLECHANGING, sent|parent },
6077 { WM_STYLECHANGED, sent|parent },
6078 { 0 }
6081 static void test_paint_messages(void)
6083 BOOL ret;
6084 RECT rect;
6085 POINT pt;
6086 MSG msg;
6087 HWND hparent, hchild;
6088 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
6089 HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
6090 HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
6091 100, 100, 200, 200, 0, 0, 0, NULL);
6092 ok (hwnd != 0, "Failed to create overlapped window\n");
6094 ShowWindow( hwnd, SW_SHOW );
6095 UpdateWindow( hwnd );
6096 flush_events();
6097 flush_sequence();
6099 check_update_rgn( hwnd, 0 );
6100 SetRectRgn( hrgn, 10, 10, 20, 20 );
6101 ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6102 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6103 check_update_rgn( hwnd, hrgn );
6104 SetRectRgn( hrgn2, 20, 20, 30, 30 );
6105 ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
6106 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6107 CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
6108 check_update_rgn( hwnd, hrgn );
6109 /* validate everything */
6110 ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6111 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6112 check_update_rgn( hwnd, 0 );
6114 /* test empty region */
6115 SetRectRgn( hrgn, 10, 10, 10, 15 );
6116 ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6117 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6118 check_update_rgn( hwnd, 0 );
6119 /* test empty rect */
6120 SetRect( &rect, 10, 10, 10, 15 );
6121 ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
6122 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6123 check_update_rgn( hwnd, 0 );
6125 /* flush pending messages */
6126 flush_events();
6127 flush_sequence();
6129 GetClientRect( hwnd, &rect );
6130 SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
6131 /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
6132 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
6134 trace("testing InvalidateRect(0, NULL, FALSE)\n");
6135 SetRectEmpty( &rect );
6136 ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
6137 check_update_rgn( hwnd, hrgn );
6138 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6139 flush_events();
6140 ok_sequence( WmPaint, "Paint", FALSE );
6141 RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6142 check_update_rgn( hwnd, 0 );
6144 /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
6145 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
6147 trace("testing ValidateRect(0, NULL)\n");
6148 SetRectEmpty( &rect );
6149 if (ValidateRect(0, &rect)) /* not supported on Win9x */
6151 check_update_rgn( hwnd, hrgn );
6152 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6153 flush_events();
6154 ok_sequence( WmPaint, "Paint", FALSE );
6155 RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6156 check_update_rgn( hwnd, 0 );
6159 trace("testing InvalidateRgn(0, NULL, FALSE)\n");
6160 SetLastError(0xdeadbeef);
6161 ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
6162 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
6163 "wrong error code %d\n", GetLastError());
6164 check_update_rgn( hwnd, 0 );
6165 flush_events();
6166 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6168 trace("testing ValidateRgn(0, NULL)\n");
6169 SetLastError(0xdeadbeef);
6170 ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
6171 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
6172 broken( GetLastError() == 0xdeadbeef ) /* win9x */,
6173 "wrong error code %d\n", GetLastError());
6174 check_update_rgn( hwnd, 0 );
6175 flush_events();
6176 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6178 trace("testing UpdateWindow(NULL)\n");
6179 SetLastError(0xdeadbeef);
6180 ok(!UpdateWindow(NULL), "UpdateWindow(NULL) should fail\n");
6181 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
6182 broken( GetLastError() == 0xdeadbeef ) /* win9x */,
6183 "wrong error code %d\n", GetLastError());
6184 check_update_rgn( hwnd, 0 );
6185 flush_events();
6186 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6188 /* now with frame */
6189 SetRectRgn( hrgn, -5, -5, 20, 20 );
6191 /* flush pending messages */
6192 flush_events();
6193 flush_sequence();
6194 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6195 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
6197 SetRectRgn( hrgn, 0, 0, 20, 20 ); /* GetUpdateRgn clips to client area */
6198 check_update_rgn( hwnd, hrgn );
6200 flush_sequence();
6201 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
6202 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
6204 flush_sequence();
6205 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
6206 ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
6208 GetClientRect( hwnd, &rect );
6209 SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
6210 check_update_rgn( hwnd, hrgn );
6212 flush_sequence();
6213 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
6214 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6216 flush_sequence();
6217 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
6218 ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
6219 check_update_rgn( hwnd, 0 );
6221 flush_sequence();
6222 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
6223 ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
6224 check_update_rgn( hwnd, 0 );
6226 flush_sequence();
6227 SetRectRgn( hrgn, 0, 0, 100, 100 );
6228 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6229 SetRectRgn( hrgn, 0, 0, 50, 100 );
6230 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
6231 SetRectRgn( hrgn, 50, 0, 100, 100 );
6232 check_update_rgn( hwnd, hrgn );
6233 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
6234 ok_sequence( WmEmptySeq, "EmptySeq", FALSE ); /* must not generate messages, everything is valid */
6235 check_update_rgn( hwnd, 0 );
6237 flush_sequence();
6238 SetRectRgn( hrgn, 0, 0, 100, 100 );
6239 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
6240 SetRectRgn( hrgn, 0, 0, 100, 50 );
6241 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
6242 ok_sequence( WmErase, "Erase", FALSE );
6243 SetRectRgn( hrgn, 0, 50, 100, 100 );
6244 check_update_rgn( hwnd, hrgn );
6246 flush_sequence();
6247 SetRectRgn( hrgn, 0, 0, 100, 100 );
6248 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
6249 SetRectRgn( hrgn, 0, 0, 50, 50 );
6250 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
6251 ok_sequence( WmPaint, "Paint", FALSE );
6253 flush_sequence();
6254 SetRectRgn( hrgn, -4, -4, -2, -2 );
6255 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6256 SetRectRgn( hrgn, -200, -200, -198, -198 );
6257 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
6258 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
6260 flush_sequence();
6261 SetRectRgn( hrgn, -4, -4, -2, -2 );
6262 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6263 SetRectRgn( hrgn, -4, -4, -3, -3 );
6264 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
6265 SetRectRgn( hrgn, 0, 0, 1, 1 );
6266 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
6267 ok_sequence( WmPaint, "Paint", FALSE );
6269 flush_sequence();
6270 SetRectRgn( hrgn, -4, -4, -1, -1 );
6271 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6272 RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
6273 /* make sure no WM_PAINT was generated */
6274 flush_events();
6275 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
6277 flush_sequence();
6278 SetRectRgn( hrgn, -4, -4, -1, -1 );
6279 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6280 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
6282 if (msg.hwnd == hwnd && msg.message == WM_PAINT)
6284 /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
6285 INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
6286 ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
6287 ret = GetUpdateRect( hwnd, &rect, FALSE );
6288 ok( ret, "Invalid GetUpdateRect result %d\n", ret );
6289 /* this will send WM_NCPAINT and validate the non client area */
6290 ret = GetUpdateRect( hwnd, &rect, TRUE );
6291 ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
6293 DispatchMessage( &msg );
6295 ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
6297 DestroyWindow( hwnd );
6299 /* now test with a child window */
6301 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
6302 100, 100, 200, 200, 0, 0, 0, NULL);
6303 ok (hparent != 0, "Failed to create parent window\n");
6305 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
6306 10, 10, 100, 100, hparent, 0, 0, NULL);
6307 ok (hchild != 0, "Failed to create child window\n");
6309 ShowWindow( hparent, SW_SHOW );
6310 UpdateWindow( hparent );
6311 UpdateWindow( hchild );
6312 flush_events();
6313 flush_sequence();
6314 log_all_parent_messages++;
6316 SetRect( &rect, 0, 0, 50, 50 );
6317 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6318 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6319 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
6321 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6322 pt.x = pt.y = 0;
6323 MapWindowPoints( hchild, hparent, &pt, 1 );
6324 SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
6325 check_update_rgn( hchild, hrgn );
6326 SetRectRgn( hrgn, 0, 0, 50, 50 );
6327 check_update_rgn( hparent, hrgn );
6328 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6329 ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
6330 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6331 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6333 flush_events();
6334 ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
6336 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6337 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6338 ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
6339 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6340 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6342 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6343 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6344 ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
6346 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6347 flush_sequence();
6348 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6349 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6350 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
6352 /* flush all paint messages */
6353 flush_events();
6354 flush_sequence();
6356 /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
6357 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6358 SetRectRgn( hrgn, 0, 0, 50, 50 );
6359 check_update_rgn( hparent, hrgn );
6360 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6361 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6362 SetRectRgn( hrgn, 0, 0, 50, 50 );
6363 check_update_rgn( hparent, hrgn );
6365 /* flush all paint messages */
6366 flush_events();
6367 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6368 flush_sequence();
6370 /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
6371 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6372 SetRectRgn( hrgn, 0, 0, 50, 50 );
6373 check_update_rgn( hparent, hrgn );
6374 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6375 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6376 SetRectRgn( hrgn2, 10, 10, 50, 50 );
6377 CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
6378 check_update_rgn( hparent, hrgn );
6379 /* flush all paint messages */
6380 flush_events();
6381 flush_sequence();
6383 /* same as above but parent gets completely validated */
6384 SetRect( &rect, 20, 20, 30, 30 );
6385 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6386 SetRectRgn( hrgn, 20, 20, 30, 30 );
6387 check_update_rgn( hparent, hrgn );
6388 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6389 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6390 check_update_rgn( hparent, 0 ); /* no update region */
6391 flush_events();
6392 ok_sequence( WmEmptySeq, "WmEmpty", FALSE ); /* and no paint messages */
6394 /* make sure RDW_VALIDATE on child doesn't have the same effect */
6395 flush_sequence();
6396 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6397 SetRectRgn( hrgn, 20, 20, 30, 30 );
6398 check_update_rgn( hparent, hrgn );
6399 RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
6400 SetRectRgn( hrgn, 20, 20, 30, 30 );
6401 check_update_rgn( hparent, hrgn );
6403 /* same as above but normal WM_PAINT doesn't validate parent */
6404 flush_sequence();
6405 SetRect( &rect, 20, 20, 30, 30 );
6406 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6407 SetRectRgn( hrgn, 20, 20, 30, 30 );
6408 check_update_rgn( hparent, hrgn );
6409 /* no WM_PAINT in child while parent still pending */
6410 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6411 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6412 while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6413 ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
6415 flush_sequence();
6416 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6417 /* no WM_PAINT in child while parent still pending */
6418 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6419 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6420 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
6421 /* now that parent is valid child should get WM_PAINT */
6422 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6423 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6424 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6425 ok_sequence( WmEmptySeq, "No other message", FALSE );
6427 /* same thing with WS_CLIPCHILDREN in parent */
6428 flush_sequence();
6429 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6430 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6431 /* changing style invalidates non client area, but we need to invalidate something else to see it */
6432 RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
6433 ok_sequence( WmEmptySeq, "No message", FALSE );
6434 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
6435 ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
6437 flush_sequence();
6438 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
6439 SetRectRgn( hrgn, 20, 20, 30, 30 );
6440 check_update_rgn( hparent, hrgn );
6441 /* no WM_PAINT in child while parent still pending */
6442 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6443 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6444 /* WM_PAINT in parent first */
6445 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6446 ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
6448 /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
6449 flush_sequence();
6450 SetRect( &rect, 0, 0, 30, 30 );
6451 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
6452 SetRectRgn( hrgn, 0, 0, 30, 30 );
6453 check_update_rgn( hparent, hrgn );
6454 flush_events();
6455 ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
6457 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6458 flush_sequence();
6459 SetRect( &rect, -10, 0, 30, 30 );
6460 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6461 SetRect( &rect, 0, 0, 20, 20 );
6462 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6463 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6464 ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
6466 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6467 flush_sequence();
6468 SetRect( &rect, -10, 0, 30, 30 );
6469 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6470 SetRect( &rect, 0, 0, 100, 100 );
6471 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6472 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6473 ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
6474 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6475 ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
6477 /* test RDW_INTERNALPAINT behavior */
6479 flush_sequence();
6480 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
6481 flush_events();
6482 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6484 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
6485 flush_events();
6486 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6488 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6489 flush_events();
6490 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6492 assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
6493 UpdateWindow( hparent );
6494 flush_events();
6495 flush_sequence();
6496 trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
6497 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6498 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6499 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6500 flush_events();
6501 ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
6503 UpdateWindow( hparent );
6504 flush_events();
6505 flush_sequence();
6506 trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
6507 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6508 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6509 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6510 flush_events();
6511 ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6513 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6514 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6515 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6516 flush_events();
6517 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6519 assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
6520 UpdateWindow( hparent );
6521 flush_events();
6522 flush_sequence();
6523 trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
6524 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6525 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6526 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6527 flush_events();
6528 ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
6530 UpdateWindow( hparent );
6531 flush_events();
6532 flush_sequence();
6533 trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
6534 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6535 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6536 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6537 flush_events();
6538 ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6540 ok(GetWindowLong( hparent, GWL_STYLE ) & WS_VISIBLE, "parent should be visible\n");
6541 ok(GetWindowLong( hchild, GWL_STYLE ) & WS_VISIBLE, "child should be visible\n");
6543 UpdateWindow( hparent );
6544 flush_events();
6545 flush_sequence();
6546 trace("testing SetWindowPos(-10000, -10000) on child\n");
6547 SetWindowPos( hchild, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6548 check_update_rgn( hchild, 0 );
6549 flush_events();
6551 #if 0 /* this one doesn't pass under Wine yet */
6552 UpdateWindow( hparent );
6553 flush_events();
6554 flush_sequence();
6555 trace("testing ShowWindow(SW_MINIMIZE) on child\n");
6556 ShowWindow( hchild, SW_MINIMIZE );
6557 check_update_rgn( hchild, 0 );
6558 flush_events();
6559 #endif
6561 UpdateWindow( hparent );
6562 flush_events();
6563 flush_sequence();
6564 trace("testing SetWindowPos(-10000, -10000) on parent\n");
6565 SetWindowPos( hparent, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6566 check_update_rgn( hparent, 0 );
6567 flush_events();
6569 log_all_parent_messages--;
6570 DestroyWindow( hparent );
6571 ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6573 /* tests for moving windows off-screen (needs simple WS_POPUP windows) */
6575 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_POPUP | WS_VISIBLE,
6576 100, 100, 200, 200, 0, 0, 0, NULL);
6577 ok (hparent != 0, "Failed to create parent window\n");
6579 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
6580 10, 10, 100, 100, hparent, 0, 0, NULL);
6581 ok (hchild != 0, "Failed to create child window\n");
6583 ShowWindow( hparent, SW_SHOW );
6584 UpdateWindow( hparent );
6585 UpdateWindow( hchild );
6586 flush_events();
6587 flush_sequence();
6589 /* moving child outside of parent boundaries changes update region */
6590 SetRect( &rect, 0, 0, 40, 40 );
6591 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6592 SetRectRgn( hrgn, 0, 0, 40, 40 );
6593 check_update_rgn( hchild, hrgn );
6594 MoveWindow( hchild, -10, 10, 100, 100, FALSE );
6595 SetRectRgn( hrgn, 10, 0, 40, 40 );
6596 check_update_rgn( hchild, hrgn );
6597 MoveWindow( hchild, -10, -10, 100, 100, FALSE );
6598 SetRectRgn( hrgn, 10, 10, 40, 40 );
6599 check_update_rgn( hchild, hrgn );
6601 /* moving parent off-screen does too */
6602 SetRect( &rect, 0, 0, 100, 100 );
6603 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
6604 SetRectRgn( hrgn, 0, 0, 100, 100 );
6605 check_update_rgn( hparent, hrgn );
6606 SetRectRgn( hrgn, 10, 10, 40, 40 );
6607 check_update_rgn( hchild, hrgn );
6608 MoveWindow( hparent, -20, -20, 200, 200, FALSE );
6609 SetRectRgn( hrgn, 20, 20, 100, 100 );
6610 check_update_rgn( hparent, hrgn );
6611 SetRectRgn( hrgn, 30, 30, 40, 40 );
6612 check_update_rgn( hchild, hrgn );
6614 /* invalidated region is cropped by the parent rects */
6615 SetRect( &rect, 0, 0, 50, 50 );
6616 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6617 SetRectRgn( hrgn, 30, 30, 50, 50 );
6618 check_update_rgn( hchild, hrgn );
6620 DestroyWindow( hparent );
6621 ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6622 flush_sequence();
6624 DeleteObject( hrgn );
6625 DeleteObject( hrgn2 );
6628 struct wnd_event
6630 HWND hwnd;
6631 HANDLE grand_child;
6632 HANDLE start_event;
6633 HANDLE stop_event;
6636 static DWORD WINAPI thread_proc(void *param)
6638 MSG msg;
6639 struct wnd_event *wnd_event = param;
6641 wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
6642 100, 100, 200, 200, 0, 0, 0, NULL);
6643 ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
6645 SetEvent(wnd_event->start_event);
6647 while (GetMessage(&msg, 0, 0, 0))
6649 TranslateMessage(&msg);
6650 DispatchMessage(&msg);
6653 ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
6655 return 0;
6658 static DWORD CALLBACK create_grand_child_thread( void *param )
6660 struct wnd_event *wnd_event = param;
6661 HWND hchild;
6662 MSG msg;
6664 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
6665 WS_CHILD | WS_VISIBLE, 0, 0, 10, 10, wnd_event->hwnd, 0, 0, NULL);
6666 ok (hchild != 0, "Failed to create child window\n");
6667 flush_events();
6668 flush_sequence();
6669 SetEvent( wnd_event->start_event );
6671 for (;;)
6673 MsgWaitForMultipleObjects(0, NULL, FALSE, 1000, QS_ALLINPUT);
6674 if (!IsWindow( hchild )) break; /* will be destroyed when parent thread exits */
6675 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6677 return 0;
6680 static DWORD CALLBACK create_child_thread( void *param )
6682 struct wnd_event *wnd_event = param;
6683 struct wnd_event child_event;
6684 DWORD ret, tid;
6685 MSG msg;
6687 child_event.hwnd = CreateWindowExA(0, "TestWindowClass", "Test child",
6688 WS_CHILD | WS_VISIBLE, 0, 0, 10, 10, wnd_event->hwnd, 0, 0, NULL);
6689 ok (child_event.hwnd != 0, "Failed to create child window\n");
6690 SetFocus( child_event.hwnd );
6691 flush_events();
6692 flush_sequence();
6693 child_event.start_event = wnd_event->start_event;
6694 wnd_event->grand_child = CreateThread(NULL, 0, create_grand_child_thread, &child_event, 0, &tid);
6695 for (;;)
6697 DWORD ret = MsgWaitForMultipleObjects(1, &child_event.start_event, FALSE, 1000, QS_SENDMESSAGE);
6698 if (ret != 1) break;
6699 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6701 ret = WaitForSingleObject( wnd_event->stop_event, 5000 );
6702 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6703 return 0;
6706 static void test_interthread_messages(void)
6708 HANDLE hThread;
6709 DWORD tid;
6710 WNDPROC proc;
6711 MSG msg;
6712 char buf[256];
6713 int len, expected_len;
6714 struct wnd_event wnd_event;
6715 BOOL ret;
6717 wnd_event.start_event = CreateEventW(NULL, 0, 0, NULL);
6718 if (!wnd_event.start_event)
6720 win_skip("skipping interthread message test under win9x\n");
6721 return;
6724 hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
6725 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
6727 ok(WaitForSingleObject(wnd_event.start_event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6729 CloseHandle(wnd_event.start_event);
6731 SetLastError(0xdeadbeef);
6732 ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeeded\n");
6733 ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
6734 "wrong error code %d\n", GetLastError());
6736 proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6737 ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
6739 expected_len = lstrlenA("window caption text");
6740 memset(buf, 0, sizeof(buf));
6741 SetLastError(0xdeadbeef);
6742 len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
6743 ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
6744 ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
6746 msg.hwnd = wnd_event.hwnd;
6747 msg.message = WM_GETTEXT;
6748 msg.wParam = sizeof(buf);
6749 msg.lParam = (LPARAM)buf;
6750 memset(buf, 0, sizeof(buf));
6751 SetLastError(0xdeadbeef);
6752 len = DispatchMessageA(&msg);
6753 ok((!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY) || broken(len), /* nt4 */
6754 "DispatchMessageA(WM_GETTEXT) succeeded on another thread window: ret %d, error %d\n", len, GetLastError());
6756 /* the following test causes an exception in user.exe under win9x */
6757 msg.hwnd = wnd_event.hwnd;
6758 msg.message = WM_TIMER;
6759 msg.wParam = 0;
6760 msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6761 SetLastError(0xdeadbeef);
6762 len = DispatchMessageA(&msg);
6763 ok(!len && GetLastError() == 0xdeadbeef,
6764 "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
6766 ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
6767 ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
6769 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6770 CloseHandle(hThread);
6772 ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
6774 wnd_event.hwnd = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6775 100, 100, 200, 200, 0, 0, 0, NULL);
6776 ok (wnd_event.hwnd != 0, "Failed to create parent window\n");
6777 flush_sequence();
6778 log_all_parent_messages++;
6779 wnd_event.start_event = CreateEventA( NULL, TRUE, FALSE, NULL );
6780 wnd_event.stop_event = CreateEventA( NULL, TRUE, FALSE, NULL );
6781 hThread = CreateThread( NULL, 0, create_child_thread, &wnd_event, 0, &tid );
6782 for (;;)
6784 ret = MsgWaitForMultipleObjects(1, &wnd_event.start_event, FALSE, 1000, QS_SENDMESSAGE);
6785 if (ret != 1) break;
6786 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6788 ok( !ret, "MsgWaitForMultipleObjects failed %x\n", ret );
6789 /* now wait for the thread without processing messages; this shouldn't deadlock */
6790 SetEvent( wnd_event.stop_event );
6791 ret = WaitForSingleObject( hThread, 5000 );
6792 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6793 CloseHandle( hThread );
6795 ret = WaitForSingleObject( wnd_event.grand_child, 5000 );
6796 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6797 CloseHandle( wnd_event.grand_child );
6799 CloseHandle( wnd_event.start_event );
6800 CloseHandle( wnd_event.stop_event );
6801 flush_events();
6802 ok_sequence(WmExitThreadSeq, "destroy child on thread exit", FALSE);
6803 log_all_parent_messages--;
6804 DestroyWindow( wnd_event.hwnd );
6808 static const struct message WmVkN[] = {
6809 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6810 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6811 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6812 { WM_CHAR, wparam|lparam, 'n', 1 },
6813 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
6814 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6815 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6816 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6817 { 0 }
6819 static const struct message WmShiftVkN[] = {
6820 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6821 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6822 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6823 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6824 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6825 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6826 { WM_CHAR, wparam|lparam, 'N', 1 },
6827 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
6828 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6829 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6830 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6831 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6832 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6833 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6834 { 0 }
6836 static const struct message WmCtrlVkN[] = {
6837 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6838 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6839 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6840 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6841 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6842 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6843 { WM_CHAR, wparam|lparam, 0x000e, 1 },
6844 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6845 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6846 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6847 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6848 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6849 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6850 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6851 { 0 }
6853 static const struct message WmCtrlVkN_2[] = {
6854 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6855 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6856 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6857 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6858 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6859 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6860 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6861 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6862 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6863 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6864 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6865 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6866 { 0 }
6868 static const struct message WmAltVkN[] = {
6869 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6870 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6871 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6872 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6873 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6874 { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6875 { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
6876 { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
6877 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
6878 { HCBT_SYSCOMMAND, hook },
6879 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6880 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6881 { 0x00AE, sent|defwinproc|optional }, /* XP */
6882 { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
6883 { WM_INITMENU, sent|defwinproc },
6884 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6885 { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
6886 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
6887 { WM_CAPTURECHANGED, sent|defwinproc },
6888 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
6889 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6890 { WM_EXITMENULOOP, sent|defwinproc },
6891 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
6892 { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
6893 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6894 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6895 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6896 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6897 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6898 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6899 { 0 }
6901 static const struct message WmAltVkN_2[] = {
6902 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6903 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6904 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6905 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6906 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6907 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
6908 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6909 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6910 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6911 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6912 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6913 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6914 { 0 }
6916 static const struct message WmCtrlAltVkN[] = {
6917 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6918 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6919 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6920 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6921 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6922 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6923 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6924 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6925 { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6926 { WM_CHAR, optional },
6927 { WM_CHAR, sent|optional },
6928 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6929 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6930 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6931 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6932 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6933 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6934 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6935 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6936 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6937 { 0 }
6939 static const struct message WmCtrlShiftVkN[] = {
6940 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6941 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6942 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6943 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6944 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6945 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6946 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6947 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6948 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
6949 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6950 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6951 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6952 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6953 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6954 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6955 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6956 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6957 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6958 { 0 }
6960 static const struct message WmCtrlAltShiftVkN[] = {
6961 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6962 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6963 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6964 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6965 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6966 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6967 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
6968 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
6969 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
6970 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6971 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6972 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
6973 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6974 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6975 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6976 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
6977 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
6978 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
6979 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6980 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6981 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6982 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6983 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6984 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6985 { 0 }
6987 static const struct message WmAltPressRelease[] = {
6988 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6989 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6990 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6991 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6992 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6993 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6994 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
6995 { HCBT_SYSCOMMAND, hook },
6996 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6997 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6998 { WM_INITMENU, sent|defwinproc },
6999 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7000 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
7001 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7003 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
7005 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7006 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
7007 { WM_CAPTURECHANGED, sent|defwinproc },
7008 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
7009 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7010 { WM_EXITMENULOOP, sent|defwinproc },
7011 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
7012 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
7013 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
7014 { 0 }
7016 static const struct message WmShiftMouseButton[] = {
7017 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
7018 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
7019 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
7020 { WM_MOUSEMOVE, wparam|optional, 0, 0 },
7021 { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
7022 { WM_LBUTTONDOWN, wparam, MK_LBUTTON|MK_SHIFT, 0 },
7023 { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON|MK_SHIFT, 0 },
7024 { WM_LBUTTONUP, wparam, MK_SHIFT, 0 },
7025 { WM_LBUTTONUP, sent|wparam, MK_SHIFT, 0 },
7026 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
7027 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
7028 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
7029 { 0 }
7031 static const struct message WmF1Seq[] = {
7032 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
7033 { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
7034 { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
7035 { WM_KEYF1, wparam|lparam, 0, 0 },
7036 { WM_KEYF1, sent|wparam|lparam, 0, 0 },
7037 { WM_HELP, sent|defwinproc },
7038 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
7039 { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
7040 { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
7041 { 0 }
7043 static const struct message WmVkAppsSeq[] = {
7044 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
7045 { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
7046 { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
7047 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
7048 { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
7049 { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
7050 { WM_CONTEXTMENU, lparam, /*hwnd*/0, -1 },
7051 { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, -1 },
7052 { 0 }
7054 static const struct message WmVkF10Seq[] = {
7055 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7056 { WM_SYSKEYDOWN, wparam|lparam, VK_F10, 1 },
7057 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_F10, 0x00000001 },
7058 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7059 { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7060 { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7061 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_KEYMENU },
7062 { HCBT_SYSCOMMAND, hook },
7063 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7064 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7065 { WM_INITMENU, sent|defwinproc },
7066 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7067 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
7068 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7070 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0x10000001 }, /* XP */
7072 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7073 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7074 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
7075 { WM_CAPTURECHANGED, sent|defwinproc },
7076 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
7077 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7078 { WM_EXITMENULOOP, sent|defwinproc },
7079 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7080 { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7081 { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7082 { 0 }
7084 static const struct message WmShiftF10Seq[] = {
7085 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
7086 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
7087 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x00000001 },
7088 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7089 { WM_SYSKEYDOWN, wparam|lparam, VK_F10, 1 },
7090 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_F10, 0x00000001 },
7091 { WM_CONTEXTMENU, sent|defwinproc|lparam, /*hwnd*/0, -1 },
7092 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7093 { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7094 { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7095 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_KEYMENU },
7096 { HCBT_SYSCOMMAND, hook },
7097 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7098 { WM_INITMENU, sent|defwinproc },
7099 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
7100 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xd0000001 }, /* XP */
7101 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0x10000001 }, /* XP */
7102 { WM_CAPTURECHANGED, sent|defwinproc|wparam|lparam, 0, 0 },
7103 { WM_MENUSELECT, sent|defwinproc|wparam|lparam, 0xffff0000, 0 },
7104 { WM_EXITMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7105 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0xc0000001 }, /* XP */
7106 { WM_KEYUP, wparam|lparam, VK_ESCAPE, 0xc0000001 },
7107 { WM_KEYUP, sent|wparam|lparam, VK_ESCAPE, 0xc0000001 },
7108 { 0 }
7111 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
7113 MSG msg;
7115 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
7117 struct recvd_message log_msg;
7119 /* ignore some unwanted messages */
7120 if (msg.message == WM_MOUSEMOVE ||
7121 msg.message == WM_TIMER ||
7122 ignore_message( msg.message ))
7123 continue;
7125 log_msg.hwnd = msg.hwnd;
7126 log_msg.message = msg.message;
7127 log_msg.flags = wparam|lparam;
7128 log_msg.wParam = msg.wParam;
7129 log_msg.lParam = msg.lParam;
7130 log_msg.descr = "accel";
7131 add_message(&log_msg);
7133 if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
7135 TranslateMessage(&msg);
7136 DispatchMessage(&msg);
7141 static void test_accelerators(void)
7143 RECT rc;
7144 POINT pt;
7145 SHORT state;
7146 HACCEL hAccel;
7147 HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7148 100, 100, 200, 200, 0, 0, 0, NULL);
7149 BOOL ret;
7151 assert(hwnd != 0);
7152 UpdateWindow(hwnd);
7153 flush_events();
7154 flush_sequence();
7156 SetFocus(hwnd);
7157 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
7159 state = GetKeyState(VK_SHIFT);
7160 ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
7161 state = GetKeyState(VK_CAPITAL);
7162 ok(state == 0, "wrong CapsLock state %04x\n", state);
7164 hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
7165 assert(hAccel != 0);
7167 flush_events();
7168 pump_msg_loop(hwnd, 0);
7169 flush_sequence();
7171 trace("testing VK_N press/release\n");
7172 flush_sequence();
7173 keybd_event('N', 0, 0, 0);
7174 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7175 pump_msg_loop(hwnd, hAccel);
7176 if (!sequence_cnt) /* we didn't get any message */
7178 skip( "queuing key events not supported\n" );
7179 goto done;
7181 ok_sequence(WmVkN, "VK_N press/release", FALSE);
7183 trace("testing Shift+VK_N press/release\n");
7184 flush_sequence();
7185 keybd_event(VK_SHIFT, 0, 0, 0);
7186 keybd_event('N', 0, 0, 0);
7187 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7188 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7189 pump_msg_loop(hwnd, hAccel);
7190 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
7192 trace("testing Ctrl+VK_N press/release\n");
7193 flush_sequence();
7194 keybd_event(VK_CONTROL, 0, 0, 0);
7195 keybd_event('N', 0, 0, 0);
7196 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7197 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7198 pump_msg_loop(hwnd, hAccel);
7199 ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
7201 trace("testing Alt+VK_N press/release\n");
7202 flush_sequence();
7203 keybd_event(VK_MENU, 0, 0, 0);
7204 keybd_event('N', 0, 0, 0);
7205 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7206 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7207 pump_msg_loop(hwnd, hAccel);
7208 ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
7210 trace("testing Ctrl+Alt+VK_N press/release 1\n");
7211 flush_sequence();
7212 keybd_event(VK_CONTROL, 0, 0, 0);
7213 keybd_event(VK_MENU, 0, 0, 0);
7214 keybd_event('N', 0, 0, 0);
7215 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7216 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7217 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7218 pump_msg_loop(hwnd, hAccel);
7219 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
7221 ret = DestroyAcceleratorTable(hAccel);
7222 ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7224 hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
7225 assert(hAccel != 0);
7227 trace("testing VK_N press/release\n");
7228 flush_sequence();
7229 keybd_event('N', 0, 0, 0);
7230 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7231 pump_msg_loop(hwnd, hAccel);
7232 ok_sequence(WmVkN, "VK_N press/release", FALSE);
7234 trace("testing Shift+VK_N press/release\n");
7235 flush_sequence();
7236 keybd_event(VK_SHIFT, 0, 0, 0);
7237 keybd_event('N', 0, 0, 0);
7238 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7239 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7240 pump_msg_loop(hwnd, hAccel);
7241 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
7243 trace("testing Ctrl+VK_N press/release 2\n");
7244 flush_sequence();
7245 keybd_event(VK_CONTROL, 0, 0, 0);
7246 keybd_event('N', 0, 0, 0);
7247 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7248 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7249 pump_msg_loop(hwnd, hAccel);
7250 ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
7252 trace("testing Alt+VK_N press/release 2\n");
7253 flush_sequence();
7254 keybd_event(VK_MENU, 0, 0, 0);
7255 keybd_event('N', 0, 0, 0);
7256 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7257 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7258 pump_msg_loop(hwnd, hAccel);
7259 ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
7261 trace("testing Ctrl+Alt+VK_N press/release 2\n");
7262 flush_sequence();
7263 keybd_event(VK_CONTROL, 0, 0, 0);
7264 keybd_event(VK_MENU, 0, 0, 0);
7265 keybd_event('N', 0, 0, 0);
7266 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7267 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7268 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7269 pump_msg_loop(hwnd, hAccel);
7270 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
7272 trace("testing Ctrl+Shift+VK_N press/release\n");
7273 flush_sequence();
7274 keybd_event(VK_CONTROL, 0, 0, 0);
7275 keybd_event(VK_SHIFT, 0, 0, 0);
7276 keybd_event('N', 0, 0, 0);
7277 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7278 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7279 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7280 pump_msg_loop(hwnd, hAccel);
7281 ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
7283 trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
7284 flush_sequence();
7285 keybd_event(VK_CONTROL, 0, 0, 0);
7286 keybd_event(VK_MENU, 0, 0, 0);
7287 keybd_event(VK_SHIFT, 0, 0, 0);
7288 keybd_event('N', 0, 0, 0);
7289 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7290 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7291 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7292 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7293 pump_msg_loop(hwnd, hAccel);
7294 ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
7296 ret = DestroyAcceleratorTable(hAccel);
7297 ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7298 hAccel = 0;
7300 trace("testing Alt press/release\n");
7301 flush_sequence();
7302 keybd_event(VK_MENU, 0, 0, 0);
7303 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7304 keybd_event(VK_MENU, 0, 0, 0);
7305 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7306 pump_msg_loop(hwnd, 0);
7307 /* this test doesn't pass in Wine for managed windows */
7308 ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
7310 trace("testing VK_F1 press/release\n");
7311 keybd_event(VK_F1, 0, 0, 0);
7312 keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
7313 pump_msg_loop(hwnd, 0);
7314 ok_sequence(WmF1Seq, "F1 press/release", FALSE);
7316 trace("testing VK_APPS press/release\n");
7317 keybd_event(VK_APPS, 0, 0, 0);
7318 keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
7319 pump_msg_loop(hwnd, 0);
7320 ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
7322 trace("testing VK_F10 press/release\n");
7323 keybd_event(VK_F10, 0, 0, 0);
7324 keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7325 keybd_event(VK_F10, 0, 0, 0);
7326 keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7327 pump_msg_loop(hwnd, 0);
7328 ok_sequence(WmVkF10Seq, "VK_F10 press/release", TRUE);
7330 trace("testing SHIFT+F10 press/release\n");
7331 keybd_event(VK_SHIFT, 0, 0, 0);
7332 keybd_event(VK_F10, 0, 0, 0);
7333 keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7334 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7335 keybd_event(VK_ESCAPE, 0, 0, 0);
7336 keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0);
7337 pump_msg_loop(hwnd, 0);
7338 ok_sequence(WmShiftF10Seq, "SHIFT+F10 press/release", TRUE);
7340 trace("testing Shift+MouseButton press/release\n");
7341 /* first, move mouse pointer inside of the window client area */
7342 GetClientRect(hwnd, &rc);
7343 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
7344 rc.left += (rc.right - rc.left)/2;
7345 rc.top += (rc.bottom - rc.top)/2;
7346 SetCursorPos(rc.left, rc.top);
7347 SetActiveWindow(hwnd);
7349 flush_events();
7350 flush_sequence();
7351 GetCursorPos(&pt);
7352 if (pt.x == rc.left && pt.y == rc.top)
7354 int i;
7355 keybd_event(VK_SHIFT, 0, 0, 0);
7356 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
7357 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7358 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7359 pump_msg_loop(hwnd, 0);
7360 for (i = 0; i < sequence_cnt; i++) if (sequence[i].message == WM_LBUTTONDOWN) break;
7361 if (i < sequence_cnt)
7362 ok_sequence(WmShiftMouseButton, "Shift+MouseButton press/release", FALSE);
7363 else
7364 skip( "Shift+MouseButton event didn't get to the window\n" );
7367 done:
7368 if (hAccel) DestroyAcceleratorTable(hAccel);
7369 DestroyWindow(hwnd);
7372 /************* window procedures ********************/
7374 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message,
7375 WPARAM wParam, LPARAM lParam)
7377 static LONG defwndproc_counter = 0;
7378 static LONG beginpaint_counter = 0;
7379 LRESULT ret;
7380 struct recvd_message msg;
7382 if (ignore_message( message )) return 0;
7384 switch (message)
7386 case WM_ENABLE:
7388 LONG style = GetWindowLongA(hwnd, GWL_STYLE);
7389 ok((BOOL)wParam == !(style & WS_DISABLED),
7390 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
7391 break;
7394 case WM_CAPTURECHANGED:
7395 if (test_DestroyWindow_flag)
7397 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7398 if (style & WS_CHILD)
7399 lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7400 else if (style & WS_POPUP)
7401 lParam = WND_POPUP_ID;
7402 else
7403 lParam = WND_PARENT_ID;
7405 break;
7407 case WM_NCDESTROY:
7409 HWND capture;
7411 ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
7412 capture = GetCapture();
7413 if (capture)
7415 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
7416 trace("current capture %p, releasing...\n", capture);
7417 ReleaseCapture();
7420 /* fall through */
7421 case WM_DESTROY:
7422 if (pGetAncestor)
7423 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
7424 if (test_DestroyWindow_flag)
7426 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7427 if (style & WS_CHILD)
7428 lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7429 else if (style & WS_POPUP)
7430 lParam = WND_POPUP_ID;
7431 else
7432 lParam = WND_PARENT_ID;
7434 break;
7436 /* test_accelerators() depends on this */
7437 case WM_NCHITTEST:
7438 return HTCLIENT;
7440 /* ignore */
7441 case WM_MOUSEMOVE:
7442 case WM_MOUSEACTIVATE:
7443 case WM_NCMOUSEMOVE:
7444 case WM_SETCURSOR:
7445 case WM_IME_SELECT:
7446 return 0;
7449 msg.hwnd = hwnd;
7450 msg.message = message;
7451 msg.flags = sent|wparam|lparam;
7452 if (defwndproc_counter) msg.flags |= defwinproc;
7453 if (beginpaint_counter) msg.flags |= beginpaint;
7454 msg.wParam = wParam;
7455 msg.lParam = lParam;
7456 msg.descr = "MsgCheckProc";
7457 add_message(&msg);
7459 if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
7461 HWND parent = GetParent(hwnd);
7462 RECT rc;
7463 MINMAXINFO *minmax = (MINMAXINFO *)lParam;
7465 GetClientRect(parent, &rc);
7466 trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
7467 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
7468 minmax->ptReserved.x, minmax->ptReserved.y,
7469 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
7470 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
7471 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
7472 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
7474 ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
7475 minmax->ptMaxSize.x, rc.right);
7476 ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
7477 minmax->ptMaxSize.y, rc.bottom);
7480 if (message == WM_PAINT)
7482 PAINTSTRUCT ps;
7483 beginpaint_counter++;
7484 BeginPaint( hwnd, &ps );
7485 beginpaint_counter--;
7486 EndPaint( hwnd, &ps );
7487 return 0;
7490 defwndproc_counter++;
7491 ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam)
7492 : DefWindowProcA(hwnd, message, wParam, lParam);
7493 defwndproc_counter--;
7495 return ret;
7498 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7500 return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
7503 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7505 return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
7508 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7510 static LONG defwndproc_counter = 0;
7511 LRESULT ret;
7512 struct recvd_message msg;
7514 if (ignore_message( message )) return 0;
7516 switch (message)
7518 case WM_QUERYENDSESSION:
7519 case WM_ENDSESSION:
7520 lParam &= ~0x01; /* Vista adds a 0x01 flag */
7521 break;
7524 msg.hwnd = hwnd;
7525 msg.message = message;
7526 msg.flags = sent|wparam|lparam;
7527 if (defwndproc_counter) msg.flags |= defwinproc;
7528 msg.wParam = wParam;
7529 msg.lParam = lParam;
7530 msg.descr = "popup";
7531 add_message(&msg);
7533 if (message == WM_CREATE)
7535 DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
7536 SetWindowLongA(hwnd, GWL_STYLE, style);
7539 defwndproc_counter++;
7540 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7541 defwndproc_counter--;
7543 return ret;
7546 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7548 static LONG defwndproc_counter = 0;
7549 static LONG beginpaint_counter = 0;
7550 LRESULT ret;
7551 struct recvd_message msg;
7553 if (ignore_message( message )) return 0;
7555 if (log_all_parent_messages ||
7556 message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
7557 message == WM_SETFOCUS || message == WM_KILLFOCUS ||
7558 message == WM_ENABLE || message == WM_ENTERIDLE ||
7559 message == WM_DRAWITEM || message == WM_COMMAND ||
7560 message == WM_IME_SETCONTEXT)
7562 switch (message)
7564 /* ignore */
7565 case WM_NCHITTEST:
7566 return HTCLIENT;
7567 case WM_SETCURSOR:
7568 case WM_MOUSEMOVE:
7569 case WM_NCMOUSEMOVE:
7570 return 0;
7572 case WM_ERASEBKGND:
7574 RECT rc;
7575 INT ret = GetClipBox((HDC)wParam, &rc);
7577 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
7578 ret, rc.left, rc.top, rc.right, rc.bottom);
7579 break;
7583 msg.hwnd = hwnd;
7584 msg.message = message;
7585 msg.flags = sent|parent|wparam|lparam;
7586 if (defwndproc_counter) msg.flags |= defwinproc;
7587 if (beginpaint_counter) msg.flags |= beginpaint;
7588 msg.wParam = wParam;
7589 msg.lParam = lParam;
7590 msg.descr = "parent";
7591 add_message(&msg);
7594 if (message == WM_PAINT)
7596 PAINTSTRUCT ps;
7597 beginpaint_counter++;
7598 BeginPaint( hwnd, &ps );
7599 beginpaint_counter--;
7600 EndPaint( hwnd, &ps );
7601 return 0;
7604 defwndproc_counter++;
7605 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7606 defwndproc_counter--;
7608 return ret;
7611 static INT_PTR CALLBACK StopQuitMsgCheckProcA(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
7613 if (message == WM_CREATE)
7614 PostMessage(hwnd, WM_CLOSE, 0, 0);
7615 else if (message == WM_CLOSE)
7617 /* Only the first WM_QUIT will survive the window destruction */
7618 PostMessage(hwnd, WM_USER, 0x1234, 0x5678);
7619 PostMessage(hwnd, WM_QUIT, 0x1234, 0x5678);
7620 PostMessage(hwnd, WM_QUIT, 0x4321, 0x8765);
7623 return DefWindowProcA(hwnd, message, wp, lp);
7626 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7628 static LONG defwndproc_counter = 0;
7629 LRESULT ret;
7630 struct recvd_message msg;
7632 if (ignore_message( message )) return 0;
7634 if (test_def_id)
7636 DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
7637 ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
7638 if (after_end_dialog)
7639 ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
7640 else
7641 ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
7644 msg.hwnd = hwnd;
7645 msg.message = message;
7646 msg.flags = sent|wparam|lparam;
7647 if (defwndproc_counter) msg.flags |= defwinproc;
7648 msg.wParam = wParam;
7649 msg.lParam = lParam;
7650 msg.descr = "dialog";
7651 add_message(&msg);
7653 defwndproc_counter++;
7654 ret = DefDlgProcA(hwnd, message, wParam, lParam);
7655 defwndproc_counter--;
7657 return ret;
7660 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7662 static LONG defwndproc_counter = 0;
7663 LRESULT ret;
7664 struct recvd_message msg;
7666 /* log only specific messages we are interested in */
7667 switch (message)
7669 #if 0 /* probably log these as well */
7670 case WM_ACTIVATE:
7671 case WM_SETFOCUS:
7672 case WM_KILLFOCUS:
7673 #endif
7674 case WM_SHOWWINDOW:
7675 case WM_SIZE:
7676 case WM_MOVE:
7677 case WM_GETMINMAXINFO:
7678 case WM_WINDOWPOSCHANGING:
7679 case WM_WINDOWPOSCHANGED:
7680 break;
7682 default: /* ignore */
7683 /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
7684 return DefWindowProcA(hwnd, message, wParam, lParam);
7687 msg.hwnd = hwnd;
7688 msg.message = message;
7689 msg.flags = sent|wparam|lparam;
7690 if (defwndproc_counter) msg.flags |= defwinproc;
7691 msg.wParam = wParam;
7692 msg.lParam = lParam;
7693 msg.descr = "show";
7694 add_message(&msg);
7696 defwndproc_counter++;
7697 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7698 defwndproc_counter--;
7700 return ret;
7703 static LRESULT WINAPI PaintLoopProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
7705 switch (msg)
7707 case WM_CREATE: return 0;
7708 case WM_PAINT:
7710 MSG msg2;
7711 static int i = 0;
7713 if (i < 256)
7715 i++;
7716 if (PeekMessageA(&msg2, 0, 0, 0, 1))
7718 TranslateMessage(&msg2);
7719 DispatchMessage(&msg2);
7721 i--;
7723 else ok(broken(1), "infinite loop\n");
7724 if ( i == 0)
7725 paint_loop_done = 1;
7726 return DefWindowProcA(hWnd,msg,wParam,lParam);
7729 return DefWindowProcA(hWnd,msg,wParam,lParam);
7732 static LRESULT WINAPI HotkeyMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7734 static LONG defwndproc_counter = 0;
7735 LRESULT ret;
7736 struct recvd_message msg;
7737 DWORD queue_status;
7739 if (ignore_message( message )) return 0;
7741 if ((message >= WM_KEYFIRST && message <= WM_KEYLAST) ||
7742 message == WM_HOTKEY || message >= WM_APP)
7744 msg.hwnd = hwnd;
7745 msg.message = message;
7746 msg.flags = sent|wparam|lparam;
7747 if (defwndproc_counter) msg.flags |= defwinproc;
7748 msg.wParam = wParam;
7749 msg.lParam = lParam;
7750 msg.descr = "HotkeyMsgCheckProcA";
7751 add_message(&msg);
7754 defwndproc_counter++;
7755 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7756 defwndproc_counter--;
7758 if (message == WM_APP)
7760 queue_status = GetQueueStatus(QS_HOTKEY);
7761 ok((queue_status & (QS_HOTKEY << 16)) == QS_HOTKEY << 16, "expected QS_HOTKEY << 16 set, got %x\n", queue_status);
7762 queue_status = GetQueueStatus(QS_POSTMESSAGE);
7763 ok((queue_status & (QS_POSTMESSAGE << 16)) == QS_POSTMESSAGE << 16, "expected QS_POSTMESSAGE << 16 set, got %x\n", queue_status);
7764 PostMessageA(hwnd, WM_APP+1, 0, 0);
7766 else if (message == WM_APP+1)
7768 queue_status = GetQueueStatus(QS_HOTKEY);
7769 ok((queue_status & (QS_HOTKEY << 16)) == 0, "expected QS_HOTKEY << 16 cleared, got %x\n", queue_status);
7772 return ret;
7775 static BOOL RegisterWindowClasses(void)
7777 WNDCLASSA cls;
7778 WNDCLASSW clsW;
7780 cls.style = 0;
7781 cls.lpfnWndProc = MsgCheckProcA;
7782 cls.cbClsExtra = 0;
7783 cls.cbWndExtra = 0;
7784 cls.hInstance = GetModuleHandleA(0);
7785 cls.hIcon = 0;
7786 cls.hCursor = LoadCursorA(0, IDC_ARROW);
7787 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7788 cls.lpszMenuName = NULL;
7789 cls.lpszClassName = "TestWindowClass";
7790 if(!RegisterClassA(&cls)) return FALSE;
7792 cls.lpfnWndProc = HotkeyMsgCheckProcA;
7793 cls.lpszClassName = "HotkeyWindowClass";
7794 if(!RegisterClassA(&cls)) return FALSE;
7796 cls.lpfnWndProc = ShowWindowProcA;
7797 cls.lpszClassName = "ShowWindowClass";
7798 if(!RegisterClassA(&cls)) return FALSE;
7800 cls.lpfnWndProc = PopupMsgCheckProcA;
7801 cls.lpszClassName = "TestPopupClass";
7802 if(!RegisterClassA(&cls)) return FALSE;
7804 cls.lpfnWndProc = ParentMsgCheckProcA;
7805 cls.lpszClassName = "TestParentClass";
7806 if(!RegisterClassA(&cls)) return FALSE;
7808 cls.lpfnWndProc = StopQuitMsgCheckProcA;
7809 cls.lpszClassName = "StopQuitClass";
7810 if(!RegisterClassA(&cls)) return FALSE;
7812 cls.lpfnWndProc = DefWindowProcA;
7813 cls.lpszClassName = "SimpleWindowClass";
7814 if(!RegisterClassA(&cls)) return FALSE;
7816 cls.lpfnWndProc = PaintLoopProcA;
7817 cls.lpszClassName = "PaintLoopWindowClass";
7818 if(!RegisterClassA(&cls)) return FALSE;
7820 cls.style = CS_NOCLOSE;
7821 cls.lpszClassName = "NoCloseWindowClass";
7822 if(!RegisterClassA(&cls)) return FALSE;
7824 ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
7825 cls.style = 0;
7826 cls.hInstance = GetModuleHandleA(0);
7827 cls.hbrBackground = 0;
7828 cls.lpfnWndProc = TestDlgProcA;
7829 cls.lpszClassName = "TestDialogClass";
7830 if(!RegisterClassA(&cls)) return FALSE;
7832 clsW.style = 0;
7833 clsW.lpfnWndProc = MsgCheckProcW;
7834 clsW.cbClsExtra = 0;
7835 clsW.cbWndExtra = 0;
7836 clsW.hInstance = GetModuleHandleW(0);
7837 clsW.hIcon = 0;
7838 clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
7839 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
7840 clsW.lpszMenuName = NULL;
7841 clsW.lpszClassName = testWindowClassW;
7842 RegisterClassW(&clsW); /* ignore error, this fails on Win9x */
7844 return TRUE;
7847 static BOOL is_our_logged_class(HWND hwnd)
7849 char buf[256];
7851 if (GetClassNameA(hwnd, buf, sizeof(buf)))
7853 if (!lstrcmpiA(buf, "TestWindowClass") ||
7854 !lstrcmpiA(buf, "ShowWindowClass") ||
7855 !lstrcmpiA(buf, "TestParentClass") ||
7856 !lstrcmpiA(buf, "TestPopupClass") ||
7857 !lstrcmpiA(buf, "SimpleWindowClass") ||
7858 !lstrcmpiA(buf, "TestDialogClass") ||
7859 !lstrcmpiA(buf, "MDI_frame_class") ||
7860 !lstrcmpiA(buf, "MDI_client_class") ||
7861 !lstrcmpiA(buf, "MDI_child_class") ||
7862 !lstrcmpiA(buf, "my_button_class") ||
7863 !lstrcmpiA(buf, "my_edit_class") ||
7864 !lstrcmpiA(buf, "static") ||
7865 !lstrcmpiA(buf, "ListBox") ||
7866 !lstrcmpiA(buf, "ComboBox") ||
7867 !lstrcmpiA(buf, "MyDialogClass") ||
7868 !lstrcmpiA(buf, "#32770") ||
7869 !lstrcmpiA(buf, "#32768"))
7870 return TRUE;
7872 return FALSE;
7875 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
7877 HWND hwnd;
7879 ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7881 if (nCode == HCBT_CLICKSKIPPED)
7883 /* ignore this event, XP sends it a lot when switching focus between windows */
7884 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7887 if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
7889 struct recvd_message msg;
7891 msg.hwnd = 0;
7892 msg.message = nCode;
7893 msg.flags = hook|wparam|lparam;
7894 msg.wParam = wParam;
7895 msg.lParam = lParam;
7896 msg.descr = "CBT";
7897 add_message(&msg);
7899 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7902 if (nCode == HCBT_DESTROYWND)
7904 if (test_DestroyWindow_flag)
7906 DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
7907 if (style & WS_CHILD)
7908 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
7909 else if (style & WS_POPUP)
7910 lParam = WND_POPUP_ID;
7911 else
7912 lParam = WND_PARENT_ID;
7916 /* Log also SetFocus(0) calls */
7917 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7919 if (is_our_logged_class(hwnd))
7921 struct recvd_message msg;
7923 msg.hwnd = hwnd;
7924 msg.message = nCode;
7925 msg.flags = hook|wparam|lparam;
7926 msg.wParam = wParam;
7927 msg.lParam = lParam;
7928 msg.descr = "CBT";
7929 add_message(&msg);
7931 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7934 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
7935 DWORD event,
7936 HWND hwnd,
7937 LONG object_id,
7938 LONG child_id,
7939 DWORD thread_id,
7940 DWORD event_time)
7942 ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7944 /* ignore mouse cursor events */
7945 if (object_id == OBJID_CURSOR) return;
7947 if (!hwnd || is_our_logged_class(hwnd))
7949 struct recvd_message msg;
7951 msg.hwnd = hwnd;
7952 msg.message = event;
7953 msg.flags = winevent_hook|wparam|lparam;
7954 msg.wParam = object_id;
7955 msg.lParam = child_id;
7956 msg.descr = "WEH";
7957 add_message(&msg);
7961 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
7962 static const WCHAR wszAnsi[] = {'U',0};
7964 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
7966 switch (uMsg)
7968 case CB_FINDSTRINGEXACT:
7969 trace("String: %p\n", (LPCWSTR)lParam);
7970 if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
7971 return 1;
7972 if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
7973 return 0;
7974 return -1;
7976 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
7979 static const struct message WmGetTextLengthAfromW[] = {
7980 { WM_GETTEXTLENGTH, sent },
7981 { WM_GETTEXT, sent|optional },
7982 { 0 }
7985 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
7987 /* dummy window proc for WM_GETTEXTLENGTH test */
7988 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
7990 switch(msg)
7992 case WM_GETTEXTLENGTH:
7993 return lstrlenW(dummy_window_text) + 37; /* some random length */
7994 case WM_GETTEXT:
7995 lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
7996 return lstrlenW( (LPWSTR)lp );
7997 default:
7998 return DefWindowProcW( hwnd, msg, wp, lp );
8002 static void test_message_conversion(void)
8004 static const WCHAR wszMsgConversionClass[] =
8005 {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
8006 WNDCLASSW cls;
8007 LRESULT lRes;
8008 HWND hwnd;
8009 WNDPROC wndproc, newproc;
8010 BOOL ret;
8012 cls.style = 0;
8013 cls.lpfnWndProc = MsgConversionProcW;
8014 cls.cbClsExtra = 0;
8015 cls.cbWndExtra = 0;
8016 cls.hInstance = GetModuleHandleW(NULL);
8017 cls.hIcon = NULL;
8018 cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
8019 cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
8020 cls.lpszMenuName = NULL;
8021 cls.lpszClassName = wszMsgConversionClass;
8022 /* this call will fail on Win9x, but that doesn't matter as this test is
8023 * meaningless on those platforms */
8024 if(!RegisterClassW(&cls)) return;
8026 hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
8027 100, 100, 200, 200, 0, 0, 0, NULL);
8028 ok(hwnd != NULL, "Window creation failed\n");
8030 /* {W, A} -> A */
8032 wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
8033 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8034 ok(lRes == 0, "String should have been converted\n");
8035 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8036 ok(lRes == 1, "String shouldn't have been converted\n");
8038 /* {W, A} -> W */
8040 wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
8041 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8042 ok(lRes == 1, "String shouldn't have been converted\n");
8043 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8044 ok(lRes == 1, "String shouldn't have been converted\n");
8046 /* Synchronous messages */
8048 lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8049 ok(lRes == 0, "String should have been converted\n");
8050 lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8051 ok(lRes == 1, "String shouldn't have been converted\n");
8053 /* Asynchronous messages */
8055 SetLastError(0);
8056 lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8057 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8058 "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8059 SetLastError(0);
8060 lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8061 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8062 "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8063 SetLastError(0);
8064 lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8065 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8066 "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8067 SetLastError(0);
8068 lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8069 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8070 "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8071 SetLastError(0);
8072 lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8073 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8074 "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8075 SetLastError(0);
8076 lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8077 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8078 "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8079 SetLastError(0);
8080 lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
8081 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8082 "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8083 SetLastError(0);
8084 lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
8085 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8086 "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8088 /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
8090 hwnd = CreateWindowW (testWindowClassW, wszUnicode,
8091 WS_OVERLAPPEDWINDOW,
8092 100, 100, 200, 200, 0, 0, 0, NULL);
8093 assert(hwnd);
8094 flush_sequence();
8095 lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
8096 ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
8097 ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
8098 "got bad length %ld\n", lRes );
8100 flush_sequence();
8101 lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
8102 hwnd, WM_GETTEXTLENGTH, 0, 0);
8103 ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
8104 ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
8105 "got bad length %ld\n", lRes );
8107 wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
8108 newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
8109 lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
8110 ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
8111 NULL, 0, NULL, NULL ) ||
8112 broken(lRes == lstrlenW(dummy_window_text) + 37),
8113 "got bad length %ld\n", lRes );
8115 SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc ); /* restore old wnd proc */
8116 lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
8117 ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
8118 NULL, 0, NULL, NULL ) ||
8119 broken(lRes == lstrlenW(dummy_window_text) + 37),
8120 "got bad length %ld\n", lRes );
8122 ret = DestroyWindow(hwnd);
8123 ok( ret, "DestroyWindow() error %d\n", GetLastError());
8126 struct timer_info
8128 HWND hWnd;
8129 HANDLE handles[2];
8130 DWORD id;
8133 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
8137 #define TIMER_ID 0x19
8139 static DWORD WINAPI timer_thread_proc(LPVOID x)
8141 struct timer_info *info = x;
8142 DWORD r;
8144 r = KillTimer(info->hWnd, 0x19);
8145 ok(r,"KillTimer failed in thread\n");
8146 r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
8147 ok(r,"SetTimer failed in thread\n");
8148 ok(r==TIMER_ID,"SetTimer id different\n");
8149 r = SetEvent(info->handles[0]);
8150 ok(r,"SetEvent failed in thread\n");
8151 return 0;
8154 static void test_timers(void)
8156 struct timer_info info;
8157 DWORD id;
8159 info.hWnd = CreateWindow ("TestWindowClass", NULL,
8160 WS_OVERLAPPEDWINDOW ,
8161 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8162 NULL, NULL, 0);
8164 info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
8165 ok(info.id, "SetTimer failed\n");
8166 ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
8167 info.handles[0] = CreateEvent(NULL,0,0,NULL);
8168 info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
8170 WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
8172 WaitForSingleObject(info.handles[1], INFINITE);
8174 CloseHandle(info.handles[0]);
8175 CloseHandle(info.handles[1]);
8177 ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
8179 ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
8182 static int count = 0;
8183 static VOID CALLBACK callback_count(
8184 HWND hwnd,
8185 UINT uMsg,
8186 UINT_PTR idEvent,
8187 DWORD dwTime
8190 count++;
8193 static void test_timers_no_wnd(void)
8195 UINT_PTR id, id2;
8196 MSG msg;
8198 count = 0;
8199 id = SetTimer(NULL, 0, 100, callback_count);
8200 ok(id != 0, "did not get id from SetTimer.\n");
8201 id2 = SetTimer(NULL, id, 200, callback_count);
8202 ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
8203 Sleep(150);
8204 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8205 ok(count == 0, "did not get zero count as expected (%i).\n", count);
8206 Sleep(150);
8207 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8208 ok(count == 1, "did not get one count as expected (%i).\n", count);
8209 KillTimer(NULL, id);
8210 Sleep(250);
8211 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8212 ok(count == 1, "killing replaced timer did not work (%i).\n", count);
8215 /* Various win events with arbitrary parameters */
8216 static const struct message WmWinEventsSeq[] = {
8217 { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
8218 { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
8219 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
8220 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
8221 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
8222 { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
8223 { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
8224 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
8225 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
8226 /* our win event hook ignores OBJID_CURSOR events */
8227 /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
8228 { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
8229 { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
8230 { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
8231 { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
8232 { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
8233 { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
8234 { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
8235 { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
8236 { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
8237 { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
8238 { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
8239 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
8240 { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
8241 { 0 }
8243 static const struct message WmWinEventCaretSeq[] = {
8244 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8245 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8246 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
8247 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8248 { 0 }
8250 static const struct message WmWinEventCaretSeq_2[] = {
8251 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8252 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8253 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8254 { 0 }
8256 static const struct message WmWinEventAlertSeq[] = {
8257 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
8258 { 0 }
8260 static const struct message WmWinEventAlertSeq_2[] = {
8261 /* create window in the thread proc */
8262 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
8263 /* our test event */
8264 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
8265 { 0 }
8267 static const struct message WmGlobalHookSeq_1[] = {
8268 /* create window in the thread proc */
8269 { HCBT_CREATEWND, hook|lparam, 0, 2 },
8270 /* our test events */
8271 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
8272 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
8273 { 0 }
8275 static const struct message WmGlobalHookSeq_2[] = {
8276 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
8277 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
8278 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
8279 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
8280 { 0 }
8283 static const struct message WmMouseLLHookSeq[] = {
8284 { WM_MOUSEMOVE, hook },
8285 { WM_LBUTTONUP, hook },
8286 { WM_MOUSEMOVE, hook },
8287 { 0 }
8290 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
8291 DWORD event,
8292 HWND hwnd,
8293 LONG object_id,
8294 LONG child_id,
8295 DWORD thread_id,
8296 DWORD event_time)
8298 char buf[256];
8300 if (GetClassNameA(hwnd, buf, sizeof(buf)))
8302 if (!lstrcmpiA(buf, "TestWindowClass") ||
8303 !lstrcmpiA(buf, "static"))
8305 struct recvd_message msg;
8307 msg.hwnd = hwnd;
8308 msg.message = event;
8309 msg.flags = winevent_hook|wparam|lparam;
8310 msg.wParam = object_id;
8311 msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
8312 msg.descr = "WEH_2";
8313 add_message(&msg);
8318 static HHOOK hCBT_global_hook;
8319 static DWORD cbt_global_hook_thread_id;
8321 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
8323 HWND hwnd;
8324 char buf[256];
8326 if (nCode == HCBT_SYSCOMMAND)
8328 struct recvd_message msg;
8330 msg.hwnd = 0;
8331 msg.message = nCode;
8332 msg.flags = hook|wparam|lparam;
8333 msg.wParam = wParam;
8334 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8335 msg.descr = "CBT_2";
8336 add_message(&msg);
8338 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8340 /* WH_MOUSE_LL hook */
8341 if (nCode == HC_ACTION)
8343 MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
8345 /* we can't test for real mouse events */
8346 if (mhll->flags & LLMHF_INJECTED)
8348 struct recvd_message msg;
8350 memset (&msg, 0, sizeof (msg));
8351 msg.message = wParam;
8352 msg.flags = hook;
8353 msg.descr = "CBT_2";
8354 add_message(&msg);
8356 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8359 /* Log also SetFocus(0) calls */
8360 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
8362 if (GetClassNameA(hwnd, buf, sizeof(buf)))
8364 if (!lstrcmpiA(buf, "TestWindowClass") ||
8365 !lstrcmpiA(buf, "static"))
8367 struct recvd_message msg;
8369 msg.hwnd = hwnd;
8370 msg.message = nCode;
8371 msg.flags = hook|wparam|lparam;
8372 msg.wParam = wParam;
8373 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8374 msg.descr = "CBT_2";
8375 add_message(&msg);
8378 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8381 static DWORD WINAPI win_event_global_thread_proc(void *param)
8383 HWND hwnd;
8384 MSG msg;
8385 HANDLE hevent = *(HANDLE *)param;
8387 assert(pNotifyWinEvent);
8389 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8390 assert(hwnd);
8391 trace("created thread window %p\n", hwnd);
8393 *(HWND *)param = hwnd;
8395 flush_sequence();
8396 /* this event should be received only by our new hook proc,
8397 * an old one does not expect an event from another thread.
8399 pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
8400 SetEvent(hevent);
8402 while (GetMessage(&msg, 0, 0, 0))
8404 TranslateMessage(&msg);
8405 DispatchMessage(&msg);
8407 return 0;
8410 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
8412 HWND hwnd;
8413 MSG msg;
8414 HANDLE hevent = *(HANDLE *)param;
8416 flush_sequence();
8417 /* these events should be received only by our new hook proc,
8418 * an old one does not expect an event from another thread.
8421 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8422 assert(hwnd);
8423 trace("created thread window %p\n", hwnd);
8425 *(HWND *)param = hwnd;
8427 /* Windows doesn't like when a thread plays games with the focus,
8428 that leads to all kinds of misbehaviours and failures to activate
8429 a window. So, better keep next lines commented out.
8430 SetFocus(0);
8431 SetFocus(hwnd);*/
8433 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8434 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8436 SetEvent(hevent);
8438 while (GetMessage(&msg, 0, 0, 0))
8440 TranslateMessage(&msg);
8441 DispatchMessage(&msg);
8443 return 0;
8446 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
8448 HWND hwnd;
8449 MSG msg;
8450 HANDLE hevent = *(HANDLE *)param;
8452 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8453 assert(hwnd);
8454 trace("created thread window %p\n", hwnd);
8456 *(HWND *)param = hwnd;
8458 flush_sequence();
8460 /* Windows doesn't like when a thread plays games with the focus,
8461 * that leads to all kinds of misbehaviours and failures to activate
8462 * a window. So, better don't generate a mouse click message below.
8464 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8465 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8466 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8468 SetEvent(hevent);
8469 while (GetMessage(&msg, 0, 0, 0))
8471 TranslateMessage(&msg);
8472 DispatchMessage(&msg);
8474 return 0;
8477 static void test_winevents(void)
8479 BOOL ret;
8480 MSG msg;
8481 HWND hwnd, hwnd2;
8482 UINT i;
8483 HANDLE hthread, hevent;
8484 DWORD tid;
8485 HWINEVENTHOOK hhook;
8486 const struct message *events = WmWinEventsSeq;
8488 hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
8489 WS_OVERLAPPEDWINDOW,
8490 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8491 NULL, NULL, 0);
8492 assert(hwnd);
8494 /****** start of global hook test *************/
8495 hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8496 if (!hCBT_global_hook)
8498 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8499 skip( "cannot set global hook\n" );
8500 return;
8503 hevent = CreateEventA(NULL, 0, 0, NULL);
8504 assert(hevent);
8505 hwnd2 = hevent;
8507 hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
8508 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8510 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8512 ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
8514 flush_sequence();
8515 /* this one should be received only by old hook proc */
8516 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8517 /* this one should be received only by old hook proc */
8518 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8520 ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
8522 ret = UnhookWindowsHookEx(hCBT_global_hook);
8523 ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8525 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8526 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8527 CloseHandle(hthread);
8528 CloseHandle(hevent);
8529 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8530 /****** end of global hook test *************/
8532 if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
8534 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8535 return;
8538 flush_sequence();
8540 if (0)
8542 /* this test doesn't pass under Win9x */
8543 /* win2k ignores events with hwnd == 0 */
8544 SetLastError(0xdeadbeef);
8545 pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
8546 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
8547 GetLastError() == 0xdeadbeef, /* Win9x */
8548 "unexpected error %d\n", GetLastError());
8549 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8552 for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
8553 pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
8555 ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
8557 /****** start of event filtering test *************/
8558 hhook = pSetWinEventHook(
8559 EVENT_OBJECT_SHOW, /* 0x8002 */
8560 EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
8561 GetModuleHandleA(0), win_event_global_hook_proc,
8562 GetCurrentProcessId(), 0,
8563 WINEVENT_INCONTEXT);
8564 ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8566 hevent = CreateEventA(NULL, 0, 0, NULL);
8567 assert(hevent);
8568 hwnd2 = hevent;
8570 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8571 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8573 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8575 ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
8577 flush_sequence();
8578 /* this one should be received only by old hook proc */
8579 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8580 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8581 /* this one should be received only by old hook proc */
8582 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8584 ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
8586 ret = pUnhookWinEvent(hhook);
8587 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8589 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8590 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8591 CloseHandle(hthread);
8592 CloseHandle(hevent);
8593 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8594 /****** end of event filtering test *************/
8596 /****** start of out of context event test *************/
8597 hhook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0,
8598 win_event_global_hook_proc, GetCurrentProcessId(), 0,
8599 WINEVENT_OUTOFCONTEXT);
8600 ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8602 hevent = CreateEventA(NULL, 0, 0, NULL);
8603 assert(hevent);
8604 hwnd2 = hevent;
8606 flush_sequence();
8608 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8609 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8611 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8613 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8614 /* process pending winevent messages */
8615 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8616 ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
8618 flush_sequence();
8619 /* this one should be received only by old hook proc */
8620 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8621 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8622 /* this one should be received only by old hook proc */
8623 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8625 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
8626 /* process pending winevent messages */
8627 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8628 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
8630 ret = pUnhookWinEvent(hhook);
8631 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8633 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8634 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8635 CloseHandle(hthread);
8636 CloseHandle(hevent);
8637 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8638 /****** end of out of context event test *************/
8640 /****** start of MOUSE_LL hook test *************/
8641 hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8642 /* WH_MOUSE_LL is not supported on Win9x platforms */
8643 if (!hCBT_global_hook)
8645 win_skip("Skipping WH_MOUSE_LL test on this platform\n");
8646 goto skip_mouse_ll_hook_test;
8649 hevent = CreateEventA(NULL, 0, 0, NULL);
8650 assert(hevent);
8651 hwnd2 = hevent;
8653 hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
8654 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8656 while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
8657 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
8659 ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
8660 flush_sequence();
8662 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8663 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8664 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8666 ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
8668 ret = UnhookWindowsHookEx(hCBT_global_hook);
8669 ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8671 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8672 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8673 CloseHandle(hthread);
8674 CloseHandle(hevent);
8675 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8676 /****** end of MOUSE_LL hook test *************/
8677 skip_mouse_ll_hook_test:
8679 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8682 static void test_set_hook(void)
8684 BOOL ret;
8685 HHOOK hhook;
8686 HWINEVENTHOOK hwinevent_hook;
8688 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
8689 ok(hhook != 0, "local hook does not require hModule set to 0\n");
8690 UnhookWindowsHookEx(hhook);
8692 if (0)
8694 /* this test doesn't pass under Win9x: BUG! */
8695 SetLastError(0xdeadbeef);
8696 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
8697 ok(!hhook, "global hook requires hModule != 0\n");
8698 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
8701 SetLastError(0xdeadbeef);
8702 hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
8703 ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
8704 ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
8705 GetLastError() == 0xdeadbeef, /* Win9x */
8706 "unexpected error %d\n", GetLastError());
8708 SetLastError(0xdeadbeef);
8709 ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
8710 ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
8711 GetLastError() == 0xdeadbeef, /* Win9x */
8712 "unexpected error %d\n", GetLastError());
8714 if (!pSetWinEventHook || !pUnhookWinEvent) return;
8716 /* even process local incontext hooks require hmodule */
8717 SetLastError(0xdeadbeef);
8718 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8719 GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
8720 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8721 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8722 GetLastError() == 0xdeadbeef, /* Win9x */
8723 "unexpected error %d\n", GetLastError());
8725 /* even thread local incontext hooks require hmodule */
8726 SetLastError(0xdeadbeef);
8727 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8728 GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
8729 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8730 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8731 GetLastError() == 0xdeadbeef, /* Win9x */
8732 "unexpected error %d\n", GetLastError());
8734 if (0)
8736 /* these 3 tests don't pass under Win9x */
8737 SetLastError(0xdeadbeef);
8738 hwinevent_hook = pSetWinEventHook(1, 0, 0, win_event_proc,
8739 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8740 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8741 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8743 SetLastError(0xdeadbeef);
8744 hwinevent_hook = pSetWinEventHook(-1, 1, 0, win_event_proc,
8745 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8746 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8747 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8749 SetLastError(0xdeadbeef);
8750 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8751 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
8752 ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
8753 ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
8756 SetLastError(0xdeadbeef);
8757 hwinevent_hook = pSetWinEventHook(0, 0, 0, win_event_proc,
8758 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8759 ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8760 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8761 ret = pUnhookWinEvent(hwinevent_hook);
8762 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8764 todo_wine {
8765 /* This call succeeds under win2k SP4, but fails under Wine.
8766 Does win2k test/use passed process id? */
8767 SetLastError(0xdeadbeef);
8768 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8769 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
8770 ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8771 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8772 ret = pUnhookWinEvent(hwinevent_hook);
8773 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8776 SetLastError(0xdeadbeef);
8777 ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
8778 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
8779 GetLastError() == 0xdeadbeef, /* Win9x */
8780 "unexpected error %d\n", GetLastError());
8783 static const struct message ScrollWindowPaint1[] = {
8784 { WM_PAINT, sent },
8785 { WM_ERASEBKGND, sent|beginpaint },
8786 { WM_GETTEXTLENGTH, sent|optional },
8787 { WM_PAINT, sent|optional },
8788 { WM_NCPAINT, sent|beginpaint|optional },
8789 { WM_GETTEXT, sent|beginpaint|optional },
8790 { WM_GETTEXT, sent|beginpaint|optional },
8791 { WM_GETTEXT, sent|beginpaint|optional },
8792 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
8793 { WM_ERASEBKGND, sent|beginpaint|optional },
8794 { 0 }
8797 static const struct message ScrollWindowPaint2[] = {
8798 { WM_PAINT, sent },
8799 { 0 }
8802 static void test_scrollwindowex(void)
8804 HWND hwnd, hchild;
8805 RECT rect={0,0,130,130};
8807 hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
8808 WS_VISIBLE|WS_OVERLAPPEDWINDOW,
8809 100, 100, 200, 200, 0, 0, 0, NULL);
8810 ok (hwnd != 0, "Failed to create overlapped window\n");
8811 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
8812 WS_VISIBLE|WS_CAPTION|WS_CHILD,
8813 10, 10, 150, 150, hwnd, 0, 0, NULL);
8814 ok (hchild != 0, "Failed to create child\n");
8815 UpdateWindow(hwnd);
8816 flush_events();
8817 flush_sequence();
8819 /* scroll without the child window */
8820 trace("start scroll\n");
8821 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8822 SW_ERASE|SW_INVALIDATE);
8823 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8824 trace("end scroll\n");
8825 flush_sequence();
8826 flush_events();
8827 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8828 flush_events();
8829 flush_sequence();
8831 /* Now without the SW_ERASE flag */
8832 trace("start scroll\n");
8833 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
8834 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8835 trace("end scroll\n");
8836 flush_sequence();
8837 flush_events();
8838 ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
8839 flush_events();
8840 flush_sequence();
8842 /* now scroll the child window as well */
8843 trace("start scroll\n");
8844 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8845 SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
8846 /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
8847 /* windows sometimes a WM_MOVE */
8848 ok_sequence(WmEmptySeq, "ScrollWindowEx", TRUE);
8849 trace("end scroll\n");
8850 flush_sequence();
8851 flush_events();
8852 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8853 flush_events();
8854 flush_sequence();
8856 /* now scroll with ScrollWindow() */
8857 trace("start scroll with ScrollWindow\n");
8858 ScrollWindow( hwnd, 5, 5, NULL, NULL);
8859 trace("end scroll\n");
8860 flush_sequence();
8861 flush_events();
8862 ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
8864 ok(DestroyWindow(hchild), "failed to destroy window\n");
8865 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8866 flush_sequence();
8869 static const struct message destroy_window_with_children[] = {
8870 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8871 { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
8872 { 0x0090, sent|optional },
8873 { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
8874 { 0x0090, sent|optional },
8875 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8876 { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8877 { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8878 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8879 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
8880 { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8881 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8882 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8883 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8884 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8885 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8886 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8887 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8888 { 0 }
8891 static void test_DestroyWindow(void)
8893 BOOL ret;
8894 HWND parent, child1, child2, child3, child4, test;
8895 UINT_PTR child_id = WND_CHILD_ID + 1;
8897 parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8898 100, 100, 200, 200, 0, 0, 0, NULL);
8899 assert(parent != 0);
8900 child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8901 0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
8902 assert(child1 != 0);
8903 child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8904 0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
8905 assert(child2 != 0);
8906 child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8907 0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
8908 assert(child3 != 0);
8909 child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
8910 0, 0, 50, 50, parent, 0, 0, NULL);
8911 assert(child4 != 0);
8913 /* test owner/parent of child2 */
8914 test = GetParent(child2);
8915 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8916 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8917 if(pGetAncestor) {
8918 test = pGetAncestor(child2, GA_PARENT);
8919 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8921 test = GetWindow(child2, GW_OWNER);
8922 ok(!test, "wrong owner %p\n", test);
8924 test = SetParent(child2, parent);
8925 ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
8927 /* test owner/parent of the parent */
8928 test = GetParent(parent);
8929 ok(!test, "wrong parent %p\n", test);
8930 ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
8931 if(pGetAncestor) {
8932 test = pGetAncestor(parent, GA_PARENT);
8933 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8935 test = GetWindow(parent, GW_OWNER);
8936 ok(!test, "wrong owner %p\n", test);
8938 /* test owner/parent of child1 */
8939 test = GetParent(child1);
8940 ok(test == parent, "wrong parent %p\n", test);
8941 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
8942 if(pGetAncestor) {
8943 test = pGetAncestor(child1, GA_PARENT);
8944 ok(test == parent, "wrong parent %p\n", test);
8946 test = GetWindow(child1, GW_OWNER);
8947 ok(!test, "wrong owner %p\n", test);
8949 /* test owner/parent of child2 */
8950 test = GetParent(child2);
8951 ok(test == parent, "wrong parent %p\n", test);
8952 ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8953 if(pGetAncestor) {
8954 test = pGetAncestor(child2, GA_PARENT);
8955 ok(test == parent, "wrong parent %p\n", test);
8957 test = GetWindow(child2, GW_OWNER);
8958 ok(!test, "wrong owner %p\n", test);
8960 /* test owner/parent of child3 */
8961 test = GetParent(child3);
8962 ok(test == child1, "wrong parent %p\n", test);
8963 ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
8964 if(pGetAncestor) {
8965 test = pGetAncestor(child3, GA_PARENT);
8966 ok(test == child1, "wrong parent %p\n", test);
8968 test = GetWindow(child3, GW_OWNER);
8969 ok(!test, "wrong owner %p\n", test);
8971 /* test owner/parent of child4 */
8972 test = GetParent(child4);
8973 ok(test == parent, "wrong parent %p\n", test);
8974 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
8975 if(pGetAncestor) {
8976 test = pGetAncestor(child4, GA_PARENT);
8977 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8979 test = GetWindow(child4, GW_OWNER);
8980 ok(test == parent, "wrong owner %p\n", test);
8982 flush_sequence();
8984 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
8985 parent, child1, child2, child3, child4);
8987 SetCapture(child4);
8988 test = GetCapture();
8989 ok(test == child4, "wrong capture window %p\n", test);
8991 test_DestroyWindow_flag = TRUE;
8992 ret = DestroyWindow(parent);
8993 ok( ret, "DestroyWindow() error %d\n", GetLastError());
8994 test_DestroyWindow_flag = FALSE;
8995 ok_sequence(destroy_window_with_children, "destroy window with children", 0);
8997 ok(!IsWindow(parent), "parent still exists\n");
8998 ok(!IsWindow(child1), "child1 still exists\n");
8999 ok(!IsWindow(child2), "child2 still exists\n");
9000 ok(!IsWindow(child3), "child3 still exists\n");
9001 ok(!IsWindow(child4), "child4 still exists\n");
9003 test = GetCapture();
9004 ok(!test, "wrong capture window %p\n", test);
9008 static const struct message WmDispatchPaint[] = {
9009 { WM_NCPAINT, sent },
9010 { WM_GETTEXT, sent|defwinproc|optional },
9011 { WM_GETTEXT, sent|defwinproc|optional },
9012 { WM_ERASEBKGND, sent },
9013 { 0 }
9016 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9018 if (message == WM_PAINT) return 0;
9019 return MsgCheckProcA( hwnd, message, wParam, lParam );
9022 static void test_DispatchMessage(void)
9024 RECT rect;
9025 MSG msg;
9026 int count;
9027 HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9028 100, 100, 200, 200, 0, 0, 0, NULL);
9029 ShowWindow( hwnd, SW_SHOW );
9030 UpdateWindow( hwnd );
9031 flush_events();
9032 flush_sequence();
9033 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
9035 SetRect( &rect, -5, -5, 5, 5 );
9036 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
9037 count = 0;
9038 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
9040 if (msg.message != WM_PAINT) DispatchMessage( &msg );
9041 else
9043 flush_sequence();
9044 DispatchMessage( &msg );
9045 /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
9046 if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
9047 else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
9048 if (++count > 10) break;
9051 ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
9053 trace("now without DispatchMessage\n");
9054 flush_sequence();
9055 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
9056 count = 0;
9057 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
9059 if (msg.message != WM_PAINT) DispatchMessage( &msg );
9060 else
9062 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
9063 flush_sequence();
9064 /* this will send WM_NCCPAINT just like DispatchMessage does */
9065 GetUpdateRgn( hwnd, hrgn, TRUE );
9066 ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
9067 DeleteObject( hrgn );
9068 GetClientRect( hwnd, &rect );
9069 ValidateRect( hwnd, &rect ); /* this will stop WM_PAINTs */
9070 ok( !count, "Got multiple WM_PAINTs\n" );
9071 if (++count > 10) break;
9074 DestroyWindow(hwnd);
9078 static const struct message WmUser[] = {
9079 { WM_USER, sent },
9080 { 0 }
9083 struct sendmsg_info
9085 HWND hwnd;
9086 DWORD timeout;
9087 DWORD ret;
9090 static DWORD CALLBACK send_msg_thread( LPVOID arg )
9092 struct sendmsg_info *info = arg;
9093 SetLastError( 0xdeadbeef );
9094 info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
9095 if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT ||
9096 broken(GetLastError() == 0), /* win9x */
9097 "unexpected error %d\n", GetLastError());
9098 return 0;
9101 static void wait_for_thread( HANDLE thread )
9103 while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
9105 MSG msg;
9106 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
9110 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9112 if (message == WM_USER) Sleep(200);
9113 return MsgCheckProcA( hwnd, message, wParam, lParam );
9116 static void test_SendMessageTimeout(void)
9118 HANDLE thread;
9119 struct sendmsg_info info;
9120 DWORD tid;
9121 BOOL is_win9x;
9123 info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9124 100, 100, 200, 200, 0, 0, 0, NULL);
9125 flush_events();
9126 flush_sequence();
9128 info.timeout = 1000;
9129 info.ret = 0xdeadbeef;
9130 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9131 wait_for_thread( thread );
9132 CloseHandle( thread );
9133 ok( info.ret == 1, "SendMessageTimeout failed\n" );
9134 ok_sequence( WmUser, "WmUser", FALSE );
9136 info.timeout = 1;
9137 info.ret = 0xdeadbeef;
9138 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9139 Sleep(100); /* SendMessageTimeout should time out here */
9140 wait_for_thread( thread );
9141 CloseHandle( thread );
9142 ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
9143 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9145 /* 0 means infinite timeout (but not on win9x) */
9146 info.timeout = 0;
9147 info.ret = 0xdeadbeef;
9148 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9149 Sleep(100);
9150 wait_for_thread( thread );
9151 CloseHandle( thread );
9152 is_win9x = !info.ret;
9153 if (is_win9x) ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9154 else ok_sequence( WmUser, "WmUser", FALSE );
9156 /* timeout is treated as signed despite the prototype (but not on win9x) */
9157 info.timeout = 0x7fffffff;
9158 info.ret = 0xdeadbeef;
9159 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9160 Sleep(100);
9161 wait_for_thread( thread );
9162 CloseHandle( thread );
9163 ok( info.ret == 1, "SendMessageTimeout failed\n" );
9164 ok_sequence( WmUser, "WmUser", FALSE );
9166 info.timeout = 0x80000000;
9167 info.ret = 0xdeadbeef;
9168 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9169 Sleep(100);
9170 wait_for_thread( thread );
9171 CloseHandle( thread );
9172 if (is_win9x)
9174 ok( info.ret == 1, "SendMessageTimeout failed\n" );
9175 ok_sequence( WmUser, "WmUser", FALSE );
9177 else
9179 ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
9180 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9183 /* now check for timeout during message processing */
9184 SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
9185 info.timeout = 100;
9186 info.ret = 0xdeadbeef;
9187 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9188 wait_for_thread( thread );
9189 CloseHandle( thread );
9190 /* we should time out but still get the message */
9191 ok( info.ret == 0, "SendMessageTimeout failed\n" );
9192 ok_sequence( WmUser, "WmUser", FALSE );
9194 DestroyWindow( info.hwnd );
9198 /****************** edit message test *************************/
9199 #define ID_EDIT 0x1234
9200 static const struct message sl_edit_setfocus[] =
9202 { HCBT_SETFOCUS, hook },
9203 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9204 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9205 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9206 { WM_SETFOCUS, sent|wparam, 0 },
9207 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9208 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
9209 { WM_CTLCOLOREDIT, sent|parent },
9210 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9211 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9212 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9213 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9214 { 0 }
9216 static const struct message ml_edit_setfocus[] =
9218 { HCBT_SETFOCUS, hook },
9219 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9220 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9221 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9222 { WM_SETFOCUS, sent|wparam, 0 },
9223 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9224 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9225 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9226 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9227 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9228 { 0 }
9230 static const struct message sl_edit_killfocus[] =
9232 { HCBT_SETFOCUS, hook },
9233 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9234 { WM_KILLFOCUS, sent|wparam, 0 },
9235 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9236 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9237 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
9238 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
9239 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
9240 { 0 }
9242 static const struct message sl_edit_lbutton_dblclk[] =
9244 { WM_LBUTTONDBLCLK, sent },
9245 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9246 { 0 }
9248 static const struct message sl_edit_lbutton_down[] =
9250 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
9251 { HCBT_SETFOCUS, hook },
9252 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9253 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9254 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9255 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9256 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9257 { WM_CTLCOLOREDIT, sent|parent },
9258 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9259 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9260 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9261 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9262 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9263 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9264 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9265 { WM_CTLCOLOREDIT, sent|parent|optional },
9266 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9267 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9268 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9269 { 0 }
9271 static const struct message ml_edit_lbutton_down[] =
9273 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
9274 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9275 { HCBT_SETFOCUS, hook },
9276 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9277 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9278 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9279 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9280 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9281 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9282 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9283 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9284 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9285 { 0 }
9287 static const struct message sl_edit_lbutton_up[] =
9289 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9290 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9291 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9292 { WM_CAPTURECHANGED, sent|defwinproc },
9293 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9294 { 0 }
9296 static const struct message ml_edit_lbutton_up[] =
9298 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9299 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9300 { WM_CAPTURECHANGED, sent|defwinproc },
9301 { 0 }
9304 static WNDPROC old_edit_proc;
9306 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9308 static LONG defwndproc_counter = 0;
9309 LRESULT ret;
9310 struct recvd_message msg;
9312 if (ignore_message( message )) return 0;
9314 msg.hwnd = hwnd;
9315 msg.message = message;
9316 msg.flags = sent|wparam|lparam;
9317 if (defwndproc_counter) msg.flags |= defwinproc;
9318 msg.wParam = wParam;
9319 msg.lParam = lParam;
9320 msg.descr = "edit";
9321 add_message(&msg);
9323 defwndproc_counter++;
9324 ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
9325 defwndproc_counter--;
9327 return ret;
9330 static void subclass_edit(void)
9332 WNDCLASSA cls;
9334 if (!GetClassInfoA(0, "edit", &cls)) assert(0);
9336 old_edit_proc = cls.lpfnWndProc;
9338 cls.hInstance = GetModuleHandle(0);
9339 cls.lpfnWndProc = edit_hook_proc;
9340 cls.lpszClassName = "my_edit_class";
9341 UnregisterClass(cls.lpszClassName, cls.hInstance);
9342 if (!RegisterClassA(&cls)) assert(0);
9345 static void test_edit_messages(void)
9347 HWND hwnd, parent;
9348 DWORD dlg_code;
9350 subclass_edit();
9351 log_all_parent_messages++;
9353 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9354 100, 100, 200, 200, 0, 0, 0, NULL);
9355 ok (parent != 0, "Failed to create parent window\n");
9357 /* test single line edit */
9358 hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
9359 0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9360 ok(hwnd != 0, "Failed to create edit window\n");
9362 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9363 ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
9365 ShowWindow(hwnd, SW_SHOW);
9366 UpdateWindow(hwnd);
9367 SetFocus(0);
9368 flush_sequence();
9370 SetFocus(hwnd);
9371 ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
9373 SetFocus(0);
9374 ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
9376 SetFocus(0);
9377 ReleaseCapture();
9378 flush_sequence();
9380 SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9381 ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
9383 SetFocus(0);
9384 ReleaseCapture();
9385 flush_sequence();
9387 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9388 ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
9390 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9391 ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
9393 DestroyWindow(hwnd);
9395 /* test multiline edit */
9396 hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
9397 0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9398 ok(hwnd != 0, "Failed to create edit window\n");
9400 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9401 ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
9402 "wrong dlg_code %08x\n", dlg_code);
9404 ShowWindow(hwnd, SW_SHOW);
9405 UpdateWindow(hwnd);
9406 SetFocus(0);
9407 flush_sequence();
9409 SetFocus(hwnd);
9410 ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
9412 SetFocus(0);
9413 ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
9415 SetFocus(0);
9416 ReleaseCapture();
9417 flush_sequence();
9419 SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9420 ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
9422 SetFocus(0);
9423 ReleaseCapture();
9424 flush_sequence();
9426 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9427 ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
9429 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9430 ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
9432 DestroyWindow(hwnd);
9433 DestroyWindow(parent);
9435 log_all_parent_messages--;
9438 /**************************** End of Edit test ******************************/
9440 static const struct message WmKeyDownSkippedSeq[] =
9442 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
9443 { 0 }
9445 static const struct message WmKeyDownWasDownSkippedSeq[] =
9447 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x40000001 }, /* XP */
9448 { 0 }
9450 static const struct message WmKeyUpSkippedSeq[] =
9452 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9453 { 0 }
9455 static const struct message WmUserKeyUpSkippedSeq[] =
9457 { WM_USER, sent },
9458 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9459 { 0 }
9462 #define EV_STOP 0
9463 #define EV_SENDMSG 1
9464 #define EV_ACK 2
9466 struct peekmsg_info
9468 HWND hwnd;
9469 HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
9472 static DWORD CALLBACK send_msg_thread_2(void *param)
9474 DWORD ret;
9475 struct peekmsg_info *info = param;
9477 trace("thread: looping\n");
9478 SetEvent(info->hevent[EV_ACK]);
9480 while (1)
9482 ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
9484 switch (ret)
9486 case WAIT_OBJECT_0 + EV_STOP:
9487 trace("thread: exiting\n");
9488 return 0;
9490 case WAIT_OBJECT_0 + EV_SENDMSG:
9491 trace("thread: sending message\n");
9492 ret = SendNotifyMessageA(info->hwnd, WM_USER, 0, 0);
9493 ok(ret, "SendNotifyMessageA failed error %u\n", GetLastError());
9494 SetEvent(info->hevent[EV_ACK]);
9495 break;
9497 default:
9498 trace("unexpected return: %04x\n", ret);
9499 assert(0);
9500 break;
9503 return 0;
9506 static void test_PeekMessage(void)
9508 MSG msg;
9509 HANDLE hthread;
9510 DWORD tid, qstatus;
9511 UINT qs_all_input = QS_ALLINPUT;
9512 UINT qs_input = QS_INPUT;
9513 BOOL ret;
9514 struct peekmsg_info info;
9516 info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9517 100, 100, 200, 200, 0, 0, 0, NULL);
9518 assert(info.hwnd);
9519 ShowWindow(info.hwnd, SW_SHOW);
9520 UpdateWindow(info.hwnd);
9521 SetFocus(info.hwnd);
9523 info.hevent[EV_STOP] = CreateEventA(NULL, 0, 0, NULL);
9524 info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
9525 info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
9527 hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
9528 WaitForSingleObject(info.hevent[EV_ACK], 10000);
9530 flush_events();
9531 flush_sequence();
9533 SetLastError(0xdeadbeef);
9534 qstatus = GetQueueStatus(qs_all_input);
9535 if (GetLastError() == ERROR_INVALID_FLAGS)
9537 trace("QS_RAWINPUT not supported on this platform\n");
9538 qs_all_input &= ~QS_RAWINPUT;
9539 qs_input &= ~QS_RAWINPUT;
9541 if (qstatus & QS_POSTMESSAGE)
9543 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) /* nothing */ ;
9544 qstatus = GetQueueStatus(qs_all_input);
9546 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9548 trace("signalling to send message\n");
9549 SetEvent(info.hevent[EV_SENDMSG]);
9550 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9552 /* pass invalid QS_xxxx flags */
9553 SetLastError(0xdeadbeef);
9554 qstatus = GetQueueStatus(0xffffffff);
9555 ok(qstatus == 0 || broken(qstatus) /* win9x */, "GetQueueStatus should fail: %08x\n", qstatus);
9556 if (!qstatus)
9558 ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
9559 qstatus = GetQueueStatus(qs_all_input);
9561 qstatus &= ~MAKELONG( 0x4000, 0x4000 ); /* sometimes set on Win95 */
9562 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
9563 "wrong qstatus %08x\n", qstatus);
9565 msg.message = 0;
9566 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9567 ok(!ret,
9568 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9569 msg.message);
9570 ok_sequence(WmUser, "WmUser", FALSE);
9572 qstatus = GetQueueStatus(qs_all_input);
9573 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9575 keybd_event('N', 0, 0, 0);
9576 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9577 qstatus = GetQueueStatus(qs_all_input);
9578 if (!(qstatus & MAKELONG(QS_KEY, QS_KEY)))
9580 skip( "queuing key events not supported\n" );
9581 goto done;
9583 ok(qstatus == MAKELONG(QS_KEY, QS_KEY) ||
9584 /* keybd_event seems to trigger a sent message on NT4 */
9585 qstatus == MAKELONG(QS_KEY|QS_SENDMESSAGE, QS_KEY|QS_SENDMESSAGE),
9586 "wrong qstatus %08x\n", qstatus);
9588 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9589 qstatus = GetQueueStatus(qs_all_input);
9590 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY) ||
9591 qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY|QS_SENDMESSAGE),
9592 "wrong qstatus %08x\n", qstatus);
9594 InvalidateRect(info.hwnd, NULL, FALSE);
9595 qstatus = GetQueueStatus(qs_all_input);
9596 ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY) ||
9597 qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY|QS_SENDMESSAGE),
9598 "wrong qstatus %08x\n", qstatus);
9600 trace("signalling to send message\n");
9601 SetEvent(info.hevent[EV_SENDMSG]);
9602 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9604 qstatus = GetQueueStatus(qs_all_input);
9605 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9606 "wrong qstatus %08x\n", qstatus);
9608 msg.message = 0;
9609 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
9610 if (ret && msg.message == WM_CHAR)
9612 win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9613 goto done;
9615 ok(!ret,
9616 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9617 msg.message);
9618 if (!sequence_cnt) /* nt4 doesn't fetch anything with PM_QS_* flags */
9620 win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9621 goto done;
9623 ok_sequence(WmUser, "WmUser", FALSE);
9625 qstatus = GetQueueStatus(qs_all_input);
9626 ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9627 "wrong qstatus %08x\n", qstatus);
9629 trace("signalling to send message\n");
9630 SetEvent(info.hevent[EV_SENDMSG]);
9631 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9633 qstatus = GetQueueStatus(qs_all_input);
9634 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9635 "wrong qstatus %08x\n", qstatus);
9637 msg.message = 0;
9638 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE );
9639 ok(!ret,
9640 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9641 msg.message);
9642 ok_sequence(WmUser, "WmUser", FALSE);
9644 qstatus = GetQueueStatus(qs_all_input);
9645 ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9646 "wrong qstatus %08x\n", qstatus);
9648 msg.message = 0;
9649 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9650 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9651 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9652 ret, msg.message, msg.wParam);
9653 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9655 qstatus = GetQueueStatus(qs_all_input);
9656 ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9657 "wrong qstatus %08x\n", qstatus);
9659 msg.message = 0;
9660 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9661 ok(!ret,
9662 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9663 msg.message);
9664 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9666 qstatus = GetQueueStatus(qs_all_input);
9667 ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9668 "wrong qstatus %08x\n", qstatus);
9670 msg.message = 0;
9671 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9672 ok(ret && msg.message == WM_PAINT,
9673 "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
9674 DispatchMessageA(&msg);
9675 ok_sequence(WmPaint, "WmPaint", FALSE);
9677 qstatus = GetQueueStatus(qs_all_input);
9678 ok(qstatus == MAKELONG(0, QS_KEY),
9679 "wrong qstatus %08x\n", qstatus);
9681 msg.message = 0;
9682 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9683 ok(!ret,
9684 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9685 msg.message);
9686 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9688 qstatus = GetQueueStatus(qs_all_input);
9689 ok(qstatus == MAKELONG(0, QS_KEY),
9690 "wrong qstatus %08x\n", qstatus);
9692 trace("signalling to send message\n");
9693 SetEvent(info.hevent[EV_SENDMSG]);
9694 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9696 qstatus = GetQueueStatus(qs_all_input);
9697 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
9698 "wrong qstatus %08x\n", qstatus);
9700 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9702 qstatus = GetQueueStatus(qs_all_input);
9703 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9704 "wrong qstatus %08x\n", qstatus);
9706 msg.message = 0;
9707 ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9708 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9709 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9710 ret, msg.message, msg.wParam);
9711 ok_sequence(WmUser, "WmUser", FALSE);
9713 qstatus = GetQueueStatus(qs_all_input);
9714 ok(qstatus == MAKELONG(0, QS_KEY),
9715 "wrong qstatus %08x\n", qstatus);
9717 msg.message = 0;
9718 ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9719 ok(!ret,
9720 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9721 msg.message);
9722 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9724 qstatus = GetQueueStatus(qs_all_input);
9725 ok(qstatus == MAKELONG(0, QS_KEY),
9726 "wrong qstatus %08x\n", qstatus);
9728 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9730 qstatus = GetQueueStatus(qs_all_input);
9731 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9732 "wrong qstatus %08x\n", qstatus);
9734 trace("signalling to send message\n");
9735 SetEvent(info.hevent[EV_SENDMSG]);
9736 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9738 qstatus = GetQueueStatus(qs_all_input);
9739 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9740 "wrong qstatus %08x\n", qstatus);
9742 msg.message = 0;
9743 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
9744 ok(!ret,
9745 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9746 msg.message);
9747 ok_sequence(WmUser, "WmUser", FALSE);
9749 qstatus = GetQueueStatus(qs_all_input);
9750 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9751 "wrong qstatus %08x\n", qstatus);
9753 msg.message = 0;
9754 if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9755 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9756 else /* workaround for a missing QS_RAWINPUT support */
9757 ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
9758 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9759 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9760 ret, msg.message, msg.wParam);
9761 ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9763 qstatus = GetQueueStatus(qs_all_input);
9764 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9765 "wrong qstatus %08x\n", qstatus);
9767 msg.message = 0;
9768 if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9769 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9770 else /* workaround for a missing QS_RAWINPUT support */
9771 ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
9772 ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9773 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
9774 ret, msg.message, msg.wParam);
9775 ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
9777 qstatus = GetQueueStatus(qs_all_input);
9778 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9779 "wrong qstatus %08x\n", qstatus);
9781 msg.message = 0;
9782 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
9783 ok(!ret,
9784 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9785 msg.message);
9786 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9788 qstatus = GetQueueStatus(qs_all_input);
9789 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9790 "wrong qstatus %08x\n", qstatus);
9792 msg.message = 0;
9793 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9794 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9795 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9796 ret, msg.message, msg.wParam);
9797 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9799 qstatus = GetQueueStatus(qs_all_input);
9800 ok(qstatus == 0,
9801 "wrong qstatus %08x\n", qstatus);
9803 msg.message = 0;
9804 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9805 ok(!ret,
9806 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9807 msg.message);
9808 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9810 qstatus = GetQueueStatus(qs_all_input);
9811 ok(qstatus == 0,
9812 "wrong qstatus %08x\n", qstatus);
9814 /* test whether presence of the quit flag in the queue affects
9815 * the queue state
9817 PostQuitMessage(0x1234abcd);
9819 qstatus = GetQueueStatus(qs_all_input);
9820 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9821 "wrong qstatus %08x\n", qstatus);
9823 PostMessageA(info.hwnd, WM_USER, 0, 0);
9825 qstatus = GetQueueStatus(qs_all_input);
9826 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9827 "wrong qstatus %08x\n", qstatus);
9829 msg.message = 0;
9830 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9831 ok(ret && msg.message == WM_USER,
9832 "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
9833 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9835 qstatus = GetQueueStatus(qs_all_input);
9836 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9837 "wrong qstatus %08x\n", qstatus);
9839 msg.message = 0;
9840 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9841 ok(ret && msg.message == WM_QUIT,
9842 "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
9843 ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
9844 ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
9845 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9847 qstatus = GetQueueStatus(qs_all_input);
9848 todo_wine {
9849 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9850 "wrong qstatus %08x\n", qstatus);
9853 msg.message = 0;
9854 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9855 ok(!ret,
9856 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9857 msg.message);
9858 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9860 qstatus = GetQueueStatus(qs_all_input);
9861 ok(qstatus == 0,
9862 "wrong qstatus %08x\n", qstatus);
9864 /* some GetMessage tests */
9866 keybd_event('N', 0, 0, 0);
9867 qstatus = GetQueueStatus(qs_all_input);
9868 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9870 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9871 qstatus = GetQueueStatus(qs_all_input);
9872 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9874 if (qstatus)
9876 ret = GetMessageA( &msg, 0, 0, 0 );
9877 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9878 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9879 ret, msg.message, msg.wParam);
9880 qstatus = GetQueueStatus(qs_all_input);
9881 ok(qstatus == MAKELONG(0, QS_KEY), "wrong qstatus %08x\n", qstatus);
9884 if (qstatus)
9886 ret = GetMessageA( &msg, 0, 0, 0 );
9887 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9888 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9889 ret, msg.message, msg.wParam);
9890 ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9891 qstatus = GetQueueStatus(qs_all_input);
9892 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9895 keybd_event('N', 0, 0, 0);
9896 qstatus = GetQueueStatus(qs_all_input);
9897 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9899 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9900 qstatus = GetQueueStatus(qs_all_input);
9901 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9903 if (qstatus & (QS_KEY << 16))
9905 ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9906 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9907 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9908 ret, msg.message, msg.wParam);
9909 ok_sequence(WmKeyDownWasDownSkippedSeq, "WmKeyDownWasDownSkippedSeq", FALSE);
9910 qstatus = GetQueueStatus(qs_all_input);
9911 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9914 if (qstatus)
9916 ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9917 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9918 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9919 ret, msg.message, msg.wParam);
9920 qstatus = GetQueueStatus(qs_all_input);
9921 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9924 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9925 qstatus = GetQueueStatus(qs_all_input);
9926 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9928 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9929 qstatus = GetQueueStatus(qs_all_input);
9930 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9932 trace("signalling to send message\n");
9933 SetEvent(info.hevent[EV_SENDMSG]);
9934 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9935 qstatus = GetQueueStatus(qs_all_input);
9936 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9937 "wrong qstatus %08x\n", qstatus);
9939 if (qstatus & (QS_KEY << 16))
9941 ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9942 ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9943 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9944 ret, msg.message, msg.wParam);
9945 ok_sequence(WmUserKeyUpSkippedSeq, "WmUserKeyUpSkippedSeq", FALSE);
9946 qstatus = GetQueueStatus(qs_all_input);
9947 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9950 if (qstatus)
9952 ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9953 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9954 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9955 ret, msg.message, msg.wParam);
9956 qstatus = GetQueueStatus(qs_all_input);
9957 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9959 done:
9960 trace("signalling to exit\n");
9961 SetEvent(info.hevent[EV_STOP]);
9963 WaitForSingleObject(hthread, INFINITE);
9965 CloseHandle(hthread);
9966 CloseHandle(info.hevent[0]);
9967 CloseHandle(info.hevent[1]);
9968 CloseHandle(info.hevent[2]);
9970 DestroyWindow(info.hwnd);
9973 static void wait_move_event(HWND hwnd, int x, int y)
9975 MSG msg;
9976 DWORD time;
9977 BOOL ret;
9978 int go = 0;
9980 time = GetTickCount();
9981 while (GetTickCount() - time < 200 && !go) {
9982 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9983 go = ret && msg.pt.x > x && msg.pt.y > y;
9984 if (!ret) MsgWaitForMultipleObjects( 0, NULL, FALSE, GetTickCount() - time, QS_ALLINPUT );
9988 #define STEP 5
9989 static void test_PeekMessage2(void)
9991 HWND hwnd;
9992 BOOL ret;
9993 MSG msg;
9994 UINT message;
9995 DWORD time1, time2, time3;
9996 int x1, y1, x2, y2, x3, y3;
9997 POINT pos;
9999 time1 = time2 = time3 = 0;
10000 x1 = y1 = x2 = y2 = x3 = y3 = 0;
10002 /* Initialise window and make sure it is ready for events */
10003 hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
10004 10, 10, 800, 800, NULL, NULL, NULL, NULL);
10005 assert(hwnd);
10006 trace("Window for test_PeekMessage2 %p\n", hwnd);
10007 ShowWindow(hwnd, SW_SHOW);
10008 UpdateWindow(hwnd);
10009 SetFocus(hwnd);
10010 GetCursorPos(&pos);
10011 SetCursorPos(100, 100);
10012 mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
10013 flush_events();
10015 /* Do initial mousemove, wait until we can see it
10016 and then do our test peek with PM_NOREMOVE. */
10017 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
10018 wait_move_event(hwnd, 100-STEP, 100-STEP);
10020 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
10021 if (!ret)
10023 skip( "queuing mouse events not supported\n" );
10024 goto done;
10026 else
10028 trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
10029 message = msg.message;
10030 time1 = msg.time;
10031 x1 = msg.pt.x;
10032 y1 = msg.pt.y;
10033 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
10036 /* Allow time to advance a bit, and then simulate the user moving their
10037 * mouse around. After that we peek again with PM_NOREMOVE.
10038 * Although the previous mousemove message was never removed, the
10039 * mousemove we now peek should reflect the recent mouse movements
10040 * because the input queue will merge the move events. */
10041 Sleep(100);
10042 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
10043 wait_move_event(hwnd, x1, y1);
10045 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
10046 ok(ret, "no message available\n");
10047 if (ret) {
10048 trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
10049 message = msg.message;
10050 time2 = msg.time;
10051 x2 = msg.pt.x;
10052 y2 = msg.pt.y;
10053 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
10054 ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
10055 ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
10058 /* Have another go, to drive the point home */
10059 Sleep(100);
10060 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
10061 wait_move_event(hwnd, x2, y2);
10063 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
10064 ok(ret, "no message available\n");
10065 if (ret) {
10066 trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
10067 message = msg.message;
10068 time3 = msg.time;
10069 x3 = msg.pt.x;
10070 y3 = msg.pt.y;
10071 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
10072 ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
10073 ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
10076 done:
10077 DestroyWindow(hwnd);
10078 SetCursorPos(pos.x, pos.y);
10079 flush_events();
10082 static INT_PTR CALLBACK wm_quit_dlg_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
10084 struct recvd_message msg;
10086 if (ignore_message( message )) return 0;
10088 msg.hwnd = hwnd;
10089 msg.message = message;
10090 msg.flags = sent|wparam|lparam;
10091 msg.wParam = wp;
10092 msg.lParam = lp;
10093 msg.descr = "dialog";
10094 add_message(&msg);
10096 switch (message)
10098 case WM_INITDIALOG:
10099 PostMessage(hwnd, WM_QUIT, 0x1234, 0x5678);
10100 PostMessage(hwnd, WM_USER, 0xdead, 0xbeef);
10101 return 0;
10103 case WM_GETDLGCODE:
10104 return 0;
10106 case WM_USER:
10107 EndDialog(hwnd, 0);
10108 break;
10111 return 1;
10114 static const struct message WmQuitDialogSeq[] = {
10115 { HCBT_CREATEWND, hook },
10116 { WM_SETFONT, sent },
10117 { WM_INITDIALOG, sent },
10118 { WM_CHANGEUISTATE, sent|optional },
10119 { HCBT_DESTROYWND, hook },
10120 { 0x0090, sent|optional }, /* Vista */
10121 { WM_DESTROY, sent },
10122 { WM_NCDESTROY, sent },
10123 { 0 }
10126 static const struct message WmStopQuitSeq[] = {
10127 { WM_DWMNCRENDERINGCHANGED, posted|optional },
10128 { WM_CLOSE, posted },
10129 { WM_QUIT, posted|wparam|lparam, 0x1234, 0 },
10130 { 0 }
10133 static void test_quit_message(void)
10135 MSG msg;
10136 BOOL ret;
10138 /* test using PostQuitMessage */
10139 flush_events();
10140 PostQuitMessage(0xbeef);
10142 ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
10143 ok(ret, "PeekMessage failed with error %d\n", GetLastError());
10144 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10145 ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
10147 ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
10148 ok(ret, "PostMessage failed with error %d\n", GetLastError());
10150 ret = GetMessage(&msg, NULL, 0, 0);
10151 ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
10152 ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
10154 /* note: WM_QUIT message received after WM_USER message */
10155 ret = GetMessage(&msg, NULL, 0, 0);
10156 ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
10157 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10158 ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
10160 ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
10161 ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
10163 /* now test with PostThreadMessage - different behaviour! */
10164 PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
10166 ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
10167 ok(ret, "PeekMessage failed with error %d\n", GetLastError());
10168 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10169 ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
10171 ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
10172 ok(ret, "PostMessage failed with error %d\n", GetLastError());
10174 /* note: we receive the WM_QUIT message first this time */
10175 ret = GetMessage(&msg, NULL, 0, 0);
10176 ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
10177 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10178 ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
10180 ret = GetMessage(&msg, NULL, 0, 0);
10181 ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
10182 ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
10184 flush_events();
10185 flush_sequence();
10186 ret = DialogBoxParam(GetModuleHandle(0), "TEST_EMPTY_DIALOG", 0, wm_quit_dlg_proc, 0);
10187 ok(ret == 1, "expected 1, got %d\n", ret);
10188 ok_sequence(WmQuitDialogSeq, "WmQuitDialogSeq", FALSE);
10189 memset(&msg, 0xab, sizeof(msg));
10190 ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
10191 ok(ret, "PeekMessage failed\n");
10192 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10193 ok(msg.wParam == 0x1234, "wParam was 0x%lx instead of 0x1234\n", msg.wParam);
10194 ok(msg.lParam == 0, "lParam was 0x%lx instead of 0\n", msg.lParam);
10196 /* Check what happens to a WM_QUIT message posted to a window that gets
10197 * destroyed.
10199 CreateWindowExA(0, "StopQuitClass", "Stop Quit Test", WS_OVERLAPPEDWINDOW,
10200 0, 0, 100, 100, NULL, NULL, NULL, NULL);
10201 flush_sequence();
10202 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
10204 struct recvd_message rmsg;
10205 rmsg.hwnd = msg.hwnd;
10206 rmsg.message = msg.message;
10207 rmsg.flags = posted|wparam|lparam;
10208 rmsg.wParam = msg.wParam;
10209 rmsg.lParam = msg.lParam;
10210 rmsg.descr = "stop/quit";
10211 if (msg.message == WM_QUIT)
10212 /* The hwnd can only be checked here */
10213 ok(!msg.hwnd, "The WM_QUIT hwnd was %p instead of NULL\n", msg.hwnd);
10214 add_message(&rmsg);
10215 DispatchMessage(&msg);
10217 ok_sequence(WmStopQuitSeq, "WmStopQuitSeq", FALSE);
10220 static const struct message WmMouseHoverSeq[] = {
10221 { WM_MOUSEACTIVATE, sent|optional }, /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
10222 { WM_MOUSEACTIVATE, sent|optional },
10223 { WM_TIMER, sent|optional }, /* XP sends it */
10224 { WM_SYSTIMER, sent },
10225 { WM_MOUSEHOVER, sent|wparam, 0 },
10226 { 0 }
10229 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
10231 MSG msg;
10232 DWORD start_ticks, end_ticks;
10234 start_ticks = GetTickCount();
10235 /* add some deviation (50%) to cover not expected delays */
10236 start_ticks += timeout / 2;
10240 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
10242 /* Timer proc messages are not dispatched to the window proc,
10243 * and therefore not logged.
10245 if ((msg.message == WM_TIMER || msg.message == WM_SYSTIMER) && msg.hwnd)
10247 struct recvd_message s_msg;
10249 s_msg.hwnd = msg.hwnd;
10250 s_msg.message = msg.message;
10251 s_msg.flags = sent|wparam|lparam;
10252 s_msg.wParam = msg.wParam;
10253 s_msg.lParam = msg.lParam;
10254 s_msg.descr = "msg_loop";
10255 add_message(&s_msg);
10257 DispatchMessage(&msg);
10260 end_ticks = GetTickCount();
10262 /* inject WM_MOUSEMOVE to see how it changes tracking */
10263 if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
10265 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
10266 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
10268 inject_mouse_move = FALSE;
10270 } while (start_ticks + timeout >= end_ticks);
10273 static void test_TrackMouseEvent(void)
10275 TRACKMOUSEEVENT tme;
10276 BOOL ret;
10277 HWND hwnd, hchild;
10278 RECT rc_parent, rc_child;
10279 UINT default_hover_time, hover_width = 0, hover_height = 0;
10281 #define track_hover(track_hwnd, track_hover_time) \
10282 tme.cbSize = sizeof(tme); \
10283 tme.dwFlags = TME_HOVER; \
10284 tme.hwndTrack = track_hwnd; \
10285 tme.dwHoverTime = track_hover_time; \
10286 SetLastError(0xdeadbeef); \
10287 ret = pTrackMouseEvent(&tme); \
10288 ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
10290 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
10291 tme.cbSize = sizeof(tme); \
10292 tme.dwFlags = TME_QUERY; \
10293 tme.hwndTrack = (HWND)0xdeadbeef; \
10294 tme.dwHoverTime = 0xdeadbeef; \
10295 SetLastError(0xdeadbeef); \
10296 ret = pTrackMouseEvent(&tme); \
10297 ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
10298 ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
10299 ok(tme.dwFlags == (expected_track_flags), \
10300 "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
10301 ok(tme.hwndTrack == (expected_track_hwnd), \
10302 "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
10303 ok(tme.dwHoverTime == (expected_hover_time), \
10304 "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
10306 #define track_hover_cancel(track_hwnd) \
10307 tme.cbSize = sizeof(tme); \
10308 tme.dwFlags = TME_HOVER | TME_CANCEL; \
10309 tme.hwndTrack = track_hwnd; \
10310 tme.dwHoverTime = 0xdeadbeef; \
10311 SetLastError(0xdeadbeef); \
10312 ret = pTrackMouseEvent(&tme); \
10313 ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
10315 default_hover_time = 0xdeadbeef;
10316 SetLastError(0xdeadbeef);
10317 ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
10318 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
10319 "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
10320 if (!ret) default_hover_time = 400;
10321 trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
10323 SetLastError(0xdeadbeef);
10324 ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
10325 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
10326 "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
10327 if (!ret) hover_width = 4;
10328 SetLastError(0xdeadbeef);
10329 ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
10330 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
10331 "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
10332 if (!ret) hover_height = 4;
10333 trace("hover rect is %u x %d\n", hover_width, hover_height);
10335 hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
10336 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10337 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
10338 NULL, NULL, 0);
10339 assert(hwnd);
10341 hchild = CreateWindowEx(0, "TestWindowClass", NULL,
10342 WS_CHILD | WS_BORDER | WS_VISIBLE,
10343 50, 50, 200, 200, hwnd,
10344 NULL, NULL, 0);
10345 assert(hchild);
10347 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
10348 flush_events();
10349 flush_sequence();
10351 tme.cbSize = 0;
10352 tme.dwFlags = TME_QUERY;
10353 tme.hwndTrack = (HWND)0xdeadbeef;
10354 tme.dwHoverTime = 0xdeadbeef;
10355 SetLastError(0xdeadbeef);
10356 ret = pTrackMouseEvent(&tme);
10357 ok(!ret, "TrackMouseEvent should fail\n");
10358 ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef),
10359 "not expected error %u\n", GetLastError());
10361 tme.cbSize = sizeof(tme);
10362 tme.dwFlags = TME_HOVER;
10363 tme.hwndTrack = (HWND)0xdeadbeef;
10364 tme.dwHoverTime = 0xdeadbeef;
10365 SetLastError(0xdeadbeef);
10366 ret = pTrackMouseEvent(&tme);
10367 ok(!ret, "TrackMouseEvent should fail\n");
10368 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10369 "not expected error %u\n", GetLastError());
10371 tme.cbSize = sizeof(tme);
10372 tme.dwFlags = TME_HOVER | TME_CANCEL;
10373 tme.hwndTrack = (HWND)0xdeadbeef;
10374 tme.dwHoverTime = 0xdeadbeef;
10375 SetLastError(0xdeadbeef);
10376 ret = pTrackMouseEvent(&tme);
10377 ok(!ret, "TrackMouseEvent should fail\n");
10378 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10379 "not expected error %u\n", GetLastError());
10381 GetWindowRect(hwnd, &rc_parent);
10382 GetWindowRect(hchild, &rc_child);
10383 SetCursorPos(rc_child.left - 10, rc_child.top - 10);
10385 /* Process messages so that the system updates its internal current
10386 * window and hittest, otherwise TrackMouseEvent calls don't have any
10387 * effect.
10389 flush_events();
10390 flush_sequence();
10392 track_query(0, NULL, 0);
10393 track_hover(hchild, 0);
10394 track_query(0, NULL, 0);
10396 flush_events();
10397 flush_sequence();
10399 track_hover(hwnd, 0);
10400 tme.cbSize = sizeof(tme);
10401 tme.dwFlags = TME_QUERY;
10402 tme.hwndTrack = (HWND)0xdeadbeef;
10403 tme.dwHoverTime = 0xdeadbeef;
10404 SetLastError(0xdeadbeef);
10405 ret = pTrackMouseEvent(&tme);
10406 ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());
10407 ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize);
10408 if (!tme.dwFlags)
10410 skip( "Cursor not inside window, skipping TrackMouseEvent tests\n" );
10411 DestroyWindow( hwnd );
10412 return;
10414 ok(tme.dwFlags == TME_HOVER, "wrong tme.dwFlags %08x, expected TME_HOVER\n", tme.dwFlags);
10415 ok(tme.hwndTrack == hwnd, "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, hwnd);
10416 ok(tme.dwHoverTime == default_hover_time, "wrong tme.dwHoverTime %u, expected %u\n",
10417 tme.dwHoverTime, default_hover_time);
10419 pump_msg_loop_timeout(default_hover_time, FALSE);
10420 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10422 track_query(0, NULL, 0);
10424 track_hover(hwnd, HOVER_DEFAULT);
10425 track_query(TME_HOVER, hwnd, default_hover_time);
10427 Sleep(default_hover_time / 2);
10428 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
10429 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
10431 track_query(TME_HOVER, hwnd, default_hover_time);
10433 pump_msg_loop_timeout(default_hover_time, FALSE);
10434 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10436 track_query(0, NULL, 0);
10438 track_hover(hwnd, HOVER_DEFAULT);
10439 track_query(TME_HOVER, hwnd, default_hover_time);
10441 pump_msg_loop_timeout(default_hover_time, TRUE);
10442 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10444 track_query(0, NULL, 0);
10446 track_hover(hwnd, HOVER_DEFAULT);
10447 track_query(TME_HOVER, hwnd, default_hover_time);
10448 track_hover_cancel(hwnd);
10450 DestroyWindow(hwnd);
10452 #undef track_hover
10453 #undef track_query
10454 #undef track_hover_cancel
10458 static const struct message WmSetWindowRgn[] = {
10459 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10460 { WM_NCCALCSIZE, sent|wparam, 1 },
10461 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
10462 { WM_GETTEXT, sent|defwinproc|optional },
10463 { WM_ERASEBKGND, sent|optional },
10464 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10465 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10466 { 0 }
10469 static const struct message WmSetWindowRgn_no_redraw[] = {
10470 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10471 { WM_NCCALCSIZE, sent|wparam, 1 },
10472 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10473 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10474 { 0 }
10477 static const struct message WmSetWindowRgn_clear[] = {
10478 { WM_WINDOWPOSCHANGING, sent/*|wparam*/, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE/*|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE only on some Windows versions */ },
10479 { WM_NCCALCSIZE, sent|wparam, 1 },
10480 { WM_NCPAINT, sent|optional },
10481 { WM_GETTEXT, sent|defwinproc|optional },
10482 { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
10483 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10484 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
10485 { WM_NCPAINT, sent|optional },
10486 { WM_GETTEXT, sent|defwinproc|optional },
10487 { WM_ERASEBKGND, sent|optional },
10488 { WM_WINDOWPOSCHANGING, sent|optional },
10489 { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10490 { WM_NCPAINT, sent|optional },
10491 { WM_GETTEXT, sent|defwinproc|optional },
10492 { WM_ERASEBKGND, sent|optional },
10493 { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10494 { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10495 { WM_NCPAINT, sent|optional },
10496 { WM_GETTEXT, sent|defwinproc|optional },
10497 { WM_ERASEBKGND, sent|optional },
10498 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10499 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10500 { 0 }
10503 static void test_SetWindowRgn(void)
10505 HRGN hrgn;
10506 HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10507 100, 100, 200, 200, 0, 0, 0, NULL);
10508 ok( hwnd != 0, "Failed to create overlapped window\n" );
10510 ShowWindow( hwnd, SW_SHOW );
10511 UpdateWindow( hwnd );
10512 flush_events();
10513 flush_sequence();
10515 trace("testing SetWindowRgn\n");
10516 hrgn = CreateRectRgn( 0, 0, 150, 150 );
10517 SetWindowRgn( hwnd, hrgn, TRUE );
10518 ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
10520 hrgn = CreateRectRgn( 30, 30, 160, 160 );
10521 SetWindowRgn( hwnd, hrgn, FALSE );
10522 ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
10524 hrgn = CreateRectRgn( 0, 0, 180, 180 );
10525 SetWindowRgn( hwnd, hrgn, TRUE );
10526 ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
10528 SetWindowRgn( hwnd, 0, TRUE );
10529 ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
10531 DestroyWindow( hwnd );
10534 /*************************** ShowWindow() test ******************************/
10535 static const struct message WmShowNormal[] = {
10536 { WM_SHOWWINDOW, sent|wparam, 1 },
10537 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10538 { HCBT_ACTIVATE, hook },
10539 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10540 { HCBT_SETFOCUS, hook },
10541 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10542 { 0 }
10544 static const struct message WmShow[] = {
10545 { WM_SHOWWINDOW, sent|wparam, 1 },
10546 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10547 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10548 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10549 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10550 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10551 { 0 }
10553 static const struct message WmShowNoActivate_1[] = {
10554 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10555 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10556 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10557 { WM_MOVE, sent|defwinproc|optional },
10558 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10559 { 0 }
10561 static const struct message WmShowNoActivate_2[] = {
10562 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10563 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10564 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10565 { WM_MOVE, sent|defwinproc },
10566 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10567 { HCBT_SETFOCUS, hook|optional },
10568 { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10569 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10570 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10571 { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10572 { 0 }
10574 static const struct message WmShowNA_1[] = {
10575 { WM_SHOWWINDOW, sent|wparam, 1 },
10576 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10577 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10578 { 0 }
10580 static const struct message WmShowNA_2[] = {
10581 { WM_SHOWWINDOW, sent|wparam, 1 },
10582 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10583 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10584 { 0 }
10586 static const struct message WmRestore_1[] = {
10587 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10588 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10589 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10590 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10591 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10592 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10593 { WM_MOVE, sent|defwinproc },
10594 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10595 { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10596 { 0 }
10598 static const struct message WmRestore_2[] = {
10599 { WM_SHOWWINDOW, sent|wparam, 1 },
10600 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10601 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10602 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10603 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10604 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10605 { 0 }
10607 static const struct message WmRestore_3[] = {
10608 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10609 { WM_GETMINMAXINFO, sent },
10610 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10611 { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10612 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10613 { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10614 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10615 { WM_MOVE, sent|defwinproc },
10616 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10617 { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10618 { 0 }
10620 static const struct message WmRestore_4[] = {
10621 { HCBT_MINMAX, hook|lparam|optional, 0, SW_RESTORE },
10622 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10623 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10624 { WM_MOVE, sent|defwinproc|optional },
10625 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10626 { 0 }
10628 static const struct message WmRestore_5[] = {
10629 { HCBT_MINMAX, hook|lparam|optional, 0, SW_SHOWNORMAL },
10630 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10631 { HCBT_ACTIVATE, hook|optional },
10632 { HCBT_SETFOCUS, hook|optional },
10633 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10634 { WM_MOVE, sent|defwinproc|optional },
10635 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10636 { 0 }
10638 static const struct message WmHide_1[] = {
10639 { WM_SHOWWINDOW, sent|wparam, 0 },
10640 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOACTIVATE },
10641 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOACTIVATE },
10642 { HCBT_ACTIVATE, hook|optional },
10643 { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10644 { 0 }
10646 static const struct message WmHide_2[] = {
10647 { WM_SHOWWINDOW, sent|wparam, 0 },
10648 { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10649 { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10650 { HCBT_ACTIVATE, hook|optional },
10651 { 0 }
10653 static const struct message WmHide_3[] = {
10654 { WM_SHOWWINDOW, sent|wparam, 0 },
10655 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10656 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10657 { HCBT_SETFOCUS, hook|optional },
10658 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10659 { 0 }
10661 static const struct message WmShowMinimized_1[] = {
10662 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10663 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10664 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10665 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10666 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10667 { WM_MOVE, sent|defwinproc },
10668 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10669 { 0 }
10671 static const struct message WmMinimize_1[] = {
10672 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10673 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10674 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10675 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10676 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10677 { WM_MOVE, sent|defwinproc },
10678 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10679 { 0 }
10681 static const struct message WmMinimize_2[] = {
10682 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10683 { HCBT_SETFOCUS, hook|optional },
10684 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10685 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10686 { WM_MOVE, sent|defwinproc },
10687 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10688 { 0 }
10690 static const struct message WmMinimize_3[] = {
10691 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10692 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10693 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10694 { WM_MOVE, sent|defwinproc },
10695 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10696 { 0 }
10698 static const struct message WmShowMinNoActivate[] = {
10699 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10700 { WM_WINDOWPOSCHANGING, sent },
10701 { WM_WINDOWPOSCHANGED, sent },
10702 { WM_MOVE, sent|defwinproc|optional },
10703 { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
10704 { 0 }
10706 static const struct message WmMinMax_1[] = {
10707 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10708 { 0 }
10710 static const struct message WmMinMax_2[] = {
10711 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10712 { WM_GETMINMAXINFO, sent|optional },
10713 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED },
10714 { HCBT_ACTIVATE, hook|optional },
10715 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10716 { HCBT_SETFOCUS, hook|optional },
10717 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10718 { WM_MOVE, sent|defwinproc|optional },
10719 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MAXIMIZED },
10720 { HCBT_SETFOCUS, hook|optional },
10721 { 0 }
10723 static const struct message WmMinMax_3[] = {
10724 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10725 { HCBT_SETFOCUS, hook|optional },
10726 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10727 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10728 { WM_MOVE, sent|defwinproc|optional },
10729 { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
10730 { 0 }
10732 static const struct message WmMinMax_4[] = {
10733 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10734 { 0 }
10736 static const struct message WmShowMaximized_1[] = {
10737 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10738 { WM_GETMINMAXINFO, sent },
10739 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10740 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10741 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10742 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10743 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10744 { WM_MOVE, sent|defwinproc },
10745 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10746 { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10747 { 0 }
10749 static const struct message WmShowMaximized_2[] = {
10750 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10751 { WM_GETMINMAXINFO, sent },
10752 { WM_WINDOWPOSCHANGING, sent|optional },
10753 { HCBT_ACTIVATE, hook|optional },
10754 { WM_WINDOWPOSCHANGED, sent|optional },
10755 { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
10756 { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
10757 { WM_WINDOWPOSCHANGING, sent|optional },
10758 { HCBT_SETFOCUS, hook|optional },
10759 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10760 { WM_MOVE, sent|defwinproc },
10761 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10762 { HCBT_SETFOCUS, hook|optional },
10763 { 0 }
10765 static const struct message WmShowMaximized_3[] = {
10766 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10767 { WM_GETMINMAXINFO, sent|optional },
10768 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10769 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10770 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10771 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10772 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10773 { WM_MOVE, sent|defwinproc|optional },
10774 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10775 { 0 }
10778 static void test_ShowWindow(void)
10780 /* ShowWindow commands in random order */
10781 static const struct
10783 INT cmd; /* ShowWindow command */
10784 LPARAM ret; /* ShowWindow return value */
10785 DWORD style; /* window style after the command */
10786 const struct message *msg; /* message sequence the command produces */
10787 INT wp_cmd, wp_flags; /* window placement after the command */
10788 POINT wp_min, wp_max; /* window placement after the command */
10789 BOOL todo_msg; /* message sequence doesn't match what Wine does */
10790 } sw[] =
10792 /* 1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal,
10793 SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10794 /* 2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq,
10795 SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10796 /* 3 */ { SW_HIDE, TRUE, 0, WmHide_1,
10797 SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10798 /* 4 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10799 SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10800 /* 5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1,
10801 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10802 /* 6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1,
10803 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10804 /* 7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1,
10805 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10806 /* 8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq,
10807 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10808 /* 9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1,
10809 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10810 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2,
10811 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10812 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1,
10813 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10814 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq,
10815 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10816 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1,
10817 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10818 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq,
10819 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10820 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2,
10821 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10822 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10823 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10824 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow,
10825 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10826 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq,
10827 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10828 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1,
10829 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10830 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3,
10831 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10832 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
10833 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10834 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate,
10835 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, TRUE },
10836 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4,
10837 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10838 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
10839 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10840 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq,
10841 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10842 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1,
10843 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10844 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2,
10845 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10846 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
10847 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10848 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq,
10849 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10850 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1,
10851 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10852 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq,
10853 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10854 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3,
10855 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10856 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10857 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10858 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, /* what does this mean?! */
10859 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10860 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq,
10861 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10862 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10863 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10864 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2,
10865 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10866 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq,
10867 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10868 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq,
10869 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10870 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2,
10871 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10872 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3,
10873 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10874 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2,
10875 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10876 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2,
10877 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10878 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1,
10879 SW_SHOWMINIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10880 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3,
10881 SW_SHOWMINIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10882 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3,
10883 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10884 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4,
10885 SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10886 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3,
10887 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10888 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq,
10889 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10890 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5,
10891 SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10892 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5,
10893 SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10894 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1,
10895 SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10896 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10897 SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10898 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3,
10899 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10900 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
10901 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10902 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2,
10903 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10904 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq,
10905 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE }
10907 HWND hwnd;
10908 DWORD style;
10909 LPARAM ret;
10910 INT i;
10911 WINDOWPLACEMENT wp;
10912 RECT win_rc, work_rc = {0, 0, 0, 0};
10914 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
10915 hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
10916 120, 120, 90, 90,
10917 0, 0, 0, NULL);
10918 assert(hwnd);
10920 style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10921 ok(style == 0, "expected style 0, got %08x\n", style);
10923 flush_events();
10924 flush_sequence();
10926 if (pGetMonitorInfoA && pMonitorFromPoint)
10928 HMONITOR hmon;
10929 MONITORINFO mi;
10930 POINT pt = {0, 0};
10932 SetLastError(0xdeadbeef);
10933 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
10934 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
10936 mi.cbSize = sizeof(mi);
10937 SetLastError(0xdeadbeef);
10938 ret = pGetMonitorInfoA(hmon, &mi);
10939 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
10940 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
10941 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
10942 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
10943 work_rc = mi.rcWork;
10946 GetWindowRect(hwnd, &win_rc);
10947 OffsetRect(&win_rc, -work_rc.left, -work_rc.top);
10949 wp.length = sizeof(wp);
10950 SetLastError(0xdeadbeaf);
10951 ret = GetWindowPlacement(hwnd, &wp);
10952 ok(ret, "GetWindowPlacement error %u\n", GetLastError());
10953 ok(wp.flags == 0, "expected 0, got %#x\n", wp.flags);
10954 ok(wp.showCmd == SW_SHOWNORMAL, "expected SW_SHOWNORMAL, got %d\n", wp.showCmd);
10955 ok(wp.ptMinPosition.x == -1 && wp.ptMinPosition.y == -1,
10956 "expected -1,-1 got %d,%d\n", wp.ptMinPosition.x, wp.ptMinPosition.y);
10957 ok(wp.ptMaxPosition.x == -1 && wp.ptMaxPosition.y == -1,
10958 "expected -1,-1 got %d,%d\n", wp.ptMaxPosition.x, wp.ptMaxPosition.y);
10959 if (work_rc.left || work_rc.top) todo_wine /* FIXME: remove once Wine is fixed */
10960 ok(EqualRect(&win_rc, &wp.rcNormalPosition),
10961 "expected %d,%d-%d,%d got %d,%d-%d,%d\n",
10962 win_rc.left, win_rc.top, win_rc.right, win_rc.bottom,
10963 wp.rcNormalPosition.left, wp.rcNormalPosition.top,
10964 wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
10965 else
10966 ok(EqualRect(&win_rc, &wp.rcNormalPosition),
10967 "expected %d,%d-%d,%d got %d,%d-%d,%d\n",
10968 win_rc.left, win_rc.top, win_rc.right, win_rc.bottom,
10969 wp.rcNormalPosition.left, wp.rcNormalPosition.top,
10970 wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
10972 for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
10974 static const char * const sw_cmd_name[13] =
10976 "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
10977 "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
10978 "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
10979 "SW_NORMALNA" /* 0xCC */
10981 char comment[64];
10982 INT idx; /* index into the above array of names */
10984 idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
10986 style = GetWindowLong(hwnd, GWL_STYLE);
10987 trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
10988 ret = ShowWindow(hwnd, sw[i].cmd);
10989 ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
10990 style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10991 ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
10993 sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
10994 ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
10996 wp.length = sizeof(wp);
10997 SetLastError(0xdeadbeaf);
10998 ret = GetWindowPlacement(hwnd, &wp);
10999 ok(ret, "GetWindowPlacement error %u\n", GetLastError());
11000 ok(wp.flags == sw[i].wp_flags, "expected %#x, got %#x\n", sw[i].wp_flags, wp.flags);
11001 ok(wp.showCmd == sw[i].wp_cmd, "expected %d, got %d\n", sw[i].wp_cmd, wp.showCmd);
11003 /* NT moves the minimized window to -32000,-32000, win9x to 3000,3000 */
11004 if ((wp.ptMinPosition.x + work_rc.left == -32000 && wp.ptMinPosition.y + work_rc.top == -32000) ||
11005 (wp.ptMinPosition.x + work_rc.left == 3000 && wp.ptMinPosition.y + work_rc.top == 3000))
11007 ok((wp.ptMinPosition.x + work_rc.left == sw[i].wp_min.x && wp.ptMinPosition.y + work_rc.top == sw[i].wp_min.y) ||
11008 (wp.ptMinPosition.x + work_rc.left == 3000 && wp.ptMinPosition.y + work_rc.top == 3000),
11009 "expected %d,%d got %d,%d\n", sw[i].wp_min.x, sw[i].wp_min.y, wp.ptMinPosition.x, wp.ptMinPosition.y);
11011 else
11013 if (wp.ptMinPosition.x != sw[i].wp_min.x || wp.ptMinPosition.y != sw[i].wp_min.y)
11014 todo_wine
11015 ok(wp.ptMinPosition.x == sw[i].wp_min.x && wp.ptMinPosition.y == sw[i].wp_min.y,
11016 "expected %d,%d got %d,%d\n", sw[i].wp_min.x, sw[i].wp_min.y, wp.ptMinPosition.x, wp.ptMinPosition.y);
11017 else
11018 ok(wp.ptMinPosition.x == sw[i].wp_min.x && wp.ptMinPosition.y == sw[i].wp_min.y,
11019 "expected %d,%d got %d,%d\n", sw[i].wp_min.x, sw[i].wp_min.y, wp.ptMinPosition.x, wp.ptMinPosition.y);
11022 if (wp.ptMaxPosition.x != sw[i].wp_max.x || wp.ptMaxPosition.y != sw[i].wp_max.y)
11023 todo_wine
11024 ok(wp.ptMaxPosition.x == sw[i].wp_max.x && wp.ptMaxPosition.y == sw[i].wp_max.y,
11025 "expected %d,%d got %d,%d\n", sw[i].wp_max.x, sw[i].wp_max.y, wp.ptMaxPosition.x, wp.ptMaxPosition.y);
11026 else
11027 ok(wp.ptMaxPosition.x == sw[i].wp_max.x && wp.ptMaxPosition.y == sw[i].wp_max.y,
11028 "expected %d,%d got %d,%d\n", sw[i].wp_max.x, sw[i].wp_max.y, wp.ptMaxPosition.x, wp.ptMaxPosition.y);
11030 if (0) /* FIXME: Wine behaves completely different here */
11031 ok(EqualRect(&win_rc, &wp.rcNormalPosition),
11032 "expected %d,%d-%d,%d got %d,%d-%d,%d\n",
11033 win_rc.left, win_rc.top, win_rc.right, win_rc.bottom,
11034 wp.rcNormalPosition.left, wp.rcNormalPosition.top,
11035 wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
11037 flush_events();
11038 flush_sequence();
11041 DestroyWindow(hwnd);
11044 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
11046 struct recvd_message msg;
11048 if (ignore_message( message )) return 0;
11050 msg.hwnd = hwnd;
11051 msg.message = message;
11052 msg.flags = sent|wparam|lparam;
11053 msg.wParam = wParam;
11054 msg.lParam = lParam;
11055 msg.descr = "dialog";
11056 add_message(&msg);
11058 /* calling DefDlgProc leads to a recursion under XP */
11060 switch (message)
11062 case WM_INITDIALOG:
11063 case WM_GETDLGCODE:
11064 return 0;
11066 return 1;
11069 static const struct message WmDefDlgSetFocus_1[] = {
11070 { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
11071 { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
11072 { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
11073 { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
11074 { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
11075 { HCBT_SETFOCUS, hook },
11076 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
11077 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11078 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
11079 { WM_SETFOCUS, sent|wparam, 0 },
11080 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
11081 { WM_CTLCOLOREDIT, sent },
11082 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
11083 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11084 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11085 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11086 { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
11087 { 0 }
11089 static const struct message WmDefDlgSetFocus_2[] = {
11090 { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
11091 { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
11092 { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
11093 { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
11094 { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
11095 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11096 { WM_CTLCOLOREDIT, sent|optional }, /* XP */
11097 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11098 { 0 }
11100 /* Creation of a dialog */
11101 static const struct message WmCreateDialogParamSeq_1[] = {
11102 { HCBT_CREATEWND, hook },
11103 { WM_NCCREATE, sent },
11104 { WM_NCCALCSIZE, sent|wparam, 0 },
11105 { WM_CREATE, sent },
11106 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
11107 { WM_SIZE, sent|wparam, SIZE_RESTORED },
11108 { WM_MOVE, sent },
11109 { WM_SETFONT, sent },
11110 { WM_INITDIALOG, sent },
11111 { WM_CHANGEUISTATE, sent|optional },
11112 { 0 }
11114 /* Creation of a dialog */
11115 static const struct message WmCreateDialogParamSeq_2[] = {
11116 { HCBT_CREATEWND, hook },
11117 { WM_NCCREATE, sent },
11118 { WM_NCCALCSIZE, sent|wparam, 0 },
11119 { WM_CREATE, sent },
11120 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
11121 { WM_SIZE, sent|wparam, SIZE_RESTORED },
11122 { WM_MOVE, sent },
11123 { WM_CHANGEUISTATE, sent|optional },
11124 { 0 }
11127 static void test_dialog_messages(void)
11129 WNDCLASS cls;
11130 HWND hdlg, hedit1, hedit2, hfocus;
11131 LRESULT ret;
11133 #define set_selection(hctl, start, end) \
11134 ret = SendMessage(hctl, EM_SETSEL, start, end); \
11135 ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
11137 #define check_selection(hctl, start, end) \
11138 ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
11139 ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
11141 subclass_edit();
11143 hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
11144 WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
11145 0, 0, 100, 100, 0, 0, 0, NULL);
11146 ok(hdlg != 0, "Failed to create custom dialog window\n");
11148 hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
11149 WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
11150 0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
11151 ok(hedit1 != 0, "Failed to create edit control\n");
11152 hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
11153 WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
11154 0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
11155 ok(hedit2 != 0, "Failed to create edit control\n");
11157 SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
11158 SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
11160 hfocus = GetFocus();
11161 ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
11163 SetFocus(hedit2);
11164 hfocus = GetFocus();
11165 ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
11167 check_selection(hedit1, 0, 0);
11168 check_selection(hedit2, 0, 0);
11170 set_selection(hedit2, 0, -1);
11171 check_selection(hedit2, 0, 3);
11173 SetFocus(0);
11174 hfocus = GetFocus();
11175 ok(hfocus == 0, "wrong focus %p\n", hfocus);
11177 flush_sequence();
11178 ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
11179 ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
11180 ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
11182 hfocus = GetFocus();
11183 ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
11185 check_selection(hedit1, 0, 5);
11186 check_selection(hedit2, 0, 3);
11188 flush_sequence();
11189 ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
11190 ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
11191 ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
11193 hfocus = GetFocus();
11194 ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
11196 check_selection(hedit1, 0, 5);
11197 check_selection(hedit2, 0, 3);
11199 EndDialog(hdlg, 0);
11200 DestroyWindow(hedit1);
11201 DestroyWindow(hedit2);
11202 DestroyWindow(hdlg);
11203 flush_sequence();
11205 #undef set_selection
11206 #undef check_selection
11208 ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
11209 cls.lpszClassName = "MyDialogClass";
11210 cls.hInstance = GetModuleHandle(0);
11211 /* need a cast since a dlgproc is used as a wndproc */
11212 cls.lpfnWndProc = test_dlg_proc;
11213 if (!RegisterClass(&cls)) assert(0);
11215 hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
11216 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
11217 ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
11218 EndDialog(hdlg, 0);
11219 DestroyWindow(hdlg);
11220 flush_sequence();
11222 hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
11223 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
11224 ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
11225 EndDialog(hdlg, 0);
11226 DestroyWindow(hdlg);
11227 flush_sequence();
11229 UnregisterClass(cls.lpszClassName, cls.hInstance);
11232 static void test_EndDialog(void)
11234 HWND hparent, hother, hactive, hdlg;
11235 WNDCLASS cls;
11237 hparent = CreateWindowExA(0, "TestParentClass", "Test parent",
11238 WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_DISABLED,
11239 100, 100, 200, 200, 0, 0, 0, NULL);
11240 ok (hparent != 0, "Failed to create parent window\n");
11242 hother = CreateWindowExA(0, "TestParentClass", "Test parent 2",
11243 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11244 100, 100, 200, 200, 0, 0, 0, NULL);
11245 ok (hother != 0, "Failed to create parent window\n");
11247 ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
11248 cls.lpszClassName = "MyDialogClass";
11249 cls.hInstance = GetModuleHandle(0);
11250 /* need a cast since a dlgproc is used as a wndproc */
11251 cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
11252 if (!RegisterClass(&cls)) assert(0);
11254 flush_sequence();
11255 SetForegroundWindow(hother);
11256 hactive = GetForegroundWindow();
11257 ok(hother == hactive, "Wrong window has focus (%p != %p)\n", hother, hactive);
11259 /* create a dialog where the parent is disabled, this parent should still
11260 receive the focus when the dialog exits (even though "normally" a
11261 disabled window should not receive the focus) */
11262 hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", hparent, test_dlg_proc, 0);
11263 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
11264 SetForegroundWindow(hdlg);
11265 hactive = GetForegroundWindow();
11266 ok(hdlg == hactive, "Wrong window has focus (%p != %p)\n", hdlg, hactive);
11267 EndDialog(hdlg, 0);
11268 hactive = GetForegroundWindow();
11269 ok(hparent == hactive, "Wrong window has focus (parent != active) (active: %p, parent: %p, dlg: %p, other: %p)\n", hactive, hparent, hdlg, hother);
11270 DestroyWindow(hdlg);
11271 flush_sequence();
11273 DestroyWindow( hother );
11274 DestroyWindow( hparent );
11275 UnregisterClass(cls.lpszClassName, cls.hInstance);
11278 static void test_nullCallback(void)
11280 HWND hwnd;
11282 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
11283 100, 100, 200, 200, 0, 0, 0, NULL);
11284 ok (hwnd != 0, "Failed to create overlapped window\n");
11286 SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
11287 flush_events();
11288 DestroyWindow(hwnd);
11291 /* SetActiveWindow( 0 ) hwnd visible */
11292 static const struct message SetActiveWindowSeq0[] =
11294 { HCBT_ACTIVATE, hook|optional },
11295 { WM_NCACTIVATE, sent|wparam, 0 },
11296 { WM_GETTEXT, sent|defwinproc|optional },
11297 { WM_ACTIVATE, sent|wparam, 0 },
11298 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
11299 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
11300 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11301 { WM_KILLFOCUS, sent|optional },
11302 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11303 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
11304 { WM_NCACTIVATE, sent|wparam|optional, 1 },
11305 { WM_GETTEXT, sent|defwinproc|optional },
11306 { WM_ACTIVATE, sent|wparam|optional, 1 },
11307 { HCBT_SETFOCUS, hook|optional },
11308 { WM_KILLFOCUS, sent|defwinproc|optional },
11309 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
11310 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
11311 { WM_IME_SETCONTEXT, sent|optional },
11312 { WM_IME_SETCONTEXT, sent|optional },
11313 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
11314 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11315 { WM_SETFOCUS, sent|defwinproc|optional },
11316 { WM_GETTEXT, sent|optional },
11317 { 0 }
11319 /* SetActiveWindow( hwnd ) hwnd visible */
11320 static const struct message SetActiveWindowSeq1[] =
11322 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11323 { 0 }
11325 /* SetActiveWindow( popup ) hwnd visible, popup visible */
11326 static const struct message SetActiveWindowSeq2[] =
11328 { HCBT_ACTIVATE, hook },
11329 { WM_NCACTIVATE, sent|wparam, 0 },
11330 { WM_GETTEXT, sent|defwinproc|optional },
11331 { WM_ACTIVATE, sent|wparam, 0 },
11332 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11333 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
11334 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11335 { WM_NCPAINT, sent|optional },
11336 { WM_GETTEXT, sent|defwinproc|optional },
11337 { WM_ERASEBKGND, sent|optional },
11338 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11339 { WM_NCACTIVATE, sent|wparam, 1 },
11340 { WM_GETTEXT, sent|defwinproc|optional },
11341 { WM_ACTIVATE, sent|wparam, 1 },
11342 { HCBT_SETFOCUS, hook },
11343 { WM_KILLFOCUS, sent|defwinproc },
11344 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
11345 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11346 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
11347 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11348 { WM_SETFOCUS, sent|defwinproc },
11349 { WM_GETTEXT, sent|optional },
11350 { 0 }
11353 /* SetActiveWindow( hwnd ) hwnd not visible */
11354 static const struct message SetActiveWindowSeq3[] =
11356 { HCBT_ACTIVATE, hook },
11357 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11358 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11359 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
11360 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11361 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11362 { WM_ACTIVATEAPP, sent|wparam, 1 },
11363 { WM_ACTIVATEAPP, sent|wparam, 1 },
11364 { WM_NCACTIVATE, sent|wparam, 1 },
11365 { WM_ACTIVATE, sent|wparam, 1 },
11366 { HCBT_SETFOCUS, hook },
11367 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11368 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11369 { WM_SETFOCUS, sent|defwinproc },
11370 { 0 }
11372 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
11373 static const struct message SetActiveWindowSeq4[] =
11375 { HCBT_ACTIVATE, hook },
11376 { WM_NCACTIVATE, sent|wparam, 0 },
11377 { WM_GETTEXT, sent|defwinproc|optional },
11378 { WM_ACTIVATE, sent|wparam, 0 },
11379 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11380 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
11381 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11382 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11383 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11384 { WM_NCACTIVATE, sent|wparam, 1 },
11385 { WM_GETTEXT, sent|defwinproc|optional },
11386 { WM_ACTIVATE, sent|wparam, 1 },
11387 { HCBT_SETFOCUS, hook },
11388 { WM_KILLFOCUS, sent|defwinproc },
11389 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
11390 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11391 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
11392 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11393 { WM_SETFOCUS, sent|defwinproc },
11394 { 0 }
11398 static void test_SetActiveWindow(void)
11400 HWND hwnd, popup, ret;
11402 hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
11403 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11404 100, 100, 200, 200, 0, 0, 0, NULL);
11406 popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
11407 WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
11408 100, 100, 200, 200, hwnd, 0, 0, NULL);
11410 ok(hwnd != 0, "Failed to create overlapped window\n");
11411 ok(popup != 0, "Failed to create popup window\n");
11412 SetForegroundWindow( popup );
11413 flush_sequence();
11415 trace("SetActiveWindow(0)\n");
11416 ret = SetActiveWindow(0);
11417 ok( ret == popup, "Failed to SetActiveWindow(0)\n");
11418 ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", FALSE);
11419 flush_sequence();
11421 trace("SetActiveWindow(hwnd), hwnd visible\n");
11422 ret = SetActiveWindow(hwnd);
11423 if (ret == hwnd) ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
11424 flush_sequence();
11426 trace("SetActiveWindow(popup), hwnd visible, popup visible\n");
11427 ret = SetActiveWindow(popup);
11428 ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visible\n");
11429 ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visible", FALSE);
11430 flush_sequence();
11432 ShowWindow(hwnd, SW_HIDE);
11433 ShowWindow(popup, SW_HIDE);
11434 flush_sequence();
11436 trace("SetActiveWindow(hwnd), hwnd not visible\n");
11437 ret = SetActiveWindow(hwnd);
11438 ok( ret == NULL, "SetActiveWindow(hwnd), hwnd not visible, previous is %p\n", ret );
11439 ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
11440 flush_sequence();
11442 trace("SetActiveWindow(popup), hwnd not visible, popup not visible\n");
11443 ret = SetActiveWindow(popup);
11444 ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
11445 ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visible", TRUE);
11446 flush_sequence();
11448 trace("done\n");
11450 DestroyWindow(hwnd);
11453 static const struct message SetForegroundWindowSeq[] =
11455 { WM_NCACTIVATE, sent|wparam, 0 },
11456 { WM_GETTEXT, sent|defwinproc|optional },
11457 { WM_ACTIVATE, sent|wparam, 0 },
11458 { WM_ACTIVATEAPP, sent|wparam, 0 },
11459 { WM_KILLFOCUS, sent },
11460 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
11461 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
11462 { 0 }
11465 static void test_SetForegroundWindow(void)
11467 HWND hwnd;
11469 hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
11470 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11471 100, 100, 200, 200, 0, 0, 0, NULL);
11472 ok (hwnd != 0, "Failed to create overlapped window\n");
11473 SetForegroundWindow( hwnd );
11474 flush_sequence();
11476 trace("SetForegroundWindow( 0 )\n");
11477 SetForegroundWindow( 0 );
11478 ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
11479 trace("SetForegroundWindow( GetDesktopWindow() )\n");
11480 SetForegroundWindow( GetDesktopWindow() );
11481 ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
11482 "foreground top level window", FALSE);
11483 trace("done\n");
11485 DestroyWindow(hwnd);
11488 static void test_dbcs_wm_char(void)
11490 BYTE dbch[2];
11491 WCHAR wch, bad_wch;
11492 HWND hwnd, hwnd2;
11493 MSG msg;
11494 DWORD time;
11495 POINT pt;
11496 DWORD_PTR res;
11497 CPINFOEXA cpinfo;
11498 UINT i, j, k;
11499 struct message wmCharSeq[2];
11500 BOOL ret;
11502 if (!pGetCPInfoExA)
11504 win_skip("GetCPInfoExA is not available\n");
11505 return;
11508 pGetCPInfoExA( CP_ACP, 0, &cpinfo );
11509 if (cpinfo.MaxCharSize != 2)
11511 skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
11512 return;
11515 dbch[0] = dbch[1] = 0;
11516 wch = 0;
11517 bad_wch = cpinfo.UnicodeDefaultChar;
11518 for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
11519 for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
11520 for (k = 128; k <= 255; k++)
11522 char str[2];
11523 WCHAR wstr[2];
11524 str[0] = j;
11525 str[1] = k;
11526 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
11527 WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
11528 (BYTE)str[0] == j && (BYTE)str[1] == k &&
11529 HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
11531 dbch[0] = j;
11532 dbch[1] = k;
11533 wch = wstr[0];
11534 break;
11538 if (!wch)
11540 skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
11541 return;
11543 trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
11544 dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
11546 hwnd = CreateWindowExW(0, testWindowClassW, NULL,
11547 WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11548 hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
11549 WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11550 ok (hwnd != 0, "Failed to create overlapped window\n");
11551 ok (hwnd2 != 0, "Failed to create overlapped window\n");
11552 flush_sequence();
11554 memset( wmCharSeq, 0, sizeof(wmCharSeq) );
11555 wmCharSeq[0].message = WM_CHAR;
11556 wmCharSeq[0].flags = sent|wparam;
11557 wmCharSeq[0].wParam = wch;
11559 /* posted message */
11560 PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11561 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11562 ok( !ret, "got message %x\n", msg.message );
11563 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11564 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11565 ok( ret, "no message\n" );
11566 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11567 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11568 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11569 ok( !ret, "got message %x\n", msg.message );
11571 /* posted thread message */
11572 PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
11573 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11574 ok( !ret, "got message %x\n", msg.message );
11575 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11576 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11577 ok( ret, "no message\n" );
11578 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11579 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11580 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11581 ok( !ret, "got message %x\n", msg.message );
11583 /* sent message */
11584 flush_sequence();
11585 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11586 ok_sequence( WmEmptySeq, "no messages", FALSE );
11587 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11588 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11589 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11590 ok( !ret, "got message %x\n", msg.message );
11592 /* sent message with timeout */
11593 flush_sequence();
11594 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11595 ok_sequence( WmEmptySeq, "no messages", FALSE );
11596 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11597 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11598 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11599 ok( !ret, "got message %x\n", msg.message );
11601 /* sent message with timeout and callback */
11602 flush_sequence();
11603 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11604 ok_sequence( WmEmptySeq, "no messages", FALSE );
11605 SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11606 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11607 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11608 ok( !ret, "got message %x\n", msg.message );
11610 /* sent message with callback */
11611 flush_sequence();
11612 SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11613 ok_sequence( WmEmptySeq, "no messages", FALSE );
11614 SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11615 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11616 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11617 ok( !ret, "got message %x\n", msg.message );
11619 /* direct window proc call */
11620 flush_sequence();
11621 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11622 ok_sequence( WmEmptySeq, "no messages", FALSE );
11623 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11624 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11626 /* dispatch message */
11627 msg.hwnd = hwnd;
11628 msg.message = WM_CHAR;
11629 msg.wParam = dbch[0];
11630 msg.lParam = 0;
11631 DispatchMessageA( &msg );
11632 ok_sequence( WmEmptySeq, "no messages", FALSE );
11633 msg.wParam = dbch[1];
11634 DispatchMessageA( &msg );
11635 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11637 /* window handle is irrelevant */
11638 flush_sequence();
11639 SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11640 ok_sequence( WmEmptySeq, "no messages", FALSE );
11641 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11642 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11643 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11644 ok( !ret, "got message %x\n", msg.message );
11646 /* interleaved post and send */
11647 flush_sequence();
11648 PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11649 SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11650 ok_sequence( WmEmptySeq, "no messages", FALSE );
11651 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11652 ok( !ret, "got message %x\n", msg.message );
11653 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11654 ok_sequence( WmEmptySeq, "no messages", FALSE );
11655 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11656 ok( ret, "no message\n" );
11657 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11658 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11659 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11660 ok( !ret, "got message %x\n", msg.message );
11661 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11662 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11663 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11664 ok( !ret, "got message %x\n", msg.message );
11666 /* interleaved sent message and winproc */
11667 flush_sequence();
11668 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11669 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11670 ok_sequence( WmEmptySeq, "no messages", FALSE );
11671 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11672 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11673 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11674 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11676 /* interleaved winproc and dispatch */
11677 msg.hwnd = hwnd;
11678 msg.message = WM_CHAR;
11679 msg.wParam = dbch[0];
11680 msg.lParam = 0;
11681 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11682 DispatchMessageA( &msg );
11683 ok_sequence( WmEmptySeq, "no messages", FALSE );
11684 msg.wParam = dbch[1];
11685 DispatchMessageA( &msg );
11686 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11687 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11688 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11690 /* interleaved sends */
11691 flush_sequence();
11692 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11693 SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
11694 ok_sequence( WmEmptySeq, "no messages", FALSE );
11695 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11696 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11697 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11698 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11700 /* dbcs WM_CHAR */
11701 flush_sequence();
11702 SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
11703 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11704 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11705 ok( !ret, "got message %x\n", msg.message );
11707 /* other char messages are not magic */
11708 PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
11709 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11710 ok( ret, "no message\n" );
11711 ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
11712 ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
11713 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11714 ok( !ret, "got message %x\n", msg.message );
11715 PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
11716 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11717 ok( ret, "no message\n" );
11718 ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
11719 ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
11720 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11721 ok( !ret, "got message %x\n", msg.message );
11723 /* test retrieving messages */
11725 PostMessageW( hwnd, WM_CHAR, wch, 0 );
11726 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
11727 ok( ret, "no message\n" );
11728 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11729 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11730 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11731 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
11732 ok( ret, "no message\n" );
11733 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11734 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11735 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11736 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
11737 ok( !ret, "got message %x\n", msg.message );
11739 /* message filters */
11740 PostMessageW( hwnd, WM_CHAR, wch, 0 );
11741 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
11742 ok( ret, "no message\n" );
11743 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11744 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11745 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11746 /* message id is filtered, hwnd is not */
11747 ret = PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE );
11748 ok( !ret, "no message\n" );
11749 ret = PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE );
11750 ok( ret, "no message\n" );
11751 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11752 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11753 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11754 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
11755 ok( !ret, "got message %x\n", msg.message );
11757 /* mixing GetMessage and PostMessage */
11758 PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
11759 ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
11760 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11761 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11762 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11763 ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
11764 time = msg.time;
11765 pt = msg.pt;
11766 ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
11767 ret = PeekMessageA( &msg, 0, 0, 0, PM_REMOVE );
11768 ok( ret, "no message\n" );
11769 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11770 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11771 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11772 ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
11773 ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
11774 ok( msg.pt.x == pt.x && msg.pt.y == pt.y, "bad point %u,%u/%u,%u\n", msg.pt.x, msg.pt.y, pt.x, pt.y );
11775 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
11776 ok( !ret, "got message %x\n", msg.message );
11778 /* without PM_REMOVE */
11779 PostMessageW( hwnd, WM_CHAR, wch, 0 );
11780 ret = PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE );
11781 ok( ret, "no message\n" );
11782 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11783 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11784 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11785 ret = PeekMessageA( &msg, 0, 0, 0, PM_REMOVE );
11786 ok( ret, "no message\n" );
11787 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11788 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11789 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11790 ret = PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE );
11791 ok( ret, "no message\n" );
11792 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11793 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11794 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11795 ret = PeekMessageA( &msg, 0, 0, 0, PM_REMOVE );
11796 ok( ret, "no message\n" );
11797 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11798 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11799 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11800 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
11801 ok( !ret, "got message %x\n", msg.message );
11803 DestroyWindow(hwnd);
11804 DestroyWindow(hwnd2);
11807 #define ID_LISTBOX 0x000f
11809 static const struct message wm_lb_setcursel_0[] =
11811 { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
11812 { WM_CTLCOLORLISTBOX, sent|parent },
11813 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
11814 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11815 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11816 { 0 }
11818 static const struct message wm_lb_setcursel_1[] =
11820 { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
11821 { WM_CTLCOLORLISTBOX, sent|parent },
11822 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
11823 { WM_CTLCOLORLISTBOX, sent|parent },
11824 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
11825 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
11826 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
11827 { 0 }
11829 static const struct message wm_lb_setcursel_2[] =
11831 { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
11832 { WM_CTLCOLORLISTBOX, sent|parent },
11833 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
11834 { WM_CTLCOLORLISTBOX, sent|parent },
11835 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
11836 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11837 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11838 { 0 }
11840 static const struct message wm_lb_click_0[] =
11842 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
11843 { HCBT_SETFOCUS, hook },
11844 { WM_KILLFOCUS, sent|parent },
11845 { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
11846 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11847 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
11848 { WM_SETFOCUS, sent|defwinproc },
11850 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
11851 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
11852 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11853 { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
11854 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
11856 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
11857 { WM_CTLCOLORLISTBOX, sent|parent },
11858 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
11859 { WM_CTLCOLORLISTBOX, sent|parent },
11860 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
11861 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
11863 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11864 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11866 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
11867 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
11868 { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
11869 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
11870 { 0 }
11872 static const struct message wm_lb_deletestring[] =
11874 { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
11875 { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
11876 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11877 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11878 { 0 }
11880 static const struct message wm_lb_deletestring_reset[] =
11882 { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
11883 { LB_RESETCONTENT, sent|wparam|lparam|defwinproc|optional, 0, 0 },
11884 { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
11885 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11886 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11887 { 0 }
11890 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
11892 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
11894 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11896 static LONG defwndproc_counter = 0;
11897 LRESULT ret;
11898 struct recvd_message msg;
11900 /* do not log painting messages */
11901 if (message != WM_PAINT &&
11902 message != WM_NCPAINT &&
11903 message != WM_SYNCPAINT &&
11904 message != WM_ERASEBKGND &&
11905 message != WM_NCHITTEST &&
11906 message != WM_GETTEXT &&
11907 !ignore_message( message ))
11909 msg.hwnd = hwnd;
11910 msg.message = message;
11911 msg.flags = sent|wparam|lparam;
11912 if (defwndproc_counter) msg.flags |= defwinproc;
11913 msg.wParam = wp;
11914 msg.lParam = lp;
11915 msg.descr = "listbox";
11916 add_message(&msg);
11919 defwndproc_counter++;
11920 ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
11921 defwndproc_counter--;
11923 return ret;
11926 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
11927 int caret_index, int top_index, int line)
11929 LRESULT ret;
11931 /* calling an orig proc helps to avoid unnecessary message logging */
11932 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
11933 ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
11934 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
11935 ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
11936 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
11937 ok_(__FILE__, line)(ret == caret_index ||
11938 broken(cur_sel == -1 && caret_index == 0 && ret == -1), /* nt4 */
11939 "expected caret index %d, got %ld\n", caret_index, ret);
11940 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
11941 ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
11944 static void test_listbox_messages(void)
11946 HWND parent, listbox;
11947 LRESULT ret;
11949 parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11950 100, 100, 200, 200, 0, 0, 0, NULL);
11951 listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
11952 WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
11953 10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
11954 listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
11956 check_lb_state(listbox, 0, LB_ERR, 0, 0);
11958 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
11959 ok(ret == 0, "expected 0, got %ld\n", ret);
11960 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
11961 ok(ret == 1, "expected 1, got %ld\n", ret);
11962 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
11963 ok(ret == 2, "expected 2, got %ld\n", ret);
11965 check_lb_state(listbox, 3, LB_ERR, 0, 0);
11967 flush_sequence();
11969 log_all_parent_messages++;
11971 trace("selecting item 0\n");
11972 ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
11973 ok(ret == 0, "expected 0, got %ld\n", ret);
11974 ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
11975 check_lb_state(listbox, 3, 0, 0, 0);
11976 flush_sequence();
11978 trace("selecting item 1\n");
11979 ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
11980 ok(ret == 1, "expected 1, got %ld\n", ret);
11981 ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
11982 check_lb_state(listbox, 3, 1, 1, 0);
11984 trace("selecting item 2\n");
11985 ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
11986 ok(ret == 2, "expected 2, got %ld\n", ret);
11987 ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
11988 check_lb_state(listbox, 3, 2, 2, 0);
11990 trace("clicking on item 0\n");
11991 ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
11992 ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11993 ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
11994 ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11995 ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
11996 check_lb_state(listbox, 3, 0, 0, 0);
11997 flush_sequence();
11999 trace("deleting item 0\n");
12000 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
12001 ok(ret == 2, "expected 2, got %ld\n", ret);
12002 ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
12003 check_lb_state(listbox, 2, -1, 0, 0);
12004 flush_sequence();
12006 trace("deleting item 0\n");
12007 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
12008 ok(ret == 1, "expected 1, got %ld\n", ret);
12009 ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
12010 check_lb_state(listbox, 1, -1, 0, 0);
12011 flush_sequence();
12013 trace("deleting item 0\n");
12014 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
12015 ok(ret == 0, "expected 0, got %ld\n", ret);
12016 ok_sequence(wm_lb_deletestring_reset, "LB_DELETESTRING 0", FALSE );
12017 check_lb_state(listbox, 0, -1, 0, 0);
12018 flush_sequence();
12020 trace("deleting item 0\n");
12021 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
12022 ok(ret == LB_ERR, "expected LB_ERR, got %ld\n", ret);
12023 check_lb_state(listbox, 0, -1, 0, 0);
12024 flush_sequence();
12026 log_all_parent_messages--;
12028 DestroyWindow(listbox);
12029 DestroyWindow(parent);
12032 /*************************** Menu test ******************************/
12033 static const struct message wm_popup_menu_1[] =
12035 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
12036 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
12037 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
12038 { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
12039 { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
12040 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
12041 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
12042 { WM_INITMENU, sent|lparam, 0, 0 },
12043 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
12044 { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
12045 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
12046 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
12047 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
12048 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
12049 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001, 0, 0x40000000 },
12050 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
12051 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
12052 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
12053 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
12054 { WM_MENUCOMMAND, sent }, /* |wparam, 200 - Win9x */
12055 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
12056 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
12057 { 0 }
12059 static const struct message wm_popup_menu_2[] =
12061 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
12062 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
12063 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
12064 { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
12065 { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
12066 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
12067 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
12068 { WM_INITMENU, sent|lparam, 0, 0 },
12069 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
12070 { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
12071 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
12072 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
12073 { HCBT_CREATEWND, hook },
12074 { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
12075 |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
12076 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
12077 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
12078 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
12079 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
12080 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
12081 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
12082 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
12083 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
12084 { HCBT_DESTROYWND, hook },
12085 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
12086 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
12087 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
12088 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
12089 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
12090 { WM_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
12091 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
12092 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
12093 { 0 }
12095 static const struct message wm_popup_menu_3[] =
12097 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
12098 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
12099 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
12100 { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
12101 { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
12102 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
12103 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
12104 { WM_INITMENU, sent|lparam, 0, 0 },
12105 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
12106 { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
12107 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
12108 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
12109 { HCBT_CREATEWND, hook },
12110 { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
12111 |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
12112 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
12113 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
12114 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
12115 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
12116 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
12117 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
12118 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
12119 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
12120 { HCBT_DESTROYWND, hook },
12121 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
12122 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
12123 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
12124 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
12125 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
12126 { WM_COMMAND, sent|wparam|lparam, 100, 0 },
12127 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
12128 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
12129 { 0 }
12132 static const struct message wm_single_menu_item[] =
12134 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
12135 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
12136 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'Q', 0x20000001 },
12137 { WM_SYSKEYDOWN, sent|wparam|lparam, 'Q', 0x20000001 },
12138 { WM_SYSCHAR, sent|wparam|lparam, 'q', 0x20000001 },
12139 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'q' },
12140 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
12141 { WM_INITMENU, sent|lparam, 0, 0 },
12142 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(300,MF_HILITE) },
12143 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
12144 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
12145 { WM_MENUCOMMAND, sent },
12146 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'Q', 0xe0000001 },
12147 { WM_SYSKEYUP, sent|wparam|lparam, 'Q', 0xe0000001 },
12148 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 },
12149 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
12151 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 1 },
12152 { WM_KEYDOWN, sent|wparam|lparam, VK_ESCAPE, 1 },
12153 { WM_CHAR, sent|wparam|lparam, VK_ESCAPE, 0x00000001 },
12154 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0xc0000001 },
12155 { WM_KEYUP, sent|wparam|lparam, VK_ESCAPE, 0xc0000001 },
12156 { 0 }
12159 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
12161 if (message == WM_ENTERIDLE ||
12162 message == WM_INITMENU ||
12163 message == WM_INITMENUPOPUP ||
12164 message == WM_MENUSELECT ||
12165 message == WM_PARENTNOTIFY ||
12166 message == WM_ENTERMENULOOP ||
12167 message == WM_EXITMENULOOP ||
12168 message == WM_UNINITMENUPOPUP ||
12169 message == WM_KEYDOWN ||
12170 message == WM_KEYUP ||
12171 message == WM_CHAR ||
12172 message == WM_SYSKEYDOWN ||
12173 message == WM_SYSKEYUP ||
12174 message == WM_SYSCHAR ||
12175 message == WM_COMMAND ||
12176 message == WM_MENUCOMMAND)
12178 struct recvd_message msg;
12180 msg.hwnd = hwnd;
12181 msg.message = message;
12182 msg.flags = sent|wparam|lparam;
12183 msg.wParam = wp;
12184 msg.lParam = lp;
12185 msg.descr = "parent_menu_proc";
12186 add_message(&msg);
12189 return DefWindowProcA(hwnd, message, wp, lp);
12192 static void set_menu_style(HMENU hmenu, DWORD style)
12194 MENUINFO mi;
12195 BOOL ret;
12197 mi.cbSize = sizeof(mi);
12198 mi.fMask = MIM_STYLE;
12199 mi.dwStyle = style;
12200 SetLastError(0xdeadbeef);
12201 ret = pSetMenuInfo(hmenu, &mi);
12202 ok(ret, "SetMenuInfo error %u\n", GetLastError());
12205 static DWORD get_menu_style(HMENU hmenu)
12207 MENUINFO mi;
12208 BOOL ret;
12210 mi.cbSize = sizeof(mi);
12211 mi.fMask = MIM_STYLE;
12212 mi.dwStyle = 0;
12213 SetLastError(0xdeadbeef);
12214 ret = pGetMenuInfo(hmenu, &mi);
12215 ok(ret, "GetMenuInfo error %u\n", GetLastError());
12217 return mi.dwStyle;
12220 static void test_menu_messages(void)
12222 MSG msg;
12223 WNDCLASSA cls;
12224 HMENU hmenu, hmenu_popup;
12225 HWND hwnd;
12226 DWORD style;
12228 if (!pGetMenuInfo || !pSetMenuInfo)
12230 win_skip("GetMenuInfo and/or SetMenuInfo are not available\n");
12231 return;
12233 cls.style = 0;
12234 cls.lpfnWndProc = parent_menu_proc;
12235 cls.cbClsExtra = 0;
12236 cls.cbWndExtra = 0;
12237 cls.hInstance = GetModuleHandleA(0);
12238 cls.hIcon = 0;
12239 cls.hCursor = LoadCursorA(0, IDC_ARROW);
12240 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
12241 cls.lpszMenuName = NULL;
12242 cls.lpszClassName = "TestMenuClass";
12243 UnregisterClass(cls.lpszClassName, cls.hInstance);
12244 if (!RegisterClassA(&cls)) assert(0);
12246 SetLastError(0xdeadbeef);
12247 hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
12248 100, 100, 200, 200, 0, 0, 0, NULL);
12249 ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
12251 SetLastError(0xdeadbeef);
12252 hmenu = LoadMenuA(GetModuleHandle(0), MAKEINTRESOURCE(1));
12253 ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
12255 SetMenu(hwnd, hmenu);
12256 SetForegroundWindow( hwnd );
12258 set_menu_style(hmenu, MNS_NOTIFYBYPOS);
12259 style = get_menu_style(hmenu);
12260 ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
12262 hmenu_popup = GetSubMenu(hmenu, 0);
12263 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12264 style = get_menu_style(hmenu_popup);
12265 ok(style == 0, "expected 0, got %u\n", style);
12267 hmenu_popup = GetSubMenu(hmenu_popup, 0);
12268 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12269 style = get_menu_style(hmenu_popup);
12270 ok(style == 0, "expected 0, got %u\n", style);
12272 /* Alt+E, Enter */
12273 trace("testing a popup menu command\n");
12274 flush_sequence();
12275 keybd_event(VK_MENU, 0, 0, 0);
12276 keybd_event('E', 0, 0, 0);
12277 keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
12278 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12279 keybd_event(VK_RETURN, 0, 0, 0);
12280 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
12281 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
12283 TranslateMessage(&msg);
12284 DispatchMessage(&msg);
12286 if (!sequence_cnt) /* we didn't get any message */
12288 skip( "queuing key events not supported\n" );
12289 goto done;
12291 /* win98 queues only a WM_KEYUP and doesn't start menu tracking */
12292 if (sequence[0].message == WM_KEYUP && sequence[0].wParam == VK_MENU)
12294 win_skip( "menu tracking through VK_MENU not supported\n" );
12295 goto done;
12297 ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
12299 /* Alt+F, Right, Enter */
12300 trace("testing submenu of a popup menu command\n");
12301 flush_sequence();
12302 keybd_event(VK_MENU, 0, 0, 0);
12303 keybd_event('F', 0, 0, 0);
12304 keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
12305 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12306 keybd_event(VK_RIGHT, 0, 0, 0);
12307 keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
12308 keybd_event(VK_RETURN, 0, 0, 0);
12309 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
12310 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
12312 TranslateMessage(&msg);
12313 DispatchMessage(&msg);
12315 ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
12317 trace("testing single menu item command\n");
12318 flush_sequence();
12319 keybd_event(VK_MENU, 0, 0, 0);
12320 keybd_event('Q', 0, 0, 0);
12321 keybd_event('Q', 0, KEYEVENTF_KEYUP, 0);
12322 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12323 keybd_event(VK_ESCAPE, 0, 0, 0);
12324 keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0);
12325 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
12327 TranslateMessage(&msg);
12328 DispatchMessage(&msg);
12330 ok_sequence(wm_single_menu_item, "single menu item command", FALSE);
12332 set_menu_style(hmenu, 0);
12333 style = get_menu_style(hmenu);
12334 ok(style == 0, "expected 0, got %u\n", style);
12336 hmenu_popup = GetSubMenu(hmenu, 0);
12337 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12338 set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
12339 style = get_menu_style(hmenu_popup);
12340 ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
12342 hmenu_popup = GetSubMenu(hmenu_popup, 0);
12343 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12344 style = get_menu_style(hmenu_popup);
12345 ok(style == 0, "expected 0, got %u\n", style);
12347 /* Alt+F, Right, Enter */
12348 trace("testing submenu of a popup menu command\n");
12349 flush_sequence();
12350 keybd_event(VK_MENU, 0, 0, 0);
12351 keybd_event('F', 0, 0, 0);
12352 keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
12353 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12354 keybd_event(VK_RIGHT, 0, 0, 0);
12355 keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
12356 keybd_event(VK_RETURN, 0, 0, 0);
12357 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
12358 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
12360 TranslateMessage(&msg);
12361 DispatchMessage(&msg);
12363 ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
12365 done:
12366 DestroyWindow(hwnd);
12367 DestroyMenu(hmenu);
12371 static void test_paintingloop(void)
12373 HWND hwnd;
12375 paint_loop_done = 0;
12376 hwnd = CreateWindowExA(0x0,"PaintLoopWindowClass",
12377 "PaintLoopWindowClass",WS_OVERLAPPEDWINDOW,
12378 100, 100, 100, 100, 0, 0, 0, NULL );
12379 ok(hwnd != 0, "PaintLoop window error %u\n", GetLastError());
12380 ShowWindow(hwnd,SW_NORMAL);
12381 SetFocus(hwnd);
12383 while (!paint_loop_done)
12385 MSG msg;
12386 if (PeekMessageA(&msg, 0, 0, 0, 1))
12388 TranslateMessage(&msg);
12389 DispatchMessage(&msg);
12392 DestroyWindow(hwnd);
12395 static void test_defwinproc(void)
12397 HWND hwnd;
12398 MSG msg;
12399 int gotwmquit = FALSE;
12400 hwnd = CreateWindowExA(0, "static", "test_defwndproc", WS_POPUP, 0,0,0,0,0,0,0, NULL);
12401 assert(hwnd);
12402 DefWindowProcA( hwnd, WM_ENDSESSION, 1, 0);
12403 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) {
12404 if( msg.message == WM_QUIT) gotwmquit = TRUE;
12405 DispatchMessageA( &msg );
12407 ok( gotwmquit == FALSE, "Unexpected WM_QUIT message!\n");
12408 DestroyWindow( hwnd);
12411 #define clear_clipboard(hwnd) clear_clipboard_(__LINE__, (hwnd))
12412 static void clear_clipboard_(int line, HWND hWnd)
12414 BOOL succ;
12415 succ = OpenClipboard(hWnd);
12416 ok_(__FILE__, line)(succ, "OpenClipboard failed, err=%u\n", GetLastError());
12417 succ = EmptyClipboard();
12418 ok_(__FILE__, line)(succ, "EmptyClipboard failed, err=%u\n", GetLastError());
12419 succ = CloseClipboard();
12420 ok_(__FILE__, line)(succ, "CloseClipboard failed, err=%u\n", GetLastError());
12423 #define expect_HWND(expected, got) expect_HWND_(__LINE__, (expected), (got))
12424 static void expect_HWND_(int line, HWND expected, HWND got)
12426 ok_(__FILE__, line)(got==expected, "Expected %p, got %p\n", expected, got);
12429 static WNDPROC pOldViewerProc;
12431 static LRESULT CALLBACK recursive_viewer_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
12433 static BOOL recursion_guard;
12435 if (message == WM_DRAWCLIPBOARD && !recursion_guard)
12437 recursion_guard = TRUE;
12438 clear_clipboard(hWnd);
12439 recursion_guard = FALSE;
12441 return CallWindowProcA(pOldViewerProc, hWnd, message, wParam, lParam);
12444 static void test_clipboard_viewers(void)
12446 static struct message wm_change_cb_chain[] =
12448 { WM_CHANGECBCHAIN, sent|wparam|lparam, 0, 0 },
12449 { 0 }
12451 static const struct message wm_clipboard_destroyed[] =
12453 { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
12454 { 0 }
12456 static struct message wm_clipboard_changed[] =
12458 { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
12459 { 0 }
12461 static struct message wm_clipboard_changed_and_owned[] =
12463 { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
12464 { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
12465 { 0 }
12468 HINSTANCE hInst = GetModuleHandleA(NULL);
12469 HWND hWnd1, hWnd2, hWnd3;
12470 HWND hOrigViewer;
12471 HWND hRet;
12473 hWnd1 = CreateWindowExA(0, "TestWindowClass", "Clipboard viewer test wnd 1",
12474 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12475 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12476 GetDesktopWindow(), NULL, hInst, NULL);
12477 hWnd2 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 2",
12478 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12479 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12480 GetDesktopWindow(), NULL, hInst, NULL);
12481 hWnd3 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 3",
12482 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12483 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12484 GetDesktopWindow(), NULL, hInst, NULL);
12485 trace("clipbd viewers: hWnd1=%p, hWnd2=%p, hWnd3=%p\n", hWnd1, hWnd2, hWnd3);
12486 assert(hWnd1 && hWnd2 && hWnd3);
12488 flush_sequence();
12490 /* Test getting the clipboard viewer and setting the viewer to NULL. */
12491 hOrigViewer = GetClipboardViewer();
12492 hRet = SetClipboardViewer(NULL);
12493 ok_sequence(WmEmptySeq, "set viewer to NULL", FALSE);
12494 expect_HWND(hOrigViewer, hRet);
12495 expect_HWND(NULL, GetClipboardViewer());
12497 /* Test registering hWnd1 as a viewer. */
12498 hRet = SetClipboardViewer(hWnd1);
12499 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12500 ok_sequence(wm_clipboard_changed, "set viewer NULL->1", FALSE);
12501 expect_HWND(NULL, hRet);
12502 expect_HWND(hWnd1, GetClipboardViewer());
12504 /* Test that changing the clipboard actually refreshes the registered viewer. */
12505 clear_clipboard(hWnd1);
12506 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12507 ok_sequence(wm_clipboard_changed, "clear clipbd (viewer=owner=1)", FALSE);
12509 /* Again, but with different owner. */
12510 clear_clipboard(hWnd2);
12511 wm_clipboard_changed_and_owned[1].wParam = (WPARAM) GetClipboardOwner();
12512 ok_sequence(wm_clipboard_changed_and_owned, "clear clipbd (viewer=1, owner=2)", FALSE);
12514 /* Test re-registering same window. */
12515 hRet = SetClipboardViewer(hWnd1);
12516 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12517 ok_sequence(wm_clipboard_changed, "set viewer 1->1", FALSE);
12518 expect_HWND(hWnd1, hRet);
12519 expect_HWND(hWnd1, GetClipboardViewer());
12521 /* Test ChangeClipboardChain. */
12522 ChangeClipboardChain(hWnd2, hWnd3);
12523 wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
12524 wm_change_cb_chain[0].lParam = (LPARAM) hWnd3;
12525 ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=3)", FALSE);
12526 expect_HWND(hWnd1, GetClipboardViewer());
12528 ChangeClipboardChain(hWnd2, NULL);
12529 wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
12530 wm_change_cb_chain[0].lParam = 0;
12531 ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=NULL)", FALSE);
12532 expect_HWND(hWnd1, GetClipboardViewer());
12534 ChangeClipboardChain(NULL, hWnd2);
12535 ok_sequence(WmEmptySeq, "change chain (viewer=1, remove=NULL, next=2)", TRUE);
12536 expect_HWND(hWnd1, GetClipboardViewer());
12538 /* Actually change clipboard viewer with ChangeClipboardChain. */
12539 ChangeClipboardChain(hWnd1, hWnd2);
12540 ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=2)", FALSE);
12541 expect_HWND(hWnd2, GetClipboardViewer());
12543 /* Test that no refresh messages are sent when viewer has unregistered. */
12544 clear_clipboard(hWnd2);
12545 ok_sequence(WmEmptySeq, "clear clipd (viewer=2, owner=1)", FALSE);
12547 /* Register hWnd1 again. */
12548 ChangeClipboardChain(hWnd2, hWnd1);
12549 ok_sequence(WmEmptySeq, "change chain (viewer=remove=2, next=1)", FALSE);
12550 expect_HWND(hWnd1, GetClipboardViewer());
12552 /* Subclass hWnd1 so that when it receives a WM_DRAWCLIPBOARD message, it
12553 * changes the clipboard. When this happens, the system shouldn't send
12554 * another WM_DRAWCLIPBOARD (as this could cause an infinite loop).
12556 pOldViewerProc = (WNDPROC) SetWindowLongPtrA(hWnd1, GWLP_WNDPROC, (LONG_PTR) recursive_viewer_proc);
12557 clear_clipboard(hWnd2);
12558 /* The clipboard owner is changed in recursive_viewer_proc: */
12559 wm_clipboard_changed[0].wParam = (WPARAM) hWnd2;
12560 ok_sequence(wm_clipboard_changed, "recursive clear clipbd (viewer=1, owner=2)", TRUE);
12562 /* Test unregistering. */
12563 ChangeClipboardChain(hWnd1, NULL);
12564 ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=NULL)", FALSE);
12565 expect_HWND(NULL, GetClipboardViewer());
12567 clear_clipboard(hWnd1);
12568 ok_sequence(wm_clipboard_destroyed, "clear clipbd (no viewer, owner=1)", FALSE);
12570 DestroyWindow(hWnd1);
12571 DestroyWindow(hWnd2);
12572 DestroyWindow(hWnd3);
12573 SetClipboardViewer(hOrigViewer);
12576 static void test_PostMessage(void)
12578 static const struct
12580 HWND hwnd;
12581 BOOL ret;
12582 } data[] =
12584 { HWND_TOP /* 0 */, TRUE },
12585 { HWND_BROADCAST, TRUE },
12586 { HWND_BOTTOM, TRUE },
12587 { HWND_TOPMOST, TRUE },
12588 { HWND_NOTOPMOST, FALSE },
12589 { HWND_MESSAGE, FALSE },
12590 { (HWND)0xdeadbeef, FALSE }
12592 int i;
12593 HWND hwnd;
12594 BOOL ret;
12595 MSG msg;
12596 static const WCHAR staticW[] = {'s','t','a','t','i','c',0};
12598 SetLastError(0xdeadbeef);
12599 hwnd = CreateWindowExW(0, staticW, NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
12600 if (!hwnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
12602 win_skip("Skipping some PostMessage tests on Win9x/WinMe\n");
12603 return;
12605 assert(hwnd);
12607 flush_events();
12609 PostMessage(hwnd, WM_USER+1, 0x1234, 0x5678);
12610 PostMessage(0, WM_USER+2, 0x5678, 0x1234);
12612 for (i = 0; i < sizeof(data)/sizeof(data[0]); i++)
12614 memset(&msg, 0xab, sizeof(msg));
12615 ret = PeekMessageA(&msg, data[i].hwnd, 0, 0, PM_NOREMOVE);
12616 ok(ret == data[i].ret, "%d: hwnd %p expected %d, got %d\n", i, data[i].hwnd, data[i].ret, ret);
12617 if (data[i].ret)
12619 if (data[i].hwnd)
12620 ok(ret && msg.hwnd == 0 && msg.message == WM_USER+2 &&
12621 msg.wParam == 0x5678 && msg.lParam == 0x1234,
12622 "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/0/WM_USER+2/0x5678/0x1234\n",
12623 i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam);
12624 else
12625 ok(ret && msg.hwnd == hwnd && msg.message == WM_USER+1 &&
12626 msg.wParam == 0x1234 && msg.lParam == 0x5678,
12627 "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/%p/WM_USER+1/0x1234/0x5678\n",
12628 i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam, msg.hwnd);
12632 DestroyWindow(hwnd);
12633 flush_events();
12636 static const struct
12638 DWORD exp, broken;
12639 BOOL todo;
12640 } wait_idle_expect[] =
12642 /* 0 */ { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12643 { WAIT_TIMEOUT, 0, FALSE },
12644 { WAIT_TIMEOUT, 0, FALSE },
12645 { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12646 { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12647 /* 5 */ { WAIT_TIMEOUT, 0, FALSE },
12648 { WAIT_TIMEOUT, 0, FALSE },
12649 { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12650 { 0, 0, FALSE },
12651 { 0, 0, FALSE },
12652 /* 10 */ { 0, 0, FALSE },
12653 { 0, 0, FALSE },
12654 { 0, WAIT_TIMEOUT, FALSE },
12655 { 0, 0, FALSE },
12656 { 0, 0, FALSE },
12657 /* 15 */ { 0, 0, FALSE },
12658 { WAIT_TIMEOUT, 0, FALSE },
12659 { WAIT_TIMEOUT, 0, FALSE },
12660 { WAIT_TIMEOUT, 0, FALSE },
12661 { WAIT_TIMEOUT, 0, FALSE },
12662 /* 20 */ { WAIT_TIMEOUT, 0, FALSE },
12665 static DWORD CALLBACK do_wait_idle_child_thread( void *arg )
12667 MSG msg;
12669 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12670 Sleep( 200 );
12671 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12672 return 0;
12675 static void do_wait_idle_child( int arg )
12677 WNDCLASS cls;
12678 MSG msg;
12679 HWND hwnd = 0;
12680 HANDLE thread;
12681 DWORD id;
12682 HANDLE start_event = OpenEventA( EVENT_ALL_ACCESS, FALSE, "test_WaitForInputIdle_start" );
12683 HANDLE end_event = OpenEventA( EVENT_ALL_ACCESS, FALSE, "test_WaitForInputIdle_end" );
12685 memset( &cls, 0, sizeof(cls) );
12686 cls.lpfnWndProc = DefWindowProc;
12687 cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
12688 cls.hCursor = LoadCursor(0, IDC_ARROW);
12689 cls.lpszClassName = "TestClass";
12690 RegisterClass( &cls );
12692 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ); /* create the msg queue */
12694 ok( start_event != 0, "failed to create start event, error %u\n", GetLastError() );
12695 ok( end_event != 0, "failed to create end event, error %u\n", GetLastError() );
12697 switch (arg)
12699 case 0:
12700 SetEvent( start_event );
12701 break;
12702 case 1:
12703 SetEvent( start_event );
12704 Sleep( 200 );
12705 PeekMessage( &msg, 0, 0, 0, PM_REMOVE );
12706 break;
12707 case 2:
12708 SetEvent( start_event );
12709 Sleep( 200 );
12710 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12711 PostThreadMessage( GetCurrentThreadId(), WM_COMMAND, 0x1234, 0xabcd );
12712 PeekMessage( &msg, 0, 0, 0, PM_REMOVE );
12713 break;
12714 case 3:
12715 SetEvent( start_event );
12716 Sleep( 200 );
12717 SendMessage( HWND_BROADCAST, WM_WININICHANGE, 0, 0 );
12718 break;
12719 case 4:
12720 SetEvent( start_event );
12721 Sleep( 200 );
12722 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12723 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessage( &msg );
12724 break;
12725 case 5:
12726 SetEvent( start_event );
12727 Sleep( 200 );
12728 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12729 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12730 break;
12731 case 6:
12732 SetEvent( start_event );
12733 Sleep( 200 );
12734 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12735 while (PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ))
12737 GetMessage( &msg, 0, 0, 0 );
12738 DispatchMessage( &msg );
12740 break;
12741 case 7:
12742 SetEvent( start_event );
12743 Sleep( 200 );
12744 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12745 SetTimer( hwnd, 3, 1, NULL );
12746 Sleep( 200 );
12747 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessage( &msg );
12748 break;
12749 case 8:
12750 SetEvent( start_event );
12751 Sleep( 200 );
12752 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12753 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12754 break;
12755 case 9:
12756 SetEvent( start_event );
12757 Sleep( 200 );
12758 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12759 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12760 for (;;) GetMessage( &msg, 0, 0, 0 );
12761 break;
12762 case 10:
12763 SetEvent( start_event );
12764 Sleep( 200 );
12765 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12766 SetTimer( hwnd, 3, 1, NULL );
12767 Sleep( 200 );
12768 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12769 break;
12770 case 11:
12771 SetEvent( start_event );
12772 Sleep( 200 );
12773 return; /* exiting the process makes WaitForInputIdle return success too */
12774 case 12:
12775 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12776 Sleep( 200 );
12777 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12778 SetEvent( start_event );
12779 break;
12780 case 13:
12781 SetEvent( start_event );
12782 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12783 Sleep( 200 );
12784 thread = CreateThread( NULL, 0, do_wait_idle_child_thread, NULL, 0, &id );
12785 WaitForSingleObject( thread, 10000 );
12786 CloseHandle( thread );
12787 break;
12788 case 14:
12789 SetEvent( start_event );
12790 Sleep( 200 );
12791 PeekMessage( &msg, HWND_TOPMOST, 0, 0, PM_NOREMOVE );
12792 break;
12793 case 15:
12794 SetEvent( start_event );
12795 Sleep( 200 );
12796 PeekMessage( &msg, HWND_BROADCAST, 0, 0, PM_NOREMOVE );
12797 break;
12798 case 16:
12799 SetEvent( start_event );
12800 Sleep( 200 );
12801 PeekMessage( &msg, HWND_BOTTOM, 0, 0, PM_NOREMOVE );
12802 break;
12803 case 17:
12804 SetEvent( start_event );
12805 Sleep( 200 );
12806 PeekMessage( &msg, (HWND)0xdeadbeef, 0, 0, PM_NOREMOVE );
12807 break;
12808 case 18:
12809 SetEvent( start_event );
12810 Sleep( 200 );
12811 PeekMessage( &msg, HWND_NOTOPMOST, 0, 0, PM_NOREMOVE );
12812 break;
12813 case 19:
12814 SetEvent( start_event );
12815 Sleep( 200 );
12816 PeekMessage( &msg, HWND_MESSAGE, 0, 0, PM_NOREMOVE );
12817 break;
12818 case 20:
12819 SetEvent( start_event );
12820 Sleep( 200 );
12821 PeekMessage( &msg, GetDesktopWindow(), 0, 0, PM_NOREMOVE );
12822 break;
12824 WaitForSingleObject( end_event, 2000 );
12825 CloseHandle( start_event );
12826 CloseHandle( end_event );
12827 if (hwnd) DestroyWindow( hwnd );
12830 static LRESULT CALLBACK wait_idle_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
12832 if (msg == WM_WININICHANGE) Sleep( 200 ); /* make sure the child waits */
12833 return DefWindowProcA( hwnd, msg, wp, lp );
12836 static DWORD CALLBACK wait_idle_thread( void *arg )
12838 WNDCLASS cls;
12839 MSG msg;
12840 HWND hwnd;
12842 memset( &cls, 0, sizeof(cls) );
12843 cls.lpfnWndProc = wait_idle_proc;
12844 cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
12845 cls.hCursor = LoadCursor(0, IDC_ARROW);
12846 cls.lpszClassName = "TestClass";
12847 RegisterClass( &cls );
12849 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
12850 while (GetMessage( &msg, 0, 0, 0 )) DispatchMessage( &msg );
12851 DestroyWindow(hwnd);
12852 return 0;
12855 static void test_WaitForInputIdle( char *argv0 )
12857 char path[MAX_PATH];
12858 PROCESS_INFORMATION pi;
12859 STARTUPINFOA startup;
12860 BOOL ret;
12861 HANDLE start_event, end_event, thread;
12862 unsigned int i;
12863 DWORD id;
12864 const IMAGE_DOS_HEADER *dos = (const IMAGE_DOS_HEADER *)GetModuleHandleA(0);
12865 const IMAGE_NT_HEADERS *nt = (const IMAGE_NT_HEADERS *)((const char *)dos + dos->e_lfanew);
12866 BOOL console_app = (nt->OptionalHeader.Subsystem != IMAGE_SUBSYSTEM_WINDOWS_GUI);
12868 if (console_app) /* build the test with -mwindows for better coverage */
12869 trace( "not built as a GUI app, WaitForInputIdle may not be fully tested\n" );
12871 start_event = CreateEventA(NULL, 0, 0, "test_WaitForInputIdle_start");
12872 end_event = CreateEventA(NULL, 0, 0, "test_WaitForInputIdle_end");
12873 ok(start_event != 0, "failed to create start event, error %u\n", GetLastError());
12874 ok(end_event != 0, "failed to create end event, error %u\n", GetLastError());
12876 memset( &startup, 0, sizeof(startup) );
12877 startup.cb = sizeof(startup);
12878 startup.dwFlags = STARTF_USESHOWWINDOW;
12879 startup.wShowWindow = SW_SHOWNORMAL;
12881 thread = CreateThread( NULL, 0, wait_idle_thread, NULL, 0, &id );
12883 for (i = 0; i < sizeof(wait_idle_expect)/sizeof(wait_idle_expect[0]); i++)
12885 ResetEvent( start_event );
12886 ResetEvent( end_event );
12887 sprintf( path, "%s msg %u", argv0, i );
12888 ret = CreateProcessA( NULL, path, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &pi );
12889 ok( ret, "CreateProcess '%s' failed err %u.\n", path, GetLastError() );
12890 if (ret)
12892 ret = WaitForSingleObject( start_event, 5000 );
12893 ok( ret == WAIT_OBJECT_0, "%u: WaitForSingleObject failed\n", i );
12894 if (ret == WAIT_OBJECT_0)
12896 ret = WaitForInputIdle( pi.hProcess, 1000 );
12897 if (ret == WAIT_FAILED)
12898 ok( console_app ||
12899 ret == wait_idle_expect[i].exp ||
12900 broken(ret == wait_idle_expect[i].broken),
12901 "%u: WaitForInputIdle error %08x expected %08x\n",
12902 i, ret, wait_idle_expect[i].exp );
12903 else if (wait_idle_expect[i].todo)
12904 todo_wine
12905 ok( ret == wait_idle_expect[i].exp || broken(ret == wait_idle_expect[i].broken),
12906 "%u: WaitForInputIdle error %08x expected %08x\n",
12907 i, ret, wait_idle_expect[i].exp );
12908 else
12909 ok( ret == wait_idle_expect[i].exp || broken(ret == wait_idle_expect[i].broken),
12910 "%u: WaitForInputIdle error %08x expected %08x\n",
12911 i, ret, wait_idle_expect[i].exp );
12912 SetEvent( end_event );
12913 WaitForSingleObject( pi.hProcess, 1000 ); /* give it a chance to exit on its own */
12915 TerminateProcess( pi.hProcess, 0 ); /* just in case */
12916 winetest_wait_child_process( pi.hProcess );
12917 ret = WaitForInputIdle( pi.hProcess, 100 );
12918 ok( ret == WAIT_FAILED, "%u: WaitForInputIdle after exit error %08x\n", i, ret );
12919 CloseHandle( pi.hProcess );
12920 CloseHandle( pi.hThread );
12923 CloseHandle( start_event );
12924 PostThreadMessage( id, WM_QUIT, 0, 0 );
12925 WaitForSingleObject( thread, 10000 );
12926 CloseHandle( thread );
12929 static const struct message WmSetParentSeq_1[] = {
12930 { WM_SHOWWINDOW, sent|wparam, 0 },
12931 { EVENT_OBJECT_PARENTCHANGE, winevent_hook|wparam|lparam, 0, 0 },
12932 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
12933 { WM_CHILDACTIVATE, sent },
12934 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW|SWP_NOCLIENTSIZE },
12935 { WM_MOVE, sent|defwinproc|wparam, 0 },
12936 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
12937 { WM_SHOWWINDOW, sent|wparam, 1 },
12938 { 0 }
12941 static const struct message WmSetParentSeq_2[] = {
12942 { WM_SHOWWINDOW, sent|wparam, 0 },
12943 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
12944 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
12945 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
12946 { HCBT_SETFOCUS, hook|optional },
12947 { WM_NCACTIVATE, sent|wparam|optional, 0 },
12948 { WM_ACTIVATE, sent|wparam|optional, 0 },
12949 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
12950 { WM_KILLFOCUS, sent|wparam, 0 },
12951 { EVENT_OBJECT_PARENTCHANGE, winevent_hook|wparam|lparam, 0, 0 },
12952 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
12953 { HCBT_ACTIVATE, hook|optional },
12954 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
12955 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
12956 { WM_NCACTIVATE, sent|wparam|optional, 1 },
12957 { WM_ACTIVATE, sent|wparam|optional, 1 },
12958 { HCBT_SETFOCUS, hook|optional },
12959 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
12960 { WM_SETFOCUS, sent|optional|defwinproc },
12961 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOREDRAW|SWP_NOSIZE|SWP_NOCLIENTSIZE },
12962 { WM_MOVE, sent|defwinproc|wparam, 0 },
12963 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
12964 { WM_SHOWWINDOW, sent|wparam, 1 },
12965 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
12966 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
12967 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
12968 { 0 }
12972 static void test_SetParent(void)
12974 HWND parent1, parent2, child, popup;
12975 RECT rc, rc_old;
12977 parent1 = CreateWindowEx(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW,
12978 100, 100, 200, 200, 0, 0, 0, NULL);
12979 ok(parent1 != 0, "Failed to create parent1 window\n");
12981 parent2 = CreateWindowEx(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW,
12982 400, 100, 200, 200, 0, 0, 0, NULL);
12983 ok(parent2 != 0, "Failed to create parent2 window\n");
12985 /* WS_CHILD window */
12986 child = CreateWindowEx(0, "TestWindowClass", NULL, WS_CHILD | WS_VISIBLE,
12987 10, 10, 150, 150, parent1, 0, 0, NULL);
12988 ok(child != 0, "Failed to create child window\n");
12990 GetWindowRect(parent1, &rc);
12991 trace("parent1 (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
12992 GetWindowRect(child, &rc_old);
12993 MapWindowPoints(0, parent1, (POINT *)&rc_old, 2);
12994 trace("child (%d,%d)-(%d,%d)\n", rc_old.left, rc_old.top, rc_old.right, rc_old.bottom);
12996 flush_sequence();
12998 SetParent(child, parent2);
12999 flush_events();
13000 ok_sequence(WmSetParentSeq_1, "SetParent() visible WS_CHILD", TRUE);
13002 ok(GetWindowLongA(child, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
13003 ok(!IsWindowVisible(child), "IsWindowVisible() should return FALSE\n");
13005 GetWindowRect(parent2, &rc);
13006 trace("parent2 (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
13007 GetWindowRect(child, &rc);
13008 MapWindowPoints(0, parent2, (POINT *)&rc, 2);
13009 trace("child (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
13011 ok(EqualRect(&rc_old, &rc), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
13012 rc_old.left, rc_old.top, rc_old.right, rc_old.bottom,
13013 rc.left, rc.top, rc.right, rc.bottom );
13015 /* WS_POPUP window */
13016 popup = CreateWindowEx(0, "TestWindowClass", NULL, WS_POPUP | WS_VISIBLE,
13017 20, 20, 100, 100, 0, 0, 0, NULL);
13018 ok(popup != 0, "Failed to create popup window\n");
13020 GetWindowRect(popup, &rc_old);
13021 trace("popup (%d,%d)-(%d,%d)\n", rc_old.left, rc_old.top, rc_old.right, rc_old.bottom);
13023 flush_sequence();
13025 SetParent(popup, child);
13026 flush_events();
13027 ok_sequence(WmSetParentSeq_2, "SetParent() visible WS_POPUP", TRUE);
13029 ok(GetWindowLongA(popup, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
13030 ok(!IsWindowVisible(popup), "IsWindowVisible() should return FALSE\n");
13032 GetWindowRect(child, &rc);
13033 trace("parent2 (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
13034 GetWindowRect(popup, &rc);
13035 MapWindowPoints(0, child, (POINT *)&rc, 2);
13036 trace("popup (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
13038 ok(EqualRect(&rc_old, &rc), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
13039 rc_old.left, rc_old.top, rc_old.right, rc_old.bottom,
13040 rc.left, rc.top, rc.right, rc.bottom );
13042 DestroyWindow(popup);
13043 DestroyWindow(child);
13044 DestroyWindow(parent1);
13045 DestroyWindow(parent2);
13047 flush_sequence();
13050 static const struct message WmKeyReleaseOnly[] = {
13051 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 0x41, 0x80000001 },
13052 { WM_KEYUP, sent|wparam|lparam, 0x41, 0x80000001 },
13053 { 0 }
13055 static const struct message WmKeyPressNormal[] = {
13056 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 0x41, 0x1 },
13057 { WM_KEYDOWN, sent|wparam|lparam, 0x41, 0x1 },
13058 { 0 }
13060 static const struct message WmKeyPressRepeat[] = {
13061 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 0x41, 0x40000001 },
13062 { WM_KEYDOWN, sent|wparam|lparam, 0x41, 0x40000001 },
13063 { 0 }
13065 static const struct message WmKeyReleaseNormal[] = {
13066 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 0x41, 0xc0000001 },
13067 { WM_KEYUP, sent|wparam|lparam, 0x41, 0xc0000001 },
13068 { 0 }
13071 static void test_keyflags(void)
13073 HWND test_window;
13074 SHORT key_state;
13075 BYTE keyboard_state[256];
13076 MSG msg;
13078 test_window = CreateWindowEx(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
13079 100, 100, 200, 200, 0, 0, 0, NULL);
13081 flush_events();
13082 flush_sequence();
13084 /* keyup without a keydown */
13085 keybd_event(0x41, 0, KEYEVENTF_KEYUP, 0);
13086 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13087 DispatchMessage(&msg);
13088 ok_sequence(WmKeyReleaseOnly, "key release only", TRUE);
13090 key_state = GetAsyncKeyState(0x41);
13091 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13093 key_state = GetKeyState(0x41);
13094 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13096 /* keydown */
13097 keybd_event(0x41, 0, 0, 0);
13098 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13099 DispatchMessage(&msg);
13100 ok_sequence(WmKeyPressNormal, "key press only", FALSE);
13102 key_state = GetAsyncKeyState(0x41);
13103 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13105 key_state = GetKeyState(0x41);
13106 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13108 /* keydown repeat */
13109 keybd_event(0x41, 0, 0, 0);
13110 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13111 DispatchMessage(&msg);
13112 ok_sequence(WmKeyPressRepeat, "key press repeat", FALSE);
13114 key_state = GetAsyncKeyState(0x41);
13115 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13117 key_state = GetKeyState(0x41);
13118 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13120 /* keyup */
13121 keybd_event(0x41, 0, KEYEVENTF_KEYUP, 0);
13122 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13123 DispatchMessage(&msg);
13124 ok_sequence(WmKeyReleaseNormal, "key release repeat", FALSE);
13126 key_state = GetAsyncKeyState(0x41);
13127 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13129 key_state = GetKeyState(0x41);
13130 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13132 /* set the key state in this thread */
13133 GetKeyboardState(keyboard_state);
13134 keyboard_state[0x41] = 0x80;
13135 SetKeyboardState(keyboard_state);
13137 key_state = GetAsyncKeyState(0x41);
13138 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13140 /* keydown */
13141 keybd_event(0x41, 0, 0, 0);
13142 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13143 DispatchMessage(&msg);
13144 ok_sequence(WmKeyPressRepeat, "key press after setkeyboardstate", TRUE);
13146 key_state = GetAsyncKeyState(0x41);
13147 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13149 key_state = GetKeyState(0x41);
13150 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13152 /* clear the key state in this thread */
13153 GetKeyboardState(keyboard_state);
13154 keyboard_state[0x41] = 0;
13155 SetKeyboardState(keyboard_state);
13157 key_state = GetAsyncKeyState(0x41);
13158 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13160 /* keyup */
13161 keybd_event(0x41, 0, KEYEVENTF_KEYUP, 0);
13162 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13163 DispatchMessage(&msg);
13164 ok_sequence(WmKeyReleaseOnly, "key release after setkeyboardstate", TRUE);
13166 key_state = GetAsyncKeyState(0x41);
13167 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13169 key_state = GetKeyState(0x41);
13170 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13172 DestroyWindow(test_window);
13173 flush_sequence();
13176 static const struct message WmHotkeyPressLWIN[] = {
13177 { WM_KEYDOWN, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED },
13178 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 1 },
13179 { WM_KEYDOWN, sent|wparam|lparam, VK_LWIN, 1 },
13180 { 0 }
13182 static const struct message WmHotkeyPress[] = {
13183 { WM_KEYDOWN, kbd_hook|lparam, 0, LLKHF_INJECTED },
13184 { WM_HOTKEY, sent|wparam, 5 },
13185 { 0 }
13187 static const struct message WmHotkeyRelease[] = {
13188 { WM_KEYUP, kbd_hook|lparam, 0, LLKHF_INJECTED|LLKHF_UP },
13189 { HCBT_KEYSKIPPED, hook|lparam|optional, 0, 0x80000001 },
13190 { WM_KEYUP, sent|lparam, 0, 0x80000001 },
13191 { 0 }
13193 static const struct message WmHotkeyReleaseLWIN[] = {
13194 { WM_KEYUP, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED|LLKHF_UP },
13195 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 0xc0000001 },
13196 { WM_KEYUP, sent|wparam|lparam, VK_LWIN, 0xc0000001 },
13197 { 0 }
13199 static const struct message WmHotkeyCombined[] = {
13200 { WM_KEYDOWN, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED },
13201 { WM_KEYDOWN, kbd_hook|lparam, 0, LLKHF_INJECTED },
13202 { WM_KEYUP, kbd_hook|lparam, 0, LLKHF_INJECTED|LLKHF_UP },
13203 { WM_KEYUP, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED|LLKHF_UP },
13204 { WM_APP, sent, 0, 0 },
13205 { WM_HOTKEY, sent|wparam, 5 },
13206 { WM_APP+1, sent, 0, 0 },
13207 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 1 },
13208 { WM_KEYDOWN, sent|wparam|lparam, VK_LWIN, 1 },
13209 { HCBT_KEYSKIPPED, hook|optional, 0, 0x80000001 },
13210 { WM_KEYUP, sent, 0, 0x80000001 }, /* lparam not checked so the sequence isn't a todo */
13211 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 0xc0000001 },
13212 { WM_KEYUP, sent|wparam|lparam, VK_LWIN, 0xc0000001 },
13213 { 0 }
13215 static const struct message WmHotkeyPrevious[] = {
13216 { WM_KEYDOWN, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED },
13217 { WM_KEYDOWN, kbd_hook|lparam, 0, LLKHF_INJECTED },
13218 { WM_KEYUP, kbd_hook|lparam, 0, LLKHF_INJECTED|LLKHF_UP },
13219 { WM_KEYUP, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED|LLKHF_UP },
13220 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 1 },
13221 { WM_KEYDOWN, sent|wparam|lparam, VK_LWIN, 1 },
13222 { HCBT_KEYSKIPPED, hook|lparam|optional, 0, 1 },
13223 { WM_KEYDOWN, sent|lparam, 0, 1 },
13224 { HCBT_KEYSKIPPED, hook|optional|lparam, 0, 0xc0000001 },
13225 { WM_KEYUP, sent|lparam, 0, 0xc0000001 },
13226 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 0xc0000001 },
13227 { WM_KEYUP, sent|wparam|lparam, VK_LWIN, 0xc0000001 },
13228 { 0 }
13230 static const struct message WmHotkeyNew[] = {
13231 { WM_KEYDOWN, kbd_hook|lparam, 0, LLKHF_INJECTED },
13232 { WM_KEYUP, kbd_hook|lparam, 0, LLKHF_INJECTED|LLKHF_UP },
13233 { WM_HOTKEY, sent|wparam, 5 },
13234 { HCBT_KEYSKIPPED, hook|optional, 0, 0x80000001 },
13235 { WM_KEYUP, sent, 0, 0x80000001 }, /* lparam not checked so the sequence isn't a todo */
13236 { 0 }
13239 static int hotkey_letter;
13241 static LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
13243 struct recvd_message msg;
13245 if (nCode == HC_ACTION)
13247 KBDLLHOOKSTRUCT *kdbhookstruct = (KBDLLHOOKSTRUCT*)lParam;
13249 msg.hwnd = 0;
13250 msg.message = wParam;
13251 msg.flags = kbd_hook|wparam|lparam;
13252 msg.wParam = kdbhookstruct->vkCode;
13253 msg.lParam = kdbhookstruct->flags;
13254 msg.descr = "KeyboardHookProc";
13255 add_message(&msg);
13257 if (wParam == WM_KEYUP || wParam == WM_KEYDOWN)
13259 ok(kdbhookstruct->vkCode == VK_LWIN || kdbhookstruct->vkCode == hotkey_letter,
13260 "unexpected keycode %x\n", kdbhookstruct->vkCode);
13264 return CallNextHookEx(hKBD_hook, nCode, wParam, lParam);
13267 static void test_hotkey(void)
13269 HWND test_window, taskbar_window;
13270 BOOL ret;
13271 MSG msg;
13272 DWORD queue_status;
13273 SHORT key_state;
13275 SetLastError(0xdeadbeef);
13276 ret = UnregisterHotKey(NULL, 0);
13277 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13278 ok(GetLastError() == ERROR_HOTKEY_NOT_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13279 "unexpected error %d\n", GetLastError());
13281 if (ret == TRUE)
13283 skip("hotkeys not supported\n");
13284 return;
13287 test_window = CreateWindowEx(0, "HotkeyWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
13288 100, 100, 200, 200, 0, 0, 0, NULL);
13290 flush_sequence();
13292 SetLastError(0xdeadbeef);
13293 ret = UnregisterHotKey(test_window, 0);
13294 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13295 ok(GetLastError() == ERROR_HOTKEY_NOT_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13296 "unexpected error %d\n", GetLastError());
13298 /* Search for a Windows Key + letter combination that hasn't been registered */
13299 for (hotkey_letter = 0x41; hotkey_letter <= 0x51; hotkey_letter ++)
13301 SetLastError(0xdeadbeef);
13302 ret = RegisterHotKey(test_window, 5, MOD_WIN, hotkey_letter);
13304 if (ret == TRUE)
13306 break;
13308 else
13310 ok(GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13311 "unexpected error %d\n", GetLastError());
13315 if (hotkey_letter == 0x52)
13317 ok(0, "Couldn't find any free Windows Key + letter combination\n");
13318 goto end;
13321 hKBD_hook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProc, GetModuleHandle(NULL), 0);
13322 if (!hKBD_hook) win_skip("WH_KEYBOARD_LL is not supported\n");
13324 /* Same key combination, different id */
13325 SetLastError(0xdeadbeef);
13326 ret = RegisterHotKey(test_window, 4, MOD_WIN, hotkey_letter);
13327 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13328 ok(GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13329 "unexpected error %d\n", GetLastError());
13331 /* Same key combination, different window */
13332 SetLastError(0xdeadbeef);
13333 ret = RegisterHotKey(NULL, 5, MOD_WIN, hotkey_letter);
13334 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13335 ok(GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13336 "unexpected error %d\n", GetLastError());
13338 /* Register the same hotkey twice */
13339 SetLastError(0xdeadbeef);
13340 ret = RegisterHotKey(test_window, 5, MOD_WIN, hotkey_letter);
13341 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13342 ok(GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13343 "unexpected error %d\n", GetLastError());
13345 /* Window on another thread */
13346 taskbar_window = FindWindowA("Shell_TrayWnd", NULL);
13347 if (!taskbar_window)
13349 skip("no taskbar?\n");
13351 else
13353 SetLastError(0xdeadbeef);
13354 ret = RegisterHotKey(taskbar_window, 5, 0, hotkey_letter);
13355 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13356 ok(GetLastError() == ERROR_WINDOW_OF_OTHER_THREAD || broken(GetLastError() == 0xdeadbeef),
13357 "unexpected error %d\n", GetLastError());
13360 /* Inject the appropriate key sequence */
13361 keybd_event(VK_LWIN, 0, 0, 0);
13362 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13363 DispatchMessage(&msg);
13364 ok_sequence(WmHotkeyPressLWIN, "window hotkey press LWIN", FALSE);
13366 keybd_event(hotkey_letter, 0, 0, 0);
13367 queue_status = GetQueueStatus(QS_HOTKEY);
13368 ok((queue_status & (QS_HOTKEY << 16)) == QS_HOTKEY << 16, "expected QS_HOTKEY << 16 set, got %x\n", queue_status);
13369 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13371 if (msg.message == WM_HOTKEY)
13373 ok(msg.hwnd == test_window, "unexpected hwnd %p\n", msg.hwnd);
13374 ok(msg.lParam == MAKELPARAM(MOD_WIN, hotkey_letter), "unexpected WM_HOTKEY lparam %lx\n", msg.lParam);
13376 DispatchMessage(&msg);
13378 ok_sequence(WmHotkeyPress, "window hotkey press", FALSE);
13380 queue_status = GetQueueStatus(QS_HOTKEY);
13381 ok((queue_status & (QS_HOTKEY << 16)) == 0, "expected QS_HOTKEY << 16 cleared, got %x\n", queue_status);
13383 key_state = GetAsyncKeyState(hotkey_letter);
13384 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13386 keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13387 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13388 DispatchMessage(&msg);
13389 ok_sequence(WmHotkeyRelease, "window hotkey release", TRUE);
13391 keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
13392 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13393 DispatchMessage(&msg);
13394 ok_sequence(WmHotkeyReleaseLWIN, "window hotkey release LWIN", FALSE);
13396 /* normal posted WM_HOTKEY messages set QS_HOTKEY */
13397 PostMessage(test_window, WM_HOTKEY, 0, 0);
13398 queue_status = GetQueueStatus(QS_HOTKEY);
13399 ok((queue_status & (QS_HOTKEY << 16)) == QS_HOTKEY << 16, "expected QS_HOTKEY << 16 set, got %x\n", queue_status);
13400 queue_status = GetQueueStatus(QS_POSTMESSAGE);
13401 ok((queue_status & (QS_POSTMESSAGE << 16)) == QS_POSTMESSAGE << 16, "expected QS_POSTMESSAGE << 16 set, got %x\n", queue_status);
13402 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13403 DispatchMessage(&msg);
13404 flush_sequence();
13406 /* Send and process all messages at once */
13407 PostMessage(test_window, WM_APP, 0, 0);
13408 keybd_event(VK_LWIN, 0, 0, 0);
13409 keybd_event(hotkey_letter, 0, 0, 0);
13410 keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13411 keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
13413 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13415 if (msg.message == WM_HOTKEY)
13417 ok(msg.hwnd == test_window, "unexpected hwnd %p\n", msg.hwnd);
13418 ok(msg.lParam == MAKELPARAM(MOD_WIN, hotkey_letter), "unexpected WM_HOTKEY lparam %lx\n", msg.lParam);
13420 DispatchMessage(&msg);
13422 ok_sequence(WmHotkeyCombined, "window hotkey combined", FALSE);
13424 /* Register same hwnd/id with different key combination */
13425 ret = RegisterHotKey(test_window, 5, 0, hotkey_letter);
13426 ok(ret == TRUE, "expected TRUE, got %i, err=%d\n", ret, GetLastError());
13428 /* Previous key combination does not work */
13429 keybd_event(VK_LWIN, 0, 0, 0);
13430 keybd_event(hotkey_letter, 0, 0, 0);
13431 keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13432 keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
13434 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13435 DispatchMessage(&msg);
13436 ok_sequence(WmHotkeyPrevious, "window hotkey previous", FALSE);
13438 /* New key combination works */
13439 keybd_event(hotkey_letter, 0, 0, 0);
13440 keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13442 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13444 if (msg.message == WM_HOTKEY)
13446 ok(msg.hwnd == test_window, "unexpected hwnd %p\n", msg.hwnd);
13447 ok(msg.lParam == MAKELPARAM(0, hotkey_letter), "unexpected WM_HOTKEY lparam %lx\n", msg.lParam);
13449 DispatchMessage(&msg);
13451 ok_sequence(WmHotkeyNew, "window hotkey new", FALSE);
13453 /* Unregister hotkey properly */
13454 ret = UnregisterHotKey(test_window, 5);
13455 ok(ret == TRUE, "expected TRUE, got %i, err=%d\n", ret, GetLastError());
13457 /* Unregister hotkey again */
13458 SetLastError(0xdeadbeef);
13459 ret = UnregisterHotKey(test_window, 5);
13460 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13461 ok(GetLastError() == ERROR_HOTKEY_NOT_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13462 "unexpected error %d\n", GetLastError());
13464 /* Register thread hotkey */
13465 ret = RegisterHotKey(NULL, 5, MOD_WIN, hotkey_letter);
13466 ok(ret == TRUE, "expected TRUE, got %i, err=%d\n", ret, GetLastError());
13468 /* Inject the appropriate key sequence */
13469 keybd_event(VK_LWIN, 0, 0, 0);
13470 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13472 ok(msg.hwnd != NULL, "unexpected thread message %x\n", msg.message);
13473 DispatchMessage(&msg);
13475 ok_sequence(WmHotkeyPressLWIN, "thread hotkey press LWIN", FALSE);
13477 keybd_event(hotkey_letter, 0, 0, 0);
13478 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13480 if (msg.message == WM_HOTKEY)
13482 struct recvd_message message;
13483 ok(msg.hwnd == NULL, "unexpected hwnd %p\n", msg.hwnd);
13484 ok(msg.lParam == MAKELPARAM(MOD_WIN, hotkey_letter), "unexpected WM_HOTKEY lparam %lx\n", msg.lParam);
13485 message.message = msg.message;
13486 message.flags = sent|wparam|lparam;
13487 message.wParam = msg.wParam;
13488 message.lParam = msg.lParam;
13489 message.descr = "test_hotkey thread message";
13490 add_message(&message);
13492 else
13493 ok(msg.hwnd != NULL, "unexpected thread message %x\n", msg.message);
13494 DispatchMessage(&msg);
13496 ok_sequence(WmHotkeyPress, "thread hotkey press", FALSE);
13498 keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13499 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13501 ok(msg.hwnd != NULL, "unexpected thread message %x\n", msg.message);
13502 DispatchMessage(&msg);
13504 ok_sequence(WmHotkeyRelease, "thread hotkey release", TRUE);
13506 keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
13507 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13509 ok(msg.hwnd != NULL, "unexpected thread message %x\n", msg.message);
13510 DispatchMessage(&msg);
13512 ok_sequence(WmHotkeyReleaseLWIN, "thread hotkey release LWIN", FALSE);
13514 /* Unregister thread hotkey */
13515 ret = UnregisterHotKey(NULL, 5);
13516 ok(ret == TRUE, "expected TRUE, got %i, err=%d\n", ret, GetLastError());
13518 if (hKBD_hook) UnhookWindowsHookEx(hKBD_hook);
13519 hKBD_hook = NULL;
13521 end:
13522 UnregisterHotKey(NULL, 5);
13523 UnregisterHotKey(test_window, 5);
13524 DestroyWindow(test_window);
13525 flush_sequence();
13529 static const struct message WmSetFocus_1[] = {
13530 { HCBT_SETFOCUS, hook }, /* child */
13531 { HCBT_ACTIVATE, hook }, /* parent */
13532 { WM_QUERYNEWPALETTE, sent|wparam|lparam|parent|optional, 0, 0 },
13533 { WM_WINDOWPOSCHANGING, sent|parent, 0, SWP_NOSIZE|SWP_NOMOVE },
13534 { WM_ACTIVATEAPP, sent|wparam|parent, 1 },
13535 { WM_NCACTIVATE, sent|parent },
13536 { WM_GETTEXT, sent|defwinproc|parent|optional },
13537 { WM_GETTEXT, sent|defwinproc|parent|optional },
13538 { WM_ACTIVATE, sent|wparam|parent, 1 },
13539 { HCBT_SETFOCUS, hook }, /* parent */
13540 { WM_SETFOCUS, sent|defwinproc|parent },
13541 { WM_KILLFOCUS, sent|parent },
13542 { WM_SETFOCUS, sent },
13543 { 0 }
13545 static const struct message WmSetFocus_2[] = {
13546 { HCBT_SETFOCUS, hook }, /* parent */
13547 { WM_KILLFOCUS, sent },
13548 { WM_SETFOCUS, sent|parent },
13549 { 0 }
13551 static const struct message WmSetFocus_3[] = {
13552 { HCBT_SETFOCUS, hook }, /* child */
13553 { 0 }
13555 static const struct message WmSetFocus_4[] = {
13556 { 0 }
13559 static void test_SetFocus(void)
13561 HWND parent, old_parent, child, old_focus, old_active;
13562 MSG msg;
13563 struct wnd_event wnd_event;
13564 HANDLE hthread;
13565 DWORD ret, tid;
13567 wnd_event.start_event = CreateEvent(NULL, 0, 0, NULL);
13568 ok(wnd_event.start_event != 0, "CreateEvent error %d\n", GetLastError());
13569 hthread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
13570 ok(hthread != 0, "CreateThread error %d\n", GetLastError());
13571 ret = WaitForSingleObject(wnd_event.start_event, INFINITE);
13572 ok(ret == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
13573 CloseHandle(wnd_event.start_event);
13575 parent = CreateWindowEx(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW,
13576 0, 0, 0, 0, 0, 0, 0, NULL);
13577 ok(parent != 0, "failed to create parent window\n");
13578 child = CreateWindowEx(0, "TestWindowClass", NULL, WS_CHILD,
13579 0, 0, 0, 0, parent, 0, 0, NULL);
13580 ok(child != 0, "failed to create child window\n");
13582 trace("parent %p, child %p, thread window %p\n", parent, child, wnd_event.hwnd);
13584 SetFocus(0);
13585 SetActiveWindow(0);
13587 flush_events();
13588 flush_sequence();
13590 ok(GetActiveWindow() == 0, "expected active 0, got %p\n", GetActiveWindow());
13591 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
13593 log_all_parent_messages++;
13595 old_focus = SetFocus(child);
13596 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13597 ok_sequence(WmSetFocus_1, "SetFocus on a child window", TRUE);
13598 ok(old_focus == parent, "expected old focus %p, got %p\n", parent, old_focus);
13599 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13600 ok(GetFocus() == child, "expected focus %p, got %p\n", child, GetFocus());
13602 old_focus = SetFocus(parent);
13603 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13604 ok_sequence(WmSetFocus_2, "SetFocus on a parent window", FALSE);
13605 ok(old_focus == child, "expected old focus %p, got %p\n", child, old_focus);
13606 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13607 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13609 SetLastError(0xdeadbeef);
13610 old_focus = SetFocus((HWND)0xdeadbeef);
13611 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
13612 "expected ERROR_INVALID_WINDOW_HANDLE, got %d\n", GetLastError());
13613 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13614 ok_sequence(WmEmptySeq, "SetFocus on an invalid window", FALSE);
13615 ok(old_focus == 0, "expected old focus 0, got %p\n", old_focus);
13616 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13617 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13619 SetLastError(0xdeadbeef);
13620 old_focus = SetFocus(GetDesktopWindow());
13621 ok(GetLastError() == ERROR_ACCESS_DENIED /* Vista+ */ ||
13622 broken(GetLastError() == 0xdeadbeef), "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
13623 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13624 ok_sequence(WmEmptySeq, "SetFocus on a desktop window", TRUE);
13625 ok(old_focus == 0, "expected old focus 0, got %p\n", old_focus);
13626 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13627 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13629 SetLastError(0xdeadbeef);
13630 old_focus = SetFocus(wnd_event.hwnd);
13631 ok(GetLastError() == ERROR_ACCESS_DENIED /* Vista+ */ ||
13632 broken(GetLastError() == 0xdeadbeef), "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
13633 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13634 ok_sequence(WmEmptySeq, "SetFocus on another thread window", TRUE);
13635 ok(old_focus == 0, "expected old focus 0, got %p\n", old_focus);
13636 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13637 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13639 SetLastError(0xdeadbeef);
13640 old_active = SetActiveWindow((HWND)0xdeadbeef);
13641 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
13642 "expected ERROR_INVALID_WINDOW_HANDLE, got %d\n", GetLastError());
13643 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13644 ok_sequence(WmEmptySeq, "SetActiveWindow on an invalid window", FALSE);
13645 ok(old_active == 0, "expected old focus 0, got %p\n", old_active);
13646 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13647 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13649 SetLastError(0xdeadbeef);
13650 old_active = SetActiveWindow(GetDesktopWindow());
13651 todo_wine
13652 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
13653 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13654 ok_sequence(WmEmptySeq, "SetActiveWindow on a desktop window", TRUE);
13655 ok(old_active == 0, "expected old focus 0, got %p\n", old_focus);
13656 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13657 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13659 SetLastError(0xdeadbeef);
13660 old_active = SetActiveWindow(wnd_event.hwnd);
13661 todo_wine
13662 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
13663 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13664 ok_sequence(WmEmptySeq, "SetActiveWindow on another thread window", TRUE);
13665 ok(old_active == 0, "expected old focus 0, got %p\n", old_active);
13666 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13667 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13669 SetLastError(0xdeadbeef);
13670 ret = AttachThreadInput(GetCurrentThreadId(), tid, TRUE);
13671 ok(ret, "AttachThreadInput error %d\n", GetLastError());
13673 todo_wine {
13674 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13675 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13677 flush_events();
13678 flush_sequence();
13680 old_focus = SetFocus(wnd_event.hwnd);
13681 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13682 ok(old_focus == wnd_event.hwnd, "expected old focus %p, got %p\n", wnd_event.hwnd, old_focus);
13683 ok(GetActiveWindow() == wnd_event.hwnd, "expected active %p, got %p\n", wnd_event.hwnd, GetActiveWindow());
13684 ok(GetFocus() == wnd_event.hwnd, "expected focus %p, got %p\n", wnd_event.hwnd, GetFocus());
13686 old_focus = SetFocus(parent);
13687 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13688 ok(old_focus == parent, "expected old focus %p, got %p\n", parent, old_focus);
13689 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13690 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13692 flush_events();
13693 flush_sequence();
13695 old_active = SetActiveWindow(wnd_event.hwnd);
13696 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13697 ok(old_active == parent, "expected old focus %p, got %p\n", parent, old_active);
13698 ok(GetActiveWindow() == wnd_event.hwnd, "expected active %p, got %p\n", wnd_event.hwnd, GetActiveWindow());
13699 ok(GetFocus() == wnd_event.hwnd, "expected focus %p, got %p\n", wnd_event.hwnd, GetFocus());
13701 SetLastError(0xdeadbeef);
13702 ret = AttachThreadInput(GetCurrentThreadId(), tid, FALSE);
13703 ok(ret, "AttachThreadInput error %d\n", GetLastError());
13705 ok(GetActiveWindow() == 0, "expected active 0, got %p\n", GetActiveWindow());
13706 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
13708 old_parent = SetParent(child, GetDesktopWindow());
13709 ok(old_parent == parent, "expected old parent %p, got %p\n", parent, old_parent);
13711 ok(GetActiveWindow() == 0, "expected active 0, got %p\n", GetActiveWindow());
13712 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
13714 old_focus = SetFocus(parent);
13715 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13716 ok(old_focus == parent, "expected old focus %p, got %p\n", parent, old_focus);
13717 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13718 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13720 flush_events();
13721 flush_sequence();
13723 SetLastError(0xdeadbeef);
13724 old_focus = SetFocus(child);
13725 todo_wine
13726 ok(GetLastError() == ERROR_INVALID_PARAMETER /* Vista+ */ ||
13727 broken(GetLastError() == 0) /* XP */ ||
13728 broken(GetLastError() == 0xdeadbeef), "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
13729 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13730 ok_sequence(WmSetFocus_3, "SetFocus on a child window", TRUE);
13731 ok(old_focus == 0, "expected old focus 0, got %p\n", old_focus);
13732 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13733 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13735 SetLastError(0xdeadbeef);
13736 old_active = SetActiveWindow(child);
13737 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
13738 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13739 ok_sequence(WmEmptySeq, "SetActiveWindow on a child window", FALSE);
13740 ok(old_active == parent, "expected old active %p, got %p\n", parent, old_active);
13741 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13742 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13744 log_all_parent_messages--;
13746 DestroyWindow(child);
13747 DestroyWindow(parent);
13749 ret = PostMessage(wnd_event.hwnd, WM_QUIT, 0, 0);
13750 ok(ret, "PostMessage(WM_QUIT) error %d\n", GetLastError());
13751 ret = WaitForSingleObject(hthread, INFINITE);
13752 ok(ret == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
13753 CloseHandle(hthread);
13756 START_TEST(msg)
13758 char **test_argv;
13759 BOOL ret;
13760 BOOL (WINAPI *pIsWinEventHookInstalled)(DWORD)= 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
13761 HMODULE hModuleImm32;
13762 BOOL (WINAPI *pImmDisableIME)(DWORD);
13764 int argc = winetest_get_mainargs( &test_argv );
13765 if (argc >= 3)
13767 unsigned int arg;
13768 /* Child process. */
13769 sscanf (test_argv[2], "%d", (unsigned int *) &arg);
13770 do_wait_idle_child( arg );
13771 return;
13774 init_procs();
13776 hModuleImm32 = LoadLibrary("imm32.dll");
13777 if (hModuleImm32) {
13778 pImmDisableIME = (void *)GetProcAddress(hModuleImm32, "ImmDisableIME");
13779 if (pImmDisableIME)
13780 pImmDisableIME(0);
13782 pImmDisableIME = NULL;
13783 FreeLibrary(hModuleImm32);
13785 if (!RegisterWindowClasses()) assert(0);
13787 if (pSetWinEventHook)
13789 hEvent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX,
13790 GetModuleHandleA(0), win_event_proc,
13791 0, GetCurrentThreadId(),
13792 WINEVENT_INCONTEXT);
13793 if (pIsWinEventHookInstalled && hEvent_hook)
13795 UINT event;
13796 for (event = EVENT_MIN; event <= EVENT_MAX; event++)
13797 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
13800 if (!hEvent_hook) win_skip( "no win event hook support\n" );
13802 cbt_hook_thread_id = GetCurrentThreadId();
13803 hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
13804 if (!hCBT_hook) win_skip( "cannot set global hook, will skip hook tests\n" );
13806 test_winevents();
13808 /* Fix message sequences before removing 4 lines below */
13809 #if 1
13810 if (pUnhookWinEvent && hEvent_hook)
13812 ret = pUnhookWinEvent(hEvent_hook);
13813 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
13814 pUnhookWinEvent = 0;
13816 hEvent_hook = 0;
13817 #endif
13819 test_SetFocus();
13820 test_SetParent();
13821 test_PostMessage();
13822 test_ShowWindow();
13823 test_PeekMessage();
13824 test_PeekMessage2();
13825 test_WaitForInputIdle( test_argv[0] );
13826 test_scrollwindowex();
13827 test_messages();
13828 test_setwindowpos();
13829 test_showwindow();
13830 invisible_parent_tests();
13831 test_mdi_messages();
13832 test_button_messages();
13833 test_static_messages();
13834 test_listbox_messages();
13835 test_combobox_messages();
13836 test_wmime_keydown_message();
13837 test_paint_messages();
13838 test_interthread_messages();
13839 test_message_conversion();
13840 test_accelerators();
13841 test_timers();
13842 test_timers_no_wnd();
13843 if (hCBT_hook) test_set_hook();
13844 test_DestroyWindow();
13845 test_DispatchMessage();
13846 test_SendMessageTimeout();
13847 test_edit_messages();
13848 test_quit_message();
13849 test_SetActiveWindow();
13851 if (!pTrackMouseEvent)
13852 win_skip("TrackMouseEvent is not available\n");
13853 else
13854 test_TrackMouseEvent();
13856 test_SetWindowRgn();
13857 test_sys_menu();
13858 test_dialog_messages();
13859 test_EndDialog();
13860 test_nullCallback();
13861 test_dbcs_wm_char();
13862 test_menu_messages();
13863 test_paintingloop();
13864 test_defwinproc();
13865 test_clipboard_viewers();
13866 test_keyflags();
13867 test_hotkey();
13868 /* keep it the last test, under Windows it tends to break the tests
13869 * which rely on active/foreground windows being correct.
13871 test_SetForegroundWindow();
13873 UnhookWindowsHookEx(hCBT_hook);
13874 if (pUnhookWinEvent && hEvent_hook)
13876 ret = pUnhookWinEvent(hEvent_hook);
13877 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
13878 SetLastError(0xdeadbeef);
13879 ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
13880 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
13881 GetLastError() == 0xdeadbeef, /* Win9x */
13882 "unexpected error %d\n", GetLastError());