quartz: Don't cast WSTR to BSTR, convert properly instead.
[wine/testsucceed.git] / dlls / user32 / tests / msg.c
blob714e57f4bcbfc5633920aa16690995eab8fafa84
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 0x0501 /* For WM_CHANGEUISTATE,QS_RAWINPUT */
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <stdio.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winnls.h"
35 #include "wine/test.h"
37 #define MDI_FIRST_CHILD_ID 2004
39 /* undocumented SWP flags - from SDK 3.1 */
40 #define SWP_NOCLIENTSIZE 0x0800
41 #define SWP_NOCLIENTMOVE 0x1000
42 #define SWP_STATECHANGED 0x8000
44 #define SW_NORMALNA 0xCC /* undoc. flag in MinMaximize */
46 #ifndef WM_KEYF1
47 #define WM_KEYF1 0x004d
48 #endif
50 #ifndef WM_SYSTIMER
51 #define WM_SYSTIMER 0x0118
52 #endif
54 #define WND_PARENT_ID 1
55 #define WND_POPUP_ID 2
56 #define WND_CHILD_ID 3
58 #ifndef WM_LBTRACKPOINT
59 #define WM_LBTRACKPOINT 0x0131
60 #endif
62 /* encoded DRAWITEMSTRUCT into an LPARAM */
63 typedef struct
65 union
67 struct
69 UINT type : 4; /* ODT_* flags */
70 UINT ctl_id : 4; /* Control ID */
71 UINT item_id : 4; /* Menu item ID */
72 UINT action : 4; /* ODA_* flags */
73 UINT state : 16; /* ODS_* flags */
74 } item;
75 LPARAM lp;
76 } u;
77 } DRAW_ITEM_STRUCT;
79 static BOOL test_DestroyWindow_flag;
80 static HWINEVENTHOOK hEvent_hook;
81 static HHOOK hCBT_hook;
82 static DWORD cbt_hook_thread_id;
84 static const WCHAR testWindowClassW[] =
85 { 'T','e','s','t','W','i','n','d','o','w','C','l','a','s','s','W',0 };
88 FIXME: add tests for these
89 Window Edge Styles (Win31/Win95/98 look), in order of precedence:
90 WS_EX_DLGMODALFRAME: double border, WS_CAPTION allowed
91 WS_THICKFRAME: thick border
92 WS_DLGFRAME: double border, WS_CAPTION not allowed (but possibly shown anyway)
93 WS_BORDER (default for overlapped windows): single black border
94 none (default for child (and popup?) windows): no border
97 typedef enum {
98 sent=0x1,
99 posted=0x2,
100 parent=0x4,
101 wparam=0x8,
102 lparam=0x10,
103 defwinproc=0x20,
104 beginpaint=0x40,
105 optional=0x80,
106 hook=0x100,
107 winevent_hook=0x200
108 } msg_flags_t;
110 struct message {
111 UINT message; /* the WM_* code */
112 msg_flags_t flags; /* message props */
113 WPARAM wParam; /* expected value of wParam */
114 LPARAM lParam; /* expected value of lParam */
115 WPARAM wp_mask; /* mask for wParam checks */
116 LPARAM lp_mask; /* mask for lParam checks */
119 struct recvd_message {
120 UINT message; /* the WM_* code */
121 msg_flags_t flags; /* message props */
122 HWND hwnd; /* window that received the message */
123 WPARAM wParam; /* expected value of wParam */
124 LPARAM lParam; /* expected value of lParam */
125 int line; /* source line where logged */
126 const char *descr; /* description for trace output */
127 char output[512]; /* trace output */
130 /* Empty message sequence */
131 static const struct message WmEmptySeq[] =
133 { 0 }
135 /* CreateWindow (for overlapped window, not initially visible) (16/32) */
136 static const struct message WmCreateOverlappedSeq[] = {
137 { HCBT_CREATEWND, hook },
138 { WM_GETMINMAXINFO, sent },
139 { WM_NCCREATE, sent },
140 { WM_NCCALCSIZE, sent|wparam, 0 },
141 { 0x0093, sent|defwinproc|optional },
142 { 0x0094, sent|defwinproc|optional },
143 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
144 { WM_CREATE, sent },
145 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
146 { 0 }
148 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
149 * for a not visible overlapped window.
151 static const struct message WmSWP_ShowOverlappedSeq[] = {
152 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
153 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
154 { WM_NCPAINT, sent|wparam|optional, 1 },
155 { WM_GETTEXT, sent|defwinproc|optional },
156 { WM_ERASEBKGND, sent|optional },
157 { HCBT_ACTIVATE, hook },
158 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
159 { WM_NOTIFYFORMAT, sent|optional },
160 { WM_QUERYUISTATE, sent|optional },
161 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
162 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x: SWP_NOSENDCHANGING */
163 { WM_ACTIVATEAPP, sent|wparam, 1 },
164 { WM_NCACTIVATE, sent },
165 { WM_GETTEXT, sent|defwinproc|optional },
166 { WM_ACTIVATE, sent|wparam, 1 },
167 { HCBT_SETFOCUS, hook },
168 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
169 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
170 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
171 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
172 { WM_GETTEXT, sent|optional },
173 { WM_NCPAINT, sent|wparam|optional, 1 },
174 { WM_GETTEXT, sent|defwinproc|optional },
175 { WM_ERASEBKGND, sent|optional },
176 /* Win9x adds SWP_NOZORDER below */
177 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
178 { WM_GETTEXT, sent|optional },
179 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
180 { WM_NCPAINT, sent|wparam|optional, 1 },
181 { WM_ERASEBKGND, sent|optional },
182 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
183 { WM_SYNCPAINT, sent|optional },
184 { WM_GETTITLEBARINFOEX, sent|optional },
185 { WM_PAINT, sent|optional },
186 { WM_NCPAINT, sent|beginpaint|optional },
187 { WM_GETTEXT, sent|defwinproc|optional },
188 { WM_ERASEBKGND, sent|beginpaint|optional },
189 { 0 }
191 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
192 * for a visible overlapped window.
194 static const struct message WmSWP_HideOverlappedSeq[] = {
195 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
196 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
197 { HCBT_ACTIVATE, hook|optional },
198 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
199 { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
200 { WM_NCACTIVATE, sent|optional },
201 { WM_ACTIVATE, sent|optional },
202 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
203 { 0 }
206 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
207 * for a visible overlapped window.
209 static const struct message WmSWP_ResizeSeq[] = {
210 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
211 { WM_GETMINMAXINFO, sent|defwinproc },
212 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
213 { WM_NCPAINT, sent|optional },
214 { WM_GETTEXT, sent|defwinproc|optional },
215 { WM_ERASEBKGND, sent|optional },
216 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
217 { WM_SIZE, sent|defwinproc|optional },
218 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
219 { WM_NCPAINT, sent|optional },
220 { WM_GETTEXT, sent|defwinproc|optional },
221 { WM_ERASEBKGND, sent|optional },
222 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
223 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
224 { 0 }
227 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
228 * for a visible popup window.
230 static const struct message WmSWP_ResizePopupSeq[] = {
231 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
232 { WM_GETMINMAXINFO, sent|defwinproc|optional }, /* Win9x */
233 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
234 { WM_NCPAINT, sent|optional },
235 { WM_GETTEXT, sent|defwinproc|optional },
236 { WM_ERASEBKGND, sent|optional },
237 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
238 { WM_SIZE, sent|defwinproc|wparam|optional, SIZE_RESTORED },
239 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
240 { WM_NCPAINT, sent|optional },
241 { WM_GETTEXT, sent|defwinproc|optional },
242 { WM_ERASEBKGND, sent|optional },
243 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
244 { 0 }
247 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
248 * for a visible overlapped window.
250 static const struct message WmSWP_MoveSeq[] = {
251 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE },
252 { WM_NCPAINT, sent|optional },
253 { WM_GETTEXT, sent|defwinproc|optional },
254 { WM_ERASEBKGND, sent|optional },
255 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
256 { WM_MOVE, sent|defwinproc|wparam, 0 },
257 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
258 { 0 }
260 /* Resize with SetWindowPos(SWP_NOZORDER)
261 * for a visible overlapped window
262 * SWP_NOZORDER is stripped by the logging code
264 static const struct message WmSWP_ResizeNoZOrder[] = {
265 { WM_WINDOWPOSCHANGING, sent|wparam, /*SWP_NOZORDER|*/SWP_NOACTIVATE },
266 { WM_GETMINMAXINFO, sent|defwinproc },
267 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
268 { WM_NCPAINT, sent|optional },
269 { WM_GETTEXT, sent|defwinproc|optional },
270 { WM_ERASEBKGND, sent|optional },
271 { WM_WINDOWPOSCHANGED, sent|wparam|optional, /*SWP_NOZORDER|*/SWP_NOACTIVATE, 0,
272 SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
273 { WM_MOVE, sent|defwinproc|optional },
274 { WM_SIZE, sent|defwinproc|optional },
275 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
276 { WM_NCPAINT, sent|optional }, /* Win9x doesn't send it */
277 { WM_GETTEXT, sent|defwinproc|optional }, /* Win9x doesn't send it */
278 { WM_ERASEBKGND, sent|optional }, /* Win9x doesn't send it */
279 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
280 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
281 { 0 }
284 /* Switch visible mdi children */
285 static const struct message WmSwitchChild[] = {
286 /* Switch MDI child */
287 { WM_MDIACTIVATE, sent },/* in the MDI client */
288 { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 1st MDI child */
289 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
290 { WM_CHILDACTIVATE, sent },/* in the 1st MDI child */
291 /* Deactivate 2nd MDI child */
292 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
293 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
294 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
295 /* Preparing for maximize and maximaze the 1st MDI child */
296 { WM_GETMINMAXINFO, sent|defwinproc }, /* in the 1st MDI child */
297 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED }, /* in the 1st MDI child */
298 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
299 { WM_CHILDACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
300 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 1st MDI child */
301 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED }, /* in the 1st MDI child */
302 /* Lock redraw 2nd MDI child */
303 { WM_SETREDRAW, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
304 { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
305 /* Restore 2nd MDI child */
306 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },/* in the 2nd MDI child */
307 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
308 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
309 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 2nd MDI child */
310 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED }, /* in the 2nd MDI child */
311 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
312 /* Redraw 2nd MDI child */
313 { WM_SETREDRAW, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
314 /* Redraw MDI frame */
315 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },/* in MDI frame */
316 { WM_NCCALCSIZE, sent|wparam, 1 },/* in MDI frame */
317 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in MDI frame */
318 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in MDI frame */
319 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
320 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
321 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
322 { HCBT_SETFOCUS, hook },
323 { WM_KILLFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
324 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },/* in the 1st MDI child */
325 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
326 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
327 { WM_SETFOCUS, sent },/* in the MDI client */
328 { HCBT_SETFOCUS, hook },
329 { WM_KILLFOCUS, sent },/* in the MDI client */
330 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
331 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 }, /* in the 1st MDI child */
332 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
333 { WM_SETFOCUS, sent|defwinproc }, /* in the 1st MDI child */
334 { WM_MDIACTIVATE, sent|defwinproc },/* in the 1st MDI child */
335 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* in the 1st MDI child */
336 { 0 }
339 /* Switch visible not maximized mdi children */
340 static const struct message WmSwitchNotMaximizedChild[] = {
341 /* Switch not maximized MDI child */
342 { WM_MDIACTIVATE, sent },/* in the MDI client */
343 { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 2nd MDI child */
344 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
345 { WM_CHILDACTIVATE, sent },/* in the 2nd MDI child */
346 /* Deactivate 1st MDI child */
347 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
348 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
349 /* Activate 2nd MDI child */
350 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE}, /* in the 2nd MDI child */
351 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 2nd MDI child */
352 { HCBT_SETFOCUS, hook }, /* in the 1st MDI child */
353 { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
354 { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
355 { WM_IME_SETCONTEXT, sent|optional }, /* in the MDI client */
356 { WM_SETFOCUS, sent, 0 }, /* in the MDI client */
357 { HCBT_SETFOCUS, hook },
358 { WM_KILLFOCUS, sent }, /* in the MDI client */
359 { WM_IME_SETCONTEXT, sent|optional }, /* in the MDI client */
360 { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
361 { WM_SETFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
362 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
363 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in the 2nd MDI child */
364 { 0 }
368 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
369 SWP_NOZORDER|SWP_FRAMECHANGED)
370 * for a visible overlapped window with WS_CLIPCHILDREN style set.
372 static const struct message WmSWP_FrameChanged_clip[] = {
373 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
374 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
375 { WM_NCPAINT, sent|parent|optional }, /* wparam != 1 */
376 { WM_GETTEXT, sent|parent|defwinproc|optional },
377 { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
378 { WM_NCPAINT, sent }, /* wparam != 1 */
379 { WM_ERASEBKGND, sent },
380 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
381 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
382 { WM_PAINT, sent },
383 { 0 }
385 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|
386 SWP_NOZORDER|SWP_FRAMECHANGED)
387 * for a visible overlapped window.
389 static const struct message WmSWP_FrameChangedDeferErase[] = {
390 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
391 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
392 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
393 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
394 { WM_PAINT, sent|parent|optional },
395 { WM_NCPAINT, sent|beginpaint|parent|optional }, /* wparam != 1 */
396 { WM_GETTEXT, sent|beginpaint|parent|defwinproc|optional },
397 { WM_PAINT, sent },
398 { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
399 { WM_ERASEBKGND, sent|beginpaint|optional },
400 { 0 }
403 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
404 SWP_NOZORDER|SWP_FRAMECHANGED)
405 * for a visible overlapped window without WS_CLIPCHILDREN style set.
407 static const struct message WmSWP_FrameChanged_noclip[] = {
408 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
409 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
410 { WM_NCPAINT, sent|parent|optional }, /* wparam != 1 */
411 { WM_GETTEXT, sent|parent|defwinproc|optional },
412 { WM_ERASEBKGND, sent|parent|optional },
413 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
414 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
415 { WM_PAINT, sent },
416 { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
417 { WM_ERASEBKGND, sent|beginpaint|optional },
418 { 0 }
421 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
422 static const struct message WmShowOverlappedSeq[] = {
423 { WM_SHOWWINDOW, sent|wparam, 1 },
424 { WM_NCPAINT, sent|wparam|optional, 1 },
425 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
426 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
427 { WM_NCPAINT, sent|wparam|optional, 1 },
428 { WM_GETTEXT, sent|defwinproc|optional },
429 { WM_ERASEBKGND, sent|optional },
430 { HCBT_ACTIVATE, hook },
431 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
432 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
433 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
434 { WM_NCPAINT, sent|wparam|optional, 1 },
435 { WM_ACTIVATEAPP, sent|wparam, 1 },
436 { WM_NCACTIVATE, sent|wparam, 1 },
437 { WM_GETTEXT, sent|defwinproc|optional },
438 { WM_ACTIVATE, sent|wparam, 1 },
439 { HCBT_SETFOCUS, hook },
440 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
441 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
442 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
443 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
444 { WM_GETTEXT, sent|optional },
445 { WM_NCPAINT, sent|wparam|optional, 1 },
446 { WM_GETTEXT, sent|defwinproc|optional },
447 { WM_ERASEBKGND, sent|optional },
448 /* Win9x adds SWP_NOZORDER below */
449 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
450 { WM_NCCALCSIZE, sent|optional },
451 { WM_GETTEXT, sent|optional },
452 { WM_NCPAINT, sent|optional },
453 { WM_ERASEBKGND, sent|optional },
454 { WM_SYNCPAINT, sent|optional },
455 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
456 * messages. Does that mean that CreateWindow doesn't set initial
457 * window dimensions for overlapped windows?
459 { WM_SIZE, sent },
460 { WM_MOVE, sent },
461 #endif
462 { WM_PAINT, sent|optional },
463 { WM_NCPAINT, sent|beginpaint|optional },
464 { 0 }
466 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible overlapped window */
467 static const struct message WmShowMaxOverlappedSeq[] = {
468 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
469 { WM_GETMINMAXINFO, sent },
470 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
471 { WM_GETMINMAXINFO, sent|defwinproc },
472 { WM_NCCALCSIZE, sent|wparam, TRUE },
473 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
474 { HCBT_ACTIVATE, hook },
475 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
476 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
477 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
478 { WM_ACTIVATEAPP, sent|wparam, 1 },
479 { WM_NCACTIVATE, sent|wparam, 1 },
480 { WM_GETTEXT, sent|defwinproc|optional },
481 { WM_ACTIVATE, sent|wparam, 1 },
482 { HCBT_SETFOCUS, hook },
483 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
484 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
485 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
486 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
487 { WM_GETTEXT, sent|optional },
488 { WM_NCPAINT, sent|wparam|optional, 1 },
489 { WM_GETTEXT, sent|defwinproc|optional },
490 { WM_ERASEBKGND, sent|optional },
491 /* Win9x adds SWP_NOZORDER below */
492 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
493 { WM_MOVE, sent|defwinproc },
494 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
495 { WM_GETTEXT, sent|optional },
496 { WM_NCCALCSIZE, sent|optional },
497 { WM_NCPAINT, sent|optional },
498 { WM_ERASEBKGND, sent|optional },
499 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
500 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
501 { WM_SYNCPAINT, sent|optional },
502 { WM_GETTITLEBARINFOEX, sent|optional },
503 { WM_PAINT, sent|optional },
504 { WM_NCPAINT, sent|beginpaint|optional },
505 { WM_ERASEBKGND, sent|beginpaint|optional },
506 { 0 }
508 /* ShowWindow(SW_RESTORE) for a not visible maximized overlapped window */
509 static const struct message WmShowRestoreMaxOverlappedSeq[] = {
510 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
511 { WM_GETTEXT, sent|optional },
512 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
513 { WM_GETMINMAXINFO, sent|defwinproc },
514 { WM_NCCALCSIZE, sent|wparam, TRUE },
515 { WM_NCPAINT, sent|optional },
516 { WM_GETTEXT, sent|defwinproc|optional },
517 { WM_ERASEBKGND, sent|optional },
518 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
519 { WM_MOVE, sent|defwinproc|optional },
520 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
521 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
522 { WM_NCPAINT, sent|optional },
523 { WM_ERASEBKGND, sent|optional },
524 { WM_PAINT, sent|optional },
525 { WM_GETTITLEBARINFOEX, sent|optional },
526 { WM_NCPAINT, sent|beginpaint|optional },
527 { WM_ERASEBKGND, sent|beginpaint|optional },
528 { 0 }
530 /* ShowWindow(SW_RESTORE) for a not visible minimized overlapped window */
531 static const struct message WmShowRestoreMinOverlappedSeq[] = {
532 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
533 { WM_QUERYOPEN, sent|optional },
534 { WM_GETTEXT, sent|optional },
535 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED|SWP_NOCOPYBITS },
536 { WM_GETMINMAXINFO, sent|defwinproc },
537 { WM_NCCALCSIZE, sent|wparam, TRUE },
538 { HCBT_ACTIVATE, hook },
539 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
540 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
541 { WM_ACTIVATEAPP, sent|wparam, 1 },
542 { WM_NCACTIVATE, sent|wparam, 1 },
543 { WM_GETTEXT, sent|defwinproc|optional },
544 { WM_ACTIVATE, sent|wparam, 1 },
545 { HCBT_SETFOCUS, hook },
546 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
547 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
548 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
549 { WM_GETTEXT, sent|optional },
550 { WM_NCPAINT, sent|wparam|optional, 1 },
551 { WM_GETTEXT, sent|defwinproc|optional },
552 { WM_ERASEBKGND, sent },
553 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_STATECHANGED|SWP_FRAMECHANGED|SWP_NOCOPYBITS },
554 { WM_MOVE, sent|defwinproc },
555 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
556 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
557 { WM_NCPAINT, sent|wparam|optional, 1 },
558 { WM_ERASEBKGND, sent|optional },
559 { WM_ACTIVATE, sent|wparam, 1 },
560 { WM_GETTEXT, sent|optional },
561 { WM_PAINT, sent|optional },
562 { WM_GETTITLEBARINFOEX, sent|optional },
563 { WM_NCPAINT, sent|beginpaint|optional },
564 { WM_ERASEBKGND, sent|beginpaint|optional },
565 { 0 }
567 /* ShowWindow(SW_SHOWMINIMIZED) for a not visible overlapped window */
568 static const struct message WmShowMinOverlappedSeq[] = {
569 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
570 { HCBT_SETFOCUS, hook },
571 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
572 { WM_KILLFOCUS, sent },
573 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
574 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
575 { WM_GETTEXT, sent|optional },
576 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCOPYBITS|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
577 { WM_GETMINMAXINFO, sent|defwinproc },
578 { WM_NCCALCSIZE, sent|wparam, TRUE },
579 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
580 { WM_NCPAINT, sent|optional },
581 { WM_GETTEXT, sent|defwinproc|optional },
582 { WM_WINDOWPOSCHANGED, sent },
583 { WM_MOVE, sent|defwinproc },
584 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
585 { WM_NCCALCSIZE, sent|optional },
586 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
587 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
588 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
589 { WM_NCACTIVATE, sent|wparam, 0 },
590 { WM_GETTEXT, sent|defwinproc|optional },
591 { WM_ACTIVATE, sent },
592 { WM_ACTIVATEAPP, sent|wparam, 0 },
594 /* Vista sometimes restores the window right away... */
595 { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
596 { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
597 { HCBT_MINMAX, hook|optional|lparam, 0, SW_RESTORE },
598 { WM_QUERYOPEN, sent|optional },
599 { WM_WINDOWPOSCHANGING, sent|optional|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
600 { WM_GETMINMAXINFO, sent|optional|defwinproc },
601 { WM_NCCALCSIZE, sent|optional|wparam, TRUE },
602 { HCBT_ACTIVATE, hook|optional },
603 { WM_ACTIVATEAPP, sent|optional|wparam, 1 },
604 { WM_NCACTIVATE, sent|optional },
605 { WM_GETTEXT, sent|optional },
606 { WM_ACTIVATE, sent|optional|wparam, 1 },
607 { HCBT_SETFOCUS, hook|optional },
608 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
609 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
610 { WM_SETFOCUS, sent|optional },
611 { WM_NCPAINT, sent|optional },
612 { WM_GETTEXT, sent|defwinproc|optional },
613 { WM_ERASEBKGND, sent|optional },
614 { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
615 { WM_MOVE, sent|defwinproc|optional },
616 { WM_SIZE, sent|defwinproc|optional|wparam, SIZE_RESTORED },
617 { WM_ACTIVATE, sent|optional|wparam, 1 },
618 { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
619 { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
621 { WM_PAINT, sent|optional },
622 { WM_NCPAINT, sent|beginpaint|optional },
623 { WM_ERASEBKGND, sent|beginpaint|optional },
624 { 0 }
626 /* ShowWindow(SW_HIDE) for a visible overlapped window */
627 static const struct message WmHideOverlappedSeq[] = {
628 { WM_SHOWWINDOW, sent|wparam, 0 },
629 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
630 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
631 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
632 { WM_SIZE, sent|optional }, /* XP doesn't send it */
633 { WM_MOVE, sent|optional }, /* XP doesn't send it */
634 { WM_NCACTIVATE, sent|wparam|optional, 0 },
635 { WM_ACTIVATE, sent|wparam|optional, 0 },
636 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
637 { HCBT_SETFOCUS, hook|optional },
638 { WM_KILLFOCUS, sent|wparam, 0 },
639 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
640 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
641 { 0 }
643 /* DestroyWindow for a visible overlapped window */
644 static const struct message WmDestroyOverlappedSeq[] = {
645 { HCBT_DESTROYWND, hook },
646 { 0x0090, sent|optional },
647 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
648 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
649 { 0x0090, sent|optional },
650 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
651 { WM_NCACTIVATE, sent|optional|wparam, 0 },
652 { WM_ACTIVATE, sent|optional },
653 { WM_ACTIVATEAPP, sent|optional|wparam, 0 },
654 { WM_KILLFOCUS, sent|optional|wparam, 0 },
655 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
656 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
657 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
658 { WM_DESTROY, sent },
659 { WM_NCDESTROY, sent },
660 { 0 }
662 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
663 static const struct message WmCreateMaxPopupSeq[] = {
664 { HCBT_CREATEWND, hook },
665 { WM_NCCREATE, sent },
666 { WM_NCCALCSIZE, sent|wparam, 0 },
667 { WM_CREATE, sent },
668 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
669 { WM_SIZE, sent|wparam, SIZE_RESTORED },
670 { WM_MOVE, sent },
671 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
672 { WM_GETMINMAXINFO, sent },
673 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
674 { WM_NCCALCSIZE, sent|wparam, TRUE },
675 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
676 { WM_MOVE, sent|defwinproc },
677 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
678 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
679 { WM_SHOWWINDOW, sent|wparam, 1 },
680 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
681 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
682 { HCBT_ACTIVATE, hook },
683 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
684 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
685 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
686 { WM_NCPAINT, sent|wparam|optional, 1 },
687 { WM_ERASEBKGND, sent|optional },
688 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_NOMOVE|SWP_NOSIZE },
689 { WM_ACTIVATEAPP, sent|wparam, 1 },
690 { WM_NCACTIVATE, sent },
691 { WM_ACTIVATE, sent|wparam, 1 },
692 { HCBT_SETFOCUS, hook },
693 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
694 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
695 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
696 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
697 { WM_GETTEXT, sent|optional },
698 { WM_SYNCPAINT, sent|wparam|optional, 4 },
699 { WM_NCPAINT, sent|wparam|optional, 1 },
700 { WM_ERASEBKGND, sent|optional },
701 { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
702 { WM_ERASEBKGND, sent|defwinproc|optional },
703 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
704 { 0 }
706 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
707 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
708 { HCBT_CREATEWND, hook },
709 { WM_NCCREATE, sent },
710 { WM_NCCALCSIZE, sent|wparam, 0 },
711 { WM_CREATE, sent },
712 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
713 { WM_SIZE, sent|wparam, SIZE_RESTORED },
714 { WM_MOVE, sent },
715 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
716 { WM_GETMINMAXINFO, sent },
717 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
718 { WM_NCCALCSIZE, sent|wparam, TRUE },
719 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
720 { WM_MOVE, sent|defwinproc },
721 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
722 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
723 { 0 }
725 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
726 static const struct message WmShowMaxPopupResizedSeq[] = {
727 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
728 { WM_GETMINMAXINFO, sent },
729 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
730 { WM_NCCALCSIZE, sent|wparam, TRUE },
731 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
732 { HCBT_ACTIVATE, hook },
733 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
734 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
735 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
736 { WM_NCPAINT, sent|wparam|optional, 1 },
737 { WM_ERASEBKGND, sent|optional },
738 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
739 { WM_ACTIVATEAPP, sent|wparam, 1 },
740 { WM_NCACTIVATE, sent },
741 { WM_ACTIVATE, sent|wparam, 1 },
742 { HCBT_SETFOCUS, hook },
743 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
744 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
745 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
746 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
747 { WM_GETTEXT, sent|optional },
748 { WM_NCPAINT, sent|wparam|optional, 1 },
749 { WM_ERASEBKGND, sent|optional },
750 { WM_WINDOWPOSCHANGED, sent },
751 /* WinNT4.0 sends WM_MOVE */
752 { WM_MOVE, sent|defwinproc|optional },
753 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
754 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
755 { 0 }
757 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
758 static const struct message WmShowMaxPopupSeq[] = {
759 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
760 { WM_GETMINMAXINFO, sent },
761 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
762 { WM_NCCALCSIZE, sent|wparam, TRUE },
763 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
764 { HCBT_ACTIVATE, hook },
765 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
766 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
767 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
768 { WM_ACTIVATEAPP, sent|wparam, 1 },
769 { WM_NCACTIVATE, sent },
770 { WM_ACTIVATE, sent|wparam, 1 },
771 { HCBT_SETFOCUS, hook },
772 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
773 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
774 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
775 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
776 { WM_GETTEXT, sent|optional },
777 { WM_SYNCPAINT, sent|wparam|optional, 4 },
778 { WM_NCPAINT, sent|wparam|optional, 1 },
779 { WM_ERASEBKGND, sent|optional },
780 { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
781 { WM_ERASEBKGND, sent|defwinproc|optional },
782 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
783 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
784 { 0 }
786 /* CreateWindow(WS_VISIBLE) for popup window */
787 static const struct message WmCreatePopupSeq[] = {
788 { HCBT_CREATEWND, hook },
789 { WM_NCCREATE, sent },
790 { WM_NCCALCSIZE, sent|wparam, 0 },
791 { WM_CREATE, sent },
792 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
793 { WM_SIZE, sent|wparam, SIZE_RESTORED },
794 { WM_MOVE, sent },
795 { WM_SHOWWINDOW, sent|wparam, 1 },
796 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
797 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
798 { HCBT_ACTIVATE, hook },
799 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
800 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
801 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
802 { WM_NCPAINT, sent|wparam|optional, 1 },
803 { WM_ERASEBKGND, sent|optional },
804 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
805 { WM_ACTIVATEAPP, sent|wparam, 1 },
806 { WM_NCACTIVATE, sent },
807 { WM_ACTIVATE, sent|wparam, 1 },
808 { HCBT_SETFOCUS, hook },
809 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
810 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
811 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
812 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
813 { WM_GETTEXT, sent|optional },
814 { WM_SYNCPAINT, sent|wparam|optional, 4 },
815 { WM_NCPAINT, sent|wparam|optional, 1 },
816 { WM_ERASEBKGND, sent|optional },
817 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
818 { 0 }
820 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
821 static const struct message WmShowVisMaxPopupSeq[] = {
822 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
823 { WM_GETMINMAXINFO, sent },
824 { WM_GETTEXT, sent|optional },
825 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
826 { WM_GETTEXT, sent|optional },
827 { WM_NCCALCSIZE, sent|wparam, TRUE },
828 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
829 { WM_NCPAINT, sent|wparam|optional, 1 },
830 { WM_ERASEBKGND, sent|optional },
831 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
832 { WM_MOVE, sent|defwinproc },
833 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
834 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
835 { 0 }
837 /* CreateWindow (for a child popup window, not initially visible) */
838 static const struct message WmCreateChildPopupSeq[] = {
839 { HCBT_CREATEWND, hook },
840 { WM_NCCREATE, sent },
841 { WM_NCCALCSIZE, sent|wparam, 0 },
842 { WM_CREATE, sent },
843 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
844 { WM_SIZE, sent|wparam, SIZE_RESTORED },
845 { WM_MOVE, sent },
846 { 0 }
848 /* CreateWindow (for a popup window, not initially visible,
849 * which sets WS_VISIBLE in WM_CREATE handler)
851 static const struct message WmCreateInvisiblePopupSeq[] = {
852 { HCBT_CREATEWND, hook },
853 { WM_NCCREATE, sent },
854 { WM_NCCALCSIZE, sent|wparam, 0 },
855 { WM_CREATE, sent },
856 { WM_STYLECHANGING, sent },
857 { WM_STYLECHANGED, sent },
858 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
859 { WM_SIZE, sent|wparam, SIZE_RESTORED },
860 { WM_MOVE, sent },
861 { 0 }
863 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
864 * for a popup window with WS_VISIBLE style set
866 static const struct message WmShowVisiblePopupSeq_2[] = {
867 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
868 { 0 }
870 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
871 * for a popup window with WS_VISIBLE style set
873 static const struct message WmShowVisiblePopupSeq_3[] = {
874 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
875 { HCBT_ACTIVATE, hook },
876 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
877 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
878 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
879 { WM_NCACTIVATE, sent },
880 { WM_ACTIVATE, sent|wparam, 1 },
881 { HCBT_SETFOCUS, hook },
882 { WM_KILLFOCUS, sent|parent },
883 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
884 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
885 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
886 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
887 { WM_SETFOCUS, sent|defwinproc },
888 { WM_GETTEXT, sent|optional },
889 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_SHOWWINDOW },
890 { 0 }
892 /* CreateWindow (for child window, not initially visible) */
893 static const struct message WmCreateChildSeq[] = {
894 { HCBT_CREATEWND, hook },
895 { WM_NCCREATE, sent },
896 /* child is inserted into parent's child list after WM_NCCREATE returns */
897 { WM_NCCALCSIZE, sent|wparam, 0 },
898 { WM_CREATE, sent },
899 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
900 { WM_SIZE, sent|wparam, SIZE_RESTORED },
901 { WM_MOVE, sent },
902 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
903 { 0 }
905 /* CreateWindow (for maximized child window, not initially visible) */
906 static const struct message WmCreateMaximizedChildSeq[] = {
907 { HCBT_CREATEWND, hook },
908 { WM_NCCREATE, sent },
909 { WM_NCCALCSIZE, sent|wparam, 0 },
910 { WM_CREATE, sent },
911 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
912 { WM_SIZE, sent|wparam, SIZE_RESTORED },
913 { WM_MOVE, sent },
914 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
915 { WM_GETMINMAXINFO, sent },
916 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
917 { WM_NCCALCSIZE, sent|wparam, 1 },
918 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
919 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
920 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
921 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
922 { 0 }
924 /* CreateWindow (for a child window, initially visible) */
925 static const struct message WmCreateVisibleChildSeq[] = {
926 { HCBT_CREATEWND, hook },
927 { WM_NCCREATE, sent },
928 /* child is inserted into parent's child list after WM_NCCREATE returns */
929 { WM_NCCALCSIZE, sent|wparam, 0 },
930 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
931 { WM_CREATE, sent },
932 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
933 { WM_SIZE, sent|wparam, SIZE_RESTORED },
934 { WM_MOVE, sent },
935 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
936 { WM_SHOWWINDOW, sent|wparam, 1 },
937 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
938 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
939 { WM_ERASEBKGND, sent|parent|optional },
940 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
941 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
942 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
943 { 0 }
945 /* ShowWindow(SW_SHOW) for a not visible child window */
946 static const struct message WmShowChildSeq[] = {
947 { WM_SHOWWINDOW, sent|wparam, 1 },
948 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
949 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
950 { WM_ERASEBKGND, sent|parent|optional },
951 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
952 { 0 }
954 /* ShowWindow(SW_HIDE) for a visible child window */
955 static const struct message WmHideChildSeq[] = {
956 { WM_SHOWWINDOW, sent|wparam, 0 },
957 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
958 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
959 { WM_ERASEBKGND, sent|parent|optional },
960 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
961 { 0 }
963 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
964 static const struct message WmHideChildSeq2[] = {
965 { WM_SHOWWINDOW, sent|wparam, 0 },
966 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
967 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
968 { WM_ERASEBKGND, sent|parent|optional },
969 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
970 { 0 }
972 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
973 * for a not visible child window
975 static const struct message WmShowChildSeq_2[] = {
976 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
977 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
978 { WM_CHILDACTIVATE, sent },
979 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
980 { 0 }
982 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
983 * for a not visible child window
985 static const struct message WmShowChildSeq_3[] = {
986 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
987 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
988 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
989 { 0 }
991 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
992 * for a visible child window with a caption
994 static const struct message WmShowChildSeq_4[] = {
995 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
996 { WM_CHILDACTIVATE, sent },
997 { 0 }
999 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
1000 static const struct message WmShowChildInvisibleParentSeq_1[] = {
1001 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
1002 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
1003 { WM_NCCALCSIZE, sent|wparam, 1 },
1004 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1005 { WM_CHILDACTIVATE, sent|optional },
1006 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
1007 { WM_MOVE, sent|defwinproc },
1008 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1009 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1010 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1011 /* FIXME: Wine creates an icon/title window while Windows doesn't */
1012 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1013 { WM_GETTEXT, sent|optional },
1014 { 0 }
1016 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
1017 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
1018 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
1019 { 0 }
1021 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1022 static const struct message WmShowChildInvisibleParentSeq_2[] = {
1023 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1024 { WM_GETMINMAXINFO, sent },
1025 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
1026 { WM_NCCALCSIZE, sent|wparam, 1 },
1027 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1028 { WM_CHILDACTIVATE, sent },
1029 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
1030 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
1031 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1032 { 0 }
1034 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1035 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
1036 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1037 { 0 }
1039 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1040 static const struct message WmShowChildInvisibleParentSeq_3[] = {
1041 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1042 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
1043 { WM_NCCALCSIZE, sent|wparam, 1 },
1044 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1045 { WM_CHILDACTIVATE, sent },
1046 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1047 { WM_MOVE, sent|defwinproc },
1048 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1049 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1050 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1051 /* FIXME: Wine creates an icon/title window while Windows doesn't */
1052 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1053 { WM_GETTEXT, sent|optional },
1054 { 0 }
1056 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1057 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
1058 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1059 { 0 }
1061 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1062 static const struct message WmShowChildInvisibleParentSeq_4[] = {
1063 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1064 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
1065 { WM_NCCALCSIZE, sent|wparam, 1 },
1066 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1067 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1068 { WM_MOVE, sent|defwinproc },
1069 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1070 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1071 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1072 /* FIXME: Wine creates an icon/title window while Windows doesn't */
1073 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1074 { WM_GETTEXT, sent|optional },
1075 { 0 }
1077 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1078 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
1079 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1080 { 0 }
1082 /* ShowWindow(SW_SHOW) for child with invisible parent */
1083 static const struct message WmShowChildInvisibleParentSeq_5[] = {
1084 { WM_SHOWWINDOW, sent|wparam, 1 },
1085 { 0 }
1087 /* ShowWindow(SW_HIDE) for child with invisible parent */
1088 static const struct message WmHideChildInvisibleParentSeq[] = {
1089 { WM_SHOWWINDOW, sent|wparam, 0 },
1090 { 0 }
1092 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
1093 static const struct message WmShowChildInvisibleParentSeq_6[] = {
1094 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1095 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1096 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1097 { 0 }
1099 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
1100 static const struct message WmHideChildInvisibleParentSeq_2[] = {
1101 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1102 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1103 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1104 { 0 }
1106 /* DestroyWindow for a visible child window */
1107 static const struct message WmDestroyChildSeq[] = {
1108 { HCBT_DESTROYWND, hook },
1109 { 0x0090, sent|optional },
1110 { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1111 { WM_SHOWWINDOW, sent|wparam, 0 },
1112 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1113 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1114 { WM_ERASEBKGND, sent|parent|optional },
1115 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1116 { HCBT_SETFOCUS, hook }, /* set focus to a parent */
1117 { WM_KILLFOCUS, sent },
1118 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1119 { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
1120 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1121 { WM_SETFOCUS, sent|parent },
1122 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1123 { WM_DESTROY, sent },
1124 { WM_DESTROY, sent|optional }, /* some other (IME?) window */
1125 { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
1126 { WM_NCDESTROY, sent },
1127 { 0 }
1129 /* visible child window destroyed by thread exit */
1130 static const struct message WmExitThreadSeq[] = {
1131 { WM_NCDESTROY, sent }, /* actually in grandchild */
1132 { WM_PAINT, sent|parent },
1133 { WM_ERASEBKGND, sent|parent|beginpaint },
1134 { 0 }
1136 /* DestroyWindow for a visible child window with invisible parent */
1137 static const struct message WmDestroyInvisibleChildSeq[] = {
1138 { HCBT_DESTROYWND, hook },
1139 { 0x0090, sent|optional },
1140 { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1141 { WM_SHOWWINDOW, sent|wparam, 0 },
1142 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1143 { WM_DESTROY, sent },
1144 { WM_NCDESTROY, sent },
1145 { 0 }
1147 /* Moving the mouse in nonclient area */
1148 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
1149 { WM_NCHITTEST, sent },
1150 { WM_SETCURSOR, sent },
1151 { WM_NCMOUSEMOVE, posted },
1152 { 0 }
1154 /* Moving the mouse in client area */
1155 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
1156 { WM_NCHITTEST, sent },
1157 { WM_SETCURSOR, sent },
1158 { WM_MOUSEMOVE, posted },
1159 { 0 }
1161 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1162 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
1163 { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
1164 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
1165 { WM_GETMINMAXINFO, sent|defwinproc },
1166 { WM_ENTERSIZEMOVE, sent|defwinproc },
1167 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1168 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1169 { WM_MOVE, sent|defwinproc },
1170 { WM_EXITSIZEMOVE, sent|defwinproc },
1171 { 0 }
1173 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1174 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
1175 { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
1176 { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
1177 { WM_GETMINMAXINFO, sent|defwinproc },
1178 { WM_ENTERSIZEMOVE, sent|defwinproc },
1179 { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
1180 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1181 { WM_GETMINMAXINFO, sent|defwinproc },
1182 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1183 { WM_NCPAINT, sent|defwinproc|wparam, 1 },
1184 { WM_GETTEXT, sent|defwinproc },
1185 { WM_ERASEBKGND, sent|defwinproc },
1186 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1187 { WM_MOVE, sent|defwinproc },
1188 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1189 { WM_EXITSIZEMOVE, sent|defwinproc },
1190 { 0 }
1192 /* Resizing child window with MoveWindow (32) */
1193 static const struct message WmResizingChildWithMoveWindowSeq[] = {
1194 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1195 { WM_NCCALCSIZE, sent|wparam, 1 },
1196 { WM_ERASEBKGND, sent|parent|optional },
1197 { WM_ERASEBKGND, sent|optional },
1198 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
1199 { WM_MOVE, sent|defwinproc },
1200 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1201 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1202 { 0 }
1204 /* Clicking on inactive button */
1205 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
1206 { WM_NCHITTEST, sent },
1207 { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
1208 { WM_MOUSEACTIVATE, sent },
1209 { WM_MOUSEACTIVATE, sent|parent|defwinproc },
1210 { WM_SETCURSOR, sent },
1211 { WM_SETCURSOR, sent|parent|defwinproc },
1212 { WM_LBUTTONDOWN, posted },
1213 { WM_KILLFOCUS, posted|parent },
1214 { WM_SETFOCUS, posted },
1215 { WM_CTLCOLORBTN, posted|parent },
1216 { BM_SETSTATE, posted },
1217 { WM_CTLCOLORBTN, posted|parent },
1218 { WM_LBUTTONUP, posted },
1219 { BM_SETSTATE, posted },
1220 { WM_CTLCOLORBTN, posted|parent },
1221 { WM_COMMAND, posted|parent },
1222 { 0 }
1224 /* Reparenting a button (16/32) */
1225 /* The last child (button) reparented gets topmost for its new parent. */
1226 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
1227 { WM_SHOWWINDOW, sent|wparam, 0 },
1228 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1229 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1230 { WM_ERASEBKGND, sent|parent },
1231 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1232 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
1233 { WM_CHILDACTIVATE, sent },
1234 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
1235 { WM_MOVE, sent|defwinproc },
1236 { WM_SHOWWINDOW, sent|wparam, 1 },
1237 { 0 }
1239 /* Creation of a custom dialog (32) */
1240 static const struct message WmCreateCustomDialogSeq[] = {
1241 { HCBT_CREATEWND, hook },
1242 { WM_GETMINMAXINFO, sent },
1243 { WM_NCCREATE, sent },
1244 { WM_NCCALCSIZE, sent|wparam, 0 },
1245 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1246 { WM_CREATE, sent },
1247 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1248 { WM_NOTIFYFORMAT, sent|optional },
1249 { WM_QUERYUISTATE, sent|optional },
1250 { WM_WINDOWPOSCHANGING, sent|optional },
1251 { WM_GETMINMAXINFO, sent|optional },
1252 { WM_NCCALCSIZE, sent|optional },
1253 { WM_WINDOWPOSCHANGED, sent|optional },
1254 { WM_SHOWWINDOW, sent|wparam, 1 },
1255 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1256 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1257 { HCBT_ACTIVATE, hook },
1258 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1261 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1263 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1265 { WM_NCACTIVATE, sent },
1266 { WM_GETTEXT, sent|optional|defwinproc },
1267 { WM_GETTEXT, sent|optional|defwinproc },
1268 { WM_GETTEXT, sent|optional|defwinproc },
1269 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1270 { WM_ACTIVATE, sent|wparam, 1 },
1271 { WM_GETTEXT, sent|optional },
1272 { WM_KILLFOCUS, sent|parent },
1273 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1274 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1275 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1276 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1277 { WM_SETFOCUS, sent },
1278 { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1279 { WM_NCPAINT, sent|wparam, 1 },
1280 { WM_GETTEXT, sent|optional|defwinproc },
1281 { WM_GETTEXT, sent|optional|defwinproc },
1282 { WM_ERASEBKGND, sent },
1283 { WM_CTLCOLORDLG, sent|optional|defwinproc },
1284 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1285 { WM_GETTEXT, sent|optional },
1286 { WM_GETTEXT, sent|optional },
1287 { WM_NCCALCSIZE, sent|optional },
1288 { WM_NCPAINT, sent|optional },
1289 { WM_GETTEXT, sent|optional|defwinproc },
1290 { WM_GETTEXT, sent|optional|defwinproc },
1291 { WM_ERASEBKGND, sent|optional },
1292 { WM_CTLCOLORDLG, sent|optional|defwinproc },
1293 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1294 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1295 { WM_MOVE, sent },
1296 { 0 }
1298 /* Calling EndDialog for a custom dialog (32) */
1299 static const struct message WmEndCustomDialogSeq[] = {
1300 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1301 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1302 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1303 { WM_GETTEXT, sent|optional },
1304 { HCBT_ACTIVATE, hook },
1305 { WM_NCACTIVATE, sent|wparam, 0 },
1306 { WM_GETTEXT, sent|optional|defwinproc },
1307 { WM_GETTEXT, sent|optional|defwinproc },
1308 { WM_ACTIVATE, sent|wparam, 0 },
1309 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1310 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1311 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1312 { WM_GETTEXT, sent|optional|defwinproc },
1313 { WM_GETTEXT, sent|optional|defwinproc },
1314 { HCBT_SETFOCUS, hook },
1315 { WM_KILLFOCUS, sent },
1316 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1317 { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1318 { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1319 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1320 { WM_SETFOCUS, sent|parent|defwinproc },
1321 { 0 }
1323 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1324 static const struct message WmShowCustomDialogSeq[] = {
1325 { WM_SHOWWINDOW, sent|wparam, 1 },
1326 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1327 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1328 { HCBT_ACTIVATE, hook },
1329 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1331 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1333 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1334 { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1335 { WM_NCACTIVATE, sent },
1336 { WM_ACTIVATE, sent|wparam, 1 },
1337 { WM_GETTEXT, sent|optional },
1339 { WM_KILLFOCUS, sent|parent },
1340 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1341 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1342 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1343 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1344 { WM_SETFOCUS, sent },
1345 { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1346 { WM_NCPAINT, sent|wparam, 1 },
1347 { WM_ERASEBKGND, sent },
1348 { WM_CTLCOLORDLG, sent|defwinproc },
1349 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1350 { 0 }
1352 /* Creation and destruction of a modal dialog (32) */
1353 static const struct message WmModalDialogSeq[] = {
1354 { WM_CANCELMODE, sent|parent },
1355 { HCBT_SETFOCUS, hook },
1356 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1357 { WM_KILLFOCUS, sent|parent },
1358 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1359 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1360 { WM_ENABLE, sent|parent|wparam, 0 },
1361 { HCBT_CREATEWND, hook },
1362 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1363 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1364 { WM_SETFONT, sent },
1365 { WM_INITDIALOG, sent },
1366 { WM_CHANGEUISTATE, sent|optional },
1367 { WM_UPDATEUISTATE, sent|optional },
1368 { WM_SHOWWINDOW, sent },
1369 { HCBT_ACTIVATE, hook },
1370 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1371 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1372 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1373 { WM_NCACTIVATE, sent },
1374 { WM_GETTEXT, sent|optional },
1375 { WM_ACTIVATE, sent|wparam, 1 },
1376 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1377 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1378 { WM_NCPAINT, sent|optional },
1379 { WM_GETTEXT, sent|optional },
1380 { WM_ERASEBKGND, sent|optional },
1381 { WM_CTLCOLORDLG, sent|optional },
1382 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1383 { WM_GETTEXT, sent|optional },
1384 { WM_NCCALCSIZE, sent|optional },
1385 { WM_NCPAINT, sent|optional },
1386 { WM_GETTEXT, sent|optional },
1387 { WM_ERASEBKGND, sent|optional },
1388 { WM_CTLCOLORDLG, sent|optional },
1389 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1390 { WM_PAINT, sent|optional },
1391 { WM_CTLCOLORBTN, sent|optional },
1392 { WM_GETTITLEBARINFOEX, sent|optional },
1393 { WM_ENTERIDLE, sent|parent|optional },
1394 { WM_ENTERIDLE, sent|parent|optional },
1395 { WM_ENTERIDLE, sent|parent|optional },
1396 { WM_ENTERIDLE, sent|parent|optional },
1397 { WM_ENTERIDLE, sent|parent|optional },
1398 { WM_ENTERIDLE, sent|parent|optional },
1399 { WM_ENTERIDLE, sent|parent|optional },
1400 { WM_ENTERIDLE, sent|parent|optional },
1401 { WM_ENTERIDLE, sent|parent|optional },
1402 { WM_ENTERIDLE, sent|parent|optional },
1403 { WM_ENTERIDLE, sent|parent|optional },
1404 { WM_ENTERIDLE, sent|parent|optional },
1405 { WM_ENTERIDLE, sent|parent|optional },
1406 { WM_ENTERIDLE, sent|parent|optional },
1407 { WM_ENTERIDLE, sent|parent|optional },
1408 { WM_ENTERIDLE, sent|parent|optional },
1409 { WM_ENTERIDLE, sent|parent|optional },
1410 { WM_ENTERIDLE, sent|parent|optional },
1411 { WM_ENTERIDLE, sent|parent|optional },
1412 { WM_ENTERIDLE, sent|parent|optional },
1413 { WM_TIMER, sent },
1414 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1415 { WM_ENABLE, sent|parent|wparam, 1 },
1416 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1417 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1418 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1419 { WM_GETTEXT, sent|optional },
1420 { HCBT_ACTIVATE, hook },
1421 { WM_NCACTIVATE, sent|wparam, 0 },
1422 { WM_GETTEXT, sent|optional },
1423 { WM_ACTIVATE, sent|wparam, 0 },
1424 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1425 { WM_WINDOWPOSCHANGING, sent|optional },
1426 { WM_WINDOWPOSCHANGED, sent|optional },
1427 { HCBT_SETFOCUS, hook },
1428 { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1429 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1430 { WM_SETFOCUS, sent|parent|defwinproc },
1431 { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1432 { HCBT_DESTROYWND, hook },
1433 { 0x0090, sent|optional },
1434 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1435 { WM_DESTROY, sent },
1436 { WM_NCDESTROY, sent },
1437 { 0 }
1439 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1440 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1441 /* (inside dialog proc, handling WM_INITDIALOG) */
1442 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1443 { WM_NCCALCSIZE, sent },
1444 { WM_NCACTIVATE, sent|parent|wparam, 0 },
1445 { WM_GETTEXT, sent|defwinproc },
1446 { WM_ACTIVATE, sent|parent|wparam, 0 },
1447 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1448 { WM_WINDOWPOSCHANGING, sent|parent },
1449 { WM_NCACTIVATE, sent|wparam, 1 },
1450 { WM_ACTIVATE, sent|wparam, 1 },
1451 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1452 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1453 /* (setting focus) */
1454 { WM_SHOWWINDOW, sent|wparam, 1 },
1455 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1456 { WM_NCPAINT, sent },
1457 { WM_GETTEXT, sent|defwinproc },
1458 { WM_ERASEBKGND, sent },
1459 { WM_CTLCOLORDLG, sent|defwinproc },
1460 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1461 { WM_PAINT, sent },
1462 /* (bunch of WM_CTLCOLOR* for each control) */
1463 { WM_PAINT, sent|parent },
1464 { WM_ENTERIDLE, sent|parent|wparam, 0 },
1465 { WM_SETCURSOR, sent|parent },
1466 { 0 }
1468 /* SetMenu for NonVisible windows with size change*/
1469 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1470 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1471 { WM_NCCALCSIZE, sent|wparam, 1 },
1472 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1473 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1474 { WM_MOVE, sent|defwinproc },
1475 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1476 { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1477 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1478 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1479 { WM_GETTEXT, sent|optional },
1480 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1481 { 0 }
1483 /* SetMenu for NonVisible windows with no size change */
1484 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1485 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1486 { WM_NCCALCSIZE, sent|wparam, 1 },
1487 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1488 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1489 { 0 }
1491 /* SetMenu for Visible windows with size change */
1492 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1493 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1494 { WM_NCCALCSIZE, sent|wparam, 1 },
1495 { 0x0093, sent|defwinproc|optional },
1496 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1497 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1498 { 0x0093, sent|defwinproc|optional },
1499 { 0x0093, sent|defwinproc|optional },
1500 { 0x0091, sent|defwinproc|optional },
1501 { 0x0092, sent|defwinproc|optional },
1502 { WM_GETTEXT, sent|defwinproc|optional },
1503 { WM_ERASEBKGND, sent|optional },
1504 { WM_ACTIVATE, sent|optional },
1505 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1506 { WM_MOVE, sent|defwinproc },
1507 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1508 { 0x0093, sent|optional },
1509 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1510 { 0x0093, sent|defwinproc|optional },
1511 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1512 { 0x0093, sent|defwinproc|optional },
1513 { 0x0093, sent|defwinproc|optional },
1514 { 0x0091, sent|defwinproc|optional },
1515 { 0x0092, sent|defwinproc|optional },
1516 { WM_ERASEBKGND, sent|optional },
1517 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1518 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1519 { 0 }
1521 /* SetMenu for Visible windows with no size change */
1522 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1523 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1524 { WM_NCCALCSIZE, sent|wparam, 1 },
1525 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1526 { WM_GETTEXT, sent|defwinproc|optional },
1527 { WM_ERASEBKGND, sent|optional },
1528 { WM_ACTIVATE, sent|optional },
1529 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1530 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1531 { 0 }
1533 /* DrawMenuBar for a visible window */
1534 static const struct message WmDrawMenuBarSeq[] =
1536 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1537 { WM_NCCALCSIZE, sent|wparam, 1 },
1538 { 0x0093, sent|defwinproc|optional },
1539 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1540 { 0x0093, sent|defwinproc|optional },
1541 { 0x0093, sent|defwinproc|optional },
1542 { 0x0091, sent|defwinproc|optional },
1543 { 0x0092, sent|defwinproc|optional },
1544 { WM_GETTEXT, sent|defwinproc|optional },
1545 { WM_ERASEBKGND, sent|optional },
1546 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1547 { 0x0093, sent|optional },
1548 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1549 { 0 }
1552 static const struct message WmSetRedrawFalseSeq[] =
1554 { WM_SETREDRAW, sent|wparam, 0 },
1555 { 0 }
1558 static const struct message WmSetRedrawTrueSeq[] =
1560 { WM_SETREDRAW, sent|wparam, 1 },
1561 { 0 }
1564 static const struct message WmEnableWindowSeq_1[] =
1566 { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1567 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1568 { HCBT_SETFOCUS, hook|optional },
1569 { WM_KILLFOCUS, sent|optional },
1570 { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1571 { 0 }
1574 static const struct message WmEnableWindowSeq_2[] =
1576 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1577 { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1578 { 0 }
1581 static const struct message WmGetScrollRangeSeq[] =
1583 { SBM_GETRANGE, sent },
1584 { 0 }
1586 static const struct message WmGetScrollInfoSeq[] =
1588 { SBM_GETSCROLLINFO, sent },
1589 { 0 }
1591 static const struct message WmSetScrollRangeSeq[] =
1593 /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1594 sends SBM_SETSCROLLINFO.
1596 { SBM_SETSCROLLINFO, sent },
1597 { 0 }
1599 /* SetScrollRange for a window without a non-client area */
1600 static const struct message WmSetScrollRangeHSeq_empty[] =
1602 { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1603 { 0 }
1605 static const struct message WmSetScrollRangeVSeq_empty[] =
1607 { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1608 { 0 }
1610 static const struct message WmSetScrollRangeHVSeq[] =
1612 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1613 { WM_NCCALCSIZE, sent|wparam, 1 },
1614 { WM_GETTEXT, sent|defwinproc|optional },
1615 { WM_ERASEBKGND, sent|optional },
1616 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1617 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1618 { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1619 { 0 }
1621 /* SetScrollRange for a window with a non-client area */
1622 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1624 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1625 { WM_NCCALCSIZE, sent|wparam, 1 },
1626 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1627 { WM_NCPAINT, sent|optional },
1628 { WM_STYLECHANGING, sent|defwinproc|optional },
1629 { WM_STYLECHANGED, sent|defwinproc|optional },
1630 { WM_STYLECHANGING, sent|defwinproc|optional },
1631 { WM_STYLECHANGED, sent|defwinproc|optional },
1632 { WM_STYLECHANGING, sent|defwinproc|optional },
1633 { WM_STYLECHANGED, sent|defwinproc|optional },
1634 { WM_STYLECHANGING, sent|defwinproc|optional },
1635 { WM_STYLECHANGED, sent|defwinproc|optional },
1636 { WM_GETTEXT, sent|defwinproc|optional },
1637 { WM_GETTEXT, sent|defwinproc|optional },
1638 { WM_ERASEBKGND, sent|optional },
1639 { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1640 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOCLIENTSIZE },
1641 { WM_SIZE, sent|defwinproc|optional },
1642 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1643 { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1644 { WM_GETTEXT, sent|optional },
1645 { WM_GETTEXT, sent|optional },
1646 { WM_GETTEXT, sent|optional },
1647 { WM_GETTEXT, sent|optional },
1648 { 0 }
1650 /* test if we receive the right sequence of messages */
1651 /* after calling ShowWindow( SW_SHOWNA) */
1652 static const struct message WmSHOWNAChildInvisParInvis[] = {
1653 { WM_SHOWWINDOW, sent|wparam, 1 },
1654 { 0 }
1656 static const struct message WmSHOWNAChildVisParInvis[] = {
1657 { WM_SHOWWINDOW, sent|wparam, 1 },
1658 { 0 }
1660 static const struct message WmSHOWNAChildVisParVis[] = {
1661 { WM_SHOWWINDOW, sent|wparam, 1 },
1662 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1663 { 0 }
1665 static const struct message WmSHOWNAChildInvisParVis[] = {
1666 { WM_SHOWWINDOW, sent|wparam, 1 },
1667 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1668 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1669 { WM_ERASEBKGND, sent|optional },
1670 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1671 { 0 }
1673 static const struct message WmSHOWNATopVisible[] = {
1674 { WM_SHOWWINDOW, sent|wparam, 1 },
1675 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1676 { WM_NCPAINT, sent|wparam|optional, 1 },
1677 { WM_GETTEXT, sent|defwinproc|optional },
1678 { WM_ERASEBKGND, sent|optional },
1679 { WM_WINDOWPOSCHANGED, sent|optional },
1680 { 0 }
1682 static const struct message WmSHOWNATopInvisible[] = {
1683 { WM_NOTIFYFORMAT, sent|optional },
1684 { WM_QUERYUISTATE, sent|optional },
1685 { WM_WINDOWPOSCHANGING, sent|optional },
1686 { WM_GETMINMAXINFO, sent|optional },
1687 { WM_NCCALCSIZE, sent|optional },
1688 { WM_WINDOWPOSCHANGED, sent|optional },
1689 { WM_SHOWWINDOW, sent|wparam, 1 },
1690 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1691 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1692 { WM_NCPAINT, sent|wparam|optional, 1 },
1693 { WM_GETTEXT, sent|defwinproc|optional },
1694 { WM_ERASEBKGND, sent|optional },
1695 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1696 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1697 { WM_NCPAINT, sent|wparam|optional, 1 },
1698 { WM_ERASEBKGND, sent|optional },
1699 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1700 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1701 { WM_MOVE, sent },
1702 { 0 }
1705 static int after_end_dialog, test_def_id;
1706 static int sequence_cnt, sequence_size;
1707 static struct recvd_message* sequence;
1708 static int log_all_parent_messages;
1709 static int paint_loop_done;
1711 /* user32 functions */
1712 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1713 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
1714 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1715 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
1716 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1717 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1718 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1719 /* kernel32 functions */
1720 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1722 static void init_procs(void)
1724 HMODULE user32 = GetModuleHandleA("user32.dll");
1725 HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1727 #define GET_PROC(dll, func) \
1728 p ## func = (void*)GetProcAddress(dll, #func); \
1729 if(!p ## func) { \
1730 trace("GetProcAddress(%s) failed\n", #func); \
1733 GET_PROC(user32, GetAncestor)
1734 GET_PROC(user32, GetMenuInfo)
1735 GET_PROC(user32, NotifyWinEvent)
1736 GET_PROC(user32, SetMenuInfo)
1737 GET_PROC(user32, SetWinEventHook)
1738 GET_PROC(user32, TrackMouseEvent)
1739 GET_PROC(user32, UnhookWinEvent)
1741 GET_PROC(kernel32, GetCPInfoExA)
1743 #undef GET_PROC
1746 static const char *get_winpos_flags(UINT flags)
1748 static char buffer[300];
1750 buffer[0] = 0;
1751 #define DUMP(flag) do { if (flags & flag) { strcat( buffer, "|" #flag ); flags &= ~flag; } } while(0)
1752 DUMP( SWP_SHOWWINDOW );
1753 DUMP( SWP_HIDEWINDOW );
1754 DUMP( SWP_NOACTIVATE );
1755 DUMP( SWP_FRAMECHANGED );
1756 DUMP( SWP_NOCOPYBITS );
1757 DUMP( SWP_NOOWNERZORDER );
1758 DUMP( SWP_NOSENDCHANGING );
1759 DUMP( SWP_DEFERERASE );
1760 DUMP( SWP_ASYNCWINDOWPOS );
1761 DUMP( SWP_NOZORDER );
1762 DUMP( SWP_NOREDRAW );
1763 DUMP( SWP_NOSIZE );
1764 DUMP( SWP_NOMOVE );
1765 DUMP( SWP_NOCLIENTSIZE );
1766 DUMP( SWP_NOCLIENTMOVE );
1767 if (flags) sprintf(buffer + strlen(buffer),"|0x%04x", flags);
1768 return buffer + 1;
1769 #undef DUMP
1772 static BOOL ignore_message( UINT message )
1774 /* these are always ignored */
1775 return (message >= 0xc000 ||
1776 message == WM_GETICON ||
1777 message == WM_GETOBJECT ||
1778 message == WM_TIMECHANGE ||
1779 message == WM_DISPLAYCHANGE ||
1780 message == WM_DEVICECHANGE ||
1781 message == WM_DWMNCRENDERINGCHANGED);
1785 #define add_message(msg) add_message_(__LINE__,msg);
1786 static void add_message_(int line, const struct recvd_message *msg)
1788 struct recvd_message *seq;
1790 if (!sequence)
1792 sequence_size = 10;
1793 sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof(*sequence) );
1795 if (sequence_cnt == sequence_size)
1797 sequence_size *= 2;
1798 sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof(*sequence) );
1800 assert(sequence);
1802 seq = &sequence[sequence_cnt];
1803 seq->hwnd = msg->hwnd;
1804 seq->message = msg->message;
1805 seq->flags = msg->flags;
1806 seq->wParam = msg->wParam;
1807 seq->lParam = msg->lParam;
1808 seq->line = line;
1809 seq->descr = msg->descr;
1810 seq->output[0] = 0;
1812 if (msg->descr)
1814 if (msg->flags & hook)
1816 static const char * const CBT_code_name[10] =
1818 "HCBT_MOVESIZE",
1819 "HCBT_MINMAX",
1820 "HCBT_QS",
1821 "HCBT_CREATEWND",
1822 "HCBT_DESTROYWND",
1823 "HCBT_ACTIVATE",
1824 "HCBT_CLICKSKIPPED",
1825 "HCBT_KEYSKIPPED",
1826 "HCBT_SYSCOMMAND",
1827 "HCBT_SETFOCUS"
1829 const char *code_name = (msg->message <= HCBT_SETFOCUS) ? CBT_code_name[msg->message] : "Unknown";
1831 sprintf( seq->output, "%s: hook %d (%s) wp %08lx lp %08lx",
1832 msg->descr, msg->message, code_name, msg->wParam, msg->lParam );
1834 else if (msg->flags & winevent_hook)
1836 sprintf( seq->output, "%s: winevent %p %08x %08lx %08lx",
1837 msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1839 else
1841 switch (msg->message)
1843 case WM_WINDOWPOSCHANGING:
1844 case WM_WINDOWPOSCHANGED:
1846 WINDOWPOS *winpos = (WINDOWPOS *)msg->lParam;
1848 sprintf( seq->output, "%s: %p WM_WINDOWPOS%s wp %08lx lp %08lx after %p x %d y %d cx %d cy %d flags %s",
1849 msg->descr, msg->hwnd,
1850 (msg->message == WM_WINDOWPOSCHANGING) ? "CHANGING" : "CHANGED",
1851 msg->wParam, msg->lParam, winpos->hwndInsertAfter,
1852 winpos->x, winpos->y, winpos->cx, winpos->cy,
1853 get_winpos_flags(winpos->flags) );
1855 /* Log only documented flags, win2k uses 0x1000 and 0x2000
1856 * in the high word for internal purposes
1858 seq->wParam = winpos->flags & 0xffff;
1859 /* We are not interested in the flags that don't match under XP and Win9x */
1860 seq->wParam &= ~SWP_NOZORDER;
1861 break;
1864 case WM_DRAWITEM:
1866 DRAW_ITEM_STRUCT di;
1867 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)msg->lParam;
1869 sprintf( seq->output, "%s: %p WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x",
1870 msg->descr, msg->hwnd, dis->CtlType, dis->CtlID,
1871 dis->itemID, dis->itemAction, dis->itemState);
1873 di.u.lp = 0;
1874 di.u.item.type = dis->CtlType;
1875 di.u.item.ctl_id = dis->CtlID;
1876 if (dis->CtlType == ODT_LISTBOX ||
1877 dis->CtlType == ODT_COMBOBOX ||
1878 dis->CtlType == ODT_MENU)
1879 di.u.item.item_id = dis->itemID;
1880 di.u.item.action = dis->itemAction;
1881 di.u.item.state = dis->itemState;
1883 seq->lParam = di.u.lp;
1884 break;
1886 default:
1887 if (msg->message >= 0xc000) return; /* ignore registered messages */
1888 sprintf( seq->output, "%s: %p %04x wp %08lx lp %08lx",
1889 msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1891 if (msg->flags & (sent|posted|parent|defwinproc|beginpaint))
1892 sprintf( seq->output + strlen(seq->output), " (flags %x)", msg->flags );
1896 sequence_cnt++;
1899 /* try to make sure pending X events have been processed before continuing */
1900 static void flush_events(void)
1902 MSG msg;
1903 int diff = 200;
1904 int min_timeout = 100;
1905 DWORD time = GetTickCount() + diff;
1907 while (diff > 0)
1909 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1910 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1911 diff = time - GetTickCount();
1915 static void flush_sequence(void)
1917 HeapFree(GetProcessHeap(), 0, sequence);
1918 sequence = 0;
1919 sequence_cnt = sequence_size = 0;
1922 static void dump_sequence(const struct message *expected, const char *context, const char *file, int line)
1924 const struct recvd_message *actual = sequence;
1925 unsigned int count = 0;
1927 trace_(file, line)("Failed sequence %s:\n", context );
1928 while (expected->message && actual->message)
1930 if (actual->output[0])
1932 if (expected->flags & hook)
1934 trace_(file, line)( " %u: expected: hook %04x - actual: %s\n",
1935 count, expected->message, actual->output );
1937 else if (expected->flags & winevent_hook)
1939 trace_(file, line)( " %u: expected: winevent %04x - actual: %s\n",
1940 count, expected->message, actual->output );
1942 else
1944 trace_(file, line)( " %u: expected: msg %04x - actual: %s\n",
1945 count, expected->message, actual->output );
1949 if (expected->message == actual->message)
1951 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) &&
1952 (expected->flags & optional))
1954 /* don't match messages if their defwinproc status differs */
1955 expected++;
1957 else
1959 expected++;
1960 actual++;
1963 /* silently drop winevent messages if there is no support for them */
1964 else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1965 expected++;
1966 else
1968 expected++;
1969 actual++;
1971 count++;
1974 /* optional trailing messages */
1975 while (expected->message && ((expected->flags & optional) ||
1976 ((expected->flags & winevent_hook) && !hEvent_hook)))
1978 trace_(file, line)( " %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1979 expected++;
1980 count++;
1983 if (expected->message)
1985 trace_(file, line)( " %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1986 return;
1989 while (actual->message && actual->output[0])
1991 trace_(file, line)( " %u: expected: nothing - actual: %s\n", count, actual->output );
1992 actual++;
1993 count++;
1997 #define ok_sequence( exp, contx, todo) \
1998 ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
2001 static void ok_sequence_(const struct message *expected_list, const char *context, int todo,
2002 const char *file, int line)
2004 static const struct recvd_message end_of_sequence;
2005 const struct message *expected = expected_list;
2006 const struct recvd_message *actual;
2007 int failcount = 0, dump = 0;
2008 unsigned int count = 0;
2010 add_message(&end_of_sequence);
2012 actual = sequence;
2014 while (expected->message && actual->message)
2016 if (expected->message == actual->message)
2018 if (expected->flags & wparam)
2020 if (((expected->wParam ^ actual->wParam) & ~expected->wp_mask) && todo)
2022 todo_wine {
2023 failcount ++;
2024 if (strcmp(winetest_platform, "wine")) dump++;
2025 ok_( file, line) (FALSE,
2026 "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2027 context, count, expected->message, expected->wParam, actual->wParam);
2030 else
2032 ok_( file, line)( ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) == 0,
2033 "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2034 context, count, expected->message, expected->wParam, actual->wParam);
2035 if ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) dump++;
2039 if (expected->flags & lparam)
2041 if (((expected->lParam ^ actual->lParam) & ~expected->lp_mask) && todo)
2043 todo_wine {
2044 failcount ++;
2045 if (strcmp(winetest_platform, "wine")) dump++;
2046 ok_( file, line) (FALSE,
2047 "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2048 context, count, expected->message, expected->lParam, actual->lParam);
2051 else
2053 ok_( file, line)(((expected->lParam ^ actual->lParam) & ~expected->lp_mask) == 0,
2054 "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2055 context, count, expected->message, expected->lParam, actual->lParam);
2056 if ((expected->lParam ^ actual->lParam) & ~expected->lp_mask) dump++;
2059 if ((expected->flags & optional) &&
2060 ((expected->flags ^ actual->flags) & (defwinproc|parent)))
2062 /* don't match optional messages if their defwinproc or parent status differs */
2063 expected++;
2064 count++;
2065 continue;
2067 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
2069 todo_wine {
2070 failcount ++;
2071 if (strcmp(winetest_platform, "wine")) dump++;
2072 ok_( file, line) (FALSE,
2073 "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2074 context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2077 else
2079 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
2080 "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2081 context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2082 if ((expected->flags & defwinproc) != (actual->flags & defwinproc)) dump++;
2085 ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
2086 "%s: %u: the msg 0x%04x should %shave been sent by BeginPaint\n",
2087 context, count, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
2088 if ((expected->flags & beginpaint) != (actual->flags & beginpaint)) dump++;
2090 ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
2091 "%s: %u: the msg 0x%04x should have been %s\n",
2092 context, count, expected->message, (expected->flags & posted) ? "posted" : "sent");
2093 if ((expected->flags & (sent|posted)) != (actual->flags & (sent|posted))) dump++;
2095 ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
2096 "%s: %u: the msg 0x%04x was expected in %s\n",
2097 context, count, expected->message, (expected->flags & parent) ? "parent" : "child");
2098 if ((expected->flags & parent) != (actual->flags & parent)) dump++;
2100 ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
2101 "%s: %u: the msg 0x%04x should have been sent by a hook\n",
2102 context, count, expected->message);
2103 if ((expected->flags & hook) != (actual->flags & hook)) dump++;
2105 ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
2106 "%s: %u: the msg 0x%04x should have been sent by a winevent hook\n",
2107 context, count, expected->message);
2108 if ((expected->flags & winevent_hook) != (actual->flags & winevent_hook)) dump++;
2110 expected++;
2111 actual++;
2113 /* silently drop hook messages if there is no support for them */
2114 else if ((expected->flags & optional) ||
2115 ((expected->flags & hook) && !hCBT_hook) ||
2116 ((expected->flags & winevent_hook) && !hEvent_hook))
2117 expected++;
2118 else if (todo)
2120 failcount++;
2121 todo_wine {
2122 if (strcmp(winetest_platform, "wine")) dump++;
2123 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2124 context, count, expected->message, actual->message);
2126 goto done;
2128 else
2130 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2131 context, count, expected->message, actual->message);
2132 dump++;
2133 expected++;
2134 actual++;
2136 count++;
2139 /* skip all optional trailing messages */
2140 while (expected->message && ((expected->flags & optional) ||
2141 ((expected->flags & hook) && !hCBT_hook) ||
2142 ((expected->flags & winevent_hook) && !hEvent_hook)))
2143 expected++;
2145 if (todo)
2147 todo_wine {
2148 if (expected->message || actual->message) {
2149 failcount++;
2150 if (strcmp(winetest_platform, "wine")) dump++;
2151 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2152 context, count, expected->message, actual->message);
2156 else
2158 if (expected->message || actual->message)
2160 dump++;
2161 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2162 context, count, expected->message, actual->message);
2165 if( todo && !failcount) /* succeeded yet marked todo */
2166 todo_wine {
2167 if (!strcmp(winetest_platform, "wine")) dump++;
2168 ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
2171 done:
2172 if (dump) dump_sequence(expected_list, context, file, line);
2173 flush_sequence();
2176 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
2178 /******************************** MDI test **********************************/
2180 /* CreateWindow for MDI frame window, initially visible */
2181 static const struct message WmCreateMDIframeSeq[] = {
2182 { HCBT_CREATEWND, hook },
2183 { WM_GETMINMAXINFO, sent },
2184 { WM_NCCREATE, sent },
2185 { WM_NCCALCSIZE, sent|wparam, 0 },
2186 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2187 { WM_CREATE, sent },
2188 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2189 { WM_NOTIFYFORMAT, sent|optional },
2190 { WM_QUERYUISTATE, sent|optional },
2191 { WM_WINDOWPOSCHANGING, sent|optional },
2192 { WM_GETMINMAXINFO, sent|optional },
2193 { WM_NCCALCSIZE, sent|optional },
2194 { WM_WINDOWPOSCHANGED, sent|optional },
2195 { WM_SHOWWINDOW, sent|wparam, 1 },
2196 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2197 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2198 { HCBT_ACTIVATE, hook },
2199 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
2200 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
2201 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
2202 { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
2203 { WM_NCACTIVATE, sent },
2204 { WM_GETTEXT, sent|defwinproc|optional },
2205 { WM_ACTIVATE, sent|wparam, 1 },
2206 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
2207 { HCBT_SETFOCUS, hook },
2208 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2209 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2210 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2211 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
2212 /* Win9x adds SWP_NOZORDER below */
2213 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2214 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2215 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2216 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2217 { WM_MOVE, sent },
2218 { 0 }
2220 /* DestroyWindow for MDI frame window, initially visible */
2221 static const struct message WmDestroyMDIframeSeq[] = {
2222 { HCBT_DESTROYWND, hook },
2223 { 0x0090, sent|optional },
2224 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2225 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2226 { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2227 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2228 { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
2229 { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2230 { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
2231 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
2232 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2233 { WM_DESTROY, sent },
2234 { WM_NCDESTROY, sent },
2235 { 0 }
2237 /* CreateWindow for MDI client window, initially visible */
2238 static const struct message WmCreateMDIclientSeq[] = {
2239 { HCBT_CREATEWND, hook },
2240 { WM_NCCREATE, sent },
2241 { WM_NCCALCSIZE, sent|wparam, 0 },
2242 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2243 { WM_CREATE, sent },
2244 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2245 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2246 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2247 { WM_MOVE, sent },
2248 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
2249 { WM_SHOWWINDOW, sent|wparam, 1 },
2250 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2251 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2252 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2253 { 0 }
2255 /* ShowWindow(SW_SHOW) for MDI client window */
2256 static const struct message WmShowMDIclientSeq[] = {
2257 { WM_SHOWWINDOW, sent|wparam, 1 },
2258 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2259 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2260 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2261 { 0 }
2263 /* ShowWindow(SW_HIDE) for MDI client window */
2264 static const struct message WmHideMDIclientSeq[] = {
2265 { WM_SHOWWINDOW, sent|wparam, 0 },
2266 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2267 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
2268 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
2269 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2270 { 0 }
2272 /* DestroyWindow for MDI client window, initially visible */
2273 static const struct message WmDestroyMDIclientSeq[] = {
2274 { HCBT_DESTROYWND, hook },
2275 { 0x0090, sent|optional },
2276 { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
2277 { WM_SHOWWINDOW, sent|wparam, 0 },
2278 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2279 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2280 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2281 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2282 { WM_DESTROY, sent },
2283 { WM_NCDESTROY, sent },
2284 { 0 }
2286 /* CreateWindow for MDI child window, initially visible */
2287 static const struct message WmCreateMDIchildVisibleSeq[] = {
2288 { HCBT_CREATEWND, hook },
2289 { WM_NCCREATE, sent },
2290 { WM_NCCALCSIZE, sent|wparam, 0 },
2291 { WM_CREATE, sent },
2292 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2293 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2294 { WM_MOVE, sent },
2295 /* Win2k sends wparam set to
2296 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2297 * while Win9x doesn't bother to set child window id according to
2298 * CLIENTCREATESTRUCT.idFirstChild
2300 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2301 { WM_SHOWWINDOW, sent|wparam, 1 },
2302 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2303 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2304 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2305 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2306 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2307 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2308 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2310 /* Win9x: message sequence terminates here. */
2312 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2313 { HCBT_SETFOCUS, hook }, /* in MDI client */
2314 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2315 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2316 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2317 { WM_SETFOCUS, sent }, /* in MDI client */
2318 { HCBT_SETFOCUS, hook },
2319 { WM_KILLFOCUS, sent }, /* in MDI client */
2320 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2321 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2322 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2323 { WM_SETFOCUS, sent|defwinproc },
2324 { WM_MDIACTIVATE, sent|defwinproc },
2325 { 0 }
2327 /* CreateWindow for MDI child window with invisible parent */
2328 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
2329 { HCBT_CREATEWND, hook },
2330 { WM_GETMINMAXINFO, sent },
2331 { WM_NCCREATE, sent },
2332 { WM_NCCALCSIZE, sent|wparam, 0 },
2333 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2334 { WM_CREATE, sent },
2335 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2336 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2337 { WM_MOVE, sent },
2338 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2339 { WM_SHOWWINDOW, sent|wparam, 1 },
2340 { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2341 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2342 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2343 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2345 /* Win9x: message sequence terminates here. */
2347 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2348 { HCBT_SETFOCUS, hook }, /* in MDI client */
2349 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2350 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2351 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2352 { WM_SETFOCUS, sent }, /* in MDI client */
2353 { HCBT_SETFOCUS, hook },
2354 { WM_KILLFOCUS, sent }, /* in MDI client */
2355 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2356 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2357 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2358 { WM_SETFOCUS, sent|defwinproc },
2359 { WM_MDIACTIVATE, sent|defwinproc },
2360 { 0 }
2362 /* DestroyWindow for MDI child window, initially visible */
2363 static const struct message WmDestroyMDIchildVisibleSeq[] = {
2364 { HCBT_DESTROYWND, hook },
2365 /* Win2k sends wparam set to
2366 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2367 * while Win9x doesn't bother to set child window id according to
2368 * CLIENTCREATESTRUCT.idFirstChild
2370 { 0x0090, sent|optional },
2371 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2372 { WM_SHOWWINDOW, sent|wparam, 0 },
2373 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2374 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2375 { WM_ERASEBKGND, sent|parent|optional },
2376 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2378 /* { WM_DESTROY, sent }
2379 * Win9x: message sequence terminates here.
2382 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2383 { WM_KILLFOCUS, sent },
2384 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2385 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2386 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2387 { WM_SETFOCUS, sent }, /* in MDI client */
2389 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2390 { WM_KILLFOCUS, sent }, /* in MDI client */
2391 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2392 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2393 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2394 { WM_SETFOCUS, sent }, /* in MDI client */
2396 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2398 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2399 { WM_KILLFOCUS, sent },
2400 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2401 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2402 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2403 { WM_SETFOCUS, sent }, /* in MDI client */
2405 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2406 { WM_KILLFOCUS, sent }, /* in MDI client */
2407 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2408 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2409 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2410 { WM_SETFOCUS, sent }, /* in MDI client */
2412 { WM_DESTROY, sent },
2414 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2415 { WM_KILLFOCUS, sent },
2416 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2417 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2418 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2419 { WM_SETFOCUS, sent }, /* in MDI client */
2421 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2422 { WM_KILLFOCUS, sent }, /* in MDI client */
2423 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2424 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2425 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2426 { WM_SETFOCUS, sent }, /* in MDI client */
2428 { WM_NCDESTROY, sent },
2429 { 0 }
2431 /* CreateWindow for MDI child window, initially invisible */
2432 static const struct message WmCreateMDIchildInvisibleSeq[] = {
2433 { HCBT_CREATEWND, hook },
2434 { WM_NCCREATE, sent },
2435 { WM_NCCALCSIZE, sent|wparam, 0 },
2436 { WM_CREATE, sent },
2437 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2438 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2439 { WM_MOVE, sent },
2440 /* Win2k sends wparam set to
2441 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2442 * while Win9x doesn't bother to set child window id according to
2443 * CLIENTCREATESTRUCT.idFirstChild
2445 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2446 { 0 }
2448 /* DestroyWindow for MDI child window, initially invisible */
2449 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
2450 { HCBT_DESTROYWND, hook },
2451 /* Win2k sends wparam set to
2452 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2453 * while Win9x doesn't bother to set child window id according to
2454 * CLIENTCREATESTRUCT.idFirstChild
2456 { 0x0090, sent|optional },
2457 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2458 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2459 { WM_DESTROY, sent },
2460 { WM_NCDESTROY, sent },
2461 /* FIXME: Wine destroys an icon/title window while Windows doesn't */
2462 { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
2463 { 0 }
2465 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
2466 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
2467 { HCBT_CREATEWND, hook },
2468 { WM_NCCREATE, sent },
2469 { WM_NCCALCSIZE, sent|wparam, 0 },
2470 { WM_CREATE, sent },
2471 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2472 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2473 { WM_MOVE, sent },
2474 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2475 { WM_GETMINMAXINFO, sent },
2476 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2477 { WM_NCCALCSIZE, sent|wparam, 1 },
2478 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2479 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2480 /* in MDI frame */
2481 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2482 { WM_NCCALCSIZE, sent|wparam, 1 },
2483 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2484 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2485 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2486 /* Win2k sends wparam set to
2487 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2488 * while Win9x doesn't bother to set child window id according to
2489 * CLIENTCREATESTRUCT.idFirstChild
2491 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2492 { WM_SHOWWINDOW, sent|wparam, 1 },
2493 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2494 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2495 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2496 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2497 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2498 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2499 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_FRAMECHANGED },
2501 /* Win9x: message sequence terminates here. */
2503 { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2504 { HCBT_SETFOCUS, hook|optional }, /* in MDI client */
2505 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2506 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2507 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2508 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2509 { HCBT_SETFOCUS, hook|optional },
2510 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2511 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2512 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2513 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2514 { WM_SETFOCUS, sent|defwinproc|optional },
2515 { WM_MDIACTIVATE, sent|defwinproc|optional },
2516 /* in MDI frame */
2517 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2518 { WM_NCCALCSIZE, sent|wparam, 1 },
2519 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2520 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2521 { 0 }
2523 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2524 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2525 /* restore the 1st MDI child */
2526 { WM_SETREDRAW, sent|wparam, 0 },
2527 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2528 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2529 { WM_NCCALCSIZE, sent|wparam, 1 },
2530 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2531 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2532 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
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 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2539 { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2540 /* create the 2nd MDI child */
2541 { HCBT_CREATEWND, hook },
2542 { WM_NCCREATE, sent },
2543 { WM_NCCALCSIZE, sent|wparam, 0 },
2544 { WM_CREATE, sent },
2545 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2546 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2547 { WM_MOVE, sent },
2548 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2549 { WM_GETMINMAXINFO, sent },
2550 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2551 { WM_NCCALCSIZE, sent|wparam, 1 },
2552 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2553 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2554 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2555 /* in MDI frame */
2556 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2557 { WM_NCCALCSIZE, sent|wparam, 1 },
2558 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2559 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2560 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2561 /* Win2k sends wparam set to
2562 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2563 * while Win9x doesn't bother to set child window id according to
2564 * CLIENTCREATESTRUCT.idFirstChild
2566 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2567 { WM_SHOWWINDOW, sent|wparam, 1 },
2568 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2569 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2570 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2571 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2572 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2573 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2575 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2576 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2578 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2580 /* Win9x: message sequence terminates here. */
2582 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2583 { HCBT_SETFOCUS, hook },
2584 { WM_KILLFOCUS, sent|defwinproc|optional }, /* in the 1st MDI child */
2585 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2586 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2587 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2588 { WM_SETFOCUS, sent }, /* in MDI client */
2589 { HCBT_SETFOCUS, hook },
2590 { WM_KILLFOCUS, sent }, /* in MDI client */
2591 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2592 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2593 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2594 { WM_SETFOCUS, sent|defwinproc },
2596 { WM_MDIACTIVATE, sent|defwinproc },
2597 /* in MDI frame */
2598 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2599 { WM_NCCALCSIZE, sent|wparam, 1 },
2600 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2601 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2602 { 0 }
2604 /* WM_MDICREATE MDI child window, initially visible and maximized */
2605 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2606 { WM_MDICREATE, sent },
2607 { HCBT_CREATEWND, hook },
2608 { WM_NCCREATE, sent },
2609 { WM_NCCALCSIZE, sent|wparam, 0 },
2610 { WM_CREATE, sent },
2611 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2612 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2613 { WM_MOVE, sent },
2614 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2615 { WM_GETMINMAXINFO, sent },
2616 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2617 { WM_NCCALCSIZE, sent|wparam, 1 },
2618 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2619 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2621 /* in MDI frame */
2622 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2623 { WM_NCCALCSIZE, sent|wparam, 1 },
2624 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2625 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2626 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2628 /* Win2k sends wparam set to
2629 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2630 * while Win9x doesn't bother to set child window id according to
2631 * CLIENTCREATESTRUCT.idFirstChild
2633 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2634 { WM_SHOWWINDOW, sent|wparam, 1 },
2635 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2637 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2639 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2640 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2641 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2643 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2644 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2646 /* Win9x: message sequence terminates here. */
2648 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2649 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2650 { HCBT_SETFOCUS, hook }, /* in MDI client */
2651 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2652 { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2653 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2654 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2655 { HCBT_SETFOCUS, hook|optional },
2656 { WM_KILLFOCUS, sent }, /* in MDI client */
2657 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2658 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2659 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2660 { WM_SETFOCUS, sent|defwinproc },
2662 { WM_MDIACTIVATE, sent|defwinproc },
2664 /* in MDI child */
2665 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2666 { WM_NCCALCSIZE, sent|wparam, 1 },
2667 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2668 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2670 /* in MDI frame */
2671 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2672 { WM_NCCALCSIZE, sent|wparam, 1 },
2673 { 0x0093, sent|defwinproc|optional },
2674 { 0x0093, sent|defwinproc|optional },
2675 { 0x0093, sent|defwinproc|optional },
2676 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2677 { WM_MOVE, sent|defwinproc },
2678 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2680 /* in MDI client */
2681 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2682 { WM_NCCALCSIZE, sent|wparam, 1 },
2683 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2684 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2686 /* in MDI child */
2687 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2688 { WM_NCCALCSIZE, sent|wparam, 1 },
2689 { 0x0093, sent|optional },
2690 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2691 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2693 { 0x0093, sent|optional },
2694 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2695 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2696 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2697 { 0x0093, sent|defwinproc|optional },
2698 { 0x0093, sent|defwinproc|optional },
2699 { 0x0093, sent|defwinproc|optional },
2700 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2701 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2703 { 0 }
2705 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2706 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2707 { HCBT_CREATEWND, hook },
2708 { WM_GETMINMAXINFO, sent },
2709 { WM_NCCREATE, sent },
2710 { WM_NCCALCSIZE, sent|wparam, 0 },
2711 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2712 { WM_CREATE, sent },
2713 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2714 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2715 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2716 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI frame */
2717 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2718 { WM_MOVE, sent },
2719 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2720 { WM_GETMINMAXINFO, sent },
2721 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2722 { WM_GETMINMAXINFO, sent|defwinproc },
2723 { WM_NCCALCSIZE, sent|wparam, 1 },
2724 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_STATECHANGED },
2725 { WM_MOVE, sent|defwinproc },
2726 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2727 /* in MDI frame */
2728 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2729 { WM_NCCALCSIZE, sent|wparam, 1 },
2730 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2731 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2732 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2733 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2734 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2735 /* Win2k sends wparam set to
2736 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2737 * while Win9x doesn't bother to set child window id according to
2738 * CLIENTCREATESTRUCT.idFirstChild
2740 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2741 { 0 }
2743 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2744 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2745 { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2746 { HCBT_SYSCOMMAND, hook },
2747 { WM_CLOSE, sent|defwinproc },
2748 { WM_MDIDESTROY, sent }, /* in MDI client */
2750 /* bring the 1st MDI child to top */
2751 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2752 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2754 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2756 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2757 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2758 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2760 /* maximize the 1st MDI child */
2761 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2762 { WM_GETMINMAXINFO, sent|defwinproc },
2763 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED },
2764 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2765 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2766 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2767 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2769 /* restore the 2nd MDI child */
2770 { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2771 { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2772 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2773 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2775 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2777 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2778 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2780 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2782 { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2783 /* in MDI frame */
2784 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2785 { WM_NCCALCSIZE, sent|wparam, 1 },
2786 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2787 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2788 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2790 /* bring the 1st MDI child to top */
2791 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2792 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2793 { HCBT_SETFOCUS, hook },
2794 { WM_KILLFOCUS, sent|defwinproc },
2795 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2796 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2797 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2798 { WM_SETFOCUS, sent }, /* in MDI client */
2799 { HCBT_SETFOCUS, hook },
2800 { WM_KILLFOCUS, sent }, /* in MDI client */
2801 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2802 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2803 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2804 { WM_SETFOCUS, sent|defwinproc },
2805 { WM_MDIACTIVATE, sent|defwinproc },
2806 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2808 /* apparently ShowWindow(SW_SHOW) on an MDI client */
2809 { WM_SHOWWINDOW, sent|wparam, 1 },
2810 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2811 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2812 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2813 { WM_MDIREFRESHMENU, sent },
2815 { HCBT_DESTROYWND, hook },
2816 /* Win2k sends wparam set to
2817 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2818 * while Win9x doesn't bother to set child window id according to
2819 * CLIENTCREATESTRUCT.idFirstChild
2821 { 0x0090, sent|defwinproc|optional },
2822 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2823 { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2824 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2825 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2826 { WM_ERASEBKGND, sent|parent|optional },
2827 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2829 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2830 { WM_DESTROY, sent|defwinproc },
2831 { WM_NCDESTROY, sent|defwinproc },
2832 { 0 }
2834 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2835 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2836 { WM_MDIDESTROY, sent }, /* in MDI client */
2837 { WM_SHOWWINDOW, sent|wparam, 0 },
2838 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2839 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2840 { WM_ERASEBKGND, sent|parent|optional },
2841 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2843 { HCBT_SETFOCUS, hook },
2844 { WM_KILLFOCUS, sent },
2845 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2846 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2847 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2848 { WM_SETFOCUS, sent }, /* in MDI client */
2849 { HCBT_SETFOCUS, hook },
2850 { WM_KILLFOCUS, sent }, /* in MDI client */
2851 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2852 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2853 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2854 { WM_SETFOCUS, sent },
2856 /* in MDI child */
2857 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2858 { WM_NCCALCSIZE, sent|wparam, 1 },
2859 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2860 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2862 /* in MDI frame */
2863 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2864 { WM_NCCALCSIZE, sent|wparam, 1 },
2865 { 0x0093, sent|defwinproc|optional },
2866 { 0x0093, sent|defwinproc|optional },
2867 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2868 { WM_MOVE, sent|defwinproc },
2869 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2871 /* in MDI client */
2872 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2873 { WM_NCCALCSIZE, sent|wparam, 1 },
2874 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2875 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2877 /* in MDI child */
2878 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2879 { WM_NCCALCSIZE, sent|wparam, 1 },
2880 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2881 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2883 /* in MDI child */
2884 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2885 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2886 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2887 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2889 /* in MDI frame */
2890 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2891 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2892 { 0x0093, sent|defwinproc|optional },
2893 { 0x0093, sent|defwinproc|optional },
2894 { 0x0093, sent|defwinproc|optional },
2895 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2896 { WM_MOVE, sent|defwinproc },
2897 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2899 /* in MDI client */
2900 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2901 { WM_NCCALCSIZE, sent|wparam, 1 },
2902 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2903 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2905 /* in MDI child */
2906 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2907 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2908 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2909 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2910 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2911 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2913 { 0x0093, sent|defwinproc|optional },
2914 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2915 { 0x0093, sent|defwinproc|optional },
2916 { 0x0093, sent|defwinproc|optional },
2917 { 0x0093, sent|defwinproc|optional },
2918 { 0x0093, sent|optional },
2920 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2921 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2922 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2923 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2924 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2926 /* in MDI frame */
2927 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2928 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2929 { 0x0093, sent|defwinproc|optional },
2930 { 0x0093, sent|defwinproc|optional },
2931 { 0x0093, sent|defwinproc|optional },
2932 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2933 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2934 { 0x0093, sent|optional },
2936 { WM_NCACTIVATE, sent|wparam, 0 },
2937 { WM_MDIACTIVATE, sent },
2939 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2940 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2941 { WM_NCCALCSIZE, sent|wparam, 1 },
2943 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2945 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2946 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2947 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2949 /* in MDI child */
2950 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2951 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2952 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2953 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2955 /* in MDI frame */
2956 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2957 { WM_NCCALCSIZE, sent|wparam, 1 },
2958 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2959 { WM_MOVE, sent|defwinproc },
2960 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2962 /* in MDI client */
2963 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2964 { WM_NCCALCSIZE, sent|wparam, 1 },
2965 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2966 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2967 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2968 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2969 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2970 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2971 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2973 { HCBT_SETFOCUS, hook },
2974 { WM_KILLFOCUS, sent },
2975 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2976 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2977 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2978 { WM_SETFOCUS, sent }, /* in MDI client */
2980 { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2982 { HCBT_DESTROYWND, hook },
2983 /* Win2k sends wparam set to
2984 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2985 * while Win9x doesn't bother to set child window id according to
2986 * CLIENTCREATESTRUCT.idFirstChild
2988 { 0x0090, sent|optional },
2989 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2991 { WM_SHOWWINDOW, sent|wparam, 0 },
2992 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2993 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2994 { WM_ERASEBKGND, sent|parent|optional },
2995 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2997 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2998 { WM_DESTROY, sent },
2999 { WM_NCDESTROY, sent },
3000 { 0 }
3002 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
3003 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
3004 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3005 { WM_GETMINMAXINFO, sent },
3006 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
3007 { WM_NCCALCSIZE, sent|wparam, 1 },
3008 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3009 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3011 { WM_WINDOWPOSCHANGING, sent|wparam|optional|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3012 { WM_NCACTIVATE, sent|wparam|optional|defwinproc, 1 },
3013 { HCBT_SETFOCUS, hook|optional },
3014 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3015 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3016 { WM_SETFOCUS, sent|optional }, /* in MDI client */
3017 { HCBT_SETFOCUS, hook|optional },
3018 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3019 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3020 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3021 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3022 { WM_SETFOCUS, sent|optional|defwinproc },
3023 { WM_MDIACTIVATE, sent|optional|defwinproc },
3024 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3025 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3026 /* in MDI frame */
3027 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3028 { WM_NCCALCSIZE, sent|wparam, 1 },
3029 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3030 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3031 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3032 { 0 }
3034 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
3035 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
3036 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3037 { WM_GETMINMAXINFO, sent },
3038 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
3039 { WM_GETMINMAXINFO, sent|defwinproc },
3040 { WM_NCCALCSIZE, sent|wparam, 1 },
3041 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3042 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3044 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3045 { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
3046 { HCBT_SETFOCUS, hook|optional },
3047 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3048 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3049 { WM_SETFOCUS, sent|optional }, /* in MDI client */
3050 { HCBT_SETFOCUS, hook|optional },
3051 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3052 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3053 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3054 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3055 { WM_SETFOCUS, sent|defwinproc|optional },
3056 { WM_MDIACTIVATE, sent|defwinproc|optional },
3057 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3058 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3059 { 0 }
3061 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
3062 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
3063 { WM_MDIMAXIMIZE, sent }, /* in MDI client */
3064 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3065 { WM_GETMINMAXINFO, sent },
3066 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3067 { WM_GETMINMAXINFO, sent|defwinproc },
3068 { WM_NCCALCSIZE, sent|wparam, 1 },
3069 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
3070 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3071 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
3072 { WM_MOVE, sent|defwinproc },
3073 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3075 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3076 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3077 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3078 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3079 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3080 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3081 /* in MDI frame */
3082 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3083 { WM_NCCALCSIZE, sent|wparam, 1 },
3084 { 0x0093, sent|defwinproc|optional },
3085 { 0x0094, sent|defwinproc|optional },
3086 { 0x0094, sent|defwinproc|optional },
3087 { 0x0094, sent|defwinproc|optional },
3088 { 0x0094, sent|defwinproc|optional },
3089 { 0x0093, sent|defwinproc|optional },
3090 { 0x0093, sent|defwinproc|optional },
3091 { 0x0091, sent|defwinproc|optional },
3092 { 0x0092, sent|defwinproc|optional },
3093 { 0x0092, sent|defwinproc|optional },
3094 { 0x0092, sent|defwinproc|optional },
3095 { 0x0092, sent|defwinproc|optional },
3096 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3097 { WM_MOVE, sent|defwinproc },
3098 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3099 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
3100 /* in MDI client */
3101 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
3102 { WM_NCCALCSIZE, sent|wparam, 1 },
3103 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3104 { WM_SIZE, sent|wparam, SIZE_RESTORED },
3105 /* in MDI child */
3106 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
3107 { WM_GETMINMAXINFO, sent|defwinproc },
3108 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3109 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3110 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3111 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
3112 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3113 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3114 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3115 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3116 /* in MDI frame */
3117 { 0x0093, sent|optional },
3118 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
3119 { 0x0093, sent|defwinproc|optional },
3120 { 0x0093, sent|defwinproc|optional },
3121 { 0x0093, sent|defwinproc|optional },
3122 { 0x0091, sent|defwinproc|optional },
3123 { 0x0092, sent|defwinproc|optional },
3124 { 0x0092, sent|defwinproc|optional },
3125 { 0x0092, sent|defwinproc|optional },
3126 { 0x0092, sent|defwinproc|optional },
3127 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3128 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3129 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3130 { 0 }
3132 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
3133 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
3134 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3135 { WM_GETMINMAXINFO, sent },
3136 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3137 { WM_NCCALCSIZE, sent|wparam, 1 },
3138 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3139 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3140 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3141 /* in MDI frame */
3142 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3143 { WM_NCCALCSIZE, sent|wparam, 1 },
3144 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3145 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3146 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3147 { 0 }
3149 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
3150 static const struct message WmRestoreMDIchildVisibleSeq[] = {
3151 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3152 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3153 { WM_NCCALCSIZE, sent|wparam, 1 },
3154 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3155 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3156 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3157 /* in MDI frame */
3158 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3159 { WM_NCCALCSIZE, sent|wparam, 1 },
3160 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3161 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3162 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3163 { 0 }
3165 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
3166 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
3167 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3168 { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
3169 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3170 { WM_NCCALCSIZE, sent|wparam, 1 },
3171 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3172 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3173 { WM_MOVE, sent|defwinproc },
3174 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3175 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3176 { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3177 { HCBT_SETFOCUS, hook },
3178 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3179 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
3180 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3181 { WM_SETFOCUS, sent },
3182 { 0 }
3184 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
3185 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
3186 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
3187 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3188 { WM_NCCALCSIZE, sent|wparam, 1 },
3189 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3190 { WM_MOVE, sent|defwinproc },
3191 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
3192 { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
3193 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3194 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3195 /* FIXME: Wine creates an icon/title window while Windows doesn't */
3196 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
3197 { 0 }
3199 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
3200 static const struct message WmRestoreMDIchildInisibleSeq[] = {
3201 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3202 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
3203 { WM_NCCALCSIZE, sent|wparam, 1 },
3204 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3205 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3206 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3207 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3208 /* in MDI frame */
3209 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3210 { WM_NCCALCSIZE, sent|wparam, 1 },
3211 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3212 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3213 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3214 { 0 }
3217 static HWND mdi_client;
3218 static WNDPROC old_mdi_client_proc;
3220 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3222 struct recvd_message msg;
3224 /* do not log painting messages */
3225 if (message != WM_PAINT &&
3226 message != WM_NCPAINT &&
3227 message != WM_SYNCPAINT &&
3228 message != WM_ERASEBKGND &&
3229 message != WM_NCHITTEST &&
3230 message != WM_GETTEXT &&
3231 message != WM_MDIGETACTIVE &&
3232 !ignore_message( message ))
3234 msg.hwnd = hwnd;
3235 msg.message = message;
3236 msg.flags = sent|wparam|lparam;
3237 msg.wParam = wParam;
3238 msg.lParam = lParam;
3239 msg.descr = "mdi client";
3240 add_message(&msg);
3243 return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
3246 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3248 static LONG defwndproc_counter = 0;
3249 LRESULT ret;
3250 struct recvd_message msg;
3252 /* do not log painting messages */
3253 if (message != WM_PAINT &&
3254 message != WM_NCPAINT &&
3255 message != WM_SYNCPAINT &&
3256 message != WM_ERASEBKGND &&
3257 message != WM_NCHITTEST &&
3258 message != WM_GETTEXT &&
3259 !ignore_message( message ))
3261 switch (message)
3263 case WM_MDIACTIVATE:
3265 HWND active, client = GetParent(hwnd);
3267 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
3269 if (hwnd == (HWND)lParam) /* if we are being activated */
3270 ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
3271 else
3272 ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
3273 break;
3277 msg.hwnd = hwnd;
3278 msg.message = message;
3279 msg.flags = sent|wparam|lparam;
3280 if (defwndproc_counter) msg.flags |= defwinproc;
3281 msg.wParam = wParam;
3282 msg.lParam = lParam;
3283 msg.descr = "mdi child";
3284 add_message(&msg);
3287 defwndproc_counter++;
3288 ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
3289 defwndproc_counter--;
3291 return ret;
3294 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3296 static LONG defwndproc_counter = 0;
3297 LRESULT ret;
3298 struct recvd_message msg;
3300 /* do not log painting messages */
3301 if (message != WM_PAINT &&
3302 message != WM_NCPAINT &&
3303 message != WM_SYNCPAINT &&
3304 message != WM_ERASEBKGND &&
3305 message != WM_NCHITTEST &&
3306 message != WM_GETTEXT &&
3307 !ignore_message( message ))
3309 msg.hwnd = hwnd;
3310 msg.message = message;
3311 msg.flags = sent|wparam|lparam;
3312 if (defwndproc_counter) msg.flags |= defwinproc;
3313 msg.wParam = wParam;
3314 msg.lParam = lParam;
3315 msg.descr = "mdi frame";
3316 add_message(&msg);
3319 defwndproc_counter++;
3320 ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
3321 defwndproc_counter--;
3323 return ret;
3326 static BOOL mdi_RegisterWindowClasses(void)
3328 WNDCLASSA cls;
3330 cls.style = 0;
3331 cls.lpfnWndProc = mdi_frame_wnd_proc;
3332 cls.cbClsExtra = 0;
3333 cls.cbWndExtra = 0;
3334 cls.hInstance = GetModuleHandleA(0);
3335 cls.hIcon = 0;
3336 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3337 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3338 cls.lpszMenuName = NULL;
3339 cls.lpszClassName = "MDI_frame_class";
3340 if (!RegisterClassA(&cls)) return FALSE;
3342 cls.lpfnWndProc = mdi_child_wnd_proc;
3343 cls.lpszClassName = "MDI_child_class";
3344 if (!RegisterClassA(&cls)) return FALSE;
3346 if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
3347 old_mdi_client_proc = cls.lpfnWndProc;
3348 cls.hInstance = GetModuleHandleA(0);
3349 cls.lpfnWndProc = mdi_client_hook_proc;
3350 cls.lpszClassName = "MDI_client_class";
3351 if (!RegisterClassA(&cls)) assert(0);
3353 return TRUE;
3356 static void test_mdi_messages(void)
3358 MDICREATESTRUCTA mdi_cs;
3359 CLIENTCREATESTRUCT client_cs;
3360 HWND mdi_frame, mdi_child, mdi_child2, active_child;
3361 BOOL zoomed;
3362 RECT rc;
3363 HMENU hMenu = CreateMenu();
3365 assert(mdi_RegisterWindowClasses());
3367 flush_sequence();
3369 trace("creating MDI frame window\n");
3370 mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
3371 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3372 WS_MAXIMIZEBOX | WS_VISIBLE,
3373 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
3374 GetDesktopWindow(), hMenu,
3375 GetModuleHandleA(0), NULL);
3376 assert(mdi_frame);
3377 ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
3379 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3380 ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
3382 trace("creating MDI client window\n");
3383 GetClientRect(mdi_frame, &rc);
3384 client_cs.hWindowMenu = 0;
3385 client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
3386 mdi_client = CreateWindowExA(0, "MDI_client_class",
3387 NULL,
3388 WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
3389 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
3390 mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3391 assert(mdi_client);
3392 ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
3394 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3395 ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
3397 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3398 ok(!active_child, "wrong active MDI child %p\n", active_child);
3399 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3401 SetFocus(0);
3402 flush_sequence();
3404 trace("creating invisible MDI child window\n");
3405 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3406 WS_CHILD,
3407 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3408 mdi_client, 0, GetModuleHandleA(0), NULL);
3409 assert(mdi_child);
3411 flush_sequence();
3412 ShowWindow(mdi_child, SW_SHOWNORMAL);
3413 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
3415 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3416 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3418 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3419 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3421 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3422 ok(!active_child, "wrong active MDI child %p\n", active_child);
3423 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3425 ShowWindow(mdi_child, SW_HIDE);
3426 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
3427 flush_sequence();
3429 ShowWindow(mdi_child, SW_SHOW);
3430 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) 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 DestroyWindow(mdi_child);
3443 flush_sequence();
3445 trace("creating visible MDI child window\n");
3446 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3447 WS_CHILD | WS_VISIBLE,
3448 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3449 mdi_client, 0, GetModuleHandleA(0), NULL);
3450 assert(mdi_child);
3451 ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
3453 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3454 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3456 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3457 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3459 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3460 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3461 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3462 flush_sequence();
3464 DestroyWindow(mdi_child);
3465 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3467 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3468 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3470 /* Win2k: MDI client still returns a just destroyed child as active
3471 * Win9x: MDI client returns 0
3473 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3474 ok(active_child == mdi_child || /* win2k */
3475 !active_child, /* win9x */
3476 "wrong active MDI child %p\n", active_child);
3477 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3479 flush_sequence();
3481 trace("creating invisible MDI child window\n");
3482 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3483 WS_CHILD,
3484 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3485 mdi_client, 0, GetModuleHandleA(0), NULL);
3486 assert(mdi_child2);
3487 ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
3489 ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
3490 ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
3492 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3493 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3495 /* Win2k: MDI client still returns a just destroyed child as active
3496 * Win9x: MDI client returns mdi_child2
3498 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3499 ok(active_child == mdi_child || /* win2k */
3500 active_child == mdi_child2, /* win9x */
3501 "wrong active MDI child %p\n", active_child);
3502 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3503 flush_sequence();
3505 ShowWindow(mdi_child2, SW_MAXIMIZE);
3506 ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3508 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3509 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3511 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3512 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3513 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3514 flush_sequence();
3516 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3517 ok(GetFocus() == mdi_child2 || /* win2k */
3518 GetFocus() == 0, /* win9x */
3519 "wrong focus window %p\n", GetFocus());
3521 SetFocus(0);
3522 flush_sequence();
3524 ShowWindow(mdi_child2, SW_HIDE);
3525 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3527 ShowWindow(mdi_child2, SW_RESTORE);
3528 ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3529 flush_sequence();
3531 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3532 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3534 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3535 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3536 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3537 flush_sequence();
3539 SetFocus(0);
3540 flush_sequence();
3542 ShowWindow(mdi_child2, SW_HIDE);
3543 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3545 ShowWindow(mdi_child2, SW_SHOW);
3546 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3548 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3549 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3551 ShowWindow(mdi_child2, SW_MAXIMIZE);
3552 ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3554 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3555 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3557 ShowWindow(mdi_child2, SW_RESTORE);
3558 ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3560 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3561 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3563 ShowWindow(mdi_child2, SW_MINIMIZE);
3564 ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3566 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3567 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3569 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3570 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3571 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3572 flush_sequence();
3574 ShowWindow(mdi_child2, SW_RESTORE);
3575 ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", FALSE);
3577 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3578 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3580 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3581 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3582 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3583 flush_sequence();
3585 SetFocus(0);
3586 flush_sequence();
3588 ShowWindow(mdi_child2, SW_HIDE);
3589 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3591 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3592 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3594 DestroyWindow(mdi_child2);
3595 ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3597 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3598 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3600 /* test for maximized MDI children */
3601 trace("creating maximized visible MDI child window 1\n");
3602 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3603 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3604 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3605 mdi_client, 0, GetModuleHandleA(0), NULL);
3606 assert(mdi_child);
3607 ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3608 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3610 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3611 ok(GetFocus() == mdi_child || /* win2k */
3612 GetFocus() == 0, /* win9x */
3613 "wrong focus window %p\n", GetFocus());
3615 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3616 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3617 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3618 flush_sequence();
3620 trace("creating maximized visible MDI child window 2\n");
3621 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3622 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3623 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3624 mdi_client, 0, GetModuleHandleA(0), NULL);
3625 assert(mdi_child2);
3626 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3627 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3628 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3630 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3631 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3633 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3634 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3635 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3636 flush_sequence();
3638 trace("destroying maximized visible MDI child window 2\n");
3639 DestroyWindow(mdi_child2);
3640 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3642 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3644 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3645 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3647 /* Win2k: MDI client still returns a just destroyed child as active
3648 * Win9x: MDI client returns 0
3650 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3651 ok(active_child == mdi_child2 || /* win2k */
3652 !active_child, /* win9x */
3653 "wrong active MDI child %p\n", active_child);
3654 flush_sequence();
3656 ShowWindow(mdi_child, SW_MAXIMIZE);
3657 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3658 flush_sequence();
3660 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3661 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3663 trace("re-creating maximized visible MDI child window 2\n");
3664 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3665 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3666 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3667 mdi_client, 0, GetModuleHandleA(0), NULL);
3668 assert(mdi_child2);
3669 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3670 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3671 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3673 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3674 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3676 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3677 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3678 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3679 flush_sequence();
3681 SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3682 ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3683 ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3685 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3686 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3687 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3689 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3690 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3691 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3692 flush_sequence();
3694 DestroyWindow(mdi_child);
3695 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3697 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3698 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3700 /* Win2k: MDI client still returns a just destroyed child as active
3701 * Win9x: MDI client returns 0
3703 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3704 ok(active_child == mdi_child || /* win2k */
3705 !active_child, /* win9x */
3706 "wrong active MDI child %p\n", active_child);
3707 flush_sequence();
3709 trace("creating maximized invisible MDI child window\n");
3710 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3711 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3712 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3713 mdi_client, 0, GetModuleHandleA(0), NULL);
3714 assert(mdi_child2);
3715 ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", FALSE);
3716 ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3717 ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3718 ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3720 /* Win2k: MDI client still returns a just destroyed child as active
3721 * Win9x: MDI client returns 0
3723 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3724 ok(active_child == mdi_child || /* win2k */
3725 !active_child || active_child == mdi_child2, /* win9x */
3726 "wrong active MDI child %p\n", active_child);
3727 flush_sequence();
3729 trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3730 ShowWindow(mdi_child2, SW_MAXIMIZE);
3731 ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3732 ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3733 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3734 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3736 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3737 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3738 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3739 flush_sequence();
3741 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3742 flush_sequence();
3744 /* end of test for maximized MDI children */
3745 SetFocus(0);
3746 flush_sequence();
3747 trace("creating maximized visible MDI child window 1(Switch test)\n");
3748 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3749 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3750 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3751 mdi_client, 0, GetModuleHandleA(0), NULL);
3752 assert(mdi_child);
3753 ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3754 ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3756 ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3757 ok(GetFocus() == mdi_child || /* win2k */
3758 GetFocus() == 0, /* win9x */
3759 "wrong focus window %p(Switch test)\n", GetFocus());
3761 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3762 ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3763 ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3764 flush_sequence();
3766 trace("creating maximized visible MDI child window 2(Switch test)\n");
3767 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3768 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3769 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3770 mdi_client, 0, GetModuleHandleA(0), NULL);
3771 assert(mdi_child2);
3772 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3774 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3775 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3777 ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3778 ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3780 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3781 ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3782 ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3783 flush_sequence();
3785 trace("Switch child window.\n");
3786 SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3787 ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3788 trace("end of test for switch maximized MDI children\n");
3789 flush_sequence();
3791 /* Prepare for switching test of not maximized MDI children */
3792 ShowWindow( mdi_child, SW_NORMAL );
3793 ok(!IsZoomed(mdi_child), "wrong zoomed state for %p(Switch test)\n", mdi_child);
3794 ok(!IsZoomed(mdi_child2), "wrong zoomed state for %p(Switch test)\n", mdi_child2);
3795 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
3796 ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3797 flush_sequence();
3799 SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child2, 0);
3800 ok_sequence(WmSwitchNotMaximizedChild, "Not maximized child did not switch correctly", FALSE);
3801 trace("end of test for switch not maximized MDI children\n");
3802 flush_sequence();
3804 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3805 flush_sequence();
3807 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3808 flush_sequence();
3810 SetFocus(0);
3811 flush_sequence();
3812 /* end of tests for switch maximized/not maximized MDI children */
3814 mdi_cs.szClass = "MDI_child_Class";
3815 mdi_cs.szTitle = "MDI child";
3816 mdi_cs.hOwner = GetModuleHandleA(0);
3817 mdi_cs.x = 0;
3818 mdi_cs.y = 0;
3819 mdi_cs.cx = CW_USEDEFAULT;
3820 mdi_cs.cy = CW_USEDEFAULT;
3821 mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3822 mdi_cs.lParam = 0;
3823 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3824 ok(mdi_child != 0, "MDI child creation failed\n");
3825 ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3827 ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3829 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3830 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3832 ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3833 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3834 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3836 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3837 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3838 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3839 flush_sequence();
3841 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3842 ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3844 ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3845 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3846 ok(!active_child, "wrong active MDI child %p\n", active_child);
3848 SetFocus(0);
3849 flush_sequence();
3851 DestroyWindow(mdi_client);
3852 ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3854 /* test maximization of MDI child with invisible parent */
3855 client_cs.hWindowMenu = 0;
3856 mdi_client = CreateWindow("MDI_client_class",
3857 NULL,
3858 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3859 0, 0, 660, 430,
3860 mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3861 ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3863 ShowWindow(mdi_client, SW_HIDE);
3864 ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3866 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3867 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3868 0, 0, 650, 440,
3869 mdi_client, 0, GetModuleHandleA(0), NULL);
3870 ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3872 SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3873 ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3874 zoomed = IsZoomed(mdi_child);
3875 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3877 ShowWindow(mdi_client, SW_SHOW);
3878 ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3880 DestroyWindow(mdi_child);
3881 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3883 /* end of test for maximization of MDI child with invisible parent */
3885 DestroyWindow(mdi_client);
3886 ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3888 DestroyWindow(mdi_frame);
3889 ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3891 /************************* End of MDI test **********************************/
3893 static void test_WM_SETREDRAW(HWND hwnd)
3895 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3897 flush_events();
3898 flush_sequence();
3900 SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3901 ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3903 ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3904 ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3906 flush_sequence();
3907 SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3908 ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3910 ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3911 ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3913 /* restore original WS_VISIBLE state */
3914 SetWindowLongA(hwnd, GWL_STYLE, style);
3916 flush_events();
3917 flush_sequence();
3920 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3922 struct recvd_message msg;
3924 if (ignore_message( message )) return 0;
3926 switch (message)
3928 /* ignore */
3929 case WM_MOUSEMOVE:
3930 case WM_NCMOUSEMOVE:
3931 case WM_NCMOUSELEAVE:
3932 case WM_SETCURSOR:
3933 return 0;
3934 case WM_NCHITTEST:
3935 return HTCLIENT;
3938 msg.hwnd = hwnd;
3939 msg.message = message;
3940 msg.flags = sent|wparam|lparam;
3941 msg.wParam = wParam;
3942 msg.lParam = lParam;
3943 msg.descr = "dialog";
3944 add_message(&msg);
3946 if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3947 if (message == WM_TIMER) EndDialog( hwnd, 0 );
3948 return 0;
3951 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3953 DWORD style, exstyle;
3954 INT xmin, xmax;
3955 BOOL ret;
3957 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3958 style = GetWindowLongA(hwnd, GWL_STYLE);
3959 /* do not be confused by WS_DLGFRAME set */
3960 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3962 if (clear) ok(style & clear, "style %08x should be set\n", clear);
3963 if (set) ok(!(style & set), "style %08x should not be set\n", set);
3965 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3966 ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3967 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3968 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3969 else
3970 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3972 style = GetWindowLongA(hwnd, GWL_STYLE);
3973 if (set) ok(style & set, "style %08x should be set\n", set);
3974 if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3976 /* a subsequent call should do nothing */
3977 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3978 ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3979 ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3981 xmin = 0xdeadbeef;
3982 xmax = 0xdeadbeef;
3983 ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
3984 ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
3985 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3986 ok(xmin == min, "unexpected min scroll value %d\n", xmin);
3987 ok(xmax == max, "unexpected max scroll value %d\n", xmax);
3990 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3992 DWORD style, exstyle;
3993 SCROLLINFO si;
3994 BOOL ret;
3996 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3997 style = GetWindowLongA(hwnd, GWL_STYLE);
3998 /* do not be confused by WS_DLGFRAME set */
3999 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
4001 if (clear) ok(style & clear, "style %08x should be set\n", clear);
4002 if (set) ok(!(style & set), "style %08x should not be set\n", set);
4004 si.cbSize = sizeof(si);
4005 si.fMask = SIF_RANGE;
4006 si.nMin = min;
4007 si.nMax = max;
4008 SetScrollInfo(hwnd, ctl, &si, TRUE);
4009 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
4010 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
4011 else
4012 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
4014 style = GetWindowLongA(hwnd, GWL_STYLE);
4015 if (set) ok(style & set, "style %08x should be set\n", set);
4016 if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
4018 /* a subsequent call should do nothing */
4019 SetScrollInfo(hwnd, ctl, &si, TRUE);
4020 if (style & WS_HSCROLL)
4021 ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4022 else if (style & WS_VSCROLL)
4023 ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4024 else
4025 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4027 si.fMask = SIF_PAGE;
4028 si.nPage = 5;
4029 SetScrollInfo(hwnd, ctl, &si, FALSE);
4030 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4032 si.fMask = SIF_POS;
4033 si.nPos = max - 1;
4034 SetScrollInfo(hwnd, ctl, &si, FALSE);
4035 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4037 si.fMask = SIF_RANGE;
4038 si.nMin = 0xdeadbeef;
4039 si.nMax = 0xdeadbeef;
4040 ret = GetScrollInfo(hwnd, ctl, &si);
4041 ok( ret, "GetScrollInfo error %d\n", GetLastError());
4042 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
4043 ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
4044 ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
4047 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
4048 static void test_scroll_messages(HWND hwnd)
4050 SCROLLINFO si;
4051 INT min, max;
4052 BOOL ret;
4054 flush_events();
4055 flush_sequence();
4057 min = 0xdeadbeef;
4058 max = 0xdeadbeef;
4059 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4060 ok( ret, "GetScrollRange error %d\n", GetLastError());
4061 if (sequence->message != WmGetScrollRangeSeq[0].message)
4062 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4063 /* values of min and max are undefined */
4064 flush_sequence();
4066 ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
4067 ok( ret, "SetScrollRange error %d\n", GetLastError());
4068 if (sequence->message != WmSetScrollRangeSeq[0].message)
4069 trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4070 flush_sequence();
4072 min = 0xdeadbeef;
4073 max = 0xdeadbeef;
4074 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4075 ok( ret, "GetScrollRange error %d\n", GetLastError());
4076 if (sequence->message != WmGetScrollRangeSeq[0].message)
4077 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4078 /* values of min and max are undefined */
4079 flush_sequence();
4081 si.cbSize = sizeof(si);
4082 si.fMask = SIF_RANGE;
4083 si.nMin = 20;
4084 si.nMax = 160;
4085 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4086 if (sequence->message != WmSetScrollRangeSeq[0].message)
4087 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4088 flush_sequence();
4090 si.fMask = SIF_PAGE;
4091 si.nPage = 10;
4092 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4093 if (sequence->message != WmSetScrollRangeSeq[0].message)
4094 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4095 flush_sequence();
4097 si.fMask = SIF_POS;
4098 si.nPos = 20;
4099 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4100 if (sequence->message != WmSetScrollRangeSeq[0].message)
4101 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4102 flush_sequence();
4104 si.fMask = SIF_RANGE;
4105 si.nMin = 0xdeadbeef;
4106 si.nMax = 0xdeadbeef;
4107 ret = GetScrollInfo(hwnd, SB_CTL, &si);
4108 ok( ret, "GetScrollInfo error %d\n", GetLastError());
4109 if (sequence->message != WmGetScrollInfoSeq[0].message)
4110 trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4111 /* values of min and max are undefined */
4112 flush_sequence();
4114 /* set WS_HSCROLL */
4115 test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4116 /* clear WS_HSCROLL */
4117 test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4119 /* set WS_HSCROLL */
4120 test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4121 /* clear WS_HSCROLL */
4122 test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4124 /* set WS_VSCROLL */
4125 test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4126 /* clear WS_VSCROLL */
4127 test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4129 /* set WS_VSCROLL */
4130 test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4131 /* clear WS_VSCROLL */
4132 test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4135 static void test_showwindow(void)
4137 HWND hwnd, hchild;
4138 RECT rc;
4140 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4141 100, 100, 200, 200, 0, 0, 0, NULL);
4142 ok (hwnd != 0, "Failed to create overlapped window\n");
4143 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4144 0, 0, 10, 10, hwnd, 0, 0, NULL);
4145 ok (hchild != 0, "Failed to create child\n");
4146 flush_sequence();
4148 /* ShowWindow( SW_SHOWNA) for invisible top level window */
4149 trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
4150 ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4151 ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", FALSE);
4153 /* ShowWindow( SW_SHOWNA) for now visible top level window */
4154 trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
4155 ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4156 ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
4157 /* back to invisible */
4158 ShowWindow(hchild, SW_HIDE);
4159 ShowWindow(hwnd, SW_HIDE);
4160 flush_sequence();
4161 /* ShowWindow(SW_SHOWNA) with child and parent invisible */
4162 trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
4163 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4164 ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
4165 /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */
4166 ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
4167 flush_sequence();
4168 trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
4169 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4170 ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
4171 /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
4172 ShowWindow( hwnd, SW_SHOW);
4173 flush_sequence();
4174 trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
4175 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4176 ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
4178 /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
4179 ShowWindow( hchild, SW_HIDE);
4180 flush_sequence();
4181 trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
4182 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4183 ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
4185 SetCapture(hchild);
4186 ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
4187 DestroyWindow(hchild);
4188 ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
4190 DestroyWindow(hwnd);
4191 flush_sequence();
4193 /* Popup windows */
4194 /* Test 1:
4195 * 1. Create invisible maximized popup window.
4196 * 2. Move and resize it.
4197 * 3. Show it maximized.
4199 trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4200 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4201 100, 100, 200, 200, 0, 0, 0, NULL);
4202 ok (hwnd != 0, "Failed to create popup window\n");
4203 ok(IsZoomed(hwnd), "window should be maximized\n");
4204 ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4206 GetWindowRect(hwnd, &rc);
4207 ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4208 rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4209 "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
4210 rc.left, rc.top, rc.right, rc.bottom);
4211 /* Reset window's size & position */
4212 SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
4213 ok(IsZoomed(hwnd), "window should be maximized\n");
4214 flush_sequence();
4216 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4217 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4218 ok(IsZoomed(hwnd), "window should be maximized\n");
4219 ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
4221 GetWindowRect(hwnd, &rc);
4222 ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4223 rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4224 "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
4225 rc.left, rc.top, rc.right, rc.bottom);
4226 DestroyWindow(hwnd);
4227 flush_sequence();
4229 /* Test 2:
4230 * 1. Create invisible maximized popup window.
4231 * 2. Show it maximized.
4233 trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4234 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4235 100, 100, 200, 200, 0, 0, 0, NULL);
4236 ok (hwnd != 0, "Failed to create popup window\n");
4237 ok(IsZoomed(hwnd), "window should be maximized\n");
4238 ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4240 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4241 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4242 ok(IsZoomed(hwnd), "window should be maximized\n");
4243 ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
4244 DestroyWindow(hwnd);
4245 flush_sequence();
4247 /* Test 3:
4248 * 1. Create visible maximized popup window.
4250 trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
4251 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
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(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4256 DestroyWindow(hwnd);
4257 flush_sequence();
4259 /* Test 4:
4260 * 1. Create visible popup window.
4261 * 2. Maximize it.
4263 trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
4264 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
4265 100, 100, 200, 200, 0, 0, 0, NULL);
4266 ok (hwnd != 0, "Failed to create popup window\n");
4267 ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
4268 ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
4270 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
4271 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4272 ok(IsZoomed(hwnd), "window should be maximized\n");
4273 ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
4274 DestroyWindow(hwnd);
4275 flush_sequence();
4278 static void test_sys_menu(void)
4280 HWND hwnd;
4281 HMENU hmenu;
4282 UINT state;
4284 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4285 100, 100, 200, 200, 0, 0, 0, NULL);
4286 ok (hwnd != 0, "Failed to create overlapped window\n");
4288 flush_sequence();
4290 /* test existing window without CS_NOCLOSE style */
4291 hmenu = GetSystemMenu(hwnd, FALSE);
4292 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4294 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4295 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4296 ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4298 EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
4299 ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4301 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4302 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4303 ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
4305 EnableMenuItem(hmenu, SC_CLOSE, 0);
4306 ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4308 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4309 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4310 ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4312 /* test whether removing WS_SYSMENU destroys a system menu */
4313 SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
4314 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4315 flush_sequence();
4316 hmenu = GetSystemMenu(hwnd, FALSE);
4317 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4319 DestroyWindow(hwnd);
4321 /* test new window with CS_NOCLOSE style */
4322 hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4323 100, 100, 200, 200, 0, 0, 0, NULL);
4324 ok (hwnd != 0, "Failed to create overlapped window\n");
4326 hmenu = GetSystemMenu(hwnd, FALSE);
4327 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4329 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4330 ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4332 DestroyWindow(hwnd);
4334 /* test new window without WS_SYSMENU style */
4335 hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
4336 100, 100, 200, 200, 0, 0, 0, NULL);
4337 ok(hwnd != 0, "Failed to create overlapped window\n");
4339 hmenu = GetSystemMenu(hwnd, FALSE);
4340 ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
4342 DestroyWindow(hwnd);
4345 /* For shown WS_OVERLAPPEDWINDOW */
4346 static const struct message WmSetIcon_1[] = {
4347 { WM_SETICON, sent },
4348 { 0x00AE, sent|defwinproc|optional }, /* XP */
4349 { WM_GETTEXT, sent|defwinproc|optional },
4350 { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
4351 { 0 }
4354 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
4355 static const struct message WmSetIcon_2[] = {
4356 { WM_SETICON, sent },
4357 { 0 }
4360 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4361 static const struct message WmInitEndSession[] = {
4362 { 0x003B, sent },
4363 { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4364 { 0 }
4367 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4368 static const struct message WmInitEndSession_2[] = {
4369 { 0x003B, sent },
4370 { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4371 { 0 }
4374 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4375 static const struct message WmInitEndSession_3[] = {
4376 { 0x003B, sent },
4377 { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4378 { 0 }
4381 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4382 static const struct message WmInitEndSession_4[] = {
4383 { 0x003B, sent },
4384 { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4385 { 0 }
4388 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4389 static const struct message WmInitEndSession_5[] = {
4390 { 0x003B, sent },
4391 { WM_ENDSESSION, sent|defwinproc/*|wparam*/|lparam, 1, ENDSESSION_LOGOFF },
4392 { 0 }
4395 static const struct message WmOptionalPaint[] = {
4396 { WM_PAINT, sent|optional },
4397 { WM_NCPAINT, sent|beginpaint|optional },
4398 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4399 { WM_ERASEBKGND, sent|beginpaint|optional },
4400 { 0 }
4403 static const struct message WmZOrder[] = {
4404 { WM_WINDOWPOSCHANGING, sent|wparam, 0, 0 },
4405 { WM_GETMINMAXINFO, sent|defwinproc|wparam, 0, 0 },
4406 { HCBT_ACTIVATE, hook },
4407 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
4408 { WM_WINDOWPOSCHANGING, sent|wparam, 3, 0 },
4409 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0 },
4410 { WM_GETTEXT, sent|optional },
4411 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
4412 { WM_ACTIVATEAPP, sent|wparam, 1, 0 },
4413 { WM_NCACTIVATE, sent|lparam, 1, 0 },
4414 { WM_GETTEXT, sent|defwinproc|optional },
4415 { WM_GETTEXT, sent|defwinproc|optional },
4416 { WM_ACTIVATE, sent|wparam|lparam, 1, 0 },
4417 { HCBT_SETFOCUS, hook },
4418 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4419 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4420 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4421 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
4422 { WM_GETTEXT, sent|optional },
4423 { WM_NCCALCSIZE, sent|optional },
4424 { 0 }
4427 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4429 DWORD ret;
4430 MSG msg;
4432 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4433 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4435 PostMessageA(hwnd, WM_USER, 0, 0);
4437 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4438 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4440 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4441 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4443 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4444 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4446 PostMessageA(hwnd, WM_USER, 0, 0);
4448 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4449 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4451 ok(PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4452 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4454 /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4455 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4456 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4458 PostMessageA(hwnd, WM_USER, 0, 0);
4460 /* new incoming message causes it to become signaled again */
4461 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4462 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4464 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4465 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4466 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4467 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4470 /* test if we receive the right sequence of messages */
4471 static void test_messages(void)
4473 HWND hwnd, hparent, hchild;
4474 HWND hchild2, hbutton;
4475 HMENU hmenu;
4476 MSG msg;
4477 LRESULT res;
4479 flush_sequence();
4481 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4482 100, 100, 200, 200, 0, 0, 0, NULL);
4483 ok (hwnd != 0, "Failed to create overlapped window\n");
4484 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4486 /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4487 ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4488 ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4490 /* test WM_SETREDRAW on a not visible top level window */
4491 test_WM_SETREDRAW(hwnd);
4493 SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4494 flush_events();
4495 ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4496 ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4498 ok(GetActiveWindow() == hwnd, "window should be active\n");
4499 ok(GetFocus() == hwnd, "window should have input focus\n");
4500 ShowWindow(hwnd, SW_HIDE);
4501 flush_events();
4502 ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4504 ShowWindow(hwnd, SW_SHOW);
4505 flush_events();
4506 ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4508 ShowWindow(hwnd, SW_HIDE);
4509 flush_events();
4510 ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4512 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4513 flush_events();
4514 ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4515 flush_sequence();
4517 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MAXIMIZE)
4519 ShowWindow(hwnd, SW_RESTORE);
4520 flush_events();
4521 ok_sequence(WmShowRestoreMaxOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4522 flush_sequence();
4525 ShowWindow(hwnd, SW_MINIMIZE);
4526 flush_events();
4527 ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4528 flush_sequence();
4530 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MINIMIZE)
4532 ShowWindow(hwnd, SW_RESTORE);
4533 flush_events();
4534 ok_sequence(WmShowRestoreMinOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4535 flush_sequence();
4538 ShowWindow(hwnd, SW_SHOW);
4539 flush_events();
4540 ok_sequence(WmOptionalPaint, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4542 SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4543 ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4544 ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4545 ok(GetActiveWindow() == hwnd, "window should still be active\n");
4547 /* test WM_SETREDRAW on a visible top level window */
4548 ShowWindow(hwnd, SW_SHOW);
4549 flush_events();
4550 test_WM_SETREDRAW(hwnd);
4552 trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4553 test_scroll_messages(hwnd);
4555 /* test resizing and moving */
4556 SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4557 ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4558 flush_events();
4559 flush_sequence();
4560 SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4561 ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4562 flush_events();
4563 flush_sequence();
4564 SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER|SWP_NOACTIVATE );
4565 ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4566 flush_events();
4567 flush_sequence();
4569 /* popups don't get WM_GETMINMAXINFO */
4570 SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4571 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4572 flush_sequence();
4573 SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4574 ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4576 DestroyWindow(hwnd);
4577 ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4579 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4580 100, 100, 200, 200, 0, 0, 0, NULL);
4581 ok (hparent != 0, "Failed to create parent window\n");
4582 flush_sequence();
4584 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4585 0, 0, 10, 10, hparent, 0, 0, NULL);
4586 ok (hchild != 0, "Failed to create child window\n");
4587 ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4588 DestroyWindow(hchild);
4589 flush_sequence();
4591 /* visible child window with a caption */
4592 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4593 WS_CHILD | WS_VISIBLE | WS_CAPTION,
4594 0, 0, 10, 10, hparent, 0, 0, NULL);
4595 ok (hchild != 0, "Failed to create child window\n");
4596 ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4598 trace("testing scroll APIs on a visible child window %p\n", hchild);
4599 test_scroll_messages(hchild);
4601 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4602 ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4604 DestroyWindow(hchild);
4605 flush_sequence();
4607 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4608 0, 0, 10, 10, hparent, 0, 0, NULL);
4609 ok (hchild != 0, "Failed to create child window\n");
4610 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4612 hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4613 100, 100, 50, 50, hparent, 0, 0, NULL);
4614 ok (hchild2 != 0, "Failed to create child2 window\n");
4615 flush_sequence();
4617 hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4618 0, 100, 50, 50, hchild, 0, 0, NULL);
4619 ok (hbutton != 0, "Failed to create button window\n");
4621 /* test WM_SETREDRAW on a not visible child window */
4622 test_WM_SETREDRAW(hchild);
4624 ShowWindow(hchild, SW_SHOW);
4625 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4627 /* check parent messages too */
4628 log_all_parent_messages++;
4629 ShowWindow(hchild, SW_HIDE);
4630 ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4631 log_all_parent_messages--;
4633 ShowWindow(hchild, SW_SHOW);
4634 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4636 ShowWindow(hchild, SW_HIDE);
4637 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4639 ShowWindow(hchild, SW_SHOW);
4640 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4642 /* test WM_SETREDRAW on a visible child window */
4643 test_WM_SETREDRAW(hchild);
4645 log_all_parent_messages++;
4646 MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4647 ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4648 log_all_parent_messages--;
4650 ShowWindow(hchild, SW_HIDE);
4651 flush_sequence();
4652 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4653 ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4655 ShowWindow(hchild, SW_HIDE);
4656 flush_sequence();
4657 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4658 ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4660 /* DestroyWindow sequence below expects that a child has focus */
4661 SetFocus(hchild);
4662 flush_sequence();
4664 DestroyWindow(hchild);
4665 ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4666 DestroyWindow(hchild2);
4667 DestroyWindow(hbutton);
4669 flush_sequence();
4670 hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4671 0, 0, 100, 100, hparent, 0, 0, NULL);
4672 ok (hchild != 0, "Failed to create child popup window\n");
4673 ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4674 DestroyWindow(hchild);
4676 /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4677 flush_sequence();
4678 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4679 0, 0, 100, 100, hparent, 0, 0, NULL);
4680 ok (hchild != 0, "Failed to create popup window\n");
4681 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4682 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4683 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4684 flush_sequence();
4685 ShowWindow(hchild, SW_SHOW);
4686 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4687 flush_sequence();
4688 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4689 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4690 flush_sequence();
4691 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4692 ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
4693 DestroyWindow(hchild);
4695 /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4696 * changes nothing in message sequences.
4698 flush_sequence();
4699 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4700 0, 0, 100, 100, hparent, 0, 0, NULL);
4701 ok (hchild != 0, "Failed to create popup window\n");
4702 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4703 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4704 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4705 flush_sequence();
4706 ShowWindow(hchild, SW_SHOW);
4707 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4708 flush_sequence();
4709 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4710 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4711 DestroyWindow(hchild);
4713 flush_sequence();
4714 hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4715 0, 0, 100, 100, hparent, 0, 0, NULL);
4716 ok(hwnd != 0, "Failed to create custom dialog window\n");
4717 ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4720 trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4721 test_scroll_messages(hwnd);
4724 flush_sequence();
4726 test_def_id = 1;
4727 SendMessage(hwnd, WM_NULL, 0, 0);
4729 flush_sequence();
4730 after_end_dialog = 1;
4731 EndDialog( hwnd, 0 );
4732 ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4734 DestroyWindow(hwnd);
4735 after_end_dialog = 0;
4736 test_def_id = 0;
4738 hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4739 0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4740 ok(hwnd != 0, "Failed to create custom dialog window\n");
4741 flush_sequence();
4742 trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4743 ShowWindow(hwnd, SW_SHOW);
4744 ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4745 DestroyWindow(hwnd);
4747 flush_sequence();
4748 DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4749 ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4751 DestroyWindow(hparent);
4752 flush_sequence();
4754 /* Message sequence for SetMenu */
4755 ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4756 ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4758 hmenu = CreateMenu();
4759 ok (hmenu != 0, "Failed to create menu\n");
4760 ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4761 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4762 100, 100, 200, 200, 0, hmenu, 0, NULL);
4763 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4764 ok (SetMenu(hwnd, 0), "SetMenu\n");
4765 ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4766 ok (SetMenu(hwnd, 0), "SetMenu\n");
4767 ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4768 ShowWindow(hwnd, SW_SHOW);
4769 UpdateWindow( hwnd );
4770 flush_events();
4771 flush_sequence();
4772 ok (SetMenu(hwnd, 0), "SetMenu\n");
4773 ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4774 ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4775 ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4777 UpdateWindow( hwnd );
4778 flush_events();
4779 flush_sequence();
4780 ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4781 flush_events();
4782 ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4784 DestroyWindow(hwnd);
4785 flush_sequence();
4787 /* Message sequence for EnableWindow */
4788 hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4789 100, 100, 200, 200, 0, 0, 0, NULL);
4790 ok (hparent != 0, "Failed to create parent window\n");
4791 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4792 0, 0, 10, 10, hparent, 0, 0, NULL);
4793 ok (hchild != 0, "Failed to create child window\n");
4795 SetFocus(hchild);
4796 flush_events();
4797 flush_sequence();
4799 EnableWindow(hparent, FALSE);
4800 ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4802 EnableWindow(hparent, TRUE);
4803 ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4805 flush_events();
4806 flush_sequence();
4808 test_MsgWaitForMultipleObjects(hparent);
4810 /* the following test causes an exception in user.exe under win9x */
4811 if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4813 DestroyWindow(hparent);
4814 flush_sequence();
4815 return;
4817 PostMessageW( hparent, WM_USER+1, 0, 0 );
4818 /* PeekMessage(NULL) fails, but still removes the message */
4819 SetLastError(0xdeadbeef);
4820 ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4821 ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4822 GetLastError() == 0xdeadbeef, /* NT4 */
4823 "last error is %d\n", GetLastError() );
4824 ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4825 ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4827 DestroyWindow(hchild);
4828 DestroyWindow(hparent);
4829 flush_sequence();
4831 /* Message sequences for WM_SETICON */
4832 trace("testing WM_SETICON\n");
4833 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4834 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4835 NULL, NULL, 0);
4836 ShowWindow(hwnd, SW_SHOW);
4837 UpdateWindow(hwnd);
4838 flush_events();
4839 flush_sequence();
4840 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4841 ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4843 ShowWindow(hwnd, SW_HIDE);
4844 flush_events();
4845 flush_sequence();
4846 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4847 ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4848 DestroyWindow(hwnd);
4849 flush_sequence();
4851 hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4852 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4853 NULL, NULL, 0);
4854 ShowWindow(hwnd, SW_SHOW);
4855 UpdateWindow(hwnd);
4856 flush_events();
4857 flush_sequence();
4858 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4859 ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4861 ShowWindow(hwnd, SW_HIDE);
4862 flush_events();
4863 flush_sequence();
4864 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4865 ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4867 flush_sequence();
4868 res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4869 if (!res)
4871 todo_wine win_skip( "Message 0x3b not supported\n" );
4872 goto done;
4874 ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4875 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4876 res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4877 ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4878 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4879 res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4880 ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4881 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4883 flush_sequence();
4884 res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4885 ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4886 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4887 res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4888 ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4889 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4891 res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4892 ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4893 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4895 res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4896 ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4897 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4899 done:
4900 DestroyWindow(hwnd);
4901 flush_sequence();
4904 static void test_setwindowpos(void)
4906 HWND hwnd;
4907 RECT rc;
4908 LRESULT res;
4909 const INT winX = 100;
4910 const INT winY = 100;
4911 const INT sysX = GetSystemMetrics(SM_CXMINTRACK);
4913 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
4914 0, 0, winX, winY, 0,
4915 NULL, NULL, 0);
4917 GetWindowRect(hwnd, &rc);
4918 expect(sysX, rc.right);
4919 expect(winY, rc.bottom);
4921 flush_events();
4922 flush_sequence();
4923 res = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, winX, winY, 0);
4924 ok_sequence(WmZOrder, "Z-Order", TRUE);
4925 ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
4927 GetWindowRect(hwnd, &rc);
4928 expect(sysX, rc.right);
4929 expect(winY, rc.bottom);
4930 DestroyWindow(hwnd);
4933 static void invisible_parent_tests(void)
4935 HWND hparent, hchild;
4937 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4938 100, 100, 200, 200, 0, 0, 0, NULL);
4939 ok (hparent != 0, "Failed to create parent window\n");
4940 flush_sequence();
4942 /* test showing child with hidden parent */
4944 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4945 0, 0, 10, 10, hparent, 0, 0, NULL);
4946 ok (hchild != 0, "Failed to create child window\n");
4947 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4949 ShowWindow( hchild, SW_MINIMIZE );
4950 ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4951 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4952 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4954 /* repeat */
4955 flush_events();
4956 flush_sequence();
4957 ShowWindow( hchild, SW_MINIMIZE );
4958 ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4960 DestroyWindow(hchild);
4961 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4962 0, 0, 10, 10, hparent, 0, 0, NULL);
4963 flush_sequence();
4965 ShowWindow( hchild, SW_MAXIMIZE );
4966 ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4967 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4968 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4970 /* repeat */
4971 flush_events();
4972 flush_sequence();
4973 ShowWindow( hchild, SW_MAXIMIZE );
4974 ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4976 DestroyWindow(hchild);
4977 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4978 0, 0, 10, 10, hparent, 0, 0, NULL);
4979 flush_sequence();
4981 ShowWindow( hchild, SW_RESTORE );
4982 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
4983 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4984 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4986 DestroyWindow(hchild);
4987 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4988 0, 0, 10, 10, hparent, 0, 0, NULL);
4989 flush_sequence();
4991 ShowWindow( hchild, SW_SHOWMINIMIZED );
4992 ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4993 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4994 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4996 /* repeat */
4997 flush_events();
4998 flush_sequence();
4999 ShowWindow( hchild, SW_SHOWMINIMIZED );
5000 ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
5002 DestroyWindow(hchild);
5003 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5004 0, 0, 10, 10, hparent, 0, 0, NULL);
5005 flush_sequence();
5007 /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
5008 ShowWindow( hchild, SW_SHOWMAXIMIZED );
5009 ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) 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 DestroyWindow(hchild);
5014 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5015 0, 0, 10, 10, hparent, 0, 0, NULL);
5016 flush_sequence();
5018 ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5019 ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5020 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5021 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5023 /* repeat */
5024 flush_events();
5025 flush_sequence();
5026 ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5027 ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5029 DestroyWindow(hchild);
5030 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5031 0, 0, 10, 10, hparent, 0, 0, NULL);
5032 flush_sequence();
5034 /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
5035 ShowWindow( hchild, SW_FORCEMINIMIZE );
5036 ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
5037 todo_wine {
5038 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5040 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5042 DestroyWindow(hchild);
5043 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5044 0, 0, 10, 10, hparent, 0, 0, NULL);
5045 flush_sequence();
5047 ShowWindow( hchild, SW_SHOWNA );
5048 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5049 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5050 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5052 /* repeat */
5053 flush_events();
5054 flush_sequence();
5055 ShowWindow( hchild, SW_SHOWNA );
5056 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5058 DestroyWindow(hchild);
5059 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5060 0, 0, 10, 10, hparent, 0, 0, NULL);
5061 flush_sequence();
5063 ShowWindow( hchild, SW_SHOW );
5064 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5065 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5066 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5068 /* repeat */
5069 flush_events();
5070 flush_sequence();
5071 ShowWindow( hchild, SW_SHOW );
5072 ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5074 ShowWindow( hchild, SW_HIDE );
5075 ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
5076 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5077 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5079 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5080 ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
5081 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5082 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5084 SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5085 ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
5086 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
5087 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5089 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5090 flush_sequence();
5091 DestroyWindow(hchild);
5092 ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
5094 DestroyWindow(hparent);
5095 flush_sequence();
5098 /****************** button message test *************************/
5099 #define ID_BUTTON 0x000e
5101 static const struct message WmSetFocusButtonSeq[] =
5103 { HCBT_SETFOCUS, hook },
5104 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5105 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5106 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5107 { WM_SETFOCUS, sent|wparam, 0 },
5108 { WM_CTLCOLORBTN, sent|parent },
5109 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5110 { WM_APP, sent|wparam|lparam, 0, 0 },
5111 { 0 }
5113 static const struct message WmKillFocusButtonSeq[] =
5115 { HCBT_SETFOCUS, hook },
5116 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5117 { WM_KILLFOCUS, sent|wparam, 0 },
5118 { WM_CTLCOLORBTN, sent|parent },
5119 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5120 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5121 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5122 { WM_APP, sent|wparam|lparam, 0, 0 },
5123 { WM_PAINT, sent },
5124 { WM_CTLCOLORBTN, sent|parent },
5125 { 0 }
5127 static const struct message WmSetFocusStaticSeq[] =
5129 { HCBT_SETFOCUS, hook },
5130 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5131 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5132 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5133 { WM_SETFOCUS, sent|wparam, 0 },
5134 { WM_CTLCOLORSTATIC, sent|parent },
5135 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5136 { WM_COMMAND, sent|wparam|parent|optional, MAKEWPARAM(ID_BUTTON, BN_CLICKED) }, /* radio button */
5137 { WM_APP, sent|wparam|lparam, 0, 0 },
5138 { 0 }
5140 static const struct message WmKillFocusStaticSeq[] =
5142 { HCBT_SETFOCUS, hook },
5143 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5144 { WM_KILLFOCUS, sent|wparam, 0 },
5145 { WM_CTLCOLORSTATIC, sent|parent },
5146 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5147 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5148 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5149 { WM_APP, sent|wparam|lparam, 0, 0 },
5150 { WM_PAINT, sent },
5151 { WM_CTLCOLORSTATIC, sent|parent },
5152 { 0 }
5154 static const struct message WmSetFocusOwnerdrawSeq[] =
5156 { HCBT_SETFOCUS, hook },
5157 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5158 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5159 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5160 { WM_SETFOCUS, sent|wparam, 0 },
5161 { WM_CTLCOLORBTN, sent|parent },
5162 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x001040e4 },
5163 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5164 { WM_APP, sent|wparam|lparam, 0, 0 },
5165 { 0 }
5167 static const struct message WmKillFocusOwnerdrawSeq[] =
5169 { HCBT_SETFOCUS, hook },
5170 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5171 { WM_KILLFOCUS, sent|wparam, 0 },
5172 { WM_CTLCOLORBTN, sent|parent },
5173 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000040e4 },
5174 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5175 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5176 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5177 { WM_APP, sent|wparam|lparam, 0, 0 },
5178 { WM_PAINT, sent },
5179 { WM_CTLCOLORBTN, sent|parent },
5180 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 },
5181 { 0 }
5183 static const struct message WmLButtonDownSeq[] =
5185 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
5186 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5187 { HCBT_SETFOCUS, hook },
5188 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
5189 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5190 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5191 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
5192 { WM_CTLCOLORBTN, sent|defwinproc },
5193 { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
5194 { WM_CTLCOLORBTN, sent|defwinproc },
5195 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5196 { 0 }
5198 static const struct message WmLButtonUpSeq[] =
5200 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
5201 { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
5202 { WM_CTLCOLORBTN, sent|defwinproc },
5203 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5204 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5205 { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
5206 { 0 }
5208 static const struct message WmSetFontButtonSeq[] =
5210 { WM_SETFONT, sent },
5211 { WM_PAINT, sent },
5212 { WM_ERASEBKGND, sent|defwinproc|optional },
5213 { WM_CTLCOLORBTN, sent|defwinproc },
5214 { 0 }
5216 static const struct message WmSetStyleButtonSeq[] =
5218 { BM_SETSTYLE, sent },
5219 { WM_APP, sent|wparam|lparam, 0, 0 },
5220 { WM_PAINT, sent },
5221 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5222 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5223 { WM_CTLCOLORBTN, sent|parent },
5224 { 0 }
5226 static const struct message WmSetStyleStaticSeq[] =
5228 { BM_SETSTYLE, sent },
5229 { WM_APP, sent|wparam|lparam, 0, 0 },
5230 { WM_PAINT, sent },
5231 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5232 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5233 { WM_CTLCOLORSTATIC, sent|parent },
5234 { 0 }
5236 static const struct message WmSetStyleUserSeq[] =
5238 { BM_SETSTYLE, sent },
5239 { WM_APP, sent|wparam|lparam, 0, 0 },
5240 { WM_PAINT, sent },
5241 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5242 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5243 { WM_CTLCOLORBTN, sent|parent },
5244 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_PAINT) },
5245 { 0 }
5247 static const struct message WmSetStyleOwnerdrawSeq[] =
5249 { BM_SETSTYLE, sent },
5250 { WM_APP, sent|wparam|lparam, 0, 0 },
5251 { WM_PAINT, sent },
5252 { WM_NCPAINT, sent|optional }, /* FIXME: Wine sends it */
5253 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5254 { WM_CTLCOLORBTN, sent|parent },
5255 { WM_CTLCOLORBTN, sent|parent|optional }, /* Win9x doesn't send it */
5256 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 },
5257 { 0 }
5260 static WNDPROC old_button_proc;
5262 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5264 static LONG defwndproc_counter = 0;
5265 LRESULT ret;
5266 struct recvd_message msg;
5268 if (ignore_message( message )) return 0;
5270 switch (message)
5272 case WM_SYNCPAINT:
5273 break;
5274 case BM_SETSTATE:
5275 ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
5276 /* fall through */
5277 default:
5278 msg.hwnd = hwnd;
5279 msg.message = message;
5280 msg.flags = sent|wparam|lparam;
5281 if (defwndproc_counter) msg.flags |= defwinproc;
5282 msg.wParam = wParam;
5283 msg.lParam = lParam;
5284 msg.descr = "button";
5285 add_message(&msg);
5288 defwndproc_counter++;
5289 ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
5290 defwndproc_counter--;
5292 return ret;
5295 static void subclass_button(void)
5297 WNDCLASSA cls;
5299 if (!GetClassInfoA(0, "button", &cls)) assert(0);
5301 old_button_proc = cls.lpfnWndProc;
5303 cls.hInstance = GetModuleHandle(0);
5304 cls.lpfnWndProc = button_hook_proc;
5305 cls.lpszClassName = "my_button_class";
5306 UnregisterClass(cls.lpszClassName, cls.hInstance);
5307 if (!RegisterClassA(&cls)) assert(0);
5310 static void test_button_messages(void)
5312 static const struct
5314 DWORD style;
5315 DWORD dlg_code;
5316 const struct message *setfocus;
5317 const struct message *killfocus;
5318 const struct message *setstyle;
5319 } button[] = {
5320 { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5321 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq },
5322 { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
5323 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq },
5324 { BS_CHECKBOX, DLGC_BUTTON,
5325 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5326 { BS_AUTOCHECKBOX, DLGC_BUTTON,
5327 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5328 { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5329 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5330 { BS_3STATE, DLGC_BUTTON,
5331 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5332 { BS_AUTO3STATE, DLGC_BUTTON,
5333 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5334 { BS_GROUPBOX, DLGC_STATIC,
5335 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5336 { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5337 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleUserSeq },
5338 { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5339 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5340 { BS_OWNERDRAW, DLGC_BUTTON,
5341 WmSetFocusOwnerdrawSeq, WmKillFocusOwnerdrawSeq, WmSetStyleOwnerdrawSeq }
5343 unsigned int i;
5344 HWND hwnd, parent;
5345 DWORD dlg_code;
5346 HFONT zfont;
5348 /* selection with VK_SPACE should capture button window */
5349 hwnd = CreateWindowExA(0, "button", "test", BS_CHECKBOX | WS_VISIBLE | WS_POPUP,
5350 0, 0, 50, 14, 0, 0, 0, NULL);
5351 ok(hwnd != 0, "Failed to create button window\n");
5352 ReleaseCapture();
5353 SetFocus(hwnd);
5354 SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
5355 ok(GetCapture() == hwnd, "Should be captured on VK_SPACE WM_KEYDOWN\n");
5356 SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
5357 DestroyWindow(hwnd);
5359 subclass_button();
5361 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5362 100, 100, 200, 200, 0, 0, 0, NULL);
5363 ok(parent != 0, "Failed to create parent window\n");
5365 for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
5367 MSG msg;
5368 DWORD style;
5370 trace("button style %08x\n", button[i].style);
5372 hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_CHILD | BS_NOTIFY,
5373 0, 0, 50, 14, parent, (HMENU)ID_BUTTON, 0, NULL);
5374 ok(hwnd != 0, "Failed to create button window\n");
5376 style = GetWindowLongA(hwnd, GWL_STYLE);
5377 style &= ~(WS_CHILD | BS_NOTIFY);
5378 /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
5379 if (button[i].style == BS_USERBUTTON)
5380 ok(style == BS_PUSHBUTTON, "expected style BS_PUSHBUTTON got %x\n", style);
5381 else
5382 ok(style == button[i].style, "expected style %x got %x\n", button[i].style, style);
5384 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5385 ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5387 ShowWindow(hwnd, SW_SHOW);
5388 UpdateWindow(hwnd);
5389 SetFocus(0);
5390 flush_events();
5391 SetFocus(0);
5392 flush_sequence();
5394 log_all_parent_messages++;
5396 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
5397 SetFocus(hwnd);
5398 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5399 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5400 ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
5402 SetFocus(0);
5403 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5404 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5405 ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
5407 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
5409 SendMessage(hwnd, BM_SETSTYLE, button[i].style | BS_BOTTOM, TRUE);
5410 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5411 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5412 ok_sequence(button[i].setstyle, "BM_SETSTYLE on a button", FALSE);
5414 style = GetWindowLongA(hwnd, GWL_STYLE);
5415 style &= ~(WS_VISIBLE | WS_CHILD | BS_NOTIFY);
5416 /* XP doesn't turn a BS_USERBUTTON into BS_PUSHBUTTON here! */
5417 ok(style == button[i].style, "expected style %x got %x\n", button[i].style, style);
5419 log_all_parent_messages--;
5421 DestroyWindow(hwnd);
5424 DestroyWindow(parent);
5426 hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
5427 0, 0, 50, 14, 0, 0, 0, NULL);
5428 ok(hwnd != 0, "Failed to create button window\n");
5430 SetForegroundWindow(hwnd);
5431 flush_events();
5433 SetActiveWindow(hwnd);
5434 SetFocus(0);
5435 flush_sequence();
5437 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
5438 ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
5440 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
5441 ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
5443 flush_sequence();
5444 zfont = GetStockObject(SYSTEM_FONT);
5445 SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
5446 UpdateWindow(hwnd);
5447 ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
5449 DestroyWindow(hwnd);
5452 /****************** static message test *************************/
5453 static const struct message WmSetFontStaticSeq[] =
5455 { WM_SETFONT, sent },
5456 { WM_PAINT, sent|defwinproc|optional },
5457 { WM_ERASEBKGND, sent|defwinproc|optional },
5458 { WM_CTLCOLORSTATIC, sent|defwinproc|optional },
5459 { 0 }
5462 static WNDPROC old_static_proc;
5464 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5466 static LONG defwndproc_counter = 0;
5467 LRESULT ret;
5468 struct recvd_message msg;
5470 if (ignore_message( message )) return 0;
5472 msg.hwnd = hwnd;
5473 msg.message = message;
5474 msg.flags = sent|wparam|lparam;
5475 if (defwndproc_counter) msg.flags |= defwinproc;
5476 msg.wParam = wParam;
5477 msg.lParam = lParam;
5478 msg.descr = "static";
5479 add_message(&msg);
5481 defwndproc_counter++;
5482 ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
5483 defwndproc_counter--;
5485 return ret;
5488 static void subclass_static(void)
5490 WNDCLASSA cls;
5492 if (!GetClassInfoA(0, "static", &cls)) assert(0);
5494 old_static_proc = cls.lpfnWndProc;
5496 cls.hInstance = GetModuleHandle(0);
5497 cls.lpfnWndProc = static_hook_proc;
5498 cls.lpszClassName = "my_static_class";
5499 UnregisterClass(cls.lpszClassName, cls.hInstance);
5500 if (!RegisterClassA(&cls)) assert(0);
5503 static void test_static_messages(void)
5505 /* FIXME: make as comprehensive as the button message test */
5506 static const struct
5508 DWORD style;
5509 DWORD dlg_code;
5510 const struct message *setfont;
5511 } static_ctrl[] = {
5512 { SS_LEFT, DLGC_STATIC,
5513 WmSetFontStaticSeq }
5515 unsigned int i;
5516 HWND hwnd;
5517 DWORD dlg_code;
5519 subclass_static();
5521 for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
5523 hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
5524 0, 0, 50, 14, 0, 0, 0, NULL);
5525 ok(hwnd != 0, "Failed to create static window\n");
5527 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5528 ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5530 ShowWindow(hwnd, SW_SHOW);
5531 UpdateWindow(hwnd);
5532 SetFocus(0);
5533 flush_sequence();
5535 trace("static style %08x\n", static_ctrl[i].style);
5536 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
5537 ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
5539 DestroyWindow(hwnd);
5543 /****************** ComboBox message test *************************/
5544 #define ID_COMBOBOX 0x000f
5546 static const struct message WmKeyDownComboSeq[] =
5548 { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
5549 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
5550 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
5551 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
5552 { WM_CTLCOLOREDIT, sent|parent },
5553 { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
5554 { 0 }
5557 static WNDPROC old_combobox_proc;
5559 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5561 static LONG defwndproc_counter = 0;
5562 LRESULT ret;
5563 struct recvd_message msg;
5565 /* do not log painting messages */
5566 if (message != WM_PAINT &&
5567 message != WM_NCPAINT &&
5568 message != WM_SYNCPAINT &&
5569 message != WM_ERASEBKGND &&
5570 message != WM_NCHITTEST &&
5571 message != WM_GETTEXT &&
5572 !ignore_message( message ))
5574 msg.hwnd = hwnd;
5575 msg.message = message;
5576 msg.flags = sent|wparam|lparam;
5577 if (defwndproc_counter) msg.flags |= defwinproc;
5578 msg.wParam = wParam;
5579 msg.lParam = lParam;
5580 msg.descr = "combo";
5581 add_message(&msg);
5584 defwndproc_counter++;
5585 ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5586 defwndproc_counter--;
5588 return ret;
5591 static void subclass_combobox(void)
5593 WNDCLASSA cls;
5595 if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5597 old_combobox_proc = cls.lpfnWndProc;
5599 cls.hInstance = GetModuleHandle(0);
5600 cls.lpfnWndProc = combobox_hook_proc;
5601 cls.lpszClassName = "my_combobox_class";
5602 UnregisterClass(cls.lpszClassName, cls.hInstance);
5603 if (!RegisterClassA(&cls)) assert(0);
5606 static void test_combobox_messages(void)
5608 HWND parent, combo;
5609 LRESULT ret;
5611 subclass_combobox();
5613 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5614 100, 100, 200, 200, 0, 0, 0, NULL);
5615 ok(parent != 0, "Failed to create parent window\n");
5616 flush_sequence();
5618 combo = CreateWindowEx(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5619 0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5620 ok(combo != 0, "Failed to create combobox window\n");
5622 UpdateWindow(combo);
5624 ret = SendMessage(combo, WM_GETDLGCODE, 0, 0);
5625 ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5627 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5628 ok(ret == 0, "expected 0, got %ld\n", ret);
5629 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5630 ok(ret == 1, "expected 1, got %ld\n", ret);
5631 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5632 ok(ret == 2, "expected 2, got %ld\n", ret);
5634 SendMessage(combo, CB_SETCURSEL, 0, 0);
5635 SetFocus(combo);
5636 flush_sequence();
5638 log_all_parent_messages++;
5639 SendMessage(combo, WM_KEYDOWN, VK_DOWN, 0);
5640 SendMessage(combo, WM_KEYUP, VK_DOWN, 0);
5641 log_all_parent_messages--;
5642 ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5644 DestroyWindow(combo);
5645 DestroyWindow(parent);
5648 /****************** WM_IME_KEYDOWN message test *******************/
5650 static const struct message WmImeKeydownMsgSeq_0[] =
5652 { WM_IME_KEYDOWN, wparam, VK_RETURN },
5653 { WM_CHAR, wparam, 'A' },
5654 { 0 }
5657 static const struct message WmImeKeydownMsgSeq_1[] =
5659 { WM_KEYDOWN, optional|wparam, VK_RETURN },
5660 { WM_CHAR, optional|wparam, VK_RETURN },
5661 { 0 }
5664 static LRESULT WINAPI wmime_keydown_procA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5666 struct recvd_message msg;
5668 msg.hwnd = hwnd;
5669 msg.message = message;
5670 msg.flags = wparam|lparam;
5671 msg.wParam = wParam;
5672 msg.lParam = lParam;
5673 msg.descr = "wmime_keydown";
5674 add_message(&msg);
5676 return DefWindowProcA(hwnd, message, wParam, lParam);
5679 static void register_wmime_keydown_class(void)
5681 WNDCLASSA cls;
5683 ZeroMemory(&cls, sizeof(WNDCLASSA));
5684 cls.lpfnWndProc = wmime_keydown_procA;
5685 cls.hInstance = GetModuleHandleA(0);
5686 cls.lpszClassName = "wmime_keydown_class";
5687 if (!RegisterClassA(&cls)) assert(0);
5690 static void test_wmime_keydown_message(void)
5692 HWND hwnd;
5693 MSG msg;
5695 trace("Message sequences by WM_IME_KEYDOWN\n");
5697 register_wmime_keydown_class();
5698 hwnd = CreateWindowExA(0, "wmime_keydown_class", NULL, WS_OVERLAPPEDWINDOW,
5699 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5700 NULL, NULL, 0);
5701 flush_events();
5702 flush_sequence();
5704 SendMessage(hwnd, WM_IME_KEYDOWN, VK_RETURN, 0x1c0001);
5705 SendMessage(hwnd, WM_CHAR, 'A', 1);
5706 ok_sequence(WmImeKeydownMsgSeq_0, "WM_IME_KEYDOWN 0", FALSE);
5708 while ( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
5710 TranslateMessage(&msg);
5711 DispatchMessage(&msg);
5713 ok_sequence(WmImeKeydownMsgSeq_1, "WM_IME_KEYDOWN 1", FALSE);
5715 DestroyWindow(hwnd);
5718 /************* painting message test ********************/
5720 void dump_region(HRGN hrgn)
5722 DWORD i, size;
5723 RGNDATA *data = NULL;
5724 RECT *rect;
5726 if (!hrgn)
5728 printf( "null region\n" );
5729 return;
5731 if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5732 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5733 GetRegionData( hrgn, size, data );
5734 printf("%d rects:", data->rdh.nCount );
5735 for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5736 printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
5737 printf("\n");
5738 HeapFree( GetProcessHeap(), 0, data );
5741 static void check_update_rgn( HWND hwnd, HRGN hrgn )
5743 INT ret;
5744 RECT r1, r2;
5745 HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
5746 HRGN update = CreateRectRgn( 0, 0, 0, 0 );
5748 ret = GetUpdateRgn( hwnd, update, FALSE );
5749 ok( ret != ERROR, "GetUpdateRgn failed\n" );
5750 if (ret == NULLREGION)
5752 ok( !hrgn, "Update region shouldn't be empty\n" );
5754 else
5756 if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
5758 ok( 0, "Regions are different\n" );
5759 if (winetest_debug > 0)
5761 printf( "Update region: " );
5762 dump_region( update );
5763 printf( "Wanted region: " );
5764 dump_region( hrgn );
5768 GetRgnBox( update, &r1 );
5769 GetUpdateRect( hwnd, &r2, FALSE );
5770 ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
5771 "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
5772 r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
5774 DeleteObject( tmp );
5775 DeleteObject( update );
5778 static const struct message WmInvalidateRgn[] = {
5779 { WM_NCPAINT, sent },
5780 { WM_GETTEXT, sent|defwinproc|optional },
5781 { 0 }
5784 static const struct message WmGetUpdateRect[] = {
5785 { WM_NCPAINT, sent },
5786 { WM_GETTEXT, sent|defwinproc|optional },
5787 { WM_PAINT, sent },
5788 { 0 }
5791 static const struct message WmInvalidateFull[] = {
5792 { WM_NCPAINT, sent|wparam, 1 },
5793 { WM_GETTEXT, sent|defwinproc|optional },
5794 { 0 }
5797 static const struct message WmInvalidateErase[] = {
5798 { WM_NCPAINT, sent|wparam, 1 },
5799 { WM_GETTEXT, sent|defwinproc|optional },
5800 { WM_ERASEBKGND, sent },
5801 { 0 }
5804 static const struct message WmInvalidatePaint[] = {
5805 { WM_PAINT, sent },
5806 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5807 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5808 { 0 }
5811 static const struct message WmInvalidateErasePaint[] = {
5812 { WM_PAINT, sent },
5813 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5814 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5815 { WM_ERASEBKGND, sent|beginpaint|optional },
5816 { 0 }
5819 static const struct message WmInvalidateErasePaint2[] = {
5820 { WM_PAINT, sent },
5821 { WM_NCPAINT, sent|beginpaint },
5822 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5823 { WM_ERASEBKGND, sent|beginpaint|optional },
5824 { 0 }
5827 static const struct message WmErase[] = {
5828 { WM_ERASEBKGND, sent },
5829 { 0 }
5832 static const struct message WmPaint[] = {
5833 { WM_PAINT, sent },
5834 { 0 }
5837 static const struct message WmParentOnlyPaint[] = {
5838 { WM_PAINT, sent|parent },
5839 { 0 }
5842 static const struct message WmInvalidateParent[] = {
5843 { WM_NCPAINT, sent|parent },
5844 { WM_GETTEXT, sent|defwinproc|parent|optional },
5845 { WM_ERASEBKGND, sent|parent },
5846 { 0 }
5849 static const struct message WmInvalidateParentChild[] = {
5850 { WM_NCPAINT, sent|parent },
5851 { WM_GETTEXT, sent|defwinproc|parent|optional },
5852 { WM_ERASEBKGND, sent|parent },
5853 { WM_NCPAINT, sent },
5854 { WM_GETTEXT, sent|defwinproc|optional },
5855 { WM_ERASEBKGND, sent },
5856 { 0 }
5859 static const struct message WmInvalidateParentChild2[] = {
5860 { WM_ERASEBKGND, sent|parent },
5861 { WM_NCPAINT, sent },
5862 { WM_GETTEXT, sent|defwinproc|optional },
5863 { WM_ERASEBKGND, sent },
5864 { 0 }
5867 static const struct message WmParentPaint[] = {
5868 { WM_PAINT, sent|parent },
5869 { WM_PAINT, sent },
5870 { 0 }
5873 static const struct message WmParentPaintNc[] = {
5874 { WM_PAINT, sent|parent },
5875 { WM_PAINT, sent },
5876 { WM_NCPAINT, sent|beginpaint },
5877 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5878 { WM_ERASEBKGND, sent|beginpaint|optional },
5879 { 0 }
5882 static const struct message WmChildPaintNc[] = {
5883 { WM_PAINT, sent },
5884 { WM_NCPAINT, sent|beginpaint },
5885 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5886 { WM_ERASEBKGND, sent|beginpaint|optional },
5887 { 0 }
5890 static const struct message WmParentErasePaint[] = {
5891 { WM_PAINT, sent|parent },
5892 { WM_NCPAINT, sent|parent|beginpaint },
5893 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5894 { WM_ERASEBKGND, sent|parent|beginpaint|optional },
5895 { WM_PAINT, sent },
5896 { WM_NCPAINT, sent|beginpaint },
5897 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5898 { WM_ERASEBKGND, sent|beginpaint|optional },
5899 { 0 }
5902 static const struct message WmParentOnlyNcPaint[] = {
5903 { WM_PAINT, sent|parent },
5904 { WM_NCPAINT, sent|parent|beginpaint },
5905 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5906 { 0 }
5909 static const struct message WmSetParentStyle[] = {
5910 { WM_STYLECHANGING, sent|parent },
5911 { WM_STYLECHANGED, sent|parent },
5912 { 0 }
5915 static void test_paint_messages(void)
5917 BOOL ret;
5918 RECT rect;
5919 POINT pt;
5920 MSG msg;
5921 HWND hparent, hchild;
5922 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
5923 HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
5924 HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
5925 100, 100, 200, 200, 0, 0, 0, NULL);
5926 ok (hwnd != 0, "Failed to create overlapped window\n");
5928 ShowWindow( hwnd, SW_SHOW );
5929 UpdateWindow( hwnd );
5930 flush_events();
5931 flush_sequence();
5933 check_update_rgn( hwnd, 0 );
5934 SetRectRgn( hrgn, 10, 10, 20, 20 );
5935 ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5936 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5937 check_update_rgn( hwnd, hrgn );
5938 SetRectRgn( hrgn2, 20, 20, 30, 30 );
5939 ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
5940 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5941 CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
5942 check_update_rgn( hwnd, hrgn );
5943 /* validate everything */
5944 ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5945 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5946 check_update_rgn( hwnd, 0 );
5948 /* test empty region */
5949 SetRectRgn( hrgn, 10, 10, 10, 15 );
5950 ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5951 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5952 check_update_rgn( hwnd, 0 );
5953 /* test empty rect */
5954 SetRect( &rect, 10, 10, 10, 15 );
5955 ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
5956 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5957 check_update_rgn( hwnd, 0 );
5959 /* flush pending messages */
5960 flush_events();
5961 flush_sequence();
5963 GetClientRect( hwnd, &rect );
5964 SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
5965 /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
5966 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5968 trace("testing InvalidateRect(0, NULL, FALSE)\n");
5969 SetRectEmpty( &rect );
5970 ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
5971 check_update_rgn( hwnd, hrgn );
5972 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5973 flush_events();
5974 ok_sequence( WmPaint, "Paint", FALSE );
5975 RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5976 check_update_rgn( hwnd, 0 );
5978 /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
5979 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5981 trace("testing ValidateRect(0, NULL)\n");
5982 SetRectEmpty( &rect );
5983 if (ValidateRect(0, &rect)) /* not supported on Win9x */
5985 check_update_rgn( hwnd, hrgn );
5986 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5987 flush_events();
5988 ok_sequence( WmPaint, "Paint", FALSE );
5989 RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5990 check_update_rgn( hwnd, 0 );
5993 trace("testing InvalidateRgn(0, NULL, FALSE)\n");
5994 SetLastError(0xdeadbeef);
5995 ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
5996 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
5997 "wrong error code %d\n", GetLastError());
5998 check_update_rgn( hwnd, 0 );
5999 flush_events();
6000 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6002 trace("testing ValidateRgn(0, NULL)\n");
6003 SetLastError(0xdeadbeef);
6004 ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
6005 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
6006 broken( GetLastError() == 0xdeadbeef ) /* win9x */,
6007 "wrong error code %d\n", GetLastError());
6008 check_update_rgn( hwnd, 0 );
6009 flush_events();
6010 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6012 /* now with frame */
6013 SetRectRgn( hrgn, -5, -5, 20, 20 );
6015 /* flush pending messages */
6016 flush_events();
6017 flush_sequence();
6018 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6019 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
6021 SetRectRgn( hrgn, 0, 0, 20, 20 ); /* GetUpdateRgn clips to client area */
6022 check_update_rgn( hwnd, hrgn );
6024 flush_sequence();
6025 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
6026 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
6028 flush_sequence();
6029 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
6030 ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
6032 GetClientRect( hwnd, &rect );
6033 SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
6034 check_update_rgn( hwnd, hrgn );
6036 flush_sequence();
6037 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
6038 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6040 flush_sequence();
6041 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
6042 ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
6043 check_update_rgn( hwnd, 0 );
6045 flush_sequence();
6046 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
6047 ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
6048 check_update_rgn( hwnd, 0 );
6050 flush_sequence();
6051 SetRectRgn( hrgn, 0, 0, 100, 100 );
6052 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6053 SetRectRgn( hrgn, 0, 0, 50, 100 );
6054 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
6055 SetRectRgn( hrgn, 50, 0, 100, 100 );
6056 check_update_rgn( hwnd, hrgn );
6057 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
6058 ok_sequence( WmEmptySeq, "EmptySeq", FALSE ); /* must not generate messages, everything is valid */
6059 check_update_rgn( hwnd, 0 );
6061 flush_sequence();
6062 SetRectRgn( hrgn, 0, 0, 100, 100 );
6063 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
6064 SetRectRgn( hrgn, 0, 0, 100, 50 );
6065 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
6066 ok_sequence( WmErase, "Erase", FALSE );
6067 SetRectRgn( hrgn, 0, 50, 100, 100 );
6068 check_update_rgn( hwnd, hrgn );
6070 flush_sequence();
6071 SetRectRgn( hrgn, 0, 0, 100, 100 );
6072 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
6073 SetRectRgn( hrgn, 0, 0, 50, 50 );
6074 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
6075 ok_sequence( WmPaint, "Paint", FALSE );
6077 flush_sequence();
6078 SetRectRgn( hrgn, -4, -4, -2, -2 );
6079 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6080 SetRectRgn( hrgn, -200, -200, -198, -198 );
6081 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
6082 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
6084 flush_sequence();
6085 SetRectRgn( hrgn, -4, -4, -2, -2 );
6086 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6087 SetRectRgn( hrgn, -4, -4, -3, -3 );
6088 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
6089 SetRectRgn( hrgn, 0, 0, 1, 1 );
6090 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
6091 ok_sequence( WmPaint, "Paint", FALSE );
6093 flush_sequence();
6094 SetRectRgn( hrgn, -4, -4, -1, -1 );
6095 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6096 RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
6097 /* make sure no WM_PAINT was generated */
6098 flush_events();
6099 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
6101 flush_sequence();
6102 SetRectRgn( hrgn, -4, -4, -1, -1 );
6103 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6104 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
6106 if (msg.hwnd == hwnd && msg.message == WM_PAINT)
6108 /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
6109 INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
6110 ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
6111 ret = GetUpdateRect( hwnd, &rect, FALSE );
6112 ok( ret, "Invalid GetUpdateRect result %d\n", ret );
6113 /* this will send WM_NCPAINT and validate the non client area */
6114 ret = GetUpdateRect( hwnd, &rect, TRUE );
6115 ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
6117 DispatchMessage( &msg );
6119 ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
6121 DestroyWindow( hwnd );
6123 /* now test with a child window */
6125 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
6126 100, 100, 200, 200, 0, 0, 0, NULL);
6127 ok (hparent != 0, "Failed to create parent window\n");
6129 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
6130 10, 10, 100, 100, hparent, 0, 0, NULL);
6131 ok (hchild != 0, "Failed to create child window\n");
6133 ShowWindow( hparent, SW_SHOW );
6134 UpdateWindow( hparent );
6135 UpdateWindow( hchild );
6136 flush_events();
6137 flush_sequence();
6138 log_all_parent_messages++;
6140 SetRect( &rect, 0, 0, 50, 50 );
6141 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6142 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6143 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
6145 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6146 pt.x = pt.y = 0;
6147 MapWindowPoints( hchild, hparent, &pt, 1 );
6148 SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
6149 check_update_rgn( hchild, hrgn );
6150 SetRectRgn( hrgn, 0, 0, 50, 50 );
6151 check_update_rgn( hparent, hrgn );
6152 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6153 ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
6154 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6155 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6157 flush_events();
6158 ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
6160 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6161 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6162 ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
6163 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6164 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6166 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6167 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6168 ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
6170 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6171 flush_sequence();
6172 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6173 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6174 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
6176 /* flush all paint messages */
6177 flush_events();
6178 flush_sequence();
6180 /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
6181 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6182 SetRectRgn( hrgn, 0, 0, 50, 50 );
6183 check_update_rgn( hparent, hrgn );
6184 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6185 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6186 SetRectRgn( hrgn, 0, 0, 50, 50 );
6187 check_update_rgn( hparent, hrgn );
6189 /* flush all paint messages */
6190 flush_events();
6191 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6192 flush_sequence();
6194 /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
6195 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6196 SetRectRgn( hrgn, 0, 0, 50, 50 );
6197 check_update_rgn( hparent, hrgn );
6198 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6199 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6200 SetRectRgn( hrgn2, 10, 10, 50, 50 );
6201 CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
6202 check_update_rgn( hparent, hrgn );
6203 /* flush all paint messages */
6204 flush_events();
6205 flush_sequence();
6207 /* same as above but parent gets completely validated */
6208 SetRect( &rect, 20, 20, 30, 30 );
6209 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6210 SetRectRgn( hrgn, 20, 20, 30, 30 );
6211 check_update_rgn( hparent, hrgn );
6212 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6213 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6214 check_update_rgn( hparent, 0 ); /* no update region */
6215 flush_events();
6216 ok_sequence( WmEmptySeq, "WmEmpty", FALSE ); /* and no paint messages */
6218 /* make sure RDW_VALIDATE on child doesn't have the same effect */
6219 flush_sequence();
6220 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6221 SetRectRgn( hrgn, 20, 20, 30, 30 );
6222 check_update_rgn( hparent, hrgn );
6223 RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
6224 SetRectRgn( hrgn, 20, 20, 30, 30 );
6225 check_update_rgn( hparent, hrgn );
6227 /* same as above but normal WM_PAINT doesn't validate parent */
6228 flush_sequence();
6229 SetRect( &rect, 20, 20, 30, 30 );
6230 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6231 SetRectRgn( hrgn, 20, 20, 30, 30 );
6232 check_update_rgn( hparent, hrgn );
6233 /* no WM_PAINT in child while parent still pending */
6234 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6235 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6236 while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6237 ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
6239 flush_sequence();
6240 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6241 /* no WM_PAINT in child while parent still pending */
6242 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6243 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6244 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
6245 /* now that parent is valid child should get WM_PAINT */
6246 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6247 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6248 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6249 ok_sequence( WmEmptySeq, "No other message", FALSE );
6251 /* same thing with WS_CLIPCHILDREN in parent */
6252 flush_sequence();
6253 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6254 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6255 /* changing style invalidates non client area, but we need to invalidate something else to see it */
6256 RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
6257 ok_sequence( WmEmptySeq, "No message", FALSE );
6258 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
6259 ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
6261 flush_sequence();
6262 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
6263 SetRectRgn( hrgn, 20, 20, 30, 30 );
6264 check_update_rgn( hparent, hrgn );
6265 /* no WM_PAINT in child while parent still pending */
6266 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6267 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6268 /* WM_PAINT in parent first */
6269 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6270 ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
6272 /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
6273 flush_sequence();
6274 SetRect( &rect, 0, 0, 30, 30 );
6275 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
6276 SetRectRgn( hrgn, 0, 0, 30, 30 );
6277 check_update_rgn( hparent, hrgn );
6278 flush_events();
6279 ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
6281 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6282 flush_sequence();
6283 SetRect( &rect, -10, 0, 30, 30 );
6284 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6285 SetRect( &rect, 0, 0, 20, 20 );
6286 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6287 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6288 ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
6290 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6291 flush_sequence();
6292 SetRect( &rect, -10, 0, 30, 30 );
6293 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6294 SetRect( &rect, 0, 0, 100, 100 );
6295 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6296 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6297 ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
6298 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6299 ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
6301 /* test RDW_INTERNALPAINT behavior */
6303 flush_sequence();
6304 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
6305 flush_events();
6306 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6308 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
6309 flush_events();
6310 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6312 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6313 flush_events();
6314 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6316 assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
6317 UpdateWindow( hparent );
6318 flush_events();
6319 flush_sequence();
6320 trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
6321 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6322 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6323 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6324 flush_events();
6325 ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
6327 UpdateWindow( hparent );
6328 flush_events();
6329 flush_sequence();
6330 trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
6331 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6332 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6333 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6334 flush_events();
6335 ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6337 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6338 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6339 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6340 flush_events();
6341 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6343 assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
6344 UpdateWindow( hparent );
6345 flush_events();
6346 flush_sequence();
6347 trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
6348 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6349 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6350 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6351 flush_events();
6352 ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
6354 UpdateWindow( hparent );
6355 flush_events();
6356 flush_sequence();
6357 trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
6358 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6359 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6360 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6361 flush_events();
6362 ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6364 ok(GetWindowLong( hparent, GWL_STYLE ) & WS_VISIBLE, "parent should be visible\n");
6365 ok(GetWindowLong( hchild, GWL_STYLE ) & WS_VISIBLE, "child should be visible\n");
6367 UpdateWindow( hparent );
6368 flush_events();
6369 flush_sequence();
6370 trace("testing SetWindowPos(-10000, -10000) on child\n");
6371 SetWindowPos( hchild, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6372 check_update_rgn( hchild, 0 );
6373 flush_events();
6375 #if 0 /* this one doesn't pass under Wine yet */
6376 UpdateWindow( hparent );
6377 flush_events();
6378 flush_sequence();
6379 trace("testing ShowWindow(SW_MINIMIZE) on child\n");
6380 ShowWindow( hchild, SW_MINIMIZE );
6381 check_update_rgn( hchild, 0 );
6382 flush_events();
6383 #endif
6385 UpdateWindow( hparent );
6386 flush_events();
6387 flush_sequence();
6388 trace("testing SetWindowPos(-10000, -10000) on parent\n");
6389 SetWindowPos( hparent, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6390 check_update_rgn( hparent, 0 );
6391 flush_events();
6393 log_all_parent_messages--;
6394 DestroyWindow( hparent );
6395 ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6397 /* tests for moving windows off-screen (needs simple WS_POPUP windows) */
6399 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_POPUP | WS_VISIBLE,
6400 100, 100, 200, 200, 0, 0, 0, NULL);
6401 ok (hparent != 0, "Failed to create parent window\n");
6403 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
6404 10, 10, 100, 100, hparent, 0, 0, NULL);
6405 ok (hchild != 0, "Failed to create child window\n");
6407 ShowWindow( hparent, SW_SHOW );
6408 UpdateWindow( hparent );
6409 UpdateWindow( hchild );
6410 flush_events();
6411 flush_sequence();
6413 /* moving child outside of parent boundaries changes update region */
6414 SetRect( &rect, 0, 0, 40, 40 );
6415 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6416 SetRectRgn( hrgn, 0, 0, 40, 40 );
6417 check_update_rgn( hchild, hrgn );
6418 MoveWindow( hchild, -10, 10, 100, 100, FALSE );
6419 SetRectRgn( hrgn, 10, 0, 40, 40 );
6420 check_update_rgn( hchild, hrgn );
6421 MoveWindow( hchild, -10, -10, 100, 100, FALSE );
6422 SetRectRgn( hrgn, 10, 10, 40, 40 );
6423 check_update_rgn( hchild, hrgn );
6425 /* moving parent off-screen does too */
6426 SetRect( &rect, 0, 0, 100, 100 );
6427 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
6428 SetRectRgn( hrgn, 0, 0, 100, 100 );
6429 check_update_rgn( hparent, hrgn );
6430 SetRectRgn( hrgn, 10, 10, 40, 40 );
6431 check_update_rgn( hchild, hrgn );
6432 MoveWindow( hparent, -20, -20, 200, 200, FALSE );
6433 SetRectRgn( hrgn, 20, 20, 100, 100 );
6434 check_update_rgn( hparent, hrgn );
6435 SetRectRgn( hrgn, 30, 30, 40, 40 );
6436 check_update_rgn( hchild, hrgn );
6438 /* invalidated region is cropped by the parent rects */
6439 SetRect( &rect, 0, 0, 50, 50 );
6440 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6441 SetRectRgn( hrgn, 30, 30, 50, 50 );
6442 check_update_rgn( hchild, hrgn );
6444 DestroyWindow( hparent );
6445 ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6446 flush_sequence();
6448 DeleteObject( hrgn );
6449 DeleteObject( hrgn2 );
6452 struct wnd_event
6454 HWND hwnd;
6455 HANDLE grand_child;
6456 HANDLE start_event;
6457 HANDLE stop_event;
6460 static DWORD WINAPI thread_proc(void *param)
6462 MSG msg;
6463 struct wnd_event *wnd_event = param;
6465 wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
6466 100, 100, 200, 200, 0, 0, 0, NULL);
6467 ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
6469 SetEvent(wnd_event->start_event);
6471 while (GetMessage(&msg, 0, 0, 0))
6473 TranslateMessage(&msg);
6474 DispatchMessage(&msg);
6477 ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
6479 return 0;
6482 static DWORD CALLBACK create_grand_child_thread( void *param )
6484 struct wnd_event *wnd_event = param;
6485 HWND hchild;
6486 MSG msg;
6488 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
6489 WS_CHILD | WS_VISIBLE, 0, 0, 10, 10, wnd_event->hwnd, 0, 0, NULL);
6490 ok (hchild != 0, "Failed to create child window\n");
6491 flush_events();
6492 flush_sequence();
6493 SetEvent( wnd_event->start_event );
6495 for (;;)
6497 MsgWaitForMultipleObjects(0, NULL, FALSE, 1000, QS_ALLINPUT);
6498 if (!IsWindow( hchild )) break; /* will be destroyed when parent thread exits */
6499 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6501 return 0;
6504 static DWORD CALLBACK create_child_thread( void *param )
6506 struct wnd_event *wnd_event = param;
6507 struct wnd_event child_event;
6508 DWORD ret, tid;
6509 MSG msg;
6511 child_event.hwnd = CreateWindowExA(0, "TestWindowClass", "Test child",
6512 WS_CHILD | WS_VISIBLE, 0, 0, 10, 10, wnd_event->hwnd, 0, 0, NULL);
6513 ok (child_event.hwnd != 0, "Failed to create child window\n");
6514 SetFocus( child_event.hwnd );
6515 flush_events();
6516 flush_sequence();
6517 child_event.start_event = wnd_event->start_event;
6518 wnd_event->grand_child = CreateThread(NULL, 0, create_grand_child_thread, &child_event, 0, &tid);
6519 for (;;)
6521 DWORD ret = MsgWaitForMultipleObjects(1, &child_event.start_event, FALSE, 1000, QS_SENDMESSAGE);
6522 if (ret != 1) break;
6523 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6525 ret = WaitForSingleObject( wnd_event->stop_event, 5000 );
6526 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6527 return 0;
6530 static void test_interthread_messages(void)
6532 HANDLE hThread;
6533 DWORD tid;
6534 WNDPROC proc;
6535 MSG msg;
6536 char buf[256];
6537 int len, expected_len;
6538 struct wnd_event wnd_event;
6539 BOOL ret;
6541 wnd_event.start_event = CreateEventW(NULL, 0, 0, NULL);
6542 if (!wnd_event.start_event)
6544 win_skip("skipping interthread message test under win9x\n");
6545 return;
6548 hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
6549 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
6551 ok(WaitForSingleObject(wnd_event.start_event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6553 CloseHandle(wnd_event.start_event);
6555 SetLastError(0xdeadbeef);
6556 ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
6557 ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
6558 "wrong error code %d\n", GetLastError());
6560 proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6561 ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
6563 expected_len = lstrlenA("window caption text");
6564 memset(buf, 0, sizeof(buf));
6565 SetLastError(0xdeadbeef);
6566 len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
6567 ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
6568 ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
6570 msg.hwnd = wnd_event.hwnd;
6571 msg.message = WM_GETTEXT;
6572 msg.wParam = sizeof(buf);
6573 msg.lParam = (LPARAM)buf;
6574 memset(buf, 0, sizeof(buf));
6575 SetLastError(0xdeadbeef);
6576 len = DispatchMessageA(&msg);
6577 ok((!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY) || broken(len), /* nt4 */
6578 "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
6580 /* the following test causes an exception in user.exe under win9x */
6581 msg.hwnd = wnd_event.hwnd;
6582 msg.message = WM_TIMER;
6583 msg.wParam = 0;
6584 msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6585 SetLastError(0xdeadbeef);
6586 len = DispatchMessageA(&msg);
6587 ok(!len && GetLastError() == 0xdeadbeef,
6588 "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
6590 ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
6591 ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
6593 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6594 CloseHandle(hThread);
6596 ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
6598 wnd_event.hwnd = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6599 100, 100, 200, 200, 0, 0, 0, NULL);
6600 ok (wnd_event.hwnd != 0, "Failed to create parent window\n");
6601 flush_sequence();
6602 log_all_parent_messages++;
6603 wnd_event.start_event = CreateEventA( NULL, TRUE, FALSE, NULL );
6604 wnd_event.stop_event = CreateEventA( NULL, TRUE, FALSE, NULL );
6605 hThread = CreateThread( NULL, 0, create_child_thread, &wnd_event, 0, &tid );
6606 for (;;)
6608 ret = MsgWaitForMultipleObjects(1, &wnd_event.start_event, FALSE, 1000, QS_SENDMESSAGE);
6609 if (ret != 1) break;
6610 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6612 ok( !ret, "MsgWaitForMultipleObjects failed %x\n", ret );
6613 /* now wait for the thread without processing messages; this shouldn't deadlock */
6614 SetEvent( wnd_event.stop_event );
6615 ret = WaitForSingleObject( hThread, 5000 );
6616 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6617 CloseHandle( hThread );
6619 ret = WaitForSingleObject( wnd_event.grand_child, 5000 );
6620 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6621 CloseHandle( wnd_event.grand_child );
6623 CloseHandle( wnd_event.start_event );
6624 CloseHandle( wnd_event.stop_event );
6625 flush_events();
6626 ok_sequence(WmExitThreadSeq, "destroy child on thread exit", FALSE);
6627 log_all_parent_messages--;
6628 DestroyWindow( wnd_event.hwnd );
6632 static const struct message WmVkN[] = {
6633 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6634 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6635 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6636 { WM_CHAR, wparam|lparam, 'n', 1 },
6637 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
6638 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6639 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6640 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6641 { 0 }
6643 static const struct message WmShiftVkN[] = {
6644 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6645 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6646 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6647 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6648 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6649 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6650 { WM_CHAR, wparam|lparam, 'N', 1 },
6651 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
6652 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6653 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6654 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6655 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6656 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6657 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6658 { 0 }
6660 static const struct message WmCtrlVkN[] = {
6661 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6662 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6663 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6664 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6665 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6666 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6667 { WM_CHAR, wparam|lparam, 0x000e, 1 },
6668 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6669 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6670 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6671 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6672 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6673 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6674 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6675 { 0 }
6677 static const struct message WmCtrlVkN_2[] = {
6678 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6679 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6680 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6681 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6682 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6683 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6684 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6685 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6686 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6687 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6688 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6689 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6690 { 0 }
6692 static const struct message WmAltVkN[] = {
6693 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6694 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6695 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6696 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6697 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6698 { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6699 { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
6700 { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
6701 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
6702 { HCBT_SYSCOMMAND, hook },
6703 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6704 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6705 { 0x00AE, sent|defwinproc|optional }, /* XP */
6706 { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
6707 { WM_INITMENU, sent|defwinproc },
6708 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6709 { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
6710 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
6711 { WM_CAPTURECHANGED, sent|defwinproc },
6712 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
6713 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6714 { WM_EXITMENULOOP, sent|defwinproc },
6715 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
6716 { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
6717 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6718 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6719 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6720 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6721 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6722 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6723 { 0 }
6725 static const struct message WmAltVkN_2[] = {
6726 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6727 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6728 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6729 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6730 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6731 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
6732 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6733 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6734 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6735 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6736 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6737 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6738 { 0 }
6740 static const struct message WmCtrlAltVkN[] = {
6741 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6742 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6743 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6744 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6745 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6746 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6747 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6748 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6749 { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6750 { WM_CHAR, optional },
6751 { WM_CHAR, sent|optional },
6752 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6753 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6754 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6755 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6756 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6757 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6758 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6759 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6760 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6761 { 0 }
6763 static const struct message WmCtrlShiftVkN[] = {
6764 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6765 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6766 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6767 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6768 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6769 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6770 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6771 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6772 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
6773 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6774 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6775 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6776 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6777 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6778 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6779 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6780 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6781 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6782 { 0 }
6784 static const struct message WmCtrlAltShiftVkN[] = {
6785 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6786 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6787 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6788 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6789 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6790 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6791 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
6792 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
6793 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
6794 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6795 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6796 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
6797 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6798 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6799 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6800 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
6801 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
6802 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
6803 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6804 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6805 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6806 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6807 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6808 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6809 { 0 }
6811 static const struct message WmAltPressRelease[] = {
6812 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6813 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6814 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6815 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6816 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6817 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6818 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
6819 { HCBT_SYSCOMMAND, hook },
6820 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6821 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6822 { WM_INITMENU, sent|defwinproc },
6823 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6824 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6825 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6827 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
6829 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6830 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
6831 { WM_CAPTURECHANGED, sent|defwinproc },
6832 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
6833 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6834 { WM_EXITMENULOOP, sent|defwinproc },
6835 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6836 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6837 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6838 { 0 }
6840 static const struct message WmShiftMouseButton[] = {
6841 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6842 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6843 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6844 { WM_MOUSEMOVE, wparam|optional, 0, 0 },
6845 { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
6846 { WM_LBUTTONDOWN, wparam, MK_LBUTTON|MK_SHIFT, 0 },
6847 { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON|MK_SHIFT, 0 },
6848 { WM_LBUTTONUP, wparam, MK_SHIFT, 0 },
6849 { WM_LBUTTONUP, sent|wparam, MK_SHIFT, 0 },
6850 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6851 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6852 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6853 { 0 }
6855 static const struct message WmF1Seq[] = {
6856 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
6857 { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
6858 { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
6859 { WM_KEYF1, wparam|lparam, 0, 0 },
6860 { WM_KEYF1, sent|wparam|lparam, 0, 0 },
6861 { WM_HELP, sent|defwinproc },
6862 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
6863 { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
6864 { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
6865 { 0 }
6867 static const struct message WmVkAppsSeq[] = {
6868 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
6869 { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
6870 { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
6871 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
6872 { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
6873 { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
6874 { WM_CONTEXTMENU, lparam, /*hwnd*/0, -1 },
6875 { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, -1 },
6876 { 0 }
6878 static const struct message WmVkF10Seq[] = {
6879 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
6880 { WM_SYSKEYDOWN, wparam|lparam, VK_F10, 1 },
6881 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_F10, 0x00000001 },
6882 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
6883 { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
6884 { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
6885 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_KEYMENU },
6886 { HCBT_SYSCOMMAND, hook },
6887 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6888 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6889 { WM_INITMENU, sent|defwinproc },
6890 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6891 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6892 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6894 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0x10000001 }, /* XP */
6896 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
6897 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6898 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
6899 { WM_CAPTURECHANGED, sent|defwinproc },
6900 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
6901 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6902 { WM_EXITMENULOOP, sent|defwinproc },
6903 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
6904 { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
6905 { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
6906 { 0 }
6908 static const struct message WmShiftF10Seq[] = {
6909 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6910 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6911 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x00000001 },
6912 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
6913 { WM_SYSKEYDOWN, wparam|lparam, VK_F10, 1 },
6914 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_F10, 0x00000001 },
6915 { WM_CONTEXTMENU, sent|defwinproc|lparam, /*hwnd*/0, -1 },
6916 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
6917 { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
6918 { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
6919 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_KEYMENU },
6920 { HCBT_SYSCOMMAND, hook },
6921 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6922 { WM_INITMENU, sent|defwinproc },
6923 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6924 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xd0000001 }, /* XP */
6925 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0x10000001 }, /* XP */
6926 { WM_CAPTURECHANGED, sent|defwinproc|wparam|lparam, 0, 0 },
6927 { WM_MENUSELECT, sent|defwinproc|wparam|lparam, 0xffff0000, 0 },
6928 { WM_EXITMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6929 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0xc0000001 }, /* XP */
6930 { WM_KEYUP, wparam|lparam, VK_ESCAPE, 0xc0000001 },
6931 { WM_KEYUP, sent|wparam|lparam, VK_ESCAPE, 0xc0000001 },
6932 { 0 }
6935 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
6937 MSG msg;
6939 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
6941 struct recvd_message log_msg;
6943 /* ignore some unwanted messages */
6944 if (msg.message == WM_MOUSEMOVE ||
6945 msg.message == WM_TIMER ||
6946 ignore_message( msg.message ))
6947 continue;
6949 log_msg.hwnd = msg.hwnd;
6950 log_msg.message = msg.message;
6951 log_msg.flags = wparam|lparam;
6952 log_msg.wParam = msg.wParam;
6953 log_msg.lParam = msg.lParam;
6954 log_msg.descr = "accel";
6955 add_message(&log_msg);
6957 if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
6959 TranslateMessage(&msg);
6960 DispatchMessage(&msg);
6965 static void test_accelerators(void)
6967 RECT rc;
6968 POINT pt;
6969 SHORT state;
6970 HACCEL hAccel;
6971 HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6972 100, 100, 200, 200, 0, 0, 0, NULL);
6973 BOOL ret;
6975 assert(hwnd != 0);
6976 UpdateWindow(hwnd);
6977 flush_events();
6978 flush_sequence();
6980 SetFocus(hwnd);
6981 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
6983 state = GetKeyState(VK_SHIFT);
6984 ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
6985 state = GetKeyState(VK_CAPITAL);
6986 ok(state == 0, "wrong CapsLock state %04x\n", state);
6988 hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
6989 assert(hAccel != 0);
6991 flush_events();
6992 pump_msg_loop(hwnd, 0);
6993 flush_sequence();
6995 trace("testing VK_N press/release\n");
6996 flush_sequence();
6997 keybd_event('N', 0, 0, 0);
6998 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6999 pump_msg_loop(hwnd, hAccel);
7000 if (!sequence_cnt) /* we didn't get any message */
7002 skip( "queuing key events not supported\n" );
7003 goto done;
7005 ok_sequence(WmVkN, "VK_N press/release", FALSE);
7007 trace("testing Shift+VK_N press/release\n");
7008 flush_sequence();
7009 keybd_event(VK_SHIFT, 0, 0, 0);
7010 keybd_event('N', 0, 0, 0);
7011 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7012 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7013 pump_msg_loop(hwnd, hAccel);
7014 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
7016 trace("testing Ctrl+VK_N press/release\n");
7017 flush_sequence();
7018 keybd_event(VK_CONTROL, 0, 0, 0);
7019 keybd_event('N', 0, 0, 0);
7020 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7021 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7022 pump_msg_loop(hwnd, hAccel);
7023 ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
7025 trace("testing Alt+VK_N press/release\n");
7026 flush_sequence();
7027 keybd_event(VK_MENU, 0, 0, 0);
7028 keybd_event('N', 0, 0, 0);
7029 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7030 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7031 pump_msg_loop(hwnd, hAccel);
7032 ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
7034 trace("testing Ctrl+Alt+VK_N press/release 1\n");
7035 flush_sequence();
7036 keybd_event(VK_CONTROL, 0, 0, 0);
7037 keybd_event(VK_MENU, 0, 0, 0);
7038 keybd_event('N', 0, 0, 0);
7039 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7040 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7041 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7042 pump_msg_loop(hwnd, hAccel);
7043 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
7045 ret = DestroyAcceleratorTable(hAccel);
7046 ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7048 hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
7049 assert(hAccel != 0);
7051 trace("testing VK_N press/release\n");
7052 flush_sequence();
7053 keybd_event('N', 0, 0, 0);
7054 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7055 pump_msg_loop(hwnd, hAccel);
7056 ok_sequence(WmVkN, "VK_N press/release", FALSE);
7058 trace("testing Shift+VK_N press/release\n");
7059 flush_sequence();
7060 keybd_event(VK_SHIFT, 0, 0, 0);
7061 keybd_event('N', 0, 0, 0);
7062 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7063 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7064 pump_msg_loop(hwnd, hAccel);
7065 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
7067 trace("testing Ctrl+VK_N press/release 2\n");
7068 flush_sequence();
7069 keybd_event(VK_CONTROL, 0, 0, 0);
7070 keybd_event('N', 0, 0, 0);
7071 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7072 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7073 pump_msg_loop(hwnd, hAccel);
7074 ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
7076 trace("testing Alt+VK_N press/release 2\n");
7077 flush_sequence();
7078 keybd_event(VK_MENU, 0, 0, 0);
7079 keybd_event('N', 0, 0, 0);
7080 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7081 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7082 pump_msg_loop(hwnd, hAccel);
7083 ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
7085 trace("testing Ctrl+Alt+VK_N press/release 2\n");
7086 flush_sequence();
7087 keybd_event(VK_CONTROL, 0, 0, 0);
7088 keybd_event(VK_MENU, 0, 0, 0);
7089 keybd_event('N', 0, 0, 0);
7090 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7091 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7092 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7093 pump_msg_loop(hwnd, hAccel);
7094 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
7096 trace("testing Ctrl+Shift+VK_N press/release\n");
7097 flush_sequence();
7098 keybd_event(VK_CONTROL, 0, 0, 0);
7099 keybd_event(VK_SHIFT, 0, 0, 0);
7100 keybd_event('N', 0, 0, 0);
7101 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7102 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7103 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7104 pump_msg_loop(hwnd, hAccel);
7105 ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
7107 trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
7108 flush_sequence();
7109 keybd_event(VK_CONTROL, 0, 0, 0);
7110 keybd_event(VK_MENU, 0, 0, 0);
7111 keybd_event(VK_SHIFT, 0, 0, 0);
7112 keybd_event('N', 0, 0, 0);
7113 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7114 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7115 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7116 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7117 pump_msg_loop(hwnd, hAccel);
7118 ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
7120 ret = DestroyAcceleratorTable(hAccel);
7121 ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7122 hAccel = 0;
7124 trace("testing Alt press/release\n");
7125 flush_sequence();
7126 keybd_event(VK_MENU, 0, 0, 0);
7127 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7128 keybd_event(VK_MENU, 0, 0, 0);
7129 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7130 pump_msg_loop(hwnd, 0);
7131 /* this test doesn't pass in Wine for managed windows */
7132 ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
7134 trace("testing VK_F1 press/release\n");
7135 keybd_event(VK_F1, 0, 0, 0);
7136 keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
7137 pump_msg_loop(hwnd, 0);
7138 ok_sequence(WmF1Seq, "F1 press/release", FALSE);
7140 trace("testing VK_APPS press/release\n");
7141 keybd_event(VK_APPS, 0, 0, 0);
7142 keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
7143 pump_msg_loop(hwnd, 0);
7144 ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
7146 trace("testing VK_F10 press/release\n");
7147 keybd_event(VK_F10, 0, 0, 0);
7148 keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7149 keybd_event(VK_F10, 0, 0, 0);
7150 keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7151 pump_msg_loop(hwnd, 0);
7152 ok_sequence(WmVkF10Seq, "VK_F10 press/release", TRUE);
7154 trace("testing SHIFT+F10 press/release\n");
7155 keybd_event(VK_SHIFT, 0, 0, 0);
7156 keybd_event(VK_F10, 0, 0, 0);
7157 keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7158 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7159 keybd_event(VK_ESCAPE, 0, 0, 0);
7160 keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0);
7161 pump_msg_loop(hwnd, 0);
7162 ok_sequence(WmShiftF10Seq, "SHIFT+F10 press/release", TRUE);
7164 trace("testing Shift+MouseButton press/release\n");
7165 /* first, move mouse pointer inside of the window client area */
7166 GetClientRect(hwnd, &rc);
7167 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
7168 rc.left += (rc.right - rc.left)/2;
7169 rc.top += (rc.bottom - rc.top)/2;
7170 SetCursorPos(rc.left, rc.top);
7171 SetActiveWindow(hwnd);
7173 flush_events();
7174 flush_sequence();
7175 GetCursorPos(&pt);
7176 if (pt.x == rc.left && pt.y == rc.top)
7178 int i;
7179 keybd_event(VK_SHIFT, 0, 0, 0);
7180 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
7181 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7182 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7183 pump_msg_loop(hwnd, 0);
7184 for (i = 0; i < sequence_cnt; i++) if (sequence[i].message == WM_LBUTTONDOWN) break;
7185 if (i < sequence_cnt)
7186 ok_sequence(WmShiftMouseButton, "Shift+MouseButton press/release", FALSE);
7187 else
7188 skip( "Shift+MouseButton event didn't get to the window\n" );
7191 done:
7192 if (hAccel) DestroyAcceleratorTable(hAccel);
7193 DestroyWindow(hwnd);
7196 /************* window procedures ********************/
7198 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message,
7199 WPARAM wParam, LPARAM lParam)
7201 static LONG defwndproc_counter = 0;
7202 static LONG beginpaint_counter = 0;
7203 LRESULT ret;
7204 struct recvd_message msg;
7206 if (ignore_message( message )) return 0;
7208 switch (message)
7210 case WM_ENABLE:
7212 LONG style = GetWindowLongA(hwnd, GWL_STYLE);
7213 ok((BOOL)wParam == !(style & WS_DISABLED),
7214 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
7215 break;
7218 case WM_CAPTURECHANGED:
7219 if (test_DestroyWindow_flag)
7221 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7222 if (style & WS_CHILD)
7223 lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7224 else if (style & WS_POPUP)
7225 lParam = WND_POPUP_ID;
7226 else
7227 lParam = WND_PARENT_ID;
7229 break;
7231 case WM_NCDESTROY:
7233 HWND capture;
7235 ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
7236 capture = GetCapture();
7237 if (capture)
7239 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
7240 trace("current capture %p, releasing...\n", capture);
7241 ReleaseCapture();
7244 /* fall through */
7245 case WM_DESTROY:
7246 if (pGetAncestor)
7247 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
7248 if (test_DestroyWindow_flag)
7250 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7251 if (style & WS_CHILD)
7252 lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7253 else if (style & WS_POPUP)
7254 lParam = WND_POPUP_ID;
7255 else
7256 lParam = WND_PARENT_ID;
7258 break;
7260 /* test_accelerators() depends on this */
7261 case WM_NCHITTEST:
7262 return HTCLIENT;
7264 /* ignore */
7265 case WM_MOUSEMOVE:
7266 case WM_MOUSEACTIVATE:
7267 case WM_NCMOUSEMOVE:
7268 case WM_SETCURSOR:
7269 case WM_IME_SELECT:
7270 return 0;
7273 msg.hwnd = hwnd;
7274 msg.message = message;
7275 msg.flags = sent|wparam|lparam;
7276 if (defwndproc_counter) msg.flags |= defwinproc;
7277 if (beginpaint_counter) msg.flags |= beginpaint;
7278 msg.wParam = wParam;
7279 msg.lParam = lParam;
7280 msg.descr = "MsgCheckProc";
7281 add_message(&msg);
7283 if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
7285 HWND parent = GetParent(hwnd);
7286 RECT rc;
7287 MINMAXINFO *minmax = (MINMAXINFO *)lParam;
7289 GetClientRect(parent, &rc);
7290 trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
7291 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
7292 minmax->ptReserved.x, minmax->ptReserved.y,
7293 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
7294 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
7295 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
7296 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
7298 ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
7299 minmax->ptMaxSize.x, rc.right);
7300 ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
7301 minmax->ptMaxSize.y, rc.bottom);
7304 if (message == WM_PAINT)
7306 PAINTSTRUCT ps;
7307 beginpaint_counter++;
7308 BeginPaint( hwnd, &ps );
7309 beginpaint_counter--;
7310 EndPaint( hwnd, &ps );
7311 return 0;
7314 defwndproc_counter++;
7315 ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam)
7316 : DefWindowProcA(hwnd, message, wParam, lParam);
7317 defwndproc_counter--;
7319 return ret;
7322 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7324 return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
7327 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7329 return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
7332 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7334 static LONG defwndproc_counter = 0;
7335 LRESULT ret;
7336 struct recvd_message msg;
7338 if (ignore_message( message )) return 0;
7340 switch (message)
7342 case WM_QUERYENDSESSION:
7343 case WM_ENDSESSION:
7344 lParam &= ~0x01; /* Vista adds a 0x01 flag */
7345 break;
7348 msg.hwnd = hwnd;
7349 msg.message = message;
7350 msg.flags = sent|wparam|lparam;
7351 if (defwndproc_counter) msg.flags |= defwinproc;
7352 msg.wParam = wParam;
7353 msg.lParam = lParam;
7354 msg.descr = "popup";
7355 add_message(&msg);
7357 if (message == WM_CREATE)
7359 DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
7360 SetWindowLongA(hwnd, GWL_STYLE, style);
7363 defwndproc_counter++;
7364 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7365 defwndproc_counter--;
7367 return ret;
7370 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7372 static LONG defwndproc_counter = 0;
7373 static LONG beginpaint_counter = 0;
7374 LRESULT ret;
7375 struct recvd_message msg;
7377 if (ignore_message( message )) return 0;
7379 if (log_all_parent_messages ||
7380 message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
7381 message == WM_SETFOCUS || message == WM_KILLFOCUS ||
7382 message == WM_ENABLE || message == WM_ENTERIDLE ||
7383 message == WM_DRAWITEM || message == WM_COMMAND ||
7384 message == WM_IME_SETCONTEXT)
7386 switch (message)
7388 /* ignore */
7389 case WM_NCHITTEST:
7390 return HTCLIENT;
7391 case WM_SETCURSOR:
7392 case WM_MOUSEMOVE:
7393 case WM_NCMOUSEMOVE:
7394 return 0;
7396 case WM_ERASEBKGND:
7398 RECT rc;
7399 INT ret = GetClipBox((HDC)wParam, &rc);
7401 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
7402 ret, rc.left, rc.top, rc.right, rc.bottom);
7403 break;
7407 msg.hwnd = hwnd;
7408 msg.message = message;
7409 msg.flags = sent|parent|wparam|lparam;
7410 if (defwndproc_counter) msg.flags |= defwinproc;
7411 if (beginpaint_counter) msg.flags |= beginpaint;
7412 msg.wParam = wParam;
7413 msg.lParam = lParam;
7414 msg.descr = "parent";
7415 add_message(&msg);
7418 if (message == WM_PAINT)
7420 PAINTSTRUCT ps;
7421 beginpaint_counter++;
7422 BeginPaint( hwnd, &ps );
7423 beginpaint_counter--;
7424 EndPaint( hwnd, &ps );
7425 return 0;
7428 defwndproc_counter++;
7429 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7430 defwndproc_counter--;
7432 return ret;
7435 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7437 static LONG defwndproc_counter = 0;
7438 LRESULT ret;
7439 struct recvd_message msg;
7441 if (ignore_message( message )) return 0;
7443 if (test_def_id)
7445 DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
7446 ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
7447 if (after_end_dialog)
7448 ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
7449 else
7450 ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
7453 msg.hwnd = hwnd;
7454 msg.message = message;
7455 msg.flags = sent|wparam|lparam;
7456 if (defwndproc_counter) msg.flags |= defwinproc;
7457 msg.wParam = wParam;
7458 msg.lParam = lParam;
7459 msg.descr = "dialog";
7460 add_message(&msg);
7462 defwndproc_counter++;
7463 ret = DefDlgProcA(hwnd, message, wParam, lParam);
7464 defwndproc_counter--;
7466 return ret;
7469 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7471 static LONG defwndproc_counter = 0;
7472 LRESULT ret;
7473 struct recvd_message msg;
7475 /* log only specific messages we are interested in */
7476 switch (message)
7478 #if 0 /* probably log these as well */
7479 case WM_ACTIVATE:
7480 case WM_SETFOCUS:
7481 case WM_KILLFOCUS:
7482 #endif
7483 case WM_SHOWWINDOW:
7484 case WM_SIZE:
7485 case WM_MOVE:
7486 case WM_GETMINMAXINFO:
7487 case WM_WINDOWPOSCHANGING:
7488 case WM_WINDOWPOSCHANGED:
7489 break;
7491 default: /* ignore */
7492 /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
7493 return DefWindowProcA(hwnd, message, wParam, lParam);
7496 msg.hwnd = hwnd;
7497 msg.message = message;
7498 msg.flags = sent|wparam|lparam;
7499 if (defwndproc_counter) msg.flags |= defwinproc;
7500 msg.wParam = wParam;
7501 msg.lParam = lParam;
7502 msg.descr = "show";
7503 add_message(&msg);
7505 defwndproc_counter++;
7506 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7507 defwndproc_counter--;
7509 return ret;
7512 static LRESULT WINAPI PaintLoopProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
7514 switch (msg)
7516 case WM_CREATE: return 0;
7517 case WM_PAINT:
7519 MSG msg2;
7520 static int i = 0;
7522 if (i < 256)
7524 i++;
7525 if (PeekMessageA(&msg2, 0, 0, 0, 1))
7527 TranslateMessage(&msg2);
7528 DispatchMessage(&msg2);
7530 i--;
7532 else ok(broken(1), "infinite loop\n");
7533 if ( i == 0)
7534 paint_loop_done = 1;
7535 return DefWindowProcA(hWnd,msg,wParam,lParam);
7538 return DefWindowProcA(hWnd,msg,wParam,lParam);
7541 static BOOL RegisterWindowClasses(void)
7543 WNDCLASSA cls;
7544 WNDCLASSW clsW;
7546 cls.style = 0;
7547 cls.lpfnWndProc = MsgCheckProcA;
7548 cls.cbClsExtra = 0;
7549 cls.cbWndExtra = 0;
7550 cls.hInstance = GetModuleHandleA(0);
7551 cls.hIcon = 0;
7552 cls.hCursor = LoadCursorA(0, IDC_ARROW);
7553 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7554 cls.lpszMenuName = NULL;
7555 cls.lpszClassName = "TestWindowClass";
7556 if(!RegisterClassA(&cls)) return FALSE;
7558 cls.lpfnWndProc = ShowWindowProcA;
7559 cls.lpszClassName = "ShowWindowClass";
7560 if(!RegisterClassA(&cls)) return FALSE;
7562 cls.lpfnWndProc = PopupMsgCheckProcA;
7563 cls.lpszClassName = "TestPopupClass";
7564 if(!RegisterClassA(&cls)) return FALSE;
7566 cls.lpfnWndProc = ParentMsgCheckProcA;
7567 cls.lpszClassName = "TestParentClass";
7568 if(!RegisterClassA(&cls)) return FALSE;
7570 cls.lpfnWndProc = DefWindowProcA;
7571 cls.lpszClassName = "SimpleWindowClass";
7572 if(!RegisterClassA(&cls)) return FALSE;
7574 cls.lpfnWndProc = PaintLoopProcA;
7575 cls.lpszClassName = "PaintLoopWindowClass";
7576 if(!RegisterClassA(&cls)) return FALSE;
7578 cls.style = CS_NOCLOSE;
7579 cls.lpszClassName = "NoCloseWindowClass";
7580 if(!RegisterClassA(&cls)) return FALSE;
7582 ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
7583 cls.style = 0;
7584 cls.hInstance = GetModuleHandleA(0);
7585 cls.hbrBackground = 0;
7586 cls.lpfnWndProc = TestDlgProcA;
7587 cls.lpszClassName = "TestDialogClass";
7588 if(!RegisterClassA(&cls)) return FALSE;
7590 clsW.style = 0;
7591 clsW.lpfnWndProc = MsgCheckProcW;
7592 clsW.cbClsExtra = 0;
7593 clsW.cbWndExtra = 0;
7594 clsW.hInstance = GetModuleHandleW(0);
7595 clsW.hIcon = 0;
7596 clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
7597 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
7598 clsW.lpszMenuName = NULL;
7599 clsW.lpszClassName = testWindowClassW;
7600 RegisterClassW(&clsW); /* ignore error, this fails on Win9x */
7602 return TRUE;
7605 static BOOL is_our_logged_class(HWND hwnd)
7607 char buf[256];
7609 if (GetClassNameA(hwnd, buf, sizeof(buf)))
7611 if (!lstrcmpiA(buf, "TestWindowClass") ||
7612 !lstrcmpiA(buf, "ShowWindowClass") ||
7613 !lstrcmpiA(buf, "TestParentClass") ||
7614 !lstrcmpiA(buf, "TestPopupClass") ||
7615 !lstrcmpiA(buf, "SimpleWindowClass") ||
7616 !lstrcmpiA(buf, "TestDialogClass") ||
7617 !lstrcmpiA(buf, "MDI_frame_class") ||
7618 !lstrcmpiA(buf, "MDI_client_class") ||
7619 !lstrcmpiA(buf, "MDI_child_class") ||
7620 !lstrcmpiA(buf, "my_button_class") ||
7621 !lstrcmpiA(buf, "my_edit_class") ||
7622 !lstrcmpiA(buf, "static") ||
7623 !lstrcmpiA(buf, "ListBox") ||
7624 !lstrcmpiA(buf, "ComboBox") ||
7625 !lstrcmpiA(buf, "MyDialogClass") ||
7626 !lstrcmpiA(buf, "#32770") ||
7627 !lstrcmpiA(buf, "#32768"))
7628 return TRUE;
7630 return FALSE;
7633 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
7635 HWND hwnd;
7637 ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7639 if (nCode == HCBT_CLICKSKIPPED)
7641 /* ignore this event, XP sends it a lot when switching focus between windows */
7642 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7645 if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
7647 struct recvd_message msg;
7649 msg.hwnd = 0;
7650 msg.message = nCode;
7651 msg.flags = hook|wparam|lparam;
7652 msg.wParam = wParam;
7653 msg.lParam = lParam;
7654 msg.descr = "CBT";
7655 add_message(&msg);
7657 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7660 if (nCode == HCBT_DESTROYWND)
7662 if (test_DestroyWindow_flag)
7664 DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
7665 if (style & WS_CHILD)
7666 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
7667 else if (style & WS_POPUP)
7668 lParam = WND_POPUP_ID;
7669 else
7670 lParam = WND_PARENT_ID;
7674 /* Log also SetFocus(0) calls */
7675 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7677 if (is_our_logged_class(hwnd))
7679 struct recvd_message msg;
7681 msg.hwnd = hwnd;
7682 msg.message = nCode;
7683 msg.flags = hook|wparam|lparam;
7684 msg.wParam = wParam;
7685 msg.lParam = lParam;
7686 msg.descr = "CBT";
7687 add_message(&msg);
7689 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7692 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
7693 DWORD event,
7694 HWND hwnd,
7695 LONG object_id,
7696 LONG child_id,
7697 DWORD thread_id,
7698 DWORD event_time)
7700 ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7702 /* ignore mouse cursor events */
7703 if (object_id == OBJID_CURSOR) return;
7705 if (!hwnd || is_our_logged_class(hwnd))
7707 struct recvd_message msg;
7709 msg.hwnd = hwnd;
7710 msg.message = event;
7711 msg.flags = winevent_hook|wparam|lparam;
7712 msg.wParam = object_id;
7713 msg.lParam = child_id;
7714 msg.descr = "WEH";
7715 add_message(&msg);
7719 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
7720 static const WCHAR wszAnsi[] = {'U',0};
7722 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
7724 switch (uMsg)
7726 case CB_FINDSTRINGEXACT:
7727 trace("String: %p\n", (LPCWSTR)lParam);
7728 if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
7729 return 1;
7730 if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
7731 return 0;
7732 return -1;
7734 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
7737 static const struct message WmGetTextLengthAfromW[] = {
7738 { WM_GETTEXTLENGTH, sent },
7739 { WM_GETTEXT, sent|optional },
7740 { 0 }
7743 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
7745 /* dummy window proc for WM_GETTEXTLENGTH test */
7746 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
7748 switch(msg)
7750 case WM_GETTEXTLENGTH:
7751 return lstrlenW(dummy_window_text) + 37; /* some random length */
7752 case WM_GETTEXT:
7753 lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
7754 return lstrlenW( (LPWSTR)lp );
7755 default:
7756 return DefWindowProcW( hwnd, msg, wp, lp );
7760 static void test_message_conversion(void)
7762 static const WCHAR wszMsgConversionClass[] =
7763 {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
7764 WNDCLASSW cls;
7765 LRESULT lRes;
7766 HWND hwnd;
7767 WNDPROC wndproc, newproc;
7768 BOOL ret;
7770 cls.style = 0;
7771 cls.lpfnWndProc = MsgConversionProcW;
7772 cls.cbClsExtra = 0;
7773 cls.cbWndExtra = 0;
7774 cls.hInstance = GetModuleHandleW(NULL);
7775 cls.hIcon = NULL;
7776 cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
7777 cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
7778 cls.lpszMenuName = NULL;
7779 cls.lpszClassName = wszMsgConversionClass;
7780 /* this call will fail on Win9x, but that doesn't matter as this test is
7781 * meaningless on those platforms */
7782 if(!RegisterClassW(&cls)) return;
7784 hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
7785 100, 100, 200, 200, 0, 0, 0, NULL);
7786 ok(hwnd != NULL, "Window creation failed\n");
7788 /* {W, A} -> A */
7790 wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
7791 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7792 ok(lRes == 0, "String should have been converted\n");
7793 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7794 ok(lRes == 1, "String shouldn't have been converted\n");
7796 /* {W, A} -> W */
7798 wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
7799 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7800 ok(lRes == 1, "String shouldn't have been converted\n");
7801 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7802 ok(lRes == 1, "String shouldn't have been converted\n");
7804 /* Synchronous messages */
7806 lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7807 ok(lRes == 0, "String should have been converted\n");
7808 lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7809 ok(lRes == 1, "String shouldn't have been converted\n");
7811 /* Asynchronous messages */
7813 SetLastError(0);
7814 lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7815 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7816 "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7817 SetLastError(0);
7818 lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7819 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7820 "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7821 SetLastError(0);
7822 lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7823 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7824 "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7825 SetLastError(0);
7826 lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7827 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7828 "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7829 SetLastError(0);
7830 lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7831 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7832 "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7833 SetLastError(0);
7834 lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7835 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7836 "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7837 SetLastError(0);
7838 lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7839 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7840 "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7841 SetLastError(0);
7842 lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7843 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7844 "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7846 /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
7848 hwnd = CreateWindowW (testWindowClassW, wszUnicode,
7849 WS_OVERLAPPEDWINDOW,
7850 100, 100, 200, 200, 0, 0, 0, NULL);
7851 assert(hwnd);
7852 flush_sequence();
7853 lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
7854 ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7855 ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7856 "got bad length %ld\n", lRes );
7858 flush_sequence();
7859 lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
7860 hwnd, WM_GETTEXTLENGTH, 0, 0);
7861 ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7862 ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7863 "got bad length %ld\n", lRes );
7865 wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
7866 newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
7867 lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7868 ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7869 NULL, 0, NULL, NULL ) ||
7870 broken(lRes == lstrlenW(dummy_window_text) + 37),
7871 "got bad length %ld\n", lRes );
7873 SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc ); /* restore old wnd proc */
7874 lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7875 ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7876 NULL, 0, NULL, NULL ) ||
7877 broken(lRes == lstrlenW(dummy_window_text) + 37),
7878 "got bad length %ld\n", lRes );
7880 ret = DestroyWindow(hwnd);
7881 ok( ret, "DestroyWindow() error %d\n", GetLastError());
7884 struct timer_info
7886 HWND hWnd;
7887 HANDLE handles[2];
7888 DWORD id;
7891 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
7895 static VOID CALLBACK tfunc_crash(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
7897 /* Crash on purpose */
7898 *(volatile int *)0 = 2;
7901 #define TIMER_ID 0x19
7903 static DWORD WINAPI timer_thread_proc(LPVOID x)
7905 struct timer_info *info = x;
7906 DWORD r;
7908 r = KillTimer(info->hWnd, 0x19);
7909 ok(r,"KillTimer failed in thread\n");
7910 r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
7911 ok(r,"SetTimer failed in thread\n");
7912 ok(r==TIMER_ID,"SetTimer id different\n");
7913 r = SetEvent(info->handles[0]);
7914 ok(r,"SetEvent failed in thread\n");
7915 return 0;
7918 static void test_timers(void)
7920 struct timer_info info;
7921 DWORD id;
7922 MSG msg;
7924 info.hWnd = CreateWindow ("TestWindowClass", NULL,
7925 WS_OVERLAPPEDWINDOW ,
7926 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7927 NULL, NULL, 0);
7929 info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
7930 ok(info.id, "SetTimer failed\n");
7931 ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
7932 info.handles[0] = CreateEvent(NULL,0,0,NULL);
7933 info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
7935 WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
7937 WaitForSingleObject(info.handles[1], INFINITE);
7939 CloseHandle(info.handles[0]);
7940 CloseHandle(info.handles[1]);
7942 ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
7944 ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
7946 /* Test timer callback with crash */
7947 SetLastError(0xdeadbeef);
7948 info.hWnd = CreateWindowW(testWindowClassW, NULL,
7949 WS_OVERLAPPEDWINDOW ,
7950 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7951 NULL, NULL, 0);
7952 if ((!info.hWnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) || /* Win9x/Me */
7953 (!pGetMenuInfo)) /* Win95/NT4 */
7955 win_skip("Test would crash on Win9x/WinMe/NT4\n");
7956 DestroyWindow(info.hWnd);
7957 return;
7959 info.id = SetTimer(info.hWnd, TIMER_ID, 0, tfunc_crash);
7960 ok(info.id, "SetTimer failed\n");
7961 Sleep(150);
7962 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7964 ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
7967 static int count = 0;
7968 static VOID CALLBACK callback_count(
7969 HWND hwnd,
7970 UINT uMsg,
7971 UINT_PTR idEvent,
7972 DWORD dwTime
7975 count++;
7978 static void test_timers_no_wnd(void)
7980 UINT_PTR id, id2;
7981 MSG msg;
7983 count = 0;
7984 id = SetTimer(NULL, 0, 100, callback_count);
7985 ok(id != 0, "did not get id from SetTimer.\n");
7986 id2 = SetTimer(NULL, id, 200, callback_count);
7987 ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
7988 Sleep(150);
7989 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7990 ok(count == 0, "did not get zero count as expected (%i).\n", count);
7991 Sleep(150);
7992 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7993 ok(count == 1, "did not get one count as expected (%i).\n", count);
7994 KillTimer(NULL, id);
7995 Sleep(250);
7996 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7997 ok(count == 1, "killing replaced timer did not work (%i).\n", count);
8000 /* Various win events with arbitrary parameters */
8001 static const struct message WmWinEventsSeq[] = {
8002 { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
8003 { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
8004 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
8005 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
8006 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
8007 { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
8008 { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
8009 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
8010 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
8011 /* our win event hook ignores OBJID_CURSOR events */
8012 /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
8013 { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
8014 { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
8015 { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
8016 { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
8017 { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
8018 { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
8019 { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
8020 { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
8021 { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
8022 { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
8023 { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
8024 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
8025 { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
8026 { 0 }
8028 static const struct message WmWinEventCaretSeq[] = {
8029 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8030 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8031 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
8032 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8033 { 0 }
8035 static const struct message WmWinEventCaretSeq_2[] = {
8036 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8037 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8038 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8039 { 0 }
8041 static const struct message WmWinEventAlertSeq[] = {
8042 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
8043 { 0 }
8045 static const struct message WmWinEventAlertSeq_2[] = {
8046 /* create window in the thread proc */
8047 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
8048 /* our test event */
8049 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
8050 { 0 }
8052 static const struct message WmGlobalHookSeq_1[] = {
8053 /* create window in the thread proc */
8054 { HCBT_CREATEWND, hook|lparam, 0, 2 },
8055 /* our test events */
8056 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
8057 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
8058 { 0 }
8060 static const struct message WmGlobalHookSeq_2[] = {
8061 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
8062 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
8063 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
8064 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
8065 { 0 }
8068 static const struct message WmMouseLLHookSeq[] = {
8069 { WM_MOUSEMOVE, hook },
8070 { WM_LBUTTONUP, hook },
8071 { WM_MOUSEMOVE, hook },
8072 { 0 }
8075 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
8076 DWORD event,
8077 HWND hwnd,
8078 LONG object_id,
8079 LONG child_id,
8080 DWORD thread_id,
8081 DWORD event_time)
8083 char buf[256];
8085 if (GetClassNameA(hwnd, buf, sizeof(buf)))
8087 if (!lstrcmpiA(buf, "TestWindowClass") ||
8088 !lstrcmpiA(buf, "static"))
8090 struct recvd_message msg;
8092 msg.hwnd = hwnd;
8093 msg.message = event;
8094 msg.flags = winevent_hook|wparam|lparam;
8095 msg.wParam = object_id;
8096 msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
8097 msg.descr = "WEH_2";
8098 add_message(&msg);
8103 static HHOOK hCBT_global_hook;
8104 static DWORD cbt_global_hook_thread_id;
8106 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
8108 HWND hwnd;
8109 char buf[256];
8111 if (nCode == HCBT_SYSCOMMAND)
8113 struct recvd_message msg;
8115 msg.hwnd = 0;
8116 msg.message = nCode;
8117 msg.flags = hook|wparam|lparam;
8118 msg.wParam = wParam;
8119 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8120 msg.descr = "CBT_2";
8121 add_message(&msg);
8123 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8125 /* WH_MOUSE_LL hook */
8126 if (nCode == HC_ACTION)
8128 MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
8130 /* we can't test for real mouse events */
8131 if (mhll->flags & LLMHF_INJECTED)
8133 struct recvd_message msg;
8135 memset (&msg, 0, sizeof (msg));
8136 msg.message = wParam;
8137 msg.flags = hook;
8138 msg.descr = "CBT_2";
8139 add_message(&msg);
8141 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8144 /* Log also SetFocus(0) calls */
8145 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
8147 if (GetClassNameA(hwnd, buf, sizeof(buf)))
8149 if (!lstrcmpiA(buf, "TestWindowClass") ||
8150 !lstrcmpiA(buf, "static"))
8152 struct recvd_message msg;
8154 msg.hwnd = hwnd;
8155 msg.message = nCode;
8156 msg.flags = hook|wparam|lparam;
8157 msg.wParam = wParam;
8158 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8159 msg.descr = "CBT_2";
8160 add_message(&msg);
8163 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8166 static DWORD WINAPI win_event_global_thread_proc(void *param)
8168 HWND hwnd;
8169 MSG msg;
8170 HANDLE hevent = *(HANDLE *)param;
8172 assert(pNotifyWinEvent);
8174 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8175 assert(hwnd);
8176 trace("created thread window %p\n", hwnd);
8178 *(HWND *)param = hwnd;
8180 flush_sequence();
8181 /* this event should be received only by our new hook proc,
8182 * an old one does not expect an event from another thread.
8184 pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
8185 SetEvent(hevent);
8187 while (GetMessage(&msg, 0, 0, 0))
8189 TranslateMessage(&msg);
8190 DispatchMessage(&msg);
8192 return 0;
8195 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
8197 HWND hwnd;
8198 MSG msg;
8199 HANDLE hevent = *(HANDLE *)param;
8201 flush_sequence();
8202 /* these events should be received only by our new hook proc,
8203 * an old one does not expect an event from another thread.
8206 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8207 assert(hwnd);
8208 trace("created thread window %p\n", hwnd);
8210 *(HWND *)param = hwnd;
8212 /* Windows doesn't like when a thread plays games with the focus,
8213 that leads to all kinds of misbehaviours and failures to activate
8214 a window. So, better keep next lines commented out.
8215 SetFocus(0);
8216 SetFocus(hwnd);*/
8218 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8219 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8221 SetEvent(hevent);
8223 while (GetMessage(&msg, 0, 0, 0))
8225 TranslateMessage(&msg);
8226 DispatchMessage(&msg);
8228 return 0;
8231 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
8233 HWND hwnd;
8234 MSG msg;
8235 HANDLE hevent = *(HANDLE *)param;
8237 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8238 assert(hwnd);
8239 trace("created thread window %p\n", hwnd);
8241 *(HWND *)param = hwnd;
8243 flush_sequence();
8245 /* Windows doesn't like when a thread plays games with the focus,
8246 * that leads to all kinds of misbehaviours and failures to activate
8247 * a window. So, better don't generate a mouse click message below.
8249 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8250 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8251 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8253 SetEvent(hevent);
8254 while (GetMessage(&msg, 0, 0, 0))
8256 TranslateMessage(&msg);
8257 DispatchMessage(&msg);
8259 return 0;
8262 static void test_winevents(void)
8264 BOOL ret;
8265 MSG msg;
8266 HWND hwnd, hwnd2;
8267 UINT i;
8268 HANDLE hthread, hevent;
8269 DWORD tid;
8270 HWINEVENTHOOK hhook;
8271 const struct message *events = WmWinEventsSeq;
8273 hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
8274 WS_OVERLAPPEDWINDOW,
8275 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8276 NULL, NULL, 0);
8277 assert(hwnd);
8279 /****** start of global hook test *************/
8280 hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8281 if (!hCBT_global_hook)
8283 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8284 skip( "cannot set global hook\n" );
8285 return;
8288 hevent = CreateEventA(NULL, 0, 0, NULL);
8289 assert(hevent);
8290 hwnd2 = hevent;
8292 hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
8293 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8295 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8297 ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
8299 flush_sequence();
8300 /* this one should be received only by old hook proc */
8301 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8302 /* this one should be received only by old hook proc */
8303 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8305 ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
8307 ret = UnhookWindowsHookEx(hCBT_global_hook);
8308 ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8310 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8311 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8312 CloseHandle(hthread);
8313 CloseHandle(hevent);
8314 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8315 /****** end of global hook test *************/
8317 if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
8319 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8320 return;
8323 flush_sequence();
8325 if (0)
8327 /* this test doesn't pass under Win9x */
8328 /* win2k ignores events with hwnd == 0 */
8329 SetLastError(0xdeadbeef);
8330 pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
8331 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
8332 GetLastError() == 0xdeadbeef, /* Win9x */
8333 "unexpected error %d\n", GetLastError());
8334 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8337 for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
8338 pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
8340 ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
8342 /****** start of event filtering test *************/
8343 hhook = pSetWinEventHook(
8344 EVENT_OBJECT_SHOW, /* 0x8002 */
8345 EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
8346 GetModuleHandleA(0), win_event_global_hook_proc,
8347 GetCurrentProcessId(), 0,
8348 WINEVENT_INCONTEXT);
8349 ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8351 hevent = CreateEventA(NULL, 0, 0, NULL);
8352 assert(hevent);
8353 hwnd2 = hevent;
8355 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8356 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8358 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8360 ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
8362 flush_sequence();
8363 /* this one should be received only by old hook proc */
8364 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8365 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8366 /* this one should be received only by old hook proc */
8367 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8369 ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
8371 ret = pUnhookWinEvent(hhook);
8372 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8374 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8375 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8376 CloseHandle(hthread);
8377 CloseHandle(hevent);
8378 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8379 /****** end of event filtering test *************/
8381 /****** start of out of context event test *************/
8382 hhook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0,
8383 win_event_global_hook_proc, GetCurrentProcessId(), 0,
8384 WINEVENT_OUTOFCONTEXT);
8385 ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8387 hevent = CreateEventA(NULL, 0, 0, NULL);
8388 assert(hevent);
8389 hwnd2 = hevent;
8391 flush_sequence();
8393 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8394 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8396 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8398 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8399 /* process pending winevent messages */
8400 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8401 ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
8403 flush_sequence();
8404 /* this one should be received only by old hook proc */
8405 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8406 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8407 /* this one should be received only by old hook proc */
8408 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8410 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
8411 /* process pending winevent messages */
8412 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8413 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
8415 ret = pUnhookWinEvent(hhook);
8416 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8418 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8419 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8420 CloseHandle(hthread);
8421 CloseHandle(hevent);
8422 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8423 /****** end of out of context event test *************/
8425 /****** start of MOUSE_LL hook test *************/
8426 hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8427 /* WH_MOUSE_LL is not supported on Win9x platforms */
8428 if (!hCBT_global_hook)
8430 win_skip("Skipping WH_MOUSE_LL test on this platform\n");
8431 goto skip_mouse_ll_hook_test;
8434 hevent = CreateEventA(NULL, 0, 0, NULL);
8435 assert(hevent);
8436 hwnd2 = hevent;
8438 hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
8439 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8441 while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
8442 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
8444 ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
8445 flush_sequence();
8447 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8448 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8449 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8451 ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
8453 ret = UnhookWindowsHookEx(hCBT_global_hook);
8454 ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8456 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8457 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8458 CloseHandle(hthread);
8459 CloseHandle(hevent);
8460 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8461 /****** end of MOUSE_LL hook test *************/
8462 skip_mouse_ll_hook_test:
8464 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8467 static void test_set_hook(void)
8469 BOOL ret;
8470 HHOOK hhook;
8471 HWINEVENTHOOK hwinevent_hook;
8473 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
8474 ok(hhook != 0, "local hook does not require hModule set to 0\n");
8475 UnhookWindowsHookEx(hhook);
8477 if (0)
8479 /* this test doesn't pass under Win9x: BUG! */
8480 SetLastError(0xdeadbeef);
8481 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
8482 ok(!hhook, "global hook requires hModule != 0\n");
8483 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
8486 SetLastError(0xdeadbeef);
8487 hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
8488 ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
8489 ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
8490 GetLastError() == 0xdeadbeef, /* Win9x */
8491 "unexpected error %d\n", GetLastError());
8493 SetLastError(0xdeadbeef);
8494 ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
8495 ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
8496 GetLastError() == 0xdeadbeef, /* Win9x */
8497 "unexpected error %d\n", GetLastError());
8499 if (!pSetWinEventHook || !pUnhookWinEvent) return;
8501 /* even process local incontext hooks require hmodule */
8502 SetLastError(0xdeadbeef);
8503 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8504 GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
8505 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8506 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8507 GetLastError() == 0xdeadbeef, /* Win9x */
8508 "unexpected error %d\n", GetLastError());
8510 /* even thread local incontext hooks require hmodule */
8511 SetLastError(0xdeadbeef);
8512 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8513 GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
8514 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8515 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8516 GetLastError() == 0xdeadbeef, /* Win9x */
8517 "unexpected error %d\n", GetLastError());
8519 if (0)
8521 /* these 3 tests don't pass under Win9x */
8522 SetLastError(0xdeadbeef);
8523 hwinevent_hook = pSetWinEventHook(1, 0, 0, win_event_proc,
8524 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8525 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8526 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8528 SetLastError(0xdeadbeef);
8529 hwinevent_hook = pSetWinEventHook(-1, 1, 0, win_event_proc,
8530 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8531 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8532 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8534 SetLastError(0xdeadbeef);
8535 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8536 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
8537 ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
8538 ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
8541 SetLastError(0xdeadbeef);
8542 hwinevent_hook = pSetWinEventHook(0, 0, 0, win_event_proc,
8543 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8544 ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8545 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8546 ret = pUnhookWinEvent(hwinevent_hook);
8547 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8549 todo_wine {
8550 /* This call succeeds under win2k SP4, but fails under Wine.
8551 Does win2k test/use passed process id? */
8552 SetLastError(0xdeadbeef);
8553 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8554 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
8555 ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8556 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8557 ret = pUnhookWinEvent(hwinevent_hook);
8558 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8561 SetLastError(0xdeadbeef);
8562 ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
8563 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
8564 GetLastError() == 0xdeadbeef, /* Win9x */
8565 "unexpected error %d\n", GetLastError());
8568 static const struct message ScrollWindowPaint1[] = {
8569 { WM_PAINT, sent },
8570 { WM_ERASEBKGND, sent|beginpaint },
8571 { WM_GETTEXTLENGTH, sent|optional },
8572 { WM_PAINT, sent|optional },
8573 { WM_NCPAINT, sent|beginpaint|optional },
8574 { WM_GETTEXT, sent|beginpaint|optional },
8575 { WM_GETTEXT, sent|beginpaint|optional },
8576 { WM_GETTEXT, sent|beginpaint|optional },
8577 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
8578 { WM_ERASEBKGND, sent|beginpaint|optional },
8579 { 0 }
8582 static const struct message ScrollWindowPaint2[] = {
8583 { WM_PAINT, sent },
8584 { 0 }
8587 static void test_scrollwindowex(void)
8589 HWND hwnd, hchild;
8590 RECT rect={0,0,130,130};
8592 hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
8593 WS_VISIBLE|WS_OVERLAPPEDWINDOW,
8594 100, 100, 200, 200, 0, 0, 0, NULL);
8595 ok (hwnd != 0, "Failed to create overlapped window\n");
8596 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
8597 WS_VISIBLE|WS_CAPTION|WS_CHILD,
8598 10, 10, 150, 150, hwnd, 0, 0, NULL);
8599 ok (hchild != 0, "Failed to create child\n");
8600 UpdateWindow(hwnd);
8601 flush_events();
8602 flush_sequence();
8604 /* scroll without the child window */
8605 trace("start scroll\n");
8606 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8607 SW_ERASE|SW_INVALIDATE);
8608 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8609 trace("end scroll\n");
8610 flush_sequence();
8611 flush_events();
8612 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8613 flush_events();
8614 flush_sequence();
8616 /* Now without the SW_ERASE flag */
8617 trace("start scroll\n");
8618 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
8619 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8620 trace("end scroll\n");
8621 flush_sequence();
8622 flush_events();
8623 ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
8624 flush_events();
8625 flush_sequence();
8627 /* now scroll the child window as well */
8628 trace("start scroll\n");
8629 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8630 SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
8631 /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
8632 /* windows sometimes a WM_MOVE */
8633 ok_sequence(WmEmptySeq, "ScrollWindowEx", TRUE);
8634 trace("end scroll\n");
8635 flush_sequence();
8636 flush_events();
8637 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8638 flush_events();
8639 flush_sequence();
8641 /* now scroll with ScrollWindow() */
8642 trace("start scroll with ScrollWindow\n");
8643 ScrollWindow( hwnd, 5, 5, NULL, NULL);
8644 trace("end scroll\n");
8645 flush_sequence();
8646 flush_events();
8647 ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
8649 ok(DestroyWindow(hchild), "failed to destroy window\n");
8650 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8651 flush_sequence();
8654 static const struct message destroy_window_with_children[] = {
8655 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8656 { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
8657 { 0x0090, sent|optional },
8658 { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
8659 { 0x0090, sent|optional },
8660 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8661 { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8662 { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8663 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8664 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
8665 { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8666 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8667 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8668 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8669 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8670 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8671 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8672 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8673 { 0 }
8676 static void test_DestroyWindow(void)
8678 BOOL ret;
8679 HWND parent, child1, child2, child3, child4, test;
8680 UINT_PTR child_id = WND_CHILD_ID + 1;
8682 parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8683 100, 100, 200, 200, 0, 0, 0, NULL);
8684 assert(parent != 0);
8685 child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8686 0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
8687 assert(child1 != 0);
8688 child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8689 0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
8690 assert(child2 != 0);
8691 child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8692 0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
8693 assert(child3 != 0);
8694 child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
8695 0, 0, 50, 50, parent, 0, 0, NULL);
8696 assert(child4 != 0);
8698 /* test owner/parent of child2 */
8699 test = GetParent(child2);
8700 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8701 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8702 if(pGetAncestor) {
8703 test = pGetAncestor(child2, GA_PARENT);
8704 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8706 test = GetWindow(child2, GW_OWNER);
8707 ok(!test, "wrong owner %p\n", test);
8709 test = SetParent(child2, parent);
8710 ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
8712 /* test owner/parent of the parent */
8713 test = GetParent(parent);
8714 ok(!test, "wrong parent %p\n", test);
8715 ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
8716 if(pGetAncestor) {
8717 test = pGetAncestor(parent, GA_PARENT);
8718 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8720 test = GetWindow(parent, GW_OWNER);
8721 ok(!test, "wrong owner %p\n", test);
8723 /* test owner/parent of child1 */
8724 test = GetParent(child1);
8725 ok(test == parent, "wrong parent %p\n", test);
8726 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
8727 if(pGetAncestor) {
8728 test = pGetAncestor(child1, GA_PARENT);
8729 ok(test == parent, "wrong parent %p\n", test);
8731 test = GetWindow(child1, GW_OWNER);
8732 ok(!test, "wrong owner %p\n", test);
8734 /* test owner/parent of child2 */
8735 test = GetParent(child2);
8736 ok(test == parent, "wrong parent %p\n", test);
8737 ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8738 if(pGetAncestor) {
8739 test = pGetAncestor(child2, GA_PARENT);
8740 ok(test == parent, "wrong parent %p\n", test);
8742 test = GetWindow(child2, GW_OWNER);
8743 ok(!test, "wrong owner %p\n", test);
8745 /* test owner/parent of child3 */
8746 test = GetParent(child3);
8747 ok(test == child1, "wrong parent %p\n", test);
8748 ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
8749 if(pGetAncestor) {
8750 test = pGetAncestor(child3, GA_PARENT);
8751 ok(test == child1, "wrong parent %p\n", test);
8753 test = GetWindow(child3, GW_OWNER);
8754 ok(!test, "wrong owner %p\n", test);
8756 /* test owner/parent of child4 */
8757 test = GetParent(child4);
8758 ok(test == parent, "wrong parent %p\n", test);
8759 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
8760 if(pGetAncestor) {
8761 test = pGetAncestor(child4, GA_PARENT);
8762 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8764 test = GetWindow(child4, GW_OWNER);
8765 ok(test == parent, "wrong owner %p\n", test);
8767 flush_sequence();
8769 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
8770 parent, child1, child2, child3, child4);
8772 SetCapture(child4);
8773 test = GetCapture();
8774 ok(test == child4, "wrong capture window %p\n", test);
8776 test_DestroyWindow_flag = TRUE;
8777 ret = DestroyWindow(parent);
8778 ok( ret, "DestroyWindow() error %d\n", GetLastError());
8779 test_DestroyWindow_flag = FALSE;
8780 ok_sequence(destroy_window_with_children, "destroy window with children", 0);
8782 ok(!IsWindow(parent), "parent still exists\n");
8783 ok(!IsWindow(child1), "child1 still exists\n");
8784 ok(!IsWindow(child2), "child2 still exists\n");
8785 ok(!IsWindow(child3), "child3 still exists\n");
8786 ok(!IsWindow(child4), "child4 still exists\n");
8788 test = GetCapture();
8789 ok(!test, "wrong capture window %p\n", test);
8793 static const struct message WmDispatchPaint[] = {
8794 { WM_NCPAINT, sent },
8795 { WM_GETTEXT, sent|defwinproc|optional },
8796 { WM_GETTEXT, sent|defwinproc|optional },
8797 { WM_ERASEBKGND, sent },
8798 { 0 }
8801 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8803 if (message == WM_PAINT) return 0;
8804 return MsgCheckProcA( hwnd, message, wParam, lParam );
8807 static void test_DispatchMessage(void)
8809 RECT rect;
8810 MSG msg;
8811 int count;
8812 HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8813 100, 100, 200, 200, 0, 0, 0, NULL);
8814 ShowWindow( hwnd, SW_SHOW );
8815 UpdateWindow( hwnd );
8816 flush_events();
8817 flush_sequence();
8818 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
8820 SetRect( &rect, -5, -5, 5, 5 );
8821 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8822 count = 0;
8823 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8825 if (msg.message != WM_PAINT) DispatchMessage( &msg );
8826 else
8828 flush_sequence();
8829 DispatchMessage( &msg );
8830 /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
8831 if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8832 else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
8833 if (++count > 10) break;
8836 ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
8838 trace("now without DispatchMessage\n");
8839 flush_sequence();
8840 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8841 count = 0;
8842 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8844 if (msg.message != WM_PAINT) DispatchMessage( &msg );
8845 else
8847 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
8848 flush_sequence();
8849 /* this will send WM_NCCPAINT just like DispatchMessage does */
8850 GetUpdateRgn( hwnd, hrgn, TRUE );
8851 ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8852 DeleteObject( hrgn );
8853 GetClientRect( hwnd, &rect );
8854 ValidateRect( hwnd, &rect ); /* this will stop WM_PAINTs */
8855 ok( !count, "Got multiple WM_PAINTs\n" );
8856 if (++count > 10) break;
8859 DestroyWindow(hwnd);
8863 static const struct message WmUser[] = {
8864 { WM_USER, sent },
8865 { 0 }
8868 struct sendmsg_info
8870 HWND hwnd;
8871 DWORD timeout;
8872 DWORD ret;
8875 static DWORD CALLBACK send_msg_thread( LPVOID arg )
8877 struct sendmsg_info *info = arg;
8878 SetLastError( 0xdeadbeef );
8879 info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
8880 if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT ||
8881 broken(GetLastError() == 0), /* win9x */
8882 "unexpected error %d\n", GetLastError());
8883 return 0;
8886 static void wait_for_thread( HANDLE thread )
8888 while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
8890 MSG msg;
8891 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
8895 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8897 if (message == WM_USER) Sleep(200);
8898 return MsgCheckProcA( hwnd, message, wParam, lParam );
8901 static void test_SendMessageTimeout(void)
8903 HANDLE thread;
8904 struct sendmsg_info info;
8905 DWORD tid;
8906 BOOL is_win9x;
8908 info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8909 100, 100, 200, 200, 0, 0, 0, NULL);
8910 flush_events();
8911 flush_sequence();
8913 info.timeout = 1000;
8914 info.ret = 0xdeadbeef;
8915 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8916 wait_for_thread( thread );
8917 CloseHandle( thread );
8918 ok( info.ret == 1, "SendMessageTimeout failed\n" );
8919 ok_sequence( WmUser, "WmUser", FALSE );
8921 info.timeout = 1;
8922 info.ret = 0xdeadbeef;
8923 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8924 Sleep(100); /* SendMessageTimeout should time out here */
8925 wait_for_thread( thread );
8926 CloseHandle( thread );
8927 ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8928 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8930 /* 0 means infinite timeout (but not on win9x) */
8931 info.timeout = 0;
8932 info.ret = 0xdeadbeef;
8933 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8934 Sleep(100);
8935 wait_for_thread( thread );
8936 CloseHandle( thread );
8937 is_win9x = !info.ret;
8938 if (is_win9x) ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8939 else ok_sequence( WmUser, "WmUser", FALSE );
8941 /* timeout is treated as signed despite the prototype (but not on win9x) */
8942 info.timeout = 0x7fffffff;
8943 info.ret = 0xdeadbeef;
8944 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8945 Sleep(100);
8946 wait_for_thread( thread );
8947 CloseHandle( thread );
8948 ok( info.ret == 1, "SendMessageTimeout failed\n" );
8949 ok_sequence( WmUser, "WmUser", FALSE );
8951 info.timeout = 0x80000000;
8952 info.ret = 0xdeadbeef;
8953 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8954 Sleep(100);
8955 wait_for_thread( thread );
8956 CloseHandle( thread );
8957 if (is_win9x)
8959 ok( info.ret == 1, "SendMessageTimeout failed\n" );
8960 ok_sequence( WmUser, "WmUser", FALSE );
8962 else
8964 ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8965 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8968 /* now check for timeout during message processing */
8969 SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
8970 info.timeout = 100;
8971 info.ret = 0xdeadbeef;
8972 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8973 wait_for_thread( thread );
8974 CloseHandle( thread );
8975 /* we should time out but still get the message */
8976 ok( info.ret == 0, "SendMessageTimeout failed\n" );
8977 ok_sequence( WmUser, "WmUser", FALSE );
8979 DestroyWindow( info.hwnd );
8983 /****************** edit message test *************************/
8984 #define ID_EDIT 0x1234
8985 static const struct message sl_edit_setfocus[] =
8987 { HCBT_SETFOCUS, hook },
8988 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8989 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8990 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8991 { WM_SETFOCUS, sent|wparam, 0 },
8992 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8993 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
8994 { WM_CTLCOLOREDIT, sent|parent },
8995 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8996 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8997 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8998 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8999 { 0 }
9001 static const struct message ml_edit_setfocus[] =
9003 { HCBT_SETFOCUS, hook },
9004 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9005 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9006 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9007 { WM_SETFOCUS, sent|wparam, 0 },
9008 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9009 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9010 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9011 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9012 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9013 { 0 }
9015 static const struct message sl_edit_killfocus[] =
9017 { HCBT_SETFOCUS, hook },
9018 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9019 { WM_KILLFOCUS, sent|wparam, 0 },
9020 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9021 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9022 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
9023 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
9024 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
9025 { 0 }
9027 static const struct message sl_edit_lbutton_dblclk[] =
9029 { WM_LBUTTONDBLCLK, sent },
9030 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9031 { 0 }
9033 static const struct message sl_edit_lbutton_down[] =
9035 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
9036 { HCBT_SETFOCUS, hook },
9037 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9038 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9039 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9040 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9041 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9042 { WM_CTLCOLOREDIT, sent|parent },
9043 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9044 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9045 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9046 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9047 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9048 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9049 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9050 { WM_CTLCOLOREDIT, sent|parent|optional },
9051 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9052 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9053 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9054 { 0 }
9056 static const struct message ml_edit_lbutton_down[] =
9058 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
9059 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9060 { HCBT_SETFOCUS, hook },
9061 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9062 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9063 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9064 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9065 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9066 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9067 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9068 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9069 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9070 { 0 }
9072 static const struct message sl_edit_lbutton_up[] =
9074 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9075 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9076 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9077 { WM_CAPTURECHANGED, sent|defwinproc },
9078 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9079 { 0 }
9081 static const struct message ml_edit_lbutton_up[] =
9083 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9084 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9085 { WM_CAPTURECHANGED, sent|defwinproc },
9086 { 0 }
9089 static WNDPROC old_edit_proc;
9091 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9093 static LONG defwndproc_counter = 0;
9094 LRESULT ret;
9095 struct recvd_message msg;
9097 if (ignore_message( message )) return 0;
9099 msg.hwnd = hwnd;
9100 msg.message = message;
9101 msg.flags = sent|wparam|lparam;
9102 if (defwndproc_counter) msg.flags |= defwinproc;
9103 msg.wParam = wParam;
9104 msg.lParam = lParam;
9105 msg.descr = "edit";
9106 add_message(&msg);
9108 defwndproc_counter++;
9109 ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
9110 defwndproc_counter--;
9112 return ret;
9115 static void subclass_edit(void)
9117 WNDCLASSA cls;
9119 if (!GetClassInfoA(0, "edit", &cls)) assert(0);
9121 old_edit_proc = cls.lpfnWndProc;
9123 cls.hInstance = GetModuleHandle(0);
9124 cls.lpfnWndProc = edit_hook_proc;
9125 cls.lpszClassName = "my_edit_class";
9126 UnregisterClass(cls.lpszClassName, cls.hInstance);
9127 if (!RegisterClassA(&cls)) assert(0);
9130 static void test_edit_messages(void)
9132 HWND hwnd, parent;
9133 DWORD dlg_code;
9135 subclass_edit();
9136 log_all_parent_messages++;
9138 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9139 100, 100, 200, 200, 0, 0, 0, NULL);
9140 ok (parent != 0, "Failed to create parent window\n");
9142 /* test single line edit */
9143 hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
9144 0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9145 ok(hwnd != 0, "Failed to create edit window\n");
9147 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9148 ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
9150 ShowWindow(hwnd, SW_SHOW);
9151 UpdateWindow(hwnd);
9152 SetFocus(0);
9153 flush_sequence();
9155 SetFocus(hwnd);
9156 ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
9158 SetFocus(0);
9159 ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
9161 SetFocus(0);
9162 ReleaseCapture();
9163 flush_sequence();
9165 SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9166 ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
9168 SetFocus(0);
9169 ReleaseCapture();
9170 flush_sequence();
9172 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9173 ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
9175 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9176 ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
9178 DestroyWindow(hwnd);
9180 /* test multiline edit */
9181 hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
9182 0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9183 ok(hwnd != 0, "Failed to create edit window\n");
9185 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9186 ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
9187 "wrong dlg_code %08x\n", dlg_code);
9189 ShowWindow(hwnd, SW_SHOW);
9190 UpdateWindow(hwnd);
9191 SetFocus(0);
9192 flush_sequence();
9194 SetFocus(hwnd);
9195 ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
9197 SetFocus(0);
9198 ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
9200 SetFocus(0);
9201 ReleaseCapture();
9202 flush_sequence();
9204 SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9205 ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
9207 SetFocus(0);
9208 ReleaseCapture();
9209 flush_sequence();
9211 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9212 ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
9214 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9215 ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
9217 DestroyWindow(hwnd);
9218 DestroyWindow(parent);
9220 log_all_parent_messages--;
9223 /**************************** End of Edit test ******************************/
9225 static const struct message WmKeyDownSkippedSeq[] =
9227 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
9228 { 0 }
9230 static const struct message WmKeyDownWasDownSkippedSeq[] =
9232 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x40000001 }, /* XP */
9233 { 0 }
9235 static const struct message WmKeyUpSkippedSeq[] =
9237 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9238 { 0 }
9240 static const struct message WmUserKeyUpSkippedSeq[] =
9242 { WM_USER, sent },
9243 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9244 { 0 }
9247 #define EV_STOP 0
9248 #define EV_SENDMSG 1
9249 #define EV_ACK 2
9251 struct peekmsg_info
9253 HWND hwnd;
9254 HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
9257 static DWORD CALLBACK send_msg_thread_2(void *param)
9259 DWORD ret;
9260 struct peekmsg_info *info = param;
9262 trace("thread: looping\n");
9263 SetEvent(info->hevent[EV_ACK]);
9265 while (1)
9267 ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
9269 switch (ret)
9271 case WAIT_OBJECT_0 + EV_STOP:
9272 trace("thread: exiting\n");
9273 return 0;
9275 case WAIT_OBJECT_0 + EV_SENDMSG:
9276 trace("thread: sending message\n");
9277 ok( SendNotifyMessageA(info->hwnd, WM_USER, 0, 0),
9278 "SendNotifyMessageA failed error %u\n", GetLastError());
9279 SetEvent(info->hevent[EV_ACK]);
9280 break;
9282 default:
9283 trace("unexpected return: %04x\n", ret);
9284 assert(0);
9285 break;
9288 return 0;
9291 static void test_PeekMessage(void)
9293 MSG msg;
9294 HANDLE hthread;
9295 DWORD tid, qstatus;
9296 UINT qs_all_input = QS_ALLINPUT;
9297 UINT qs_input = QS_INPUT;
9298 BOOL ret;
9299 struct peekmsg_info info;
9301 info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9302 100, 100, 200, 200, 0, 0, 0, NULL);
9303 assert(info.hwnd);
9304 ShowWindow(info.hwnd, SW_SHOW);
9305 UpdateWindow(info.hwnd);
9306 SetFocus(info.hwnd);
9308 info.hevent[EV_STOP] = CreateEventA(NULL, 0, 0, NULL);
9309 info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
9310 info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
9312 hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
9313 WaitForSingleObject(info.hevent[EV_ACK], 10000);
9315 flush_events();
9316 flush_sequence();
9318 SetLastError(0xdeadbeef);
9319 qstatus = GetQueueStatus(qs_all_input);
9320 if (GetLastError() == ERROR_INVALID_FLAGS)
9322 trace("QS_RAWINPUT not supported on this platform\n");
9323 qs_all_input &= ~QS_RAWINPUT;
9324 qs_input &= ~QS_RAWINPUT;
9326 if (qstatus & QS_POSTMESSAGE)
9328 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) /* nothing */ ;
9329 qstatus = GetQueueStatus(qs_all_input);
9331 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9333 trace("signalling to send message\n");
9334 SetEvent(info.hevent[EV_SENDMSG]);
9335 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9337 /* pass invalid QS_xxxx flags */
9338 SetLastError(0xdeadbeef);
9339 qstatus = GetQueueStatus(0xffffffff);
9340 ok(qstatus == 0 || broken(qstatus) /* win9x */, "GetQueueStatus should fail: %08x\n", qstatus);
9341 if (!qstatus)
9343 ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
9344 qstatus = GetQueueStatus(qs_all_input);
9346 qstatus &= ~MAKELONG( 0x4000, 0x4000 ); /* sometimes set on Win95 */
9347 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
9348 "wrong qstatus %08x\n", qstatus);
9350 msg.message = 0;
9351 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9352 ok(!ret,
9353 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9354 msg.message);
9355 ok_sequence(WmUser, "WmUser", FALSE);
9357 qstatus = GetQueueStatus(qs_all_input);
9358 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9360 keybd_event('N', 0, 0, 0);
9361 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9362 qstatus = GetQueueStatus(qs_all_input);
9363 if (!(qstatus & MAKELONG(QS_KEY, QS_KEY)))
9365 skip( "queuing key events not supported\n" );
9366 goto done;
9368 ok(qstatus == MAKELONG(QS_KEY, QS_KEY) ||
9369 /* keybd_event seems to trigger a sent message on NT4 */
9370 qstatus == MAKELONG(QS_KEY|QS_SENDMESSAGE, QS_KEY|QS_SENDMESSAGE),
9371 "wrong qstatus %08x\n", qstatus);
9373 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9374 qstatus = GetQueueStatus(qs_all_input);
9375 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY) ||
9376 qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY|QS_SENDMESSAGE),
9377 "wrong qstatus %08x\n", qstatus);
9379 InvalidateRect(info.hwnd, NULL, FALSE);
9380 qstatus = GetQueueStatus(qs_all_input);
9381 ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY) ||
9382 qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY|QS_SENDMESSAGE),
9383 "wrong qstatus %08x\n", qstatus);
9385 trace("signalling to send message\n");
9386 SetEvent(info.hevent[EV_SENDMSG]);
9387 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9389 qstatus = GetQueueStatus(qs_all_input);
9390 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9391 "wrong qstatus %08x\n", qstatus);
9393 msg.message = 0;
9394 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
9395 if (ret && msg.message == WM_CHAR)
9397 win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9398 goto done;
9400 ok(!ret,
9401 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9402 msg.message);
9403 if (!sequence_cnt) /* nt4 doesn't fetch anything with PM_QS_* flags */
9405 win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9406 goto done;
9408 ok_sequence(WmUser, "WmUser", FALSE);
9410 qstatus = GetQueueStatus(qs_all_input);
9411 ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9412 "wrong qstatus %08x\n", qstatus);
9414 trace("signalling to send message\n");
9415 SetEvent(info.hevent[EV_SENDMSG]);
9416 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9418 qstatus = GetQueueStatus(qs_all_input);
9419 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9420 "wrong qstatus %08x\n", qstatus);
9422 msg.message = 0;
9423 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE );
9424 ok(!ret,
9425 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9426 msg.message);
9427 ok_sequence(WmUser, "WmUser", FALSE);
9429 qstatus = GetQueueStatus(qs_all_input);
9430 ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9431 "wrong qstatus %08x\n", qstatus);
9433 msg.message = 0;
9434 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9435 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9436 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9437 ret, msg.message, msg.wParam);
9438 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9440 qstatus = GetQueueStatus(qs_all_input);
9441 ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9442 "wrong qstatus %08x\n", qstatus);
9444 msg.message = 0;
9445 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9446 ok(!ret,
9447 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9448 msg.message);
9449 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9451 qstatus = GetQueueStatus(qs_all_input);
9452 ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9453 "wrong qstatus %08x\n", qstatus);
9455 msg.message = 0;
9456 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9457 ok(ret && msg.message == WM_PAINT,
9458 "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
9459 DispatchMessageA(&msg);
9460 ok_sequence(WmPaint, "WmPaint", FALSE);
9462 qstatus = GetQueueStatus(qs_all_input);
9463 ok(qstatus == MAKELONG(0, QS_KEY),
9464 "wrong qstatus %08x\n", qstatus);
9466 msg.message = 0;
9467 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9468 ok(!ret,
9469 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9470 msg.message);
9471 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9473 qstatus = GetQueueStatus(qs_all_input);
9474 ok(qstatus == MAKELONG(0, QS_KEY),
9475 "wrong qstatus %08x\n", qstatus);
9477 trace("signalling to send message\n");
9478 SetEvent(info.hevent[EV_SENDMSG]);
9479 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9481 qstatus = GetQueueStatus(qs_all_input);
9482 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
9483 "wrong qstatus %08x\n", qstatus);
9485 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9487 qstatus = GetQueueStatus(qs_all_input);
9488 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9489 "wrong qstatus %08x\n", qstatus);
9491 msg.message = 0;
9492 ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9493 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9494 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9495 ret, msg.message, msg.wParam);
9496 ok_sequence(WmUser, "WmUser", FALSE);
9498 qstatus = GetQueueStatus(qs_all_input);
9499 ok(qstatus == MAKELONG(0, QS_KEY),
9500 "wrong qstatus %08x\n", qstatus);
9502 msg.message = 0;
9503 ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9504 ok(!ret,
9505 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9506 msg.message);
9507 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9509 qstatus = GetQueueStatus(qs_all_input);
9510 ok(qstatus == MAKELONG(0, QS_KEY),
9511 "wrong qstatus %08x\n", qstatus);
9513 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9515 qstatus = GetQueueStatus(qs_all_input);
9516 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9517 "wrong qstatus %08x\n", qstatus);
9519 trace("signalling to send message\n");
9520 SetEvent(info.hevent[EV_SENDMSG]);
9521 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9523 qstatus = GetQueueStatus(qs_all_input);
9524 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9525 "wrong qstatus %08x\n", qstatus);
9527 msg.message = 0;
9528 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
9529 ok(!ret,
9530 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9531 msg.message);
9532 ok_sequence(WmUser, "WmUser", FALSE);
9534 qstatus = GetQueueStatus(qs_all_input);
9535 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9536 "wrong qstatus %08x\n", qstatus);
9538 msg.message = 0;
9539 if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9540 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9541 else /* workaround for a missing QS_RAWINPUT support */
9542 ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
9543 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9544 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9545 ret, msg.message, msg.wParam);
9546 ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9548 qstatus = GetQueueStatus(qs_all_input);
9549 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9550 "wrong qstatus %08x\n", qstatus);
9552 msg.message = 0;
9553 if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9554 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9555 else /* workaround for a missing QS_RAWINPUT support */
9556 ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
9557 ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9558 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
9559 ret, msg.message, msg.wParam);
9560 ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
9562 qstatus = GetQueueStatus(qs_all_input);
9563 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9564 "wrong qstatus %08x\n", qstatus);
9566 msg.message = 0;
9567 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
9568 ok(!ret,
9569 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9570 msg.message);
9571 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9573 qstatus = GetQueueStatus(qs_all_input);
9574 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9575 "wrong qstatus %08x\n", qstatus);
9577 msg.message = 0;
9578 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9579 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9580 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9581 ret, msg.message, msg.wParam);
9582 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9584 qstatus = GetQueueStatus(qs_all_input);
9585 ok(qstatus == 0,
9586 "wrong qstatus %08x\n", qstatus);
9588 msg.message = 0;
9589 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9590 ok(!ret,
9591 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9592 msg.message);
9593 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9595 qstatus = GetQueueStatus(qs_all_input);
9596 ok(qstatus == 0,
9597 "wrong qstatus %08x\n", qstatus);
9599 /* test whether presence of the quit flag in the queue affects
9600 * the queue state
9602 PostQuitMessage(0x1234abcd);
9604 qstatus = GetQueueStatus(qs_all_input);
9605 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9606 "wrong qstatus %08x\n", qstatus);
9608 PostMessageA(info.hwnd, WM_USER, 0, 0);
9610 qstatus = GetQueueStatus(qs_all_input);
9611 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9612 "wrong qstatus %08x\n", qstatus);
9614 msg.message = 0;
9615 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9616 ok(ret && msg.message == WM_USER,
9617 "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
9618 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9620 qstatus = GetQueueStatus(qs_all_input);
9621 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9622 "wrong qstatus %08x\n", qstatus);
9624 msg.message = 0;
9625 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9626 ok(ret && msg.message == WM_QUIT,
9627 "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
9628 ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
9629 ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
9630 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9632 qstatus = GetQueueStatus(qs_all_input);
9633 todo_wine {
9634 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9635 "wrong qstatus %08x\n", qstatus);
9638 msg.message = 0;
9639 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9640 ok(!ret,
9641 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9642 msg.message);
9643 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9645 qstatus = GetQueueStatus(qs_all_input);
9646 ok(qstatus == 0,
9647 "wrong qstatus %08x\n", qstatus);
9649 /* some GetMessage tests */
9651 keybd_event('N', 0, 0, 0);
9652 qstatus = GetQueueStatus(qs_all_input);
9653 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9655 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9656 qstatus = GetQueueStatus(qs_all_input);
9657 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9659 if (qstatus)
9661 ret = GetMessageA( &msg, 0, 0, 0 );
9662 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9663 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9664 ret, msg.message, msg.wParam);
9665 qstatus = GetQueueStatus(qs_all_input);
9666 ok(qstatus == MAKELONG(0, QS_KEY), "wrong qstatus %08x\n", qstatus);
9669 if (qstatus)
9671 ret = GetMessageA( &msg, 0, 0, 0 );
9672 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9673 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9674 ret, msg.message, msg.wParam);
9675 ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9676 qstatus = GetQueueStatus(qs_all_input);
9677 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9680 keybd_event('N', 0, 0, 0);
9681 qstatus = GetQueueStatus(qs_all_input);
9682 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9684 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9685 qstatus = GetQueueStatus(qs_all_input);
9686 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9688 if (qstatus & (QS_KEY << 16))
9690 ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9691 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9692 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9693 ret, msg.message, msg.wParam);
9694 ok_sequence(WmKeyDownWasDownSkippedSeq, "WmKeyDownWasDownSkippedSeq", FALSE);
9695 qstatus = GetQueueStatus(qs_all_input);
9696 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9699 if (qstatus)
9701 ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9702 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9703 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9704 ret, msg.message, msg.wParam);
9705 qstatus = GetQueueStatus(qs_all_input);
9706 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9709 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9710 qstatus = GetQueueStatus(qs_all_input);
9711 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9713 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9714 qstatus = GetQueueStatus(qs_all_input);
9715 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9717 trace("signalling to send message\n");
9718 SetEvent(info.hevent[EV_SENDMSG]);
9719 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9720 qstatus = GetQueueStatus(qs_all_input);
9721 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9722 "wrong qstatus %08x\n", qstatus);
9724 if (qstatus & (QS_KEY << 16))
9726 ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9727 ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9728 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9729 ret, msg.message, msg.wParam);
9730 ok_sequence(WmUserKeyUpSkippedSeq, "WmUserKeyUpSkippedSeq", FALSE);
9731 qstatus = GetQueueStatus(qs_all_input);
9732 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9735 if (qstatus)
9737 ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9738 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9739 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9740 ret, msg.message, msg.wParam);
9741 qstatus = GetQueueStatus(qs_all_input);
9742 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9744 done:
9745 trace("signalling to exit\n");
9746 SetEvent(info.hevent[EV_STOP]);
9748 WaitForSingleObject(hthread, INFINITE);
9750 CloseHandle(hthread);
9751 CloseHandle(info.hevent[0]);
9752 CloseHandle(info.hevent[1]);
9753 CloseHandle(info.hevent[2]);
9755 DestroyWindow(info.hwnd);
9758 static void wait_move_event(HWND hwnd, int x, int y)
9760 MSG msg;
9761 DWORD time;
9762 BOOL ret;
9763 int go = 0;
9765 time = GetTickCount();
9766 while (GetTickCount() - time < 200 && !go) {
9767 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9768 go = ret && msg.pt.x > x && msg.pt.y > y;
9769 if (!ret) MsgWaitForMultipleObjects( 0, NULL, FALSE, GetTickCount() - time, QS_ALLINPUT );
9773 #define STEP 5
9774 static void test_PeekMessage2(void)
9776 HWND hwnd;
9777 BOOL ret;
9778 MSG msg;
9779 UINT message;
9780 DWORD time1, time2, time3;
9781 int x1, y1, x2, y2, x3, y3;
9782 POINT pos;
9784 time1 = time2 = time3 = 0;
9785 x1 = y1 = x2 = y2 = x3 = y3 = 0;
9787 /* Initialise window and make sure it is ready for events */
9788 hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
9789 10, 10, 800, 800, NULL, NULL, NULL, NULL);
9790 assert(hwnd);
9791 trace("Window for test_PeekMessage2 %p\n", hwnd);
9792 ShowWindow(hwnd, SW_SHOW);
9793 UpdateWindow(hwnd);
9794 SetFocus(hwnd);
9795 GetCursorPos(&pos);
9796 SetCursorPos(100, 100);
9797 mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
9798 flush_events();
9800 /* Do initial mousemove, wait until we can see it
9801 and then do our test peek with PM_NOREMOVE. */
9802 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9803 wait_move_event(hwnd, 100-STEP, 100-STEP);
9805 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9806 if (!ret)
9808 skip( "queuing mouse events not supported\n" );
9809 goto done;
9811 else
9813 trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9814 message = msg.message;
9815 time1 = msg.time;
9816 x1 = msg.pt.x;
9817 y1 = msg.pt.y;
9818 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9821 /* Allow time to advance a bit, and then simulate the user moving their
9822 * mouse around. After that we peek again with PM_NOREMOVE.
9823 * Although the previous mousemove message was never removed, the
9824 * mousemove we now peek should reflect the recent mouse movements
9825 * because the input queue will merge the move events. */
9826 Sleep(100);
9827 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9828 wait_move_event(hwnd, x1, y1);
9830 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9831 ok(ret, "no message available\n");
9832 if (ret) {
9833 trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9834 message = msg.message;
9835 time2 = msg.time;
9836 x2 = msg.pt.x;
9837 y2 = msg.pt.y;
9838 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9839 ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
9840 ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
9843 /* Have another go, to drive the point home */
9844 Sleep(100);
9845 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9846 wait_move_event(hwnd, x2, y2);
9848 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9849 ok(ret, "no message available\n");
9850 if (ret) {
9851 trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9852 message = msg.message;
9853 time3 = msg.time;
9854 x3 = msg.pt.x;
9855 y3 = msg.pt.y;
9856 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9857 ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
9858 ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
9861 done:
9862 DestroyWindow(hwnd);
9863 SetCursorPos(pos.x, pos.y);
9864 flush_events();
9867 static void test_quit_message(void)
9869 MSG msg;
9870 BOOL ret;
9872 /* test using PostQuitMessage */
9873 flush_events();
9874 PostQuitMessage(0xbeef);
9876 ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9877 ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9878 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9879 ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9881 ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9882 ok(ret, "PostMessage failed with error %d\n", GetLastError());
9884 ret = GetMessage(&msg, NULL, 0, 0);
9885 ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9886 ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9888 /* note: WM_QUIT message received after WM_USER message */
9889 ret = GetMessage(&msg, NULL, 0, 0);
9890 ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9891 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9892 ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9894 ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
9895 ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
9897 /* now test with PostThreadMessage - different behaviour! */
9898 PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
9900 ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9901 ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9902 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9903 ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9905 ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9906 ok(ret, "PostMessage failed with error %d\n", GetLastError());
9908 /* note: we receive the WM_QUIT message first this time */
9909 ret = GetMessage(&msg, NULL, 0, 0);
9910 ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9911 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9912 ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9914 ret = GetMessage(&msg, NULL, 0, 0);
9915 ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9916 ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9919 static const struct message WmMouseHoverSeq[] = {
9920 { WM_MOUSEACTIVATE, sent|optional }, /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
9921 { WM_MOUSEACTIVATE, sent|optional },
9922 { WM_TIMER, sent|optional }, /* XP sends it */
9923 { WM_SYSTIMER, sent },
9924 { WM_MOUSEHOVER, sent|wparam, 0 },
9925 { 0 }
9928 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
9930 MSG msg;
9931 DWORD start_ticks, end_ticks;
9933 start_ticks = GetTickCount();
9934 /* add some deviation (50%) to cover not expected delays */
9935 start_ticks += timeout / 2;
9939 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
9941 /* Timer proc messages are not dispatched to the window proc,
9942 * and therefore not logged.
9944 if ((msg.message == WM_TIMER || msg.message == WM_SYSTIMER) && msg.hwnd)
9946 struct recvd_message s_msg;
9948 s_msg.hwnd = msg.hwnd;
9949 s_msg.message = msg.message;
9950 s_msg.flags = sent|wparam|lparam;
9951 s_msg.wParam = msg.wParam;
9952 s_msg.lParam = msg.lParam;
9953 s_msg.descr = "msg_loop";
9954 add_message(&s_msg);
9956 DispatchMessage(&msg);
9959 end_ticks = GetTickCount();
9961 /* inject WM_MOUSEMOVE to see how it changes tracking */
9962 if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
9964 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9965 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9967 inject_mouse_move = FALSE;
9969 } while (start_ticks + timeout >= end_ticks);
9972 static void test_TrackMouseEvent(void)
9974 TRACKMOUSEEVENT tme;
9975 BOOL ret;
9976 HWND hwnd, hchild;
9977 RECT rc_parent, rc_child;
9978 UINT default_hover_time, hover_width = 0, hover_height = 0;
9980 #define track_hover(track_hwnd, track_hover_time) \
9981 tme.cbSize = sizeof(tme); \
9982 tme.dwFlags = TME_HOVER; \
9983 tme.hwndTrack = track_hwnd; \
9984 tme.dwHoverTime = track_hover_time; \
9985 SetLastError(0xdeadbeef); \
9986 ret = pTrackMouseEvent(&tme); \
9987 ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
9989 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
9990 tme.cbSize = sizeof(tme); \
9991 tme.dwFlags = TME_QUERY; \
9992 tme.hwndTrack = (HWND)0xdeadbeef; \
9993 tme.dwHoverTime = 0xdeadbeef; \
9994 SetLastError(0xdeadbeef); \
9995 ret = pTrackMouseEvent(&tme); \
9996 ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
9997 ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
9998 ok(tme.dwFlags == (expected_track_flags), \
9999 "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
10000 ok(tme.hwndTrack == (expected_track_hwnd), \
10001 "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
10002 ok(tme.dwHoverTime == (expected_hover_time), \
10003 "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
10005 #define track_hover_cancel(track_hwnd) \
10006 tme.cbSize = sizeof(tme); \
10007 tme.dwFlags = TME_HOVER | TME_CANCEL; \
10008 tme.hwndTrack = track_hwnd; \
10009 tme.dwHoverTime = 0xdeadbeef; \
10010 SetLastError(0xdeadbeef); \
10011 ret = pTrackMouseEvent(&tme); \
10012 ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
10014 default_hover_time = 0xdeadbeef;
10015 SetLastError(0xdeadbeef);
10016 ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
10017 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
10018 "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
10019 if (!ret) default_hover_time = 400;
10020 trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
10022 SetLastError(0xdeadbeef);
10023 ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
10024 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
10025 "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
10026 if (!ret) hover_width = 4;
10027 SetLastError(0xdeadbeef);
10028 ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
10029 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
10030 "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
10031 if (!ret) hover_height = 4;
10032 trace("hover rect is %u x %d\n", hover_width, hover_height);
10034 hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
10035 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10036 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
10037 NULL, NULL, 0);
10038 assert(hwnd);
10040 hchild = CreateWindowEx(0, "TestWindowClass", NULL,
10041 WS_CHILD | WS_BORDER | WS_VISIBLE,
10042 50, 50, 200, 200, hwnd,
10043 NULL, NULL, 0);
10044 assert(hchild);
10046 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
10047 flush_events();
10048 flush_sequence();
10050 tme.cbSize = 0;
10051 tme.dwFlags = TME_QUERY;
10052 tme.hwndTrack = (HWND)0xdeadbeef;
10053 tme.dwHoverTime = 0xdeadbeef;
10054 SetLastError(0xdeadbeef);
10055 ret = pTrackMouseEvent(&tme);
10056 ok(!ret, "TrackMouseEvent should fail\n");
10057 ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef),
10058 "not expected error %u\n", GetLastError());
10060 tme.cbSize = sizeof(tme);
10061 tme.dwFlags = TME_HOVER;
10062 tme.hwndTrack = (HWND)0xdeadbeef;
10063 tme.dwHoverTime = 0xdeadbeef;
10064 SetLastError(0xdeadbeef);
10065 ret = pTrackMouseEvent(&tme);
10066 ok(!ret, "TrackMouseEvent should fail\n");
10067 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10068 "not expected error %u\n", GetLastError());
10070 tme.cbSize = sizeof(tme);
10071 tme.dwFlags = TME_HOVER | TME_CANCEL;
10072 tme.hwndTrack = (HWND)0xdeadbeef;
10073 tme.dwHoverTime = 0xdeadbeef;
10074 SetLastError(0xdeadbeef);
10075 ret = pTrackMouseEvent(&tme);
10076 ok(!ret, "TrackMouseEvent should fail\n");
10077 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10078 "not expected error %u\n", GetLastError());
10080 GetWindowRect(hwnd, &rc_parent);
10081 GetWindowRect(hchild, &rc_child);
10082 SetCursorPos(rc_child.left - 10, rc_child.top - 10);
10084 /* Process messages so that the system updates its internal current
10085 * window and hittest, otherwise TrackMouseEvent calls don't have any
10086 * effect.
10088 flush_events();
10089 flush_sequence();
10091 track_query(0, NULL, 0);
10092 track_hover(hchild, 0);
10093 track_query(0, NULL, 0);
10095 flush_events();
10096 flush_sequence();
10098 track_hover(hwnd, 0);
10099 tme.cbSize = sizeof(tme);
10100 tme.dwFlags = TME_QUERY;
10101 tme.hwndTrack = (HWND)0xdeadbeef;
10102 tme.dwHoverTime = 0xdeadbeef;
10103 SetLastError(0xdeadbeef);
10104 ret = pTrackMouseEvent(&tme);
10105 ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());
10106 ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize);
10107 if (!tme.dwFlags)
10109 skip( "Cursor not inside window, skipping TrackMouseEvent tests\n" );
10110 DestroyWindow( hwnd );
10111 return;
10113 ok(tme.dwFlags == TME_HOVER, "wrong tme.dwFlags %08x, expected TME_HOVER\n", tme.dwFlags);
10114 ok(tme.hwndTrack == hwnd, "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, hwnd);
10115 ok(tme.dwHoverTime == default_hover_time, "wrong tme.dwHoverTime %u, expected %u\n",
10116 tme.dwHoverTime, default_hover_time);
10118 pump_msg_loop_timeout(default_hover_time, FALSE);
10119 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10121 track_query(0, NULL, 0);
10123 track_hover(hwnd, HOVER_DEFAULT);
10124 track_query(TME_HOVER, hwnd, default_hover_time);
10126 Sleep(default_hover_time / 2);
10127 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
10128 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
10130 track_query(TME_HOVER, hwnd, default_hover_time);
10132 pump_msg_loop_timeout(default_hover_time, FALSE);
10133 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10135 track_query(0, NULL, 0);
10137 track_hover(hwnd, HOVER_DEFAULT);
10138 track_query(TME_HOVER, hwnd, default_hover_time);
10140 pump_msg_loop_timeout(default_hover_time, TRUE);
10141 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10143 track_query(0, NULL, 0);
10145 track_hover(hwnd, HOVER_DEFAULT);
10146 track_query(TME_HOVER, hwnd, default_hover_time);
10147 track_hover_cancel(hwnd);
10149 DestroyWindow(hwnd);
10151 #undef track_hover
10152 #undef track_query
10153 #undef track_hover_cancel
10157 static const struct message WmSetWindowRgn[] = {
10158 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10159 { WM_NCCALCSIZE, sent|wparam, 1 },
10160 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
10161 { WM_GETTEXT, sent|defwinproc|optional },
10162 { WM_ERASEBKGND, sent|optional },
10163 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10164 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10165 { 0 }
10168 static const struct message WmSetWindowRgn_no_redraw[] = {
10169 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10170 { WM_NCCALCSIZE, sent|wparam, 1 },
10171 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10172 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10173 { 0 }
10176 static const struct message WmSetWindowRgn_clear[] = {
10177 { WM_WINDOWPOSCHANGING, sent/*|wparam*/, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE/*|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE only on some Windows versions */ },
10178 { WM_NCCALCSIZE, sent|wparam, 1 },
10179 { WM_NCPAINT, sent|optional },
10180 { WM_GETTEXT, sent|defwinproc|optional },
10181 { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
10182 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10183 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
10184 { WM_NCPAINT, sent|optional },
10185 { WM_GETTEXT, sent|defwinproc|optional },
10186 { WM_ERASEBKGND, sent|optional },
10187 { WM_WINDOWPOSCHANGING, sent|optional },
10188 { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10189 { WM_NCPAINT, sent|optional },
10190 { WM_GETTEXT, sent|defwinproc|optional },
10191 { WM_ERASEBKGND, sent|optional },
10192 { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10193 { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10194 { WM_NCPAINT, sent|optional },
10195 { WM_GETTEXT, sent|defwinproc|optional },
10196 { WM_ERASEBKGND, sent|optional },
10197 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10198 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10199 { 0 }
10202 static void test_SetWindowRgn(void)
10204 HRGN hrgn;
10205 HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10206 100, 100, 200, 200, 0, 0, 0, NULL);
10207 ok( hwnd != 0, "Failed to create overlapped window\n" );
10209 ShowWindow( hwnd, SW_SHOW );
10210 UpdateWindow( hwnd );
10211 flush_events();
10212 flush_sequence();
10214 trace("testing SetWindowRgn\n");
10215 hrgn = CreateRectRgn( 0, 0, 150, 150 );
10216 SetWindowRgn( hwnd, hrgn, TRUE );
10217 ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
10219 hrgn = CreateRectRgn( 30, 30, 160, 160 );
10220 SetWindowRgn( hwnd, hrgn, FALSE );
10221 ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
10223 hrgn = CreateRectRgn( 0, 0, 180, 180 );
10224 SetWindowRgn( hwnd, hrgn, TRUE );
10225 ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
10227 SetWindowRgn( hwnd, 0, TRUE );
10228 ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
10230 DestroyWindow( hwnd );
10233 /*************************** ShowWindow() test ******************************/
10234 static const struct message WmShowNormal[] = {
10235 { WM_SHOWWINDOW, sent|wparam, 1 },
10236 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10237 { HCBT_ACTIVATE, hook },
10238 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10239 { HCBT_SETFOCUS, hook },
10240 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10241 { 0 }
10243 static const struct message WmShow[] = {
10244 { WM_SHOWWINDOW, sent|wparam, 1 },
10245 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10246 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10247 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10248 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10249 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10250 { 0 }
10252 static const struct message WmShowNoActivate_1[] = {
10253 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10254 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10255 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10256 { WM_MOVE, sent|defwinproc|optional },
10257 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10258 { 0 }
10260 static const struct message WmShowNoActivate_2[] = {
10261 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10262 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10263 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10264 { WM_MOVE, sent|defwinproc },
10265 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10266 { HCBT_SETFOCUS, hook|optional },
10267 { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10268 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10269 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10270 { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10271 { 0 }
10273 static const struct message WmShowNA_1[] = {
10274 { WM_SHOWWINDOW, sent|wparam, 1 },
10275 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10276 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10277 { 0 }
10279 static const struct message WmShowNA_2[] = {
10280 { WM_SHOWWINDOW, sent|wparam, 1 },
10281 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10282 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10283 { 0 }
10285 static const struct message WmRestore_1[] = {
10286 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10287 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10288 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10289 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10290 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10291 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10292 { WM_MOVE, sent|defwinproc },
10293 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10294 { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10295 { 0 }
10297 static const struct message WmRestore_2[] = {
10298 { WM_SHOWWINDOW, sent|wparam, 1 },
10299 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10300 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10301 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10302 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10303 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10304 { 0 }
10306 static const struct message WmRestore_3[] = {
10307 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10308 { WM_GETMINMAXINFO, sent },
10309 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10310 { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10311 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10312 { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10313 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10314 { WM_MOVE, sent|defwinproc },
10315 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10316 { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10317 { 0 }
10319 static const struct message WmRestore_4[] = {
10320 { HCBT_MINMAX, hook|lparam|optional, 0, SW_RESTORE },
10321 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10322 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10323 { WM_MOVE, sent|defwinproc|optional },
10324 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10325 { 0 }
10327 static const struct message WmRestore_5[] = {
10328 { HCBT_MINMAX, hook|lparam|optional, 0, SW_SHOWNORMAL },
10329 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10330 { HCBT_ACTIVATE, hook|optional },
10331 { HCBT_SETFOCUS, hook|optional },
10332 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10333 { WM_MOVE, sent|defwinproc|optional },
10334 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10335 { 0 }
10337 static const struct message WmHide_1[] = {
10338 { WM_SHOWWINDOW, sent|wparam, 0 },
10339 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOACTIVATE },
10340 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOACTIVATE },
10341 { HCBT_ACTIVATE, hook|optional },
10342 { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10343 { 0 }
10345 static const struct message WmHide_2[] = {
10346 { WM_SHOWWINDOW, sent|wparam, 0 },
10347 { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10348 { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10349 { HCBT_ACTIVATE, hook|optional },
10350 { 0 }
10352 static const struct message WmHide_3[] = {
10353 { WM_SHOWWINDOW, sent|wparam, 0 },
10354 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10355 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10356 { HCBT_SETFOCUS, hook|optional },
10357 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10358 { 0 }
10360 static const struct message WmShowMinimized_1[] = {
10361 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10362 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10363 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10364 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10365 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10366 { WM_MOVE, sent|defwinproc },
10367 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10368 { 0 }
10370 static const struct message WmMinimize_1[] = {
10371 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10372 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10373 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10374 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10375 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10376 { WM_MOVE, sent|defwinproc },
10377 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10378 { 0 }
10380 static const struct message WmMinimize_2[] = {
10381 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10382 { HCBT_SETFOCUS, hook|optional },
10383 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10384 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10385 { WM_MOVE, sent|defwinproc },
10386 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10387 { 0 }
10389 static const struct message WmMinimize_3[] = {
10390 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10391 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10392 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10393 { WM_MOVE, sent|defwinproc },
10394 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10395 { 0 }
10397 static const struct message WmShowMinNoActivate[] = {
10398 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10399 { WM_WINDOWPOSCHANGING, sent },
10400 { WM_WINDOWPOSCHANGED, sent },
10401 { WM_MOVE, sent|defwinproc|optional },
10402 { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
10403 { 0 }
10405 static const struct message WmMinMax_1[] = {
10406 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10407 { 0 }
10409 static const struct message WmMinMax_2[] = {
10410 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10411 { WM_GETMINMAXINFO, sent|optional },
10412 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED },
10413 { HCBT_ACTIVATE, hook|optional },
10414 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10415 { HCBT_SETFOCUS, hook|optional },
10416 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10417 { WM_MOVE, sent|defwinproc|optional },
10418 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MAXIMIZED },
10419 { HCBT_SETFOCUS, hook|optional },
10420 { 0 }
10422 static const struct message WmMinMax_3[] = {
10423 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10424 { HCBT_SETFOCUS, hook|optional },
10425 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10426 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10427 { WM_MOVE, sent|defwinproc|optional },
10428 { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
10429 { 0 }
10431 static const struct message WmMinMax_4[] = {
10432 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10433 { 0 }
10435 static const struct message WmShowMaximized_1[] = {
10436 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10437 { WM_GETMINMAXINFO, sent },
10438 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10439 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10440 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10441 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10442 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10443 { WM_MOVE, sent|defwinproc },
10444 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10445 { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10446 { 0 }
10448 static const struct message WmShowMaximized_2[] = {
10449 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10450 { WM_GETMINMAXINFO, sent },
10451 { WM_WINDOWPOSCHANGING, sent|optional },
10452 { HCBT_ACTIVATE, hook|optional },
10453 { WM_WINDOWPOSCHANGED, sent|optional },
10454 { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
10455 { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
10456 { WM_WINDOWPOSCHANGING, sent|optional },
10457 { HCBT_SETFOCUS, hook|optional },
10458 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10459 { WM_MOVE, sent|defwinproc },
10460 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10461 { HCBT_SETFOCUS, hook|optional },
10462 { 0 }
10464 static const struct message WmShowMaximized_3[] = {
10465 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10466 { WM_GETMINMAXINFO, sent|optional },
10467 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10468 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10469 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10470 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10471 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10472 { WM_MOVE, sent|defwinproc|optional },
10473 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10474 { 0 }
10477 static void test_ShowWindow(void)
10479 /* ShowWindow commands in random order */
10480 static const struct
10482 INT cmd; /* ShowWindow command */
10483 LPARAM ret; /* ShowWindow return value */
10484 DWORD style; /* window style after the command */
10485 const struct message *msg; /* message sequence the command produces */
10486 BOOL todo_msg; /* message sequence doesn't match what Wine does */
10487 } sw[] =
10489 /* 1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
10490 /* 2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10491 /* 3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10492 /* 4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10493 /* 5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
10494 /* 6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
10495 /* 7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
10496 /* 8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10497 /* 9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
10498 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10499 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
10500 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
10501 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
10502 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10503 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
10504 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10505 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
10506 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10507 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10508 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10509 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10510 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
10511 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
10512 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10513 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10514 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
10515 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
10516 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10517 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10518 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
10519 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10520 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, FALSE },
10521 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10522 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE }, /* what does this mean?! */
10523 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE },
10524 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10525 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
10526 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10527 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10528 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, FALSE },
10529 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10530 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, FALSE },
10531 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10532 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10533 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10534 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
10535 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
10536 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
10537 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
10538 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
10539 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
10540 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10541 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10542 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, FALSE },
10543 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10544 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
10545 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
10547 HWND hwnd;
10548 DWORD style;
10549 LPARAM ret;
10550 INT i;
10552 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
10553 hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
10554 120, 120, 90, 90,
10555 0, 0, 0, NULL);
10556 assert(hwnd);
10558 style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10559 ok(style == 0, "expected style 0, got %08x\n", style);
10561 flush_events();
10562 flush_sequence();
10564 for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
10566 static const char * const sw_cmd_name[13] =
10568 "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
10569 "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
10570 "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
10571 "SW_NORMALNA" /* 0xCC */
10573 char comment[64];
10574 INT idx; /* index into the above array of names */
10576 idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
10578 style = GetWindowLong(hwnd, GWL_STYLE);
10579 trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
10580 ret = ShowWindow(hwnd, sw[i].cmd);
10581 ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
10582 style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10583 ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
10585 sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
10586 ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
10588 flush_events();
10589 flush_sequence();
10592 DestroyWindow(hwnd);
10595 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
10597 struct recvd_message msg;
10599 if (ignore_message( message )) return 0;
10601 msg.hwnd = hwnd;
10602 msg.message = message;
10603 msg.flags = sent|wparam|lparam;
10604 msg.wParam = wParam;
10605 msg.lParam = lParam;
10606 msg.descr = "dialog";
10607 add_message(&msg);
10609 /* calling DefDlgProc leads to a recursion under XP */
10611 switch (message)
10613 case WM_INITDIALOG:
10614 case WM_GETDLGCODE:
10615 return 0;
10617 return 1;
10620 static const struct message WmDefDlgSetFocus_1[] = {
10621 { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10622 { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10623 { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10624 { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10625 { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10626 { HCBT_SETFOCUS, hook },
10627 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
10628 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10629 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10630 { WM_SETFOCUS, sent|wparam, 0 },
10631 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
10632 { WM_CTLCOLOREDIT, sent },
10633 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
10634 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10635 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10636 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10637 { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
10638 { 0 }
10640 static const struct message WmDefDlgSetFocus_2[] = {
10641 { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10642 { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10643 { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10644 { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10645 { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10646 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10647 { WM_CTLCOLOREDIT, sent|optional }, /* XP */
10648 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10649 { 0 }
10651 /* Creation of a dialog */
10652 static const struct message WmCreateDialogParamSeq_1[] = {
10653 { HCBT_CREATEWND, hook },
10654 { WM_NCCREATE, sent },
10655 { WM_NCCALCSIZE, sent|wparam, 0 },
10656 { WM_CREATE, sent },
10657 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10658 { WM_SIZE, sent|wparam, SIZE_RESTORED },
10659 { WM_MOVE, sent },
10660 { WM_SETFONT, sent },
10661 { WM_INITDIALOG, sent },
10662 { WM_CHANGEUISTATE, sent|optional },
10663 { 0 }
10665 /* Creation of a dialog */
10666 static const struct message WmCreateDialogParamSeq_2[] = {
10667 { HCBT_CREATEWND, hook },
10668 { WM_NCCREATE, sent },
10669 { WM_NCCALCSIZE, sent|wparam, 0 },
10670 { WM_CREATE, sent },
10671 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10672 { WM_SIZE, sent|wparam, SIZE_RESTORED },
10673 { WM_MOVE, sent },
10674 { WM_CHANGEUISTATE, sent|optional },
10675 { 0 }
10678 static void test_dialog_messages(void)
10680 WNDCLASS cls;
10681 HWND hdlg, hedit1, hedit2, hfocus;
10682 LRESULT ret;
10684 #define set_selection(hctl, start, end) \
10685 ret = SendMessage(hctl, EM_SETSEL, start, end); \
10686 ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
10688 #define check_selection(hctl, start, end) \
10689 ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
10690 ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
10692 subclass_edit();
10694 hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
10695 WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
10696 0, 0, 100, 100, 0, 0, 0, NULL);
10697 ok(hdlg != 0, "Failed to create custom dialog window\n");
10699 hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
10700 WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10701 0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
10702 ok(hedit1 != 0, "Failed to create edit control\n");
10703 hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
10704 WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10705 0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
10706 ok(hedit2 != 0, "Failed to create edit control\n");
10708 SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
10709 SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
10711 hfocus = GetFocus();
10712 ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
10714 SetFocus(hedit2);
10715 hfocus = GetFocus();
10716 ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
10718 check_selection(hedit1, 0, 0);
10719 check_selection(hedit2, 0, 0);
10721 set_selection(hedit2, 0, -1);
10722 check_selection(hedit2, 0, 3);
10724 SetFocus(0);
10725 hfocus = GetFocus();
10726 ok(hfocus == 0, "wrong focus %p\n", hfocus);
10728 flush_sequence();
10729 ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10730 ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10731 ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
10733 hfocus = GetFocus();
10734 ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10736 check_selection(hedit1, 0, 5);
10737 check_selection(hedit2, 0, 3);
10739 flush_sequence();
10740 ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10741 ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10742 ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
10744 hfocus = GetFocus();
10745 ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10747 check_selection(hedit1, 0, 5);
10748 check_selection(hedit2, 0, 3);
10750 EndDialog(hdlg, 0);
10751 DestroyWindow(hedit1);
10752 DestroyWindow(hedit2);
10753 DestroyWindow(hdlg);
10754 flush_sequence();
10756 #undef set_selection
10757 #undef check_selection
10759 ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
10760 cls.lpszClassName = "MyDialogClass";
10761 cls.hInstance = GetModuleHandle(0);
10762 /* need a cast since a dlgproc is used as a wndproc */
10763 cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
10764 if (!RegisterClass(&cls)) assert(0);
10766 hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
10767 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10768 ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
10769 EndDialog(hdlg, 0);
10770 DestroyWindow(hdlg);
10771 flush_sequence();
10773 hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
10774 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10775 ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
10776 EndDialog(hdlg, 0);
10777 DestroyWindow(hdlg);
10778 flush_sequence();
10780 UnregisterClass(cls.lpszClassName, cls.hInstance);
10783 static void test_nullCallback(void)
10785 HWND hwnd;
10787 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10788 100, 100, 200, 200, 0, 0, 0, NULL);
10789 ok (hwnd != 0, "Failed to create overlapped window\n");
10791 SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
10792 flush_events();
10793 DestroyWindow(hwnd);
10796 /* SetActiveWindow( 0 ) hwnd visible */
10797 static const struct message SetActiveWindowSeq0[] =
10799 { HCBT_ACTIVATE, hook|optional },
10800 { WM_NCACTIVATE, sent|wparam, 0 },
10801 { WM_GETTEXT, sent|defwinproc|optional },
10802 { WM_ACTIVATE, sent|wparam, 0 },
10803 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
10804 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
10805 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10806 { WM_KILLFOCUS, sent|optional },
10807 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10808 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10809 { WM_NCACTIVATE, sent|wparam|optional, 1 },
10810 { WM_GETTEXT, sent|defwinproc|optional },
10811 { WM_ACTIVATE, sent|wparam|optional, 1 },
10812 { HCBT_SETFOCUS, hook|optional },
10813 { WM_KILLFOCUS, sent|defwinproc|optional },
10814 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
10815 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
10816 { WM_IME_SETCONTEXT, sent|optional },
10817 { WM_IME_SETCONTEXT, sent|optional },
10818 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10819 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10820 { WM_SETFOCUS, sent|defwinproc|optional },
10821 { WM_GETTEXT, sent|optional },
10822 { 0 }
10824 /* SetActiveWindow( hwnd ) hwnd visible */
10825 static const struct message SetActiveWindowSeq1[] =
10827 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10828 { 0 }
10830 /* SetActiveWindow( popup ) hwnd visible, popup visible */
10831 static const struct message SetActiveWindowSeq2[] =
10833 { HCBT_ACTIVATE, hook },
10834 { WM_NCACTIVATE, sent|wparam, 0 },
10835 { WM_GETTEXT, sent|defwinproc|optional },
10836 { WM_ACTIVATE, sent|wparam, 0 },
10837 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10838 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10839 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10840 { WM_NCPAINT, sent|optional },
10841 { WM_GETTEXT, sent|defwinproc|optional },
10842 { WM_ERASEBKGND, sent|optional },
10843 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10844 { WM_NCACTIVATE, sent|wparam, 1 },
10845 { WM_GETTEXT, sent|defwinproc|optional },
10846 { WM_ACTIVATE, sent|wparam, 1 },
10847 { HCBT_SETFOCUS, hook },
10848 { WM_KILLFOCUS, sent|defwinproc },
10849 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10850 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10851 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10852 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10853 { WM_SETFOCUS, sent|defwinproc },
10854 { WM_GETTEXT, sent|optional },
10855 { 0 }
10858 /* SetActiveWindow( hwnd ) hwnd not visible */
10859 static const struct message SetActiveWindowSeq3[] =
10861 { HCBT_ACTIVATE, hook },
10862 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10863 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10864 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10865 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10866 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10867 { WM_ACTIVATEAPP, sent|wparam, 1 },
10868 { WM_ACTIVATEAPP, sent|wparam, 1 },
10869 { WM_NCACTIVATE, sent|wparam, 1 },
10870 { WM_ACTIVATE, sent|wparam, 1 },
10871 { HCBT_SETFOCUS, hook },
10872 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10873 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10874 { WM_SETFOCUS, sent|defwinproc },
10875 { 0 }
10877 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
10878 static const struct message SetActiveWindowSeq4[] =
10880 { HCBT_ACTIVATE, hook },
10881 { WM_NCACTIVATE, sent|wparam, 0 },
10882 { WM_GETTEXT, sent|defwinproc|optional },
10883 { WM_ACTIVATE, sent|wparam, 0 },
10884 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10885 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10886 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10887 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10888 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10889 { WM_NCACTIVATE, sent|wparam, 1 },
10890 { WM_GETTEXT, sent|defwinproc|optional },
10891 { WM_ACTIVATE, sent|wparam, 1 },
10892 { HCBT_SETFOCUS, hook },
10893 { WM_KILLFOCUS, sent|defwinproc },
10894 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10895 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10896 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10897 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10898 { WM_SETFOCUS, sent|defwinproc },
10899 { 0 }
10903 static void test_SetActiveWindow(void)
10905 HWND hwnd, popup, ret;
10907 hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10908 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10909 100, 100, 200, 200, 0, 0, 0, NULL);
10911 popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10912 WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
10913 100, 100, 200, 200, hwnd, 0, 0, NULL);
10915 ok(hwnd != 0, "Failed to create overlapped window\n");
10916 ok(popup != 0, "Failed to create popup window\n");
10917 SetForegroundWindow( popup );
10918 flush_sequence();
10920 trace("SetActiveWindow(0)\n");
10921 ret = SetActiveWindow(0);
10922 ok( ret == popup, "Failed to SetActiveWindow(0)\n");
10923 ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", FALSE);
10924 flush_sequence();
10926 trace("SetActiveWindow(hwnd), hwnd visible\n");
10927 ret = SetActiveWindow(hwnd);
10928 if (ret == hwnd) ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
10929 flush_sequence();
10931 trace("SetActiveWindow(popup), hwnd visible, popup visible\n");
10932 ret = SetActiveWindow(popup);
10933 ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visible\n");
10934 ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visible", FALSE);
10935 flush_sequence();
10937 ShowWindow(hwnd, SW_HIDE);
10938 ShowWindow(popup, SW_HIDE);
10939 flush_sequence();
10941 trace("SetActiveWindow(hwnd), hwnd not visible\n");
10942 ret = SetActiveWindow(hwnd);
10943 ok( ret == NULL, "SetActiveWindow(hwnd), hwnd not visible, previous is %p\n", ret );
10944 ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
10945 flush_sequence();
10947 trace("SetActiveWindow(popup), hwnd not visible, popup not visible\n");
10948 ret = SetActiveWindow(popup);
10949 ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
10950 ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visible", TRUE);
10951 flush_sequence();
10953 trace("done\n");
10955 DestroyWindow(hwnd);
10958 static const struct message SetForegroundWindowSeq[] =
10960 { WM_NCACTIVATE, sent|wparam, 0 },
10961 { WM_GETTEXT, sent|defwinproc|optional },
10962 { WM_ACTIVATE, sent|wparam, 0 },
10963 { WM_ACTIVATEAPP, sent|wparam, 0 },
10964 { WM_KILLFOCUS, sent },
10965 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
10966 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
10967 { 0 }
10970 static void test_SetForegroundWindow(void)
10972 HWND hwnd;
10974 hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
10975 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10976 100, 100, 200, 200, 0, 0, 0, NULL);
10977 ok (hwnd != 0, "Failed to create overlapped window\n");
10978 SetForegroundWindow( hwnd );
10979 flush_sequence();
10981 trace("SetForegroundWindow( 0 )\n");
10982 SetForegroundWindow( 0 );
10983 ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
10984 trace("SetForegroundWindow( GetDesktopWindow() )\n");
10985 SetForegroundWindow( GetDesktopWindow() );
10986 ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
10987 "foreground top level window", FALSE);
10988 trace("done\n");
10990 DestroyWindow(hwnd);
10993 static void test_dbcs_wm_char(void)
10995 BYTE dbch[2];
10996 WCHAR wch, bad_wch;
10997 HWND hwnd, hwnd2;
10998 MSG msg;
10999 DWORD time;
11000 POINT pt;
11001 DWORD_PTR res;
11002 CPINFOEXA cpinfo;
11003 UINT i, j, k;
11004 struct message wmCharSeq[2];
11006 if (!pGetCPInfoExA)
11008 win_skip("GetCPInfoExA is not available\n");
11009 return;
11012 pGetCPInfoExA( CP_ACP, 0, &cpinfo );
11013 if (cpinfo.MaxCharSize != 2)
11015 skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
11016 return;
11019 dbch[0] = dbch[1] = 0;
11020 wch = 0;
11021 bad_wch = cpinfo.UnicodeDefaultChar;
11022 for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
11023 for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
11024 for (k = 128; k <= 255; k++)
11026 char str[2];
11027 WCHAR wstr[2];
11028 str[0] = j;
11029 str[1] = k;
11030 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
11031 WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
11032 (BYTE)str[0] == j && (BYTE)str[1] == k &&
11033 HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
11035 dbch[0] = j;
11036 dbch[1] = k;
11037 wch = wstr[0];
11038 break;
11042 if (!wch)
11044 skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
11045 return;
11047 trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
11048 dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
11050 hwnd = CreateWindowExW(0, testWindowClassW, NULL,
11051 WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11052 hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
11053 WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11054 ok (hwnd != 0, "Failed to create overlapped window\n");
11055 ok (hwnd2 != 0, "Failed to create overlapped window\n");
11056 flush_sequence();
11058 memset( wmCharSeq, 0, sizeof(wmCharSeq) );
11059 wmCharSeq[0].message = WM_CHAR;
11060 wmCharSeq[0].flags = sent|wparam;
11061 wmCharSeq[0].wParam = wch;
11063 /* posted message */
11064 PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11065 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11066 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11067 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11068 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11069 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11070 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11072 /* posted thread message */
11073 PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
11074 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11075 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11076 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11077 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11078 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11079 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11081 /* sent message */
11082 flush_sequence();
11083 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11084 ok_sequence( WmEmptySeq, "no messages", FALSE );
11085 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11086 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11087 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11089 /* sent message with timeout */
11090 flush_sequence();
11091 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11092 ok_sequence( WmEmptySeq, "no messages", FALSE );
11093 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11094 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11095 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11097 /* sent message with timeout and callback */
11098 flush_sequence();
11099 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11100 ok_sequence( WmEmptySeq, "no messages", FALSE );
11101 SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11102 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11103 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11105 /* sent message with callback */
11106 flush_sequence();
11107 SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11108 ok_sequence( WmEmptySeq, "no messages", FALSE );
11109 SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11110 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11111 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11113 /* direct window proc call */
11114 flush_sequence();
11115 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11116 ok_sequence( WmEmptySeq, "no messages", FALSE );
11117 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11118 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11120 /* dispatch message */
11121 msg.hwnd = hwnd;
11122 msg.message = WM_CHAR;
11123 msg.wParam = dbch[0];
11124 msg.lParam = 0;
11125 DispatchMessageA( &msg );
11126 ok_sequence( WmEmptySeq, "no messages", FALSE );
11127 msg.wParam = dbch[1];
11128 DispatchMessageA( &msg );
11129 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11131 /* window handle is irrelevant */
11132 flush_sequence();
11133 SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11134 ok_sequence( WmEmptySeq, "no messages", FALSE );
11135 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11136 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11137 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11139 /* interleaved post and send */
11140 flush_sequence();
11141 PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11142 SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11143 ok_sequence( WmEmptySeq, "no messages", FALSE );
11144 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11145 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11146 ok_sequence( WmEmptySeq, "no messages", FALSE );
11147 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11148 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11149 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11150 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11151 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11152 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11153 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11155 /* interleaved sent message and winproc */
11156 flush_sequence();
11157 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11158 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11159 ok_sequence( WmEmptySeq, "no messages", FALSE );
11160 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11161 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11162 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11163 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11165 /* interleaved winproc and dispatch */
11166 msg.hwnd = hwnd;
11167 msg.message = WM_CHAR;
11168 msg.wParam = dbch[0];
11169 msg.lParam = 0;
11170 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11171 DispatchMessageA( &msg );
11172 ok_sequence( WmEmptySeq, "no messages", FALSE );
11173 msg.wParam = dbch[1];
11174 DispatchMessageA( &msg );
11175 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11176 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11177 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11179 /* interleaved sends */
11180 flush_sequence();
11181 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11182 SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
11183 ok_sequence( WmEmptySeq, "no messages", FALSE );
11184 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11185 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11186 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11187 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11189 /* dbcs WM_CHAR */
11190 flush_sequence();
11191 SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
11192 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11193 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11195 /* other char messages are not magic */
11196 PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
11197 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11198 ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
11199 ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
11200 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11201 PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
11202 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11203 ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
11204 ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
11205 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11207 /* test retrieving messages */
11209 PostMessageW( hwnd, WM_CHAR, wch, 0 );
11210 ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11211 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11212 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11213 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11214 ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11215 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11216 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11217 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11218 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11220 /* message filters */
11221 PostMessageW( hwnd, WM_CHAR, wch, 0 );
11222 ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11223 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11224 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11225 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11226 /* message id is filtered, hwnd is not */
11227 ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
11228 ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
11229 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11230 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11231 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11232 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11234 /* mixing GetMessage and PostMessage */
11235 PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
11236 ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
11237 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11238 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11239 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11240 ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
11241 time = msg.time;
11242 pt = msg.pt;
11243 ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
11244 ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11245 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11246 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11247 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11248 ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
11249 ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
11250 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 );
11251 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11253 /* without PM_REMOVE */
11254 PostMessageW( hwnd, WM_CHAR, wch, 0 );
11255 ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
11256 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11257 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11258 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11259 ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11260 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11261 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11262 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11263 ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
11264 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11265 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11266 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11267 ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11268 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11269 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11270 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11271 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11273 DestroyWindow(hwnd);
11276 #define ID_LISTBOX 0x000f
11278 static const struct message wm_lb_setcursel_0[] =
11280 { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
11281 { WM_CTLCOLORLISTBOX, sent|parent },
11282 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
11283 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11284 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11285 { 0 }
11287 static const struct message wm_lb_setcursel_1[] =
11289 { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
11290 { WM_CTLCOLORLISTBOX, sent|parent },
11291 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
11292 { WM_CTLCOLORLISTBOX, sent|parent },
11293 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
11294 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
11295 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
11296 { 0 }
11298 static const struct message wm_lb_setcursel_2[] =
11300 { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
11301 { WM_CTLCOLORLISTBOX, sent|parent },
11302 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
11303 { WM_CTLCOLORLISTBOX, sent|parent },
11304 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
11305 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11306 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11307 { 0 }
11309 static const struct message wm_lb_click_0[] =
11311 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
11312 { HCBT_SETFOCUS, hook },
11313 { WM_KILLFOCUS, sent|parent },
11314 { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
11315 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11316 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
11317 { WM_SETFOCUS, sent|defwinproc },
11319 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
11320 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
11321 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11322 { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
11323 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
11325 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
11326 { WM_CTLCOLORLISTBOX, sent|parent },
11327 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
11328 { WM_CTLCOLORLISTBOX, sent|parent },
11329 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
11330 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
11332 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11333 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11335 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
11336 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
11337 { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
11338 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
11339 { 0 }
11341 static const struct message wm_lb_deletestring[] =
11343 { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
11344 { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
11345 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11346 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11347 { 0 }
11349 static const struct message wm_lb_deletestring_reset[] =
11351 { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
11352 { LB_RESETCONTENT, sent|wparam|lparam|defwinproc|optional, 0, 0 },
11353 { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
11354 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11355 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11356 { 0 }
11359 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
11361 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
11363 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11365 static LONG defwndproc_counter = 0;
11366 LRESULT ret;
11367 struct recvd_message msg;
11369 /* do not log painting messages */
11370 if (message != WM_PAINT &&
11371 message != WM_NCPAINT &&
11372 message != WM_SYNCPAINT &&
11373 message != WM_ERASEBKGND &&
11374 message != WM_NCHITTEST &&
11375 message != WM_GETTEXT &&
11376 !ignore_message( message ))
11378 msg.hwnd = hwnd;
11379 msg.message = message;
11380 msg.flags = sent|wparam|lparam;
11381 if (defwndproc_counter) msg.flags |= defwinproc;
11382 msg.wParam = wp;
11383 msg.lParam = lp;
11384 msg.descr = "listbox";
11385 add_message(&msg);
11388 defwndproc_counter++;
11389 ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
11390 defwndproc_counter--;
11392 return ret;
11395 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
11396 int caret_index, int top_index, int line)
11398 LRESULT ret;
11400 /* calling an orig proc helps to avoid unnecessary message logging */
11401 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
11402 ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
11403 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
11404 ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
11405 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
11406 ok_(__FILE__, line)(ret == caret_index ||
11407 broken(cur_sel == -1 && caret_index == 0 && ret == -1), /* nt4 */
11408 "expected caret index %d, got %ld\n", caret_index, ret);
11409 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
11410 ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
11413 static void test_listbox_messages(void)
11415 HWND parent, listbox;
11416 LRESULT ret;
11418 parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11419 100, 100, 200, 200, 0, 0, 0, NULL);
11420 listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
11421 WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
11422 10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
11423 listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
11425 check_lb_state(listbox, 0, LB_ERR, 0, 0);
11427 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
11428 ok(ret == 0, "expected 0, got %ld\n", ret);
11429 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
11430 ok(ret == 1, "expected 1, got %ld\n", ret);
11431 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
11432 ok(ret == 2, "expected 2, got %ld\n", ret);
11434 check_lb_state(listbox, 3, LB_ERR, 0, 0);
11436 flush_sequence();
11438 log_all_parent_messages++;
11440 trace("selecting item 0\n");
11441 ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
11442 ok(ret == 0, "expected 0, got %ld\n", ret);
11443 ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
11444 check_lb_state(listbox, 3, 0, 0, 0);
11445 flush_sequence();
11447 trace("selecting item 1\n");
11448 ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
11449 ok(ret == 1, "expected 1, got %ld\n", ret);
11450 ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
11451 check_lb_state(listbox, 3, 1, 1, 0);
11453 trace("selecting item 2\n");
11454 ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
11455 ok(ret == 2, "expected 2, got %ld\n", ret);
11456 ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
11457 check_lb_state(listbox, 3, 2, 2, 0);
11459 trace("clicking on item 0\n");
11460 ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
11461 ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11462 ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
11463 ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11464 ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
11465 check_lb_state(listbox, 3, 0, 0, 0);
11466 flush_sequence();
11468 trace("deleting item 0\n");
11469 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11470 ok(ret == 2, "expected 2, got %ld\n", ret);
11471 ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
11472 check_lb_state(listbox, 2, -1, 0, 0);
11473 flush_sequence();
11475 trace("deleting item 0\n");
11476 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11477 ok(ret == 1, "expected 1, got %ld\n", ret);
11478 ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
11479 check_lb_state(listbox, 1, -1, 0, 0);
11480 flush_sequence();
11482 trace("deleting item 0\n");
11483 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11484 ok(ret == 0, "expected 0, got %ld\n", ret);
11485 ok_sequence(wm_lb_deletestring_reset, "LB_DELETESTRING 0", FALSE );
11486 check_lb_state(listbox, 0, -1, 0, 0);
11487 flush_sequence();
11489 trace("deleting item 0\n");
11490 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11491 ok(ret == LB_ERR, "expected LB_ERR, got %ld\n", ret);
11492 check_lb_state(listbox, 0, -1, 0, 0);
11493 flush_sequence();
11495 log_all_parent_messages--;
11497 DestroyWindow(listbox);
11498 DestroyWindow(parent);
11501 /*************************** Menu test ******************************/
11502 static const struct message wm_popup_menu_1[] =
11504 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11505 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11506 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
11507 { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
11508 { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
11509 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
11510 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11511 { WM_INITMENU, sent|lparam, 0, 0 },
11512 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
11513 { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
11514 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
11515 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
11516 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
11517 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11518 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11519 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
11520 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11521 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11522 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11523 { WM_MENUCOMMAND, sent }, /* |wparam, 200 - Win9x */
11524 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11525 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11526 { 0 }
11528 static const struct message wm_popup_menu_2[] =
11530 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11531 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11532 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11533 { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11534 { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11535 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11536 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11537 { WM_INITMENU, sent|lparam, 0, 0 },
11538 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11539 { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11540 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11541 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11542 { HCBT_CREATEWND, hook },
11543 { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11544 |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11545 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11546 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11547 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11548 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11549 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11550 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11551 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11552 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11553 { HCBT_DESTROYWND, hook },
11554 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11555 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11556 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11557 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11558 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11559 { WM_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
11560 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11561 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11562 { 0 }
11564 static const struct message wm_popup_menu_3[] =
11566 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11567 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11568 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11569 { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11570 { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11571 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11572 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11573 { WM_INITMENU, sent|lparam, 0, 0 },
11574 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11575 { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11576 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11577 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11578 { HCBT_CREATEWND, hook },
11579 { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11580 |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11581 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11582 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11583 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11584 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11585 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11586 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11587 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11588 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11589 { HCBT_DESTROYWND, hook },
11590 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11591 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11592 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11593 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11594 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11595 { WM_COMMAND, sent|wparam|lparam, 100, 0 },
11596 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11597 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11598 { 0 }
11601 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11603 if (message == WM_ENTERIDLE ||
11604 message == WM_INITMENU ||
11605 message == WM_INITMENUPOPUP ||
11606 message == WM_MENUSELECT ||
11607 message == WM_PARENTNOTIFY ||
11608 message == WM_ENTERMENULOOP ||
11609 message == WM_EXITMENULOOP ||
11610 message == WM_UNINITMENUPOPUP ||
11611 message == WM_KEYDOWN ||
11612 message == WM_KEYUP ||
11613 message == WM_CHAR ||
11614 message == WM_SYSKEYDOWN ||
11615 message == WM_SYSKEYUP ||
11616 message == WM_SYSCHAR ||
11617 message == WM_COMMAND ||
11618 message == WM_MENUCOMMAND)
11620 struct recvd_message msg;
11622 msg.hwnd = hwnd;
11623 msg.message = message;
11624 msg.flags = sent|wparam|lparam;
11625 msg.wParam = wp;
11626 msg.lParam = lp;
11627 msg.descr = "parent_menu_proc";
11628 add_message(&msg);
11631 return DefWindowProcA(hwnd, message, wp, lp);
11634 static void set_menu_style(HMENU hmenu, DWORD style)
11636 MENUINFO mi;
11637 BOOL ret;
11639 mi.cbSize = sizeof(mi);
11640 mi.fMask = MIM_STYLE;
11641 mi.dwStyle = style;
11642 SetLastError(0xdeadbeef);
11643 ret = pSetMenuInfo(hmenu, &mi);
11644 ok(ret, "SetMenuInfo error %u\n", GetLastError());
11647 static DWORD get_menu_style(HMENU hmenu)
11649 MENUINFO mi;
11650 BOOL ret;
11652 mi.cbSize = sizeof(mi);
11653 mi.fMask = MIM_STYLE;
11654 mi.dwStyle = 0;
11655 SetLastError(0xdeadbeef);
11656 ret = pGetMenuInfo(hmenu, &mi);
11657 ok(ret, "GetMenuInfo error %u\n", GetLastError());
11659 return mi.dwStyle;
11662 static void test_menu_messages(void)
11664 MSG msg;
11665 WNDCLASSA cls;
11666 HMENU hmenu, hmenu_popup;
11667 HWND hwnd;
11668 DWORD style;
11670 if (!pGetMenuInfo || !pSetMenuInfo)
11672 win_skip("GetMenuInfo and/or SetMenuInfo are not available\n");
11673 return;
11675 cls.style = 0;
11676 cls.lpfnWndProc = parent_menu_proc;
11677 cls.cbClsExtra = 0;
11678 cls.cbWndExtra = 0;
11679 cls.hInstance = GetModuleHandleA(0);
11680 cls.hIcon = 0;
11681 cls.hCursor = LoadCursorA(0, IDC_ARROW);
11682 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
11683 cls.lpszMenuName = NULL;
11684 cls.lpszClassName = "TestMenuClass";
11685 UnregisterClass(cls.lpszClassName, cls.hInstance);
11686 if (!RegisterClassA(&cls)) assert(0);
11688 SetLastError(0xdeadbeef);
11689 hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11690 100, 100, 200, 200, 0, 0, 0, NULL);
11691 ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
11693 SetLastError(0xdeadbeef);
11694 hmenu = LoadMenuA(GetModuleHandle(0), MAKEINTRESOURCE(1));
11695 ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
11697 SetMenu(hwnd, hmenu);
11698 SetForegroundWindow( hwnd );
11700 set_menu_style(hmenu, MNS_NOTIFYBYPOS);
11701 style = get_menu_style(hmenu);
11702 ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11704 hmenu_popup = GetSubMenu(hmenu, 0);
11705 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11706 style = get_menu_style(hmenu_popup);
11707 ok(style == 0, "expected 0, got %u\n", style);
11709 hmenu_popup = GetSubMenu(hmenu_popup, 0);
11710 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11711 style = get_menu_style(hmenu_popup);
11712 ok(style == 0, "expected 0, got %u\n", style);
11714 /* Alt+E, Enter */
11715 trace("testing a popup menu command\n");
11716 flush_sequence();
11717 keybd_event(VK_MENU, 0, 0, 0);
11718 keybd_event('E', 0, 0, 0);
11719 keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
11720 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11721 keybd_event(VK_RETURN, 0, 0, 0);
11722 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11723 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11725 TranslateMessage(&msg);
11726 DispatchMessage(&msg);
11728 if (!sequence_cnt) /* we didn't get any message */
11730 skip( "queuing key events not supported\n" );
11731 goto done;
11733 /* win98 queues only a WM_KEYUP and doesn't start menu tracking */
11734 if (sequence[0].message == WM_KEYUP && sequence[0].wParam == VK_MENU)
11736 win_skip( "menu tracking through VK_MENU not supported\n" );
11737 goto done;
11739 ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
11741 /* Alt+F, Right, Enter */
11742 trace("testing submenu of a popup menu command\n");
11743 flush_sequence();
11744 keybd_event(VK_MENU, 0, 0, 0);
11745 keybd_event('F', 0, 0, 0);
11746 keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11747 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11748 keybd_event(VK_RIGHT, 0, 0, 0);
11749 keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11750 keybd_event(VK_RETURN, 0, 0, 0);
11751 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11752 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11754 TranslateMessage(&msg);
11755 DispatchMessage(&msg);
11757 ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
11759 set_menu_style(hmenu, 0);
11760 style = get_menu_style(hmenu);
11761 ok(style == 0, "expected 0, got %u\n", style);
11763 hmenu_popup = GetSubMenu(hmenu, 0);
11764 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11765 set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
11766 style = get_menu_style(hmenu_popup);
11767 ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11769 hmenu_popup = GetSubMenu(hmenu_popup, 0);
11770 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11771 style = get_menu_style(hmenu_popup);
11772 ok(style == 0, "expected 0, got %u\n", style);
11774 /* Alt+F, Right, Enter */
11775 trace("testing submenu of a popup menu command\n");
11776 flush_sequence();
11777 keybd_event(VK_MENU, 0, 0, 0);
11778 keybd_event('F', 0, 0, 0);
11779 keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11780 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11781 keybd_event(VK_RIGHT, 0, 0, 0);
11782 keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11783 keybd_event(VK_RETURN, 0, 0, 0);
11784 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11785 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11787 TranslateMessage(&msg);
11788 DispatchMessage(&msg);
11790 ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
11792 done:
11793 DestroyWindow(hwnd);
11794 DestroyMenu(hmenu);
11798 static void test_paintingloop(void)
11800 HWND hwnd;
11802 paint_loop_done = 0;
11803 hwnd = CreateWindowExA(0x0,"PaintLoopWindowClass",
11804 "PaintLoopWindowClass",WS_OVERLAPPEDWINDOW,
11805 100, 100, 100, 100, 0, 0, 0, NULL );
11806 ok(hwnd != 0, "PaintLoop window error %u\n", GetLastError());
11807 ShowWindow(hwnd,SW_NORMAL);
11808 SetFocus(hwnd);
11810 while (!paint_loop_done)
11812 MSG msg;
11813 if (PeekMessageA(&msg, 0, 0, 0, 1))
11815 TranslateMessage(&msg);
11816 DispatchMessage(&msg);
11819 DestroyWindow(hwnd);
11822 static void test_defwinproc(void)
11824 HWND hwnd;
11825 MSG msg;
11826 int gotwmquit = FALSE;
11827 hwnd = CreateWindowExA(0, "static", "test_defwndproc", WS_POPUP, 0,0,0,0,0,0,0, NULL);
11828 assert(hwnd);
11829 DefWindowProcA( hwnd, WM_ENDSESSION, 1, 0);
11830 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) {
11831 if( msg.message == WM_QUIT) gotwmquit = TRUE;
11832 DispatchMessageA( &msg );
11834 ok( gotwmquit == FALSE, "Unexpected WM_QUIT message!\n");
11835 DestroyWindow( hwnd);
11838 #define clear_clipboard(hwnd) clear_clipboard_(__LINE__, (hwnd))
11839 static void clear_clipboard_(int line, HWND hWnd)
11841 BOOL succ;
11842 succ = OpenClipboard(hWnd);
11843 ok_(__FILE__, line)(succ, "OpenClipboard failed, err=%u\n", GetLastError());
11844 succ = EmptyClipboard();
11845 ok_(__FILE__, line)(succ, "EmptyClipboard failed, err=%u\n", GetLastError());
11846 succ = CloseClipboard();
11847 ok_(__FILE__, line)(succ, "CloseClipboard failed, err=%u\n", GetLastError());
11850 #define expect_HWND(expected, got) expect_HWND_(__LINE__, (expected), (got))
11851 static void expect_HWND_(int line, HWND expected, HWND got)
11853 ok_(__FILE__, line)(got==expected, "Expected %p, got %p\n", expected, got);
11856 static WNDPROC pOldViewerProc;
11858 static LRESULT CALLBACK recursive_viewer_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
11860 static BOOL recursion_guard;
11862 if (message == WM_DRAWCLIPBOARD && !recursion_guard)
11864 recursion_guard = TRUE;
11865 clear_clipboard(hWnd);
11866 recursion_guard = FALSE;
11868 return CallWindowProcA(pOldViewerProc, hWnd, message, wParam, lParam);
11871 static void test_clipboard_viewers(void)
11873 static struct message wm_change_cb_chain[] =
11875 { WM_CHANGECBCHAIN, sent|wparam|lparam, 0, 0 },
11876 { 0 }
11878 static const struct message wm_clipboard_destroyed[] =
11880 { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
11881 { 0 }
11883 static struct message wm_clipboard_changed[] =
11885 { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
11886 { 0 }
11888 static struct message wm_clipboard_changed_and_owned[] =
11890 { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
11891 { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
11892 { 0 }
11895 HINSTANCE hInst = GetModuleHandleA(NULL);
11896 HWND hWnd1, hWnd2, hWnd3;
11897 HWND hOrigViewer;
11898 HWND hRet;
11900 hWnd1 = CreateWindowExA(0, "TestWindowClass", "Clipboard viewer test wnd 1",
11901 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
11902 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
11903 GetDesktopWindow(), NULL, hInst, NULL);
11904 hWnd2 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 2",
11905 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
11906 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
11907 GetDesktopWindow(), NULL, hInst, NULL);
11908 hWnd3 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 3",
11909 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
11910 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
11911 GetDesktopWindow(), NULL, hInst, NULL);
11912 trace("clipbd viewers: hWnd1=%p, hWnd2=%p, hWnd3=%p\n", hWnd1, hWnd2, hWnd3);
11913 assert(hWnd1 && hWnd2 && hWnd3);
11915 flush_sequence();
11917 /* Test getting the clipboard viewer and setting the viewer to NULL. */
11918 hOrigViewer = GetClipboardViewer();
11919 hRet = SetClipboardViewer(NULL);
11920 ok_sequence(WmEmptySeq, "set viewer to NULL", FALSE);
11921 expect_HWND(hOrigViewer, hRet);
11922 expect_HWND(NULL, GetClipboardViewer());
11924 /* Test registering hWnd1 as a viewer. */
11925 hRet = SetClipboardViewer(hWnd1);
11926 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
11927 ok_sequence(wm_clipboard_changed, "set viewer NULL->1", FALSE);
11928 expect_HWND(NULL, hRet);
11929 expect_HWND(hWnd1, GetClipboardViewer());
11931 /* Test that changing the clipboard actually refreshes the registered viewer. */
11932 clear_clipboard(hWnd1);
11933 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
11934 ok_sequence(wm_clipboard_changed, "clear clipbd (viewer=owner=1)", FALSE);
11936 /* Again, but with different owner. */
11937 clear_clipboard(hWnd2);
11938 wm_clipboard_changed_and_owned[1].wParam = (WPARAM) GetClipboardOwner();
11939 ok_sequence(wm_clipboard_changed_and_owned, "clear clipbd (viewer=1, owner=2)", FALSE);
11941 /* Test re-registering same window. */
11942 hRet = SetClipboardViewer(hWnd1);
11943 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
11944 ok_sequence(wm_clipboard_changed, "set viewer 1->1", FALSE);
11945 expect_HWND(hWnd1, hRet);
11946 expect_HWND(hWnd1, GetClipboardViewer());
11948 /* Test ChangeClipboardChain. */
11949 ChangeClipboardChain(hWnd2, hWnd3);
11950 wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
11951 wm_change_cb_chain[0].lParam = (LPARAM) hWnd3;
11952 ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=3)", FALSE);
11953 expect_HWND(hWnd1, GetClipboardViewer());
11955 ChangeClipboardChain(hWnd2, NULL);
11956 wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
11957 wm_change_cb_chain[0].lParam = 0;
11958 ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=NULL)", FALSE);
11959 expect_HWND(hWnd1, GetClipboardViewer());
11961 ChangeClipboardChain(NULL, hWnd2);
11962 ok_sequence(WmEmptySeq, "change chain (viewer=1, remove=NULL, next=2)", TRUE);
11963 expect_HWND(hWnd1, GetClipboardViewer());
11965 /* Actually change clipboard viewer with ChangeClipboardChain. */
11966 ChangeClipboardChain(hWnd1, hWnd2);
11967 ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=2)", FALSE);
11968 expect_HWND(hWnd2, GetClipboardViewer());
11970 /* Test that no refresh messages are sent when viewer has unregistered. */
11971 clear_clipboard(hWnd2);
11972 ok_sequence(WmEmptySeq, "clear clipd (viewer=2, owner=1)", FALSE);
11974 /* Register hWnd1 again. */
11975 ChangeClipboardChain(hWnd2, hWnd1);
11976 ok_sequence(WmEmptySeq, "change chain (viewer=remove=2, next=1)", FALSE);
11977 expect_HWND(hWnd1, GetClipboardViewer());
11979 /* Subclass hWnd1 so that when it receives a WM_DRAWCLIPBOARD message, it
11980 * changes the clipboard. When this happens, the system shouldn't send
11981 * another WM_DRAWCLIPBOARD (as this could cause an infinite loop).
11983 pOldViewerProc = (WNDPROC) SetWindowLongPtrA(hWnd1, GWLP_WNDPROC, (LONG_PTR) recursive_viewer_proc);
11984 clear_clipboard(hWnd2);
11985 /* The clipboard owner is changed in recursive_viewer_proc: */
11986 wm_clipboard_changed[0].wParam = (WPARAM) hWnd2;
11987 ok_sequence(wm_clipboard_changed, "recursive clear clipbd (viewer=1, owner=2)", TRUE);
11989 /* Test unregistering. */
11990 ChangeClipboardChain(hWnd1, NULL);
11991 ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=NULL)", FALSE);
11992 expect_HWND(NULL, GetClipboardViewer());
11994 clear_clipboard(hWnd1);
11995 ok_sequence(wm_clipboard_destroyed, "clear clipbd (no viewer, owner=1)", FALSE);
11997 DestroyWindow(hWnd1);
11998 DestroyWindow(hWnd2);
11999 DestroyWindow(hWnd3);
12000 SetClipboardViewer(hOrigViewer);
12003 static void test_PostMessage(void)
12005 static const struct
12007 HWND hwnd;
12008 BOOL ret;
12009 } data[] =
12011 { HWND_TOP /* 0 */, TRUE },
12012 { HWND_BROADCAST, TRUE },
12013 { HWND_BOTTOM, TRUE },
12014 { HWND_TOPMOST, TRUE },
12015 { HWND_NOTOPMOST, FALSE },
12016 { HWND_MESSAGE, FALSE },
12017 { (HWND)0xdeadbeef, FALSE }
12019 int i;
12020 HWND hwnd;
12021 BOOL ret;
12022 MSG msg;
12023 static const WCHAR staticW[] = {'s','t','a','t','i','c',0};
12025 SetLastError(0xdeadbeef);
12026 hwnd = CreateWindowExW(0, staticW, NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
12027 if (!hwnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
12029 win_skip("Skipping some PostMessage tests on Win9x/WinMe\n");
12030 return;
12032 assert(hwnd);
12034 flush_events();
12036 PostMessage(hwnd, WM_USER+1, 0x1234, 0x5678);
12037 PostMessage(0, WM_USER+2, 0x5678, 0x1234);
12039 for (i = 0; i < sizeof(data)/sizeof(data[0]); i++)
12041 memset(&msg, 0xab, sizeof(msg));
12042 ret = PeekMessageA(&msg, data[i].hwnd, 0, 0, PM_NOREMOVE);
12043 ok(ret == data[i].ret, "%d: hwnd %p expected %d, got %d\n", i, data[i].hwnd, data[i].ret, ret);
12044 if (data[i].ret)
12046 if (data[i].hwnd)
12047 ok(ret && msg.hwnd == 0 && msg.message == WM_USER+2 &&
12048 msg.wParam == 0x5678 && msg.lParam == 0x1234,
12049 "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/0/WM_USER+2/0x5678/0x1234\n",
12050 i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam);
12051 else
12052 ok(ret && msg.hwnd == hwnd && msg.message == WM_USER+1 &&
12053 msg.wParam == 0x1234 && msg.lParam == 0x5678,
12054 "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/%p/WM_USER+1/0x1234/0x5678\n",
12055 i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam, msg.hwnd);
12059 DestroyWindow(hwnd);
12060 flush_events();
12063 static const struct
12065 DWORD exp, broken;
12066 BOOL todo;
12067 } wait_idle_expect[] =
12069 /* 0 */ { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12070 { WAIT_TIMEOUT, 0, FALSE },
12071 { WAIT_TIMEOUT, 0, FALSE },
12072 { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12073 { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12074 /* 5 */ { WAIT_TIMEOUT, 0, FALSE },
12075 { WAIT_TIMEOUT, 0, FALSE },
12076 { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12077 { 0, 0, FALSE },
12078 { 0, 0, FALSE },
12079 /* 10 */ { 0, 0, FALSE },
12080 { 0, 0, FALSE },
12081 { 0, WAIT_TIMEOUT, FALSE },
12082 { 0, 0, FALSE },
12083 { 0, 0, FALSE },
12084 /* 15 */ { 0, 0, FALSE },
12085 { WAIT_TIMEOUT, 0, FALSE },
12086 { WAIT_TIMEOUT, 0, FALSE },
12087 { WAIT_TIMEOUT, 0, FALSE },
12088 { WAIT_TIMEOUT, 0, FALSE },
12089 /* 20 */ { WAIT_TIMEOUT, 0, FALSE },
12092 static DWORD CALLBACK do_wait_idle_child_thread( void *arg )
12094 MSG msg;
12096 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12097 Sleep( 200 );
12098 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12099 return 0;
12102 static void do_wait_idle_child( int arg )
12104 WNDCLASS cls;
12105 MSG msg;
12106 HWND hwnd = 0;
12107 HANDLE thread;
12108 DWORD id;
12109 HANDLE start_event = OpenEventA( EVENT_ALL_ACCESS, FALSE, "test_WaitForInputIdle_start" );
12110 HANDLE end_event = OpenEventA( EVENT_ALL_ACCESS, FALSE, "test_WaitForInputIdle_end" );
12112 memset( &cls, 0, sizeof(cls) );
12113 cls.lpfnWndProc = DefWindowProc;
12114 cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
12115 cls.hCursor = LoadCursor(0, IDC_ARROW);
12116 cls.lpszClassName = "TestClass";
12117 RegisterClass( &cls );
12119 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ); /* create the msg queue */
12121 ok( start_event != 0, "failed to create start event, error %u\n", GetLastError() );
12122 ok( end_event != 0, "failed to create end event, error %u\n", GetLastError() );
12124 switch (arg)
12126 case 0:
12127 SetEvent( start_event );
12128 break;
12129 case 1:
12130 SetEvent( start_event );
12131 Sleep( 200 );
12132 PeekMessage( &msg, 0, 0, 0, PM_REMOVE );
12133 break;
12134 case 2:
12135 SetEvent( start_event );
12136 Sleep( 200 );
12137 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12138 PostThreadMessage( GetCurrentThreadId(), WM_COMMAND, 0x1234, 0xabcd );
12139 PeekMessage( &msg, 0, 0, 0, PM_REMOVE );
12140 break;
12141 case 3:
12142 SetEvent( start_event );
12143 Sleep( 200 );
12144 SendMessage( HWND_BROADCAST, WM_WININICHANGE, 0, 0 );
12145 break;
12146 case 4:
12147 SetEvent( start_event );
12148 Sleep( 200 );
12149 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12150 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessage( &msg );
12151 break;
12152 case 5:
12153 SetEvent( start_event );
12154 Sleep( 200 );
12155 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12156 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12157 break;
12158 case 6:
12159 SetEvent( start_event );
12160 Sleep( 200 );
12161 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12162 while (PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ))
12164 GetMessage( &msg, 0, 0, 0 );
12165 DispatchMessage( &msg );
12167 break;
12168 case 7:
12169 SetEvent( start_event );
12170 Sleep( 200 );
12171 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12172 SetTimer( hwnd, 3, 1, NULL );
12173 Sleep( 200 );
12174 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessage( &msg );
12175 break;
12176 case 8:
12177 SetEvent( start_event );
12178 Sleep( 200 );
12179 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12180 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12181 break;
12182 case 9:
12183 SetEvent( start_event );
12184 Sleep( 200 );
12185 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12186 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12187 for (;;) GetMessage( &msg, 0, 0, 0 );
12188 break;
12189 case 10:
12190 SetEvent( start_event );
12191 Sleep( 200 );
12192 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12193 SetTimer( hwnd, 3, 1, NULL );
12194 Sleep( 200 );
12195 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12196 break;
12197 case 11:
12198 SetEvent( start_event );
12199 Sleep( 200 );
12200 return; /* exiting the process makes WaitForInputIdle return success too */
12201 case 12:
12202 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12203 Sleep( 200 );
12204 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12205 SetEvent( start_event );
12206 break;
12207 case 13:
12208 SetEvent( start_event );
12209 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12210 Sleep( 200 );
12211 thread = CreateThread( NULL, 0, do_wait_idle_child_thread, NULL, 0, &id );
12212 WaitForSingleObject( thread, 10000 );
12213 CloseHandle( thread );
12214 break;
12215 case 14:
12216 SetEvent( start_event );
12217 Sleep( 200 );
12218 PeekMessage( &msg, HWND_TOPMOST, 0, 0, PM_NOREMOVE );
12219 break;
12220 case 15:
12221 SetEvent( start_event );
12222 Sleep( 200 );
12223 PeekMessage( &msg, HWND_BROADCAST, 0, 0, PM_NOREMOVE );
12224 break;
12225 case 16:
12226 SetEvent( start_event );
12227 Sleep( 200 );
12228 PeekMessage( &msg, HWND_BOTTOM, 0, 0, PM_NOREMOVE );
12229 break;
12230 case 17:
12231 SetEvent( start_event );
12232 Sleep( 200 );
12233 PeekMessage( &msg, (HWND)0xdeadbeef, 0, 0, PM_NOREMOVE );
12234 break;
12235 case 18:
12236 SetEvent( start_event );
12237 Sleep( 200 );
12238 PeekMessage( &msg, HWND_NOTOPMOST, 0, 0, PM_NOREMOVE );
12239 break;
12240 case 19:
12241 SetEvent( start_event );
12242 Sleep( 200 );
12243 PeekMessage( &msg, HWND_MESSAGE, 0, 0, PM_NOREMOVE );
12244 break;
12245 case 20:
12246 SetEvent( start_event );
12247 Sleep( 200 );
12248 PeekMessage( &msg, GetDesktopWindow(), 0, 0, PM_NOREMOVE );
12249 break;
12251 WaitForSingleObject( end_event, 2000 );
12252 CloseHandle( start_event );
12253 CloseHandle( end_event );
12254 if (hwnd) DestroyWindow( hwnd );
12257 static LRESULT CALLBACK wait_idle_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
12259 if (msg == WM_WININICHANGE) Sleep( 200 ); /* make sure the child waits */
12260 return DefWindowProcA( hwnd, msg, wp, lp );
12263 static DWORD CALLBACK wait_idle_thread( void *arg )
12265 WNDCLASS cls;
12266 MSG msg;
12267 HWND hwnd;
12269 memset( &cls, 0, sizeof(cls) );
12270 cls.lpfnWndProc = wait_idle_proc;
12271 cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
12272 cls.hCursor = LoadCursor(0, IDC_ARROW);
12273 cls.lpszClassName = "TestClass";
12274 RegisterClass( &cls );
12276 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
12277 while (GetMessage( &msg, 0, 0, 0 )) DispatchMessage( &msg );
12278 return 0;
12281 static void test_WaitForInputIdle( char *argv0 )
12283 char path[MAX_PATH];
12284 PROCESS_INFORMATION pi;
12285 STARTUPINFOA startup;
12286 BOOL ret;
12287 HANDLE start_event, end_event, thread;
12288 unsigned int i;
12289 DWORD id;
12290 const IMAGE_DOS_HEADER *dos = (const IMAGE_DOS_HEADER *)GetModuleHandleA(0);
12291 const IMAGE_NT_HEADERS *nt = (const IMAGE_NT_HEADERS *)((const char *)dos + dos->e_lfanew);
12292 BOOL console_app = (nt->OptionalHeader.Subsystem != IMAGE_SUBSYSTEM_WINDOWS_GUI);
12294 if (console_app) /* build the test with -mwindows for better coverage */
12295 trace( "not built as a GUI app, WaitForInputIdle may not be fully tested\n" );
12297 start_event = CreateEventA(NULL, 0, 0, "test_WaitForInputIdle_start");
12298 end_event = CreateEventA(NULL, 0, 0, "test_WaitForInputIdle_end");
12299 ok(start_event != 0, "failed to create start event, error %u\n", GetLastError());
12300 ok(end_event != 0, "failed to create end event, error %u\n", GetLastError());
12302 memset( &startup, 0, sizeof(startup) );
12303 startup.cb = sizeof(startup);
12304 startup.dwFlags = STARTF_USESHOWWINDOW;
12305 startup.wShowWindow = SW_SHOWNORMAL;
12307 thread = CreateThread( NULL, 0, wait_idle_thread, NULL, 0, &id );
12309 for (i = 0; i < sizeof(wait_idle_expect)/sizeof(wait_idle_expect[0]); i++)
12311 ResetEvent( start_event );
12312 ResetEvent( end_event );
12313 sprintf( path, "%s msg %u", argv0, i );
12314 ret = CreateProcessA( NULL, path, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &pi );
12315 ok( ret, "CreateProcess '%s' failed err %u.\n", path, GetLastError() );
12316 if (ret)
12318 ret = WaitForSingleObject( start_event, 5000 );
12319 ok( ret == WAIT_OBJECT_0, "%u: WaitForSingleObject failed\n", i );
12320 if (ret == WAIT_OBJECT_0)
12322 ret = WaitForInputIdle( pi.hProcess, 1000 );
12323 if (ret == WAIT_FAILED)
12324 ok( console_app ||
12325 ret == wait_idle_expect[i].exp ||
12326 broken(ret == wait_idle_expect[i].broken),
12327 "%u: WaitForInputIdle error %08x expected %08x\n",
12328 i, ret, wait_idle_expect[i].exp );
12329 else if (wait_idle_expect[i].todo)
12330 todo_wine
12331 ok( ret == wait_idle_expect[i].exp || broken(ret == wait_idle_expect[i].broken),
12332 "%u: WaitForInputIdle error %08x expected %08x\n",
12333 i, ret, wait_idle_expect[i].exp );
12334 else
12335 ok( ret == wait_idle_expect[i].exp || broken(ret == wait_idle_expect[i].broken),
12336 "%u: WaitForInputIdle error %08x expected %08x\n",
12337 i, ret, wait_idle_expect[i].exp );
12338 SetEvent( end_event );
12339 WaitForSingleObject( pi.hProcess, 1000 ); /* give it a chance to exit on its own */
12341 TerminateProcess( pi.hProcess, 0 ); /* just in case */
12342 winetest_wait_child_process( pi.hProcess );
12343 ret = WaitForInputIdle( pi.hProcess, 100 );
12344 ok( ret == WAIT_FAILED, "%u: WaitForInputIdle after exit error %08x\n", i, ret );
12345 CloseHandle( pi.hProcess );
12346 CloseHandle( pi.hThread );
12349 CloseHandle( start_event );
12350 PostThreadMessage( id, WM_QUIT, 0, 0 );
12351 WaitForSingleObject( thread, 10000 );
12352 CloseHandle( thread );
12355 START_TEST(msg)
12357 char **test_argv;
12358 BOOL ret;
12359 BOOL (WINAPI *pIsWinEventHookInstalled)(DWORD)= 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
12361 int argc = winetest_get_mainargs( &test_argv );
12362 if (argc >= 3)
12364 unsigned int arg;
12365 /* Child process. */
12366 sscanf (test_argv[2], "%d", (unsigned int *) &arg);
12367 do_wait_idle_child( arg );
12368 return;
12371 init_procs();
12373 if (!RegisterWindowClasses()) assert(0);
12375 if (pSetWinEventHook)
12377 hEvent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX,
12378 GetModuleHandleA(0), win_event_proc,
12379 0, GetCurrentThreadId(),
12380 WINEVENT_INCONTEXT);
12381 if (pIsWinEventHookInstalled && hEvent_hook)
12383 UINT event;
12384 for (event = EVENT_MIN; event <= EVENT_MAX; event++)
12385 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
12388 if (!hEvent_hook) win_skip( "no win event hook support\n" );
12390 cbt_hook_thread_id = GetCurrentThreadId();
12391 hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
12392 if (!hCBT_hook) win_skip( "cannot set global hook, will skip hook tests\n" );
12394 test_winevents();
12396 /* Fix message sequences before removing 4 lines below */
12397 #if 1
12398 if (pUnhookWinEvent && hEvent_hook)
12400 ret = pUnhookWinEvent(hEvent_hook);
12401 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
12402 pUnhookWinEvent = 0;
12404 hEvent_hook = 0;
12405 #endif
12407 test_PostMessage();
12408 test_ShowWindow();
12409 test_PeekMessage();
12410 test_PeekMessage2();
12411 test_WaitForInputIdle( test_argv[0] );
12412 test_scrollwindowex();
12413 test_messages();
12414 test_setwindowpos();
12415 test_showwindow();
12416 invisible_parent_tests();
12417 test_mdi_messages();
12418 test_button_messages();
12419 test_static_messages();
12420 test_listbox_messages();
12421 test_combobox_messages();
12422 test_wmime_keydown_message();
12423 test_paint_messages();
12424 test_interthread_messages();
12425 test_message_conversion();
12426 test_accelerators();
12427 test_timers();
12428 test_timers_no_wnd();
12429 if (hCBT_hook) test_set_hook();
12430 test_DestroyWindow();
12431 test_DispatchMessage();
12432 test_SendMessageTimeout();
12433 test_edit_messages();
12434 test_quit_message();
12435 test_SetActiveWindow();
12437 if (!pTrackMouseEvent)
12438 win_skip("TrackMouseEvent is not available\n");
12439 else
12440 test_TrackMouseEvent();
12442 test_SetWindowRgn();
12443 test_sys_menu();
12444 test_dialog_messages();
12445 test_nullCallback();
12446 test_dbcs_wm_char();
12447 test_menu_messages();
12448 test_paintingloop();
12449 test_defwinproc();
12450 test_clipboard_viewers();
12451 /* keep it the last test, under Windows it tends to break the tests
12452 * which rely on active/foreground windows being correct.
12454 test_SetForegroundWindow();
12456 UnhookWindowsHookEx(hCBT_hook);
12457 if (pUnhookWinEvent && hEvent_hook)
12459 ret = pUnhookWinEvent(hEvent_hook);
12460 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
12461 SetLastError(0xdeadbeef);
12462 ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
12463 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
12464 GetLastError() == 0xdeadbeef, /* Win9x */
12465 "unexpected error %d\n", GetLastError());