user32/tests: Ignore paint messages in hotkey tests.
[wine/multimedia.git] / dlls / user32 / tests / msg.c
blobda7e3d98b723425e8df8b2940abc2d498714eb1a
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 maximaze 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)
2030 if (expected->flags & wparam)
2032 if (((expected->wParam ^ actual->wParam) & ~expected->wp_mask) && todo)
2034 todo_wine {
2035 failcount ++;
2036 if (strcmp(winetest_platform, "wine")) dump++;
2037 ok_( file, line) (FALSE,
2038 "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2039 context, count, expected->message, expected->wParam, actual->wParam);
2042 else
2044 ok_( file, line)( ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) == 0,
2045 "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2046 context, count, expected->message, expected->wParam, actual->wParam);
2047 if ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) dump++;
2051 if (expected->flags & lparam)
2053 if (((expected->lParam ^ actual->lParam) & ~expected->lp_mask) && todo)
2055 todo_wine {
2056 failcount ++;
2057 if (strcmp(winetest_platform, "wine")) dump++;
2058 ok_( file, line) (FALSE,
2059 "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2060 context, count, expected->message, expected->lParam, actual->lParam);
2063 else
2065 ok_( file, line)(((expected->lParam ^ actual->lParam) & ~expected->lp_mask) == 0,
2066 "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2067 context, count, expected->message, expected->lParam, actual->lParam);
2068 if ((expected->lParam ^ actual->lParam) & ~expected->lp_mask) dump++;
2071 if ((expected->flags & optional) &&
2072 ((expected->flags ^ actual->flags) & (defwinproc|parent)))
2074 /* don't match optional messages if their defwinproc or parent status differs */
2075 expected++;
2076 count++;
2077 continue;
2079 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
2081 todo_wine {
2082 failcount ++;
2083 if (strcmp(winetest_platform, "wine")) dump++;
2084 ok_( file, line) (FALSE,
2085 "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2086 context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2089 else
2091 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
2092 "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2093 context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2094 if ((expected->flags & defwinproc) != (actual->flags & defwinproc)) dump++;
2097 ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
2098 "%s: %u: the msg 0x%04x should %shave been sent by BeginPaint\n",
2099 context, count, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
2100 if ((expected->flags & beginpaint) != (actual->flags & beginpaint)) dump++;
2102 ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
2103 "%s: %u: the msg 0x%04x should have been %s\n",
2104 context, count, expected->message, (expected->flags & posted) ? "posted" : "sent");
2105 if ((expected->flags & (sent|posted)) != (actual->flags & (sent|posted))) dump++;
2107 ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
2108 "%s: %u: the msg 0x%04x was expected in %s\n",
2109 context, count, expected->message, (expected->flags & parent) ? "parent" : "child");
2110 if ((expected->flags & parent) != (actual->flags & parent)) dump++;
2112 ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
2113 "%s: %u: the msg 0x%04x should have been sent by a hook\n",
2114 context, count, expected->message);
2115 if ((expected->flags & hook) != (actual->flags & hook)) dump++;
2117 ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
2118 "%s: %u: the msg 0x%04x should have been sent by a winevent hook\n",
2119 context, count, expected->message);
2120 if ((expected->flags & winevent_hook) != (actual->flags & winevent_hook)) dump++;
2122 ok_( file, line) ((expected->flags & kbd_hook) == (actual->flags & kbd_hook),
2123 "%s: %u: the msg 0x%04x should have been sent by a keyboard hook\n",
2124 context, count, expected->message);
2125 if ((expected->flags & kbd_hook) != (actual->flags & kbd_hook)) dump++;
2127 expected++;
2128 actual++;
2130 /* silently drop hook messages if there is no support for them */
2131 else if ((expected->flags & optional) ||
2132 ((expected->flags & hook) && !hCBT_hook) ||
2133 ((expected->flags & winevent_hook) && !hEvent_hook))
2134 expected++;
2135 else if (todo)
2137 failcount++;
2138 todo_wine {
2139 if (strcmp(winetest_platform, "wine")) dump++;
2140 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2141 context, count, expected->message, actual->message);
2143 goto done;
2145 else
2147 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2148 context, count, expected->message, actual->message);
2149 dump++;
2150 expected++;
2151 actual++;
2153 count++;
2156 /* skip all optional trailing messages */
2157 while (expected->message && ((expected->flags & optional) ||
2158 ((expected->flags & hook) && !hCBT_hook) ||
2159 ((expected->flags & winevent_hook) && !hEvent_hook)))
2160 expected++;
2162 if (todo)
2164 todo_wine {
2165 if (expected->message || actual->message) {
2166 failcount++;
2167 if (strcmp(winetest_platform, "wine")) dump++;
2168 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2169 context, count, expected->message, actual->message);
2173 else
2175 if (expected->message || actual->message)
2177 dump++;
2178 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2179 context, count, expected->message, actual->message);
2182 if( todo && !failcount) /* succeeded yet marked todo */
2183 todo_wine {
2184 if (!strcmp(winetest_platform, "wine")) dump++;
2185 ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
2188 done:
2189 if (dump) dump_sequence(expected_list, context, file, line);
2190 flush_sequence();
2193 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
2195 /******************************** MDI test **********************************/
2197 /* CreateWindow for MDI frame window, initially visible */
2198 static const struct message WmCreateMDIframeSeq[] = {
2199 { HCBT_CREATEWND, hook },
2200 { WM_GETMINMAXINFO, sent },
2201 { WM_NCCREATE, sent },
2202 { WM_NCCALCSIZE, sent|wparam, 0 },
2203 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2204 { WM_CREATE, sent },
2205 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2206 { WM_NOTIFYFORMAT, sent|optional },
2207 { WM_QUERYUISTATE, sent|optional },
2208 { WM_WINDOWPOSCHANGING, sent|optional },
2209 { WM_GETMINMAXINFO, sent|optional },
2210 { WM_NCCALCSIZE, sent|optional },
2211 { WM_WINDOWPOSCHANGED, sent|optional },
2212 { WM_SHOWWINDOW, sent|wparam, 1 },
2213 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2214 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2215 { HCBT_ACTIVATE, hook },
2216 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
2217 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
2218 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
2219 { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
2220 { WM_NCACTIVATE, sent },
2221 { WM_GETTEXT, sent|defwinproc|optional },
2222 { WM_ACTIVATE, sent|wparam, 1 },
2223 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
2224 { HCBT_SETFOCUS, hook },
2225 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2226 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2227 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2228 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
2229 /* Win9x adds SWP_NOZORDER below */
2230 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2231 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2232 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2233 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2234 { WM_MOVE, sent },
2235 { 0 }
2237 /* DestroyWindow for MDI frame window, initially visible */
2238 static const struct message WmDestroyMDIframeSeq[] = {
2239 { HCBT_DESTROYWND, hook },
2240 { 0x0090, sent|optional },
2241 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2242 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2243 { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2244 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2245 { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
2246 { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2247 { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
2248 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
2249 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2250 { WM_DESTROY, sent },
2251 { WM_NCDESTROY, sent },
2252 { 0 }
2254 /* CreateWindow for MDI client window, initially visible */
2255 static const struct message WmCreateMDIclientSeq[] = {
2256 { HCBT_CREATEWND, hook },
2257 { WM_NCCREATE, sent },
2258 { WM_NCCALCSIZE, sent|wparam, 0 },
2259 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2260 { WM_CREATE, sent },
2261 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2262 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2263 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2264 { WM_MOVE, sent },
2265 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
2266 { WM_SHOWWINDOW, sent|wparam, 1 },
2267 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2268 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2269 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2270 { 0 }
2272 /* ShowWindow(SW_SHOW) for MDI client window */
2273 static const struct message WmShowMDIclientSeq[] = {
2274 { WM_SHOWWINDOW, sent|wparam, 1 },
2275 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2276 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2277 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2278 { 0 }
2280 /* ShowWindow(SW_HIDE) for MDI client window */
2281 static const struct message WmHideMDIclientSeq[] = {
2282 { WM_SHOWWINDOW, sent|wparam, 0 },
2283 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2284 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
2285 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
2286 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2287 { 0 }
2289 /* DestroyWindow for MDI client window, initially visible */
2290 static const struct message WmDestroyMDIclientSeq[] = {
2291 { HCBT_DESTROYWND, hook },
2292 { 0x0090, sent|optional },
2293 { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
2294 { WM_SHOWWINDOW, sent|wparam, 0 },
2295 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2296 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2297 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2298 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2299 { WM_DESTROY, sent },
2300 { WM_NCDESTROY, sent },
2301 { 0 }
2303 /* CreateWindow for MDI child window, initially visible */
2304 static const struct message WmCreateMDIchildVisibleSeq[] = {
2305 { HCBT_CREATEWND, hook },
2306 { WM_NCCREATE, sent },
2307 { WM_NCCALCSIZE, sent|wparam, 0 },
2308 { WM_CREATE, sent },
2309 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2310 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2311 { WM_MOVE, sent },
2312 /* Win2k sends wparam set to
2313 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2314 * while Win9x doesn't bother to set child window id according to
2315 * CLIENTCREATESTRUCT.idFirstChild
2317 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2318 { WM_SHOWWINDOW, sent|wparam, 1 },
2319 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2320 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2321 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2322 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2323 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2324 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2325 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2327 /* Win9x: message sequence terminates here. */
2329 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2330 { HCBT_SETFOCUS, hook }, /* in MDI client */
2331 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2332 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2333 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2334 { WM_SETFOCUS, sent }, /* in MDI client */
2335 { HCBT_SETFOCUS, hook },
2336 { WM_KILLFOCUS, sent }, /* in MDI client */
2337 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2338 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2339 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2340 { WM_SETFOCUS, sent|defwinproc },
2341 { WM_MDIACTIVATE, sent|defwinproc },
2342 { 0 }
2344 /* CreateWindow for MDI child window with invisible parent */
2345 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
2346 { HCBT_CREATEWND, hook },
2347 { WM_GETMINMAXINFO, sent },
2348 { WM_NCCREATE, sent },
2349 { WM_NCCALCSIZE, sent|wparam, 0 },
2350 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2351 { WM_CREATE, sent },
2352 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2353 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2354 { WM_MOVE, sent },
2355 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2356 { WM_SHOWWINDOW, sent|wparam, 1 },
2357 { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2358 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2359 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2360 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2362 /* Win9x: message sequence terminates here. */
2364 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2365 { HCBT_SETFOCUS, hook }, /* in MDI client */
2366 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2367 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2368 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2369 { WM_SETFOCUS, sent }, /* in MDI client */
2370 { HCBT_SETFOCUS, hook },
2371 { WM_KILLFOCUS, sent }, /* in MDI client */
2372 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2373 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2374 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2375 { WM_SETFOCUS, sent|defwinproc },
2376 { WM_MDIACTIVATE, sent|defwinproc },
2377 { 0 }
2379 /* DestroyWindow for MDI child window, initially visible */
2380 static const struct message WmDestroyMDIchildVisibleSeq[] = {
2381 { HCBT_DESTROYWND, hook },
2382 /* Win2k sends wparam set to
2383 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2384 * while Win9x doesn't bother to set child window id according to
2385 * CLIENTCREATESTRUCT.idFirstChild
2387 { 0x0090, sent|optional },
2388 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2389 { WM_SHOWWINDOW, sent|wparam, 0 },
2390 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2391 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2392 { WM_ERASEBKGND, sent|parent|optional },
2393 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2395 /* { WM_DESTROY, sent }
2396 * Win9x: message sequence terminates here.
2399 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2400 { WM_KILLFOCUS, sent },
2401 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2402 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2403 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2404 { WM_SETFOCUS, sent }, /* in MDI client */
2406 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2407 { WM_KILLFOCUS, sent }, /* in MDI client */
2408 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2409 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2410 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2411 { WM_SETFOCUS, sent }, /* in MDI client */
2413 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2415 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2416 { WM_KILLFOCUS, sent },
2417 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2418 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2419 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2420 { WM_SETFOCUS, sent }, /* in MDI client */
2422 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2423 { WM_KILLFOCUS, sent }, /* in MDI client */
2424 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2425 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2426 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2427 { WM_SETFOCUS, sent }, /* in MDI client */
2429 { WM_DESTROY, sent },
2431 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2432 { WM_KILLFOCUS, sent },
2433 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2434 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2435 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2436 { WM_SETFOCUS, sent }, /* in MDI client */
2438 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2439 { WM_KILLFOCUS, sent }, /* in MDI client */
2440 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2441 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2442 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2443 { WM_SETFOCUS, sent }, /* in MDI client */
2445 { WM_NCDESTROY, sent },
2446 { 0 }
2448 /* CreateWindow for MDI child window, initially invisible */
2449 static const struct message WmCreateMDIchildInvisibleSeq[] = {
2450 { HCBT_CREATEWND, hook },
2451 { WM_NCCREATE, sent },
2452 { WM_NCCALCSIZE, sent|wparam, 0 },
2453 { WM_CREATE, sent },
2454 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2455 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2456 { WM_MOVE, sent },
2457 /* Win2k sends wparam set to
2458 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2459 * while Win9x doesn't bother to set child window id according to
2460 * CLIENTCREATESTRUCT.idFirstChild
2462 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2463 { 0 }
2465 /* DestroyWindow for MDI child window, initially invisible */
2466 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
2467 { HCBT_DESTROYWND, hook },
2468 /* Win2k sends wparam set to
2469 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2470 * while Win9x doesn't bother to set child window id according to
2471 * CLIENTCREATESTRUCT.idFirstChild
2473 { 0x0090, sent|optional },
2474 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2475 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2476 { WM_DESTROY, sent },
2477 { WM_NCDESTROY, sent },
2478 /* FIXME: Wine destroys an icon/title window while Windows doesn't */
2479 { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
2480 { 0 }
2482 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
2483 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
2484 { HCBT_CREATEWND, hook },
2485 { WM_NCCREATE, sent },
2486 { WM_NCCALCSIZE, sent|wparam, 0 },
2487 { WM_CREATE, sent },
2488 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2489 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2490 { WM_MOVE, sent },
2491 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2492 { WM_GETMINMAXINFO, sent },
2493 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2494 { WM_NCCALCSIZE, sent|wparam, 1 },
2495 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2496 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2497 /* in MDI frame */
2498 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2499 { WM_NCCALCSIZE, sent|wparam, 1 },
2500 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2501 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2502 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2503 /* Win2k sends wparam set to
2504 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2505 * while Win9x doesn't bother to set child window id according to
2506 * CLIENTCREATESTRUCT.idFirstChild
2508 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2509 { WM_SHOWWINDOW, sent|wparam, 1 },
2510 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2511 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2512 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2513 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2514 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2515 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2516 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_FRAMECHANGED },
2518 /* Win9x: message sequence terminates here. */
2520 { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2521 { HCBT_SETFOCUS, hook|optional }, /* in MDI client */
2522 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2523 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2524 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2525 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2526 { HCBT_SETFOCUS, hook|optional },
2527 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2528 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2529 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2530 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2531 { WM_SETFOCUS, sent|defwinproc|optional },
2532 { WM_MDIACTIVATE, sent|defwinproc|optional },
2533 /* in MDI frame */
2534 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2535 { WM_NCCALCSIZE, sent|wparam, 1 },
2536 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2537 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2538 { 0 }
2540 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2541 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2542 /* restore the 1st MDI child */
2543 { WM_SETREDRAW, sent|wparam, 0 },
2544 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2545 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2546 { WM_NCCALCSIZE, sent|wparam, 1 },
2547 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2548 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2549 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2550 /* in MDI frame */
2551 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2552 { WM_NCCALCSIZE, sent|wparam, 1 },
2553 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2554 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2555 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2556 { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2557 /* create the 2nd MDI child */
2558 { HCBT_CREATEWND, hook },
2559 { WM_NCCREATE, sent },
2560 { WM_NCCALCSIZE, sent|wparam, 0 },
2561 { WM_CREATE, sent },
2562 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2563 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2564 { WM_MOVE, sent },
2565 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2566 { WM_GETMINMAXINFO, sent },
2567 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2568 { WM_NCCALCSIZE, sent|wparam, 1 },
2569 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2570 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2571 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2572 /* in MDI frame */
2573 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2574 { WM_NCCALCSIZE, sent|wparam, 1 },
2575 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2576 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2577 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2578 /* Win2k sends wparam set to
2579 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2580 * while Win9x doesn't bother to set child window id according to
2581 * CLIENTCREATESTRUCT.idFirstChild
2583 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2584 { WM_SHOWWINDOW, sent|wparam, 1 },
2585 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2586 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2587 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2588 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2589 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2590 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2592 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2593 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2595 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2597 /* Win9x: message sequence terminates here. */
2599 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2600 { HCBT_SETFOCUS, hook },
2601 { WM_KILLFOCUS, sent|defwinproc|optional }, /* in the 1st MDI child */
2602 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2603 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2604 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2605 { WM_SETFOCUS, sent }, /* in MDI client */
2606 { HCBT_SETFOCUS, hook },
2607 { WM_KILLFOCUS, sent }, /* in MDI client */
2608 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2609 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2610 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2611 { WM_SETFOCUS, sent|defwinproc },
2613 { WM_MDIACTIVATE, sent|defwinproc },
2614 /* in MDI frame */
2615 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2616 { WM_NCCALCSIZE, sent|wparam, 1 },
2617 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2618 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2619 { 0 }
2621 /* WM_MDICREATE MDI child window, initially visible and maximized */
2622 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2623 { WM_MDICREATE, sent },
2624 { HCBT_CREATEWND, hook },
2625 { WM_NCCREATE, sent },
2626 { WM_NCCALCSIZE, sent|wparam, 0 },
2627 { WM_CREATE, sent },
2628 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2629 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2630 { WM_MOVE, sent },
2631 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2632 { WM_GETMINMAXINFO, sent },
2633 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2634 { WM_NCCALCSIZE, sent|wparam, 1 },
2635 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2636 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2638 /* in MDI frame */
2639 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2640 { WM_NCCALCSIZE, sent|wparam, 1 },
2641 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2642 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2643 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2645 /* Win2k sends wparam set to
2646 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2647 * while Win9x doesn't bother to set child window id according to
2648 * CLIENTCREATESTRUCT.idFirstChild
2650 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2651 { WM_SHOWWINDOW, sent|wparam, 1 },
2652 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2654 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2656 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2657 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2658 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2660 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2661 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2663 /* Win9x: message sequence terminates here. */
2665 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2666 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2667 { HCBT_SETFOCUS, hook }, /* in MDI client */
2668 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2669 { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2670 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2671 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2672 { HCBT_SETFOCUS, hook|optional },
2673 { WM_KILLFOCUS, sent }, /* in MDI client */
2674 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2675 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2676 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2677 { WM_SETFOCUS, sent|defwinproc },
2679 { WM_MDIACTIVATE, sent|defwinproc },
2681 /* in MDI child */
2682 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2683 { WM_NCCALCSIZE, sent|wparam, 1 },
2684 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2685 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2687 /* in MDI frame */
2688 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2689 { WM_NCCALCSIZE, sent|wparam, 1 },
2690 { 0x0093, sent|defwinproc|optional },
2691 { 0x0093, sent|defwinproc|optional },
2692 { 0x0093, sent|defwinproc|optional },
2693 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2694 { WM_MOVE, sent|defwinproc },
2695 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2697 /* in MDI client */
2698 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2699 { WM_NCCALCSIZE, sent|wparam, 1 },
2700 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2701 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2703 /* in MDI child */
2704 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2705 { WM_NCCALCSIZE, sent|wparam, 1 },
2706 { 0x0093, sent|optional },
2707 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2708 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2710 { 0x0093, sent|optional },
2711 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2712 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2713 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2714 { 0x0093, sent|defwinproc|optional },
2715 { 0x0093, sent|defwinproc|optional },
2716 { 0x0093, sent|defwinproc|optional },
2717 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2718 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2720 { 0 }
2722 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2723 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2724 { HCBT_CREATEWND, hook },
2725 { WM_GETMINMAXINFO, sent },
2726 { WM_NCCREATE, sent },
2727 { WM_NCCALCSIZE, sent|wparam, 0 },
2728 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2729 { WM_CREATE, sent },
2730 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2731 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2732 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2733 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI frame */
2734 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2735 { WM_MOVE, sent },
2736 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2737 { WM_GETMINMAXINFO, sent },
2738 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2739 { WM_GETMINMAXINFO, sent|defwinproc },
2740 { WM_NCCALCSIZE, sent|wparam, 1 },
2741 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_STATECHANGED },
2742 { WM_MOVE, sent|defwinproc },
2743 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2744 /* in MDI frame */
2745 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2746 { WM_NCCALCSIZE, sent|wparam, 1 },
2747 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2748 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2749 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2750 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2751 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2752 /* Win2k sends wparam set to
2753 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2754 * while Win9x doesn't bother to set child window id according to
2755 * CLIENTCREATESTRUCT.idFirstChild
2757 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2758 { 0 }
2760 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2761 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2762 { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2763 { HCBT_SYSCOMMAND, hook },
2764 { WM_CLOSE, sent|defwinproc },
2765 { WM_MDIDESTROY, sent }, /* in MDI client */
2767 /* bring the 1st MDI child to top */
2768 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2769 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2771 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2773 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2774 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2775 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2777 /* maximize the 1st MDI child */
2778 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2779 { WM_GETMINMAXINFO, sent|defwinproc },
2780 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED },
2781 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2782 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2783 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2784 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2786 /* restore the 2nd MDI child */
2787 { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2788 { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2789 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2790 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2792 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2794 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2795 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2797 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2799 { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2800 /* in MDI frame */
2801 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2802 { WM_NCCALCSIZE, sent|wparam, 1 },
2803 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2804 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2805 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2807 /* bring the 1st MDI child to top */
2808 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2809 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2810 { HCBT_SETFOCUS, hook },
2811 { WM_KILLFOCUS, sent|defwinproc },
2812 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2813 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2814 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2815 { WM_SETFOCUS, sent }, /* in MDI client */
2816 { HCBT_SETFOCUS, hook },
2817 { WM_KILLFOCUS, sent }, /* in MDI client */
2818 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2819 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2820 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2821 { WM_SETFOCUS, sent|defwinproc },
2822 { WM_MDIACTIVATE, sent|defwinproc },
2823 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2825 /* apparently ShowWindow(SW_SHOW) on an MDI client */
2826 { WM_SHOWWINDOW, sent|wparam, 1 },
2827 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2828 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2829 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2830 { WM_MDIREFRESHMENU, sent },
2832 { HCBT_DESTROYWND, hook },
2833 /* Win2k sends wparam set to
2834 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2835 * while Win9x doesn't bother to set child window id according to
2836 * CLIENTCREATESTRUCT.idFirstChild
2838 { 0x0090, sent|defwinproc|optional },
2839 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2840 { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2841 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2842 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2843 { WM_ERASEBKGND, sent|parent|optional },
2844 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2846 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2847 { WM_DESTROY, sent|defwinproc },
2848 { WM_NCDESTROY, sent|defwinproc },
2849 { 0 }
2851 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2852 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2853 { WM_MDIDESTROY, sent }, /* in MDI client */
2854 { WM_SHOWWINDOW, sent|wparam, 0 },
2855 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2856 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2857 { WM_ERASEBKGND, sent|parent|optional },
2858 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2860 { HCBT_SETFOCUS, hook },
2861 { WM_KILLFOCUS, sent },
2862 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2863 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2864 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2865 { WM_SETFOCUS, sent }, /* in MDI client */
2866 { HCBT_SETFOCUS, hook },
2867 { WM_KILLFOCUS, sent }, /* in MDI client */
2868 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2869 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2870 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2871 { WM_SETFOCUS, sent },
2873 /* in MDI child */
2874 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2875 { WM_NCCALCSIZE, sent|wparam, 1 },
2876 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2877 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2879 /* in MDI frame */
2880 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2881 { WM_NCCALCSIZE, sent|wparam, 1 },
2882 { 0x0093, sent|defwinproc|optional },
2883 { 0x0093, sent|defwinproc|optional },
2884 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2885 { WM_MOVE, sent|defwinproc },
2886 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2888 /* in MDI client */
2889 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2890 { WM_NCCALCSIZE, sent|wparam, 1 },
2891 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2892 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2894 /* in MDI child */
2895 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2896 { WM_NCCALCSIZE, sent|wparam, 1 },
2897 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2898 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2900 /* in MDI child */
2901 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2902 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2903 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2904 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2906 /* in MDI frame */
2907 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2908 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2909 { 0x0093, sent|defwinproc|optional },
2910 { 0x0093, sent|defwinproc|optional },
2911 { 0x0093, sent|defwinproc|optional },
2912 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2913 { WM_MOVE, sent|defwinproc },
2914 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2916 /* in MDI client */
2917 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2918 { WM_NCCALCSIZE, sent|wparam, 1 },
2919 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2920 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2922 /* in MDI child */
2923 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2924 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2925 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2926 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2927 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2928 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2930 { 0x0093, sent|defwinproc|optional },
2931 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2932 { 0x0093, sent|defwinproc|optional },
2933 { 0x0093, sent|defwinproc|optional },
2934 { 0x0093, sent|defwinproc|optional },
2935 { 0x0093, sent|optional },
2937 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2938 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2939 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2940 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2941 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2943 /* in MDI frame */
2944 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2945 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2946 { 0x0093, sent|defwinproc|optional },
2947 { 0x0093, sent|defwinproc|optional },
2948 { 0x0093, sent|defwinproc|optional },
2949 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2950 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2951 { 0x0093, sent|optional },
2953 { WM_NCACTIVATE, sent|wparam, 0 },
2954 { WM_MDIACTIVATE, sent },
2956 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2957 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2958 { WM_NCCALCSIZE, sent|wparam, 1 },
2960 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2962 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2963 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2964 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2966 /* in MDI child */
2967 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2968 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2969 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2970 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2972 /* in MDI frame */
2973 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2974 { WM_NCCALCSIZE, sent|wparam, 1 },
2975 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2976 { WM_MOVE, sent|defwinproc },
2977 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2979 /* in MDI client */
2980 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2981 { WM_NCCALCSIZE, sent|wparam, 1 },
2982 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2983 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2984 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2985 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2986 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2987 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2988 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2990 { HCBT_SETFOCUS, hook },
2991 { WM_KILLFOCUS, sent },
2992 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2993 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2994 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2995 { WM_SETFOCUS, sent }, /* in MDI client */
2997 { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2999 { HCBT_DESTROYWND, hook },
3000 /* Win2k sends wparam set to
3001 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
3002 * while Win9x doesn't bother to set child window id according to
3003 * CLIENTCREATESTRUCT.idFirstChild
3005 { 0x0090, sent|optional },
3006 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
3008 { WM_SHOWWINDOW, sent|wparam, 0 },
3009 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3010 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
3011 { WM_ERASEBKGND, sent|parent|optional },
3012 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3014 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
3015 { WM_DESTROY, sent },
3016 { WM_NCDESTROY, sent },
3017 { 0 }
3019 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
3020 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
3021 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3022 { WM_GETMINMAXINFO, sent },
3023 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
3024 { WM_NCCALCSIZE, sent|wparam, 1 },
3025 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3026 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3028 { WM_WINDOWPOSCHANGING, sent|wparam|optional|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3029 { WM_NCACTIVATE, sent|wparam|optional|defwinproc, 1 },
3030 { HCBT_SETFOCUS, hook|optional },
3031 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3032 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3033 { WM_SETFOCUS, sent|optional }, /* in MDI client */
3034 { HCBT_SETFOCUS, hook|optional },
3035 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3036 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3037 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3038 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3039 { WM_SETFOCUS, sent|optional|defwinproc },
3040 { WM_MDIACTIVATE, sent|optional|defwinproc },
3041 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3042 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3043 /* in MDI frame */
3044 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3045 { WM_NCCALCSIZE, sent|wparam, 1 },
3046 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3047 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3048 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3049 { 0 }
3051 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
3052 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
3053 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3054 { WM_GETMINMAXINFO, sent },
3055 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
3056 { WM_GETMINMAXINFO, sent|defwinproc },
3057 { WM_NCCALCSIZE, sent|wparam, 1 },
3058 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3059 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3061 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3062 { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
3063 { HCBT_SETFOCUS, hook|optional },
3064 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3065 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3066 { WM_SETFOCUS, sent|optional }, /* in MDI client */
3067 { HCBT_SETFOCUS, hook|optional },
3068 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3069 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3070 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3071 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3072 { WM_SETFOCUS, sent|defwinproc|optional },
3073 { WM_MDIACTIVATE, sent|defwinproc|optional },
3074 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3075 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3076 { 0 }
3078 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
3079 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
3080 { WM_MDIMAXIMIZE, sent }, /* in MDI client */
3081 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3082 { WM_GETMINMAXINFO, sent },
3083 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3084 { WM_GETMINMAXINFO, sent|defwinproc },
3085 { WM_NCCALCSIZE, sent|wparam, 1 },
3086 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
3087 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3088 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
3089 { WM_MOVE, sent|defwinproc },
3090 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3092 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3093 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3094 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3095 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3096 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3097 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3098 /* in MDI frame */
3099 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3100 { WM_NCCALCSIZE, sent|wparam, 1 },
3101 { 0x0093, sent|defwinproc|optional },
3102 { 0x0094, sent|defwinproc|optional },
3103 { 0x0094, sent|defwinproc|optional },
3104 { 0x0094, sent|defwinproc|optional },
3105 { 0x0094, sent|defwinproc|optional },
3106 { 0x0093, sent|defwinproc|optional },
3107 { 0x0093, sent|defwinproc|optional },
3108 { 0x0091, sent|defwinproc|optional },
3109 { 0x0092, sent|defwinproc|optional },
3110 { 0x0092, sent|defwinproc|optional },
3111 { 0x0092, sent|defwinproc|optional },
3112 { 0x0092, sent|defwinproc|optional },
3113 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3114 { WM_MOVE, sent|defwinproc },
3115 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3116 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
3117 /* in MDI client */
3118 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
3119 { WM_NCCALCSIZE, sent|wparam, 1 },
3120 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3121 { WM_SIZE, sent|wparam, SIZE_RESTORED },
3122 /* in MDI child */
3123 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
3124 { WM_GETMINMAXINFO, sent|defwinproc },
3125 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3126 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3127 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3128 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
3129 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3130 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3131 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3132 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3133 /* in MDI frame */
3134 { 0x0093, sent|optional },
3135 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
3136 { 0x0093, sent|defwinproc|optional },
3137 { 0x0093, sent|defwinproc|optional },
3138 { 0x0093, sent|defwinproc|optional },
3139 { 0x0091, sent|defwinproc|optional },
3140 { 0x0092, sent|defwinproc|optional },
3141 { 0x0092, sent|defwinproc|optional },
3142 { 0x0092, sent|defwinproc|optional },
3143 { 0x0092, sent|defwinproc|optional },
3144 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3145 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3146 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3147 { 0 }
3149 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
3150 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
3151 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3152 { WM_GETMINMAXINFO, sent },
3153 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3154 { WM_NCCALCSIZE, sent|wparam, 1 },
3155 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3156 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3157 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3158 /* in MDI frame */
3159 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3160 { WM_NCCALCSIZE, sent|wparam, 1 },
3161 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3162 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3163 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3164 { 0 }
3166 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
3167 static const struct message WmRestoreMDIchildVisibleSeq[] = {
3168 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3169 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3170 { WM_NCCALCSIZE, sent|wparam, 1 },
3171 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3172 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3173 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3174 /* in MDI frame */
3175 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3176 { WM_NCCALCSIZE, sent|wparam, 1 },
3177 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3178 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3179 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3180 { 0 }
3182 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
3183 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
3184 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3185 { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
3186 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3187 { WM_NCCALCSIZE, sent|wparam, 1 },
3188 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3189 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3190 { WM_MOVE, sent|defwinproc },
3191 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3192 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3193 { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3194 { HCBT_SETFOCUS, hook },
3195 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3196 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
3197 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3198 { WM_SETFOCUS, sent },
3199 { 0 }
3201 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
3202 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
3203 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
3204 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3205 { WM_NCCALCSIZE, sent|wparam, 1 },
3206 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3207 { WM_MOVE, sent|defwinproc },
3208 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
3209 { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
3210 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3211 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3212 /* FIXME: Wine creates an icon/title window while Windows doesn't */
3213 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
3214 { 0 }
3216 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
3217 static const struct message WmRestoreMDIchildInisibleSeq[] = {
3218 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3219 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
3220 { WM_NCCALCSIZE, sent|wparam, 1 },
3221 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3222 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3223 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3224 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3225 /* in MDI frame */
3226 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3227 { WM_NCCALCSIZE, sent|wparam, 1 },
3228 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3229 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3230 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3231 { 0 }
3234 static HWND mdi_client;
3235 static WNDPROC old_mdi_client_proc;
3237 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3239 struct recvd_message msg;
3241 /* do not log painting messages */
3242 if (message != WM_PAINT &&
3243 message != WM_NCPAINT &&
3244 message != WM_SYNCPAINT &&
3245 message != WM_ERASEBKGND &&
3246 message != WM_NCHITTEST &&
3247 message != WM_GETTEXT &&
3248 message != WM_MDIGETACTIVE &&
3249 !ignore_message( message ))
3251 msg.hwnd = hwnd;
3252 msg.message = message;
3253 msg.flags = sent|wparam|lparam;
3254 msg.wParam = wParam;
3255 msg.lParam = lParam;
3256 msg.descr = "mdi client";
3257 add_message(&msg);
3260 return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
3263 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3265 static LONG defwndproc_counter = 0;
3266 LRESULT ret;
3267 struct recvd_message msg;
3269 /* do not log painting messages */
3270 if (message != WM_PAINT &&
3271 message != WM_NCPAINT &&
3272 message != WM_SYNCPAINT &&
3273 message != WM_ERASEBKGND &&
3274 message != WM_NCHITTEST &&
3275 message != WM_GETTEXT &&
3276 !ignore_message( message ))
3278 switch (message)
3280 case WM_MDIACTIVATE:
3282 HWND active, client = GetParent(hwnd);
3284 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
3286 if (hwnd == (HWND)lParam) /* if we are being activated */
3287 ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
3288 else
3289 ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
3290 break;
3294 msg.hwnd = hwnd;
3295 msg.message = message;
3296 msg.flags = sent|wparam|lparam;
3297 if (defwndproc_counter) msg.flags |= defwinproc;
3298 msg.wParam = wParam;
3299 msg.lParam = lParam;
3300 msg.descr = "mdi child";
3301 add_message(&msg);
3304 defwndproc_counter++;
3305 ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
3306 defwndproc_counter--;
3308 return ret;
3311 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3313 static LONG defwndproc_counter = 0;
3314 LRESULT ret;
3315 struct recvd_message msg;
3317 /* do not log painting messages */
3318 if (message != WM_PAINT &&
3319 message != WM_NCPAINT &&
3320 message != WM_SYNCPAINT &&
3321 message != WM_ERASEBKGND &&
3322 message != WM_NCHITTEST &&
3323 message != WM_GETTEXT &&
3324 !ignore_message( message ))
3326 msg.hwnd = hwnd;
3327 msg.message = message;
3328 msg.flags = sent|wparam|lparam;
3329 if (defwndproc_counter) msg.flags |= defwinproc;
3330 msg.wParam = wParam;
3331 msg.lParam = lParam;
3332 msg.descr = "mdi frame";
3333 add_message(&msg);
3336 defwndproc_counter++;
3337 ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
3338 defwndproc_counter--;
3340 return ret;
3343 static BOOL mdi_RegisterWindowClasses(void)
3345 WNDCLASSA cls;
3347 cls.style = 0;
3348 cls.lpfnWndProc = mdi_frame_wnd_proc;
3349 cls.cbClsExtra = 0;
3350 cls.cbWndExtra = 0;
3351 cls.hInstance = GetModuleHandleA(0);
3352 cls.hIcon = 0;
3353 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3354 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3355 cls.lpszMenuName = NULL;
3356 cls.lpszClassName = "MDI_frame_class";
3357 if (!RegisterClassA(&cls)) return FALSE;
3359 cls.lpfnWndProc = mdi_child_wnd_proc;
3360 cls.lpszClassName = "MDI_child_class";
3361 if (!RegisterClassA(&cls)) return FALSE;
3363 if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
3364 old_mdi_client_proc = cls.lpfnWndProc;
3365 cls.hInstance = GetModuleHandleA(0);
3366 cls.lpfnWndProc = mdi_client_hook_proc;
3367 cls.lpszClassName = "MDI_client_class";
3368 if (!RegisterClassA(&cls)) assert(0);
3370 return TRUE;
3373 static void test_mdi_messages(void)
3375 MDICREATESTRUCTA mdi_cs;
3376 CLIENTCREATESTRUCT client_cs;
3377 HWND mdi_frame, mdi_child, mdi_child2, active_child;
3378 BOOL zoomed;
3379 RECT rc;
3380 HMENU hMenu = CreateMenu();
3382 if (!mdi_RegisterWindowClasses()) assert(0);
3384 flush_sequence();
3386 trace("creating MDI frame window\n");
3387 mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
3388 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3389 WS_MAXIMIZEBOX | WS_VISIBLE,
3390 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
3391 GetDesktopWindow(), hMenu,
3392 GetModuleHandleA(0), NULL);
3393 assert(mdi_frame);
3394 ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
3396 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3397 ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
3399 trace("creating MDI client window\n");
3400 GetClientRect(mdi_frame, &rc);
3401 client_cs.hWindowMenu = 0;
3402 client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
3403 mdi_client = CreateWindowExA(0, "MDI_client_class",
3404 NULL,
3405 WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
3406 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
3407 mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3408 assert(mdi_client);
3409 ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
3411 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3412 ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
3414 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3415 ok(!active_child, "wrong active MDI child %p\n", active_child);
3416 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3418 SetFocus(0);
3419 flush_sequence();
3421 trace("creating invisible MDI child window\n");
3422 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3423 WS_CHILD,
3424 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3425 mdi_client, 0, GetModuleHandleA(0), NULL);
3426 assert(mdi_child);
3428 flush_sequence();
3429 ShowWindow(mdi_child, SW_SHOWNORMAL);
3430 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
3432 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3433 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3435 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3436 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3438 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3439 ok(!active_child, "wrong active MDI child %p\n", active_child);
3440 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3442 ShowWindow(mdi_child, SW_HIDE);
3443 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
3444 flush_sequence();
3446 ShowWindow(mdi_child, SW_SHOW);
3447 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
3449 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3450 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3452 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3453 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3455 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3456 ok(!active_child, "wrong active MDI child %p\n", active_child);
3457 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3459 DestroyWindow(mdi_child);
3460 flush_sequence();
3462 trace("creating visible MDI child window\n");
3463 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3464 WS_CHILD | WS_VISIBLE,
3465 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3466 mdi_client, 0, GetModuleHandleA(0), NULL);
3467 assert(mdi_child);
3468 ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
3470 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3471 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3473 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3474 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3476 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3477 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3478 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3479 flush_sequence();
3481 DestroyWindow(mdi_child);
3482 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3484 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3485 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3487 /* Win2k: MDI client still returns a just destroyed child as active
3488 * Win9x: MDI client returns 0
3490 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3491 ok(active_child == mdi_child || /* win2k */
3492 !active_child, /* win9x */
3493 "wrong active MDI child %p\n", active_child);
3494 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3496 flush_sequence();
3498 trace("creating invisible MDI child window\n");
3499 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3500 WS_CHILD,
3501 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3502 mdi_client, 0, GetModuleHandleA(0), NULL);
3503 assert(mdi_child2);
3504 ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
3506 ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
3507 ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
3509 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3510 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3512 /* Win2k: MDI client still returns a just destroyed child as active
3513 * Win9x: MDI client returns mdi_child2
3515 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3516 ok(active_child == mdi_child || /* win2k */
3517 active_child == mdi_child2, /* win9x */
3518 "wrong active MDI child %p\n", active_child);
3519 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3520 flush_sequence();
3522 ShowWindow(mdi_child2, SW_MAXIMIZE);
3523 ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3525 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3526 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3528 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3529 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3530 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3531 flush_sequence();
3533 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3534 ok(GetFocus() == mdi_child2 || /* win2k */
3535 GetFocus() == 0, /* win9x */
3536 "wrong focus window %p\n", GetFocus());
3538 SetFocus(0);
3539 flush_sequence();
3541 ShowWindow(mdi_child2, SW_HIDE);
3542 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3544 ShowWindow(mdi_child2, SW_RESTORE);
3545 ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3546 flush_sequence();
3548 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3549 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3551 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3552 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3553 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3554 flush_sequence();
3556 SetFocus(0);
3557 flush_sequence();
3559 ShowWindow(mdi_child2, SW_HIDE);
3560 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3562 ShowWindow(mdi_child2, SW_SHOW);
3563 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3565 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3566 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3568 ShowWindow(mdi_child2, SW_MAXIMIZE);
3569 ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3571 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3572 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3574 ShowWindow(mdi_child2, SW_RESTORE);
3575 ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3577 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3578 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3580 ShowWindow(mdi_child2, SW_MINIMIZE);
3581 ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3583 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3584 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3586 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3587 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3588 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3589 flush_sequence();
3591 ShowWindow(mdi_child2, SW_RESTORE);
3592 ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", FALSE);
3594 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3595 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3597 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3598 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3599 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3600 flush_sequence();
3602 SetFocus(0);
3603 flush_sequence();
3605 ShowWindow(mdi_child2, SW_HIDE);
3606 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3608 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3609 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3611 DestroyWindow(mdi_child2);
3612 ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3614 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3615 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3617 /* test for maximized MDI children */
3618 trace("creating maximized visible MDI child window 1\n");
3619 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3620 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3621 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3622 mdi_client, 0, GetModuleHandleA(0), NULL);
3623 assert(mdi_child);
3624 ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3625 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3627 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3628 ok(GetFocus() == mdi_child || /* win2k */
3629 GetFocus() == 0, /* win9x */
3630 "wrong focus window %p\n", GetFocus());
3632 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3633 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3634 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3635 flush_sequence();
3637 trace("creating maximized visible MDI child window 2\n");
3638 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3639 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3640 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3641 mdi_client, 0, GetModuleHandleA(0), NULL);
3642 assert(mdi_child2);
3643 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3644 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3645 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3647 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3648 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3650 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3651 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3652 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3653 flush_sequence();
3655 trace("destroying maximized visible MDI child window 2\n");
3656 DestroyWindow(mdi_child2);
3657 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3659 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3661 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3662 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3664 /* Win2k: MDI client still returns a just destroyed child as active
3665 * Win9x: MDI client returns 0
3667 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3668 ok(active_child == mdi_child2 || /* win2k */
3669 !active_child, /* win9x */
3670 "wrong active MDI child %p\n", active_child);
3671 flush_sequence();
3673 ShowWindow(mdi_child, SW_MAXIMIZE);
3674 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3675 flush_sequence();
3677 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3678 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3680 trace("re-creating maximized visible MDI child window 2\n");
3681 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3682 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3683 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3684 mdi_client, 0, GetModuleHandleA(0), NULL);
3685 assert(mdi_child2);
3686 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3687 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3688 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3690 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3691 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3693 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3694 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3695 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3696 flush_sequence();
3698 SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3699 ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3700 ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3702 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3703 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3704 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3706 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3707 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3708 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3709 flush_sequence();
3711 DestroyWindow(mdi_child);
3712 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3714 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3715 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3717 /* Win2k: MDI client still returns a just destroyed child as active
3718 * Win9x: MDI client returns 0
3720 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3721 ok(active_child == mdi_child || /* win2k */
3722 !active_child, /* win9x */
3723 "wrong active MDI child %p\n", active_child);
3724 flush_sequence();
3726 trace("creating maximized invisible MDI child window\n");
3727 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3728 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3729 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3730 mdi_client, 0, GetModuleHandleA(0), NULL);
3731 assert(mdi_child2);
3732 ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", FALSE);
3733 ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3734 ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3735 ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3737 /* Win2k: MDI client still returns a just destroyed child as active
3738 * Win9x: MDI client returns 0
3740 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3741 ok(active_child == mdi_child || /* win2k */
3742 !active_child || active_child == mdi_child2, /* win9x */
3743 "wrong active MDI child %p\n", active_child);
3744 flush_sequence();
3746 trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3747 ShowWindow(mdi_child2, SW_MAXIMIZE);
3748 ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3749 ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3750 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3751 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3753 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3754 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3755 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3756 flush_sequence();
3758 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3759 flush_sequence();
3761 /* end of test for maximized MDI children */
3762 SetFocus(0);
3763 flush_sequence();
3764 trace("creating maximized visible MDI child window 1(Switch test)\n");
3765 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3766 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3767 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3768 mdi_client, 0, GetModuleHandleA(0), NULL);
3769 assert(mdi_child);
3770 ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3771 ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3773 ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3774 ok(GetFocus() == mdi_child || /* win2k */
3775 GetFocus() == 0, /* win9x */
3776 "wrong focus window %p(Switch test)\n", GetFocus());
3778 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3779 ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3780 ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3781 flush_sequence();
3783 trace("creating maximized visible MDI child window 2(Switch test)\n");
3784 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3785 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3786 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3787 mdi_client, 0, GetModuleHandleA(0), NULL);
3788 assert(mdi_child2);
3789 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3791 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3792 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3794 ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3795 ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3797 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3798 ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3799 ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3800 flush_sequence();
3802 trace("Switch child window.\n");
3803 SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3804 ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3805 trace("end of test for switch maximized MDI children\n");
3806 flush_sequence();
3808 /* Prepare for switching test of not maximized MDI children */
3809 ShowWindow( mdi_child, SW_NORMAL );
3810 ok(!IsZoomed(mdi_child), "wrong zoomed state for %p(Switch test)\n", mdi_child);
3811 ok(!IsZoomed(mdi_child2), "wrong zoomed state for %p(Switch test)\n", mdi_child2);
3812 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
3813 ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3814 flush_sequence();
3816 SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child2, 0);
3817 ok_sequence(WmSwitchNotMaximizedChild, "Not maximized child did not switch correctly", FALSE);
3818 trace("end of test for switch not maximized MDI children\n");
3819 flush_sequence();
3821 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3822 flush_sequence();
3824 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3825 flush_sequence();
3827 SetFocus(0);
3828 flush_sequence();
3829 /* end of tests for switch maximized/not maximized MDI children */
3831 mdi_cs.szClass = "MDI_child_Class";
3832 mdi_cs.szTitle = "MDI child";
3833 mdi_cs.hOwner = GetModuleHandleA(0);
3834 mdi_cs.x = 0;
3835 mdi_cs.y = 0;
3836 mdi_cs.cx = CW_USEDEFAULT;
3837 mdi_cs.cy = CW_USEDEFAULT;
3838 mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3839 mdi_cs.lParam = 0;
3840 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3841 ok(mdi_child != 0, "MDI child creation failed\n");
3842 ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3844 ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3846 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3847 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3849 ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3850 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3851 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3853 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3854 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3855 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3856 flush_sequence();
3858 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3859 ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3861 ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3862 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3863 ok(!active_child, "wrong active MDI child %p\n", active_child);
3865 SetFocus(0);
3866 flush_sequence();
3868 DestroyWindow(mdi_client);
3869 ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3871 /* test maximization of MDI child with invisible parent */
3872 client_cs.hWindowMenu = 0;
3873 mdi_client = CreateWindow("MDI_client_class",
3874 NULL,
3875 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3876 0, 0, 660, 430,
3877 mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3878 ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3880 ShowWindow(mdi_client, SW_HIDE);
3881 ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3883 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3884 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3885 0, 0, 650, 440,
3886 mdi_client, 0, GetModuleHandleA(0), NULL);
3887 ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3889 SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3890 ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3891 zoomed = IsZoomed(mdi_child);
3892 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3894 ShowWindow(mdi_client, SW_SHOW);
3895 ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3897 DestroyWindow(mdi_child);
3898 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3900 /* end of test for maximization of MDI child with invisible parent */
3902 DestroyWindow(mdi_client);
3903 ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3905 DestroyWindow(mdi_frame);
3906 ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3908 /************************* End of MDI test **********************************/
3910 static void test_WM_SETREDRAW(HWND hwnd)
3912 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3914 flush_events();
3915 flush_sequence();
3917 SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3918 ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3920 ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3921 ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3923 flush_sequence();
3924 SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3925 ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3927 ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3928 ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3930 /* restore original WS_VISIBLE state */
3931 SetWindowLongA(hwnd, GWL_STYLE, style);
3933 flush_events();
3934 flush_sequence();
3937 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3939 struct recvd_message msg;
3941 if (ignore_message( message )) return 0;
3943 switch (message)
3945 /* ignore */
3946 case WM_MOUSEMOVE:
3947 case WM_NCMOUSEMOVE:
3948 case WM_NCMOUSELEAVE:
3949 case WM_SETCURSOR:
3950 return 0;
3951 case WM_NCHITTEST:
3952 return HTCLIENT;
3955 msg.hwnd = hwnd;
3956 msg.message = message;
3957 msg.flags = sent|wparam|lparam;
3958 msg.wParam = wParam;
3959 msg.lParam = lParam;
3960 msg.descr = "dialog";
3961 add_message(&msg);
3963 if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3964 if (message == WM_TIMER) EndDialog( hwnd, 0 );
3965 return 0;
3968 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3970 DWORD style, exstyle;
3971 INT xmin, xmax;
3972 BOOL ret;
3974 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3975 style = GetWindowLongA(hwnd, GWL_STYLE);
3976 /* do not be confused by WS_DLGFRAME set */
3977 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3979 if (clear) ok(style & clear, "style %08x should be set\n", clear);
3980 if (set) ok(!(style & set), "style %08x should not be set\n", set);
3982 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3983 ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3984 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3985 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3986 else
3987 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3989 style = GetWindowLongA(hwnd, GWL_STYLE);
3990 if (set) ok(style & set, "style %08x should be set\n", set);
3991 if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3993 /* a subsequent call should do nothing */
3994 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3995 ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3996 ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3998 xmin = 0xdeadbeef;
3999 xmax = 0xdeadbeef;
4000 ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
4001 ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
4002 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
4003 ok(xmin == min, "unexpected min scroll value %d\n", xmin);
4004 ok(xmax == max, "unexpected max scroll value %d\n", xmax);
4007 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
4009 DWORD style, exstyle;
4010 SCROLLINFO si;
4011 BOOL ret;
4013 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
4014 style = GetWindowLongA(hwnd, GWL_STYLE);
4015 /* do not be confused by WS_DLGFRAME set */
4016 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
4018 if (clear) ok(style & clear, "style %08x should be set\n", clear);
4019 if (set) ok(!(style & set), "style %08x should not be set\n", set);
4021 si.cbSize = sizeof(si);
4022 si.fMask = SIF_RANGE;
4023 si.nMin = min;
4024 si.nMax = max;
4025 SetScrollInfo(hwnd, ctl, &si, TRUE);
4026 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
4027 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
4028 else
4029 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
4031 style = GetWindowLongA(hwnd, GWL_STYLE);
4032 if (set) ok(style & set, "style %08x should be set\n", set);
4033 if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
4035 /* a subsequent call should do nothing */
4036 SetScrollInfo(hwnd, ctl, &si, TRUE);
4037 if (style & WS_HSCROLL)
4038 ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4039 else if (style & WS_VSCROLL)
4040 ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4041 else
4042 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4044 si.fMask = SIF_PAGE;
4045 si.nPage = 5;
4046 SetScrollInfo(hwnd, ctl, &si, FALSE);
4047 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4049 si.fMask = SIF_POS;
4050 si.nPos = max - 1;
4051 SetScrollInfo(hwnd, ctl, &si, FALSE);
4052 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4054 si.fMask = SIF_RANGE;
4055 si.nMin = 0xdeadbeef;
4056 si.nMax = 0xdeadbeef;
4057 ret = GetScrollInfo(hwnd, ctl, &si);
4058 ok( ret, "GetScrollInfo error %d\n", GetLastError());
4059 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
4060 ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
4061 ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
4064 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
4065 static void test_scroll_messages(HWND hwnd)
4067 SCROLLINFO si;
4068 INT min, max;
4069 BOOL ret;
4071 flush_events();
4072 flush_sequence();
4074 min = 0xdeadbeef;
4075 max = 0xdeadbeef;
4076 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4077 ok( ret, "GetScrollRange error %d\n", GetLastError());
4078 if (sequence->message != WmGetScrollRangeSeq[0].message)
4079 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4080 /* values of min and max are undefined */
4081 flush_sequence();
4083 ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
4084 ok( ret, "SetScrollRange error %d\n", GetLastError());
4085 if (sequence->message != WmSetScrollRangeSeq[0].message)
4086 trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4087 flush_sequence();
4089 min = 0xdeadbeef;
4090 max = 0xdeadbeef;
4091 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4092 ok( ret, "GetScrollRange error %d\n", GetLastError());
4093 if (sequence->message != WmGetScrollRangeSeq[0].message)
4094 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4095 /* values of min and max are undefined */
4096 flush_sequence();
4098 si.cbSize = sizeof(si);
4099 si.fMask = SIF_RANGE;
4100 si.nMin = 20;
4101 si.nMax = 160;
4102 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4103 if (sequence->message != WmSetScrollRangeSeq[0].message)
4104 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4105 flush_sequence();
4107 si.fMask = SIF_PAGE;
4108 si.nPage = 10;
4109 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4110 if (sequence->message != WmSetScrollRangeSeq[0].message)
4111 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4112 flush_sequence();
4114 si.fMask = SIF_POS;
4115 si.nPos = 20;
4116 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4117 if (sequence->message != WmSetScrollRangeSeq[0].message)
4118 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4119 flush_sequence();
4121 si.fMask = SIF_RANGE;
4122 si.nMin = 0xdeadbeef;
4123 si.nMax = 0xdeadbeef;
4124 ret = GetScrollInfo(hwnd, SB_CTL, &si);
4125 ok( ret, "GetScrollInfo error %d\n", GetLastError());
4126 if (sequence->message != WmGetScrollInfoSeq[0].message)
4127 trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4128 /* values of min and max are undefined */
4129 flush_sequence();
4131 /* set WS_HSCROLL */
4132 test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4133 /* clear WS_HSCROLL */
4134 test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4136 /* set WS_HSCROLL */
4137 test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4138 /* clear WS_HSCROLL */
4139 test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4141 /* set WS_VSCROLL */
4142 test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4143 /* clear WS_VSCROLL */
4144 test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4146 /* set WS_VSCROLL */
4147 test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4148 /* clear WS_VSCROLL */
4149 test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4152 static void test_showwindow(void)
4154 HWND hwnd, hchild;
4155 RECT rc;
4157 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4158 100, 100, 200, 200, 0, 0, 0, NULL);
4159 ok (hwnd != 0, "Failed to create overlapped window\n");
4160 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4161 0, 0, 10, 10, hwnd, 0, 0, NULL);
4162 ok (hchild != 0, "Failed to create child\n");
4163 flush_sequence();
4165 /* ShowWindow( SW_SHOWNA) for invisible top level window */
4166 trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
4167 ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4168 ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", FALSE);
4170 /* ShowWindow( SW_SHOWNA) for now visible top level window */
4171 trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
4172 ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4173 ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
4174 /* back to invisible */
4175 ShowWindow(hchild, SW_HIDE);
4176 ShowWindow(hwnd, SW_HIDE);
4177 flush_sequence();
4178 /* ShowWindow(SW_SHOWNA) with child and parent invisible */
4179 trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
4180 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4181 ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
4182 /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */
4183 ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
4184 flush_sequence();
4185 trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
4186 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4187 ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
4188 /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
4189 ShowWindow( hwnd, SW_SHOW);
4190 flush_sequence();
4191 trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
4192 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4193 ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
4195 /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
4196 ShowWindow( hchild, SW_HIDE);
4197 flush_sequence();
4198 trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
4199 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4200 ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
4202 SetCapture(hchild);
4203 ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
4204 DestroyWindow(hchild);
4205 ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
4207 DestroyWindow(hwnd);
4208 flush_sequence();
4210 /* Popup windows */
4211 /* Test 1:
4212 * 1. Create invisible maximized popup window.
4213 * 2. Move and resize it.
4214 * 3. Show it maximized.
4216 trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4217 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4218 100, 100, 200, 200, 0, 0, 0, NULL);
4219 ok (hwnd != 0, "Failed to create popup window\n");
4220 ok(IsZoomed(hwnd), "window should be maximized\n");
4221 ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4223 GetWindowRect(hwnd, &rc);
4224 ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4225 rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4226 "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
4227 rc.left, rc.top, rc.right, rc.bottom);
4228 /* Reset window's size & position */
4229 SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
4230 ok(IsZoomed(hwnd), "window should be maximized\n");
4231 flush_sequence();
4233 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4234 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4235 ok(IsZoomed(hwnd), "window should be maximized\n");
4236 ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
4238 GetWindowRect(hwnd, &rc);
4239 ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4240 rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4241 "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
4242 rc.left, rc.top, rc.right, rc.bottom);
4243 DestroyWindow(hwnd);
4244 flush_sequence();
4246 /* Test 2:
4247 * 1. Create invisible maximized popup window.
4248 * 2. Show it maximized.
4250 trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4251 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4252 100, 100, 200, 200, 0, 0, 0, NULL);
4253 ok (hwnd != 0, "Failed to create popup window\n");
4254 ok(IsZoomed(hwnd), "window should be maximized\n");
4255 ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4257 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4258 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4259 ok(IsZoomed(hwnd), "window should be maximized\n");
4260 ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
4261 DestroyWindow(hwnd);
4262 flush_sequence();
4264 /* Test 3:
4265 * 1. Create visible maximized popup window.
4267 trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
4268 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4269 100, 100, 200, 200, 0, 0, 0, NULL);
4270 ok (hwnd != 0, "Failed to create popup window\n");
4271 ok(IsZoomed(hwnd), "window should be maximized\n");
4272 ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4273 DestroyWindow(hwnd);
4274 flush_sequence();
4276 /* Test 4:
4277 * 1. Create visible popup window.
4278 * 2. Maximize it.
4280 trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
4281 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
4282 100, 100, 200, 200, 0, 0, 0, NULL);
4283 ok (hwnd != 0, "Failed to create popup window\n");
4284 ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
4285 ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
4287 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
4288 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4289 ok(IsZoomed(hwnd), "window should be maximized\n");
4290 ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
4291 DestroyWindow(hwnd);
4292 flush_sequence();
4295 static void test_sys_menu(void)
4297 HWND hwnd;
4298 HMENU hmenu;
4299 UINT state;
4301 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4302 100, 100, 200, 200, 0, 0, 0, NULL);
4303 ok (hwnd != 0, "Failed to create overlapped window\n");
4305 flush_sequence();
4307 /* test existing window without CS_NOCLOSE style */
4308 hmenu = GetSystemMenu(hwnd, FALSE);
4309 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4311 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4312 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4313 ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4315 EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
4316 ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4318 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4319 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4320 ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
4322 EnableMenuItem(hmenu, SC_CLOSE, 0);
4323 ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4325 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4326 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4327 ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4329 /* test whether removing WS_SYSMENU destroys a system menu */
4330 SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
4331 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4332 flush_sequence();
4333 hmenu = GetSystemMenu(hwnd, FALSE);
4334 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4336 DestroyWindow(hwnd);
4338 /* test new window with CS_NOCLOSE style */
4339 hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4340 100, 100, 200, 200, 0, 0, 0, NULL);
4341 ok (hwnd != 0, "Failed to create overlapped window\n");
4343 hmenu = GetSystemMenu(hwnd, FALSE);
4344 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4346 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4347 ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4349 DestroyWindow(hwnd);
4351 /* test new window without WS_SYSMENU style */
4352 hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
4353 100, 100, 200, 200, 0, 0, 0, NULL);
4354 ok(hwnd != 0, "Failed to create overlapped window\n");
4356 hmenu = GetSystemMenu(hwnd, FALSE);
4357 ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
4359 DestroyWindow(hwnd);
4362 /* For shown WS_OVERLAPPEDWINDOW */
4363 static const struct message WmSetIcon_1[] = {
4364 { WM_SETICON, sent },
4365 { 0x00AE, sent|defwinproc|optional }, /* XP */
4366 { WM_GETTEXT, sent|defwinproc|optional },
4367 { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
4368 { 0 }
4371 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
4372 static const struct message WmSetIcon_2[] = {
4373 { WM_SETICON, sent },
4374 { 0 }
4377 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4378 static const struct message WmInitEndSession[] = {
4379 { 0x003B, sent },
4380 { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4381 { 0 }
4384 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4385 static const struct message WmInitEndSession_2[] = {
4386 { 0x003B, sent },
4387 { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4388 { 0 }
4391 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4392 static const struct message WmInitEndSession_3[] = {
4393 { 0x003B, sent },
4394 { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4395 { 0 }
4398 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4399 static const struct message WmInitEndSession_4[] = {
4400 { 0x003B, sent },
4401 { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4402 { 0 }
4405 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4406 static const struct message WmInitEndSession_5[] = {
4407 { 0x003B, sent },
4408 { WM_ENDSESSION, sent|defwinproc/*|wparam*/|lparam, 1, ENDSESSION_LOGOFF },
4409 { 0 }
4412 static const struct message WmOptionalPaint[] = {
4413 { WM_PAINT, sent|optional },
4414 { WM_NCPAINT, sent|beginpaint|optional },
4415 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4416 { WM_ERASEBKGND, sent|beginpaint|optional },
4417 { 0 }
4420 static const struct message WmZOrder[] = {
4421 { WM_WINDOWPOSCHANGING, sent|wparam, 0, 0 },
4422 { WM_GETMINMAXINFO, sent|defwinproc|wparam, 0, 0 },
4423 { HCBT_ACTIVATE, hook },
4424 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
4425 { WM_WINDOWPOSCHANGING, sent|wparam, 3, 0 },
4426 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0 },
4427 { WM_GETTEXT, sent|optional },
4428 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
4429 { WM_ACTIVATEAPP, sent|wparam, 1, 0 },
4430 { WM_NCACTIVATE, sent|lparam, 1, 0 },
4431 { WM_GETTEXT, sent|defwinproc|optional },
4432 { WM_GETTEXT, sent|defwinproc|optional },
4433 { WM_ACTIVATE, sent|wparam|lparam, 1, 0 },
4434 { HCBT_SETFOCUS, hook },
4435 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4436 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4437 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4438 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
4439 { WM_GETTEXT, sent|optional },
4440 { WM_NCCALCSIZE, sent|optional },
4441 { 0 }
4444 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4446 DWORD ret;
4447 MSG msg;
4449 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4450 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4452 PostMessageA(hwnd, WM_USER, 0, 0);
4454 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4455 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4457 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4458 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4460 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4461 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4463 PostMessageA(hwnd, WM_USER, 0, 0);
4465 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4466 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4468 ok(PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4469 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4471 /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4472 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4473 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4475 PostMessageA(hwnd, WM_USER, 0, 0);
4477 /* new incoming message causes it to become signaled again */
4478 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4479 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4481 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4482 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
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);
4487 /* test if we receive the right sequence of messages */
4488 static void test_messages(void)
4490 HWND hwnd, hparent, hchild;
4491 HWND hchild2, hbutton;
4492 HMENU hmenu;
4493 MSG msg;
4494 LRESULT res;
4496 flush_sequence();
4498 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4499 100, 100, 200, 200, 0, 0, 0, NULL);
4500 ok (hwnd != 0, "Failed to create overlapped window\n");
4501 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4503 /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4504 ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4505 ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4507 /* test WM_SETREDRAW on a not visible top level window */
4508 test_WM_SETREDRAW(hwnd);
4510 SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4511 flush_events();
4512 ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4513 ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4515 ok(GetActiveWindow() == hwnd, "window should be active\n");
4516 ok(GetFocus() == hwnd, "window should have input focus\n");
4517 ShowWindow(hwnd, SW_HIDE);
4518 flush_events();
4519 ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4521 ShowWindow(hwnd, SW_SHOW);
4522 flush_events();
4523 ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4525 ShowWindow(hwnd, SW_HIDE);
4526 flush_events();
4527 ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4529 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4530 flush_events();
4531 ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4532 flush_sequence();
4534 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MAXIMIZE)
4536 ShowWindow(hwnd, SW_RESTORE);
4537 flush_events();
4538 ok_sequence(WmShowRestoreMaxOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4539 flush_sequence();
4542 ShowWindow(hwnd, SW_MINIMIZE);
4543 flush_events();
4544 ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4545 flush_sequence();
4547 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MINIMIZE)
4549 ShowWindow(hwnd, SW_RESTORE);
4550 flush_events();
4551 ok_sequence(WmShowRestoreMinOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4552 flush_sequence();
4555 ShowWindow(hwnd, SW_SHOW);
4556 flush_events();
4557 ok_sequence(WmOptionalPaint, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4559 SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4560 ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4561 ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4562 ok(GetActiveWindow() == hwnd, "window should still be active\n");
4564 /* test WM_SETREDRAW on a visible top level window */
4565 ShowWindow(hwnd, SW_SHOW);
4566 flush_events();
4567 test_WM_SETREDRAW(hwnd);
4569 trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4570 test_scroll_messages(hwnd);
4572 /* test resizing and moving */
4573 SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4574 ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4575 flush_events();
4576 flush_sequence();
4577 SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4578 ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4579 flush_events();
4580 flush_sequence();
4581 SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER|SWP_NOACTIVATE );
4582 ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4583 flush_events();
4584 flush_sequence();
4586 /* popups don't get WM_GETMINMAXINFO */
4587 SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4588 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4589 flush_sequence();
4590 SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4591 ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4593 DestroyWindow(hwnd);
4594 ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4596 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4597 100, 100, 200, 200, 0, 0, 0, NULL);
4598 ok (hparent != 0, "Failed to create parent window\n");
4599 flush_sequence();
4601 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4602 0, 0, 10, 10, hparent, 0, 0, NULL);
4603 ok (hchild != 0, "Failed to create child window\n");
4604 ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4605 DestroyWindow(hchild);
4606 flush_sequence();
4608 /* visible child window with a caption */
4609 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4610 WS_CHILD | WS_VISIBLE | WS_CAPTION,
4611 0, 0, 10, 10, hparent, 0, 0, NULL);
4612 ok (hchild != 0, "Failed to create child window\n");
4613 ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4615 trace("testing scroll APIs on a visible child window %p\n", hchild);
4616 test_scroll_messages(hchild);
4618 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4619 ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4621 DestroyWindow(hchild);
4622 flush_sequence();
4624 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4625 0, 0, 10, 10, hparent, 0, 0, NULL);
4626 ok (hchild != 0, "Failed to create child window\n");
4627 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4629 hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4630 100, 100, 50, 50, hparent, 0, 0, NULL);
4631 ok (hchild2 != 0, "Failed to create child2 window\n");
4632 flush_sequence();
4634 hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4635 0, 100, 50, 50, hchild, 0, 0, NULL);
4636 ok (hbutton != 0, "Failed to create button window\n");
4638 /* test WM_SETREDRAW on a not visible child window */
4639 test_WM_SETREDRAW(hchild);
4641 ShowWindow(hchild, SW_SHOW);
4642 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4644 /* check parent messages too */
4645 log_all_parent_messages++;
4646 ShowWindow(hchild, SW_HIDE);
4647 ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4648 log_all_parent_messages--;
4650 ShowWindow(hchild, SW_SHOW);
4651 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4653 ShowWindow(hchild, SW_HIDE);
4654 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4656 ShowWindow(hchild, SW_SHOW);
4657 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4659 /* test WM_SETREDRAW on a visible child window */
4660 test_WM_SETREDRAW(hchild);
4662 log_all_parent_messages++;
4663 MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4664 ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4665 log_all_parent_messages--;
4667 ShowWindow(hchild, SW_HIDE);
4668 flush_sequence();
4669 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4670 ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4672 ShowWindow(hchild, SW_HIDE);
4673 flush_sequence();
4674 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4675 ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4677 /* DestroyWindow sequence below expects that a child has focus */
4678 SetFocus(hchild);
4679 flush_sequence();
4681 DestroyWindow(hchild);
4682 ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4683 DestroyWindow(hchild2);
4684 DestroyWindow(hbutton);
4686 flush_sequence();
4687 hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4688 0, 0, 100, 100, hparent, 0, 0, NULL);
4689 ok (hchild != 0, "Failed to create child popup window\n");
4690 ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4691 DestroyWindow(hchild);
4693 /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4694 flush_sequence();
4695 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4696 0, 0, 100, 100, hparent, 0, 0, NULL);
4697 ok (hchild != 0, "Failed to create popup window\n");
4698 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4699 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4700 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4701 flush_sequence();
4702 ShowWindow(hchild, SW_SHOW);
4703 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4704 flush_sequence();
4705 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4706 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4707 flush_sequence();
4708 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4709 ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
4710 DestroyWindow(hchild);
4712 /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4713 * changes nothing in message sequences.
4715 flush_sequence();
4716 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4717 0, 0, 100, 100, hparent, 0, 0, NULL);
4718 ok (hchild != 0, "Failed to create popup window\n");
4719 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4720 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4721 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4722 flush_sequence();
4723 ShowWindow(hchild, SW_SHOW);
4724 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4725 flush_sequence();
4726 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4727 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4728 DestroyWindow(hchild);
4730 flush_sequence();
4731 hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4732 0, 0, 100, 100, hparent, 0, 0, NULL);
4733 ok(hwnd != 0, "Failed to create custom dialog window\n");
4734 ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4736 if(0) {
4737 trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4738 test_scroll_messages(hwnd);
4741 flush_sequence();
4743 test_def_id = 1;
4744 SendMessage(hwnd, WM_NULL, 0, 0);
4746 flush_sequence();
4747 after_end_dialog = 1;
4748 EndDialog( hwnd, 0 );
4749 ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4751 DestroyWindow(hwnd);
4752 after_end_dialog = 0;
4753 test_def_id = 0;
4755 hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4756 0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4757 ok(hwnd != 0, "Failed to create custom dialog window\n");
4758 flush_sequence();
4759 trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4760 ShowWindow(hwnd, SW_SHOW);
4761 ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4762 DestroyWindow(hwnd);
4764 flush_sequence();
4765 DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4766 ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4768 DestroyWindow(hparent);
4769 flush_sequence();
4771 /* Message sequence for SetMenu */
4772 ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4773 ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4775 hmenu = CreateMenu();
4776 ok (hmenu != 0, "Failed to create menu\n");
4777 ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4778 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4779 100, 100, 200, 200, 0, hmenu, 0, NULL);
4780 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4781 ok (SetMenu(hwnd, 0), "SetMenu\n");
4782 ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4783 ok (SetMenu(hwnd, 0), "SetMenu\n");
4784 ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4785 ShowWindow(hwnd, SW_SHOW);
4786 UpdateWindow( hwnd );
4787 flush_events();
4788 flush_sequence();
4789 ok (SetMenu(hwnd, 0), "SetMenu\n");
4790 ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4791 ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4792 ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4794 UpdateWindow( hwnd );
4795 flush_events();
4796 flush_sequence();
4797 ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4798 flush_events();
4799 ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4801 DestroyWindow(hwnd);
4802 flush_sequence();
4804 /* Message sequence for EnableWindow */
4805 hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4806 100, 100, 200, 200, 0, 0, 0, NULL);
4807 ok (hparent != 0, "Failed to create parent window\n");
4808 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4809 0, 0, 10, 10, hparent, 0, 0, NULL);
4810 ok (hchild != 0, "Failed to create child window\n");
4812 SetFocus(hchild);
4813 flush_events();
4814 flush_sequence();
4816 EnableWindow(hparent, FALSE);
4817 ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4819 EnableWindow(hparent, TRUE);
4820 ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4822 flush_events();
4823 flush_sequence();
4825 test_MsgWaitForMultipleObjects(hparent);
4827 /* the following test causes an exception in user.exe under win9x */
4828 if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4830 DestroyWindow(hparent);
4831 flush_sequence();
4832 return;
4834 PostMessageW( hparent, WM_USER+1, 0, 0 );
4835 /* PeekMessage(NULL) fails, but still removes the message */
4836 SetLastError(0xdeadbeef);
4837 ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4838 ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4839 GetLastError() == 0xdeadbeef, /* NT4 */
4840 "last error is %d\n", GetLastError() );
4841 ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4842 ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4844 DestroyWindow(hchild);
4845 DestroyWindow(hparent);
4846 flush_sequence();
4848 /* Message sequences for WM_SETICON */
4849 trace("testing WM_SETICON\n");
4850 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4851 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4852 NULL, NULL, 0);
4853 ShowWindow(hwnd, SW_SHOW);
4854 UpdateWindow(hwnd);
4855 flush_events();
4856 flush_sequence();
4857 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4858 ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4860 ShowWindow(hwnd, SW_HIDE);
4861 flush_events();
4862 flush_sequence();
4863 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4864 ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4865 DestroyWindow(hwnd);
4866 flush_sequence();
4868 hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4869 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4870 NULL, NULL, 0);
4871 ShowWindow(hwnd, SW_SHOW);
4872 UpdateWindow(hwnd);
4873 flush_events();
4874 flush_sequence();
4875 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4876 ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4878 ShowWindow(hwnd, SW_HIDE);
4879 flush_events();
4880 flush_sequence();
4881 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4882 ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4884 flush_sequence();
4885 res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4886 if (!res)
4888 todo_wine win_skip( "Message 0x3b not supported\n" );
4889 goto done;
4891 ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4892 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4893 res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4894 ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4895 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4896 res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4897 ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4898 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4900 flush_sequence();
4901 res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4902 ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4903 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4904 res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4905 ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4906 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4908 res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4909 ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4910 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4912 res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4913 ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4914 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4916 done:
4917 DestroyWindow(hwnd);
4918 flush_sequence();
4921 static void test_setwindowpos(void)
4923 HWND hwnd;
4924 RECT rc;
4925 LRESULT res;
4926 const INT winX = 100;
4927 const INT winY = 100;
4928 const INT sysX = GetSystemMetrics(SM_CXMINTRACK);
4930 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
4931 0, 0, winX, winY, 0,
4932 NULL, NULL, 0);
4934 GetWindowRect(hwnd, &rc);
4935 expect(sysX, rc.right);
4936 expect(winY, rc.bottom);
4938 flush_events();
4939 flush_sequence();
4940 res = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, winX, winY, 0);
4941 ok_sequence(WmZOrder, "Z-Order", TRUE);
4942 ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
4944 GetWindowRect(hwnd, &rc);
4945 expect(sysX, rc.right);
4946 expect(winY, rc.bottom);
4947 DestroyWindow(hwnd);
4950 static void invisible_parent_tests(void)
4952 HWND hparent, hchild;
4954 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4955 100, 100, 200, 200, 0, 0, 0, NULL);
4956 ok (hparent != 0, "Failed to create parent window\n");
4957 flush_sequence();
4959 /* test showing child with hidden parent */
4961 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4962 0, 0, 10, 10, hparent, 0, 0, NULL);
4963 ok (hchild != 0, "Failed to create child window\n");
4964 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4966 ShowWindow( hchild, SW_MINIMIZE );
4967 ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4968 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4969 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4971 /* repeat */
4972 flush_events();
4973 flush_sequence();
4974 ShowWindow( hchild, SW_MINIMIZE );
4975 ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4977 DestroyWindow(hchild);
4978 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4979 0, 0, 10, 10, hparent, 0, 0, NULL);
4980 flush_sequence();
4982 ShowWindow( hchild, SW_MAXIMIZE );
4983 ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4984 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4985 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4987 /* repeat */
4988 flush_events();
4989 flush_sequence();
4990 ShowWindow( hchild, SW_MAXIMIZE );
4991 ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4993 DestroyWindow(hchild);
4994 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4995 0, 0, 10, 10, hparent, 0, 0, NULL);
4996 flush_sequence();
4998 ShowWindow( hchild, SW_RESTORE );
4999 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
5000 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5001 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5003 DestroyWindow(hchild);
5004 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5005 0, 0, 10, 10, hparent, 0, 0, NULL);
5006 flush_sequence();
5008 ShowWindow( hchild, SW_SHOWMINIMIZED );
5009 ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
5010 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5011 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5013 /* repeat */
5014 flush_events();
5015 flush_sequence();
5016 ShowWindow( hchild, SW_SHOWMINIMIZED );
5017 ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
5019 DestroyWindow(hchild);
5020 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5021 0, 0, 10, 10, hparent, 0, 0, NULL);
5022 flush_sequence();
5024 /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
5025 ShowWindow( hchild, SW_SHOWMAXIMIZED );
5026 ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
5027 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5028 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5030 DestroyWindow(hchild);
5031 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5032 0, 0, 10, 10, hparent, 0, 0, NULL);
5033 flush_sequence();
5035 ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5036 ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5037 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5038 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5040 /* repeat */
5041 flush_events();
5042 flush_sequence();
5043 ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5044 ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5046 DestroyWindow(hchild);
5047 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5048 0, 0, 10, 10, hparent, 0, 0, NULL);
5049 flush_sequence();
5051 /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
5052 ShowWindow( hchild, SW_FORCEMINIMIZE );
5053 ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
5054 todo_wine {
5055 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5057 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5059 DestroyWindow(hchild);
5060 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5061 0, 0, 10, 10, hparent, 0, 0, NULL);
5062 flush_sequence();
5064 ShowWindow( hchild, SW_SHOWNA );
5065 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5066 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5067 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5069 /* repeat */
5070 flush_events();
5071 flush_sequence();
5072 ShowWindow( hchild, SW_SHOWNA );
5073 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5075 DestroyWindow(hchild);
5076 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5077 0, 0, 10, 10, hparent, 0, 0, NULL);
5078 flush_sequence();
5080 ShowWindow( hchild, SW_SHOW );
5081 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5082 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5083 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5085 /* repeat */
5086 flush_events();
5087 flush_sequence();
5088 ShowWindow( hchild, SW_SHOW );
5089 ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5091 ShowWindow( hchild, SW_HIDE );
5092 ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
5093 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5094 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5096 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5097 ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
5098 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5099 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5101 SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5102 ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
5103 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
5104 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5106 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5107 flush_sequence();
5108 DestroyWindow(hchild);
5109 ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
5111 DestroyWindow(hparent);
5112 flush_sequence();
5115 /****************** button message test *************************/
5116 #define ID_BUTTON 0x000e
5118 static const struct message WmSetFocusButtonSeq[] =
5120 { HCBT_SETFOCUS, hook },
5121 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5122 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5123 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5124 { WM_SETFOCUS, sent|wparam, 0 },
5125 { WM_CTLCOLORBTN, sent|parent },
5126 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5127 { WM_APP, sent|wparam|lparam, 0, 0 },
5128 { 0 }
5130 static const struct message WmKillFocusButtonSeq[] =
5132 { HCBT_SETFOCUS, hook },
5133 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5134 { WM_KILLFOCUS, sent|wparam, 0 },
5135 { WM_CTLCOLORBTN, sent|parent },
5136 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5137 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5138 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5139 { WM_APP, sent|wparam|lparam, 0, 0 },
5140 { WM_PAINT, sent },
5141 { WM_CTLCOLORBTN, sent|parent },
5142 { 0 }
5144 static const struct message WmSetFocusStaticSeq[] =
5146 { HCBT_SETFOCUS, hook },
5147 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5148 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5149 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5150 { WM_SETFOCUS, sent|wparam, 0 },
5151 { WM_CTLCOLORSTATIC, sent|parent },
5152 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5153 { WM_COMMAND, sent|wparam|parent|optional, MAKEWPARAM(ID_BUTTON, BN_CLICKED) }, /* radio button */
5154 { WM_APP, sent|wparam|lparam, 0, 0 },
5155 { 0 }
5157 static const struct message WmKillFocusStaticSeq[] =
5159 { HCBT_SETFOCUS, hook },
5160 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5161 { WM_KILLFOCUS, sent|wparam, 0 },
5162 { WM_CTLCOLORSTATIC, sent|parent },
5163 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5164 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5165 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5166 { WM_APP, sent|wparam|lparam, 0, 0 },
5167 { WM_PAINT, sent },
5168 { WM_CTLCOLORSTATIC, sent|parent },
5169 { 0 }
5171 static const struct message WmSetFocusOwnerdrawSeq[] =
5173 { HCBT_SETFOCUS, hook },
5174 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5175 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5176 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5177 { WM_SETFOCUS, sent|wparam, 0 },
5178 { WM_CTLCOLORBTN, sent|parent },
5179 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x001040e4 },
5180 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5181 { WM_APP, sent|wparam|lparam, 0, 0 },
5182 { 0 }
5184 static const struct message WmKillFocusOwnerdrawSeq[] =
5186 { HCBT_SETFOCUS, hook },
5187 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5188 { WM_KILLFOCUS, sent|wparam, 0 },
5189 { WM_CTLCOLORBTN, sent|parent },
5190 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000040e4 },
5191 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5192 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5193 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5194 { WM_APP, sent|wparam|lparam, 0, 0 },
5195 { WM_PAINT, sent },
5196 { WM_CTLCOLORBTN, sent|parent },
5197 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 },
5198 { 0 }
5200 static const struct message WmLButtonDownSeq[] =
5202 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
5203 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5204 { HCBT_SETFOCUS, hook },
5205 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
5206 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5207 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5208 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
5209 { WM_CTLCOLORBTN, sent|defwinproc },
5210 { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
5211 { WM_CTLCOLORBTN, sent|defwinproc },
5212 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5213 { 0 }
5215 static const struct message WmLButtonUpSeq[] =
5217 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
5218 { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
5219 { WM_CTLCOLORBTN, sent|defwinproc },
5220 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5221 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5222 { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
5223 { 0 }
5225 static const struct message WmSetFontButtonSeq[] =
5227 { WM_SETFONT, sent },
5228 { WM_PAINT, sent },
5229 { WM_ERASEBKGND, sent|defwinproc|optional },
5230 { WM_CTLCOLORBTN, sent|defwinproc },
5231 { 0 }
5233 static const struct message WmSetStyleButtonSeq[] =
5235 { BM_SETSTYLE, sent },
5236 { WM_APP, sent|wparam|lparam, 0, 0 },
5237 { WM_PAINT, sent },
5238 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5239 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5240 { WM_CTLCOLORBTN, sent|parent },
5241 { 0 }
5243 static const struct message WmSetStyleStaticSeq[] =
5245 { BM_SETSTYLE, sent },
5246 { WM_APP, sent|wparam|lparam, 0, 0 },
5247 { WM_PAINT, sent },
5248 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5249 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5250 { WM_CTLCOLORSTATIC, sent|parent },
5251 { 0 }
5253 static const struct message WmSetStyleUserSeq[] =
5255 { BM_SETSTYLE, sent },
5256 { WM_APP, sent|wparam|lparam, 0, 0 },
5257 { WM_PAINT, sent },
5258 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5259 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5260 { WM_CTLCOLORBTN, sent|parent },
5261 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_PAINT) },
5262 { 0 }
5264 static const struct message WmSetStyleOwnerdrawSeq[] =
5266 { BM_SETSTYLE, sent },
5267 { WM_APP, sent|wparam|lparam, 0, 0 },
5268 { WM_PAINT, sent },
5269 { WM_NCPAINT, sent|optional }, /* FIXME: Wine sends it */
5270 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5271 { WM_CTLCOLORBTN, sent|parent },
5272 { WM_CTLCOLORBTN, sent|parent|optional }, /* Win9x doesn't send it */
5273 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 },
5274 { 0 }
5276 static const struct message WmSetStateButtonSeq[] =
5278 { BM_SETSTATE, sent },
5279 { WM_CTLCOLORBTN, sent|parent },
5280 { WM_APP, sent|wparam|lparam, 0, 0 },
5281 { 0 }
5283 static const struct message WmSetStateStaticSeq[] =
5285 { BM_SETSTATE, sent },
5286 { WM_CTLCOLORSTATIC, sent|parent },
5287 { WM_APP, sent|wparam|lparam, 0, 0 },
5288 { 0 }
5290 static const struct message WmSetStateUserSeq[] =
5292 { BM_SETSTATE, sent },
5293 { WM_CTLCOLORBTN, sent|parent },
5294 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_HILITE) },
5295 { WM_APP, sent|wparam|lparam, 0, 0 },
5296 { 0 }
5298 static const struct message WmSetStateOwnerdrawSeq[] =
5300 { BM_SETSTATE, sent },
5301 { WM_CTLCOLORBTN, sent|parent },
5302 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000120e4 },
5303 { WM_APP, sent|wparam|lparam, 0, 0 },
5304 { 0 }
5306 static const struct message WmClearStateButtonSeq[] =
5308 { BM_SETSTATE, sent },
5309 { WM_CTLCOLORBTN, sent|parent },
5310 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_UNHILITE) },
5311 { WM_APP, sent|wparam|lparam, 0, 0 },
5312 { 0 }
5314 static const struct message WmClearStateOwnerdrawSeq[] =
5316 { BM_SETSTATE, sent },
5317 { WM_CTLCOLORBTN, sent|parent },
5318 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000020e4 },
5319 { WM_APP, sent|wparam|lparam, 0, 0 },
5320 { 0 }
5322 static const struct message WmSetCheckIgnoredSeq[] =
5324 { BM_SETCHECK, sent },
5325 { WM_APP, sent|wparam|lparam, 0, 0 },
5326 { 0 }
5328 static const struct message WmSetCheckStaticSeq[] =
5330 { BM_SETCHECK, sent },
5331 { WM_CTLCOLORSTATIC, sent|parent },
5332 { WM_APP, sent|wparam|lparam, 0, 0 },
5333 { 0 }
5336 static WNDPROC old_button_proc;
5338 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5340 static LONG defwndproc_counter = 0;
5341 LRESULT ret;
5342 struct recvd_message msg;
5344 if (ignore_message( message )) return 0;
5346 switch (message)
5348 case WM_SYNCPAINT:
5349 break;
5350 case BM_SETSTATE:
5351 if (GetCapture())
5352 ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
5353 /* fall through */
5354 default:
5355 msg.hwnd = hwnd;
5356 msg.message = message;
5357 msg.flags = sent|wparam|lparam;
5358 if (defwndproc_counter) msg.flags |= defwinproc;
5359 msg.wParam = wParam;
5360 msg.lParam = lParam;
5361 msg.descr = "button";
5362 add_message(&msg);
5365 defwndproc_counter++;
5366 ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
5367 defwndproc_counter--;
5369 return ret;
5372 static void subclass_button(void)
5374 WNDCLASSA cls;
5376 if (!GetClassInfoA(0, "button", &cls)) assert(0);
5378 old_button_proc = cls.lpfnWndProc;
5380 cls.hInstance = GetModuleHandle(0);
5381 cls.lpfnWndProc = button_hook_proc;
5382 cls.lpszClassName = "my_button_class";
5383 UnregisterClass(cls.lpszClassName, cls.hInstance);
5384 if (!RegisterClassA(&cls)) assert(0);
5387 static void test_button_messages(void)
5389 static const struct
5391 DWORD style;
5392 DWORD dlg_code;
5393 const struct message *setfocus;
5394 const struct message *killfocus;
5395 const struct message *setstyle;
5396 const struct message *setstate;
5397 const struct message *clearstate;
5398 const struct message *setcheck;
5399 } button[] = {
5400 { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5401 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq,
5402 WmSetStateButtonSeq, WmSetStateButtonSeq, WmSetCheckIgnoredSeq },
5403 { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
5404 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq,
5405 WmSetStateButtonSeq, WmSetStateButtonSeq, WmSetCheckIgnoredSeq },
5406 { BS_CHECKBOX, DLGC_BUTTON,
5407 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5408 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5409 { BS_AUTOCHECKBOX, DLGC_BUTTON,
5410 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5411 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5412 { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5413 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5414 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5415 { BS_3STATE, DLGC_BUTTON,
5416 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5417 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5418 { BS_AUTO3STATE, DLGC_BUTTON,
5419 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5420 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5421 { BS_GROUPBOX, DLGC_STATIC,
5422 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5423 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckIgnoredSeq },
5424 { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5425 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleUserSeq,
5426 WmSetStateUserSeq, WmClearStateButtonSeq, WmSetCheckIgnoredSeq },
5427 { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5428 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5429 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5430 { BS_OWNERDRAW, DLGC_BUTTON,
5431 WmSetFocusOwnerdrawSeq, WmKillFocusOwnerdrawSeq, WmSetStyleOwnerdrawSeq,
5432 WmSetStateOwnerdrawSeq, WmClearStateOwnerdrawSeq, WmSetCheckIgnoredSeq },
5434 unsigned int i;
5435 HWND hwnd, parent;
5436 DWORD dlg_code;
5437 HFONT zfont;
5439 /* selection with VK_SPACE should capture button window */
5440 hwnd = CreateWindowExA(0, "button", "test", BS_CHECKBOX | WS_VISIBLE | WS_POPUP,
5441 0, 0, 50, 14, 0, 0, 0, NULL);
5442 ok(hwnd != 0, "Failed to create button window\n");
5443 ReleaseCapture();
5444 SetFocus(hwnd);
5445 SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
5446 ok(GetCapture() == hwnd, "Should be captured on VK_SPACE WM_KEYDOWN\n");
5447 SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
5448 DestroyWindow(hwnd);
5450 subclass_button();
5452 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5453 100, 100, 200, 200, 0, 0, 0, NULL);
5454 ok(parent != 0, "Failed to create parent window\n");
5456 for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
5458 MSG msg;
5459 DWORD style, state;
5461 trace("button style %08x\n", button[i].style);
5463 hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_CHILD | BS_NOTIFY,
5464 0, 0, 50, 14, parent, (HMENU)ID_BUTTON, 0, NULL);
5465 ok(hwnd != 0, "Failed to create button window\n");
5467 style = GetWindowLongA(hwnd, GWL_STYLE);
5468 style &= ~(WS_CHILD | BS_NOTIFY);
5469 /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
5470 if (button[i].style == BS_USERBUTTON)
5471 ok(style == BS_PUSHBUTTON, "expected style BS_PUSHBUTTON got %x\n", style);
5472 else
5473 ok(style == button[i].style, "expected style %x got %x\n", button[i].style, style);
5475 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5476 ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5478 ShowWindow(hwnd, SW_SHOW);
5479 UpdateWindow(hwnd);
5480 SetFocus(0);
5481 flush_events();
5482 SetFocus(0);
5483 flush_sequence();
5485 log_all_parent_messages++;
5487 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
5488 SetFocus(hwnd);
5489 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5490 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5491 ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
5493 SetFocus(0);
5494 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5495 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5496 ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
5498 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
5500 SendMessage(hwnd, BM_SETSTYLE, button[i].style | BS_BOTTOM, TRUE);
5501 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5502 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5503 ok_sequence(button[i].setstyle, "BM_SETSTYLE on a button", FALSE);
5505 style = GetWindowLongA(hwnd, GWL_STYLE);
5506 style &= ~(WS_VISIBLE | WS_CHILD | BS_NOTIFY);
5507 /* XP doesn't turn a BS_USERBUTTON into BS_PUSHBUTTON here! */
5508 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5510 state = SendMessage(hwnd, BM_GETSTATE, 0, 0);
5511 ok(state == 0, "expected state 0, got %04x\n", state);
5513 flush_sequence();
5515 SendMessage(hwnd, BM_SETSTATE, TRUE, 0);
5516 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5517 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5518 ok_sequence(button[i].setstate, "BM_SETSTATE/TRUE on a button", FALSE);
5520 state = SendMessage(hwnd, BM_GETSTATE, 0, 0);
5521 ok(state == 0x0004, "expected state 0x0004, got %04x\n", state);
5523 style = GetWindowLongA(hwnd, GWL_STYLE);
5524 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5525 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5527 flush_sequence();
5529 SendMessage(hwnd, BM_SETSTATE, FALSE, 0);
5530 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5531 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5532 ok_sequence(button[i].clearstate, "BM_SETSTATE/FALSE on a button", FALSE);
5534 state = SendMessage(hwnd, BM_GETSTATE, 0, 0);
5535 ok(state == 0, "expected state 0, got %04x\n", state);
5537 style = GetWindowLongA(hwnd, GWL_STYLE);
5538 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5539 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5541 state = SendMessage(hwnd, BM_GETCHECK, 0, 0);
5542 ok(state == BST_UNCHECKED, "expected BST_UNCHECKED, got %04x\n", state);
5544 flush_sequence();
5546 SendMessage(hwnd, BM_SETCHECK, BST_UNCHECKED, 0);
5547 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5548 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5549 ok_sequence(WmSetCheckIgnoredSeq, "BM_SETCHECK on a button", FALSE);
5551 state = SendMessage(hwnd, BM_GETCHECK, 0, 0);
5552 ok(state == BST_UNCHECKED, "expected BST_UNCHECKED, got %04x\n", state);
5554 style = GetWindowLongA(hwnd, GWL_STYLE);
5555 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5556 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5558 flush_sequence();
5560 SendMessage(hwnd, BM_SETCHECK, BST_CHECKED, 0);
5561 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5562 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5563 ok_sequence(button[i].setcheck, "BM_SETCHECK on a button", FALSE);
5565 state = SendMessage(hwnd, BM_GETCHECK, 0, 0);
5566 if (button[i].style == BS_PUSHBUTTON ||
5567 button[i].style == BS_DEFPUSHBUTTON ||
5568 button[i].style == BS_GROUPBOX ||
5569 button[i].style == BS_USERBUTTON ||
5570 button[i].style == BS_OWNERDRAW)
5571 ok(state == BST_UNCHECKED, "expected check 0, got %04x\n", state);
5572 else
5573 ok(state == BST_CHECKED, "expected check 1, got %04x\n", state);
5575 style = GetWindowLongA(hwnd, GWL_STYLE);
5576 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5577 if (button[i].style == BS_RADIOBUTTON ||
5578 button[i].style == BS_AUTORADIOBUTTON)
5579 ok(style == (button[i].style | WS_TABSTOP), "expected style %04x | WS_TABSTOP got %04x\n", button[i].style, style);
5580 else
5581 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5583 log_all_parent_messages--;
5585 DestroyWindow(hwnd);
5588 DestroyWindow(parent);
5590 hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
5591 0, 0, 50, 14, 0, 0, 0, NULL);
5592 ok(hwnd != 0, "Failed to create button window\n");
5594 SetForegroundWindow(hwnd);
5595 flush_events();
5597 SetActiveWindow(hwnd);
5598 SetFocus(0);
5599 flush_sequence();
5601 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
5602 ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
5604 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
5605 ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
5607 flush_sequence();
5608 zfont = GetStockObject(SYSTEM_FONT);
5609 SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
5610 UpdateWindow(hwnd);
5611 ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
5613 DestroyWindow(hwnd);
5616 /****************** static message test *************************/
5617 static const struct message WmSetFontStaticSeq[] =
5619 { WM_SETFONT, sent },
5620 { WM_PAINT, sent|defwinproc|optional },
5621 { WM_ERASEBKGND, sent|defwinproc|optional },
5622 { WM_CTLCOLORSTATIC, sent|defwinproc|optional },
5623 { 0 }
5626 static WNDPROC old_static_proc;
5628 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5630 static LONG defwndproc_counter = 0;
5631 LRESULT ret;
5632 struct recvd_message msg;
5634 if (ignore_message( message )) return 0;
5636 msg.hwnd = hwnd;
5637 msg.message = message;
5638 msg.flags = sent|wparam|lparam;
5639 if (defwndproc_counter) msg.flags |= defwinproc;
5640 msg.wParam = wParam;
5641 msg.lParam = lParam;
5642 msg.descr = "static";
5643 add_message(&msg);
5645 defwndproc_counter++;
5646 ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
5647 defwndproc_counter--;
5649 return ret;
5652 static void subclass_static(void)
5654 WNDCLASSA cls;
5656 if (!GetClassInfoA(0, "static", &cls)) assert(0);
5658 old_static_proc = cls.lpfnWndProc;
5660 cls.hInstance = GetModuleHandle(0);
5661 cls.lpfnWndProc = static_hook_proc;
5662 cls.lpszClassName = "my_static_class";
5663 UnregisterClass(cls.lpszClassName, cls.hInstance);
5664 if (!RegisterClassA(&cls)) assert(0);
5667 static void test_static_messages(void)
5669 /* FIXME: make as comprehensive as the button message test */
5670 static const struct
5672 DWORD style;
5673 DWORD dlg_code;
5674 const struct message *setfont;
5675 } static_ctrl[] = {
5676 { SS_LEFT, DLGC_STATIC,
5677 WmSetFontStaticSeq }
5679 unsigned int i;
5680 HWND hwnd;
5681 DWORD dlg_code;
5683 subclass_static();
5685 for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
5687 hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
5688 0, 0, 50, 14, 0, 0, 0, NULL);
5689 ok(hwnd != 0, "Failed to create static window\n");
5691 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5692 ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5694 ShowWindow(hwnd, SW_SHOW);
5695 UpdateWindow(hwnd);
5696 SetFocus(0);
5697 flush_sequence();
5699 trace("static style %08x\n", static_ctrl[i].style);
5700 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
5701 ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
5703 DestroyWindow(hwnd);
5707 /****************** ComboBox message test *************************/
5708 #define ID_COMBOBOX 0x000f
5710 static const struct message WmKeyDownComboSeq[] =
5712 { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
5713 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
5714 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
5715 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
5716 { WM_CTLCOLOREDIT, sent|parent },
5717 { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
5718 { 0 }
5721 static WNDPROC old_combobox_proc;
5723 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5725 static LONG defwndproc_counter = 0;
5726 LRESULT ret;
5727 struct recvd_message msg;
5729 /* do not log painting messages */
5730 if (message != WM_PAINT &&
5731 message != WM_NCPAINT &&
5732 message != WM_SYNCPAINT &&
5733 message != WM_ERASEBKGND &&
5734 message != WM_NCHITTEST &&
5735 message != WM_GETTEXT &&
5736 !ignore_message( message ))
5738 msg.hwnd = hwnd;
5739 msg.message = message;
5740 msg.flags = sent|wparam|lparam;
5741 if (defwndproc_counter) msg.flags |= defwinproc;
5742 msg.wParam = wParam;
5743 msg.lParam = lParam;
5744 msg.descr = "combo";
5745 add_message(&msg);
5748 defwndproc_counter++;
5749 ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5750 defwndproc_counter--;
5752 return ret;
5755 static void subclass_combobox(void)
5757 WNDCLASSA cls;
5759 if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5761 old_combobox_proc = cls.lpfnWndProc;
5763 cls.hInstance = GetModuleHandle(0);
5764 cls.lpfnWndProc = combobox_hook_proc;
5765 cls.lpszClassName = "my_combobox_class";
5766 UnregisterClass(cls.lpszClassName, cls.hInstance);
5767 if (!RegisterClassA(&cls)) assert(0);
5770 static void test_combobox_messages(void)
5772 HWND parent, combo;
5773 LRESULT ret;
5775 subclass_combobox();
5777 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5778 100, 100, 200, 200, 0, 0, 0, NULL);
5779 ok(parent != 0, "Failed to create parent window\n");
5780 flush_sequence();
5782 combo = CreateWindowEx(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5783 0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5784 ok(combo != 0, "Failed to create combobox window\n");
5786 UpdateWindow(combo);
5788 ret = SendMessage(combo, WM_GETDLGCODE, 0, 0);
5789 ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5791 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5792 ok(ret == 0, "expected 0, got %ld\n", ret);
5793 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5794 ok(ret == 1, "expected 1, got %ld\n", ret);
5795 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5796 ok(ret == 2, "expected 2, got %ld\n", ret);
5798 SendMessage(combo, CB_SETCURSEL, 0, 0);
5799 SetFocus(combo);
5800 flush_sequence();
5802 log_all_parent_messages++;
5803 SendMessage(combo, WM_KEYDOWN, VK_DOWN, 0);
5804 SendMessage(combo, WM_KEYUP, VK_DOWN, 0);
5805 log_all_parent_messages--;
5806 ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5808 DestroyWindow(combo);
5809 DestroyWindow(parent);
5812 /****************** WM_IME_KEYDOWN message test *******************/
5814 static const struct message WmImeKeydownMsgSeq_0[] =
5816 { WM_IME_KEYDOWN, wparam, VK_RETURN },
5817 { WM_CHAR, wparam, 'A' },
5818 { 0 }
5821 static const struct message WmImeKeydownMsgSeq_1[] =
5823 { WM_KEYDOWN, optional|wparam, VK_RETURN },
5824 { WM_CHAR, optional|wparam, VK_RETURN },
5825 { 0 }
5828 static LRESULT WINAPI wmime_keydown_procA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5830 struct recvd_message msg;
5832 msg.hwnd = hwnd;
5833 msg.message = message;
5834 msg.flags = wparam|lparam;
5835 msg.wParam = wParam;
5836 msg.lParam = lParam;
5837 msg.descr = "wmime_keydown";
5838 add_message(&msg);
5840 return DefWindowProcA(hwnd, message, wParam, lParam);
5843 static void register_wmime_keydown_class(void)
5845 WNDCLASSA cls;
5847 ZeroMemory(&cls, sizeof(WNDCLASSA));
5848 cls.lpfnWndProc = wmime_keydown_procA;
5849 cls.hInstance = GetModuleHandleA(0);
5850 cls.lpszClassName = "wmime_keydown_class";
5851 if (!RegisterClassA(&cls)) assert(0);
5854 static void test_wmime_keydown_message(void)
5856 HWND hwnd;
5857 MSG msg;
5859 trace("Message sequences by WM_IME_KEYDOWN\n");
5861 register_wmime_keydown_class();
5862 hwnd = CreateWindowExA(0, "wmime_keydown_class", NULL, WS_OVERLAPPEDWINDOW,
5863 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5864 NULL, NULL, 0);
5865 flush_events();
5866 flush_sequence();
5868 SendMessage(hwnd, WM_IME_KEYDOWN, VK_RETURN, 0x1c0001);
5869 SendMessage(hwnd, WM_CHAR, 'A', 1);
5870 ok_sequence(WmImeKeydownMsgSeq_0, "WM_IME_KEYDOWN 0", FALSE);
5872 while ( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
5874 TranslateMessage(&msg);
5875 DispatchMessage(&msg);
5877 ok_sequence(WmImeKeydownMsgSeq_1, "WM_IME_KEYDOWN 1", FALSE);
5879 DestroyWindow(hwnd);
5882 /************* painting message test ********************/
5884 void dump_region(HRGN hrgn)
5886 DWORD i, size;
5887 RGNDATA *data = NULL;
5888 RECT *rect;
5890 if (!hrgn)
5892 printf( "null region\n" );
5893 return;
5895 if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5896 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5897 GetRegionData( hrgn, size, data );
5898 printf("%d rects:", data->rdh.nCount );
5899 for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5900 printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
5901 printf("\n");
5902 HeapFree( GetProcessHeap(), 0, data );
5905 static void check_update_rgn( HWND hwnd, HRGN hrgn )
5907 INT ret;
5908 RECT r1, r2;
5909 HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
5910 HRGN update = CreateRectRgn( 0, 0, 0, 0 );
5912 ret = GetUpdateRgn( hwnd, update, FALSE );
5913 ok( ret != ERROR, "GetUpdateRgn failed\n" );
5914 if (ret == NULLREGION)
5916 ok( !hrgn, "Update region shouldn't be empty\n" );
5918 else
5920 if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
5922 ok( 0, "Regions are different\n" );
5923 if (winetest_debug > 0)
5925 printf( "Update region: " );
5926 dump_region( update );
5927 printf( "Wanted region: " );
5928 dump_region( hrgn );
5932 GetRgnBox( update, &r1 );
5933 GetUpdateRect( hwnd, &r2, FALSE );
5934 ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
5935 "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
5936 r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
5938 DeleteObject( tmp );
5939 DeleteObject( update );
5942 static const struct message WmInvalidateRgn[] = {
5943 { WM_NCPAINT, sent },
5944 { WM_GETTEXT, sent|defwinproc|optional },
5945 { 0 }
5948 static const struct message WmGetUpdateRect[] = {
5949 { WM_NCPAINT, sent },
5950 { WM_GETTEXT, sent|defwinproc|optional },
5951 { WM_PAINT, sent },
5952 { 0 }
5955 static const struct message WmInvalidateFull[] = {
5956 { WM_NCPAINT, sent|wparam, 1 },
5957 { WM_GETTEXT, sent|defwinproc|optional },
5958 { 0 }
5961 static const struct message WmInvalidateErase[] = {
5962 { WM_NCPAINT, sent|wparam, 1 },
5963 { WM_GETTEXT, sent|defwinproc|optional },
5964 { WM_ERASEBKGND, sent },
5965 { 0 }
5968 static const struct message WmInvalidatePaint[] = {
5969 { WM_PAINT, sent },
5970 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5971 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5972 { 0 }
5975 static const struct message WmInvalidateErasePaint[] = {
5976 { WM_PAINT, sent },
5977 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5978 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5979 { WM_ERASEBKGND, sent|beginpaint|optional },
5980 { 0 }
5983 static const struct message WmInvalidateErasePaint2[] = {
5984 { WM_PAINT, sent },
5985 { WM_NCPAINT, sent|beginpaint },
5986 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5987 { WM_ERASEBKGND, sent|beginpaint|optional },
5988 { 0 }
5991 static const struct message WmErase[] = {
5992 { WM_ERASEBKGND, sent },
5993 { 0 }
5996 static const struct message WmPaint[] = {
5997 { WM_PAINT, sent },
5998 { 0 }
6001 static const struct message WmParentOnlyPaint[] = {
6002 { WM_PAINT, sent|parent },
6003 { 0 }
6006 static const struct message WmInvalidateParent[] = {
6007 { WM_NCPAINT, sent|parent },
6008 { WM_GETTEXT, sent|defwinproc|parent|optional },
6009 { WM_ERASEBKGND, sent|parent },
6010 { 0 }
6013 static const struct message WmInvalidateParentChild[] = {
6014 { WM_NCPAINT, sent|parent },
6015 { WM_GETTEXT, sent|defwinproc|parent|optional },
6016 { WM_ERASEBKGND, sent|parent },
6017 { WM_NCPAINT, sent },
6018 { WM_GETTEXT, sent|defwinproc|optional },
6019 { WM_ERASEBKGND, sent },
6020 { 0 }
6023 static const struct message WmInvalidateParentChild2[] = {
6024 { WM_ERASEBKGND, sent|parent },
6025 { WM_NCPAINT, sent },
6026 { WM_GETTEXT, sent|defwinproc|optional },
6027 { WM_ERASEBKGND, sent },
6028 { 0 }
6031 static const struct message WmParentPaint[] = {
6032 { WM_PAINT, sent|parent },
6033 { WM_PAINT, sent },
6034 { 0 }
6037 static const struct message WmParentPaintNc[] = {
6038 { WM_PAINT, sent|parent },
6039 { WM_PAINT, sent },
6040 { WM_NCPAINT, sent|beginpaint },
6041 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6042 { WM_ERASEBKGND, sent|beginpaint|optional },
6043 { 0 }
6046 static const struct message WmChildPaintNc[] = {
6047 { WM_PAINT, sent },
6048 { WM_NCPAINT, sent|beginpaint },
6049 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6050 { WM_ERASEBKGND, sent|beginpaint|optional },
6051 { 0 }
6054 static const struct message WmParentErasePaint[] = {
6055 { WM_PAINT, sent|parent },
6056 { WM_NCPAINT, sent|parent|beginpaint },
6057 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
6058 { WM_ERASEBKGND, sent|parent|beginpaint|optional },
6059 { WM_PAINT, sent },
6060 { WM_NCPAINT, sent|beginpaint },
6061 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6062 { WM_ERASEBKGND, sent|beginpaint|optional },
6063 { 0 }
6066 static const struct message WmParentOnlyNcPaint[] = {
6067 { WM_PAINT, sent|parent },
6068 { WM_NCPAINT, sent|parent|beginpaint },
6069 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
6070 { 0 }
6073 static const struct message WmSetParentStyle[] = {
6074 { WM_STYLECHANGING, sent|parent },
6075 { WM_STYLECHANGED, sent|parent },
6076 { 0 }
6079 static void test_paint_messages(void)
6081 BOOL ret;
6082 RECT rect;
6083 POINT pt;
6084 MSG msg;
6085 HWND hparent, hchild;
6086 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
6087 HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
6088 HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
6089 100, 100, 200, 200, 0, 0, 0, NULL);
6090 ok (hwnd != 0, "Failed to create overlapped window\n");
6092 ShowWindow( hwnd, SW_SHOW );
6093 UpdateWindow( hwnd );
6094 flush_events();
6095 flush_sequence();
6097 check_update_rgn( hwnd, 0 );
6098 SetRectRgn( hrgn, 10, 10, 20, 20 );
6099 ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6100 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6101 check_update_rgn( hwnd, hrgn );
6102 SetRectRgn( hrgn2, 20, 20, 30, 30 );
6103 ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
6104 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6105 CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
6106 check_update_rgn( hwnd, hrgn );
6107 /* validate everything */
6108 ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6109 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6110 check_update_rgn( hwnd, 0 );
6112 /* test empty region */
6113 SetRectRgn( hrgn, 10, 10, 10, 15 );
6114 ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6115 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6116 check_update_rgn( hwnd, 0 );
6117 /* test empty rect */
6118 SetRect( &rect, 10, 10, 10, 15 );
6119 ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
6120 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6121 check_update_rgn( hwnd, 0 );
6123 /* flush pending messages */
6124 flush_events();
6125 flush_sequence();
6127 GetClientRect( hwnd, &rect );
6128 SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
6129 /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
6130 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
6132 trace("testing InvalidateRect(0, NULL, FALSE)\n");
6133 SetRectEmpty( &rect );
6134 ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
6135 check_update_rgn( hwnd, hrgn );
6136 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6137 flush_events();
6138 ok_sequence( WmPaint, "Paint", FALSE );
6139 RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6140 check_update_rgn( hwnd, 0 );
6142 /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
6143 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
6145 trace("testing ValidateRect(0, NULL)\n");
6146 SetRectEmpty( &rect );
6147 if (ValidateRect(0, &rect)) /* not supported on Win9x */
6149 check_update_rgn( hwnd, hrgn );
6150 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6151 flush_events();
6152 ok_sequence( WmPaint, "Paint", FALSE );
6153 RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6154 check_update_rgn( hwnd, 0 );
6157 trace("testing InvalidateRgn(0, NULL, FALSE)\n");
6158 SetLastError(0xdeadbeef);
6159 ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
6160 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
6161 "wrong error code %d\n", GetLastError());
6162 check_update_rgn( hwnd, 0 );
6163 flush_events();
6164 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6166 trace("testing ValidateRgn(0, NULL)\n");
6167 SetLastError(0xdeadbeef);
6168 ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
6169 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
6170 broken( GetLastError() == 0xdeadbeef ) /* win9x */,
6171 "wrong error code %d\n", GetLastError());
6172 check_update_rgn( hwnd, 0 );
6173 flush_events();
6174 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6176 trace("testing UpdateWindow(NULL)\n");
6177 SetLastError(0xdeadbeef);
6178 ok(!UpdateWindow(NULL), "UpdateWindow(NULL) should fail\n");
6179 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
6180 broken( GetLastError() == 0xdeadbeef ) /* win9x */,
6181 "wrong error code %d\n", GetLastError());
6182 check_update_rgn( hwnd, 0 );
6183 flush_events();
6184 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6186 /* now with frame */
6187 SetRectRgn( hrgn, -5, -5, 20, 20 );
6189 /* flush pending messages */
6190 flush_events();
6191 flush_sequence();
6192 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6193 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
6195 SetRectRgn( hrgn, 0, 0, 20, 20 ); /* GetUpdateRgn clips to client area */
6196 check_update_rgn( hwnd, hrgn );
6198 flush_sequence();
6199 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
6200 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
6202 flush_sequence();
6203 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
6204 ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
6206 GetClientRect( hwnd, &rect );
6207 SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
6208 check_update_rgn( hwnd, hrgn );
6210 flush_sequence();
6211 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
6212 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6214 flush_sequence();
6215 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
6216 ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
6217 check_update_rgn( hwnd, 0 );
6219 flush_sequence();
6220 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
6221 ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
6222 check_update_rgn( hwnd, 0 );
6224 flush_sequence();
6225 SetRectRgn( hrgn, 0, 0, 100, 100 );
6226 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6227 SetRectRgn( hrgn, 0, 0, 50, 100 );
6228 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
6229 SetRectRgn( hrgn, 50, 0, 100, 100 );
6230 check_update_rgn( hwnd, hrgn );
6231 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
6232 ok_sequence( WmEmptySeq, "EmptySeq", FALSE ); /* must not generate messages, everything is valid */
6233 check_update_rgn( hwnd, 0 );
6235 flush_sequence();
6236 SetRectRgn( hrgn, 0, 0, 100, 100 );
6237 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
6238 SetRectRgn( hrgn, 0, 0, 100, 50 );
6239 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
6240 ok_sequence( WmErase, "Erase", FALSE );
6241 SetRectRgn( hrgn, 0, 50, 100, 100 );
6242 check_update_rgn( hwnd, hrgn );
6244 flush_sequence();
6245 SetRectRgn( hrgn, 0, 0, 100, 100 );
6246 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
6247 SetRectRgn( hrgn, 0, 0, 50, 50 );
6248 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
6249 ok_sequence( WmPaint, "Paint", FALSE );
6251 flush_sequence();
6252 SetRectRgn( hrgn, -4, -4, -2, -2 );
6253 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6254 SetRectRgn( hrgn, -200, -200, -198, -198 );
6255 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
6256 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
6258 flush_sequence();
6259 SetRectRgn( hrgn, -4, -4, -2, -2 );
6260 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6261 SetRectRgn( hrgn, -4, -4, -3, -3 );
6262 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
6263 SetRectRgn( hrgn, 0, 0, 1, 1 );
6264 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
6265 ok_sequence( WmPaint, "Paint", FALSE );
6267 flush_sequence();
6268 SetRectRgn( hrgn, -4, -4, -1, -1 );
6269 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6270 RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
6271 /* make sure no WM_PAINT was generated */
6272 flush_events();
6273 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
6275 flush_sequence();
6276 SetRectRgn( hrgn, -4, -4, -1, -1 );
6277 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6278 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
6280 if (msg.hwnd == hwnd && msg.message == WM_PAINT)
6282 /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
6283 INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
6284 ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
6285 ret = GetUpdateRect( hwnd, &rect, FALSE );
6286 ok( ret, "Invalid GetUpdateRect result %d\n", ret );
6287 /* this will send WM_NCPAINT and validate the non client area */
6288 ret = GetUpdateRect( hwnd, &rect, TRUE );
6289 ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
6291 DispatchMessage( &msg );
6293 ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
6295 DestroyWindow( hwnd );
6297 /* now test with a child window */
6299 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
6300 100, 100, 200, 200, 0, 0, 0, NULL);
6301 ok (hparent != 0, "Failed to create parent window\n");
6303 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
6304 10, 10, 100, 100, hparent, 0, 0, NULL);
6305 ok (hchild != 0, "Failed to create child window\n");
6307 ShowWindow( hparent, SW_SHOW );
6308 UpdateWindow( hparent );
6309 UpdateWindow( hchild );
6310 flush_events();
6311 flush_sequence();
6312 log_all_parent_messages++;
6314 SetRect( &rect, 0, 0, 50, 50 );
6315 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6316 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6317 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
6319 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6320 pt.x = pt.y = 0;
6321 MapWindowPoints( hchild, hparent, &pt, 1 );
6322 SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
6323 check_update_rgn( hchild, hrgn );
6324 SetRectRgn( hrgn, 0, 0, 50, 50 );
6325 check_update_rgn( hparent, hrgn );
6326 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6327 ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
6328 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6329 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6331 flush_events();
6332 ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
6334 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6335 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6336 ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
6337 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6338 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6340 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6341 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6342 ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
6344 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6345 flush_sequence();
6346 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6347 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6348 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
6350 /* flush all paint messages */
6351 flush_events();
6352 flush_sequence();
6354 /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
6355 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6356 SetRectRgn( hrgn, 0, 0, 50, 50 );
6357 check_update_rgn( hparent, hrgn );
6358 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6359 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6360 SetRectRgn( hrgn, 0, 0, 50, 50 );
6361 check_update_rgn( hparent, hrgn );
6363 /* flush all paint messages */
6364 flush_events();
6365 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6366 flush_sequence();
6368 /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
6369 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6370 SetRectRgn( hrgn, 0, 0, 50, 50 );
6371 check_update_rgn( hparent, hrgn );
6372 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6373 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6374 SetRectRgn( hrgn2, 10, 10, 50, 50 );
6375 CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
6376 check_update_rgn( hparent, hrgn );
6377 /* flush all paint messages */
6378 flush_events();
6379 flush_sequence();
6381 /* same as above but parent gets completely validated */
6382 SetRect( &rect, 20, 20, 30, 30 );
6383 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6384 SetRectRgn( hrgn, 20, 20, 30, 30 );
6385 check_update_rgn( hparent, hrgn );
6386 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6387 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6388 check_update_rgn( hparent, 0 ); /* no update region */
6389 flush_events();
6390 ok_sequence( WmEmptySeq, "WmEmpty", FALSE ); /* and no paint messages */
6392 /* make sure RDW_VALIDATE on child doesn't have the same effect */
6393 flush_sequence();
6394 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6395 SetRectRgn( hrgn, 20, 20, 30, 30 );
6396 check_update_rgn( hparent, hrgn );
6397 RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
6398 SetRectRgn( hrgn, 20, 20, 30, 30 );
6399 check_update_rgn( hparent, hrgn );
6401 /* same as above but normal WM_PAINT doesn't validate parent */
6402 flush_sequence();
6403 SetRect( &rect, 20, 20, 30, 30 );
6404 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6405 SetRectRgn( hrgn, 20, 20, 30, 30 );
6406 check_update_rgn( hparent, hrgn );
6407 /* no WM_PAINT in child while parent still pending */
6408 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6409 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6410 while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6411 ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
6413 flush_sequence();
6414 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6415 /* no WM_PAINT in child while parent still pending */
6416 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6417 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6418 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
6419 /* now that parent is valid child should get WM_PAINT */
6420 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6421 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6422 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6423 ok_sequence( WmEmptySeq, "No other message", FALSE );
6425 /* same thing with WS_CLIPCHILDREN in parent */
6426 flush_sequence();
6427 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6428 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6429 /* changing style invalidates non client area, but we need to invalidate something else to see it */
6430 RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
6431 ok_sequence( WmEmptySeq, "No message", FALSE );
6432 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
6433 ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
6435 flush_sequence();
6436 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
6437 SetRectRgn( hrgn, 20, 20, 30, 30 );
6438 check_update_rgn( hparent, hrgn );
6439 /* no WM_PAINT in child while parent still pending */
6440 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6441 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6442 /* WM_PAINT in parent first */
6443 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6444 ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
6446 /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
6447 flush_sequence();
6448 SetRect( &rect, 0, 0, 30, 30 );
6449 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
6450 SetRectRgn( hrgn, 0, 0, 30, 30 );
6451 check_update_rgn( hparent, hrgn );
6452 flush_events();
6453 ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
6455 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6456 flush_sequence();
6457 SetRect( &rect, -10, 0, 30, 30 );
6458 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6459 SetRect( &rect, 0, 0, 20, 20 );
6460 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6461 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6462 ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
6464 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6465 flush_sequence();
6466 SetRect( &rect, -10, 0, 30, 30 );
6467 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6468 SetRect( &rect, 0, 0, 100, 100 );
6469 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6470 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6471 ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
6472 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6473 ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
6475 /* test RDW_INTERNALPAINT behavior */
6477 flush_sequence();
6478 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
6479 flush_events();
6480 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6482 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
6483 flush_events();
6484 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6486 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6487 flush_events();
6488 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6490 assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
6491 UpdateWindow( hparent );
6492 flush_events();
6493 flush_sequence();
6494 trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
6495 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6496 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6497 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6498 flush_events();
6499 ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
6501 UpdateWindow( hparent );
6502 flush_events();
6503 flush_sequence();
6504 trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
6505 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6506 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6507 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6508 flush_events();
6509 ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6511 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6512 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6513 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6514 flush_events();
6515 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6517 assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
6518 UpdateWindow( hparent );
6519 flush_events();
6520 flush_sequence();
6521 trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
6522 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6523 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6524 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6525 flush_events();
6526 ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
6528 UpdateWindow( hparent );
6529 flush_events();
6530 flush_sequence();
6531 trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
6532 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6533 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6534 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6535 flush_events();
6536 ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6538 ok(GetWindowLong( hparent, GWL_STYLE ) & WS_VISIBLE, "parent should be visible\n");
6539 ok(GetWindowLong( hchild, GWL_STYLE ) & WS_VISIBLE, "child should be visible\n");
6541 UpdateWindow( hparent );
6542 flush_events();
6543 flush_sequence();
6544 trace("testing SetWindowPos(-10000, -10000) on child\n");
6545 SetWindowPos( hchild, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6546 check_update_rgn( hchild, 0 );
6547 flush_events();
6549 #if 0 /* this one doesn't pass under Wine yet */
6550 UpdateWindow( hparent );
6551 flush_events();
6552 flush_sequence();
6553 trace("testing ShowWindow(SW_MINIMIZE) on child\n");
6554 ShowWindow( hchild, SW_MINIMIZE );
6555 check_update_rgn( hchild, 0 );
6556 flush_events();
6557 #endif
6559 UpdateWindow( hparent );
6560 flush_events();
6561 flush_sequence();
6562 trace("testing SetWindowPos(-10000, -10000) on parent\n");
6563 SetWindowPos( hparent, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6564 check_update_rgn( hparent, 0 );
6565 flush_events();
6567 log_all_parent_messages--;
6568 DestroyWindow( hparent );
6569 ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6571 /* tests for moving windows off-screen (needs simple WS_POPUP windows) */
6573 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_POPUP | WS_VISIBLE,
6574 100, 100, 200, 200, 0, 0, 0, NULL);
6575 ok (hparent != 0, "Failed to create parent window\n");
6577 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
6578 10, 10, 100, 100, hparent, 0, 0, NULL);
6579 ok (hchild != 0, "Failed to create child window\n");
6581 ShowWindow( hparent, SW_SHOW );
6582 UpdateWindow( hparent );
6583 UpdateWindow( hchild );
6584 flush_events();
6585 flush_sequence();
6587 /* moving child outside of parent boundaries changes update region */
6588 SetRect( &rect, 0, 0, 40, 40 );
6589 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6590 SetRectRgn( hrgn, 0, 0, 40, 40 );
6591 check_update_rgn( hchild, hrgn );
6592 MoveWindow( hchild, -10, 10, 100, 100, FALSE );
6593 SetRectRgn( hrgn, 10, 0, 40, 40 );
6594 check_update_rgn( hchild, hrgn );
6595 MoveWindow( hchild, -10, -10, 100, 100, FALSE );
6596 SetRectRgn( hrgn, 10, 10, 40, 40 );
6597 check_update_rgn( hchild, hrgn );
6599 /* moving parent off-screen does too */
6600 SetRect( &rect, 0, 0, 100, 100 );
6601 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
6602 SetRectRgn( hrgn, 0, 0, 100, 100 );
6603 check_update_rgn( hparent, hrgn );
6604 SetRectRgn( hrgn, 10, 10, 40, 40 );
6605 check_update_rgn( hchild, hrgn );
6606 MoveWindow( hparent, -20, -20, 200, 200, FALSE );
6607 SetRectRgn( hrgn, 20, 20, 100, 100 );
6608 check_update_rgn( hparent, hrgn );
6609 SetRectRgn( hrgn, 30, 30, 40, 40 );
6610 check_update_rgn( hchild, hrgn );
6612 /* invalidated region is cropped by the parent rects */
6613 SetRect( &rect, 0, 0, 50, 50 );
6614 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6615 SetRectRgn( hrgn, 30, 30, 50, 50 );
6616 check_update_rgn( hchild, hrgn );
6618 DestroyWindow( hparent );
6619 ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6620 flush_sequence();
6622 DeleteObject( hrgn );
6623 DeleteObject( hrgn2 );
6626 struct wnd_event
6628 HWND hwnd;
6629 HANDLE grand_child;
6630 HANDLE start_event;
6631 HANDLE stop_event;
6634 static DWORD WINAPI thread_proc(void *param)
6636 MSG msg;
6637 struct wnd_event *wnd_event = param;
6639 wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
6640 100, 100, 200, 200, 0, 0, 0, NULL);
6641 ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
6643 SetEvent(wnd_event->start_event);
6645 while (GetMessage(&msg, 0, 0, 0))
6647 TranslateMessage(&msg);
6648 DispatchMessage(&msg);
6651 ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
6653 return 0;
6656 static DWORD CALLBACK create_grand_child_thread( void *param )
6658 struct wnd_event *wnd_event = param;
6659 HWND hchild;
6660 MSG msg;
6662 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
6663 WS_CHILD | WS_VISIBLE, 0, 0, 10, 10, wnd_event->hwnd, 0, 0, NULL);
6664 ok (hchild != 0, "Failed to create child window\n");
6665 flush_events();
6666 flush_sequence();
6667 SetEvent( wnd_event->start_event );
6669 for (;;)
6671 MsgWaitForMultipleObjects(0, NULL, FALSE, 1000, QS_ALLINPUT);
6672 if (!IsWindow( hchild )) break; /* will be destroyed when parent thread exits */
6673 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6675 return 0;
6678 static DWORD CALLBACK create_child_thread( void *param )
6680 struct wnd_event *wnd_event = param;
6681 struct wnd_event child_event;
6682 DWORD ret, tid;
6683 MSG msg;
6685 child_event.hwnd = CreateWindowExA(0, "TestWindowClass", "Test child",
6686 WS_CHILD | WS_VISIBLE, 0, 0, 10, 10, wnd_event->hwnd, 0, 0, NULL);
6687 ok (child_event.hwnd != 0, "Failed to create child window\n");
6688 SetFocus( child_event.hwnd );
6689 flush_events();
6690 flush_sequence();
6691 child_event.start_event = wnd_event->start_event;
6692 wnd_event->grand_child = CreateThread(NULL, 0, create_grand_child_thread, &child_event, 0, &tid);
6693 for (;;)
6695 DWORD ret = MsgWaitForMultipleObjects(1, &child_event.start_event, FALSE, 1000, QS_SENDMESSAGE);
6696 if (ret != 1) break;
6697 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6699 ret = WaitForSingleObject( wnd_event->stop_event, 5000 );
6700 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6701 return 0;
6704 static void test_interthread_messages(void)
6706 HANDLE hThread;
6707 DWORD tid;
6708 WNDPROC proc;
6709 MSG msg;
6710 char buf[256];
6711 int len, expected_len;
6712 struct wnd_event wnd_event;
6713 BOOL ret;
6715 wnd_event.start_event = CreateEventW(NULL, 0, 0, NULL);
6716 if (!wnd_event.start_event)
6718 win_skip("skipping interthread message test under win9x\n");
6719 return;
6722 hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
6723 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
6725 ok(WaitForSingleObject(wnd_event.start_event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6727 CloseHandle(wnd_event.start_event);
6729 SetLastError(0xdeadbeef);
6730 ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
6731 ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
6732 "wrong error code %d\n", GetLastError());
6734 proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6735 ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
6737 expected_len = lstrlenA("window caption text");
6738 memset(buf, 0, sizeof(buf));
6739 SetLastError(0xdeadbeef);
6740 len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
6741 ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
6742 ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
6744 msg.hwnd = wnd_event.hwnd;
6745 msg.message = WM_GETTEXT;
6746 msg.wParam = sizeof(buf);
6747 msg.lParam = (LPARAM)buf;
6748 memset(buf, 0, sizeof(buf));
6749 SetLastError(0xdeadbeef);
6750 len = DispatchMessageA(&msg);
6751 ok((!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY) || broken(len), /* nt4 */
6752 "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
6754 /* the following test causes an exception in user.exe under win9x */
6755 msg.hwnd = wnd_event.hwnd;
6756 msg.message = WM_TIMER;
6757 msg.wParam = 0;
6758 msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6759 SetLastError(0xdeadbeef);
6760 len = DispatchMessageA(&msg);
6761 ok(!len && GetLastError() == 0xdeadbeef,
6762 "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
6764 ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
6765 ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
6767 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6768 CloseHandle(hThread);
6770 ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
6772 wnd_event.hwnd = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6773 100, 100, 200, 200, 0, 0, 0, NULL);
6774 ok (wnd_event.hwnd != 0, "Failed to create parent window\n");
6775 flush_sequence();
6776 log_all_parent_messages++;
6777 wnd_event.start_event = CreateEventA( NULL, TRUE, FALSE, NULL );
6778 wnd_event.stop_event = CreateEventA( NULL, TRUE, FALSE, NULL );
6779 hThread = CreateThread( NULL, 0, create_child_thread, &wnd_event, 0, &tid );
6780 for (;;)
6782 ret = MsgWaitForMultipleObjects(1, &wnd_event.start_event, FALSE, 1000, QS_SENDMESSAGE);
6783 if (ret != 1) break;
6784 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6786 ok( !ret, "MsgWaitForMultipleObjects failed %x\n", ret );
6787 /* now wait for the thread without processing messages; this shouldn't deadlock */
6788 SetEvent( wnd_event.stop_event );
6789 ret = WaitForSingleObject( hThread, 5000 );
6790 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6791 CloseHandle( hThread );
6793 ret = WaitForSingleObject( wnd_event.grand_child, 5000 );
6794 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6795 CloseHandle( wnd_event.grand_child );
6797 CloseHandle( wnd_event.start_event );
6798 CloseHandle( wnd_event.stop_event );
6799 flush_events();
6800 ok_sequence(WmExitThreadSeq, "destroy child on thread exit", FALSE);
6801 log_all_parent_messages--;
6802 DestroyWindow( wnd_event.hwnd );
6806 static const struct message WmVkN[] = {
6807 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6808 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6809 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6810 { WM_CHAR, wparam|lparam, 'n', 1 },
6811 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
6812 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6813 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6814 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6815 { 0 }
6817 static const struct message WmShiftVkN[] = {
6818 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6819 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6820 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6821 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6822 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6823 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6824 { WM_CHAR, wparam|lparam, 'N', 1 },
6825 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
6826 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6827 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6828 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6829 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6830 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6831 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6832 { 0 }
6834 static const struct message WmCtrlVkN[] = {
6835 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6836 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6837 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6838 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6839 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6840 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6841 { WM_CHAR, wparam|lparam, 0x000e, 1 },
6842 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6843 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6844 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6845 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6846 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6847 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6848 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6849 { 0 }
6851 static const struct message WmCtrlVkN_2[] = {
6852 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6853 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6854 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6855 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6856 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6857 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6858 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6859 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6860 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6861 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6862 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6863 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6864 { 0 }
6866 static const struct message WmAltVkN[] = {
6867 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6868 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6869 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6870 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6871 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6872 { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6873 { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
6874 { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
6875 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
6876 { HCBT_SYSCOMMAND, hook },
6877 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6878 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6879 { 0x00AE, sent|defwinproc|optional }, /* XP */
6880 { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
6881 { WM_INITMENU, sent|defwinproc },
6882 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6883 { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
6884 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
6885 { WM_CAPTURECHANGED, sent|defwinproc },
6886 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
6887 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6888 { WM_EXITMENULOOP, sent|defwinproc },
6889 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
6890 { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
6891 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6892 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6893 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6894 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6895 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6896 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6897 { 0 }
6899 static const struct message WmAltVkN_2[] = {
6900 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6901 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6902 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6903 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6904 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6905 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
6906 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6907 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6908 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6909 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6910 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6911 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6912 { 0 }
6914 static const struct message WmCtrlAltVkN[] = {
6915 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6916 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6917 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6918 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6919 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6920 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6921 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6922 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6923 { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6924 { WM_CHAR, optional },
6925 { WM_CHAR, sent|optional },
6926 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6927 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6928 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6929 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6930 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6931 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6932 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6933 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6934 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6935 { 0 }
6937 static const struct message WmCtrlShiftVkN[] = {
6938 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6939 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6940 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6941 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6942 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6943 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6944 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6945 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6946 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
6947 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6948 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6949 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6950 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6951 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6952 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6953 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6954 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6955 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6956 { 0 }
6958 static const struct message WmCtrlAltShiftVkN[] = {
6959 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6960 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6961 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6962 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6963 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6964 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6965 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
6966 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
6967 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
6968 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6969 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6970 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
6971 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6972 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6973 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6974 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
6975 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
6976 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
6977 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6978 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6979 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6980 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6981 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6982 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6983 { 0 }
6985 static const struct message WmAltPressRelease[] = {
6986 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6987 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6988 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6989 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6990 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6991 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6992 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
6993 { HCBT_SYSCOMMAND, hook },
6994 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6995 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6996 { WM_INITMENU, sent|defwinproc },
6997 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6998 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6999 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7001 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
7003 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7004 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
7005 { WM_CAPTURECHANGED, sent|defwinproc },
7006 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
7007 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7008 { WM_EXITMENULOOP, sent|defwinproc },
7009 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
7010 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
7011 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
7012 { 0 }
7014 static const struct message WmShiftMouseButton[] = {
7015 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
7016 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
7017 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
7018 { WM_MOUSEMOVE, wparam|optional, 0, 0 },
7019 { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
7020 { WM_LBUTTONDOWN, wparam, MK_LBUTTON|MK_SHIFT, 0 },
7021 { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON|MK_SHIFT, 0 },
7022 { WM_LBUTTONUP, wparam, MK_SHIFT, 0 },
7023 { WM_LBUTTONUP, sent|wparam, MK_SHIFT, 0 },
7024 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
7025 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
7026 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
7027 { 0 }
7029 static const struct message WmF1Seq[] = {
7030 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
7031 { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
7032 { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
7033 { WM_KEYF1, wparam|lparam, 0, 0 },
7034 { WM_KEYF1, sent|wparam|lparam, 0, 0 },
7035 { WM_HELP, sent|defwinproc },
7036 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
7037 { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
7038 { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
7039 { 0 }
7041 static const struct message WmVkAppsSeq[] = {
7042 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
7043 { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
7044 { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
7045 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
7046 { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
7047 { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
7048 { WM_CONTEXTMENU, lparam, /*hwnd*/0, -1 },
7049 { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, -1 },
7050 { 0 }
7052 static const struct message WmVkF10Seq[] = {
7053 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7054 { WM_SYSKEYDOWN, wparam|lparam, VK_F10, 1 },
7055 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_F10, 0x00000001 },
7056 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7057 { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7058 { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7059 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_KEYMENU },
7060 { HCBT_SYSCOMMAND, hook },
7061 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7062 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7063 { WM_INITMENU, sent|defwinproc },
7064 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7065 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
7066 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7068 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0x10000001 }, /* XP */
7070 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7071 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7072 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
7073 { WM_CAPTURECHANGED, sent|defwinproc },
7074 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
7075 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7076 { WM_EXITMENULOOP, sent|defwinproc },
7077 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7078 { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7079 { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7080 { 0 }
7082 static const struct message WmShiftF10Seq[] = {
7083 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
7084 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
7085 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x00000001 },
7086 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7087 { WM_SYSKEYDOWN, wparam|lparam, VK_F10, 1 },
7088 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_F10, 0x00000001 },
7089 { WM_CONTEXTMENU, sent|defwinproc|lparam, /*hwnd*/0, -1 },
7090 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7091 { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7092 { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7093 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_KEYMENU },
7094 { HCBT_SYSCOMMAND, hook },
7095 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7096 { WM_INITMENU, sent|defwinproc },
7097 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
7098 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xd0000001 }, /* XP */
7099 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0x10000001 }, /* XP */
7100 { WM_CAPTURECHANGED, sent|defwinproc|wparam|lparam, 0, 0 },
7101 { WM_MENUSELECT, sent|defwinproc|wparam|lparam, 0xffff0000, 0 },
7102 { WM_EXITMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7103 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0xc0000001 }, /* XP */
7104 { WM_KEYUP, wparam|lparam, VK_ESCAPE, 0xc0000001 },
7105 { WM_KEYUP, sent|wparam|lparam, VK_ESCAPE, 0xc0000001 },
7106 { 0 }
7109 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
7111 MSG msg;
7113 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
7115 struct recvd_message log_msg;
7117 /* ignore some unwanted messages */
7118 if (msg.message == WM_MOUSEMOVE ||
7119 msg.message == WM_TIMER ||
7120 ignore_message( msg.message ))
7121 continue;
7123 log_msg.hwnd = msg.hwnd;
7124 log_msg.message = msg.message;
7125 log_msg.flags = wparam|lparam;
7126 log_msg.wParam = msg.wParam;
7127 log_msg.lParam = msg.lParam;
7128 log_msg.descr = "accel";
7129 add_message(&log_msg);
7131 if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
7133 TranslateMessage(&msg);
7134 DispatchMessage(&msg);
7139 static void test_accelerators(void)
7141 RECT rc;
7142 POINT pt;
7143 SHORT state;
7144 HACCEL hAccel;
7145 HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7146 100, 100, 200, 200, 0, 0, 0, NULL);
7147 BOOL ret;
7149 assert(hwnd != 0);
7150 UpdateWindow(hwnd);
7151 flush_events();
7152 flush_sequence();
7154 SetFocus(hwnd);
7155 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
7157 state = GetKeyState(VK_SHIFT);
7158 ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
7159 state = GetKeyState(VK_CAPITAL);
7160 ok(state == 0, "wrong CapsLock state %04x\n", state);
7162 hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
7163 assert(hAccel != 0);
7165 flush_events();
7166 pump_msg_loop(hwnd, 0);
7167 flush_sequence();
7169 trace("testing VK_N press/release\n");
7170 flush_sequence();
7171 keybd_event('N', 0, 0, 0);
7172 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7173 pump_msg_loop(hwnd, hAccel);
7174 if (!sequence_cnt) /* we didn't get any message */
7176 skip( "queuing key events not supported\n" );
7177 goto done;
7179 ok_sequence(WmVkN, "VK_N press/release", FALSE);
7181 trace("testing Shift+VK_N press/release\n");
7182 flush_sequence();
7183 keybd_event(VK_SHIFT, 0, 0, 0);
7184 keybd_event('N', 0, 0, 0);
7185 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7186 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7187 pump_msg_loop(hwnd, hAccel);
7188 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
7190 trace("testing Ctrl+VK_N press/release\n");
7191 flush_sequence();
7192 keybd_event(VK_CONTROL, 0, 0, 0);
7193 keybd_event('N', 0, 0, 0);
7194 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7195 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7196 pump_msg_loop(hwnd, hAccel);
7197 ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
7199 trace("testing Alt+VK_N press/release\n");
7200 flush_sequence();
7201 keybd_event(VK_MENU, 0, 0, 0);
7202 keybd_event('N', 0, 0, 0);
7203 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7204 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7205 pump_msg_loop(hwnd, hAccel);
7206 ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
7208 trace("testing Ctrl+Alt+VK_N press/release 1\n");
7209 flush_sequence();
7210 keybd_event(VK_CONTROL, 0, 0, 0);
7211 keybd_event(VK_MENU, 0, 0, 0);
7212 keybd_event('N', 0, 0, 0);
7213 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7214 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7215 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7216 pump_msg_loop(hwnd, hAccel);
7217 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
7219 ret = DestroyAcceleratorTable(hAccel);
7220 ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7222 hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
7223 assert(hAccel != 0);
7225 trace("testing VK_N press/release\n");
7226 flush_sequence();
7227 keybd_event('N', 0, 0, 0);
7228 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7229 pump_msg_loop(hwnd, hAccel);
7230 ok_sequence(WmVkN, "VK_N press/release", FALSE);
7232 trace("testing Shift+VK_N press/release\n");
7233 flush_sequence();
7234 keybd_event(VK_SHIFT, 0, 0, 0);
7235 keybd_event('N', 0, 0, 0);
7236 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7237 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7238 pump_msg_loop(hwnd, hAccel);
7239 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
7241 trace("testing Ctrl+VK_N press/release 2\n");
7242 flush_sequence();
7243 keybd_event(VK_CONTROL, 0, 0, 0);
7244 keybd_event('N', 0, 0, 0);
7245 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7246 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7247 pump_msg_loop(hwnd, hAccel);
7248 ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
7250 trace("testing Alt+VK_N press/release 2\n");
7251 flush_sequence();
7252 keybd_event(VK_MENU, 0, 0, 0);
7253 keybd_event('N', 0, 0, 0);
7254 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7255 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7256 pump_msg_loop(hwnd, hAccel);
7257 ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
7259 trace("testing Ctrl+Alt+VK_N press/release 2\n");
7260 flush_sequence();
7261 keybd_event(VK_CONTROL, 0, 0, 0);
7262 keybd_event(VK_MENU, 0, 0, 0);
7263 keybd_event('N', 0, 0, 0);
7264 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7265 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7266 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7267 pump_msg_loop(hwnd, hAccel);
7268 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
7270 trace("testing Ctrl+Shift+VK_N press/release\n");
7271 flush_sequence();
7272 keybd_event(VK_CONTROL, 0, 0, 0);
7273 keybd_event(VK_SHIFT, 0, 0, 0);
7274 keybd_event('N', 0, 0, 0);
7275 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7276 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7277 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7278 pump_msg_loop(hwnd, hAccel);
7279 ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
7281 trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
7282 flush_sequence();
7283 keybd_event(VK_CONTROL, 0, 0, 0);
7284 keybd_event(VK_MENU, 0, 0, 0);
7285 keybd_event(VK_SHIFT, 0, 0, 0);
7286 keybd_event('N', 0, 0, 0);
7287 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7288 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7289 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7290 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7291 pump_msg_loop(hwnd, hAccel);
7292 ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
7294 ret = DestroyAcceleratorTable(hAccel);
7295 ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7296 hAccel = 0;
7298 trace("testing Alt press/release\n");
7299 flush_sequence();
7300 keybd_event(VK_MENU, 0, 0, 0);
7301 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7302 keybd_event(VK_MENU, 0, 0, 0);
7303 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7304 pump_msg_loop(hwnd, 0);
7305 /* this test doesn't pass in Wine for managed windows */
7306 ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
7308 trace("testing VK_F1 press/release\n");
7309 keybd_event(VK_F1, 0, 0, 0);
7310 keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
7311 pump_msg_loop(hwnd, 0);
7312 ok_sequence(WmF1Seq, "F1 press/release", FALSE);
7314 trace("testing VK_APPS press/release\n");
7315 keybd_event(VK_APPS, 0, 0, 0);
7316 keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
7317 pump_msg_loop(hwnd, 0);
7318 ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
7320 trace("testing VK_F10 press/release\n");
7321 keybd_event(VK_F10, 0, 0, 0);
7322 keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7323 keybd_event(VK_F10, 0, 0, 0);
7324 keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7325 pump_msg_loop(hwnd, 0);
7326 ok_sequence(WmVkF10Seq, "VK_F10 press/release", TRUE);
7328 trace("testing SHIFT+F10 press/release\n");
7329 keybd_event(VK_SHIFT, 0, 0, 0);
7330 keybd_event(VK_F10, 0, 0, 0);
7331 keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7332 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7333 keybd_event(VK_ESCAPE, 0, 0, 0);
7334 keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0);
7335 pump_msg_loop(hwnd, 0);
7336 ok_sequence(WmShiftF10Seq, "SHIFT+F10 press/release", TRUE);
7338 trace("testing Shift+MouseButton press/release\n");
7339 /* first, move mouse pointer inside of the window client area */
7340 GetClientRect(hwnd, &rc);
7341 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
7342 rc.left += (rc.right - rc.left)/2;
7343 rc.top += (rc.bottom - rc.top)/2;
7344 SetCursorPos(rc.left, rc.top);
7345 SetActiveWindow(hwnd);
7347 flush_events();
7348 flush_sequence();
7349 GetCursorPos(&pt);
7350 if (pt.x == rc.left && pt.y == rc.top)
7352 int i;
7353 keybd_event(VK_SHIFT, 0, 0, 0);
7354 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
7355 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7356 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7357 pump_msg_loop(hwnd, 0);
7358 for (i = 0; i < sequence_cnt; i++) if (sequence[i].message == WM_LBUTTONDOWN) break;
7359 if (i < sequence_cnt)
7360 ok_sequence(WmShiftMouseButton, "Shift+MouseButton press/release", FALSE);
7361 else
7362 skip( "Shift+MouseButton event didn't get to the window\n" );
7365 done:
7366 if (hAccel) DestroyAcceleratorTable(hAccel);
7367 DestroyWindow(hwnd);
7370 /************* window procedures ********************/
7372 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message,
7373 WPARAM wParam, LPARAM lParam)
7375 static LONG defwndproc_counter = 0;
7376 static LONG beginpaint_counter = 0;
7377 LRESULT ret;
7378 struct recvd_message msg;
7380 if (ignore_message( message )) return 0;
7382 switch (message)
7384 case WM_ENABLE:
7386 LONG style = GetWindowLongA(hwnd, GWL_STYLE);
7387 ok((BOOL)wParam == !(style & WS_DISABLED),
7388 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
7389 break;
7392 case WM_CAPTURECHANGED:
7393 if (test_DestroyWindow_flag)
7395 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7396 if (style & WS_CHILD)
7397 lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7398 else if (style & WS_POPUP)
7399 lParam = WND_POPUP_ID;
7400 else
7401 lParam = WND_PARENT_ID;
7403 break;
7405 case WM_NCDESTROY:
7407 HWND capture;
7409 ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
7410 capture = GetCapture();
7411 if (capture)
7413 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
7414 trace("current capture %p, releasing...\n", capture);
7415 ReleaseCapture();
7418 /* fall through */
7419 case WM_DESTROY:
7420 if (pGetAncestor)
7421 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
7422 if (test_DestroyWindow_flag)
7424 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7425 if (style & WS_CHILD)
7426 lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7427 else if (style & WS_POPUP)
7428 lParam = WND_POPUP_ID;
7429 else
7430 lParam = WND_PARENT_ID;
7432 break;
7434 /* test_accelerators() depends on this */
7435 case WM_NCHITTEST:
7436 return HTCLIENT;
7438 /* ignore */
7439 case WM_MOUSEMOVE:
7440 case WM_MOUSEACTIVATE:
7441 case WM_NCMOUSEMOVE:
7442 case WM_SETCURSOR:
7443 case WM_IME_SELECT:
7444 return 0;
7447 msg.hwnd = hwnd;
7448 msg.message = message;
7449 msg.flags = sent|wparam|lparam;
7450 if (defwndproc_counter) msg.flags |= defwinproc;
7451 if (beginpaint_counter) msg.flags |= beginpaint;
7452 msg.wParam = wParam;
7453 msg.lParam = lParam;
7454 msg.descr = "MsgCheckProc";
7455 add_message(&msg);
7457 if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
7459 HWND parent = GetParent(hwnd);
7460 RECT rc;
7461 MINMAXINFO *minmax = (MINMAXINFO *)lParam;
7463 GetClientRect(parent, &rc);
7464 trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
7465 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
7466 minmax->ptReserved.x, minmax->ptReserved.y,
7467 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
7468 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
7469 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
7470 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
7472 ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
7473 minmax->ptMaxSize.x, rc.right);
7474 ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
7475 minmax->ptMaxSize.y, rc.bottom);
7478 if (message == WM_PAINT)
7480 PAINTSTRUCT ps;
7481 beginpaint_counter++;
7482 BeginPaint( hwnd, &ps );
7483 beginpaint_counter--;
7484 EndPaint( hwnd, &ps );
7485 return 0;
7488 defwndproc_counter++;
7489 ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam)
7490 : DefWindowProcA(hwnd, message, wParam, lParam);
7491 defwndproc_counter--;
7493 return ret;
7496 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7498 return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
7501 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7503 return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
7506 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7508 static LONG defwndproc_counter = 0;
7509 LRESULT ret;
7510 struct recvd_message msg;
7512 if (ignore_message( message )) return 0;
7514 switch (message)
7516 case WM_QUERYENDSESSION:
7517 case WM_ENDSESSION:
7518 lParam &= ~0x01; /* Vista adds a 0x01 flag */
7519 break;
7522 msg.hwnd = hwnd;
7523 msg.message = message;
7524 msg.flags = sent|wparam|lparam;
7525 if (defwndproc_counter) msg.flags |= defwinproc;
7526 msg.wParam = wParam;
7527 msg.lParam = lParam;
7528 msg.descr = "popup";
7529 add_message(&msg);
7531 if (message == WM_CREATE)
7533 DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
7534 SetWindowLongA(hwnd, GWL_STYLE, style);
7537 defwndproc_counter++;
7538 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7539 defwndproc_counter--;
7541 return ret;
7544 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7546 static LONG defwndproc_counter = 0;
7547 static LONG beginpaint_counter = 0;
7548 LRESULT ret;
7549 struct recvd_message msg;
7551 if (ignore_message( message )) return 0;
7553 if (log_all_parent_messages ||
7554 message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
7555 message == WM_SETFOCUS || message == WM_KILLFOCUS ||
7556 message == WM_ENABLE || message == WM_ENTERIDLE ||
7557 message == WM_DRAWITEM || message == WM_COMMAND ||
7558 message == WM_IME_SETCONTEXT)
7560 switch (message)
7562 /* ignore */
7563 case WM_NCHITTEST:
7564 return HTCLIENT;
7565 case WM_SETCURSOR:
7566 case WM_MOUSEMOVE:
7567 case WM_NCMOUSEMOVE:
7568 return 0;
7570 case WM_ERASEBKGND:
7572 RECT rc;
7573 INT ret = GetClipBox((HDC)wParam, &rc);
7575 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
7576 ret, rc.left, rc.top, rc.right, rc.bottom);
7577 break;
7581 msg.hwnd = hwnd;
7582 msg.message = message;
7583 msg.flags = sent|parent|wparam|lparam;
7584 if (defwndproc_counter) msg.flags |= defwinproc;
7585 if (beginpaint_counter) msg.flags |= beginpaint;
7586 msg.wParam = wParam;
7587 msg.lParam = lParam;
7588 msg.descr = "parent";
7589 add_message(&msg);
7592 if (message == WM_PAINT)
7594 PAINTSTRUCT ps;
7595 beginpaint_counter++;
7596 BeginPaint( hwnd, &ps );
7597 beginpaint_counter--;
7598 EndPaint( hwnd, &ps );
7599 return 0;
7602 defwndproc_counter++;
7603 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7604 defwndproc_counter--;
7606 return ret;
7609 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7611 static LONG defwndproc_counter = 0;
7612 LRESULT ret;
7613 struct recvd_message msg;
7615 if (ignore_message( message )) return 0;
7617 if (test_def_id)
7619 DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
7620 ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
7621 if (after_end_dialog)
7622 ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
7623 else
7624 ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
7627 msg.hwnd = hwnd;
7628 msg.message = message;
7629 msg.flags = sent|wparam|lparam;
7630 if (defwndproc_counter) msg.flags |= defwinproc;
7631 msg.wParam = wParam;
7632 msg.lParam = lParam;
7633 msg.descr = "dialog";
7634 add_message(&msg);
7636 defwndproc_counter++;
7637 ret = DefDlgProcA(hwnd, message, wParam, lParam);
7638 defwndproc_counter--;
7640 return ret;
7643 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7645 static LONG defwndproc_counter = 0;
7646 LRESULT ret;
7647 struct recvd_message msg;
7649 /* log only specific messages we are interested in */
7650 switch (message)
7652 #if 0 /* probably log these as well */
7653 case WM_ACTIVATE:
7654 case WM_SETFOCUS:
7655 case WM_KILLFOCUS:
7656 #endif
7657 case WM_SHOWWINDOW:
7658 case WM_SIZE:
7659 case WM_MOVE:
7660 case WM_GETMINMAXINFO:
7661 case WM_WINDOWPOSCHANGING:
7662 case WM_WINDOWPOSCHANGED:
7663 break;
7665 default: /* ignore */
7666 /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
7667 return DefWindowProcA(hwnd, message, wParam, lParam);
7670 msg.hwnd = hwnd;
7671 msg.message = message;
7672 msg.flags = sent|wparam|lparam;
7673 if (defwndproc_counter) msg.flags |= defwinproc;
7674 msg.wParam = wParam;
7675 msg.lParam = lParam;
7676 msg.descr = "show";
7677 add_message(&msg);
7679 defwndproc_counter++;
7680 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7681 defwndproc_counter--;
7683 return ret;
7686 static LRESULT WINAPI PaintLoopProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
7688 switch (msg)
7690 case WM_CREATE: return 0;
7691 case WM_PAINT:
7693 MSG msg2;
7694 static int i = 0;
7696 if (i < 256)
7698 i++;
7699 if (PeekMessageA(&msg2, 0, 0, 0, 1))
7701 TranslateMessage(&msg2);
7702 DispatchMessage(&msg2);
7704 i--;
7706 else ok(broken(1), "infinite loop\n");
7707 if ( i == 0)
7708 paint_loop_done = 1;
7709 return DefWindowProcA(hWnd,msg,wParam,lParam);
7712 return DefWindowProcA(hWnd,msg,wParam,lParam);
7715 static BOOL RegisterWindowClasses(void)
7717 WNDCLASSA cls;
7718 WNDCLASSW clsW;
7720 cls.style = 0;
7721 cls.lpfnWndProc = MsgCheckProcA;
7722 cls.cbClsExtra = 0;
7723 cls.cbWndExtra = 0;
7724 cls.hInstance = GetModuleHandleA(0);
7725 cls.hIcon = 0;
7726 cls.hCursor = LoadCursorA(0, IDC_ARROW);
7727 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7728 cls.lpszMenuName = NULL;
7729 cls.lpszClassName = "TestWindowClass";
7730 if(!RegisterClassA(&cls)) return FALSE;
7732 cls.lpfnWndProc = ShowWindowProcA;
7733 cls.lpszClassName = "ShowWindowClass";
7734 if(!RegisterClassA(&cls)) return FALSE;
7736 cls.lpfnWndProc = PopupMsgCheckProcA;
7737 cls.lpszClassName = "TestPopupClass";
7738 if(!RegisterClassA(&cls)) return FALSE;
7740 cls.lpfnWndProc = ParentMsgCheckProcA;
7741 cls.lpszClassName = "TestParentClass";
7742 if(!RegisterClassA(&cls)) return FALSE;
7744 cls.lpfnWndProc = DefWindowProcA;
7745 cls.lpszClassName = "SimpleWindowClass";
7746 if(!RegisterClassA(&cls)) return FALSE;
7748 cls.lpfnWndProc = PaintLoopProcA;
7749 cls.lpszClassName = "PaintLoopWindowClass";
7750 if(!RegisterClassA(&cls)) return FALSE;
7752 cls.style = CS_NOCLOSE;
7753 cls.lpszClassName = "NoCloseWindowClass";
7754 if(!RegisterClassA(&cls)) return FALSE;
7756 ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
7757 cls.style = 0;
7758 cls.hInstance = GetModuleHandleA(0);
7759 cls.hbrBackground = 0;
7760 cls.lpfnWndProc = TestDlgProcA;
7761 cls.lpszClassName = "TestDialogClass";
7762 if(!RegisterClassA(&cls)) return FALSE;
7764 clsW.style = 0;
7765 clsW.lpfnWndProc = MsgCheckProcW;
7766 clsW.cbClsExtra = 0;
7767 clsW.cbWndExtra = 0;
7768 clsW.hInstance = GetModuleHandleW(0);
7769 clsW.hIcon = 0;
7770 clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
7771 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
7772 clsW.lpszMenuName = NULL;
7773 clsW.lpszClassName = testWindowClassW;
7774 RegisterClassW(&clsW); /* ignore error, this fails on Win9x */
7776 return TRUE;
7779 static BOOL is_our_logged_class(HWND hwnd)
7781 char buf[256];
7783 if (GetClassNameA(hwnd, buf, sizeof(buf)))
7785 if (!lstrcmpiA(buf, "TestWindowClass") ||
7786 !lstrcmpiA(buf, "ShowWindowClass") ||
7787 !lstrcmpiA(buf, "TestParentClass") ||
7788 !lstrcmpiA(buf, "TestPopupClass") ||
7789 !lstrcmpiA(buf, "SimpleWindowClass") ||
7790 !lstrcmpiA(buf, "TestDialogClass") ||
7791 !lstrcmpiA(buf, "MDI_frame_class") ||
7792 !lstrcmpiA(buf, "MDI_client_class") ||
7793 !lstrcmpiA(buf, "MDI_child_class") ||
7794 !lstrcmpiA(buf, "my_button_class") ||
7795 !lstrcmpiA(buf, "my_edit_class") ||
7796 !lstrcmpiA(buf, "static") ||
7797 !lstrcmpiA(buf, "ListBox") ||
7798 !lstrcmpiA(buf, "ComboBox") ||
7799 !lstrcmpiA(buf, "MyDialogClass") ||
7800 !lstrcmpiA(buf, "#32770") ||
7801 !lstrcmpiA(buf, "#32768"))
7802 return TRUE;
7804 return FALSE;
7807 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
7809 HWND hwnd;
7811 ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7813 if (nCode == HCBT_CLICKSKIPPED)
7815 /* ignore this event, XP sends it a lot when switching focus between windows */
7816 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7819 if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
7821 struct recvd_message msg;
7823 msg.hwnd = 0;
7824 msg.message = nCode;
7825 msg.flags = hook|wparam|lparam;
7826 msg.wParam = wParam;
7827 msg.lParam = lParam;
7828 msg.descr = "CBT";
7829 add_message(&msg);
7831 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7834 if (nCode == HCBT_DESTROYWND)
7836 if (test_DestroyWindow_flag)
7838 DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
7839 if (style & WS_CHILD)
7840 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
7841 else if (style & WS_POPUP)
7842 lParam = WND_POPUP_ID;
7843 else
7844 lParam = WND_PARENT_ID;
7848 /* Log also SetFocus(0) calls */
7849 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7851 if (is_our_logged_class(hwnd))
7853 struct recvd_message msg;
7855 msg.hwnd = hwnd;
7856 msg.message = nCode;
7857 msg.flags = hook|wparam|lparam;
7858 msg.wParam = wParam;
7859 msg.lParam = lParam;
7860 msg.descr = "CBT";
7861 add_message(&msg);
7863 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7866 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
7867 DWORD event,
7868 HWND hwnd,
7869 LONG object_id,
7870 LONG child_id,
7871 DWORD thread_id,
7872 DWORD event_time)
7874 ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7876 /* ignore mouse cursor events */
7877 if (object_id == OBJID_CURSOR) return;
7879 if (!hwnd || is_our_logged_class(hwnd))
7881 struct recvd_message msg;
7883 msg.hwnd = hwnd;
7884 msg.message = event;
7885 msg.flags = winevent_hook|wparam|lparam;
7886 msg.wParam = object_id;
7887 msg.lParam = child_id;
7888 msg.descr = "WEH";
7889 add_message(&msg);
7893 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
7894 static const WCHAR wszAnsi[] = {'U',0};
7896 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
7898 switch (uMsg)
7900 case CB_FINDSTRINGEXACT:
7901 trace("String: %p\n", (LPCWSTR)lParam);
7902 if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
7903 return 1;
7904 if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
7905 return 0;
7906 return -1;
7908 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
7911 static const struct message WmGetTextLengthAfromW[] = {
7912 { WM_GETTEXTLENGTH, sent },
7913 { WM_GETTEXT, sent|optional },
7914 { 0 }
7917 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
7919 /* dummy window proc for WM_GETTEXTLENGTH test */
7920 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
7922 switch(msg)
7924 case WM_GETTEXTLENGTH:
7925 return lstrlenW(dummy_window_text) + 37; /* some random length */
7926 case WM_GETTEXT:
7927 lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
7928 return lstrlenW( (LPWSTR)lp );
7929 default:
7930 return DefWindowProcW( hwnd, msg, wp, lp );
7934 static void test_message_conversion(void)
7936 static const WCHAR wszMsgConversionClass[] =
7937 {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
7938 WNDCLASSW cls;
7939 LRESULT lRes;
7940 HWND hwnd;
7941 WNDPROC wndproc, newproc;
7942 BOOL ret;
7944 cls.style = 0;
7945 cls.lpfnWndProc = MsgConversionProcW;
7946 cls.cbClsExtra = 0;
7947 cls.cbWndExtra = 0;
7948 cls.hInstance = GetModuleHandleW(NULL);
7949 cls.hIcon = NULL;
7950 cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
7951 cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
7952 cls.lpszMenuName = NULL;
7953 cls.lpszClassName = wszMsgConversionClass;
7954 /* this call will fail on Win9x, but that doesn't matter as this test is
7955 * meaningless on those platforms */
7956 if(!RegisterClassW(&cls)) return;
7958 hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
7959 100, 100, 200, 200, 0, 0, 0, NULL);
7960 ok(hwnd != NULL, "Window creation failed\n");
7962 /* {W, A} -> A */
7964 wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
7965 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7966 ok(lRes == 0, "String should have been converted\n");
7967 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7968 ok(lRes == 1, "String shouldn't have been converted\n");
7970 /* {W, A} -> W */
7972 wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
7973 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7974 ok(lRes == 1, "String shouldn't have been converted\n");
7975 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7976 ok(lRes == 1, "String shouldn't have been converted\n");
7978 /* Synchronous messages */
7980 lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7981 ok(lRes == 0, "String should have been converted\n");
7982 lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7983 ok(lRes == 1, "String shouldn't have been converted\n");
7985 /* Asynchronous messages */
7987 SetLastError(0);
7988 lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7989 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7990 "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7991 SetLastError(0);
7992 lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7993 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7994 "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7995 SetLastError(0);
7996 lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7997 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7998 "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7999 SetLastError(0);
8000 lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8001 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8002 "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8003 SetLastError(0);
8004 lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8005 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8006 "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8007 SetLastError(0);
8008 lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8009 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8010 "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8011 SetLastError(0);
8012 lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
8013 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8014 "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8015 SetLastError(0);
8016 lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
8017 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8018 "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8020 /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
8022 hwnd = CreateWindowW (testWindowClassW, wszUnicode,
8023 WS_OVERLAPPEDWINDOW,
8024 100, 100, 200, 200, 0, 0, 0, NULL);
8025 assert(hwnd);
8026 flush_sequence();
8027 lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
8028 ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
8029 ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
8030 "got bad length %ld\n", lRes );
8032 flush_sequence();
8033 lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
8034 hwnd, WM_GETTEXTLENGTH, 0, 0);
8035 ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
8036 ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
8037 "got bad length %ld\n", lRes );
8039 wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
8040 newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
8041 lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
8042 ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
8043 NULL, 0, NULL, NULL ) ||
8044 broken(lRes == lstrlenW(dummy_window_text) + 37),
8045 "got bad length %ld\n", lRes );
8047 SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc ); /* restore old wnd proc */
8048 lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
8049 ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
8050 NULL, 0, NULL, NULL ) ||
8051 broken(lRes == lstrlenW(dummy_window_text) + 37),
8052 "got bad length %ld\n", lRes );
8054 ret = DestroyWindow(hwnd);
8055 ok( ret, "DestroyWindow() error %d\n", GetLastError());
8058 struct timer_info
8060 HWND hWnd;
8061 HANDLE handles[2];
8062 DWORD id;
8065 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
8069 static VOID CALLBACK tfunc_crash(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
8071 /* Crash on purpose */
8072 *(volatile int *)0 = 2;
8075 #define TIMER_ID 0x19
8077 static DWORD WINAPI timer_thread_proc(LPVOID x)
8079 struct timer_info *info = x;
8080 DWORD r;
8082 r = KillTimer(info->hWnd, 0x19);
8083 ok(r,"KillTimer failed in thread\n");
8084 r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
8085 ok(r,"SetTimer failed in thread\n");
8086 ok(r==TIMER_ID,"SetTimer id different\n");
8087 r = SetEvent(info->handles[0]);
8088 ok(r,"SetEvent failed in thread\n");
8089 return 0;
8092 static void test_timers(void)
8094 struct timer_info info;
8095 DWORD id;
8096 MSG msg;
8098 info.hWnd = CreateWindow ("TestWindowClass", NULL,
8099 WS_OVERLAPPEDWINDOW ,
8100 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8101 NULL, NULL, 0);
8103 info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
8104 ok(info.id, "SetTimer failed\n");
8105 ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
8106 info.handles[0] = CreateEvent(NULL,0,0,NULL);
8107 info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
8109 WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
8111 WaitForSingleObject(info.handles[1], INFINITE);
8113 CloseHandle(info.handles[0]);
8114 CloseHandle(info.handles[1]);
8116 ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
8118 ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
8120 /* Test timer callback with crash */
8121 SetLastError(0xdeadbeef);
8122 info.hWnd = CreateWindowW(testWindowClassW, NULL,
8123 WS_OVERLAPPEDWINDOW ,
8124 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8125 NULL, NULL, 0);
8126 if ((!info.hWnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) || /* Win9x/Me */
8127 (!pGetMenuInfo)) /* Win95/NT4 */
8129 win_skip("Test would crash on Win9x/WinMe/NT4\n");
8130 DestroyWindow(info.hWnd);
8131 return;
8133 info.id = SetTimer(info.hWnd, TIMER_ID, 0, tfunc_crash);
8134 ok(info.id, "SetTimer failed\n");
8135 Sleep(150);
8136 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8138 ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
8141 static int count = 0;
8142 static VOID CALLBACK callback_count(
8143 HWND hwnd,
8144 UINT uMsg,
8145 UINT_PTR idEvent,
8146 DWORD dwTime
8149 count++;
8152 static void test_timers_no_wnd(void)
8154 UINT_PTR id, id2;
8155 MSG msg;
8157 count = 0;
8158 id = SetTimer(NULL, 0, 100, callback_count);
8159 ok(id != 0, "did not get id from SetTimer.\n");
8160 id2 = SetTimer(NULL, id, 200, callback_count);
8161 ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
8162 Sleep(150);
8163 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8164 ok(count == 0, "did not get zero count as expected (%i).\n", count);
8165 Sleep(150);
8166 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8167 ok(count == 1, "did not get one count as expected (%i).\n", count);
8168 KillTimer(NULL, id);
8169 Sleep(250);
8170 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8171 ok(count == 1, "killing replaced timer did not work (%i).\n", count);
8174 /* Various win events with arbitrary parameters */
8175 static const struct message WmWinEventsSeq[] = {
8176 { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
8177 { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
8178 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
8179 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
8180 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
8181 { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
8182 { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
8183 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
8184 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
8185 /* our win event hook ignores OBJID_CURSOR events */
8186 /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
8187 { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
8188 { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
8189 { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
8190 { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
8191 { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
8192 { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
8193 { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
8194 { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
8195 { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
8196 { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
8197 { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
8198 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
8199 { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
8200 { 0 }
8202 static const struct message WmWinEventCaretSeq[] = {
8203 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8204 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8205 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
8206 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8207 { 0 }
8209 static const struct message WmWinEventCaretSeq_2[] = {
8210 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8211 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8212 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8213 { 0 }
8215 static const struct message WmWinEventAlertSeq[] = {
8216 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
8217 { 0 }
8219 static const struct message WmWinEventAlertSeq_2[] = {
8220 /* create window in the thread proc */
8221 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
8222 /* our test event */
8223 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
8224 { 0 }
8226 static const struct message WmGlobalHookSeq_1[] = {
8227 /* create window in the thread proc */
8228 { HCBT_CREATEWND, hook|lparam, 0, 2 },
8229 /* our test events */
8230 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
8231 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
8232 { 0 }
8234 static const struct message WmGlobalHookSeq_2[] = {
8235 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
8236 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
8237 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
8238 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
8239 { 0 }
8242 static const struct message WmMouseLLHookSeq[] = {
8243 { WM_MOUSEMOVE, hook },
8244 { WM_LBUTTONUP, hook },
8245 { WM_MOUSEMOVE, hook },
8246 { 0 }
8249 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
8250 DWORD event,
8251 HWND hwnd,
8252 LONG object_id,
8253 LONG child_id,
8254 DWORD thread_id,
8255 DWORD event_time)
8257 char buf[256];
8259 if (GetClassNameA(hwnd, buf, sizeof(buf)))
8261 if (!lstrcmpiA(buf, "TestWindowClass") ||
8262 !lstrcmpiA(buf, "static"))
8264 struct recvd_message msg;
8266 msg.hwnd = hwnd;
8267 msg.message = event;
8268 msg.flags = winevent_hook|wparam|lparam;
8269 msg.wParam = object_id;
8270 msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
8271 msg.descr = "WEH_2";
8272 add_message(&msg);
8277 static HHOOK hCBT_global_hook;
8278 static DWORD cbt_global_hook_thread_id;
8280 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
8282 HWND hwnd;
8283 char buf[256];
8285 if (nCode == HCBT_SYSCOMMAND)
8287 struct recvd_message msg;
8289 msg.hwnd = 0;
8290 msg.message = nCode;
8291 msg.flags = hook|wparam|lparam;
8292 msg.wParam = wParam;
8293 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8294 msg.descr = "CBT_2";
8295 add_message(&msg);
8297 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8299 /* WH_MOUSE_LL hook */
8300 if (nCode == HC_ACTION)
8302 MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
8304 /* we can't test for real mouse events */
8305 if (mhll->flags & LLMHF_INJECTED)
8307 struct recvd_message msg;
8309 memset (&msg, 0, sizeof (msg));
8310 msg.message = wParam;
8311 msg.flags = hook;
8312 msg.descr = "CBT_2";
8313 add_message(&msg);
8315 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8318 /* Log also SetFocus(0) calls */
8319 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
8321 if (GetClassNameA(hwnd, buf, sizeof(buf)))
8323 if (!lstrcmpiA(buf, "TestWindowClass") ||
8324 !lstrcmpiA(buf, "static"))
8326 struct recvd_message msg;
8328 msg.hwnd = hwnd;
8329 msg.message = nCode;
8330 msg.flags = hook|wparam|lparam;
8331 msg.wParam = wParam;
8332 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8333 msg.descr = "CBT_2";
8334 add_message(&msg);
8337 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8340 static DWORD WINAPI win_event_global_thread_proc(void *param)
8342 HWND hwnd;
8343 MSG msg;
8344 HANDLE hevent = *(HANDLE *)param;
8346 assert(pNotifyWinEvent);
8348 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8349 assert(hwnd);
8350 trace("created thread window %p\n", hwnd);
8352 *(HWND *)param = hwnd;
8354 flush_sequence();
8355 /* this event should be received only by our new hook proc,
8356 * an old one does not expect an event from another thread.
8358 pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
8359 SetEvent(hevent);
8361 while (GetMessage(&msg, 0, 0, 0))
8363 TranslateMessage(&msg);
8364 DispatchMessage(&msg);
8366 return 0;
8369 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
8371 HWND hwnd;
8372 MSG msg;
8373 HANDLE hevent = *(HANDLE *)param;
8375 flush_sequence();
8376 /* these events should be received only by our new hook proc,
8377 * an old one does not expect an event from another thread.
8380 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8381 assert(hwnd);
8382 trace("created thread window %p\n", hwnd);
8384 *(HWND *)param = hwnd;
8386 /* Windows doesn't like when a thread plays games with the focus,
8387 that leads to all kinds of misbehaviours and failures to activate
8388 a window. So, better keep next lines commented out.
8389 SetFocus(0);
8390 SetFocus(hwnd);*/
8392 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8393 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8395 SetEvent(hevent);
8397 while (GetMessage(&msg, 0, 0, 0))
8399 TranslateMessage(&msg);
8400 DispatchMessage(&msg);
8402 return 0;
8405 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
8407 HWND hwnd;
8408 MSG msg;
8409 HANDLE hevent = *(HANDLE *)param;
8411 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8412 assert(hwnd);
8413 trace("created thread window %p\n", hwnd);
8415 *(HWND *)param = hwnd;
8417 flush_sequence();
8419 /* Windows doesn't like when a thread plays games with the focus,
8420 * that leads to all kinds of misbehaviours and failures to activate
8421 * a window. So, better don't generate a mouse click message below.
8423 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8424 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8425 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8427 SetEvent(hevent);
8428 while (GetMessage(&msg, 0, 0, 0))
8430 TranslateMessage(&msg);
8431 DispatchMessage(&msg);
8433 return 0;
8436 static void test_winevents(void)
8438 BOOL ret;
8439 MSG msg;
8440 HWND hwnd, hwnd2;
8441 UINT i;
8442 HANDLE hthread, hevent;
8443 DWORD tid;
8444 HWINEVENTHOOK hhook;
8445 const struct message *events = WmWinEventsSeq;
8447 hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
8448 WS_OVERLAPPEDWINDOW,
8449 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8450 NULL, NULL, 0);
8451 assert(hwnd);
8453 /****** start of global hook test *************/
8454 hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8455 if (!hCBT_global_hook)
8457 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8458 skip( "cannot set global hook\n" );
8459 return;
8462 hevent = CreateEventA(NULL, 0, 0, NULL);
8463 assert(hevent);
8464 hwnd2 = hevent;
8466 hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
8467 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8469 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8471 ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
8473 flush_sequence();
8474 /* this one should be received only by old hook proc */
8475 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8476 /* this one should be received only by old hook proc */
8477 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8479 ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
8481 ret = UnhookWindowsHookEx(hCBT_global_hook);
8482 ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8484 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8485 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8486 CloseHandle(hthread);
8487 CloseHandle(hevent);
8488 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8489 /****** end of global hook test *************/
8491 if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
8493 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8494 return;
8497 flush_sequence();
8499 if (0)
8501 /* this test doesn't pass under Win9x */
8502 /* win2k ignores events with hwnd == 0 */
8503 SetLastError(0xdeadbeef);
8504 pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
8505 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
8506 GetLastError() == 0xdeadbeef, /* Win9x */
8507 "unexpected error %d\n", GetLastError());
8508 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8511 for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
8512 pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
8514 ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
8516 /****** start of event filtering test *************/
8517 hhook = pSetWinEventHook(
8518 EVENT_OBJECT_SHOW, /* 0x8002 */
8519 EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
8520 GetModuleHandleA(0), win_event_global_hook_proc,
8521 GetCurrentProcessId(), 0,
8522 WINEVENT_INCONTEXT);
8523 ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8525 hevent = CreateEventA(NULL, 0, 0, NULL);
8526 assert(hevent);
8527 hwnd2 = hevent;
8529 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8530 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8532 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8534 ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
8536 flush_sequence();
8537 /* this one should be received only by old hook proc */
8538 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8539 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8540 /* this one should be received only by old hook proc */
8541 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8543 ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
8545 ret = pUnhookWinEvent(hhook);
8546 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8548 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8549 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8550 CloseHandle(hthread);
8551 CloseHandle(hevent);
8552 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8553 /****** end of event filtering test *************/
8555 /****** start of out of context event test *************/
8556 hhook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0,
8557 win_event_global_hook_proc, GetCurrentProcessId(), 0,
8558 WINEVENT_OUTOFCONTEXT);
8559 ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8561 hevent = CreateEventA(NULL, 0, 0, NULL);
8562 assert(hevent);
8563 hwnd2 = hevent;
8565 flush_sequence();
8567 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8568 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8570 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8572 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8573 /* process pending winevent messages */
8574 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8575 ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", 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_2, "caret winevent for incontext proc", FALSE);
8585 /* process pending winevent messages */
8586 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8587 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
8589 ret = pUnhookWinEvent(hhook);
8590 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8592 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8593 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8594 CloseHandle(hthread);
8595 CloseHandle(hevent);
8596 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8597 /****** end of out of context event test *************/
8599 /****** start of MOUSE_LL hook test *************/
8600 hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8601 /* WH_MOUSE_LL is not supported on Win9x platforms */
8602 if (!hCBT_global_hook)
8604 win_skip("Skipping WH_MOUSE_LL test on this platform\n");
8605 goto skip_mouse_ll_hook_test;
8608 hevent = CreateEventA(NULL, 0, 0, NULL);
8609 assert(hevent);
8610 hwnd2 = hevent;
8612 hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
8613 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8615 while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
8616 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
8618 ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
8619 flush_sequence();
8621 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8622 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8623 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8625 ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
8627 ret = UnhookWindowsHookEx(hCBT_global_hook);
8628 ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8630 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8631 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8632 CloseHandle(hthread);
8633 CloseHandle(hevent);
8634 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8635 /****** end of MOUSE_LL hook test *************/
8636 skip_mouse_ll_hook_test:
8638 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8641 static void test_set_hook(void)
8643 BOOL ret;
8644 HHOOK hhook;
8645 HWINEVENTHOOK hwinevent_hook;
8647 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
8648 ok(hhook != 0, "local hook does not require hModule set to 0\n");
8649 UnhookWindowsHookEx(hhook);
8651 if (0)
8653 /* this test doesn't pass under Win9x: BUG! */
8654 SetLastError(0xdeadbeef);
8655 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
8656 ok(!hhook, "global hook requires hModule != 0\n");
8657 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
8660 SetLastError(0xdeadbeef);
8661 hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
8662 ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
8663 ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
8664 GetLastError() == 0xdeadbeef, /* Win9x */
8665 "unexpected error %d\n", GetLastError());
8667 SetLastError(0xdeadbeef);
8668 ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
8669 ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
8670 GetLastError() == 0xdeadbeef, /* Win9x */
8671 "unexpected error %d\n", GetLastError());
8673 if (!pSetWinEventHook || !pUnhookWinEvent) return;
8675 /* even process local incontext hooks require hmodule */
8676 SetLastError(0xdeadbeef);
8677 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8678 GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
8679 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8680 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8681 GetLastError() == 0xdeadbeef, /* Win9x */
8682 "unexpected error %d\n", GetLastError());
8684 /* even thread local incontext hooks require hmodule */
8685 SetLastError(0xdeadbeef);
8686 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8687 GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
8688 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8689 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8690 GetLastError() == 0xdeadbeef, /* Win9x */
8691 "unexpected error %d\n", GetLastError());
8693 if (0)
8695 /* these 3 tests don't pass under Win9x */
8696 SetLastError(0xdeadbeef);
8697 hwinevent_hook = pSetWinEventHook(1, 0, 0, win_event_proc,
8698 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8699 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8700 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8702 SetLastError(0xdeadbeef);
8703 hwinevent_hook = pSetWinEventHook(-1, 1, 0, win_event_proc,
8704 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8705 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8706 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8708 SetLastError(0xdeadbeef);
8709 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8710 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
8711 ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
8712 ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
8715 SetLastError(0xdeadbeef);
8716 hwinevent_hook = pSetWinEventHook(0, 0, 0, win_event_proc,
8717 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8718 ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8719 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8720 ret = pUnhookWinEvent(hwinevent_hook);
8721 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8723 todo_wine {
8724 /* This call succeeds under win2k SP4, but fails under Wine.
8725 Does win2k test/use passed process id? */
8726 SetLastError(0xdeadbeef);
8727 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8728 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
8729 ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8730 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8731 ret = pUnhookWinEvent(hwinevent_hook);
8732 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8735 SetLastError(0xdeadbeef);
8736 ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
8737 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
8738 GetLastError() == 0xdeadbeef, /* Win9x */
8739 "unexpected error %d\n", GetLastError());
8742 static const struct message ScrollWindowPaint1[] = {
8743 { WM_PAINT, sent },
8744 { WM_ERASEBKGND, sent|beginpaint },
8745 { WM_GETTEXTLENGTH, sent|optional },
8746 { WM_PAINT, sent|optional },
8747 { WM_NCPAINT, sent|beginpaint|optional },
8748 { WM_GETTEXT, sent|beginpaint|optional },
8749 { WM_GETTEXT, sent|beginpaint|optional },
8750 { WM_GETTEXT, sent|beginpaint|optional },
8751 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
8752 { WM_ERASEBKGND, sent|beginpaint|optional },
8753 { 0 }
8756 static const struct message ScrollWindowPaint2[] = {
8757 { WM_PAINT, sent },
8758 { 0 }
8761 static void test_scrollwindowex(void)
8763 HWND hwnd, hchild;
8764 RECT rect={0,0,130,130};
8766 hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
8767 WS_VISIBLE|WS_OVERLAPPEDWINDOW,
8768 100, 100, 200, 200, 0, 0, 0, NULL);
8769 ok (hwnd != 0, "Failed to create overlapped window\n");
8770 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
8771 WS_VISIBLE|WS_CAPTION|WS_CHILD,
8772 10, 10, 150, 150, hwnd, 0, 0, NULL);
8773 ok (hchild != 0, "Failed to create child\n");
8774 UpdateWindow(hwnd);
8775 flush_events();
8776 flush_sequence();
8778 /* scroll without the child window */
8779 trace("start scroll\n");
8780 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8781 SW_ERASE|SW_INVALIDATE);
8782 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8783 trace("end scroll\n");
8784 flush_sequence();
8785 flush_events();
8786 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8787 flush_events();
8788 flush_sequence();
8790 /* Now without the SW_ERASE flag */
8791 trace("start scroll\n");
8792 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
8793 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8794 trace("end scroll\n");
8795 flush_sequence();
8796 flush_events();
8797 ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
8798 flush_events();
8799 flush_sequence();
8801 /* now scroll the child window as well */
8802 trace("start scroll\n");
8803 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8804 SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
8805 /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
8806 /* windows sometimes a WM_MOVE */
8807 ok_sequence(WmEmptySeq, "ScrollWindowEx", TRUE);
8808 trace("end scroll\n");
8809 flush_sequence();
8810 flush_events();
8811 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8812 flush_events();
8813 flush_sequence();
8815 /* now scroll with ScrollWindow() */
8816 trace("start scroll with ScrollWindow\n");
8817 ScrollWindow( hwnd, 5, 5, NULL, NULL);
8818 trace("end scroll\n");
8819 flush_sequence();
8820 flush_events();
8821 ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
8823 ok(DestroyWindow(hchild), "failed to destroy window\n");
8824 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8825 flush_sequence();
8828 static const struct message destroy_window_with_children[] = {
8829 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8830 { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
8831 { 0x0090, sent|optional },
8832 { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
8833 { 0x0090, sent|optional },
8834 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8835 { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8836 { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8837 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8838 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
8839 { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8840 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8841 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8842 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8843 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8844 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8845 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8846 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8847 { 0 }
8850 static void test_DestroyWindow(void)
8852 BOOL ret;
8853 HWND parent, child1, child2, child3, child4, test;
8854 UINT_PTR child_id = WND_CHILD_ID + 1;
8856 parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8857 100, 100, 200, 200, 0, 0, 0, NULL);
8858 assert(parent != 0);
8859 child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8860 0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
8861 assert(child1 != 0);
8862 child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8863 0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
8864 assert(child2 != 0);
8865 child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8866 0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
8867 assert(child3 != 0);
8868 child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
8869 0, 0, 50, 50, parent, 0, 0, NULL);
8870 assert(child4 != 0);
8872 /* test owner/parent of child2 */
8873 test = GetParent(child2);
8874 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8875 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8876 if(pGetAncestor) {
8877 test = pGetAncestor(child2, GA_PARENT);
8878 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8880 test = GetWindow(child2, GW_OWNER);
8881 ok(!test, "wrong owner %p\n", test);
8883 test = SetParent(child2, parent);
8884 ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
8886 /* test owner/parent of the parent */
8887 test = GetParent(parent);
8888 ok(!test, "wrong parent %p\n", test);
8889 ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
8890 if(pGetAncestor) {
8891 test = pGetAncestor(parent, GA_PARENT);
8892 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8894 test = GetWindow(parent, GW_OWNER);
8895 ok(!test, "wrong owner %p\n", test);
8897 /* test owner/parent of child1 */
8898 test = GetParent(child1);
8899 ok(test == parent, "wrong parent %p\n", test);
8900 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
8901 if(pGetAncestor) {
8902 test = pGetAncestor(child1, GA_PARENT);
8903 ok(test == parent, "wrong parent %p\n", test);
8905 test = GetWindow(child1, GW_OWNER);
8906 ok(!test, "wrong owner %p\n", test);
8908 /* test owner/parent of child2 */
8909 test = GetParent(child2);
8910 ok(test == parent, "wrong parent %p\n", test);
8911 ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8912 if(pGetAncestor) {
8913 test = pGetAncestor(child2, GA_PARENT);
8914 ok(test == parent, "wrong parent %p\n", test);
8916 test = GetWindow(child2, GW_OWNER);
8917 ok(!test, "wrong owner %p\n", test);
8919 /* test owner/parent of child3 */
8920 test = GetParent(child3);
8921 ok(test == child1, "wrong parent %p\n", test);
8922 ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
8923 if(pGetAncestor) {
8924 test = pGetAncestor(child3, GA_PARENT);
8925 ok(test == child1, "wrong parent %p\n", test);
8927 test = GetWindow(child3, GW_OWNER);
8928 ok(!test, "wrong owner %p\n", test);
8930 /* test owner/parent of child4 */
8931 test = GetParent(child4);
8932 ok(test == parent, "wrong parent %p\n", test);
8933 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
8934 if(pGetAncestor) {
8935 test = pGetAncestor(child4, GA_PARENT);
8936 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8938 test = GetWindow(child4, GW_OWNER);
8939 ok(test == parent, "wrong owner %p\n", test);
8941 flush_sequence();
8943 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
8944 parent, child1, child2, child3, child4);
8946 SetCapture(child4);
8947 test = GetCapture();
8948 ok(test == child4, "wrong capture window %p\n", test);
8950 test_DestroyWindow_flag = TRUE;
8951 ret = DestroyWindow(parent);
8952 ok( ret, "DestroyWindow() error %d\n", GetLastError());
8953 test_DestroyWindow_flag = FALSE;
8954 ok_sequence(destroy_window_with_children, "destroy window with children", 0);
8956 ok(!IsWindow(parent), "parent still exists\n");
8957 ok(!IsWindow(child1), "child1 still exists\n");
8958 ok(!IsWindow(child2), "child2 still exists\n");
8959 ok(!IsWindow(child3), "child3 still exists\n");
8960 ok(!IsWindow(child4), "child4 still exists\n");
8962 test = GetCapture();
8963 ok(!test, "wrong capture window %p\n", test);
8967 static const struct message WmDispatchPaint[] = {
8968 { WM_NCPAINT, sent },
8969 { WM_GETTEXT, sent|defwinproc|optional },
8970 { WM_GETTEXT, sent|defwinproc|optional },
8971 { WM_ERASEBKGND, sent },
8972 { 0 }
8975 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8977 if (message == WM_PAINT) return 0;
8978 return MsgCheckProcA( hwnd, message, wParam, lParam );
8981 static void test_DispatchMessage(void)
8983 RECT rect;
8984 MSG msg;
8985 int count;
8986 HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8987 100, 100, 200, 200, 0, 0, 0, NULL);
8988 ShowWindow( hwnd, SW_SHOW );
8989 UpdateWindow( hwnd );
8990 flush_events();
8991 flush_sequence();
8992 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
8994 SetRect( &rect, -5, -5, 5, 5 );
8995 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8996 count = 0;
8997 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8999 if (msg.message != WM_PAINT) DispatchMessage( &msg );
9000 else
9002 flush_sequence();
9003 DispatchMessage( &msg );
9004 /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
9005 if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
9006 else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
9007 if (++count > 10) break;
9010 ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
9012 trace("now without DispatchMessage\n");
9013 flush_sequence();
9014 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
9015 count = 0;
9016 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
9018 if (msg.message != WM_PAINT) DispatchMessage( &msg );
9019 else
9021 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
9022 flush_sequence();
9023 /* this will send WM_NCCPAINT just like DispatchMessage does */
9024 GetUpdateRgn( hwnd, hrgn, TRUE );
9025 ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
9026 DeleteObject( hrgn );
9027 GetClientRect( hwnd, &rect );
9028 ValidateRect( hwnd, &rect ); /* this will stop WM_PAINTs */
9029 ok( !count, "Got multiple WM_PAINTs\n" );
9030 if (++count > 10) break;
9033 DestroyWindow(hwnd);
9037 static const struct message WmUser[] = {
9038 { WM_USER, sent },
9039 { 0 }
9042 struct sendmsg_info
9044 HWND hwnd;
9045 DWORD timeout;
9046 DWORD ret;
9049 static DWORD CALLBACK send_msg_thread( LPVOID arg )
9051 struct sendmsg_info *info = arg;
9052 SetLastError( 0xdeadbeef );
9053 info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
9054 if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT ||
9055 broken(GetLastError() == 0), /* win9x */
9056 "unexpected error %d\n", GetLastError());
9057 return 0;
9060 static void wait_for_thread( HANDLE thread )
9062 while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
9064 MSG msg;
9065 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
9069 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9071 if (message == WM_USER) Sleep(200);
9072 return MsgCheckProcA( hwnd, message, wParam, lParam );
9075 static void test_SendMessageTimeout(void)
9077 HANDLE thread;
9078 struct sendmsg_info info;
9079 DWORD tid;
9080 BOOL is_win9x;
9082 info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9083 100, 100, 200, 200, 0, 0, 0, NULL);
9084 flush_events();
9085 flush_sequence();
9087 info.timeout = 1000;
9088 info.ret = 0xdeadbeef;
9089 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9090 wait_for_thread( thread );
9091 CloseHandle( thread );
9092 ok( info.ret == 1, "SendMessageTimeout failed\n" );
9093 ok_sequence( WmUser, "WmUser", FALSE );
9095 info.timeout = 1;
9096 info.ret = 0xdeadbeef;
9097 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9098 Sleep(100); /* SendMessageTimeout should time out here */
9099 wait_for_thread( thread );
9100 CloseHandle( thread );
9101 ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
9102 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9104 /* 0 means infinite timeout (but not on win9x) */
9105 info.timeout = 0;
9106 info.ret = 0xdeadbeef;
9107 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9108 Sleep(100);
9109 wait_for_thread( thread );
9110 CloseHandle( thread );
9111 is_win9x = !info.ret;
9112 if (is_win9x) ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9113 else ok_sequence( WmUser, "WmUser", FALSE );
9115 /* timeout is treated as signed despite the prototype (but not on win9x) */
9116 info.timeout = 0x7fffffff;
9117 info.ret = 0xdeadbeef;
9118 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9119 Sleep(100);
9120 wait_for_thread( thread );
9121 CloseHandle( thread );
9122 ok( info.ret == 1, "SendMessageTimeout failed\n" );
9123 ok_sequence( WmUser, "WmUser", FALSE );
9125 info.timeout = 0x80000000;
9126 info.ret = 0xdeadbeef;
9127 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9128 Sleep(100);
9129 wait_for_thread( thread );
9130 CloseHandle( thread );
9131 if (is_win9x)
9133 ok( info.ret == 1, "SendMessageTimeout failed\n" );
9134 ok_sequence( WmUser, "WmUser", FALSE );
9136 else
9138 ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
9139 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9142 /* now check for timeout during message processing */
9143 SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
9144 info.timeout = 100;
9145 info.ret = 0xdeadbeef;
9146 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9147 wait_for_thread( thread );
9148 CloseHandle( thread );
9149 /* we should time out but still get the message */
9150 ok( info.ret == 0, "SendMessageTimeout failed\n" );
9151 ok_sequence( WmUser, "WmUser", FALSE );
9153 DestroyWindow( info.hwnd );
9157 /****************** edit message test *************************/
9158 #define ID_EDIT 0x1234
9159 static const struct message sl_edit_setfocus[] =
9161 { HCBT_SETFOCUS, hook },
9162 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9163 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9164 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9165 { WM_SETFOCUS, sent|wparam, 0 },
9166 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9167 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
9168 { WM_CTLCOLOREDIT, sent|parent },
9169 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9170 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9171 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9172 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9173 { 0 }
9175 static const struct message ml_edit_setfocus[] =
9177 { HCBT_SETFOCUS, hook },
9178 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9179 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9180 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9181 { WM_SETFOCUS, sent|wparam, 0 },
9182 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9183 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9184 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9185 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9186 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9187 { 0 }
9189 static const struct message sl_edit_killfocus[] =
9191 { HCBT_SETFOCUS, hook },
9192 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9193 { WM_KILLFOCUS, sent|wparam, 0 },
9194 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9195 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9196 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
9197 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
9198 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
9199 { 0 }
9201 static const struct message sl_edit_lbutton_dblclk[] =
9203 { WM_LBUTTONDBLCLK, sent },
9204 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9205 { 0 }
9207 static const struct message sl_edit_lbutton_down[] =
9209 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
9210 { HCBT_SETFOCUS, hook },
9211 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9212 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9213 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9214 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9215 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9216 { WM_CTLCOLOREDIT, sent|parent },
9217 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9218 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9219 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9220 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9221 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9222 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9223 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9224 { WM_CTLCOLOREDIT, sent|parent|optional },
9225 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9226 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9227 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9228 { 0 }
9230 static const struct message ml_edit_lbutton_down[] =
9232 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
9233 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9234 { HCBT_SETFOCUS, hook },
9235 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9236 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9237 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9238 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9239 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9240 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9241 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9242 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9243 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9244 { 0 }
9246 static const struct message sl_edit_lbutton_up[] =
9248 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9249 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9250 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9251 { WM_CAPTURECHANGED, sent|defwinproc },
9252 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9253 { 0 }
9255 static const struct message ml_edit_lbutton_up[] =
9257 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9258 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9259 { WM_CAPTURECHANGED, sent|defwinproc },
9260 { 0 }
9263 static WNDPROC old_edit_proc;
9265 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9267 static LONG defwndproc_counter = 0;
9268 LRESULT ret;
9269 struct recvd_message msg;
9271 if (ignore_message( message )) return 0;
9273 msg.hwnd = hwnd;
9274 msg.message = message;
9275 msg.flags = sent|wparam|lparam;
9276 if (defwndproc_counter) msg.flags |= defwinproc;
9277 msg.wParam = wParam;
9278 msg.lParam = lParam;
9279 msg.descr = "edit";
9280 add_message(&msg);
9282 defwndproc_counter++;
9283 ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
9284 defwndproc_counter--;
9286 return ret;
9289 static void subclass_edit(void)
9291 WNDCLASSA cls;
9293 if (!GetClassInfoA(0, "edit", &cls)) assert(0);
9295 old_edit_proc = cls.lpfnWndProc;
9297 cls.hInstance = GetModuleHandle(0);
9298 cls.lpfnWndProc = edit_hook_proc;
9299 cls.lpszClassName = "my_edit_class";
9300 UnregisterClass(cls.lpszClassName, cls.hInstance);
9301 if (!RegisterClassA(&cls)) assert(0);
9304 static void test_edit_messages(void)
9306 HWND hwnd, parent;
9307 DWORD dlg_code;
9309 subclass_edit();
9310 log_all_parent_messages++;
9312 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9313 100, 100, 200, 200, 0, 0, 0, NULL);
9314 ok (parent != 0, "Failed to create parent window\n");
9316 /* test single line edit */
9317 hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
9318 0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9319 ok(hwnd != 0, "Failed to create edit window\n");
9321 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9322 ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
9324 ShowWindow(hwnd, SW_SHOW);
9325 UpdateWindow(hwnd);
9326 SetFocus(0);
9327 flush_sequence();
9329 SetFocus(hwnd);
9330 ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
9332 SetFocus(0);
9333 ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
9335 SetFocus(0);
9336 ReleaseCapture();
9337 flush_sequence();
9339 SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9340 ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
9342 SetFocus(0);
9343 ReleaseCapture();
9344 flush_sequence();
9346 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9347 ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
9349 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9350 ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
9352 DestroyWindow(hwnd);
9354 /* test multiline edit */
9355 hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
9356 0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9357 ok(hwnd != 0, "Failed to create edit window\n");
9359 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9360 ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
9361 "wrong dlg_code %08x\n", dlg_code);
9363 ShowWindow(hwnd, SW_SHOW);
9364 UpdateWindow(hwnd);
9365 SetFocus(0);
9366 flush_sequence();
9368 SetFocus(hwnd);
9369 ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
9371 SetFocus(0);
9372 ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
9374 SetFocus(0);
9375 ReleaseCapture();
9376 flush_sequence();
9378 SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9379 ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
9381 SetFocus(0);
9382 ReleaseCapture();
9383 flush_sequence();
9385 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9386 ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
9388 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9389 ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
9391 DestroyWindow(hwnd);
9392 DestroyWindow(parent);
9394 log_all_parent_messages--;
9397 /**************************** End of Edit test ******************************/
9399 static const struct message WmKeyDownSkippedSeq[] =
9401 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
9402 { 0 }
9404 static const struct message WmKeyDownWasDownSkippedSeq[] =
9406 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x40000001 }, /* XP */
9407 { 0 }
9409 static const struct message WmKeyUpSkippedSeq[] =
9411 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9412 { 0 }
9414 static const struct message WmUserKeyUpSkippedSeq[] =
9416 { WM_USER, sent },
9417 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9418 { 0 }
9421 #define EV_STOP 0
9422 #define EV_SENDMSG 1
9423 #define EV_ACK 2
9425 struct peekmsg_info
9427 HWND hwnd;
9428 HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
9431 static DWORD CALLBACK send_msg_thread_2(void *param)
9433 DWORD ret;
9434 struct peekmsg_info *info = param;
9436 trace("thread: looping\n");
9437 SetEvent(info->hevent[EV_ACK]);
9439 while (1)
9441 ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
9443 switch (ret)
9445 case WAIT_OBJECT_0 + EV_STOP:
9446 trace("thread: exiting\n");
9447 return 0;
9449 case WAIT_OBJECT_0 + EV_SENDMSG:
9450 trace("thread: sending message\n");
9451 ok( SendNotifyMessageA(info->hwnd, WM_USER, 0, 0),
9452 "SendNotifyMessageA failed error %u\n", GetLastError());
9453 SetEvent(info->hevent[EV_ACK]);
9454 break;
9456 default:
9457 trace("unexpected return: %04x\n", ret);
9458 assert(0);
9459 break;
9462 return 0;
9465 static void test_PeekMessage(void)
9467 MSG msg;
9468 HANDLE hthread;
9469 DWORD tid, qstatus;
9470 UINT qs_all_input = QS_ALLINPUT;
9471 UINT qs_input = QS_INPUT;
9472 BOOL ret;
9473 struct peekmsg_info info;
9475 info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9476 100, 100, 200, 200, 0, 0, 0, NULL);
9477 assert(info.hwnd);
9478 ShowWindow(info.hwnd, SW_SHOW);
9479 UpdateWindow(info.hwnd);
9480 SetFocus(info.hwnd);
9482 info.hevent[EV_STOP] = CreateEventA(NULL, 0, 0, NULL);
9483 info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
9484 info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
9486 hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
9487 WaitForSingleObject(info.hevent[EV_ACK], 10000);
9489 flush_events();
9490 flush_sequence();
9492 SetLastError(0xdeadbeef);
9493 qstatus = GetQueueStatus(qs_all_input);
9494 if (GetLastError() == ERROR_INVALID_FLAGS)
9496 trace("QS_RAWINPUT not supported on this platform\n");
9497 qs_all_input &= ~QS_RAWINPUT;
9498 qs_input &= ~QS_RAWINPUT;
9500 if (qstatus & QS_POSTMESSAGE)
9502 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) /* nothing */ ;
9503 qstatus = GetQueueStatus(qs_all_input);
9505 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9507 trace("signalling to send message\n");
9508 SetEvent(info.hevent[EV_SENDMSG]);
9509 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9511 /* pass invalid QS_xxxx flags */
9512 SetLastError(0xdeadbeef);
9513 qstatus = GetQueueStatus(0xffffffff);
9514 ok(qstatus == 0 || broken(qstatus) /* win9x */, "GetQueueStatus should fail: %08x\n", qstatus);
9515 if (!qstatus)
9517 ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
9518 qstatus = GetQueueStatus(qs_all_input);
9520 qstatus &= ~MAKELONG( 0x4000, 0x4000 ); /* sometimes set on Win95 */
9521 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
9522 "wrong qstatus %08x\n", qstatus);
9524 msg.message = 0;
9525 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9526 ok(!ret,
9527 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9528 msg.message);
9529 ok_sequence(WmUser, "WmUser", FALSE);
9531 qstatus = GetQueueStatus(qs_all_input);
9532 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9534 keybd_event('N', 0, 0, 0);
9535 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9536 qstatus = GetQueueStatus(qs_all_input);
9537 if (!(qstatus & MAKELONG(QS_KEY, QS_KEY)))
9539 skip( "queuing key events not supported\n" );
9540 goto done;
9542 ok(qstatus == MAKELONG(QS_KEY, QS_KEY) ||
9543 /* keybd_event seems to trigger a sent message on NT4 */
9544 qstatus == MAKELONG(QS_KEY|QS_SENDMESSAGE, QS_KEY|QS_SENDMESSAGE),
9545 "wrong qstatus %08x\n", qstatus);
9547 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9548 qstatus = GetQueueStatus(qs_all_input);
9549 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY) ||
9550 qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY|QS_SENDMESSAGE),
9551 "wrong qstatus %08x\n", qstatus);
9553 InvalidateRect(info.hwnd, NULL, FALSE);
9554 qstatus = GetQueueStatus(qs_all_input);
9555 ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY) ||
9556 qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY|QS_SENDMESSAGE),
9557 "wrong qstatus %08x\n", qstatus);
9559 trace("signalling to send message\n");
9560 SetEvent(info.hevent[EV_SENDMSG]);
9561 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9563 qstatus = GetQueueStatus(qs_all_input);
9564 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9565 "wrong qstatus %08x\n", qstatus);
9567 msg.message = 0;
9568 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
9569 if (ret && msg.message == WM_CHAR)
9571 win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9572 goto done;
9574 ok(!ret,
9575 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9576 msg.message);
9577 if (!sequence_cnt) /* nt4 doesn't fetch anything with PM_QS_* flags */
9579 win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9580 goto done;
9582 ok_sequence(WmUser, "WmUser", FALSE);
9584 qstatus = GetQueueStatus(qs_all_input);
9585 ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9586 "wrong qstatus %08x\n", qstatus);
9588 trace("signalling to send message\n");
9589 SetEvent(info.hevent[EV_SENDMSG]);
9590 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9592 qstatus = GetQueueStatus(qs_all_input);
9593 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9594 "wrong qstatus %08x\n", qstatus);
9596 msg.message = 0;
9597 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE );
9598 ok(!ret,
9599 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9600 msg.message);
9601 ok_sequence(WmUser, "WmUser", FALSE);
9603 qstatus = GetQueueStatus(qs_all_input);
9604 ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9605 "wrong qstatus %08x\n", qstatus);
9607 msg.message = 0;
9608 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9609 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9610 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9611 ret, msg.message, msg.wParam);
9612 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9614 qstatus = GetQueueStatus(qs_all_input);
9615 ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9616 "wrong qstatus %08x\n", qstatus);
9618 msg.message = 0;
9619 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9620 ok(!ret,
9621 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9622 msg.message);
9623 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9625 qstatus = GetQueueStatus(qs_all_input);
9626 ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9627 "wrong qstatus %08x\n", qstatus);
9629 msg.message = 0;
9630 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9631 ok(ret && msg.message == WM_PAINT,
9632 "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
9633 DispatchMessageA(&msg);
9634 ok_sequence(WmPaint, "WmPaint", FALSE);
9636 qstatus = GetQueueStatus(qs_all_input);
9637 ok(qstatus == MAKELONG(0, QS_KEY),
9638 "wrong qstatus %08x\n", qstatus);
9640 msg.message = 0;
9641 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9642 ok(!ret,
9643 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9644 msg.message);
9645 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9647 qstatus = GetQueueStatus(qs_all_input);
9648 ok(qstatus == MAKELONG(0, QS_KEY),
9649 "wrong qstatus %08x\n", qstatus);
9651 trace("signalling to send message\n");
9652 SetEvent(info.hevent[EV_SENDMSG]);
9653 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9655 qstatus = GetQueueStatus(qs_all_input);
9656 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
9657 "wrong qstatus %08x\n", qstatus);
9659 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9661 qstatus = GetQueueStatus(qs_all_input);
9662 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9663 "wrong qstatus %08x\n", qstatus);
9665 msg.message = 0;
9666 ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9667 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9668 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9669 ret, msg.message, msg.wParam);
9670 ok_sequence(WmUser, "WmUser", FALSE);
9672 qstatus = GetQueueStatus(qs_all_input);
9673 ok(qstatus == MAKELONG(0, QS_KEY),
9674 "wrong qstatus %08x\n", qstatus);
9676 msg.message = 0;
9677 ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9678 ok(!ret,
9679 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9680 msg.message);
9681 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9683 qstatus = GetQueueStatus(qs_all_input);
9684 ok(qstatus == MAKELONG(0, QS_KEY),
9685 "wrong qstatus %08x\n", qstatus);
9687 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9689 qstatus = GetQueueStatus(qs_all_input);
9690 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9691 "wrong qstatus %08x\n", qstatus);
9693 trace("signalling to send message\n");
9694 SetEvent(info.hevent[EV_SENDMSG]);
9695 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9697 qstatus = GetQueueStatus(qs_all_input);
9698 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9699 "wrong qstatus %08x\n", qstatus);
9701 msg.message = 0;
9702 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
9703 ok(!ret,
9704 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9705 msg.message);
9706 ok_sequence(WmUser, "WmUser", FALSE);
9708 qstatus = GetQueueStatus(qs_all_input);
9709 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9710 "wrong qstatus %08x\n", qstatus);
9712 msg.message = 0;
9713 if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9714 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9715 else /* workaround for a missing QS_RAWINPUT support */
9716 ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
9717 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9718 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9719 ret, msg.message, msg.wParam);
9720 ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9722 qstatus = GetQueueStatus(qs_all_input);
9723 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9724 "wrong qstatus %08x\n", qstatus);
9726 msg.message = 0;
9727 if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9728 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9729 else /* workaround for a missing QS_RAWINPUT support */
9730 ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
9731 ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9732 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
9733 ret, msg.message, msg.wParam);
9734 ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
9736 qstatus = GetQueueStatus(qs_all_input);
9737 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9738 "wrong qstatus %08x\n", qstatus);
9740 msg.message = 0;
9741 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
9742 ok(!ret,
9743 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9744 msg.message);
9745 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9747 qstatus = GetQueueStatus(qs_all_input);
9748 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9749 "wrong qstatus %08x\n", qstatus);
9751 msg.message = 0;
9752 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9753 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9754 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9755 ret, msg.message, msg.wParam);
9756 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9758 qstatus = GetQueueStatus(qs_all_input);
9759 ok(qstatus == 0,
9760 "wrong qstatus %08x\n", qstatus);
9762 msg.message = 0;
9763 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9764 ok(!ret,
9765 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9766 msg.message);
9767 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9769 qstatus = GetQueueStatus(qs_all_input);
9770 ok(qstatus == 0,
9771 "wrong qstatus %08x\n", qstatus);
9773 /* test whether presence of the quit flag in the queue affects
9774 * the queue state
9776 PostQuitMessage(0x1234abcd);
9778 qstatus = GetQueueStatus(qs_all_input);
9779 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9780 "wrong qstatus %08x\n", qstatus);
9782 PostMessageA(info.hwnd, WM_USER, 0, 0);
9784 qstatus = GetQueueStatus(qs_all_input);
9785 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9786 "wrong qstatus %08x\n", qstatus);
9788 msg.message = 0;
9789 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9790 ok(ret && msg.message == WM_USER,
9791 "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
9792 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9794 qstatus = GetQueueStatus(qs_all_input);
9795 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9796 "wrong qstatus %08x\n", qstatus);
9798 msg.message = 0;
9799 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9800 ok(ret && msg.message == WM_QUIT,
9801 "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
9802 ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
9803 ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
9804 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9806 qstatus = GetQueueStatus(qs_all_input);
9807 todo_wine {
9808 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9809 "wrong qstatus %08x\n", qstatus);
9812 msg.message = 0;
9813 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9814 ok(!ret,
9815 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9816 msg.message);
9817 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9819 qstatus = GetQueueStatus(qs_all_input);
9820 ok(qstatus == 0,
9821 "wrong qstatus %08x\n", qstatus);
9823 /* some GetMessage tests */
9825 keybd_event('N', 0, 0, 0);
9826 qstatus = GetQueueStatus(qs_all_input);
9827 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9829 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9830 qstatus = GetQueueStatus(qs_all_input);
9831 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9833 if (qstatus)
9835 ret = GetMessageA( &msg, 0, 0, 0 );
9836 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9837 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9838 ret, msg.message, msg.wParam);
9839 qstatus = GetQueueStatus(qs_all_input);
9840 ok(qstatus == MAKELONG(0, QS_KEY), "wrong qstatus %08x\n", qstatus);
9843 if (qstatus)
9845 ret = GetMessageA( &msg, 0, 0, 0 );
9846 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9847 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9848 ret, msg.message, msg.wParam);
9849 ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9850 qstatus = GetQueueStatus(qs_all_input);
9851 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9854 keybd_event('N', 0, 0, 0);
9855 qstatus = GetQueueStatus(qs_all_input);
9856 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9858 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9859 qstatus = GetQueueStatus(qs_all_input);
9860 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9862 if (qstatus & (QS_KEY << 16))
9864 ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9865 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9866 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9867 ret, msg.message, msg.wParam);
9868 ok_sequence(WmKeyDownWasDownSkippedSeq, "WmKeyDownWasDownSkippedSeq", FALSE);
9869 qstatus = GetQueueStatus(qs_all_input);
9870 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9873 if (qstatus)
9875 ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9876 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9877 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9878 ret, msg.message, msg.wParam);
9879 qstatus = GetQueueStatus(qs_all_input);
9880 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9883 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9884 qstatus = GetQueueStatus(qs_all_input);
9885 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9887 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9888 qstatus = GetQueueStatus(qs_all_input);
9889 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9891 trace("signalling to send message\n");
9892 SetEvent(info.hevent[EV_SENDMSG]);
9893 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9894 qstatus = GetQueueStatus(qs_all_input);
9895 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9896 "wrong qstatus %08x\n", qstatus);
9898 if (qstatus & (QS_KEY << 16))
9900 ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9901 ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9902 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9903 ret, msg.message, msg.wParam);
9904 ok_sequence(WmUserKeyUpSkippedSeq, "WmUserKeyUpSkippedSeq", FALSE);
9905 qstatus = GetQueueStatus(qs_all_input);
9906 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9909 if (qstatus)
9911 ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9912 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9913 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9914 ret, msg.message, msg.wParam);
9915 qstatus = GetQueueStatus(qs_all_input);
9916 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9918 done:
9919 trace("signalling to exit\n");
9920 SetEvent(info.hevent[EV_STOP]);
9922 WaitForSingleObject(hthread, INFINITE);
9924 CloseHandle(hthread);
9925 CloseHandle(info.hevent[0]);
9926 CloseHandle(info.hevent[1]);
9927 CloseHandle(info.hevent[2]);
9929 DestroyWindow(info.hwnd);
9932 static void wait_move_event(HWND hwnd, int x, int y)
9934 MSG msg;
9935 DWORD time;
9936 BOOL ret;
9937 int go = 0;
9939 time = GetTickCount();
9940 while (GetTickCount() - time < 200 && !go) {
9941 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9942 go = ret && msg.pt.x > x && msg.pt.y > y;
9943 if (!ret) MsgWaitForMultipleObjects( 0, NULL, FALSE, GetTickCount() - time, QS_ALLINPUT );
9947 #define STEP 5
9948 static void test_PeekMessage2(void)
9950 HWND hwnd;
9951 BOOL ret;
9952 MSG msg;
9953 UINT message;
9954 DWORD time1, time2, time3;
9955 int x1, y1, x2, y2, x3, y3;
9956 POINT pos;
9958 time1 = time2 = time3 = 0;
9959 x1 = y1 = x2 = y2 = x3 = y3 = 0;
9961 /* Initialise window and make sure it is ready for events */
9962 hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
9963 10, 10, 800, 800, NULL, NULL, NULL, NULL);
9964 assert(hwnd);
9965 trace("Window for test_PeekMessage2 %p\n", hwnd);
9966 ShowWindow(hwnd, SW_SHOW);
9967 UpdateWindow(hwnd);
9968 SetFocus(hwnd);
9969 GetCursorPos(&pos);
9970 SetCursorPos(100, 100);
9971 mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
9972 flush_events();
9974 /* Do initial mousemove, wait until we can see it
9975 and then do our test peek with PM_NOREMOVE. */
9976 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9977 wait_move_event(hwnd, 100-STEP, 100-STEP);
9979 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9980 if (!ret)
9982 skip( "queuing mouse events not supported\n" );
9983 goto done;
9985 else
9987 trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9988 message = msg.message;
9989 time1 = msg.time;
9990 x1 = msg.pt.x;
9991 y1 = msg.pt.y;
9992 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9995 /* Allow time to advance a bit, and then simulate the user moving their
9996 * mouse around. After that we peek again with PM_NOREMOVE.
9997 * Although the previous mousemove message was never removed, the
9998 * mousemove we now peek should reflect the recent mouse movements
9999 * because the input queue will merge the move events. */
10000 Sleep(100);
10001 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
10002 wait_move_event(hwnd, x1, y1);
10004 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
10005 ok(ret, "no message available\n");
10006 if (ret) {
10007 trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
10008 message = msg.message;
10009 time2 = msg.time;
10010 x2 = msg.pt.x;
10011 y2 = msg.pt.y;
10012 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
10013 ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
10014 ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
10017 /* Have another go, to drive the point home */
10018 Sleep(100);
10019 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
10020 wait_move_event(hwnd, x2, y2);
10022 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
10023 ok(ret, "no message available\n");
10024 if (ret) {
10025 trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
10026 message = msg.message;
10027 time3 = msg.time;
10028 x3 = msg.pt.x;
10029 y3 = msg.pt.y;
10030 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
10031 ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
10032 ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
10035 done:
10036 DestroyWindow(hwnd);
10037 SetCursorPos(pos.x, pos.y);
10038 flush_events();
10041 static INT_PTR CALLBACK wm_quit_dlg_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
10043 struct recvd_message msg;
10045 if (ignore_message( message )) return 0;
10047 msg.hwnd = hwnd;
10048 msg.message = message;
10049 msg.flags = sent|wparam|lparam;
10050 msg.wParam = wp;
10051 msg.lParam = lp;
10052 msg.descr = "dialog";
10053 add_message(&msg);
10055 switch (message)
10057 case WM_INITDIALOG:
10058 PostMessage(hwnd, WM_QUIT, 0x1234, 0x5678);
10059 PostMessage(hwnd, WM_USER, 0xdead, 0xbeef);
10060 return 0;
10062 case WM_GETDLGCODE:
10063 return 0;
10065 case WM_USER:
10066 EndDialog(hwnd, 0);
10067 break;
10070 return 1;
10073 static const struct message WmQuitDialogSeq[] = {
10074 { HCBT_CREATEWND, hook },
10075 { WM_SETFONT, sent },
10076 { WM_INITDIALOG, sent },
10077 { WM_CHANGEUISTATE, sent|optional },
10078 { HCBT_DESTROYWND, hook },
10079 { 0x0090, sent|optional }, /* Vista */
10080 { WM_DESTROY, sent },
10081 { WM_NCDESTROY, sent },
10082 { 0 }
10085 static void test_quit_message(void)
10087 MSG msg;
10088 BOOL ret;
10090 /* test using PostQuitMessage */
10091 flush_events();
10092 PostQuitMessage(0xbeef);
10094 ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
10095 ok(ret, "PeekMessage failed with error %d\n", GetLastError());
10096 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10097 ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
10099 ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
10100 ok(ret, "PostMessage failed with error %d\n", GetLastError());
10102 ret = GetMessage(&msg, NULL, 0, 0);
10103 ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
10104 ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
10106 /* note: WM_QUIT message received after WM_USER message */
10107 ret = GetMessage(&msg, NULL, 0, 0);
10108 ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
10109 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10110 ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
10112 ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
10113 ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
10115 /* now test with PostThreadMessage - different behaviour! */
10116 PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
10118 ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
10119 ok(ret, "PeekMessage failed with error %d\n", GetLastError());
10120 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10121 ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
10123 ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
10124 ok(ret, "PostMessage failed with error %d\n", GetLastError());
10126 /* note: we receive the WM_QUIT message first this time */
10127 ret = GetMessage(&msg, NULL, 0, 0);
10128 ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
10129 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10130 ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
10132 ret = GetMessage(&msg, NULL, 0, 0);
10133 ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
10134 ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
10136 flush_events();
10137 flush_sequence();
10138 ret = DialogBoxParam(GetModuleHandle(0), "TEST_EMPTY_DIALOG", 0, wm_quit_dlg_proc, 0);
10139 ok(ret == 1, "expected 1, got %d\n", ret);
10140 ok_sequence(WmQuitDialogSeq, "WmQuitDialogSeq", FALSE);
10141 memset(&msg, 0xab, sizeof(msg));
10142 ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
10143 ok(ret, "PeekMessage failed\n");
10144 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10145 ok(msg.wParam == 0x1234, "wParam was 0x%lx instead of 0x1234\n", msg.wParam);
10146 ok(msg.lParam == 0, "lParam was 0x%lx instead of 0\n", msg.lParam);
10149 static const struct message WmMouseHoverSeq[] = {
10150 { WM_MOUSEACTIVATE, sent|optional }, /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
10151 { WM_MOUSEACTIVATE, sent|optional },
10152 { WM_TIMER, sent|optional }, /* XP sends it */
10153 { WM_SYSTIMER, sent },
10154 { WM_MOUSEHOVER, sent|wparam, 0 },
10155 { 0 }
10158 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
10160 MSG msg;
10161 DWORD start_ticks, end_ticks;
10163 start_ticks = GetTickCount();
10164 /* add some deviation (50%) to cover not expected delays */
10165 start_ticks += timeout / 2;
10169 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
10171 /* Timer proc messages are not dispatched to the window proc,
10172 * and therefore not logged.
10174 if ((msg.message == WM_TIMER || msg.message == WM_SYSTIMER) && msg.hwnd)
10176 struct recvd_message s_msg;
10178 s_msg.hwnd = msg.hwnd;
10179 s_msg.message = msg.message;
10180 s_msg.flags = sent|wparam|lparam;
10181 s_msg.wParam = msg.wParam;
10182 s_msg.lParam = msg.lParam;
10183 s_msg.descr = "msg_loop";
10184 add_message(&s_msg);
10186 DispatchMessage(&msg);
10189 end_ticks = GetTickCount();
10191 /* inject WM_MOUSEMOVE to see how it changes tracking */
10192 if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
10194 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
10195 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
10197 inject_mouse_move = FALSE;
10199 } while (start_ticks + timeout >= end_ticks);
10202 static void test_TrackMouseEvent(void)
10204 TRACKMOUSEEVENT tme;
10205 BOOL ret;
10206 HWND hwnd, hchild;
10207 RECT rc_parent, rc_child;
10208 UINT default_hover_time, hover_width = 0, hover_height = 0;
10210 #define track_hover(track_hwnd, track_hover_time) \
10211 tme.cbSize = sizeof(tme); \
10212 tme.dwFlags = TME_HOVER; \
10213 tme.hwndTrack = track_hwnd; \
10214 tme.dwHoverTime = track_hover_time; \
10215 SetLastError(0xdeadbeef); \
10216 ret = pTrackMouseEvent(&tme); \
10217 ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
10219 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
10220 tme.cbSize = sizeof(tme); \
10221 tme.dwFlags = TME_QUERY; \
10222 tme.hwndTrack = (HWND)0xdeadbeef; \
10223 tme.dwHoverTime = 0xdeadbeef; \
10224 SetLastError(0xdeadbeef); \
10225 ret = pTrackMouseEvent(&tme); \
10226 ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
10227 ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
10228 ok(tme.dwFlags == (expected_track_flags), \
10229 "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
10230 ok(tme.hwndTrack == (expected_track_hwnd), \
10231 "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
10232 ok(tme.dwHoverTime == (expected_hover_time), \
10233 "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
10235 #define track_hover_cancel(track_hwnd) \
10236 tme.cbSize = sizeof(tme); \
10237 tme.dwFlags = TME_HOVER | TME_CANCEL; \
10238 tme.hwndTrack = track_hwnd; \
10239 tme.dwHoverTime = 0xdeadbeef; \
10240 SetLastError(0xdeadbeef); \
10241 ret = pTrackMouseEvent(&tme); \
10242 ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
10244 default_hover_time = 0xdeadbeef;
10245 SetLastError(0xdeadbeef);
10246 ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
10247 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
10248 "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
10249 if (!ret) default_hover_time = 400;
10250 trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
10252 SetLastError(0xdeadbeef);
10253 ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
10254 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
10255 "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
10256 if (!ret) hover_width = 4;
10257 SetLastError(0xdeadbeef);
10258 ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
10259 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
10260 "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
10261 if (!ret) hover_height = 4;
10262 trace("hover rect is %u x %d\n", hover_width, hover_height);
10264 hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
10265 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10266 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
10267 NULL, NULL, 0);
10268 assert(hwnd);
10270 hchild = CreateWindowEx(0, "TestWindowClass", NULL,
10271 WS_CHILD | WS_BORDER | WS_VISIBLE,
10272 50, 50, 200, 200, hwnd,
10273 NULL, NULL, 0);
10274 assert(hchild);
10276 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
10277 flush_events();
10278 flush_sequence();
10280 tme.cbSize = 0;
10281 tme.dwFlags = TME_QUERY;
10282 tme.hwndTrack = (HWND)0xdeadbeef;
10283 tme.dwHoverTime = 0xdeadbeef;
10284 SetLastError(0xdeadbeef);
10285 ret = pTrackMouseEvent(&tme);
10286 ok(!ret, "TrackMouseEvent should fail\n");
10287 ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef),
10288 "not expected error %u\n", GetLastError());
10290 tme.cbSize = sizeof(tme);
10291 tme.dwFlags = TME_HOVER;
10292 tme.hwndTrack = (HWND)0xdeadbeef;
10293 tme.dwHoverTime = 0xdeadbeef;
10294 SetLastError(0xdeadbeef);
10295 ret = pTrackMouseEvent(&tme);
10296 ok(!ret, "TrackMouseEvent should fail\n");
10297 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10298 "not expected error %u\n", GetLastError());
10300 tme.cbSize = sizeof(tme);
10301 tme.dwFlags = TME_HOVER | TME_CANCEL;
10302 tme.hwndTrack = (HWND)0xdeadbeef;
10303 tme.dwHoverTime = 0xdeadbeef;
10304 SetLastError(0xdeadbeef);
10305 ret = pTrackMouseEvent(&tme);
10306 ok(!ret, "TrackMouseEvent should fail\n");
10307 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10308 "not expected error %u\n", GetLastError());
10310 GetWindowRect(hwnd, &rc_parent);
10311 GetWindowRect(hchild, &rc_child);
10312 SetCursorPos(rc_child.left - 10, rc_child.top - 10);
10314 /* Process messages so that the system updates its internal current
10315 * window and hittest, otherwise TrackMouseEvent calls don't have any
10316 * effect.
10318 flush_events();
10319 flush_sequence();
10321 track_query(0, NULL, 0);
10322 track_hover(hchild, 0);
10323 track_query(0, NULL, 0);
10325 flush_events();
10326 flush_sequence();
10328 track_hover(hwnd, 0);
10329 tme.cbSize = sizeof(tme);
10330 tme.dwFlags = TME_QUERY;
10331 tme.hwndTrack = (HWND)0xdeadbeef;
10332 tme.dwHoverTime = 0xdeadbeef;
10333 SetLastError(0xdeadbeef);
10334 ret = pTrackMouseEvent(&tme);
10335 ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());
10336 ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize);
10337 if (!tme.dwFlags)
10339 skip( "Cursor not inside window, skipping TrackMouseEvent tests\n" );
10340 DestroyWindow( hwnd );
10341 return;
10343 ok(tme.dwFlags == TME_HOVER, "wrong tme.dwFlags %08x, expected TME_HOVER\n", tme.dwFlags);
10344 ok(tme.hwndTrack == hwnd, "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, hwnd);
10345 ok(tme.dwHoverTime == default_hover_time, "wrong tme.dwHoverTime %u, expected %u\n",
10346 tme.dwHoverTime, default_hover_time);
10348 pump_msg_loop_timeout(default_hover_time, FALSE);
10349 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10351 track_query(0, NULL, 0);
10353 track_hover(hwnd, HOVER_DEFAULT);
10354 track_query(TME_HOVER, hwnd, default_hover_time);
10356 Sleep(default_hover_time / 2);
10357 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
10358 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
10360 track_query(TME_HOVER, hwnd, default_hover_time);
10362 pump_msg_loop_timeout(default_hover_time, FALSE);
10363 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10365 track_query(0, NULL, 0);
10367 track_hover(hwnd, HOVER_DEFAULT);
10368 track_query(TME_HOVER, hwnd, default_hover_time);
10370 pump_msg_loop_timeout(default_hover_time, TRUE);
10371 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10373 track_query(0, NULL, 0);
10375 track_hover(hwnd, HOVER_DEFAULT);
10376 track_query(TME_HOVER, hwnd, default_hover_time);
10377 track_hover_cancel(hwnd);
10379 DestroyWindow(hwnd);
10381 #undef track_hover
10382 #undef track_query
10383 #undef track_hover_cancel
10387 static const struct message WmSetWindowRgn[] = {
10388 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10389 { WM_NCCALCSIZE, sent|wparam, 1 },
10390 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
10391 { WM_GETTEXT, sent|defwinproc|optional },
10392 { WM_ERASEBKGND, sent|optional },
10393 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10394 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10395 { 0 }
10398 static const struct message WmSetWindowRgn_no_redraw[] = {
10399 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10400 { WM_NCCALCSIZE, sent|wparam, 1 },
10401 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10402 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10403 { 0 }
10406 static const struct message WmSetWindowRgn_clear[] = {
10407 { WM_WINDOWPOSCHANGING, sent/*|wparam*/, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE/*|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE only on some Windows versions */ },
10408 { WM_NCCALCSIZE, sent|wparam, 1 },
10409 { WM_NCPAINT, sent|optional },
10410 { WM_GETTEXT, sent|defwinproc|optional },
10411 { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
10412 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10413 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
10414 { WM_NCPAINT, sent|optional },
10415 { WM_GETTEXT, sent|defwinproc|optional },
10416 { WM_ERASEBKGND, sent|optional },
10417 { WM_WINDOWPOSCHANGING, sent|optional },
10418 { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10419 { WM_NCPAINT, sent|optional },
10420 { WM_GETTEXT, sent|defwinproc|optional },
10421 { WM_ERASEBKGND, sent|optional },
10422 { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10423 { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10424 { WM_NCPAINT, sent|optional },
10425 { WM_GETTEXT, sent|defwinproc|optional },
10426 { WM_ERASEBKGND, sent|optional },
10427 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10428 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10429 { 0 }
10432 static void test_SetWindowRgn(void)
10434 HRGN hrgn;
10435 HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10436 100, 100, 200, 200, 0, 0, 0, NULL);
10437 ok( hwnd != 0, "Failed to create overlapped window\n" );
10439 ShowWindow( hwnd, SW_SHOW );
10440 UpdateWindow( hwnd );
10441 flush_events();
10442 flush_sequence();
10444 trace("testing SetWindowRgn\n");
10445 hrgn = CreateRectRgn( 0, 0, 150, 150 );
10446 SetWindowRgn( hwnd, hrgn, TRUE );
10447 ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
10449 hrgn = CreateRectRgn( 30, 30, 160, 160 );
10450 SetWindowRgn( hwnd, hrgn, FALSE );
10451 ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
10453 hrgn = CreateRectRgn( 0, 0, 180, 180 );
10454 SetWindowRgn( hwnd, hrgn, TRUE );
10455 ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
10457 SetWindowRgn( hwnd, 0, TRUE );
10458 ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
10460 DestroyWindow( hwnd );
10463 /*************************** ShowWindow() test ******************************/
10464 static const struct message WmShowNormal[] = {
10465 { WM_SHOWWINDOW, sent|wparam, 1 },
10466 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10467 { HCBT_ACTIVATE, hook },
10468 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10469 { HCBT_SETFOCUS, hook },
10470 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10471 { 0 }
10473 static const struct message WmShow[] = {
10474 { WM_SHOWWINDOW, sent|wparam, 1 },
10475 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10476 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10477 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10478 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10479 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10480 { 0 }
10482 static const struct message WmShowNoActivate_1[] = {
10483 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10484 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10485 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10486 { WM_MOVE, sent|defwinproc|optional },
10487 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10488 { 0 }
10490 static const struct message WmShowNoActivate_2[] = {
10491 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10492 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10493 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10494 { WM_MOVE, sent|defwinproc },
10495 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10496 { HCBT_SETFOCUS, hook|optional },
10497 { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10498 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10499 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10500 { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10501 { 0 }
10503 static const struct message WmShowNA_1[] = {
10504 { WM_SHOWWINDOW, sent|wparam, 1 },
10505 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10506 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10507 { 0 }
10509 static const struct message WmShowNA_2[] = {
10510 { WM_SHOWWINDOW, sent|wparam, 1 },
10511 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10512 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10513 { 0 }
10515 static const struct message WmRestore_1[] = {
10516 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10517 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10518 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10519 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10520 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10521 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10522 { WM_MOVE, sent|defwinproc },
10523 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10524 { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10525 { 0 }
10527 static const struct message WmRestore_2[] = {
10528 { WM_SHOWWINDOW, sent|wparam, 1 },
10529 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10530 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10531 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10532 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10533 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10534 { 0 }
10536 static const struct message WmRestore_3[] = {
10537 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10538 { WM_GETMINMAXINFO, sent },
10539 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10540 { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10541 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10542 { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10543 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10544 { WM_MOVE, sent|defwinproc },
10545 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10546 { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10547 { 0 }
10549 static const struct message WmRestore_4[] = {
10550 { HCBT_MINMAX, hook|lparam|optional, 0, SW_RESTORE },
10551 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10552 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10553 { WM_MOVE, sent|defwinproc|optional },
10554 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10555 { 0 }
10557 static const struct message WmRestore_5[] = {
10558 { HCBT_MINMAX, hook|lparam|optional, 0, SW_SHOWNORMAL },
10559 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10560 { HCBT_ACTIVATE, hook|optional },
10561 { HCBT_SETFOCUS, hook|optional },
10562 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10563 { WM_MOVE, sent|defwinproc|optional },
10564 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10565 { 0 }
10567 static const struct message WmHide_1[] = {
10568 { WM_SHOWWINDOW, sent|wparam, 0 },
10569 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOACTIVATE },
10570 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOACTIVATE },
10571 { HCBT_ACTIVATE, hook|optional },
10572 { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10573 { 0 }
10575 static const struct message WmHide_2[] = {
10576 { WM_SHOWWINDOW, sent|wparam, 0 },
10577 { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10578 { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10579 { HCBT_ACTIVATE, hook|optional },
10580 { 0 }
10582 static const struct message WmHide_3[] = {
10583 { WM_SHOWWINDOW, sent|wparam, 0 },
10584 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10585 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10586 { HCBT_SETFOCUS, hook|optional },
10587 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10588 { 0 }
10590 static const struct message WmShowMinimized_1[] = {
10591 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10592 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10593 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10594 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10595 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10596 { WM_MOVE, sent|defwinproc },
10597 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10598 { 0 }
10600 static const struct message WmMinimize_1[] = {
10601 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10602 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10603 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10604 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10605 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10606 { WM_MOVE, sent|defwinproc },
10607 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10608 { 0 }
10610 static const struct message WmMinimize_2[] = {
10611 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10612 { HCBT_SETFOCUS, hook|optional },
10613 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10614 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10615 { WM_MOVE, sent|defwinproc },
10616 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10617 { 0 }
10619 static const struct message WmMinimize_3[] = {
10620 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10621 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10622 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10623 { WM_MOVE, sent|defwinproc },
10624 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10625 { 0 }
10627 static const struct message WmShowMinNoActivate[] = {
10628 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10629 { WM_WINDOWPOSCHANGING, sent },
10630 { WM_WINDOWPOSCHANGED, sent },
10631 { WM_MOVE, sent|defwinproc|optional },
10632 { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
10633 { 0 }
10635 static const struct message WmMinMax_1[] = {
10636 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10637 { 0 }
10639 static const struct message WmMinMax_2[] = {
10640 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10641 { WM_GETMINMAXINFO, sent|optional },
10642 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED },
10643 { HCBT_ACTIVATE, hook|optional },
10644 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10645 { HCBT_SETFOCUS, hook|optional },
10646 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10647 { WM_MOVE, sent|defwinproc|optional },
10648 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MAXIMIZED },
10649 { HCBT_SETFOCUS, hook|optional },
10650 { 0 }
10652 static const struct message WmMinMax_3[] = {
10653 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10654 { HCBT_SETFOCUS, hook|optional },
10655 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10656 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10657 { WM_MOVE, sent|defwinproc|optional },
10658 { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
10659 { 0 }
10661 static const struct message WmMinMax_4[] = {
10662 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10663 { 0 }
10665 static const struct message WmShowMaximized_1[] = {
10666 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10667 { WM_GETMINMAXINFO, sent },
10668 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10669 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10670 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10671 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10672 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10673 { WM_MOVE, sent|defwinproc },
10674 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10675 { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10676 { 0 }
10678 static const struct message WmShowMaximized_2[] = {
10679 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10680 { WM_GETMINMAXINFO, sent },
10681 { WM_WINDOWPOSCHANGING, sent|optional },
10682 { HCBT_ACTIVATE, hook|optional },
10683 { WM_WINDOWPOSCHANGED, sent|optional },
10684 { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
10685 { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
10686 { WM_WINDOWPOSCHANGING, sent|optional },
10687 { HCBT_SETFOCUS, hook|optional },
10688 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10689 { WM_MOVE, sent|defwinproc },
10690 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10691 { HCBT_SETFOCUS, hook|optional },
10692 { 0 }
10694 static const struct message WmShowMaximized_3[] = {
10695 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10696 { WM_GETMINMAXINFO, sent|optional },
10697 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10698 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10699 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10700 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10701 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10702 { WM_MOVE, sent|defwinproc|optional },
10703 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10704 { 0 }
10707 static void test_ShowWindow(void)
10709 /* ShowWindow commands in random order */
10710 static const struct
10712 INT cmd; /* ShowWindow command */
10713 LPARAM ret; /* ShowWindow return value */
10714 DWORD style; /* window style after the command */
10715 const struct message *msg; /* message sequence the command produces */
10716 INT wp_cmd, wp_flags; /* window placement after the command */
10717 POINT wp_min, wp_max; /* window placement after the command */
10718 BOOL todo_msg; /* message sequence doesn't match what Wine does */
10719 } sw[] =
10721 /* 1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal,
10722 SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10723 /* 2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq,
10724 SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10725 /* 3 */ { SW_HIDE, TRUE, 0, WmHide_1,
10726 SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10727 /* 4 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10728 SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10729 /* 5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1,
10730 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10731 /* 6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1,
10732 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10733 /* 7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1,
10734 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10735 /* 8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq,
10736 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10737 /* 9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1,
10738 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10739 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2,
10740 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10741 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1,
10742 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10743 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq,
10744 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10745 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1,
10746 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10747 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq,
10748 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10749 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2,
10750 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10751 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10752 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10753 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow,
10754 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10755 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq,
10756 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10757 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1,
10758 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10759 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3,
10760 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10761 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
10762 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10763 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate,
10764 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, TRUE },
10765 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4,
10766 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10767 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
10768 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10769 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq,
10770 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10771 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1,
10772 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10773 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2,
10774 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10775 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
10776 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10777 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq,
10778 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10779 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1,
10780 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10781 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq,
10782 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10783 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3,
10784 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10785 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10786 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10787 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, /* what does this mean?! */
10788 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10789 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq,
10790 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10791 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10792 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10793 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2,
10794 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10795 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq,
10796 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10797 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq,
10798 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10799 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2,
10800 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10801 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3,
10802 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10803 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2,
10804 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10805 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2,
10806 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10807 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1,
10808 SW_SHOWMINIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10809 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3,
10810 SW_SHOWMINIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10811 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3,
10812 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10813 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4,
10814 SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10815 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3,
10816 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10817 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq,
10818 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10819 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5,
10820 SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10821 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5,
10822 SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10823 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1,
10824 SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10825 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10826 SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10827 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3,
10828 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10829 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
10830 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10831 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2,
10832 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10833 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq,
10834 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE }
10836 HWND hwnd;
10837 DWORD style;
10838 LPARAM ret;
10839 INT i;
10840 WINDOWPLACEMENT wp;
10841 RECT win_rc, work_rc = {0, 0, 0, 0};
10843 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
10844 hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
10845 120, 120, 90, 90,
10846 0, 0, 0, NULL);
10847 assert(hwnd);
10849 style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10850 ok(style == 0, "expected style 0, got %08x\n", style);
10852 flush_events();
10853 flush_sequence();
10855 if (pGetMonitorInfoA && pMonitorFromPoint)
10857 HMONITOR hmon;
10858 MONITORINFO mi;
10859 POINT pt = {0, 0};
10861 SetLastError(0xdeadbeef);
10862 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
10863 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
10865 mi.cbSize = sizeof(mi);
10866 SetLastError(0xdeadbeef);
10867 ret = pGetMonitorInfoA(hmon, &mi);
10868 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
10869 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
10870 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
10871 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
10872 work_rc = mi.rcWork;
10875 GetWindowRect(hwnd, &win_rc);
10876 OffsetRect(&win_rc, -work_rc.left, -work_rc.top);
10878 wp.length = sizeof(wp);
10879 SetLastError(0xdeadbeaf);
10880 ret = GetWindowPlacement(hwnd, &wp);
10881 ok(ret, "GetWindowPlacement error %u\n", GetLastError());
10882 ok(wp.flags == 0, "expected 0, got %#x\n", wp.flags);
10883 ok(wp.showCmd == SW_SHOWNORMAL, "expected SW_SHOWNORMAL, got %d\n", wp.showCmd);
10884 ok(wp.ptMinPosition.x == -1 && wp.ptMinPosition.y == -1,
10885 "expected -1,-1 got %d,%d\n", wp.ptMinPosition.x, wp.ptMinPosition.y);
10886 ok(wp.ptMaxPosition.x == -1 && wp.ptMaxPosition.y == -1,
10887 "expected -1,-1 got %d,%d\n", wp.ptMaxPosition.x, wp.ptMaxPosition.y);
10888 if (work_rc.left || work_rc.top) todo_wine /* FIXME: remove once Wine is fixed */
10889 ok(EqualRect(&win_rc, &wp.rcNormalPosition),
10890 "expected %d,%d-%d,%d got %d,%d-%d,%d\n",
10891 win_rc.left, win_rc.top, win_rc.right, win_rc.bottom,
10892 wp.rcNormalPosition.left, wp.rcNormalPosition.top,
10893 wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
10894 else
10895 ok(EqualRect(&win_rc, &wp.rcNormalPosition),
10896 "expected %d,%d-%d,%d got %d,%d-%d,%d\n",
10897 win_rc.left, win_rc.top, win_rc.right, win_rc.bottom,
10898 wp.rcNormalPosition.left, wp.rcNormalPosition.top,
10899 wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
10901 for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
10903 static const char * const sw_cmd_name[13] =
10905 "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
10906 "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
10907 "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
10908 "SW_NORMALNA" /* 0xCC */
10910 char comment[64];
10911 INT idx; /* index into the above array of names */
10913 idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
10915 style = GetWindowLong(hwnd, GWL_STYLE);
10916 trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
10917 ret = ShowWindow(hwnd, sw[i].cmd);
10918 ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
10919 style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10920 ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
10922 sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
10923 ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
10925 wp.length = sizeof(wp);
10926 SetLastError(0xdeadbeaf);
10927 ret = GetWindowPlacement(hwnd, &wp);
10928 ok(ret, "GetWindowPlacement error %u\n", GetLastError());
10929 ok(wp.flags == sw[i].wp_flags, "expected %#x, got %#x\n", sw[i].wp_flags, wp.flags);
10930 ok(wp.showCmd == sw[i].wp_cmd, "expected %d, got %d\n", sw[i].wp_cmd, wp.showCmd);
10932 /* NT moves the minimized window to -32000,-32000, win9x to 3000,3000 */
10933 if ((wp.ptMinPosition.x + work_rc.left == -32000 && wp.ptMinPosition.y + work_rc.top == -32000) ||
10934 (wp.ptMinPosition.x + work_rc.left == 3000 && wp.ptMinPosition.y + work_rc.top == 3000))
10936 ok((wp.ptMinPosition.x + work_rc.left == sw[i].wp_min.x && wp.ptMinPosition.y + work_rc.top == sw[i].wp_min.y) ||
10937 (wp.ptMinPosition.x + work_rc.left == 3000 && wp.ptMinPosition.y + work_rc.top == 3000),
10938 "expected %d,%d got %d,%d\n", sw[i].wp_min.x, sw[i].wp_min.y, wp.ptMinPosition.x, wp.ptMinPosition.y);
10940 else
10942 if (wp.ptMinPosition.x != sw[i].wp_min.x || wp.ptMinPosition.y != sw[i].wp_min.y)
10943 todo_wine
10944 ok(wp.ptMinPosition.x == sw[i].wp_min.x && wp.ptMinPosition.y == sw[i].wp_min.y,
10945 "expected %d,%d got %d,%d\n", sw[i].wp_min.x, sw[i].wp_min.y, wp.ptMinPosition.x, wp.ptMinPosition.y);
10946 else
10947 ok(wp.ptMinPosition.x == sw[i].wp_min.x && wp.ptMinPosition.y == sw[i].wp_min.y,
10948 "expected %d,%d got %d,%d\n", sw[i].wp_min.x, sw[i].wp_min.y, wp.ptMinPosition.x, wp.ptMinPosition.y);
10951 if (wp.ptMaxPosition.x != sw[i].wp_max.x || wp.ptMaxPosition.y != sw[i].wp_max.y)
10952 todo_wine
10953 ok(wp.ptMaxPosition.x == sw[i].wp_max.x && wp.ptMaxPosition.y == sw[i].wp_max.y,
10954 "expected %d,%d got %d,%d\n", sw[i].wp_max.x, sw[i].wp_max.y, wp.ptMaxPosition.x, wp.ptMaxPosition.y);
10955 else
10956 ok(wp.ptMaxPosition.x == sw[i].wp_max.x && wp.ptMaxPosition.y == sw[i].wp_max.y,
10957 "expected %d,%d got %d,%d\n", sw[i].wp_max.x, sw[i].wp_max.y, wp.ptMaxPosition.x, wp.ptMaxPosition.y);
10959 if (0) /* FIXME: Wine behaves completely different here */
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);
10966 flush_events();
10967 flush_sequence();
10970 DestroyWindow(hwnd);
10973 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
10975 struct recvd_message msg;
10977 if (ignore_message( message )) return 0;
10979 msg.hwnd = hwnd;
10980 msg.message = message;
10981 msg.flags = sent|wparam|lparam;
10982 msg.wParam = wParam;
10983 msg.lParam = lParam;
10984 msg.descr = "dialog";
10985 add_message(&msg);
10987 /* calling DefDlgProc leads to a recursion under XP */
10989 switch (message)
10991 case WM_INITDIALOG:
10992 case WM_GETDLGCODE:
10993 return 0;
10995 return 1;
10998 static const struct message WmDefDlgSetFocus_1[] = {
10999 { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
11000 { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
11001 { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
11002 { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
11003 { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
11004 { HCBT_SETFOCUS, hook },
11005 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
11006 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11007 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
11008 { WM_SETFOCUS, sent|wparam, 0 },
11009 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
11010 { WM_CTLCOLOREDIT, sent },
11011 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
11012 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11013 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11014 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11015 { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
11016 { 0 }
11018 static const struct message WmDefDlgSetFocus_2[] = {
11019 { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
11020 { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
11021 { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
11022 { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
11023 { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
11024 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11025 { WM_CTLCOLOREDIT, sent|optional }, /* XP */
11026 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11027 { 0 }
11029 /* Creation of a dialog */
11030 static const struct message WmCreateDialogParamSeq_1[] = {
11031 { HCBT_CREATEWND, hook },
11032 { WM_NCCREATE, sent },
11033 { WM_NCCALCSIZE, sent|wparam, 0 },
11034 { WM_CREATE, sent },
11035 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
11036 { WM_SIZE, sent|wparam, SIZE_RESTORED },
11037 { WM_MOVE, sent },
11038 { WM_SETFONT, sent },
11039 { WM_INITDIALOG, sent },
11040 { WM_CHANGEUISTATE, sent|optional },
11041 { 0 }
11043 /* Creation of a dialog */
11044 static const struct message WmCreateDialogParamSeq_2[] = {
11045 { HCBT_CREATEWND, hook },
11046 { WM_NCCREATE, sent },
11047 { WM_NCCALCSIZE, sent|wparam, 0 },
11048 { WM_CREATE, sent },
11049 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
11050 { WM_SIZE, sent|wparam, SIZE_RESTORED },
11051 { WM_MOVE, sent },
11052 { WM_CHANGEUISTATE, sent|optional },
11053 { 0 }
11056 static void test_dialog_messages(void)
11058 WNDCLASS cls;
11059 HWND hdlg, hedit1, hedit2, hfocus;
11060 LRESULT ret;
11062 #define set_selection(hctl, start, end) \
11063 ret = SendMessage(hctl, EM_SETSEL, start, end); \
11064 ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
11066 #define check_selection(hctl, start, end) \
11067 ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
11068 ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
11070 subclass_edit();
11072 hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
11073 WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
11074 0, 0, 100, 100, 0, 0, 0, NULL);
11075 ok(hdlg != 0, "Failed to create custom dialog window\n");
11077 hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
11078 WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
11079 0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
11080 ok(hedit1 != 0, "Failed to create edit control\n");
11081 hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
11082 WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
11083 0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
11084 ok(hedit2 != 0, "Failed to create edit control\n");
11086 SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
11087 SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
11089 hfocus = GetFocus();
11090 ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
11092 SetFocus(hedit2);
11093 hfocus = GetFocus();
11094 ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
11096 check_selection(hedit1, 0, 0);
11097 check_selection(hedit2, 0, 0);
11099 set_selection(hedit2, 0, -1);
11100 check_selection(hedit2, 0, 3);
11102 SetFocus(0);
11103 hfocus = GetFocus();
11104 ok(hfocus == 0, "wrong focus %p\n", hfocus);
11106 flush_sequence();
11107 ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
11108 ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
11109 ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
11111 hfocus = GetFocus();
11112 ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
11114 check_selection(hedit1, 0, 5);
11115 check_selection(hedit2, 0, 3);
11117 flush_sequence();
11118 ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
11119 ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
11120 ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
11122 hfocus = GetFocus();
11123 ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
11125 check_selection(hedit1, 0, 5);
11126 check_selection(hedit2, 0, 3);
11128 EndDialog(hdlg, 0);
11129 DestroyWindow(hedit1);
11130 DestroyWindow(hedit2);
11131 DestroyWindow(hdlg);
11132 flush_sequence();
11134 #undef set_selection
11135 #undef check_selection
11137 ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
11138 cls.lpszClassName = "MyDialogClass";
11139 cls.hInstance = GetModuleHandle(0);
11140 /* need a cast since a dlgproc is used as a wndproc */
11141 cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
11142 if (!RegisterClass(&cls)) assert(0);
11144 hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
11145 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
11146 ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
11147 EndDialog(hdlg, 0);
11148 DestroyWindow(hdlg);
11149 flush_sequence();
11151 hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
11152 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
11153 ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
11154 EndDialog(hdlg, 0);
11155 DestroyWindow(hdlg);
11156 flush_sequence();
11158 UnregisterClass(cls.lpszClassName, cls.hInstance);
11161 static void test_nullCallback(void)
11163 HWND hwnd;
11165 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
11166 100, 100, 200, 200, 0, 0, 0, NULL);
11167 ok (hwnd != 0, "Failed to create overlapped window\n");
11169 SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
11170 flush_events();
11171 DestroyWindow(hwnd);
11174 /* SetActiveWindow( 0 ) hwnd visible */
11175 static const struct message SetActiveWindowSeq0[] =
11177 { HCBT_ACTIVATE, hook|optional },
11178 { WM_NCACTIVATE, sent|wparam, 0 },
11179 { WM_GETTEXT, sent|defwinproc|optional },
11180 { WM_ACTIVATE, sent|wparam, 0 },
11181 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
11182 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
11183 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11184 { WM_KILLFOCUS, sent|optional },
11185 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11186 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
11187 { WM_NCACTIVATE, sent|wparam|optional, 1 },
11188 { WM_GETTEXT, sent|defwinproc|optional },
11189 { WM_ACTIVATE, sent|wparam|optional, 1 },
11190 { HCBT_SETFOCUS, hook|optional },
11191 { WM_KILLFOCUS, sent|defwinproc|optional },
11192 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
11193 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
11194 { WM_IME_SETCONTEXT, sent|optional },
11195 { WM_IME_SETCONTEXT, sent|optional },
11196 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
11197 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11198 { WM_SETFOCUS, sent|defwinproc|optional },
11199 { WM_GETTEXT, sent|optional },
11200 { 0 }
11202 /* SetActiveWindow( hwnd ) hwnd visible */
11203 static const struct message SetActiveWindowSeq1[] =
11205 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11206 { 0 }
11208 /* SetActiveWindow( popup ) hwnd visible, popup visible */
11209 static const struct message SetActiveWindowSeq2[] =
11211 { HCBT_ACTIVATE, hook },
11212 { WM_NCACTIVATE, sent|wparam, 0 },
11213 { WM_GETTEXT, sent|defwinproc|optional },
11214 { WM_ACTIVATE, sent|wparam, 0 },
11215 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11216 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
11217 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11218 { WM_NCPAINT, sent|optional },
11219 { WM_GETTEXT, sent|defwinproc|optional },
11220 { WM_ERASEBKGND, sent|optional },
11221 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11222 { WM_NCACTIVATE, sent|wparam, 1 },
11223 { WM_GETTEXT, sent|defwinproc|optional },
11224 { WM_ACTIVATE, sent|wparam, 1 },
11225 { HCBT_SETFOCUS, hook },
11226 { WM_KILLFOCUS, sent|defwinproc },
11227 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
11228 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11229 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
11230 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11231 { WM_SETFOCUS, sent|defwinproc },
11232 { WM_GETTEXT, sent|optional },
11233 { 0 }
11236 /* SetActiveWindow( hwnd ) hwnd not visible */
11237 static const struct message SetActiveWindowSeq3[] =
11239 { HCBT_ACTIVATE, hook },
11240 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11241 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11242 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
11243 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11244 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11245 { WM_ACTIVATEAPP, sent|wparam, 1 },
11246 { WM_ACTIVATEAPP, sent|wparam, 1 },
11247 { WM_NCACTIVATE, sent|wparam, 1 },
11248 { WM_ACTIVATE, sent|wparam, 1 },
11249 { HCBT_SETFOCUS, hook },
11250 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11251 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11252 { WM_SETFOCUS, sent|defwinproc },
11253 { 0 }
11255 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
11256 static const struct message SetActiveWindowSeq4[] =
11258 { HCBT_ACTIVATE, hook },
11259 { WM_NCACTIVATE, sent|wparam, 0 },
11260 { WM_GETTEXT, sent|defwinproc|optional },
11261 { WM_ACTIVATE, sent|wparam, 0 },
11262 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11263 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
11264 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11265 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11266 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11267 { WM_NCACTIVATE, sent|wparam, 1 },
11268 { WM_GETTEXT, sent|defwinproc|optional },
11269 { WM_ACTIVATE, sent|wparam, 1 },
11270 { HCBT_SETFOCUS, hook },
11271 { WM_KILLFOCUS, sent|defwinproc },
11272 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
11273 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11274 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
11275 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11276 { WM_SETFOCUS, sent|defwinproc },
11277 { 0 }
11281 static void test_SetActiveWindow(void)
11283 HWND hwnd, popup, ret;
11285 hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
11286 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11287 100, 100, 200, 200, 0, 0, 0, NULL);
11289 popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
11290 WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
11291 100, 100, 200, 200, hwnd, 0, 0, NULL);
11293 ok(hwnd != 0, "Failed to create overlapped window\n");
11294 ok(popup != 0, "Failed to create popup window\n");
11295 SetForegroundWindow( popup );
11296 flush_sequence();
11298 trace("SetActiveWindow(0)\n");
11299 ret = SetActiveWindow(0);
11300 ok( ret == popup, "Failed to SetActiveWindow(0)\n");
11301 ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", FALSE);
11302 flush_sequence();
11304 trace("SetActiveWindow(hwnd), hwnd visible\n");
11305 ret = SetActiveWindow(hwnd);
11306 if (ret == hwnd) ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
11307 flush_sequence();
11309 trace("SetActiveWindow(popup), hwnd visible, popup visible\n");
11310 ret = SetActiveWindow(popup);
11311 ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visible\n");
11312 ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visible", FALSE);
11313 flush_sequence();
11315 ShowWindow(hwnd, SW_HIDE);
11316 ShowWindow(popup, SW_HIDE);
11317 flush_sequence();
11319 trace("SetActiveWindow(hwnd), hwnd not visible\n");
11320 ret = SetActiveWindow(hwnd);
11321 ok( ret == NULL, "SetActiveWindow(hwnd), hwnd not visible, previous is %p\n", ret );
11322 ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
11323 flush_sequence();
11325 trace("SetActiveWindow(popup), hwnd not visible, popup not visible\n");
11326 ret = SetActiveWindow(popup);
11327 ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
11328 ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visible", TRUE);
11329 flush_sequence();
11331 trace("done\n");
11333 DestroyWindow(hwnd);
11336 static const struct message SetForegroundWindowSeq[] =
11338 { WM_NCACTIVATE, sent|wparam, 0 },
11339 { WM_GETTEXT, sent|defwinproc|optional },
11340 { WM_ACTIVATE, sent|wparam, 0 },
11341 { WM_ACTIVATEAPP, sent|wparam, 0 },
11342 { WM_KILLFOCUS, sent },
11343 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
11344 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
11345 { 0 }
11348 static void test_SetForegroundWindow(void)
11350 HWND hwnd;
11352 hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
11353 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11354 100, 100, 200, 200, 0, 0, 0, NULL);
11355 ok (hwnd != 0, "Failed to create overlapped window\n");
11356 SetForegroundWindow( hwnd );
11357 flush_sequence();
11359 trace("SetForegroundWindow( 0 )\n");
11360 SetForegroundWindow( 0 );
11361 ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
11362 trace("SetForegroundWindow( GetDesktopWindow() )\n");
11363 SetForegroundWindow( GetDesktopWindow() );
11364 ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
11365 "foreground top level window", FALSE);
11366 trace("done\n");
11368 DestroyWindow(hwnd);
11371 static void test_dbcs_wm_char(void)
11373 BYTE dbch[2];
11374 WCHAR wch, bad_wch;
11375 HWND hwnd, hwnd2;
11376 MSG msg;
11377 DWORD time;
11378 POINT pt;
11379 DWORD_PTR res;
11380 CPINFOEXA cpinfo;
11381 UINT i, j, k;
11382 struct message wmCharSeq[2];
11384 if (!pGetCPInfoExA)
11386 win_skip("GetCPInfoExA is not available\n");
11387 return;
11390 pGetCPInfoExA( CP_ACP, 0, &cpinfo );
11391 if (cpinfo.MaxCharSize != 2)
11393 skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
11394 return;
11397 dbch[0] = dbch[1] = 0;
11398 wch = 0;
11399 bad_wch = cpinfo.UnicodeDefaultChar;
11400 for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
11401 for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
11402 for (k = 128; k <= 255; k++)
11404 char str[2];
11405 WCHAR wstr[2];
11406 str[0] = j;
11407 str[1] = k;
11408 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
11409 WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
11410 (BYTE)str[0] == j && (BYTE)str[1] == k &&
11411 HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
11413 dbch[0] = j;
11414 dbch[1] = k;
11415 wch = wstr[0];
11416 break;
11420 if (!wch)
11422 skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
11423 return;
11425 trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
11426 dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
11428 hwnd = CreateWindowExW(0, testWindowClassW, NULL,
11429 WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11430 hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
11431 WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11432 ok (hwnd != 0, "Failed to create overlapped window\n");
11433 ok (hwnd2 != 0, "Failed to create overlapped window\n");
11434 flush_sequence();
11436 memset( wmCharSeq, 0, sizeof(wmCharSeq) );
11437 wmCharSeq[0].message = WM_CHAR;
11438 wmCharSeq[0].flags = sent|wparam;
11439 wmCharSeq[0].wParam = wch;
11441 /* posted message */
11442 PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11443 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11444 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11445 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11446 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11447 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11448 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11450 /* posted thread message */
11451 PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
11452 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11453 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11454 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11455 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11456 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11457 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11459 /* sent message */
11460 flush_sequence();
11461 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11462 ok_sequence( WmEmptySeq, "no messages", FALSE );
11463 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11464 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11465 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11467 /* sent message with timeout */
11468 flush_sequence();
11469 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11470 ok_sequence( WmEmptySeq, "no messages", FALSE );
11471 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11472 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11473 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11475 /* sent message with timeout and callback */
11476 flush_sequence();
11477 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11478 ok_sequence( WmEmptySeq, "no messages", FALSE );
11479 SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11480 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11481 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11483 /* sent message with callback */
11484 flush_sequence();
11485 SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11486 ok_sequence( WmEmptySeq, "no messages", FALSE );
11487 SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11488 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11489 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11491 /* direct window proc call */
11492 flush_sequence();
11493 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11494 ok_sequence( WmEmptySeq, "no messages", FALSE );
11495 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11496 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11498 /* dispatch message */
11499 msg.hwnd = hwnd;
11500 msg.message = WM_CHAR;
11501 msg.wParam = dbch[0];
11502 msg.lParam = 0;
11503 DispatchMessageA( &msg );
11504 ok_sequence( WmEmptySeq, "no messages", FALSE );
11505 msg.wParam = dbch[1];
11506 DispatchMessageA( &msg );
11507 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11509 /* window handle is irrelevant */
11510 flush_sequence();
11511 SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11512 ok_sequence( WmEmptySeq, "no messages", FALSE );
11513 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11514 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11515 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11517 /* interleaved post and send */
11518 flush_sequence();
11519 PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11520 SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11521 ok_sequence( WmEmptySeq, "no messages", FALSE );
11522 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11523 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11524 ok_sequence( WmEmptySeq, "no messages", FALSE );
11525 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11526 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11527 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11528 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11529 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11530 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11531 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11533 /* interleaved sent message and winproc */
11534 flush_sequence();
11535 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11536 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11537 ok_sequence( WmEmptySeq, "no messages", FALSE );
11538 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11539 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11540 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11541 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11543 /* interleaved winproc and dispatch */
11544 msg.hwnd = hwnd;
11545 msg.message = WM_CHAR;
11546 msg.wParam = dbch[0];
11547 msg.lParam = 0;
11548 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11549 DispatchMessageA( &msg );
11550 ok_sequence( WmEmptySeq, "no messages", FALSE );
11551 msg.wParam = dbch[1];
11552 DispatchMessageA( &msg );
11553 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11554 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11555 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11557 /* interleaved sends */
11558 flush_sequence();
11559 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11560 SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
11561 ok_sequence( WmEmptySeq, "no messages", FALSE );
11562 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11563 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11564 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11565 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11567 /* dbcs WM_CHAR */
11568 flush_sequence();
11569 SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
11570 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11571 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11573 /* other char messages are not magic */
11574 PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
11575 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11576 ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
11577 ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
11578 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11579 PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
11580 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11581 ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
11582 ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
11583 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11585 /* test retrieving messages */
11587 PostMessageW( hwnd, WM_CHAR, wch, 0 );
11588 ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11589 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11590 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11591 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11592 ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11593 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11594 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11595 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11596 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11598 /* message filters */
11599 PostMessageW( hwnd, WM_CHAR, wch, 0 );
11600 ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11601 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11602 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11603 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11604 /* message id is filtered, hwnd is not */
11605 ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
11606 ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
11607 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11608 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11609 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11610 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11612 /* mixing GetMessage and PostMessage */
11613 PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
11614 ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
11615 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11616 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11617 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11618 ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
11619 time = msg.time;
11620 pt = msg.pt;
11621 ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
11622 ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11623 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11624 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11625 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11626 ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
11627 ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
11628 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 );
11629 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11631 /* without PM_REMOVE */
11632 PostMessageW( hwnd, WM_CHAR, wch, 0 );
11633 ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
11634 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11635 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11636 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11637 ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11638 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11639 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11640 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11641 ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
11642 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11643 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11644 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11645 ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11646 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11647 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11648 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11649 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11651 DestroyWindow(hwnd);
11652 DestroyWindow(hwnd2);
11655 #define ID_LISTBOX 0x000f
11657 static const struct message wm_lb_setcursel_0[] =
11659 { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
11660 { WM_CTLCOLORLISTBOX, sent|parent },
11661 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
11662 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11663 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11664 { 0 }
11666 static const struct message wm_lb_setcursel_1[] =
11668 { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
11669 { WM_CTLCOLORLISTBOX, sent|parent },
11670 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
11671 { WM_CTLCOLORLISTBOX, sent|parent },
11672 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
11673 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
11674 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
11675 { 0 }
11677 static const struct message wm_lb_setcursel_2[] =
11679 { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
11680 { WM_CTLCOLORLISTBOX, sent|parent },
11681 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
11682 { WM_CTLCOLORLISTBOX, sent|parent },
11683 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
11684 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11685 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11686 { 0 }
11688 static const struct message wm_lb_click_0[] =
11690 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
11691 { HCBT_SETFOCUS, hook },
11692 { WM_KILLFOCUS, sent|parent },
11693 { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
11694 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11695 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
11696 { WM_SETFOCUS, sent|defwinproc },
11698 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
11699 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
11700 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11701 { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
11702 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
11704 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
11705 { WM_CTLCOLORLISTBOX, sent|parent },
11706 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
11707 { WM_CTLCOLORLISTBOX, sent|parent },
11708 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
11709 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
11711 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11712 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11714 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
11715 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
11716 { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
11717 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
11718 { 0 }
11720 static const struct message wm_lb_deletestring[] =
11722 { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
11723 { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
11724 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11725 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11726 { 0 }
11728 static const struct message wm_lb_deletestring_reset[] =
11730 { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
11731 { LB_RESETCONTENT, sent|wparam|lparam|defwinproc|optional, 0, 0 },
11732 { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
11733 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11734 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11735 { 0 }
11738 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
11740 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
11742 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11744 static LONG defwndproc_counter = 0;
11745 LRESULT ret;
11746 struct recvd_message msg;
11748 /* do not log painting messages */
11749 if (message != WM_PAINT &&
11750 message != WM_NCPAINT &&
11751 message != WM_SYNCPAINT &&
11752 message != WM_ERASEBKGND &&
11753 message != WM_NCHITTEST &&
11754 message != WM_GETTEXT &&
11755 !ignore_message( message ))
11757 msg.hwnd = hwnd;
11758 msg.message = message;
11759 msg.flags = sent|wparam|lparam;
11760 if (defwndproc_counter) msg.flags |= defwinproc;
11761 msg.wParam = wp;
11762 msg.lParam = lp;
11763 msg.descr = "listbox";
11764 add_message(&msg);
11767 defwndproc_counter++;
11768 ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
11769 defwndproc_counter--;
11771 return ret;
11774 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
11775 int caret_index, int top_index, int line)
11777 LRESULT ret;
11779 /* calling an orig proc helps to avoid unnecessary message logging */
11780 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
11781 ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
11782 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
11783 ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
11784 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
11785 ok_(__FILE__, line)(ret == caret_index ||
11786 broken(cur_sel == -1 && caret_index == 0 && ret == -1), /* nt4 */
11787 "expected caret index %d, got %ld\n", caret_index, ret);
11788 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
11789 ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
11792 static void test_listbox_messages(void)
11794 HWND parent, listbox;
11795 LRESULT ret;
11797 parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11798 100, 100, 200, 200, 0, 0, 0, NULL);
11799 listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
11800 WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
11801 10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
11802 listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
11804 check_lb_state(listbox, 0, LB_ERR, 0, 0);
11806 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
11807 ok(ret == 0, "expected 0, got %ld\n", ret);
11808 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
11809 ok(ret == 1, "expected 1, got %ld\n", ret);
11810 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
11811 ok(ret == 2, "expected 2, got %ld\n", ret);
11813 check_lb_state(listbox, 3, LB_ERR, 0, 0);
11815 flush_sequence();
11817 log_all_parent_messages++;
11819 trace("selecting item 0\n");
11820 ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
11821 ok(ret == 0, "expected 0, got %ld\n", ret);
11822 ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
11823 check_lb_state(listbox, 3, 0, 0, 0);
11824 flush_sequence();
11826 trace("selecting item 1\n");
11827 ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
11828 ok(ret == 1, "expected 1, got %ld\n", ret);
11829 ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
11830 check_lb_state(listbox, 3, 1, 1, 0);
11832 trace("selecting item 2\n");
11833 ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
11834 ok(ret == 2, "expected 2, got %ld\n", ret);
11835 ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
11836 check_lb_state(listbox, 3, 2, 2, 0);
11838 trace("clicking on item 0\n");
11839 ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
11840 ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11841 ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
11842 ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11843 ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
11844 check_lb_state(listbox, 3, 0, 0, 0);
11845 flush_sequence();
11847 trace("deleting item 0\n");
11848 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11849 ok(ret == 2, "expected 2, got %ld\n", ret);
11850 ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
11851 check_lb_state(listbox, 2, -1, 0, 0);
11852 flush_sequence();
11854 trace("deleting item 0\n");
11855 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11856 ok(ret == 1, "expected 1, got %ld\n", ret);
11857 ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
11858 check_lb_state(listbox, 1, -1, 0, 0);
11859 flush_sequence();
11861 trace("deleting item 0\n");
11862 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11863 ok(ret == 0, "expected 0, got %ld\n", ret);
11864 ok_sequence(wm_lb_deletestring_reset, "LB_DELETESTRING 0", FALSE );
11865 check_lb_state(listbox, 0, -1, 0, 0);
11866 flush_sequence();
11868 trace("deleting item 0\n");
11869 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11870 ok(ret == LB_ERR, "expected LB_ERR, got %ld\n", ret);
11871 check_lb_state(listbox, 0, -1, 0, 0);
11872 flush_sequence();
11874 log_all_parent_messages--;
11876 DestroyWindow(listbox);
11877 DestroyWindow(parent);
11880 /*************************** Menu test ******************************/
11881 static const struct message wm_popup_menu_1[] =
11883 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11884 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11885 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
11886 { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
11887 { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
11888 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
11889 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11890 { WM_INITMENU, sent|lparam, 0, 0 },
11891 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
11892 { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
11893 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
11894 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
11895 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
11896 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11897 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001, 0, 0x40000000 },
11898 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
11899 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11900 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11901 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11902 { WM_MENUCOMMAND, sent }, /* |wparam, 200 - Win9x */
11903 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11904 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11905 { 0 }
11907 static const struct message wm_popup_menu_2[] =
11909 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11910 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11911 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11912 { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11913 { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11914 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11915 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11916 { WM_INITMENU, sent|lparam, 0, 0 },
11917 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11918 { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11919 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11920 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11921 { HCBT_CREATEWND, hook },
11922 { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11923 |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11924 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11925 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11926 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11927 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11928 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11929 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11930 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11931 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11932 { HCBT_DESTROYWND, hook },
11933 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11934 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11935 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11936 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11937 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11938 { WM_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
11939 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11940 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11941 { 0 }
11943 static const struct message wm_popup_menu_3[] =
11945 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11946 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11947 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11948 { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11949 { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11950 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11951 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11952 { WM_INITMENU, sent|lparam, 0, 0 },
11953 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11954 { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11955 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11956 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11957 { HCBT_CREATEWND, hook },
11958 { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11959 |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11960 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11961 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11962 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11963 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11964 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11965 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11966 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11967 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11968 { HCBT_DESTROYWND, hook },
11969 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11970 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11971 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11972 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11973 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11974 { WM_COMMAND, sent|wparam|lparam, 100, 0 },
11975 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11976 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11977 { 0 }
11980 static const struct message wm_single_menu_item[] =
11982 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11983 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11984 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'Q', 0x20000001 },
11985 { WM_SYSKEYDOWN, sent|wparam|lparam, 'Q', 0x20000001 },
11986 { WM_SYSCHAR, sent|wparam|lparam, 'q', 0x20000001 },
11987 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'q' },
11988 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11989 { WM_INITMENU, sent|lparam, 0, 0 },
11990 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(300,MF_HILITE) },
11991 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11992 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11993 { WM_MENUCOMMAND, sent },
11994 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'Q', 0xe0000001 },
11995 { WM_SYSKEYUP, sent|wparam|lparam, 'Q', 0xe0000001 },
11996 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 },
11997 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
11999 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 1 },
12000 { WM_KEYDOWN, sent|wparam|lparam, VK_ESCAPE, 1 },
12001 { WM_CHAR, sent|wparam|lparam, VK_ESCAPE, 0x00000001 },
12002 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0xc0000001 },
12003 { WM_KEYUP, sent|wparam|lparam, VK_ESCAPE, 0xc0000001 },
12004 { 0 }
12007 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
12009 if (message == WM_ENTERIDLE ||
12010 message == WM_INITMENU ||
12011 message == WM_INITMENUPOPUP ||
12012 message == WM_MENUSELECT ||
12013 message == WM_PARENTNOTIFY ||
12014 message == WM_ENTERMENULOOP ||
12015 message == WM_EXITMENULOOP ||
12016 message == WM_UNINITMENUPOPUP ||
12017 message == WM_KEYDOWN ||
12018 message == WM_KEYUP ||
12019 message == WM_CHAR ||
12020 message == WM_SYSKEYDOWN ||
12021 message == WM_SYSKEYUP ||
12022 message == WM_SYSCHAR ||
12023 message == WM_COMMAND ||
12024 message == WM_MENUCOMMAND)
12026 struct recvd_message msg;
12028 msg.hwnd = hwnd;
12029 msg.message = message;
12030 msg.flags = sent|wparam|lparam;
12031 msg.wParam = wp;
12032 msg.lParam = lp;
12033 msg.descr = "parent_menu_proc";
12034 add_message(&msg);
12037 return DefWindowProcA(hwnd, message, wp, lp);
12040 static void set_menu_style(HMENU hmenu, DWORD style)
12042 MENUINFO mi;
12043 BOOL ret;
12045 mi.cbSize = sizeof(mi);
12046 mi.fMask = MIM_STYLE;
12047 mi.dwStyle = style;
12048 SetLastError(0xdeadbeef);
12049 ret = pSetMenuInfo(hmenu, &mi);
12050 ok(ret, "SetMenuInfo error %u\n", GetLastError());
12053 static DWORD get_menu_style(HMENU hmenu)
12055 MENUINFO mi;
12056 BOOL ret;
12058 mi.cbSize = sizeof(mi);
12059 mi.fMask = MIM_STYLE;
12060 mi.dwStyle = 0;
12061 SetLastError(0xdeadbeef);
12062 ret = pGetMenuInfo(hmenu, &mi);
12063 ok(ret, "GetMenuInfo error %u\n", GetLastError());
12065 return mi.dwStyle;
12068 static void test_menu_messages(void)
12070 MSG msg;
12071 WNDCLASSA cls;
12072 HMENU hmenu, hmenu_popup;
12073 HWND hwnd;
12074 DWORD style;
12076 if (!pGetMenuInfo || !pSetMenuInfo)
12078 win_skip("GetMenuInfo and/or SetMenuInfo are not available\n");
12079 return;
12081 cls.style = 0;
12082 cls.lpfnWndProc = parent_menu_proc;
12083 cls.cbClsExtra = 0;
12084 cls.cbWndExtra = 0;
12085 cls.hInstance = GetModuleHandleA(0);
12086 cls.hIcon = 0;
12087 cls.hCursor = LoadCursorA(0, IDC_ARROW);
12088 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
12089 cls.lpszMenuName = NULL;
12090 cls.lpszClassName = "TestMenuClass";
12091 UnregisterClass(cls.lpszClassName, cls.hInstance);
12092 if (!RegisterClassA(&cls)) assert(0);
12094 SetLastError(0xdeadbeef);
12095 hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
12096 100, 100, 200, 200, 0, 0, 0, NULL);
12097 ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
12099 SetLastError(0xdeadbeef);
12100 hmenu = LoadMenuA(GetModuleHandle(0), MAKEINTRESOURCE(1));
12101 ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
12103 SetMenu(hwnd, hmenu);
12104 SetForegroundWindow( hwnd );
12106 set_menu_style(hmenu, MNS_NOTIFYBYPOS);
12107 style = get_menu_style(hmenu);
12108 ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
12110 hmenu_popup = GetSubMenu(hmenu, 0);
12111 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12112 style = get_menu_style(hmenu_popup);
12113 ok(style == 0, "expected 0, got %u\n", style);
12115 hmenu_popup = GetSubMenu(hmenu_popup, 0);
12116 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12117 style = get_menu_style(hmenu_popup);
12118 ok(style == 0, "expected 0, got %u\n", style);
12120 /* Alt+E, Enter */
12121 trace("testing a popup menu command\n");
12122 flush_sequence();
12123 keybd_event(VK_MENU, 0, 0, 0);
12124 keybd_event('E', 0, 0, 0);
12125 keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
12126 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12127 keybd_event(VK_RETURN, 0, 0, 0);
12128 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
12129 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
12131 TranslateMessage(&msg);
12132 DispatchMessage(&msg);
12134 if (!sequence_cnt) /* we didn't get any message */
12136 skip( "queuing key events not supported\n" );
12137 goto done;
12139 /* win98 queues only a WM_KEYUP and doesn't start menu tracking */
12140 if (sequence[0].message == WM_KEYUP && sequence[0].wParam == VK_MENU)
12142 win_skip( "menu tracking through VK_MENU not supported\n" );
12143 goto done;
12145 ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
12147 /* Alt+F, Right, Enter */
12148 trace("testing submenu of a popup menu command\n");
12149 flush_sequence();
12150 keybd_event(VK_MENU, 0, 0, 0);
12151 keybd_event('F', 0, 0, 0);
12152 keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
12153 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12154 keybd_event(VK_RIGHT, 0, 0, 0);
12155 keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
12156 keybd_event(VK_RETURN, 0, 0, 0);
12157 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
12158 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
12160 TranslateMessage(&msg);
12161 DispatchMessage(&msg);
12163 ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
12165 trace("testing single menu item command\n");
12166 flush_sequence();
12167 keybd_event(VK_MENU, 0, 0, 0);
12168 keybd_event('Q', 0, 0, 0);
12169 keybd_event('Q', 0, KEYEVENTF_KEYUP, 0);
12170 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12171 keybd_event(VK_ESCAPE, 0, 0, 0);
12172 keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0);
12173 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
12175 TranslateMessage(&msg);
12176 DispatchMessage(&msg);
12178 ok_sequence(wm_single_menu_item, "single menu item command", FALSE);
12180 set_menu_style(hmenu, 0);
12181 style = get_menu_style(hmenu);
12182 ok(style == 0, "expected 0, got %u\n", style);
12184 hmenu_popup = GetSubMenu(hmenu, 0);
12185 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12186 set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
12187 style = get_menu_style(hmenu_popup);
12188 ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
12190 hmenu_popup = GetSubMenu(hmenu_popup, 0);
12191 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12192 style = get_menu_style(hmenu_popup);
12193 ok(style == 0, "expected 0, got %u\n", style);
12195 /* Alt+F, Right, Enter */
12196 trace("testing submenu of a popup menu command\n");
12197 flush_sequence();
12198 keybd_event(VK_MENU, 0, 0, 0);
12199 keybd_event('F', 0, 0, 0);
12200 keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
12201 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12202 keybd_event(VK_RIGHT, 0, 0, 0);
12203 keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
12204 keybd_event(VK_RETURN, 0, 0, 0);
12205 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
12206 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
12208 TranslateMessage(&msg);
12209 DispatchMessage(&msg);
12211 ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
12213 done:
12214 DestroyWindow(hwnd);
12215 DestroyMenu(hmenu);
12219 static void test_paintingloop(void)
12221 HWND hwnd;
12223 paint_loop_done = 0;
12224 hwnd = CreateWindowExA(0x0,"PaintLoopWindowClass",
12225 "PaintLoopWindowClass",WS_OVERLAPPEDWINDOW,
12226 100, 100, 100, 100, 0, 0, 0, NULL );
12227 ok(hwnd != 0, "PaintLoop window error %u\n", GetLastError());
12228 ShowWindow(hwnd,SW_NORMAL);
12229 SetFocus(hwnd);
12231 while (!paint_loop_done)
12233 MSG msg;
12234 if (PeekMessageA(&msg, 0, 0, 0, 1))
12236 TranslateMessage(&msg);
12237 DispatchMessage(&msg);
12240 DestroyWindow(hwnd);
12243 static void test_defwinproc(void)
12245 HWND hwnd;
12246 MSG msg;
12247 int gotwmquit = FALSE;
12248 hwnd = CreateWindowExA(0, "static", "test_defwndproc", WS_POPUP, 0,0,0,0,0,0,0, NULL);
12249 assert(hwnd);
12250 DefWindowProcA( hwnd, WM_ENDSESSION, 1, 0);
12251 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) {
12252 if( msg.message == WM_QUIT) gotwmquit = TRUE;
12253 DispatchMessageA( &msg );
12255 ok( gotwmquit == FALSE, "Unexpected WM_QUIT message!\n");
12256 DestroyWindow( hwnd);
12259 #define clear_clipboard(hwnd) clear_clipboard_(__LINE__, (hwnd))
12260 static void clear_clipboard_(int line, HWND hWnd)
12262 BOOL succ;
12263 succ = OpenClipboard(hWnd);
12264 ok_(__FILE__, line)(succ, "OpenClipboard failed, err=%u\n", GetLastError());
12265 succ = EmptyClipboard();
12266 ok_(__FILE__, line)(succ, "EmptyClipboard failed, err=%u\n", GetLastError());
12267 succ = CloseClipboard();
12268 ok_(__FILE__, line)(succ, "CloseClipboard failed, err=%u\n", GetLastError());
12271 #define expect_HWND(expected, got) expect_HWND_(__LINE__, (expected), (got))
12272 static void expect_HWND_(int line, HWND expected, HWND got)
12274 ok_(__FILE__, line)(got==expected, "Expected %p, got %p\n", expected, got);
12277 static WNDPROC pOldViewerProc;
12279 static LRESULT CALLBACK recursive_viewer_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
12281 static BOOL recursion_guard;
12283 if (message == WM_DRAWCLIPBOARD && !recursion_guard)
12285 recursion_guard = TRUE;
12286 clear_clipboard(hWnd);
12287 recursion_guard = FALSE;
12289 return CallWindowProcA(pOldViewerProc, hWnd, message, wParam, lParam);
12292 static void test_clipboard_viewers(void)
12294 static struct message wm_change_cb_chain[] =
12296 { WM_CHANGECBCHAIN, sent|wparam|lparam, 0, 0 },
12297 { 0 }
12299 static const struct message wm_clipboard_destroyed[] =
12301 { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
12302 { 0 }
12304 static struct message wm_clipboard_changed[] =
12306 { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
12307 { 0 }
12309 static struct message wm_clipboard_changed_and_owned[] =
12311 { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
12312 { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
12313 { 0 }
12316 HINSTANCE hInst = GetModuleHandleA(NULL);
12317 HWND hWnd1, hWnd2, hWnd3;
12318 HWND hOrigViewer;
12319 HWND hRet;
12321 hWnd1 = CreateWindowExA(0, "TestWindowClass", "Clipboard viewer test wnd 1",
12322 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12323 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12324 GetDesktopWindow(), NULL, hInst, NULL);
12325 hWnd2 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 2",
12326 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12327 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12328 GetDesktopWindow(), NULL, hInst, NULL);
12329 hWnd3 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 3",
12330 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12331 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12332 GetDesktopWindow(), NULL, hInst, NULL);
12333 trace("clipbd viewers: hWnd1=%p, hWnd2=%p, hWnd3=%p\n", hWnd1, hWnd2, hWnd3);
12334 assert(hWnd1 && hWnd2 && hWnd3);
12336 flush_sequence();
12338 /* Test getting the clipboard viewer and setting the viewer to NULL. */
12339 hOrigViewer = GetClipboardViewer();
12340 hRet = SetClipboardViewer(NULL);
12341 ok_sequence(WmEmptySeq, "set viewer to NULL", FALSE);
12342 expect_HWND(hOrigViewer, hRet);
12343 expect_HWND(NULL, GetClipboardViewer());
12345 /* Test registering hWnd1 as a viewer. */
12346 hRet = SetClipboardViewer(hWnd1);
12347 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12348 ok_sequence(wm_clipboard_changed, "set viewer NULL->1", FALSE);
12349 expect_HWND(NULL, hRet);
12350 expect_HWND(hWnd1, GetClipboardViewer());
12352 /* Test that changing the clipboard actually refreshes the registered viewer. */
12353 clear_clipboard(hWnd1);
12354 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12355 ok_sequence(wm_clipboard_changed, "clear clipbd (viewer=owner=1)", FALSE);
12357 /* Again, but with different owner. */
12358 clear_clipboard(hWnd2);
12359 wm_clipboard_changed_and_owned[1].wParam = (WPARAM) GetClipboardOwner();
12360 ok_sequence(wm_clipboard_changed_and_owned, "clear clipbd (viewer=1, owner=2)", FALSE);
12362 /* Test re-registering same window. */
12363 hRet = SetClipboardViewer(hWnd1);
12364 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12365 ok_sequence(wm_clipboard_changed, "set viewer 1->1", FALSE);
12366 expect_HWND(hWnd1, hRet);
12367 expect_HWND(hWnd1, GetClipboardViewer());
12369 /* Test ChangeClipboardChain. */
12370 ChangeClipboardChain(hWnd2, hWnd3);
12371 wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
12372 wm_change_cb_chain[0].lParam = (LPARAM) hWnd3;
12373 ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=3)", FALSE);
12374 expect_HWND(hWnd1, GetClipboardViewer());
12376 ChangeClipboardChain(hWnd2, NULL);
12377 wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
12378 wm_change_cb_chain[0].lParam = 0;
12379 ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=NULL)", FALSE);
12380 expect_HWND(hWnd1, GetClipboardViewer());
12382 ChangeClipboardChain(NULL, hWnd2);
12383 ok_sequence(WmEmptySeq, "change chain (viewer=1, remove=NULL, next=2)", TRUE);
12384 expect_HWND(hWnd1, GetClipboardViewer());
12386 /* Actually change clipboard viewer with ChangeClipboardChain. */
12387 ChangeClipboardChain(hWnd1, hWnd2);
12388 ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=2)", FALSE);
12389 expect_HWND(hWnd2, GetClipboardViewer());
12391 /* Test that no refresh messages are sent when viewer has unregistered. */
12392 clear_clipboard(hWnd2);
12393 ok_sequence(WmEmptySeq, "clear clipd (viewer=2, owner=1)", FALSE);
12395 /* Register hWnd1 again. */
12396 ChangeClipboardChain(hWnd2, hWnd1);
12397 ok_sequence(WmEmptySeq, "change chain (viewer=remove=2, next=1)", FALSE);
12398 expect_HWND(hWnd1, GetClipboardViewer());
12400 /* Subclass hWnd1 so that when it receives a WM_DRAWCLIPBOARD message, it
12401 * changes the clipboard. When this happens, the system shouldn't send
12402 * another WM_DRAWCLIPBOARD (as this could cause an infinite loop).
12404 pOldViewerProc = (WNDPROC) SetWindowLongPtrA(hWnd1, GWLP_WNDPROC, (LONG_PTR) recursive_viewer_proc);
12405 clear_clipboard(hWnd2);
12406 /* The clipboard owner is changed in recursive_viewer_proc: */
12407 wm_clipboard_changed[0].wParam = (WPARAM) hWnd2;
12408 ok_sequence(wm_clipboard_changed, "recursive clear clipbd (viewer=1, owner=2)", TRUE);
12410 /* Test unregistering. */
12411 ChangeClipboardChain(hWnd1, NULL);
12412 ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=NULL)", FALSE);
12413 expect_HWND(NULL, GetClipboardViewer());
12415 clear_clipboard(hWnd1);
12416 ok_sequence(wm_clipboard_destroyed, "clear clipbd (no viewer, owner=1)", FALSE);
12418 DestroyWindow(hWnd1);
12419 DestroyWindow(hWnd2);
12420 DestroyWindow(hWnd3);
12421 SetClipboardViewer(hOrigViewer);
12424 static void test_PostMessage(void)
12426 static const struct
12428 HWND hwnd;
12429 BOOL ret;
12430 } data[] =
12432 { HWND_TOP /* 0 */, TRUE },
12433 { HWND_BROADCAST, TRUE },
12434 { HWND_BOTTOM, TRUE },
12435 { HWND_TOPMOST, TRUE },
12436 { HWND_NOTOPMOST, FALSE },
12437 { HWND_MESSAGE, FALSE },
12438 { (HWND)0xdeadbeef, FALSE }
12440 int i;
12441 HWND hwnd;
12442 BOOL ret;
12443 MSG msg;
12444 static const WCHAR staticW[] = {'s','t','a','t','i','c',0};
12446 SetLastError(0xdeadbeef);
12447 hwnd = CreateWindowExW(0, staticW, NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
12448 if (!hwnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
12450 win_skip("Skipping some PostMessage tests on Win9x/WinMe\n");
12451 return;
12453 assert(hwnd);
12455 flush_events();
12457 PostMessage(hwnd, WM_USER+1, 0x1234, 0x5678);
12458 PostMessage(0, WM_USER+2, 0x5678, 0x1234);
12460 for (i = 0; i < sizeof(data)/sizeof(data[0]); i++)
12462 memset(&msg, 0xab, sizeof(msg));
12463 ret = PeekMessageA(&msg, data[i].hwnd, 0, 0, PM_NOREMOVE);
12464 ok(ret == data[i].ret, "%d: hwnd %p expected %d, got %d\n", i, data[i].hwnd, data[i].ret, ret);
12465 if (data[i].ret)
12467 if (data[i].hwnd)
12468 ok(ret && msg.hwnd == 0 && msg.message == WM_USER+2 &&
12469 msg.wParam == 0x5678 && msg.lParam == 0x1234,
12470 "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/0/WM_USER+2/0x5678/0x1234\n",
12471 i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam);
12472 else
12473 ok(ret && msg.hwnd == hwnd && msg.message == WM_USER+1 &&
12474 msg.wParam == 0x1234 && msg.lParam == 0x5678,
12475 "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/%p/WM_USER+1/0x1234/0x5678\n",
12476 i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam, msg.hwnd);
12480 DestroyWindow(hwnd);
12481 flush_events();
12484 static const struct
12486 DWORD exp, broken;
12487 BOOL todo;
12488 } wait_idle_expect[] =
12490 /* 0 */ { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12491 { WAIT_TIMEOUT, 0, FALSE },
12492 { WAIT_TIMEOUT, 0, FALSE },
12493 { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12494 { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12495 /* 5 */ { WAIT_TIMEOUT, 0, FALSE },
12496 { WAIT_TIMEOUT, 0, FALSE },
12497 { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12498 { 0, 0, FALSE },
12499 { 0, 0, FALSE },
12500 /* 10 */ { 0, 0, FALSE },
12501 { 0, 0, FALSE },
12502 { 0, WAIT_TIMEOUT, FALSE },
12503 { 0, 0, FALSE },
12504 { 0, 0, FALSE },
12505 /* 15 */ { 0, 0, FALSE },
12506 { WAIT_TIMEOUT, 0, FALSE },
12507 { WAIT_TIMEOUT, 0, FALSE },
12508 { WAIT_TIMEOUT, 0, FALSE },
12509 { WAIT_TIMEOUT, 0, FALSE },
12510 /* 20 */ { WAIT_TIMEOUT, 0, FALSE },
12513 static DWORD CALLBACK do_wait_idle_child_thread( void *arg )
12515 MSG msg;
12517 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12518 Sleep( 200 );
12519 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12520 return 0;
12523 static void do_wait_idle_child( int arg )
12525 WNDCLASS cls;
12526 MSG msg;
12527 HWND hwnd = 0;
12528 HANDLE thread;
12529 DWORD id;
12530 HANDLE start_event = OpenEventA( EVENT_ALL_ACCESS, FALSE, "test_WaitForInputIdle_start" );
12531 HANDLE end_event = OpenEventA( EVENT_ALL_ACCESS, FALSE, "test_WaitForInputIdle_end" );
12533 memset( &cls, 0, sizeof(cls) );
12534 cls.lpfnWndProc = DefWindowProc;
12535 cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
12536 cls.hCursor = LoadCursor(0, IDC_ARROW);
12537 cls.lpszClassName = "TestClass";
12538 RegisterClass( &cls );
12540 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ); /* create the msg queue */
12542 ok( start_event != 0, "failed to create start event, error %u\n", GetLastError() );
12543 ok( end_event != 0, "failed to create end event, error %u\n", GetLastError() );
12545 switch (arg)
12547 case 0:
12548 SetEvent( start_event );
12549 break;
12550 case 1:
12551 SetEvent( start_event );
12552 Sleep( 200 );
12553 PeekMessage( &msg, 0, 0, 0, PM_REMOVE );
12554 break;
12555 case 2:
12556 SetEvent( start_event );
12557 Sleep( 200 );
12558 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12559 PostThreadMessage( GetCurrentThreadId(), WM_COMMAND, 0x1234, 0xabcd );
12560 PeekMessage( &msg, 0, 0, 0, PM_REMOVE );
12561 break;
12562 case 3:
12563 SetEvent( start_event );
12564 Sleep( 200 );
12565 SendMessage( HWND_BROADCAST, WM_WININICHANGE, 0, 0 );
12566 break;
12567 case 4:
12568 SetEvent( start_event );
12569 Sleep( 200 );
12570 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12571 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessage( &msg );
12572 break;
12573 case 5:
12574 SetEvent( start_event );
12575 Sleep( 200 );
12576 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12577 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12578 break;
12579 case 6:
12580 SetEvent( start_event );
12581 Sleep( 200 );
12582 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12583 while (PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ))
12585 GetMessage( &msg, 0, 0, 0 );
12586 DispatchMessage( &msg );
12588 break;
12589 case 7:
12590 SetEvent( start_event );
12591 Sleep( 200 );
12592 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12593 SetTimer( hwnd, 3, 1, NULL );
12594 Sleep( 200 );
12595 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessage( &msg );
12596 break;
12597 case 8:
12598 SetEvent( start_event );
12599 Sleep( 200 );
12600 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12601 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12602 break;
12603 case 9:
12604 SetEvent( start_event );
12605 Sleep( 200 );
12606 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12607 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12608 for (;;) GetMessage( &msg, 0, 0, 0 );
12609 break;
12610 case 10:
12611 SetEvent( start_event );
12612 Sleep( 200 );
12613 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12614 SetTimer( hwnd, 3, 1, NULL );
12615 Sleep( 200 );
12616 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12617 break;
12618 case 11:
12619 SetEvent( start_event );
12620 Sleep( 200 );
12621 return; /* exiting the process makes WaitForInputIdle return success too */
12622 case 12:
12623 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12624 Sleep( 200 );
12625 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12626 SetEvent( start_event );
12627 break;
12628 case 13:
12629 SetEvent( start_event );
12630 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12631 Sleep( 200 );
12632 thread = CreateThread( NULL, 0, do_wait_idle_child_thread, NULL, 0, &id );
12633 WaitForSingleObject( thread, 10000 );
12634 CloseHandle( thread );
12635 break;
12636 case 14:
12637 SetEvent( start_event );
12638 Sleep( 200 );
12639 PeekMessage( &msg, HWND_TOPMOST, 0, 0, PM_NOREMOVE );
12640 break;
12641 case 15:
12642 SetEvent( start_event );
12643 Sleep( 200 );
12644 PeekMessage( &msg, HWND_BROADCAST, 0, 0, PM_NOREMOVE );
12645 break;
12646 case 16:
12647 SetEvent( start_event );
12648 Sleep( 200 );
12649 PeekMessage( &msg, HWND_BOTTOM, 0, 0, PM_NOREMOVE );
12650 break;
12651 case 17:
12652 SetEvent( start_event );
12653 Sleep( 200 );
12654 PeekMessage( &msg, (HWND)0xdeadbeef, 0, 0, PM_NOREMOVE );
12655 break;
12656 case 18:
12657 SetEvent( start_event );
12658 Sleep( 200 );
12659 PeekMessage( &msg, HWND_NOTOPMOST, 0, 0, PM_NOREMOVE );
12660 break;
12661 case 19:
12662 SetEvent( start_event );
12663 Sleep( 200 );
12664 PeekMessage( &msg, HWND_MESSAGE, 0, 0, PM_NOREMOVE );
12665 break;
12666 case 20:
12667 SetEvent( start_event );
12668 Sleep( 200 );
12669 PeekMessage( &msg, GetDesktopWindow(), 0, 0, PM_NOREMOVE );
12670 break;
12672 WaitForSingleObject( end_event, 2000 );
12673 CloseHandle( start_event );
12674 CloseHandle( end_event );
12675 if (hwnd) DestroyWindow( hwnd );
12678 static LRESULT CALLBACK wait_idle_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
12680 if (msg == WM_WININICHANGE) Sleep( 200 ); /* make sure the child waits */
12681 return DefWindowProcA( hwnd, msg, wp, lp );
12684 static DWORD CALLBACK wait_idle_thread( void *arg )
12686 WNDCLASS cls;
12687 MSG msg;
12688 HWND hwnd;
12690 memset( &cls, 0, sizeof(cls) );
12691 cls.lpfnWndProc = wait_idle_proc;
12692 cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
12693 cls.hCursor = LoadCursor(0, IDC_ARROW);
12694 cls.lpszClassName = "TestClass";
12695 RegisterClass( &cls );
12697 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
12698 while (GetMessage( &msg, 0, 0, 0 )) DispatchMessage( &msg );
12699 DestroyWindow(hwnd);
12700 return 0;
12703 static void test_WaitForInputIdle( char *argv0 )
12705 char path[MAX_PATH];
12706 PROCESS_INFORMATION pi;
12707 STARTUPINFOA startup;
12708 BOOL ret;
12709 HANDLE start_event, end_event, thread;
12710 unsigned int i;
12711 DWORD id;
12712 const IMAGE_DOS_HEADER *dos = (const IMAGE_DOS_HEADER *)GetModuleHandleA(0);
12713 const IMAGE_NT_HEADERS *nt = (const IMAGE_NT_HEADERS *)((const char *)dos + dos->e_lfanew);
12714 BOOL console_app = (nt->OptionalHeader.Subsystem != IMAGE_SUBSYSTEM_WINDOWS_GUI);
12716 if (console_app) /* build the test with -mwindows for better coverage */
12717 trace( "not built as a GUI app, WaitForInputIdle may not be fully tested\n" );
12719 start_event = CreateEventA(NULL, 0, 0, "test_WaitForInputIdle_start");
12720 end_event = CreateEventA(NULL, 0, 0, "test_WaitForInputIdle_end");
12721 ok(start_event != 0, "failed to create start event, error %u\n", GetLastError());
12722 ok(end_event != 0, "failed to create end event, error %u\n", GetLastError());
12724 memset( &startup, 0, sizeof(startup) );
12725 startup.cb = sizeof(startup);
12726 startup.dwFlags = STARTF_USESHOWWINDOW;
12727 startup.wShowWindow = SW_SHOWNORMAL;
12729 thread = CreateThread( NULL, 0, wait_idle_thread, NULL, 0, &id );
12731 for (i = 0; i < sizeof(wait_idle_expect)/sizeof(wait_idle_expect[0]); i++)
12733 ResetEvent( start_event );
12734 ResetEvent( end_event );
12735 sprintf( path, "%s msg %u", argv0, i );
12736 ret = CreateProcessA( NULL, path, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &pi );
12737 ok( ret, "CreateProcess '%s' failed err %u.\n", path, GetLastError() );
12738 if (ret)
12740 ret = WaitForSingleObject( start_event, 5000 );
12741 ok( ret == WAIT_OBJECT_0, "%u: WaitForSingleObject failed\n", i );
12742 if (ret == WAIT_OBJECT_0)
12744 ret = WaitForInputIdle( pi.hProcess, 1000 );
12745 if (ret == WAIT_FAILED)
12746 ok( console_app ||
12747 ret == wait_idle_expect[i].exp ||
12748 broken(ret == wait_idle_expect[i].broken),
12749 "%u: WaitForInputIdle error %08x expected %08x\n",
12750 i, ret, wait_idle_expect[i].exp );
12751 else if (wait_idle_expect[i].todo)
12752 todo_wine
12753 ok( ret == wait_idle_expect[i].exp || broken(ret == wait_idle_expect[i].broken),
12754 "%u: WaitForInputIdle error %08x expected %08x\n",
12755 i, ret, wait_idle_expect[i].exp );
12756 else
12757 ok( ret == wait_idle_expect[i].exp || broken(ret == wait_idle_expect[i].broken),
12758 "%u: WaitForInputIdle error %08x expected %08x\n",
12759 i, ret, wait_idle_expect[i].exp );
12760 SetEvent( end_event );
12761 WaitForSingleObject( pi.hProcess, 1000 ); /* give it a chance to exit on its own */
12763 TerminateProcess( pi.hProcess, 0 ); /* just in case */
12764 winetest_wait_child_process( pi.hProcess );
12765 ret = WaitForInputIdle( pi.hProcess, 100 );
12766 ok( ret == WAIT_FAILED, "%u: WaitForInputIdle after exit error %08x\n", i, ret );
12767 CloseHandle( pi.hProcess );
12768 CloseHandle( pi.hThread );
12771 CloseHandle( start_event );
12772 PostThreadMessage( id, WM_QUIT, 0, 0 );
12773 WaitForSingleObject( thread, 10000 );
12774 CloseHandle( thread );
12777 static const struct message WmSetParentSeq_1[] = {
12778 { WM_SHOWWINDOW, sent|wparam, 0 },
12779 { EVENT_OBJECT_PARENTCHANGE, winevent_hook|wparam|lparam, 0, 0 },
12780 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
12781 { WM_CHILDACTIVATE, sent },
12782 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW|SWP_NOCLIENTSIZE },
12783 { WM_MOVE, sent|defwinproc|wparam, 0 },
12784 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
12785 { WM_SHOWWINDOW, sent|wparam, 1 },
12786 { 0 }
12789 static const struct message WmSetParentSeq_2[] = {
12790 { WM_SHOWWINDOW, sent|wparam, 0 },
12791 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
12792 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
12793 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
12794 { HCBT_SETFOCUS, hook|optional },
12795 { WM_NCACTIVATE, sent|wparam, 0 },
12796 { WM_ACTIVATE, sent|wparam, 0 },
12797 { WM_ACTIVATEAPP, sent|wparam, 0 },
12798 { WM_KILLFOCUS, sent|wparam, 0 },
12799 { EVENT_OBJECT_PARENTCHANGE, winevent_hook|wparam|lparam, 0, 0 },
12800 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
12801 { HCBT_ACTIVATE, hook },
12802 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
12803 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
12804 { WM_NCACTIVATE, sent|wparam, 1 },
12805 { WM_ACTIVATE, sent|wparam, 1 },
12806 { HCBT_SETFOCUS, hook },
12807 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
12808 { WM_SETFOCUS, sent|defwinproc },
12809 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOREDRAW|SWP_NOSIZE|SWP_NOCLIENTSIZE },
12810 { WM_MOVE, sent|defwinproc|wparam, 0 },
12811 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
12812 { WM_SHOWWINDOW, sent|wparam, 1 },
12813 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
12814 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
12815 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
12816 { 0 }
12820 static void test_SetParent(void)
12822 HWND parent1, parent2, child, popup;
12823 RECT rc, rc_old;
12825 parent1 = CreateWindowEx(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW,
12826 100, 100, 200, 200, 0, 0, 0, NULL);
12827 ok(parent1 != 0, "Failed to create parent1 window\n");
12829 parent2 = CreateWindowEx(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW,
12830 400, 100, 200, 200, 0, 0, 0, NULL);
12831 ok(parent2 != 0, "Failed to create parent2 window\n");
12833 /* WS_CHILD window */
12834 child = CreateWindowEx(0, "TestWindowClass", NULL, WS_CHILD | WS_VISIBLE,
12835 10, 10, 150, 150, parent1, 0, 0, NULL);
12836 ok(child != 0, "Failed to create child window\n");
12838 GetWindowRect(parent1, &rc);
12839 trace("parent1 (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
12840 GetWindowRect(child, &rc_old);
12841 MapWindowPoints(0, parent1, (POINT *)&rc_old, 2);
12842 trace("child (%d,%d)-(%d,%d)\n", rc_old.left, rc_old.top, rc_old.right, rc_old.bottom);
12844 flush_sequence();
12846 SetParent(child, parent2);
12847 flush_events();
12848 ok_sequence(WmSetParentSeq_1, "SetParent() visible WS_CHILD", TRUE);
12850 ok(GetWindowLongA(child, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
12851 ok(!IsWindowVisible(child), "IsWindowVisible() should return FALSE\n");
12853 GetWindowRect(parent2, &rc);
12854 trace("parent2 (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
12855 GetWindowRect(child, &rc);
12856 MapWindowPoints(0, parent2, (POINT *)&rc, 2);
12857 trace("child (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
12859 ok(EqualRect(&rc_old, &rc), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
12860 rc_old.left, rc_old.top, rc_old.right, rc_old.bottom,
12861 rc.left, rc.top, rc.right, rc.bottom );
12863 /* WS_POPUP window */
12864 popup = CreateWindowEx(0, "TestWindowClass", NULL, WS_POPUP | WS_VISIBLE,
12865 20, 20, 100, 100, 0, 0, 0, NULL);
12866 ok(popup != 0, "Failed to create popup window\n");
12868 GetWindowRect(popup, &rc_old);
12869 trace("popup (%d,%d)-(%d,%d)\n", rc_old.left, rc_old.top, rc_old.right, rc_old.bottom);
12871 flush_sequence();
12873 SetParent(popup, child);
12874 flush_events();
12875 ok_sequence(WmSetParentSeq_2, "SetParent() visible WS_POPUP", TRUE);
12877 ok(GetWindowLongA(popup, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
12878 ok(!IsWindowVisible(popup), "IsWindowVisible() should return FALSE\n");
12880 GetWindowRect(child, &rc);
12881 trace("parent2 (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
12882 GetWindowRect(popup, &rc);
12883 MapWindowPoints(0, child, (POINT *)&rc, 2);
12884 trace("popup (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
12886 ok(EqualRect(&rc_old, &rc), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
12887 rc_old.left, rc_old.top, rc_old.right, rc_old.bottom,
12888 rc.left, rc.top, rc.right, rc.bottom );
12890 DestroyWindow(popup);
12891 DestroyWindow(child);
12892 DestroyWindow(parent1);
12893 DestroyWindow(parent2);
12895 flush_sequence();
12898 static const struct message WmKeyReleaseOnly[] = {
12899 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 0x41, 0x80000001 },
12900 { WM_KEYUP, sent|wparam|lparam, 0x41, 0x80000001 },
12901 { 0 }
12903 static const struct message WmKeyPressNormal[] = {
12904 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 0x41, 0x1 },
12905 { WM_KEYDOWN, sent|wparam|lparam, 0x41, 0x1 },
12906 { 0 }
12908 static const struct message WmKeyPressRepeat[] = {
12909 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 0x41, 0x40000001 },
12910 { WM_KEYDOWN, sent|wparam|lparam, 0x41, 0x40000001 },
12911 { 0 }
12913 static const struct message WmKeyReleaseNormal[] = {
12914 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 0x41, 0xc0000001 },
12915 { WM_KEYUP, sent|wparam|lparam, 0x41, 0xc0000001 },
12916 { 0 }
12919 static void test_keyflags(void)
12921 HWND test_window;
12922 SHORT key_state;
12923 BYTE keyboard_state[256];
12924 MSG msg;
12926 test_window = CreateWindowEx(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
12927 100, 100, 200, 200, 0, 0, 0, NULL);
12929 flush_sequence();
12931 /* keyup without a keydown */
12932 keybd_event(0x41, 0, KEYEVENTF_KEYUP, 0);
12933 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
12934 DispatchMessage(&msg);
12935 ok_sequence(WmKeyReleaseOnly, "key release only", TRUE);
12937 key_state = GetAsyncKeyState(0x41);
12938 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
12940 key_state = GetKeyState(0x41);
12941 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
12943 /* keydown */
12944 keybd_event(0x41, 0, 0, 0);
12945 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
12946 DispatchMessage(&msg);
12947 ok_sequence(WmKeyPressNormal, "key press only", FALSE);
12949 key_state = GetAsyncKeyState(0x41);
12950 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
12952 key_state = GetKeyState(0x41);
12953 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
12955 /* keydown repeat */
12956 keybd_event(0x41, 0, 0, 0);
12957 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
12958 DispatchMessage(&msg);
12959 ok_sequence(WmKeyPressRepeat, "key press repeat", FALSE);
12961 key_state = GetAsyncKeyState(0x41);
12962 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
12964 key_state = GetKeyState(0x41);
12965 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
12967 /* keyup */
12968 keybd_event(0x41, 0, KEYEVENTF_KEYUP, 0);
12969 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
12970 DispatchMessage(&msg);
12971 ok_sequence(WmKeyReleaseNormal, "key release repeat", FALSE);
12973 key_state = GetAsyncKeyState(0x41);
12974 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
12976 key_state = GetKeyState(0x41);
12977 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
12979 /* set the key state in this thread */
12980 GetKeyboardState(keyboard_state);
12981 keyboard_state[0x41] = 0x80;
12982 SetKeyboardState(keyboard_state);
12984 key_state = GetAsyncKeyState(0x41);
12985 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
12987 /* keydown */
12988 keybd_event(0x41, 0, 0, 0);
12989 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
12990 DispatchMessage(&msg);
12991 ok_sequence(WmKeyPressRepeat, "key press after setkeyboardstate", TRUE);
12993 key_state = GetAsyncKeyState(0x41);
12994 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
12996 key_state = GetKeyState(0x41);
12997 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
12999 /* clear the key state in this thread */
13000 GetKeyboardState(keyboard_state);
13001 keyboard_state[0x41] = 0;
13002 SetKeyboardState(keyboard_state);
13004 key_state = GetAsyncKeyState(0x41);
13005 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13007 /* keyup */
13008 keybd_event(0x41, 0, KEYEVENTF_KEYUP, 0);
13009 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13010 DispatchMessage(&msg);
13011 ok_sequence(WmKeyReleaseOnly, "key release after setkeyboardstate", TRUE);
13013 key_state = GetAsyncKeyState(0x41);
13014 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13016 key_state = GetKeyState(0x41);
13017 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13019 DestroyWindow(test_window);
13020 flush_sequence();
13023 static const struct message WmHotkeyPressLWIN[] = {
13024 { WM_KEYDOWN, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED },
13025 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 1 },
13026 { WM_KEYDOWN, sent|wparam|lparam, VK_LWIN, 1 },
13027 { 0 }
13029 static const struct message WmHotkeyPress[] = {
13030 { WM_KEYDOWN, kbd_hook|lparam, 0, LLKHF_INJECTED },
13031 { WM_HOTKEY, sent|wparam, 5 },
13032 { 0 }
13034 static const struct message WmHotkeyRelease[] = {
13035 { WM_KEYUP, kbd_hook|lparam, 0, LLKHF_INJECTED|LLKHF_UP },
13036 { HCBT_KEYSKIPPED, hook|lparam|optional, 0, 0x80000001 },
13037 { WM_KEYUP, sent|lparam, 0, 0x80000001 },
13038 { 0 }
13040 static const struct message WmHotkeyReleaseLWIN[] = {
13041 { WM_KEYUP, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED|LLKHF_UP },
13042 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 0xc0000001 },
13043 { WM_KEYUP, sent|wparam|lparam, VK_LWIN, 0xc0000001 },
13044 { 0 }
13047 static int hotkey_letter;
13049 static LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
13051 struct recvd_message msg;
13053 if (nCode == HC_ACTION)
13055 KBDLLHOOKSTRUCT *kdbhookstruct = (KBDLLHOOKSTRUCT*)lParam;
13057 msg.message = wParam;
13058 msg.flags = kbd_hook|wparam|lparam;
13059 msg.wParam = kdbhookstruct->vkCode;
13060 msg.lParam = kdbhookstruct->flags;
13061 msg.descr = "KeyboardHookProc";
13062 add_message(&msg);
13064 if (wParam == WM_KEYUP || wParam == WM_KEYDOWN)
13066 ok(kdbhookstruct->vkCode == VK_LWIN || kdbhookstruct->vkCode == hotkey_letter,
13067 "unexpected keycode %x\n", kdbhookstruct->vkCode);
13071 return CallNextHookEx(hKBD_hook, nCode, wParam, lParam);
13074 static void test_hotkey(void)
13076 HWND test_window, taskbar_window;
13077 BOOL ret;
13078 MSG msg;
13080 SetLastError(0xdeadbeef);
13081 ret = UnregisterHotKey(NULL, 0);
13082 todo_wine ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13083 todo_wine ok(GetLastError() == ERROR_HOTKEY_NOT_REGISTERED, "unexpected error %d\n", GetLastError());
13085 if (ret == TRUE)
13087 skip("hotkeys not supported\n");
13088 return;
13091 test_window = CreateWindowEx(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
13092 100, 100, 200, 200, 0, 0, 0, NULL);
13094 flush_sequence();
13096 SetLastError(0xdeadbeef);
13097 ret = UnregisterHotKey(test_window, 0);
13098 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13099 ok(GetLastError() == ERROR_HOTKEY_NOT_REGISTERED, "unexpected error %d\n", GetLastError());
13101 /* Search for a Windows Key + letter combination that hasn't been registered */
13102 for (hotkey_letter = 0x41; hotkey_letter <= 0x51; hotkey_letter ++)
13104 SetLastError(0xdeadbeef);
13105 ret = RegisterHotKey(test_window, 5, MOD_WIN, hotkey_letter);
13107 if (ret == TRUE)
13109 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
13110 break;
13112 else
13114 ok(GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED, "unexpected error %d\n", GetLastError());
13118 if (hotkey_letter == 0x52)
13120 ok(0, "Couldn't find any free Windows Key + letter combination\n");
13121 goto end;
13124 hKBD_hook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProc, GetModuleHandle(NULL), 0);
13125 ok(hKBD_hook != NULL, "failed to install hook, err %i\n", GetLastError());
13127 /* Same key combination, different id */
13128 SetLastError(0xdeadbeef);
13129 ret = RegisterHotKey(test_window, 4, MOD_WIN, hotkey_letter);
13130 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13131 ok(GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED, "unexpected error %d\n", GetLastError());
13133 /* Same key combination, different window */
13134 SetLastError(0xdeadbeef);
13135 ret = RegisterHotKey(NULL, 5, MOD_WIN, hotkey_letter);
13136 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13137 ok(GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED, "unexpected error %d\n", GetLastError());
13139 /* Register the same hotkey twice */
13140 SetLastError(0xdeadbeef);
13141 ret = RegisterHotKey(test_window, 5, MOD_WIN, hotkey_letter);
13142 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13143 ok(GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED, "unexpected error %d\n", GetLastError());
13145 /* Window on another thread */
13146 taskbar_window = FindWindowA("Shell_TrayWnd", NULL);
13147 if (!taskbar_window)
13149 skip("no taskbar?\n");
13151 else
13153 SetLastError(0xdeadbeef);
13154 ret = RegisterHotKey(taskbar_window, 5, 0, hotkey_letter);
13155 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13156 ok(GetLastError() == ERROR_WINDOW_OF_OTHER_THREAD, "unexpected error %d\n", GetLastError());
13159 /* Inject the appropriate key sequence */
13160 keybd_event(VK_LWIN, 0, 0, 0);
13161 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE) ||
13162 PeekMessage(&msg, NULL, WM_HOTKEY, WM_HOTKEY, PM_REMOVE))
13163 DispatchMessage(&msg);
13164 ok_sequence(WmHotkeyPressLWIN, "window hotkey press LWIN", FALSE);
13166 keybd_event(hotkey_letter, 0, 0, 0);
13167 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE) ||
13168 PeekMessage(&msg, NULL, WM_HOTKEY, WM_HOTKEY, PM_REMOVE))
13170 if (msg.message == WM_HOTKEY)
13172 ok(msg.hwnd == test_window, "unexpected hwnd %p\n", msg.hwnd);
13173 ok(msg.lParam == MAKELPARAM(MOD_WIN, hotkey_letter), "unexpected WM_HOTKEY lparam %lx\n", msg.lParam);
13175 DispatchMessage(&msg);
13177 ok_sequence(WmHotkeyPress, "window hotkey press", FALSE);
13179 keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13180 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE) ||
13181 PeekMessage(&msg, NULL, WM_HOTKEY, WM_HOTKEY, PM_REMOVE))
13182 DispatchMessage(&msg);
13183 ok_sequence(WmHotkeyRelease, "window hotkey release", FALSE);
13185 keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
13186 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE) ||
13187 PeekMessage(&msg, NULL, WM_HOTKEY, WM_HOTKEY, PM_REMOVE))
13188 DispatchMessage(&msg);
13189 ok_sequence(WmHotkeyReleaseLWIN, "window hotkey release LWIN", FALSE);
13191 /* Unregister hotkey properly */
13192 SetLastError(0xdeadbeef);
13193 ret = UnregisterHotKey(test_window, 5);
13194 ok(ret == TRUE, "expected TRUE, got %i\n", ret);
13195 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
13197 /* Unregister hotkey again */
13198 SetLastError(0xdeadbeef);
13199 ret = UnregisterHotKey(test_window, 5);
13200 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13201 ok(GetLastError() == ERROR_HOTKEY_NOT_REGISTERED, "unexpected error %d\n", GetLastError());
13203 /* Register thread hotkey */
13204 SetLastError(0xdeadbeef);
13205 ret = RegisterHotKey(NULL, 5, MOD_WIN, hotkey_letter);
13206 ok(ret == TRUE, "expected TRUE, got %i\n", ret);
13207 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
13209 /* Inject the appropriate key sequence */
13210 keybd_event(VK_LWIN, 0, 0, 0);
13211 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE) ||
13212 PeekMessage(&msg, NULL, WM_HOTKEY, WM_HOTKEY, PM_REMOVE))
13214 ok(msg.hwnd != NULL, "unexpected thread message %x\n", msg.message);
13215 DispatchMessage(&msg);
13217 ok_sequence(WmHotkeyPressLWIN, "thread hotkey press LWIN", FALSE);
13219 keybd_event(hotkey_letter, 0, 0, 0);
13220 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE) ||
13221 PeekMessage(&msg, NULL, WM_HOTKEY, WM_HOTKEY, PM_REMOVE))
13223 if (msg.message == WM_HOTKEY)
13225 struct recvd_message message;
13226 ok(msg.hwnd == NULL, "unexpected hwnd %p\n", msg.hwnd);
13227 ok(msg.lParam == MAKELPARAM(MOD_WIN, hotkey_letter), "unexpected WM_HOTKEY lparam %lx\n", msg.lParam);
13228 message.message = msg.message;
13229 message.flags = sent|wparam|lparam;
13230 message.wParam = msg.wParam;
13231 message.lParam = msg.lParam;
13232 message.descr = "test_hotkey thread message";
13233 add_message(&message);
13235 else
13236 ok(msg.hwnd != NULL, "unexpected thread message %x\n", msg.message);
13237 DispatchMessage(&msg);
13239 ok_sequence(WmHotkeyPress, "thread hotkey press", FALSE);
13241 keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13242 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE) ||
13243 PeekMessage(&msg, NULL, WM_HOTKEY, WM_HOTKEY, PM_REMOVE))
13245 ok(msg.hwnd != NULL, "unexpected thread message %x\n", msg.message);
13246 DispatchMessage(&msg);
13248 ok_sequence(WmHotkeyRelease, "thread hotkey release", FALSE);
13250 keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
13251 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE) ||
13252 PeekMessage(&msg, NULL, WM_HOTKEY, WM_HOTKEY, PM_REMOVE))
13254 ok(msg.hwnd != NULL, "unexpected thread message %x\n", msg.message);
13255 DispatchMessage(&msg);
13257 ok_sequence(WmHotkeyReleaseLWIN, "thread hotkey release LWIN", FALSE);
13259 /* Unregister thread hotkey */
13260 SetLastError(0xdeadbeef);
13261 ret = UnregisterHotKey(NULL, 5);
13262 ok(ret == TRUE, "expected TRUE, got %i\n", ret);
13263 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
13265 UnhookWindowsHookEx(hKBD_hook);
13266 hKBD_hook = NULL;
13268 end:
13269 UnregisterHotKey(NULL, 5);
13270 UnregisterHotKey(test_window, 5);
13271 DestroyWindow(test_window);
13272 flush_sequence();
13275 START_TEST(msg)
13277 char **test_argv;
13278 BOOL ret;
13279 BOOL (WINAPI *pIsWinEventHookInstalled)(DWORD)= 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
13280 HMODULE hModuleImm32;
13281 BOOL (WINAPI *pImmDisableIME)(DWORD);
13283 int argc = winetest_get_mainargs( &test_argv );
13284 if (argc >= 3)
13286 unsigned int arg;
13287 /* Child process. */
13288 sscanf (test_argv[2], "%d", (unsigned int *) &arg);
13289 do_wait_idle_child( arg );
13290 return;
13293 init_procs();
13295 hModuleImm32 = LoadLibrary("imm32.dll");
13296 if (hModuleImm32) {
13297 pImmDisableIME = (void *)GetProcAddress(hModuleImm32, "ImmDisableIME");
13298 if (pImmDisableIME)
13299 pImmDisableIME(0);
13301 pImmDisableIME = NULL;
13302 FreeLibrary(hModuleImm32);
13304 if (!RegisterWindowClasses()) assert(0);
13306 if (pSetWinEventHook)
13308 hEvent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX,
13309 GetModuleHandleA(0), win_event_proc,
13310 0, GetCurrentThreadId(),
13311 WINEVENT_INCONTEXT);
13312 if (pIsWinEventHookInstalled && hEvent_hook)
13314 UINT event;
13315 for (event = EVENT_MIN; event <= EVENT_MAX; event++)
13316 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
13319 if (!hEvent_hook) win_skip( "no win event hook support\n" );
13321 cbt_hook_thread_id = GetCurrentThreadId();
13322 hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
13323 if (!hCBT_hook) win_skip( "cannot set global hook, will skip hook tests\n" );
13325 test_winevents();
13327 /* Fix message sequences before removing 4 lines below */
13328 #if 1
13329 if (pUnhookWinEvent && hEvent_hook)
13331 ret = pUnhookWinEvent(hEvent_hook);
13332 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
13333 pUnhookWinEvent = 0;
13335 hEvent_hook = 0;
13336 #endif
13338 test_SetParent();
13339 test_PostMessage();
13340 test_ShowWindow();
13341 test_PeekMessage();
13342 test_PeekMessage2();
13343 test_WaitForInputIdle( test_argv[0] );
13344 test_scrollwindowex();
13345 test_messages();
13346 test_setwindowpos();
13347 test_showwindow();
13348 invisible_parent_tests();
13349 test_mdi_messages();
13350 test_button_messages();
13351 test_static_messages();
13352 test_listbox_messages();
13353 test_combobox_messages();
13354 test_wmime_keydown_message();
13355 test_paint_messages();
13356 test_interthread_messages();
13357 test_message_conversion();
13358 test_accelerators();
13359 test_timers();
13360 test_timers_no_wnd();
13361 if (hCBT_hook) test_set_hook();
13362 test_DestroyWindow();
13363 test_DispatchMessage();
13364 test_SendMessageTimeout();
13365 test_edit_messages();
13366 test_quit_message();
13367 test_SetActiveWindow();
13369 if (!pTrackMouseEvent)
13370 win_skip("TrackMouseEvent is not available\n");
13371 else
13372 test_TrackMouseEvent();
13374 test_SetWindowRgn();
13375 test_sys_menu();
13376 test_dialog_messages();
13377 test_nullCallback();
13378 test_dbcs_wm_char();
13379 test_menu_messages();
13380 test_paintingloop();
13381 test_defwinproc();
13382 test_clipboard_viewers();
13383 test_keyflags();
13384 test_hotkey();
13385 /* keep it the last test, under Windows it tends to break the tests
13386 * which rely on active/foreground windows being correct.
13388 test_SetForegroundWindow();
13390 UnhookWindowsHookEx(hCBT_hook);
13391 if (pUnhookWinEvent && hEvent_hook)
13393 ret = pUnhookWinEvent(hEvent_hook);
13394 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
13395 SetLastError(0xdeadbeef);
13396 ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
13397 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
13398 GetLastError() == 0xdeadbeef, /* Win9x */
13399 "unexpected error %d\n", GetLastError());