push 6fe5edf8439c19d3885814583531c2f2b1495177
[wine/hacks.git] / dlls / user32 / tests / msg.c
blob98fa42494fd32483f733acc5746e251980a160b5
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 #include <assert.h>
24 #include <stdarg.h>
25 #include <stdio.h>
27 #define _WIN32_WINNT 0x0501 /* For WM_CHANGEUISTATE,QS_RAWINPUT */
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;
82 static void dump_winpos_flags(UINT flags);
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 */
117 /* Empty message sequence */
118 static const struct message WmEmptySeq[] =
120 { 0 }
122 /* CreateWindow (for overlapped window, not initially visible) (16/32) */
123 static const struct message WmCreateOverlappedSeq[] = {
124 { HCBT_CREATEWND, hook },
125 { WM_GETMINMAXINFO, sent },
126 { WM_NCCREATE, sent },
127 { WM_NCCALCSIZE, sent|wparam, 0 },
128 { 0x0093, sent|defwinproc|optional },
129 { 0x0094, sent|defwinproc|optional },
130 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
131 { WM_CREATE, sent },
132 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
133 { 0 }
135 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
136 * for a not visible overlapped window.
138 static const struct message WmSWP_ShowOverlappedSeq[] = {
139 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
140 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
141 { WM_NCPAINT, sent|wparam|optional, 1 },
142 { WM_GETTEXT, sent|defwinproc|optional },
143 { WM_ERASEBKGND, sent|optional },
144 { HCBT_ACTIVATE, hook },
145 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
146 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
147 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x: SWP_NOSENDCHANGING */
148 { WM_ACTIVATEAPP, sent|wparam, 1 },
149 { WM_NCACTIVATE, sent|wparam, 1 },
150 { WM_GETTEXT, sent|defwinproc|optional },
151 { WM_ACTIVATE, sent|wparam, 1 },
152 { HCBT_SETFOCUS, hook },
153 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
154 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
155 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
156 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
157 { WM_NCPAINT, sent|wparam|optional, 1 },
158 { WM_GETTEXT, sent|defwinproc|optional },
159 { WM_ERASEBKGND, sent|optional },
160 /* Win9x adds SWP_NOZORDER below */
161 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
162 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
163 { WM_NCPAINT, sent|wparam|optional, 1 },
164 { WM_ERASEBKGND, sent|optional },
165 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
166 { 0 }
168 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
169 * for a visible overlapped window.
171 static const struct message WmSWP_HideOverlappedSeq[] = {
172 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
173 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
174 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
175 { 0 }
178 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
179 * for a visible overlapped window.
181 static const struct message WmSWP_ResizeSeq[] = {
182 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
183 { WM_GETMINMAXINFO, sent|defwinproc },
184 { WM_NCCALCSIZE, sent|wparam, TRUE },
185 { WM_NCPAINT, sent|optional },
186 { WM_GETTEXT, sent|defwinproc|optional },
187 { WM_ERASEBKGND, sent|optional },
188 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
189 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
190 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
191 { WM_NCPAINT, sent|optional },
192 { WM_GETTEXT, sent|defwinproc|optional },
193 { WM_ERASEBKGND, sent|optional },
194 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
195 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
196 { 0 }
199 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
200 * for a visible popup window.
202 static const struct message WmSWP_ResizePopupSeq[] = {
203 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
204 { WM_GETMINMAXINFO, sent|defwinproc|optional }, /* Win9x */
205 { WM_NCCALCSIZE, sent|wparam, TRUE },
206 { WM_NCPAINT, sent|optional },
207 { WM_GETTEXT, sent|defwinproc|optional },
208 { WM_ERASEBKGND, sent|optional },
209 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
210 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
211 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
212 { WM_NCPAINT, sent|optional },
213 { WM_GETTEXT, sent|defwinproc|optional },
214 { WM_ERASEBKGND, sent|optional },
215 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
216 { 0 }
219 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
220 * for a visible overlapped window.
222 static const struct message WmSWP_MoveSeq[] = {
223 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE },
224 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
225 { WM_MOVE, sent|defwinproc|wparam, 0 },
226 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
227 { 0 }
229 /* Resize with SetWindowPos(SWP_NOZORDER)
230 * for a visible overlapped window
231 * SWP_NOZORDER is stripped by the logging code
233 static const struct message WmSWP_ResizeNoZOrder[] = {
234 { WM_WINDOWPOSCHANGING, sent|wparam, 0/*SWP_NOZORDER*/ },
235 { WM_GETMINMAXINFO, sent|defwinproc },
236 { WM_NCCALCSIZE, sent|wparam, 1 },
237 { WM_NCPAINT, sent },
238 { WM_GETTEXT, sent|defwinproc|optional },
239 { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
240 { WM_WINDOWPOSCHANGED, sent|wparam, /*SWP_NOZORDER|*/SWP_NOMOVE|SWP_NOCLIENTMOVE },
241 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
242 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
243 { WM_NCPAINT, sent|optional }, /* Win9x doesn't send it */
244 { WM_GETTEXT, sent|defwinproc|optional }, /* Win9x doesn't send it */
245 { WM_ERASEBKGND, sent|optional }, /* Win9x doesn't send it */
246 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
247 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
248 { 0 }
251 /* Switch visible mdi children */
252 static const struct message WmSwitchChild[] = {
253 /* Switch MDI child */
254 { WM_MDIACTIVATE, sent },/* in the MDI client */
255 { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 1st MDI child */
256 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
257 { WM_CHILDACTIVATE, sent },/* in the 1st MDI child */
258 /* Deactivate 2nd MDI child */
259 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
260 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
261 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
262 /* Preparing for maximize and maximaze the 1st MDI child */
263 { WM_GETMINMAXINFO, sent|defwinproc }, /* in the 1st MDI child */
264 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED }, /* in the 1st MDI child */
265 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
266 { WM_CHILDACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
267 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 1st MDI child */
268 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED }, /* in the 1st MDI child */
269 /* Lock redraw 2nd MDI child */
270 { WM_SETREDRAW, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
271 { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
272 /* Restore 2nd MDI child */
273 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },/* in the 2nd MDI child */
274 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
275 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
276 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 2nd MDI child */
277 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED }, /* in the 2nd MDI child */
278 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
279 /* Redraw 2nd MDI child */
280 { WM_SETREDRAW, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
281 /* Redraw MDI frame */
282 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },/* in MDI frame */
283 { WM_NCCALCSIZE, sent|wparam, 1 },/* in MDI frame */
284 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in MDI frame */
285 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in MDI frame */
286 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
287 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
288 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
289 { HCBT_SETFOCUS, hook },
290 { WM_KILLFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
291 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },/* in the 1st MDI child */
292 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
293 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
294 { WM_SETFOCUS, sent },/* in the MDI client */
295 { HCBT_SETFOCUS, hook },
296 { WM_KILLFOCUS, sent },/* in the MDI client */
297 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
298 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 }, /* in the 1st MDI child */
299 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
300 { WM_SETFOCUS, sent|defwinproc }, /* in the 1st MDI child */
301 { WM_MDIACTIVATE, sent|defwinproc },/* in the 1st MDI child */
302 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* in the 1st MDI child */
303 { 0 }
306 /* Switch visible not maximized mdi children */
307 static const struct message WmSwitchNotMaximizedChild[] = {
308 /* Switch not maximized MDI child */
309 { WM_MDIACTIVATE, sent },/* in the MDI client */
310 { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 2nd MDI child */
311 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
312 { WM_CHILDACTIVATE, sent },/* in the 2nd MDI child */
313 /* Deactivate 1st MDI child */
314 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
315 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
316 /* Activate 2nd MDI child */
317 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE}, /* in the 2nd MDI child */
318 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 2nd MDI child */
319 { WM_SETVISIBLE, hook }, /* in the 1st MDI child */
320 { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
321 { WM_IME_SETCONTEXT, sent|defwinproc }, /* in the 1st MDI child */
322 { WM_IME_SETCONTEXT, sent }, /* in the MDI client */
323 { WM_SETFOCUS, sent, 0 }, /* in the MDI client */
324 { WM_SETVISIBLE, hook },
325 { WM_KILLFOCUS, sent }, /* in the MDI client */
326 { WM_IME_SETCONTEXT, sent }, /* in the MDI client */
327 { WM_IME_SETCONTEXT, sent|defwinproc }, /* in the 1st MDI child */
328 { WM_SETFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
329 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
330 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in the 2nd MDI child */
331 { 0 }
335 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
336 SWP_NOZORDER|SWP_FRAMECHANGED)
337 * for a visible overlapped window with WS_CLIPCHILDREN style set.
339 static const struct message WmSWP_FrameChanged_clip[] = {
340 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
341 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
342 { WM_NCPAINT, sent|parent }, /* wparam != 1 */
343 { WM_GETTEXT, sent|parent|defwinproc|optional },
344 { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
345 { WM_NCPAINT, sent }, /* wparam != 1 */
346 { WM_ERASEBKGND, sent },
347 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
348 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
349 { WM_PAINT, sent },
350 { 0 }
352 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|
353 SWP_NOZORDER|SWP_FRAMECHANGED)
354 * for a visible overlapped window.
356 static const struct message WmSWP_FrameChangedDeferErase[] = {
357 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
358 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
359 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
360 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
361 { WM_PAINT, sent|parent },
362 { WM_NCPAINT, sent|beginpaint|parent }, /* wparam != 1 */
363 { WM_GETTEXT, sent|beginpaint|parent|defwinproc|optional },
364 { WM_PAINT, sent },
365 { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
366 { WM_ERASEBKGND, sent|beginpaint },
367 { 0 }
370 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
371 SWP_NOZORDER|SWP_FRAMECHANGED)
372 * for a visible overlapped window without WS_CLIPCHILDREN style set.
374 static const struct message WmSWP_FrameChanged_noclip[] = {
375 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
376 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
377 { WM_NCPAINT, sent|parent }, /* wparam != 1 */
378 { WM_GETTEXT, sent|parent|defwinproc|optional },
379 { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
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 { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
384 { WM_ERASEBKGND, sent|beginpaint },
385 { 0 }
388 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
389 static const struct message WmShowOverlappedSeq[] = {
390 { WM_SHOWWINDOW, sent|wparam, 1 },
391 { WM_NCPAINT, sent|wparam|optional, 1 },
392 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
393 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
394 { WM_NCPAINT, sent|wparam|optional, 1 },
395 { WM_GETTEXT, sent|defwinproc|optional },
396 { WM_ERASEBKGND, sent|optional },
397 { HCBT_ACTIVATE, hook },
398 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
399 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
400 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
401 { WM_NCPAINT, sent|wparam|optional, 1 },
402 { WM_ACTIVATEAPP, sent|wparam, 1 },
403 { WM_NCACTIVATE, sent|wparam, 1 },
404 { WM_GETTEXT, sent|defwinproc|optional },
405 { WM_ACTIVATE, sent|wparam, 1 },
406 { HCBT_SETFOCUS, hook },
407 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
408 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
409 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
410 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
411 { WM_NCPAINT, sent|wparam|optional, 1 },
412 { WM_GETTEXT, sent|defwinproc|optional },
413 { WM_ERASEBKGND, sent|optional },
414 /* Win9x adds SWP_NOZORDER below */
415 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
416 { WM_NCCALCSIZE, sent|optional },
417 { WM_NCPAINT, sent|optional },
418 { WM_ERASEBKGND, sent|optional },
419 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
420 * messages. Does that mean that CreateWindow doesn't set initial
421 * window dimensions for overlapped windows?
423 { WM_SIZE, sent },
424 { WM_MOVE, sent },
425 #endif
426 { 0 }
428 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible overlapped window */
429 static const struct message WmShowMaxOverlappedSeq[] = {
430 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
431 { WM_GETMINMAXINFO, sent },
432 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
433 { WM_GETMINMAXINFO, sent|defwinproc },
434 { WM_NCCALCSIZE, sent|wparam, TRUE },
435 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
436 { HCBT_ACTIVATE, hook },
437 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
438 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
439 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
440 { WM_ACTIVATEAPP, sent|wparam, 1 },
441 { WM_NCACTIVATE, sent|wparam, 1 },
442 { WM_GETTEXT, sent|defwinproc|optional },
443 { WM_ACTIVATE, sent|wparam, 1 },
444 { HCBT_SETFOCUS, hook },
445 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
446 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
447 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
448 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
449 { WM_NCPAINT, sent|wparam|optional, 1 },
450 { WM_GETTEXT, sent|defwinproc|optional },
451 { WM_ERASEBKGND, sent|optional },
452 /* Win9x adds SWP_NOZORDER below */
453 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
454 { WM_MOVE, sent|defwinproc },
455 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
456 { WM_NCCALCSIZE, sent|optional },
457 { WM_NCPAINT, sent|optional },
458 { WM_ERASEBKGND, sent|optional },
459 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
460 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
461 { 0 }
463 /* ShowWindow(SW_SHOWMINIMIZED) for a not visible overlapped window */
464 static const struct message WmShowMinOverlappedSeq[] = {
465 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
466 { HCBT_SETFOCUS, hook },
467 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
468 { WM_KILLFOCUS, sent },
469 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
470 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
471 { WM_GETTEXT, sent|optional },
472 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCOPYBITS|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
473 { WM_GETMINMAXINFO, sent|defwinproc },
474 { WM_NCCALCSIZE, sent|wparam, TRUE },
475 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
476 { WM_NCPAINT, sent },
477 { WM_GETTEXT, sent|defwinproc|optional },
478 { WM_WINDOWPOSCHANGED, sent },
479 { WM_MOVE, sent|defwinproc },
480 { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
481 { WM_NCCALCSIZE, sent|optional },
482 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
483 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
484 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
485 { WM_NCACTIVATE, sent|wparam, 0 },
486 { WM_GETTEXT, sent|defwinproc|optional },
487 { WM_ACTIVATE, sent },
488 { WM_ACTIVATEAPP, sent|wparam, 0 },
489 { 0 }
491 /* ShowWindow(SW_HIDE) for a visible overlapped window */
492 static const struct message WmHideOverlappedSeq[] = {
493 { WM_SHOWWINDOW, sent|wparam, 0 },
494 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
495 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
496 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
497 { WM_SIZE, sent|optional }, /* XP doesn't send it */
498 { WM_MOVE, sent|optional }, /* XP doesn't send it */
499 { WM_NCACTIVATE, sent|wparam, 0 },
500 { WM_ACTIVATE, sent|wparam, 0 },
501 { WM_ACTIVATEAPP, sent|wparam, 0 },
502 { WM_KILLFOCUS, sent|wparam, 0 },
503 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
504 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
505 { 0 }
507 /* DestroyWindow for a visible overlapped window */
508 static const struct message WmDestroyOverlappedSeq[] = {
509 { HCBT_DESTROYWND, hook },
510 { 0x0090, sent|optional },
511 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
512 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
513 { 0x0090, sent|optional },
514 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
515 { WM_NCACTIVATE, sent|wparam, 0 },
516 { WM_ACTIVATE, sent|wparam, 0 },
517 { WM_ACTIVATEAPP, sent|wparam, 0 },
518 { WM_KILLFOCUS, sent|wparam, 0 },
519 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
520 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
521 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
522 { WM_DESTROY, sent },
523 { WM_NCDESTROY, sent },
524 { 0 }
526 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
527 static const struct message WmCreateMaxPopupSeq[] = {
528 { HCBT_CREATEWND, hook },
529 { WM_NCCREATE, sent },
530 { WM_NCCALCSIZE, sent|wparam, 0 },
531 { WM_CREATE, sent },
532 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
533 { WM_SIZE, sent|wparam, SIZE_RESTORED },
534 { WM_MOVE, sent },
535 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
536 { WM_GETMINMAXINFO, sent },
537 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
538 { WM_NCCALCSIZE, sent|wparam, TRUE },
539 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
540 { WM_MOVE, sent|defwinproc },
541 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
542 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
543 { WM_SHOWWINDOW, sent|wparam, 1 },
544 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
545 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
546 { HCBT_ACTIVATE, hook },
547 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
548 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
549 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
550 { WM_ACTIVATEAPP, sent|wparam, 1 },
551 { WM_NCACTIVATE, sent|wparam, 1 },
552 { WM_ACTIVATE, sent|wparam, 1 },
553 { HCBT_SETFOCUS, hook },
554 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
555 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
556 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
557 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
558 { WM_SYNCPAINT, sent|wparam|optional, 4 },
559 { WM_NCPAINT, sent|wparam|optional, 1 },
560 { WM_ERASEBKGND, sent|optional },
561 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
562 { 0 }
564 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
565 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
566 { HCBT_CREATEWND, hook },
567 { WM_NCCREATE, sent },
568 { WM_NCCALCSIZE, sent|wparam, 0 },
569 { WM_CREATE, sent },
570 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
571 { WM_SIZE, sent|wparam, SIZE_RESTORED },
572 { WM_MOVE, sent },
573 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
574 { WM_GETMINMAXINFO, sent },
575 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
576 { WM_NCCALCSIZE, sent|wparam, TRUE },
577 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
578 { WM_MOVE, sent|defwinproc },
579 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
580 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
581 { 0 }
583 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
584 static const struct message WmShowMaxPopupResizedSeq[] = {
585 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
586 { WM_GETMINMAXINFO, sent },
587 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
588 { WM_NCCALCSIZE, sent|wparam, TRUE },
589 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
590 { HCBT_ACTIVATE, hook },
591 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
592 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
593 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
594 { WM_ACTIVATEAPP, sent|wparam, 1 },
595 { WM_NCACTIVATE, sent|wparam, 1 },
596 { WM_ACTIVATE, sent|wparam, 1 },
597 { HCBT_SETFOCUS, hook },
598 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
599 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
600 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
601 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
602 { WM_NCPAINT, sent|wparam|optional, 1 },
603 { WM_ERASEBKGND, sent|optional },
604 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE },
605 /* WinNT4.0 sends WM_MOVE */
606 { WM_MOVE, sent|defwinproc|optional },
607 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
608 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
609 { 0 }
611 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
612 static const struct message WmShowMaxPopupSeq[] = {
613 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
614 { WM_GETMINMAXINFO, sent },
615 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
616 { WM_NCCALCSIZE, sent|wparam, TRUE },
617 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
618 { HCBT_ACTIVATE, hook },
619 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
620 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
621 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
622 { WM_ACTIVATEAPP, sent|wparam, 1 },
623 { WM_NCACTIVATE, sent|wparam, 1 },
624 { WM_ACTIVATE, sent|wparam, 1 },
625 { HCBT_SETFOCUS, hook },
626 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
627 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
628 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
629 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
630 { WM_SYNCPAINT, sent|wparam|optional, 4 },
631 { WM_NCPAINT, sent|wparam|optional, 1 },
632 { WM_ERASEBKGND, sent|optional },
633 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
634 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
635 { 0 }
637 /* CreateWindow(WS_VISIBLE) for popup window */
638 static const struct message WmCreatePopupSeq[] = {
639 { HCBT_CREATEWND, hook },
640 { WM_NCCREATE, sent },
641 { WM_NCCALCSIZE, sent|wparam, 0 },
642 { WM_CREATE, sent },
643 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
644 { WM_SIZE, sent|wparam, SIZE_RESTORED },
645 { WM_MOVE, sent },
646 { WM_SHOWWINDOW, sent|wparam, 1 },
647 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
648 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
649 { HCBT_ACTIVATE, hook },
650 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
651 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
652 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
653 { WM_NCPAINT, sent|wparam|optional, 1 },
654 { WM_ERASEBKGND, sent|optional },
655 { WM_ACTIVATEAPP, sent|wparam, 1 },
656 { WM_NCACTIVATE, sent|wparam, 1 },
657 { WM_ACTIVATE, sent|wparam, 1 },
658 { HCBT_SETFOCUS, hook },
659 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
660 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
661 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
662 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
663 { WM_SYNCPAINT, sent|wparam|optional, 4 },
664 { WM_NCPAINT, sent|wparam|optional, 1 },
665 { WM_ERASEBKGND, sent|optional },
666 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
667 { 0 }
669 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
670 static const struct message WmShowVisMaxPopupSeq[] = {
671 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
672 { WM_GETMINMAXINFO, sent },
673 { WM_GETTEXT, sent|optional },
674 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
675 { WM_NCCALCSIZE, sent|wparam, TRUE },
676 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
677 { WM_NCPAINT, sent|wparam|optional, 1 },
678 { WM_ERASEBKGND, sent|optional },
679 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
680 { WM_MOVE, sent|defwinproc },
681 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
682 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
683 { 0 }
685 /* CreateWindow (for a child popup window, not initially visible) */
686 static const struct message WmCreateChildPopupSeq[] = {
687 { HCBT_CREATEWND, hook },
688 { WM_NCCREATE, sent },
689 { WM_NCCALCSIZE, sent|wparam, 0 },
690 { WM_CREATE, sent },
691 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
692 { WM_SIZE, sent|wparam, SIZE_RESTORED },
693 { WM_MOVE, sent },
694 { 0 }
696 /* CreateWindow (for a popup window, not initially visible,
697 * which sets WS_VISIBLE in WM_CREATE handler)
699 static const struct message WmCreateInvisiblePopupSeq[] = {
700 { HCBT_CREATEWND, hook },
701 { WM_NCCREATE, sent },
702 { WM_NCCALCSIZE, sent|wparam, 0 },
703 { WM_CREATE, sent },
704 { WM_STYLECHANGING, sent },
705 { WM_STYLECHANGED, sent },
706 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
707 { WM_SIZE, sent|wparam, SIZE_RESTORED },
708 { WM_MOVE, sent },
709 { 0 }
711 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
712 * for a popup window with WS_VISIBLE style set
714 static const struct message WmShowVisiblePopupSeq_2[] = {
715 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
716 { 0 }
718 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
719 * for a popup window with WS_VISIBLE style set
721 static const struct message WmShowVisiblePopupSeq_3[] = {
722 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
723 { HCBT_ACTIVATE, hook },
724 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
725 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
726 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
727 { WM_NCACTIVATE, sent|wparam, 1 },
728 { WM_ACTIVATE, sent|wparam, 1 },
729 { HCBT_SETFOCUS, hook },
730 { WM_KILLFOCUS, sent|parent },
731 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
732 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
733 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
734 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
735 { WM_SETFOCUS, sent|defwinproc },
736 { 0 }
738 /* CreateWindow (for child window, not initially visible) */
739 static const struct message WmCreateChildSeq[] = {
740 { HCBT_CREATEWND, hook },
741 { WM_NCCREATE, sent },
742 /* child is inserted into parent's child list after WM_NCCREATE returns */
743 { WM_NCCALCSIZE, sent|wparam, 0 },
744 { WM_CREATE, sent },
745 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
746 { WM_SIZE, sent|wparam, SIZE_RESTORED },
747 { WM_MOVE, sent },
748 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
749 { 0 }
751 /* CreateWindow (for maximized child window, not initially visible) */
752 static const struct message WmCreateMaximizedChildSeq[] = {
753 { HCBT_CREATEWND, hook },
754 { WM_NCCREATE, sent },
755 { WM_NCCALCSIZE, sent|wparam, 0 },
756 { WM_CREATE, sent },
757 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
758 { WM_SIZE, sent|wparam, SIZE_RESTORED },
759 { WM_MOVE, sent },
760 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
761 { WM_GETMINMAXINFO, sent },
762 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
763 { WM_NCCALCSIZE, sent|wparam, 1 },
764 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
765 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
766 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
767 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
768 { 0 }
770 /* CreateWindow (for a child window, initially visible) */
771 static const struct message WmCreateVisibleChildSeq[] = {
772 { HCBT_CREATEWND, hook },
773 { WM_NCCREATE, sent },
774 /* child is inserted into parent's child list after WM_NCCREATE returns */
775 { WM_NCCALCSIZE, sent|wparam, 0 },
776 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
777 { WM_CREATE, sent },
778 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
779 { WM_SIZE, sent|wparam, SIZE_RESTORED },
780 { WM_MOVE, sent },
781 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
782 { WM_SHOWWINDOW, sent|wparam, 1 },
783 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
784 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
785 { WM_ERASEBKGND, sent|parent|optional },
786 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
787 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
788 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
789 { 0 }
791 /* ShowWindow(SW_SHOW) for a not visible child window */
792 static const struct message WmShowChildSeq[] = {
793 { WM_SHOWWINDOW, sent|wparam, 1 },
794 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
795 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
796 { WM_ERASEBKGND, sent|parent|optional },
797 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
798 { 0 }
800 /* ShowWindow(SW_HIDE) for a visible child window */
801 static const struct message WmHideChildSeq[] = {
802 { WM_SHOWWINDOW, sent|wparam, 0 },
803 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
804 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
805 { WM_ERASEBKGND, sent|parent|optional },
806 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
807 { 0 }
809 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
810 static const struct message WmHideChildSeq2[] = {
811 { WM_SHOWWINDOW, sent|wparam, 0 },
812 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
813 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
814 { WM_ERASEBKGND, sent|parent },
815 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
816 { 0 }
818 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
819 * for a not visible child window
821 static const struct message WmShowChildSeq_2[] = {
822 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
823 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
824 { WM_CHILDACTIVATE, sent },
825 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
826 { 0 }
828 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
829 * for a not visible child window
831 static const struct message WmShowChildSeq_3[] = {
832 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
833 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
834 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
835 { 0 }
837 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
838 * for a visible child window with a caption
840 static const struct message WmShowChildSeq_4[] = {
841 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
842 { WM_CHILDACTIVATE, sent },
843 { 0 }
845 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
846 static const struct message WmShowChildInvisibleParentSeq_1[] = {
847 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
848 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
849 { WM_NCCALCSIZE, sent|wparam, 1 },
850 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
851 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
852 { WM_MOVE, sent|defwinproc },
853 { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
854 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
855 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
856 /* FIXME: Wine creates an icon/title window while Windows doesn't */
857 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
858 { WM_GETTEXT, sent|optional },
859 { 0 }
861 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
862 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
863 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
864 { 0 }
866 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
867 static const struct message WmShowChildInvisibleParentSeq_2[] = {
868 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
869 { WM_GETMINMAXINFO, sent },
870 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
871 { WM_NCCALCSIZE, sent|wparam, 1 },
872 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
873 { WM_CHILDACTIVATE, sent },
874 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
875 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
876 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
877 { 0 }
879 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
880 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
881 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
882 { 0 }
884 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
885 static const struct message WmShowChildInvisibleParentSeq_3[] = {
886 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
887 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
888 { WM_NCCALCSIZE, sent|wparam, 1 },
889 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
890 { WM_CHILDACTIVATE, sent },
891 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
892 { WM_MOVE, sent|defwinproc },
893 { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
894 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
895 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
896 /* FIXME: Wine creates an icon/title window while Windows doesn't */
897 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
898 { WM_GETTEXT, sent|optional },
899 { 0 }
901 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
902 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
903 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
904 { 0 }
906 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
907 static const struct message WmShowChildInvisibleParentSeq_4[] = {
908 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
909 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
910 { WM_NCCALCSIZE, sent|wparam, 1 },
911 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
912 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
913 { WM_MOVE, sent|defwinproc },
914 { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
915 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
916 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
917 /* FIXME: Wine creates an icon/title window while Windows doesn't */
918 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
919 { WM_GETTEXT, sent|optional },
920 { 0 }
922 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
923 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
924 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
925 { 0 }
927 /* ShowWindow(SW_SHOW) for child with invisible parent */
928 static const struct message WmShowChildInvisibleParentSeq_5[] = {
929 { WM_SHOWWINDOW, sent|wparam, 1 },
930 { 0 }
932 /* ShowWindow(SW_HIDE) for child with invisible parent */
933 static const struct message WmHideChildInvisibleParentSeq[] = {
934 { WM_SHOWWINDOW, sent|wparam, 0 },
935 { 0 }
937 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
938 static const struct message WmShowChildInvisibleParentSeq_6[] = {
939 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
940 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
941 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
942 { 0 }
944 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
945 static const struct message WmHideChildInvisibleParentSeq_2[] = {
946 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
947 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
948 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
949 { 0 }
951 /* DestroyWindow for a visible child window */
952 static const struct message WmDestroyChildSeq[] = {
953 { HCBT_DESTROYWND, hook },
954 { 0x0090, sent|optional },
955 { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
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 { HCBT_SETFOCUS, hook }, /* set focus to a parent */
962 { WM_KILLFOCUS, sent },
963 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
964 { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
965 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
966 { WM_SETFOCUS, sent|parent },
967 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
968 { WM_DESTROY, sent },
969 { WM_DESTROY, sent|optional }, /* some other (IME?) window */
970 { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
971 { WM_NCDESTROY, sent },
972 { 0 }
974 /* DestroyWindow for a visible child window with invisible parent */
975 static const struct message WmDestroyInvisibleChildSeq[] = {
976 { HCBT_DESTROYWND, hook },
977 { 0x0090, sent|optional },
978 { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
979 { WM_SHOWWINDOW, sent|wparam, 0 },
980 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
981 { WM_DESTROY, sent },
982 { WM_NCDESTROY, sent },
983 { 0 }
985 /* Moving the mouse in nonclient area */
986 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
987 { WM_NCHITTEST, sent },
988 { WM_SETCURSOR, sent },
989 { WM_NCMOUSEMOVE, posted },
990 { 0 }
992 /* Moving the mouse in client area */
993 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
994 { WM_NCHITTEST, sent },
995 { WM_SETCURSOR, sent },
996 { WM_MOUSEMOVE, posted },
997 { 0 }
999 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1000 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
1001 { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
1002 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
1003 { WM_GETMINMAXINFO, sent|defwinproc },
1004 { WM_ENTERSIZEMOVE, sent|defwinproc },
1005 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1006 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1007 { WM_MOVE, sent|defwinproc },
1008 { WM_EXITSIZEMOVE, sent|defwinproc },
1009 { 0 }
1011 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1012 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
1013 { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
1014 { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
1015 { WM_GETMINMAXINFO, sent|defwinproc },
1016 { WM_ENTERSIZEMOVE, sent|defwinproc },
1017 { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
1018 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1019 { WM_GETMINMAXINFO, sent|defwinproc },
1020 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1021 { WM_NCPAINT, sent|defwinproc|wparam, 1 },
1022 { WM_GETTEXT, sent|defwinproc },
1023 { WM_ERASEBKGND, sent|defwinproc },
1024 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1025 { WM_MOVE, sent|defwinproc },
1026 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1027 { WM_EXITSIZEMOVE, sent|defwinproc },
1028 { 0 }
1030 /* Resizing child window with MoveWindow (32) */
1031 static const struct message WmResizingChildWithMoveWindowSeq[] = {
1032 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1033 { WM_NCCALCSIZE, sent|wparam, 1 },
1034 { WM_ERASEBKGND, sent|parent|optional },
1035 { WM_ERASEBKGND, sent|optional },
1036 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
1037 { WM_MOVE, sent|defwinproc },
1038 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1039 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1040 { 0 }
1042 /* Clicking on inactive button */
1043 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
1044 { WM_NCHITTEST, sent },
1045 { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
1046 { WM_MOUSEACTIVATE, sent },
1047 { WM_MOUSEACTIVATE, sent|parent|defwinproc },
1048 { WM_SETCURSOR, sent },
1049 { WM_SETCURSOR, sent|parent|defwinproc },
1050 { WM_LBUTTONDOWN, posted },
1051 { WM_KILLFOCUS, posted|parent },
1052 { WM_SETFOCUS, posted },
1053 { WM_CTLCOLORBTN, posted|parent },
1054 { BM_SETSTATE, posted },
1055 { WM_CTLCOLORBTN, posted|parent },
1056 { WM_LBUTTONUP, posted },
1057 { BM_SETSTATE, posted },
1058 { WM_CTLCOLORBTN, posted|parent },
1059 { WM_COMMAND, posted|parent },
1060 { 0 }
1062 /* Reparenting a button (16/32) */
1063 /* The last child (button) reparented gets topmost for its new parent. */
1064 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
1065 { WM_SHOWWINDOW, sent|wparam, 0 },
1066 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1067 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1068 { WM_ERASEBKGND, sent|parent },
1069 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1070 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
1071 { WM_CHILDACTIVATE, sent },
1072 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
1073 { WM_MOVE, sent|defwinproc },
1074 { WM_SHOWWINDOW, sent|wparam, 1 },
1075 { 0 }
1077 /* Creation of a custom dialog (32) */
1078 static const struct message WmCreateCustomDialogSeq[] = {
1079 { HCBT_CREATEWND, hook },
1080 { WM_GETMINMAXINFO, sent },
1081 { WM_NCCREATE, sent },
1082 { WM_NCCALCSIZE, sent|wparam, 0 },
1083 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1084 { WM_CREATE, sent },
1085 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1086 { WM_SHOWWINDOW, sent|wparam, 1 },
1087 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1088 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1089 { HCBT_ACTIVATE, hook },
1090 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1093 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1095 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1097 { WM_NCACTIVATE, sent|wparam, 1 },
1098 { WM_GETTEXT, sent|optional|defwinproc },
1099 { WM_GETTEXT, sent|optional|defwinproc },
1100 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1101 { WM_ACTIVATE, sent|wparam, 1 },
1102 { WM_KILLFOCUS, sent|parent },
1103 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1104 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1105 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1106 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1107 { WM_SETFOCUS, sent },
1108 { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1109 { WM_NCPAINT, sent|wparam, 1 },
1110 { WM_GETTEXT, sent|optional|defwinproc },
1111 { WM_GETTEXT, sent|optional|defwinproc },
1112 { WM_ERASEBKGND, sent },
1113 { WM_CTLCOLORDLG, sent|defwinproc },
1114 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1115 { WM_GETTEXT, sent|optional },
1116 { WM_GETTEXT, sent|optional },
1117 { WM_NCCALCSIZE, sent|optional },
1118 { WM_NCPAINT, sent|optional },
1119 { WM_GETTEXT, sent|optional|defwinproc },
1120 { WM_GETTEXT, sent|optional|defwinproc },
1121 { WM_ERASEBKGND, sent|optional },
1122 { WM_CTLCOLORDLG, sent|optional|defwinproc },
1123 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1124 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1125 { WM_MOVE, sent },
1126 { 0 }
1128 /* Calling EndDialog for a custom dialog (32) */
1129 static const struct message WmEndCustomDialogSeq[] = {
1130 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1131 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1132 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1133 { WM_GETTEXT, sent|optional },
1134 { HCBT_ACTIVATE, hook },
1135 { WM_NCACTIVATE, sent|wparam, 0 },
1136 { WM_GETTEXT, sent|optional|defwinproc },
1137 { WM_GETTEXT, sent|optional|defwinproc },
1138 { WM_ACTIVATE, sent|wparam, 0 },
1139 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1140 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1141 { HCBT_SETFOCUS, hook },
1142 { WM_KILLFOCUS, sent },
1143 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1144 { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1145 { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1146 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1147 { WM_SETFOCUS, sent|parent|defwinproc },
1148 { 0 }
1150 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1151 static const struct message WmShowCustomDialogSeq[] = {
1152 { WM_SHOWWINDOW, sent|wparam, 1 },
1153 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1154 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1155 { HCBT_ACTIVATE, hook },
1156 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1158 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1160 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1161 { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1162 { WM_NCACTIVATE, sent|wparam, 1 },
1163 { WM_ACTIVATE, sent|wparam, 1 },
1165 { WM_KILLFOCUS, sent|parent },
1166 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1167 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1168 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1169 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1170 { WM_SETFOCUS, sent },
1171 { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1172 { WM_NCPAINT, sent|wparam, 1 },
1173 { WM_ERASEBKGND, sent },
1174 { WM_CTLCOLORDLG, sent|defwinproc },
1175 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1176 { 0 }
1178 /* Creation and destruction of a modal dialog (32) */
1179 static const struct message WmModalDialogSeq[] = {
1180 { WM_CANCELMODE, sent|parent },
1181 { HCBT_SETFOCUS, hook },
1182 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1183 { WM_KILLFOCUS, sent|parent },
1184 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1185 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1186 { WM_ENABLE, sent|parent|wparam, 0 },
1187 { HCBT_CREATEWND, hook },
1188 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1189 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1190 { WM_SETFONT, sent },
1191 { WM_INITDIALOG, sent },
1192 { WM_CHANGEUISTATE, sent|optional },
1193 { WM_UPDATEUISTATE, sent|optional },
1194 { WM_SHOWWINDOW, sent },
1195 { HCBT_ACTIVATE, hook },
1196 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1197 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1198 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1199 { WM_NCACTIVATE, sent|wparam, 1 },
1200 { WM_GETTEXT, sent|optional },
1201 { WM_ACTIVATE, sent|wparam, 1 },
1202 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1203 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1204 { WM_NCPAINT, sent },
1205 { WM_GETTEXT, sent|optional },
1206 { WM_ERASEBKGND, sent },
1207 { WM_CTLCOLORDLG, sent },
1208 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1209 { WM_GETTEXT, sent|optional },
1210 { WM_NCCALCSIZE, sent|optional },
1211 { WM_NCPAINT, sent|optional },
1212 { WM_GETTEXT, sent|optional },
1213 { WM_ERASEBKGND, sent|optional },
1214 { WM_CTLCOLORDLG, sent|optional },
1215 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1216 { WM_PAINT, sent|optional },
1217 { WM_CTLCOLORBTN, sent },
1218 { WM_ENTERIDLE, sent|parent|optional },
1219 { WM_ENTERIDLE, sent|parent|optional },
1220 { WM_ENTERIDLE, sent|parent|optional },
1221 { WM_ENTERIDLE, sent|parent|optional },
1222 { WM_ENTERIDLE, sent|parent|optional },
1223 { WM_ENTERIDLE, sent|parent|optional },
1224 { WM_ENTERIDLE, sent|parent|optional },
1225 { WM_ENTERIDLE, sent|parent|optional },
1226 { WM_ENTERIDLE, sent|parent|optional },
1227 { WM_ENTERIDLE, sent|parent|optional },
1228 { WM_ENTERIDLE, sent|parent|optional },
1229 { WM_ENTERIDLE, sent|parent|optional },
1230 { WM_ENTERIDLE, sent|parent|optional },
1231 { WM_ENTERIDLE, sent|parent|optional },
1232 { WM_ENTERIDLE, sent|parent|optional },
1233 { WM_ENTERIDLE, sent|parent|optional },
1234 { WM_ENTERIDLE, sent|parent|optional },
1235 { WM_ENTERIDLE, sent|parent|optional },
1236 { WM_ENTERIDLE, sent|parent|optional },
1237 { WM_ENTERIDLE, sent|parent|optional },
1238 { WM_TIMER, sent },
1239 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1240 { WM_ENABLE, sent|parent|wparam, 1 },
1241 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1242 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1243 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1244 { WM_GETTEXT, sent|optional },
1245 { HCBT_ACTIVATE, hook },
1246 { WM_NCACTIVATE, sent|wparam, 0 },
1247 { WM_GETTEXT, sent|optional },
1248 { WM_ACTIVATE, sent|wparam, 0 },
1249 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1250 { WM_WINDOWPOSCHANGING, sent|optional },
1251 { HCBT_SETFOCUS, hook },
1252 { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1253 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1254 { WM_SETFOCUS, sent|parent|defwinproc },
1255 { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1256 { HCBT_DESTROYWND, hook },
1257 { 0x0090, sent|optional },
1258 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1259 { WM_DESTROY, sent },
1260 { WM_NCDESTROY, sent },
1261 { 0 }
1263 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1264 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1265 /* (inside dialog proc, handling WM_INITDIALOG) */
1266 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1267 { WM_NCCALCSIZE, sent },
1268 { WM_NCACTIVATE, sent|parent|wparam, 0 },
1269 { WM_GETTEXT, sent|defwinproc },
1270 { WM_ACTIVATE, sent|parent|wparam, 0 },
1271 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1272 { WM_WINDOWPOSCHANGING, sent|parent },
1273 { WM_NCACTIVATE, sent|wparam, 1 },
1274 { WM_ACTIVATE, sent|wparam, 1 },
1275 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1276 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1277 /* (setting focus) */
1278 { WM_SHOWWINDOW, sent|wparam, 1 },
1279 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1280 { WM_NCPAINT, sent },
1281 { WM_GETTEXT, sent|defwinproc },
1282 { WM_ERASEBKGND, sent },
1283 { WM_CTLCOLORDLG, sent|defwinproc },
1284 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1285 { WM_PAINT, sent },
1286 /* (bunch of WM_CTLCOLOR* for each control) */
1287 { WM_PAINT, sent|parent },
1288 { WM_ENTERIDLE, sent|parent|wparam, 0 },
1289 { WM_SETCURSOR, sent|parent },
1290 { 0 }
1292 /* SetMenu for NonVisible windows with size change*/
1293 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1294 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1295 { WM_NCCALCSIZE, sent|wparam, 1 },
1296 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1297 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1298 { WM_MOVE, sent|defwinproc },
1299 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1300 { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1301 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1302 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1303 { WM_GETTEXT, sent|optional },
1304 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1305 { 0 }
1307 /* SetMenu for NonVisible windows with no size change */
1308 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1309 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1310 { WM_NCCALCSIZE, sent|wparam, 1 },
1311 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1312 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1313 { 0 }
1315 /* SetMenu for Visible windows with size change */
1316 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1317 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1318 { WM_NCCALCSIZE, sent|wparam, 1 },
1319 { 0x0093, sent|defwinproc|optional },
1320 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1321 { WM_NCPAINT, sent }, /* wparam != 1 */
1322 { 0x0093, sent|defwinproc|optional },
1323 { 0x0093, sent|defwinproc|optional },
1324 { 0x0091, sent|defwinproc|optional },
1325 { 0x0092, sent|defwinproc|optional },
1326 { WM_GETTEXT, sent|defwinproc|optional },
1327 { WM_ERASEBKGND, sent|optional },
1328 { WM_ACTIVATE, sent|optional },
1329 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1330 { WM_MOVE, sent|defwinproc },
1331 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1332 { 0x0093, sent|optional },
1333 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1334 { 0x0093, sent|defwinproc|optional },
1335 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1336 { 0x0093, sent|defwinproc|optional },
1337 { 0x0093, sent|defwinproc|optional },
1338 { 0x0091, sent|defwinproc|optional },
1339 { 0x0092, sent|defwinproc|optional },
1340 { WM_ERASEBKGND, sent|optional },
1341 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1342 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1343 { 0 }
1345 /* SetMenu for Visible windows with no size change */
1346 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1347 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1348 { WM_NCCALCSIZE, sent|wparam, 1 },
1349 { WM_NCPAINT, sent }, /* wparam != 1 */
1350 { WM_GETTEXT, sent|defwinproc|optional },
1351 { WM_ERASEBKGND, sent|optional },
1352 { WM_ACTIVATE, sent|optional },
1353 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1354 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1355 { 0 }
1357 /* DrawMenuBar for a visible window */
1358 static const struct message WmDrawMenuBarSeq[] =
1360 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1361 { WM_NCCALCSIZE, sent|wparam, 1 },
1362 { 0x0093, sent|defwinproc|optional },
1363 { WM_NCPAINT, sent }, /* wparam != 1 */
1364 { 0x0093, sent|defwinproc|optional },
1365 { 0x0093, sent|defwinproc|optional },
1366 { 0x0091, sent|defwinproc|optional },
1367 { 0x0092, sent|defwinproc|optional },
1368 { WM_GETTEXT, sent|defwinproc|optional },
1369 { WM_ERASEBKGND, sent|optional },
1370 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1371 { 0x0093, sent|optional },
1372 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1373 { 0 }
1376 static const struct message WmSetRedrawFalseSeq[] =
1378 { WM_SETREDRAW, sent|wparam, 0 },
1379 { 0 }
1382 static const struct message WmSetRedrawTrueSeq[] =
1384 { WM_SETREDRAW, sent|wparam, 1 },
1385 { 0 }
1388 static const struct message WmEnableWindowSeq_1[] =
1390 { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1391 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1392 { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1393 { 0 }
1396 static const struct message WmEnableWindowSeq_2[] =
1398 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1399 { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1400 { 0 }
1403 static const struct message WmGetScrollRangeSeq[] =
1405 { SBM_GETRANGE, sent },
1406 { 0 }
1408 static const struct message WmGetScrollInfoSeq[] =
1410 { SBM_GETSCROLLINFO, sent },
1411 { 0 }
1413 static const struct message WmSetScrollRangeSeq[] =
1415 /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1416 sends SBM_SETSCROLLINFO.
1418 { SBM_SETSCROLLINFO, sent },
1419 { 0 }
1421 /* SetScrollRange for a window without a non-client area */
1422 static const struct message WmSetScrollRangeHSeq_empty[] =
1424 { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1425 { 0 }
1427 static const struct message WmSetScrollRangeVSeq_empty[] =
1429 { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1430 { 0 }
1432 static const struct message WmSetScrollRangeHVSeq[] =
1434 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1435 { WM_NCCALCSIZE, sent|wparam, 1 },
1436 { WM_GETTEXT, sent|defwinproc|optional },
1437 { WM_ERASEBKGND, sent|optional },
1438 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1439 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1440 { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1441 { 0 }
1443 /* SetScrollRange for a window with a non-client area */
1444 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1446 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1447 { WM_NCCALCSIZE, sent|wparam, 1 },
1448 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1449 { WM_NCPAINT, sent|optional },
1450 { WM_STYLECHANGING, sent|defwinproc|optional },
1451 { WM_STYLECHANGED, sent|defwinproc|optional },
1452 { WM_STYLECHANGING, sent|defwinproc|optional },
1453 { WM_STYLECHANGED, sent|defwinproc|optional },
1454 { WM_STYLECHANGING, sent|defwinproc|optional },
1455 { WM_STYLECHANGED, sent|defwinproc|optional },
1456 { WM_STYLECHANGING, sent|defwinproc|optional },
1457 { WM_STYLECHANGED, sent|defwinproc|optional },
1458 { WM_GETTEXT, sent|defwinproc|optional },
1459 { WM_GETTEXT, sent|defwinproc|optional },
1460 { WM_ERASEBKGND, sent|optional },
1461 { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1462 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE },
1463 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1464 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1465 { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1466 { WM_GETTEXT, sent|optional },
1467 { WM_GETTEXT, sent|optional },
1468 { WM_GETTEXT, sent|optional },
1469 { WM_GETTEXT, sent|optional },
1470 { 0 }
1472 /* test if we receive the right sequence of messages */
1473 /* after calling ShowWindow( SW_SHOWNA) */
1474 static const struct message WmSHOWNAChildInvisParInvis[] = {
1475 { WM_SHOWWINDOW, sent|wparam, 1 },
1476 { 0 }
1478 static const struct message WmSHOWNAChildVisParInvis[] = {
1479 { WM_SHOWWINDOW, sent|wparam, 1 },
1480 { 0 }
1482 static const struct message WmSHOWNAChildVisParVis[] = {
1483 { WM_SHOWWINDOW, sent|wparam, 1 },
1484 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1485 { 0 }
1487 static const struct message WmSHOWNAChildInvisParVis[] = {
1488 { WM_SHOWWINDOW, sent|wparam, 1 },
1489 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1490 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1491 { WM_ERASEBKGND, sent|optional },
1492 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1493 { 0 }
1495 static const struct message WmSHOWNATopVisible[] = {
1496 { WM_SHOWWINDOW, sent|wparam, 1 },
1497 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1498 { 0 }
1500 static const struct message WmSHOWNATopInvisible[] = {
1501 { WM_SHOWWINDOW, sent|wparam, 1 },
1502 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1503 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1504 { WM_NCPAINT, sent|wparam, 1 },
1505 { WM_GETTEXT, sent|defwinproc|optional },
1506 { WM_ERASEBKGND, sent|optional },
1507 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1508 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1509 { WM_NCPAINT, sent|wparam|optional, 1 },
1510 { WM_ERASEBKGND, sent|optional },
1511 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1512 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1513 { WM_MOVE, sent },
1514 { 0 }
1517 static int after_end_dialog, test_def_id;
1518 static int sequence_cnt, sequence_size;
1519 static struct message* sequence;
1520 static int log_all_parent_messages;
1522 /* user32 functions */
1523 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1524 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1525 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1526 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1527 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1528 /* kernel32 functions */
1529 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1531 static void init_procs(void)
1533 HMODULE user32 = GetModuleHandleA("user32.dll");
1534 HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1536 #define GET_PROC(dll, func) \
1537 p ## func = (void*)GetProcAddress(dll, #func); \
1538 if(!p ## func) { \
1539 trace("GetProcAddress(%s) failed\n", #func); \
1542 GET_PROC(user32, GetAncestor)
1543 GET_PROC(user32, NotifyWinEvent)
1544 GET_PROC(user32, SetWinEventHook)
1545 GET_PROC(user32, TrackMouseEvent)
1546 GET_PROC(user32, UnhookWinEvent)
1548 GET_PROC(kernel32, GetCPInfoExA)
1550 #undef GET_PROC
1553 static void add_message(const struct message *msg)
1555 if (!sequence)
1557 sequence_size = 10;
1558 sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof (struct message) );
1560 if (sequence_cnt == sequence_size)
1562 sequence_size *= 2;
1563 sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof (struct message) );
1565 assert(sequence);
1567 sequence[sequence_cnt].message = msg->message;
1568 sequence[sequence_cnt].flags = msg->flags;
1569 sequence[sequence_cnt].wParam = msg->wParam;
1570 sequence[sequence_cnt].lParam = msg->lParam;
1572 sequence_cnt++;
1575 /* try to make sure pending X events have been processed before continuing */
1576 static void flush_events(void)
1578 MSG msg;
1579 int diff = 200;
1580 int min_timeout = 50;
1581 DWORD time = GetTickCount() + diff;
1583 while (diff > 0)
1585 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1586 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1587 diff = time - GetTickCount();
1588 min_timeout = 10;
1592 static void flush_sequence(void)
1594 HeapFree(GetProcessHeap(), 0, sequence);
1595 sequence = 0;
1596 sequence_cnt = sequence_size = 0;
1599 #define ok_sequence( exp, contx, todo) \
1600 ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
1603 static void ok_sequence_(const struct message *expected, const char *context, int todo,
1604 const char *file, int line)
1606 static const struct message end_of_sequence = { 0, 0, 0, 0 };
1607 const struct message *actual;
1608 int failcount = 0;
1610 add_message(&end_of_sequence);
1612 actual = sequence;
1614 while (expected->message && actual->message)
1616 trace_( file, line)("expected %04x - actual %04x\n", expected->message, actual->message);
1618 if (expected->message == actual->message)
1620 if (expected->flags & wparam)
1622 if (expected->wParam != actual->wParam && todo)
1624 todo_wine {
1625 failcount ++;
1626 ok_( file, line) (FALSE,
1627 "%s: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1628 context, expected->message, expected->wParam, actual->wParam);
1631 else
1632 ok_( file, line) (expected->wParam == actual->wParam,
1633 "%s: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
1634 context, expected->message, expected->wParam, actual->wParam);
1636 if (expected->flags & lparam)
1638 if (expected->lParam != actual->lParam && todo)
1640 todo_wine {
1641 failcount ++;
1642 ok_( file, line) (FALSE,
1643 "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1644 context, expected->message, expected->lParam, actual->lParam);
1647 else
1648 ok_( file, line) (expected->lParam == actual->lParam,
1649 "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
1650 context, expected->message, expected->lParam, actual->lParam);
1652 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
1654 todo_wine {
1655 failcount ++;
1656 ok_( file, line) (FALSE,
1657 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1658 context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1661 else
1662 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
1663 "%s: the msg 0x%04x should %shave been sent by DefWindowProc\n",
1664 context, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
1665 ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
1666 "%s: the msg 0x%04x should %shave been sent by BeginPaint\n",
1667 context, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
1668 ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
1669 "%s: the msg 0x%04x should have been %s\n",
1670 context, expected->message, (expected->flags & posted) ? "posted" : "sent");
1671 ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
1672 "%s: the msg 0x%04x was expected in %s\n",
1673 context, expected->message, (expected->flags & parent) ? "parent" : "child");
1674 ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
1675 "%s: the msg 0x%04x should have been sent by a hook\n",
1676 context, expected->message);
1677 ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
1678 "%s: the msg 0x%04x should have been sent by a winevent hook\n",
1679 context, expected->message);
1680 expected++;
1681 actual++;
1683 /* silently drop winevent messages if there is no support for them */
1684 else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1685 expected++;
1686 else if (todo)
1688 failcount++;
1689 todo_wine {
1690 ok_( file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
1691 context, expected->message, actual->message);
1693 flush_sequence();
1694 return;
1696 else
1698 ok_( file, line) (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
1699 context, expected->message, actual->message);
1700 expected++;
1701 actual++;
1705 /* skip all optional trailing messages */
1706 while (expected->message && ((expected->flags & optional) ||
1707 ((expected->flags & winevent_hook) && !hEvent_hook)))
1708 expected++;
1710 if (todo)
1712 todo_wine {
1713 if (expected->message || actual->message) {
1714 failcount++;
1715 ok_( file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
1716 context, expected->message, actual->message);
1720 else
1722 if (expected->message || actual->message)
1723 ok_( file, line) (FALSE, "%s: the msg sequence is not complete: expected %04x - actual %04x\n",
1724 context, expected->message, actual->message);
1726 if( todo && !failcount) /* succeeded yet marked todo */
1727 todo_wine {
1728 ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
1731 flush_sequence();
1734 /******************************** MDI test **********************************/
1736 /* CreateWindow for MDI frame window, initially visible */
1737 static const struct message WmCreateMDIframeSeq[] = {
1738 { HCBT_CREATEWND, hook },
1739 { WM_GETMINMAXINFO, sent },
1740 { WM_NCCREATE, sent },
1741 { WM_NCCALCSIZE, sent|wparam, 0 },
1742 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1743 { WM_CREATE, sent },
1744 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1745 { WM_SHOWWINDOW, sent|wparam, 1 },
1746 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1747 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1748 { HCBT_ACTIVATE, hook },
1749 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1750 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1751 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
1752 { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
1753 { WM_NCACTIVATE, sent|wparam, 1 },
1754 { WM_GETTEXT, sent|defwinproc|optional },
1755 { WM_ACTIVATE, sent|wparam, 1 },
1756 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
1757 { HCBT_SETFOCUS, hook },
1758 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1759 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1760 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1761 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
1762 /* Win9x adds SWP_NOZORDER below */
1763 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1764 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
1765 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1766 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1767 { WM_MOVE, sent },
1768 { 0 }
1770 /* DestroyWindow for MDI frame window, initially visible */
1771 static const struct message WmDestroyMDIframeSeq[] = {
1772 { HCBT_DESTROYWND, hook },
1773 { 0x0090, sent|optional },
1774 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1775 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1776 { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
1777 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1778 { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
1779 { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
1780 { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
1781 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
1782 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1783 { WM_DESTROY, sent },
1784 { WM_NCDESTROY, sent },
1785 { 0 }
1787 /* CreateWindow for MDI client window, initially visible */
1788 static const struct message WmCreateMDIclientSeq[] = {
1789 { HCBT_CREATEWND, hook },
1790 { WM_NCCREATE, sent },
1791 { WM_NCCALCSIZE, sent|wparam, 0 },
1792 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
1793 { WM_CREATE, sent },
1794 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
1795 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1796 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1797 { WM_MOVE, sent },
1798 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
1799 { WM_SHOWWINDOW, sent|wparam, 1 },
1800 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1801 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1802 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1803 { 0 }
1805 /* ShowWindow(SW_SHOW) for MDI client window */
1806 static const struct message WmShowMDIclientSeq[] = {
1807 { WM_SHOWWINDOW, sent|wparam, 1 },
1808 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1809 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1810 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1811 { 0 }
1813 /* ShowWindow(SW_HIDE) for MDI client window */
1814 static const struct message WmHideMDIclientSeq[] = {
1815 { WM_SHOWWINDOW, sent|wparam, 0 },
1816 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1817 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
1818 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
1819 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1820 { 0 }
1822 /* DestroyWindow for MDI client window, initially visible */
1823 static const struct message WmDestroyMDIclientSeq[] = {
1824 { HCBT_DESTROYWND, hook },
1825 { 0x0090, sent|optional },
1826 { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
1827 { WM_SHOWWINDOW, sent|wparam, 0 },
1828 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1829 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1830 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1831 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1832 { WM_DESTROY, sent },
1833 { WM_NCDESTROY, sent },
1834 { 0 }
1836 /* CreateWindow for MDI child window, initially visible */
1837 static const struct message WmCreateMDIchildVisibleSeq[] = {
1838 { HCBT_CREATEWND, hook },
1839 { WM_NCCREATE, sent },
1840 { WM_NCCALCSIZE, sent|wparam, 0 },
1841 { WM_CREATE, sent },
1842 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1843 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1844 { WM_MOVE, sent },
1845 /* Win2k sends wparam set to
1846 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1847 * while Win9x doesn't bother to set child window id according to
1848 * CLIENTCREATESTRUCT.idFirstChild
1850 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1851 { WM_SHOWWINDOW, sent|wparam, 1 },
1852 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1853 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1854 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1855 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
1856 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1857 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1858 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1860 /* Win9x: message sequence terminates here. */
1862 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1863 { HCBT_SETFOCUS, hook }, /* in MDI client */
1864 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1865 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
1866 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1867 { WM_SETFOCUS, sent }, /* in MDI client */
1868 { HCBT_SETFOCUS, hook },
1869 { WM_KILLFOCUS, sent }, /* in MDI client */
1870 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1871 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1872 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1873 { WM_SETFOCUS, sent|defwinproc },
1874 { WM_MDIACTIVATE, sent|defwinproc },
1875 { 0 }
1877 /* CreateWindow for MDI child window with invisible parent */
1878 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
1879 { HCBT_CREATEWND, hook },
1880 { WM_GETMINMAXINFO, sent },
1881 { WM_NCCREATE, sent },
1882 { WM_NCCALCSIZE, sent|wparam, 0 },
1883 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
1884 { WM_CREATE, sent },
1885 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1886 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1887 { WM_MOVE, sent },
1888 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1889 { WM_SHOWWINDOW, sent|wparam, 1 },
1890 { WM_MDIREFRESHMENU, sent }, /* in MDI client */
1891 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1892 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
1893 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1895 /* Win9x: message sequence terminates here. */
1897 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
1898 { HCBT_SETFOCUS, hook }, /* in MDI client */
1899 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1900 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
1901 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1902 { WM_SETFOCUS, sent }, /* in MDI client */
1903 { HCBT_SETFOCUS, hook },
1904 { WM_KILLFOCUS, sent }, /* in MDI client */
1905 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1906 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
1907 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1908 { WM_SETFOCUS, sent|defwinproc },
1909 { WM_MDIACTIVATE, sent|defwinproc },
1910 { 0 }
1912 /* DestroyWindow for MDI child window, initially visible */
1913 static const struct message WmDestroyMDIchildVisibleSeq[] = {
1914 { HCBT_DESTROYWND, hook },
1915 /* Win2k sends wparam set to
1916 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
1917 * while Win9x doesn't bother to set child window id according to
1918 * CLIENTCREATESTRUCT.idFirstChild
1920 { 0x0090, sent|optional },
1921 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
1922 { WM_SHOWWINDOW, sent|wparam, 0 },
1923 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1924 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1925 { WM_ERASEBKGND, sent|parent|optional },
1926 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1928 /* { WM_DESTROY, sent }
1929 * Win9x: message sequence terminates here.
1932 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1933 { WM_KILLFOCUS, sent },
1934 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1935 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1936 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1937 { WM_SETFOCUS, sent }, /* in MDI client */
1939 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1940 { WM_KILLFOCUS, sent }, /* in MDI client */
1941 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1942 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1943 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1944 { WM_SETFOCUS, sent }, /* in MDI client */
1946 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1948 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1949 { WM_KILLFOCUS, sent },
1950 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1951 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1952 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1953 { WM_SETFOCUS, sent }, /* in MDI client */
1955 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1956 { WM_KILLFOCUS, sent }, /* in MDI client */
1957 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1958 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1959 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1960 { WM_SETFOCUS, sent }, /* in MDI client */
1962 { WM_DESTROY, sent },
1964 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
1965 { WM_KILLFOCUS, sent },
1966 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1967 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
1968 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1969 { WM_SETFOCUS, sent }, /* in MDI client */
1971 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
1972 { WM_KILLFOCUS, sent }, /* in MDI client */
1973 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
1974 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1975 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1976 { WM_SETFOCUS, sent }, /* in MDI client */
1978 { WM_NCDESTROY, sent },
1979 { 0 }
1981 /* CreateWindow for MDI child window, initially invisible */
1982 static const struct message WmCreateMDIchildInvisibleSeq[] = {
1983 { HCBT_CREATEWND, hook },
1984 { WM_NCCREATE, sent },
1985 { WM_NCCALCSIZE, sent|wparam, 0 },
1986 { WM_CREATE, sent },
1987 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1988 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1989 { WM_MOVE, sent },
1990 /* Win2k sends wparam set to
1991 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
1992 * while Win9x doesn't bother to set child window id according to
1993 * CLIENTCREATESTRUCT.idFirstChild
1995 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
1996 { 0 }
1998 /* DestroyWindow for MDI child window, initially invisible */
1999 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
2000 { HCBT_DESTROYWND, hook },
2001 /* Win2k sends wparam set to
2002 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2003 * while Win9x doesn't bother to set child window id according to
2004 * CLIENTCREATESTRUCT.idFirstChild
2006 { 0x0090, sent|optional },
2007 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2008 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2009 { WM_DESTROY, sent },
2010 { WM_NCDESTROY, sent },
2011 /* FIXME: Wine destroys an icon/title window while Windows doesn't */
2012 { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
2013 { 0 }
2015 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
2016 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
2017 { HCBT_CREATEWND, hook },
2018 { WM_NCCREATE, sent },
2019 { WM_NCCALCSIZE, sent|wparam, 0 },
2020 { WM_CREATE, sent },
2021 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2022 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2023 { WM_MOVE, sent },
2024 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2025 { WM_GETMINMAXINFO, sent },
2026 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2027 { WM_NCCALCSIZE, sent|wparam, 1 },
2028 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2029 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2030 /* in MDI frame */
2031 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2032 { WM_NCCALCSIZE, sent|wparam, 1 },
2033 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2034 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2035 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2036 /* Win2k sends wparam set to
2037 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2038 * while Win9x doesn't bother to set child window id according to
2039 * CLIENTCREATESTRUCT.idFirstChild
2041 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2042 { WM_SHOWWINDOW, sent|wparam, 1 },
2043 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2044 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2045 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2046 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2047 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2048 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2049 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2051 /* Win9x: message sequence terminates here. */
2053 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2054 { HCBT_SETFOCUS, hook }, /* in MDI client */
2055 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2056 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2057 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2058 { WM_SETFOCUS, sent }, /* in MDI client */
2059 { HCBT_SETFOCUS, hook },
2060 { WM_KILLFOCUS, sent }, /* in MDI client */
2061 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2062 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2063 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2064 { WM_SETFOCUS, sent|defwinproc },
2065 { WM_MDIACTIVATE, sent|defwinproc },
2066 /* in MDI frame */
2067 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2068 { WM_NCCALCSIZE, sent|wparam, 1 },
2069 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2070 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2071 { 0 }
2073 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2074 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2075 /* restore the 1st MDI child */
2076 { WM_SETREDRAW, sent|wparam, 0 },
2077 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2078 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2079 { WM_NCCALCSIZE, sent|wparam, 1 },
2080 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2081 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2082 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2083 /* in MDI frame */
2084 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2085 { WM_NCCALCSIZE, sent|wparam, 1 },
2086 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2087 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2088 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2089 { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2090 /* create the 2nd MDI child */
2091 { HCBT_CREATEWND, hook },
2092 { WM_NCCREATE, sent },
2093 { WM_NCCALCSIZE, sent|wparam, 0 },
2094 { WM_CREATE, sent },
2095 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2096 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2097 { WM_MOVE, sent },
2098 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2099 { WM_GETMINMAXINFO, sent },
2100 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2101 { WM_NCCALCSIZE, sent|wparam, 1 },
2102 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2103 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2104 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2105 /* in MDI frame */
2106 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2107 { WM_NCCALCSIZE, sent|wparam, 1 },
2108 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2109 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2110 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2111 /* Win2k sends wparam set to
2112 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2113 * while Win9x doesn't bother to set child window id according to
2114 * CLIENTCREATESTRUCT.idFirstChild
2116 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2117 { WM_SHOWWINDOW, sent|wparam, 1 },
2118 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2119 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2120 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2121 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2122 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2123 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2125 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2126 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2128 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2130 /* Win9x: message sequence terminates here. */
2132 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2133 { HCBT_SETFOCUS, hook },
2134 { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
2135 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2136 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2137 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2138 { WM_SETFOCUS, sent }, /* in MDI client */
2139 { HCBT_SETFOCUS, hook },
2140 { WM_KILLFOCUS, sent }, /* in MDI client */
2141 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2142 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2143 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2144 { WM_SETFOCUS, sent|defwinproc },
2146 { WM_MDIACTIVATE, sent|defwinproc },
2147 /* in MDI frame */
2148 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2149 { WM_NCCALCSIZE, sent|wparam, 1 },
2150 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2151 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2152 { 0 }
2154 /* WM_MDICREATE MDI child window, initially visible and maximized */
2155 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2156 { WM_MDICREATE, sent },
2157 { HCBT_CREATEWND, hook },
2158 { WM_NCCREATE, sent },
2159 { WM_NCCALCSIZE, sent|wparam, 0 },
2160 { WM_CREATE, sent },
2161 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2162 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2163 { WM_MOVE, sent },
2164 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2165 { WM_GETMINMAXINFO, sent },
2166 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2167 { WM_NCCALCSIZE, sent|wparam, 1 },
2168 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2169 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2171 /* in MDI frame */
2172 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2173 { WM_NCCALCSIZE, sent|wparam, 1 },
2174 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2175 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2176 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2178 /* Win2k sends wparam set to
2179 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2180 * while Win9x doesn't bother to set child window id according to
2181 * CLIENTCREATESTRUCT.idFirstChild
2183 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2184 { WM_SHOWWINDOW, sent|wparam, 1 },
2185 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2187 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2189 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2190 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2191 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2193 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2194 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2196 /* Win9x: message sequence terminates here. */
2198 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2199 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2200 { HCBT_SETFOCUS, hook }, /* in MDI client */
2201 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2202 { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2203 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2204 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2205 { HCBT_SETFOCUS, hook|optional },
2206 { WM_KILLFOCUS, sent }, /* in MDI client */
2207 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2208 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2209 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2210 { WM_SETFOCUS, sent|defwinproc },
2212 { WM_MDIACTIVATE, sent|defwinproc },
2214 /* in MDI child */
2215 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2216 { WM_NCCALCSIZE, sent|wparam, 1 },
2217 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2218 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2220 /* in MDI frame */
2221 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2222 { WM_NCCALCSIZE, sent|wparam, 1 },
2223 { 0x0093, sent|defwinproc|optional },
2224 { 0x0093, sent|defwinproc|optional },
2225 { 0x0093, sent|defwinproc|optional },
2226 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2227 { WM_MOVE, sent|defwinproc },
2228 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2230 /* in MDI client */
2231 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2232 { WM_NCCALCSIZE, sent|wparam, 1 },
2233 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2234 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2236 /* in MDI child */
2237 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2238 { WM_NCCALCSIZE, sent|wparam, 1 },
2239 { 0x0093, sent|optional },
2240 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2241 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2243 { 0x0093, sent|optional },
2244 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2245 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2246 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2247 { 0x0093, sent|defwinproc|optional },
2248 { 0x0093, sent|defwinproc|optional },
2249 { 0x0093, sent|defwinproc|optional },
2250 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2251 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2253 { 0 }
2255 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2256 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2257 { HCBT_CREATEWND, hook },
2258 { WM_GETMINMAXINFO, sent },
2259 { WM_NCCREATE, sent },
2260 { WM_NCCALCSIZE, sent|wparam, 0 },
2261 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2262 { WM_CREATE, sent },
2263 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2264 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2265 { WM_MOVE, sent },
2266 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2267 { WM_GETMINMAXINFO, sent },
2268 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2269 { WM_GETMINMAXINFO, sent|defwinproc },
2270 { WM_NCCALCSIZE, sent|wparam, 1 },
2271 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
2272 { WM_MOVE, sent|defwinproc },
2273 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2274 /* in MDI frame */
2275 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2276 { WM_NCCALCSIZE, sent|wparam, 1 },
2277 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2278 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2279 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2280 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2281 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2282 /* Win2k sends wparam set to
2283 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2284 * while Win9x doesn't bother to set child window id according to
2285 * CLIENTCREATESTRUCT.idFirstChild
2287 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2288 { 0 }
2290 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2291 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2292 { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2293 { HCBT_SYSCOMMAND, hook },
2294 { WM_CLOSE, sent|defwinproc },
2295 { WM_MDIDESTROY, sent }, /* in MDI client */
2297 /* bring the 1st MDI child to top */
2298 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2299 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2301 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2303 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2304 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2305 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2307 /* maximize the 1st MDI child */
2308 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2309 { WM_GETMINMAXINFO, sent|defwinproc },
2310 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED },
2311 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2312 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2313 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2314 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2316 /* restore the 2nd MDI child */
2317 { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2318 { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2319 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2320 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2322 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2324 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2325 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2327 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2329 { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2330 /* in MDI frame */
2331 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2332 { WM_NCCALCSIZE, sent|wparam, 1 },
2333 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2334 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2335 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2337 /* bring the 1st MDI child to top */
2338 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2339 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2340 { HCBT_SETFOCUS, hook },
2341 { WM_KILLFOCUS, sent|defwinproc },
2342 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2343 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2344 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2345 { WM_SETFOCUS, sent }, /* in MDI client */
2346 { HCBT_SETFOCUS, hook },
2347 { WM_KILLFOCUS, sent }, /* in MDI client */
2348 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2349 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2350 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2351 { WM_SETFOCUS, sent|defwinproc },
2352 { WM_MDIACTIVATE, sent|defwinproc },
2353 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2355 /* apparently ShowWindow(SW_SHOW) on an MDI client */
2356 { WM_SHOWWINDOW, sent|wparam, 1 },
2357 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2358 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2359 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2360 { WM_MDIREFRESHMENU, sent },
2362 { HCBT_DESTROYWND, hook },
2363 /* Win2k sends wparam set to
2364 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2365 * while Win9x doesn't bother to set child window id according to
2366 * CLIENTCREATESTRUCT.idFirstChild
2368 { 0x0090, sent|defwinproc|optional },
2369 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2370 { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2371 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2372 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2373 { WM_ERASEBKGND, sent|parent|optional },
2374 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2376 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2377 { WM_DESTROY, sent|defwinproc },
2378 { WM_NCDESTROY, sent|defwinproc },
2379 { 0 }
2381 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2382 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2383 { WM_MDIDESTROY, sent }, /* in MDI client */
2384 { WM_SHOWWINDOW, sent|wparam, 0 },
2385 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2386 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2387 { WM_ERASEBKGND, sent|parent|optional },
2388 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2390 { HCBT_SETFOCUS, hook },
2391 { WM_KILLFOCUS, sent },
2392 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2393 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2394 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2395 { WM_SETFOCUS, sent }, /* in MDI client */
2396 { HCBT_SETFOCUS, hook },
2397 { WM_KILLFOCUS, sent }, /* in MDI client */
2398 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2399 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2400 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2401 { WM_SETFOCUS, sent },
2403 /* in MDI child */
2404 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2405 { WM_NCCALCSIZE, sent|wparam, 1 },
2406 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2407 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2409 /* in MDI frame */
2410 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2411 { WM_NCCALCSIZE, sent|wparam, 1 },
2412 { 0x0093, sent|defwinproc|optional },
2413 { 0x0093, sent|defwinproc|optional },
2414 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2415 { WM_MOVE, sent|defwinproc },
2416 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2418 /* in MDI client */
2419 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2420 { WM_NCCALCSIZE, sent|wparam, 1 },
2421 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2422 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2424 /* in MDI child */
2425 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2426 { WM_NCCALCSIZE, sent|wparam, 1 },
2427 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2428 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2430 /* in MDI child */
2431 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2432 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2433 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2434 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2436 /* in MDI frame */
2437 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2438 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2439 { 0x0093, sent|defwinproc|optional },
2440 { 0x0093, sent|defwinproc|optional },
2441 { 0x0093, sent|defwinproc|optional },
2442 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2443 { WM_MOVE, sent|defwinproc },
2444 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2446 /* in MDI client */
2447 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2448 { WM_NCCALCSIZE, sent|wparam, 1 },
2449 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2450 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2452 /* in MDI child */
2453 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2454 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2455 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2456 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2457 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2458 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2460 { 0x0093, sent|defwinproc|optional },
2461 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2462 { 0x0093, sent|defwinproc|optional },
2463 { 0x0093, sent|defwinproc|optional },
2464 { 0x0093, sent|defwinproc|optional },
2465 { 0x0093, sent|optional },
2467 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2468 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2469 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2470 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2471 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2473 /* in MDI frame */
2474 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2475 { WM_NCCALCSIZE, sent|wparam, 1 },
2476 { 0x0093, sent|defwinproc|optional },
2477 { 0x0093, sent|defwinproc|optional },
2478 { 0x0093, sent|defwinproc|optional },
2479 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2480 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2481 { 0x0093, sent|optional },
2483 { WM_NCACTIVATE, sent|wparam, 0 },
2484 { WM_MDIACTIVATE, sent },
2486 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2487 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2488 { WM_NCCALCSIZE, sent|wparam, 1 },
2490 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2492 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2493 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2494 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2496 /* in MDI child */
2497 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2498 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2499 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2500 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2502 /* in MDI frame */
2503 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2504 { WM_NCCALCSIZE, sent|wparam, 1 },
2505 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2506 { WM_MOVE, sent|defwinproc },
2507 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2509 /* in MDI client */
2510 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2511 { WM_NCCALCSIZE, sent|wparam, 1 },
2512 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2513 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2514 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2515 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2516 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2517 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2518 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2520 { HCBT_SETFOCUS, hook },
2521 { WM_KILLFOCUS, sent },
2522 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2523 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2524 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2525 { WM_SETFOCUS, sent }, /* in MDI client */
2527 { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2529 { HCBT_DESTROYWND, hook },
2530 /* Win2k sends wparam set to
2531 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2532 * while Win9x doesn't bother to set child window id according to
2533 * CLIENTCREATESTRUCT.idFirstChild
2535 { 0x0090, sent|optional },
2536 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2538 { WM_SHOWWINDOW, sent|wparam, 0 },
2539 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2540 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2541 { WM_ERASEBKGND, sent|parent|optional },
2542 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2544 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2545 { WM_DESTROY, sent },
2546 { WM_NCDESTROY, sent },
2547 { 0 }
2549 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
2550 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
2551 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2552 { WM_GETMINMAXINFO, sent },
2553 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
2554 { WM_NCCALCSIZE, sent|wparam, 1 },
2555 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2556 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2558 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2559 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2560 { HCBT_SETFOCUS, hook },
2561 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2562 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2563 { WM_SETFOCUS, sent }, /* in MDI client */
2564 { HCBT_SETFOCUS, hook },
2565 { WM_KILLFOCUS, sent }, /* in MDI client */
2566 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2567 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2568 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2569 { WM_SETFOCUS, sent|defwinproc },
2570 { WM_MDIACTIVATE, sent|defwinproc },
2571 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2572 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2573 /* in MDI frame */
2574 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2575 { WM_NCCALCSIZE, sent|wparam, 1 },
2576 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2577 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2578 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2579 { 0 }
2581 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
2582 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
2583 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2584 { WM_GETMINMAXINFO, sent },
2585 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
2586 { WM_GETMINMAXINFO, sent|defwinproc },
2587 { WM_NCCALCSIZE, sent|wparam, 1 },
2588 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2589 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2591 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2592 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2593 { HCBT_SETFOCUS, hook },
2594 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2595 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2596 { WM_SETFOCUS, sent }, /* in MDI client */
2597 { HCBT_SETFOCUS, hook },
2598 { WM_KILLFOCUS, sent }, /* in MDI client */
2599 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2600 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2601 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2602 { WM_SETFOCUS, sent|defwinproc },
2603 { WM_MDIACTIVATE, sent|defwinproc },
2604 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2605 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2606 { 0 }
2608 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
2609 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
2610 { WM_MDIMAXIMIZE, sent }, /* in MDI client */
2611 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2612 { WM_GETMINMAXINFO, sent },
2613 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2614 { WM_GETMINMAXINFO, sent|defwinproc },
2615 { WM_NCCALCSIZE, sent|wparam, 1 },
2616 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
2617 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2618 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
2619 { WM_MOVE, sent|defwinproc },
2620 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2622 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2623 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2624 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2625 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
2626 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2627 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
2628 /* in MDI frame */
2629 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2630 { WM_NCCALCSIZE, sent|wparam, 1 },
2631 { 0x0093, sent|defwinproc|optional },
2632 { 0x0094, sent|defwinproc|optional },
2633 { 0x0094, sent|defwinproc|optional },
2634 { 0x0094, sent|defwinproc|optional },
2635 { 0x0094, sent|defwinproc|optional },
2636 { 0x0093, sent|defwinproc|optional },
2637 { 0x0093, sent|defwinproc|optional },
2638 { 0x0091, sent|defwinproc|optional },
2639 { 0x0092, sent|defwinproc|optional },
2640 { 0x0092, sent|defwinproc|optional },
2641 { 0x0092, sent|defwinproc|optional },
2642 { 0x0092, sent|defwinproc|optional },
2643 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2644 { WM_MOVE, sent|defwinproc },
2645 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2646 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
2647 /* in MDI client */
2648 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2649 { WM_NCCALCSIZE, sent|wparam, 1 },
2650 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2651 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2652 /* in MDI child */
2653 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2654 { WM_GETMINMAXINFO, sent|defwinproc },
2655 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2656 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2657 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2658 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
2659 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
2660 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2661 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2662 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
2663 /* in MDI frame */
2664 { 0x0093, sent|optional },
2665 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2666 { 0x0093, sent|defwinproc|optional },
2667 { 0x0093, sent|defwinproc|optional },
2668 { 0x0093, sent|defwinproc|optional },
2669 { 0x0091, sent|defwinproc|optional },
2670 { 0x0092, sent|defwinproc|optional },
2671 { 0x0092, sent|defwinproc|optional },
2672 { 0x0092, sent|defwinproc|optional },
2673 { 0x0092, sent|defwinproc|optional },
2674 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
2675 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
2676 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
2677 { 0 }
2679 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
2680 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
2681 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2682 { WM_GETMINMAXINFO, sent },
2683 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2684 { WM_NCCALCSIZE, sent|wparam, 1 },
2685 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2686 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2687 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2688 /* in MDI frame */
2689 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2690 { WM_NCCALCSIZE, sent|wparam, 1 },
2691 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2692 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2693 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2694 { 0 }
2696 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
2697 static const struct message WmRestoreMDIchildVisibleSeq[] = {
2698 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2699 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2700 { WM_NCCALCSIZE, sent|wparam, 1 },
2701 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2702 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2703 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2704 /* in MDI frame */
2705 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2706 { WM_NCCALCSIZE, sent|wparam, 1 },
2707 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2708 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2709 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2710 { 0 }
2712 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
2713 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
2714 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2715 { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
2716 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
2717 { WM_NCCALCSIZE, sent|wparam, 1 },
2718 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2719 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
2720 { WM_MOVE, sent|defwinproc },
2721 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2722 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2723 { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2724 { HCBT_SETFOCUS, hook },
2725 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2726 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2727 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2728 { WM_SETFOCUS, sent },
2729 { 0 }
2731 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
2732 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
2733 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
2734 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
2735 { WM_NCCALCSIZE, sent|wparam, 1 },
2736 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
2737 { WM_MOVE, sent|defwinproc },
2738 { WM_SIZE, sent|defwinproc|wparam, SIZE_MINIMIZED },
2739 { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
2740 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2741 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2742 /* FIXME: Wine creates an icon/title window while Windows doesn't */
2743 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
2744 { 0 }
2746 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
2747 static const struct message WmRestoreMDIchildInisibleSeq[] = {
2748 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
2749 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
2750 { WM_NCCALCSIZE, sent|wparam, 1 },
2751 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2752 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2753 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2754 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2755 /* in MDI frame */
2756 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2757 { WM_NCCALCSIZE, sent|wparam, 1 },
2758 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2759 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2760 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2761 { 0 }
2764 static HWND mdi_client;
2765 static WNDPROC old_mdi_client_proc;
2767 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2769 struct message msg;
2771 /* do not log painting messages */
2772 if (message != WM_PAINT &&
2773 message != WM_NCPAINT &&
2774 message != WM_SYNCPAINT &&
2775 message != WM_ERASEBKGND &&
2776 message != WM_NCHITTEST &&
2777 message != WM_GETTEXT &&
2778 message != WM_MDIGETACTIVE &&
2779 message != WM_GETICON &&
2780 message != WM_DEVICECHANGE)
2782 trace("mdi client: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
2784 switch (message)
2786 case WM_WINDOWPOSCHANGING:
2787 case WM_WINDOWPOSCHANGED:
2789 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2791 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2792 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2793 winpos->hwnd, winpos->hwndInsertAfter,
2794 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2795 dump_winpos_flags(winpos->flags);
2797 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2798 * in the high word for internal purposes
2800 wParam = winpos->flags & 0xffff;
2801 /* We are not interested in the flags that don't match under XP and Win9x */
2802 wParam &= ~(SWP_NOZORDER);
2803 break;
2807 msg.message = message;
2808 msg.flags = sent|wparam|lparam;
2809 msg.wParam = wParam;
2810 msg.lParam = lParam;
2811 add_message(&msg);
2814 return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
2817 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2819 static long defwndproc_counter = 0;
2820 LRESULT ret;
2821 struct message msg;
2823 /* do not log painting messages */
2824 if (message != WM_PAINT &&
2825 message != WM_NCPAINT &&
2826 message != WM_SYNCPAINT &&
2827 message != WM_ERASEBKGND &&
2828 message != WM_NCHITTEST &&
2829 message != WM_GETTEXT &&
2830 message != WM_GETICON &&
2831 message != WM_DEVICECHANGE)
2833 trace("mdi child: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
2835 switch (message)
2837 case WM_WINDOWPOSCHANGING:
2838 case WM_WINDOWPOSCHANGED:
2840 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2842 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2843 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2844 winpos->hwnd, winpos->hwndInsertAfter,
2845 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2846 dump_winpos_flags(winpos->flags);
2848 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2849 * in the high word for internal purposes
2851 wParam = winpos->flags & 0xffff;
2852 /* We are not interested in the flags that don't match under XP and Win9x */
2853 wParam &= ~(SWP_NOZORDER);
2854 break;
2857 case WM_MDIACTIVATE:
2859 HWND active, client = GetParent(hwnd);
2861 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
2863 if (hwnd == (HWND)lParam) /* if we are being activated */
2864 ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
2865 else
2866 ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
2867 break;
2871 msg.message = message;
2872 msg.flags = sent|wparam|lparam;
2873 if (defwndproc_counter) msg.flags |= defwinproc;
2874 msg.wParam = wParam;
2875 msg.lParam = lParam;
2876 add_message(&msg);
2879 defwndproc_counter++;
2880 ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
2881 defwndproc_counter--;
2883 return ret;
2886 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
2888 static long defwndproc_counter = 0;
2889 LRESULT ret;
2890 struct message msg;
2892 /* do not log painting messages */
2893 if (message != WM_PAINT &&
2894 message != WM_NCPAINT &&
2895 message != WM_SYNCPAINT &&
2896 message != WM_ERASEBKGND &&
2897 message != WM_NCHITTEST &&
2898 message != WM_GETTEXT &&
2899 message != WM_GETICON &&
2900 message != WM_DEVICECHANGE)
2902 trace("mdi frame: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
2904 switch (message)
2906 case WM_WINDOWPOSCHANGING:
2907 case WM_WINDOWPOSCHANGED:
2909 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
2911 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2912 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2913 winpos->hwnd, winpos->hwndInsertAfter,
2914 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2915 dump_winpos_flags(winpos->flags);
2917 /* Log only documented flags, win2k uses 0x1000 and 0x2000
2918 * in the high word for internal purposes
2920 wParam = winpos->flags & 0xffff;
2921 /* We are not interested in the flags that don't match under XP and Win9x */
2922 wParam &= ~(SWP_NOZORDER);
2923 break;
2927 msg.message = message;
2928 msg.flags = sent|wparam|lparam;
2929 if (defwndproc_counter) msg.flags |= defwinproc;
2930 msg.wParam = wParam;
2931 msg.lParam = lParam;
2932 add_message(&msg);
2935 defwndproc_counter++;
2936 ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
2937 defwndproc_counter--;
2939 return ret;
2942 static BOOL mdi_RegisterWindowClasses(void)
2944 WNDCLASSA cls;
2946 cls.style = 0;
2947 cls.lpfnWndProc = mdi_frame_wnd_proc;
2948 cls.cbClsExtra = 0;
2949 cls.cbWndExtra = 0;
2950 cls.hInstance = GetModuleHandleA(0);
2951 cls.hIcon = 0;
2952 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
2953 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
2954 cls.lpszMenuName = NULL;
2955 cls.lpszClassName = "MDI_frame_class";
2956 if (!RegisterClassA(&cls)) return FALSE;
2958 cls.lpfnWndProc = mdi_child_wnd_proc;
2959 cls.lpszClassName = "MDI_child_class";
2960 if (!RegisterClassA(&cls)) return FALSE;
2962 if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
2963 old_mdi_client_proc = cls.lpfnWndProc;
2964 cls.hInstance = GetModuleHandleA(0);
2965 cls.lpfnWndProc = mdi_client_hook_proc;
2966 cls.lpszClassName = "MDI_client_class";
2967 if (!RegisterClassA(&cls)) assert(0);
2969 return TRUE;
2972 static void test_mdi_messages(void)
2974 MDICREATESTRUCTA mdi_cs;
2975 CLIENTCREATESTRUCT client_cs;
2976 HWND mdi_frame, mdi_child, mdi_child2, active_child;
2977 BOOL zoomed;
2978 HMENU hMenu = CreateMenu();
2980 assert(mdi_RegisterWindowClasses());
2982 flush_sequence();
2984 trace("creating MDI frame window\n");
2985 mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
2986 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2987 WS_MAXIMIZEBOX | WS_VISIBLE,
2988 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
2989 GetDesktopWindow(), hMenu,
2990 GetModuleHandleA(0), NULL);
2991 assert(mdi_frame);
2992 ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
2994 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
2995 ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
2997 trace("creating MDI client window\n");
2998 client_cs.hWindowMenu = 0;
2999 client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
3000 mdi_client = CreateWindowExA(0, "MDI_client_class",
3001 NULL,
3002 WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
3003 0, 0, 0, 0,
3004 mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3005 assert(mdi_client);
3006 ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
3008 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3009 ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
3011 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3012 ok(!active_child, "wrong active MDI child %p\n", active_child);
3013 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3015 SetFocus(0);
3016 flush_sequence();
3018 trace("creating invisible MDI child window\n");
3019 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3020 WS_CHILD,
3021 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3022 mdi_client, 0, GetModuleHandleA(0), NULL);
3023 assert(mdi_child);
3025 flush_sequence();
3026 ShowWindow(mdi_child, SW_SHOWNORMAL);
3027 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
3029 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3030 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3032 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3033 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3035 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3036 ok(!active_child, "wrong active MDI child %p\n", active_child);
3037 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3039 ShowWindow(mdi_child, SW_HIDE);
3040 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
3041 flush_sequence();
3043 ShowWindow(mdi_child, SW_SHOW);
3044 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
3046 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3047 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3049 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3050 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3052 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3053 ok(!active_child, "wrong active MDI child %p\n", active_child);
3054 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3056 DestroyWindow(mdi_child);
3057 flush_sequence();
3059 trace("creating visible MDI child window\n");
3060 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3061 WS_CHILD | WS_VISIBLE,
3062 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3063 mdi_client, 0, GetModuleHandleA(0), NULL);
3064 assert(mdi_child);
3065 ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
3067 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3068 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3070 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3071 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3073 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3074 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3075 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3076 flush_sequence();
3078 DestroyWindow(mdi_child);
3079 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3081 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3082 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3084 /* Win2k: MDI client still returns a just destroyed child as active
3085 * Win9x: MDI client returns 0
3087 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3088 ok(active_child == mdi_child || /* win2k */
3089 !active_child, /* win9x */
3090 "wrong active MDI child %p\n", active_child);
3091 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3093 flush_sequence();
3095 trace("creating invisible MDI child window\n");
3096 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3097 WS_CHILD,
3098 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3099 mdi_client, 0, GetModuleHandleA(0), NULL);
3100 assert(mdi_child2);
3101 ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
3103 ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
3104 ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
3106 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3107 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3109 /* Win2k: MDI client still returns a just destroyed child as active
3110 * Win9x: MDI client returns mdi_child2
3112 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3113 ok(active_child == mdi_child || /* win2k */
3114 active_child == mdi_child2, /* win9x */
3115 "wrong active MDI child %p\n", active_child);
3116 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3117 flush_sequence();
3119 ShowWindow(mdi_child2, SW_MAXIMIZE);
3120 ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3122 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3123 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3125 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3126 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3127 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3128 flush_sequence();
3130 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3131 ok(GetFocus() == mdi_child2 || /* win2k */
3132 GetFocus() == 0, /* win9x */
3133 "wrong focus window %p\n", GetFocus());
3135 SetFocus(0);
3136 flush_sequence();
3138 ShowWindow(mdi_child2, SW_HIDE);
3139 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3141 ShowWindow(mdi_child2, SW_RESTORE);
3142 ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3143 flush_sequence();
3145 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3146 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3148 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3149 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3150 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3151 flush_sequence();
3153 SetFocus(0);
3154 flush_sequence();
3156 ShowWindow(mdi_child2, SW_HIDE);
3157 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3159 ShowWindow(mdi_child2, SW_SHOW);
3160 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3162 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3163 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3165 ShowWindow(mdi_child2, SW_MAXIMIZE);
3166 ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3168 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3169 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3171 ShowWindow(mdi_child2, SW_RESTORE);
3172 ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3174 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3175 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3177 ShowWindow(mdi_child2, SW_MINIMIZE);
3178 ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3180 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3181 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3183 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3184 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3185 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3186 flush_sequence();
3188 ShowWindow(mdi_child2, SW_RESTORE);
3189 ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", TRUE);
3191 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3192 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3194 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3195 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3196 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3197 flush_sequence();
3199 SetFocus(0);
3200 flush_sequence();
3202 ShowWindow(mdi_child2, SW_HIDE);
3203 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3205 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3206 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3208 DestroyWindow(mdi_child2);
3209 ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3211 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3212 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3214 /* test for maximized MDI children */
3215 trace("creating maximized visible MDI child window 1\n");
3216 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3217 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3218 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3219 mdi_client, 0, GetModuleHandleA(0), NULL);
3220 assert(mdi_child);
3221 ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3222 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3224 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3225 ok(GetFocus() == mdi_child || /* win2k */
3226 GetFocus() == 0, /* win9x */
3227 "wrong focus window %p\n", GetFocus());
3229 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3230 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3231 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3232 flush_sequence();
3234 trace("creating maximized visible MDI child window 2\n");
3235 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3236 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3237 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3238 mdi_client, 0, GetModuleHandleA(0), NULL);
3239 assert(mdi_child2);
3240 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3241 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3242 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3244 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3245 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3247 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3248 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3249 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3250 flush_sequence();
3252 trace("destroying maximized visible MDI child window 2\n");
3253 DestroyWindow(mdi_child2);
3254 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3256 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3258 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3259 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3261 /* Win2k: MDI client still returns a just destroyed child as active
3262 * Win9x: MDI client returns 0
3264 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3265 ok(active_child == mdi_child2 || /* win2k */
3266 !active_child, /* win9x */
3267 "wrong active MDI child %p\n", active_child);
3268 flush_sequence();
3270 ShowWindow(mdi_child, SW_MAXIMIZE);
3271 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3272 flush_sequence();
3274 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3275 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3277 trace("re-creating maximized visible MDI child window 2\n");
3278 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3279 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3280 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3281 mdi_client, 0, GetModuleHandleA(0), NULL);
3282 assert(mdi_child2);
3283 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3284 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3285 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3287 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3288 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3290 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3291 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3292 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3293 flush_sequence();
3295 SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3296 ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3297 ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3299 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3300 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3301 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3303 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3304 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3305 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3306 flush_sequence();
3308 DestroyWindow(mdi_child);
3309 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3311 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3312 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3314 /* Win2k: MDI client still returns a just destroyed child as active
3315 * Win9x: MDI client returns 0
3317 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3318 ok(active_child == mdi_child || /* win2k */
3319 !active_child, /* win9x */
3320 "wrong active MDI child %p\n", active_child);
3321 flush_sequence();
3323 trace("creating maximized invisible MDI child window\n");
3324 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3325 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3326 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3327 mdi_client, 0, GetModuleHandleA(0), NULL);
3328 assert(mdi_child2);
3329 ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", TRUE);
3330 ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3331 ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3332 ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3334 /* Win2k: MDI client still returns a just destroyed child as active
3335 * Win9x: MDI client returns 0
3337 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3338 ok(active_child == mdi_child || /* win2k */
3339 !active_child, /* win9x */
3340 "wrong active MDI child %p\n", active_child);
3341 flush_sequence();
3343 trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3344 ShowWindow(mdi_child2, SW_MAXIMIZE);
3345 ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3346 ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3347 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3348 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3350 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3351 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3352 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3353 flush_sequence();
3355 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3356 flush_sequence();
3358 /* end of test for maximized MDI children */
3359 SetFocus(0);
3360 flush_sequence();
3361 trace("creating maximized visible MDI child window 1(Switch test)\n");
3362 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3363 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3364 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3365 mdi_client, 0, GetModuleHandleA(0), NULL);
3366 assert(mdi_child);
3367 ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3368 ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3370 ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3371 ok(GetFocus() == mdi_child || /* win2k */
3372 GetFocus() == 0, /* win9x */
3373 "wrong focus window %p(Switch test)\n", GetFocus());
3375 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3376 ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3377 ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3378 flush_sequence();
3380 trace("creating maximized visible MDI child window 2(Switch test)\n");
3381 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3382 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3383 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3384 mdi_client, 0, GetModuleHandleA(0), NULL);
3385 assert(mdi_child2);
3386 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3388 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3389 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3391 ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3392 ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3394 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3395 ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3396 ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3397 flush_sequence();
3399 trace("Switch child window.\n");
3400 SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3401 ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3402 trace("end of test for switch maximized MDI children\n");
3403 flush_sequence();
3405 /* Prepare for switching test of not maximized MDI children */
3406 ShowWindow( mdi_child, SW_NORMAL );
3407 ok(!IsZoomed(mdi_child), "wrong zoomed state for %p(Switch test)\n", mdi_child);
3408 ok(!IsZoomed(mdi_child2), "wrong zoomed state for %p(Switch test)\n", mdi_child2);
3409 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
3410 ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3411 flush_sequence();
3413 SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child2, 0);
3414 ok_sequence(WmSwitchNotMaximizedChild, "Not maximized child did not switch correctly", TRUE);
3415 trace("end of test for switch not maximized MDI children\n");
3416 flush_sequence();
3418 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3419 flush_sequence();
3421 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3422 flush_sequence();
3424 SetFocus(0);
3425 flush_sequence();
3426 /* end of tests for switch maximized/not maximized MDI children */
3428 mdi_cs.szClass = "MDI_child_Class";
3429 mdi_cs.szTitle = "MDI child";
3430 mdi_cs.hOwner = GetModuleHandleA(0);
3431 mdi_cs.x = 0;
3432 mdi_cs.y = 0;
3433 mdi_cs.cx = CW_USEDEFAULT;
3434 mdi_cs.cy = CW_USEDEFAULT;
3435 mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3436 mdi_cs.lParam = 0;
3437 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3438 ok(mdi_child != 0, "MDI child creation failed\n");
3439 ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3441 ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3443 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3444 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3446 ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3447 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3448 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3450 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3451 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3452 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3453 flush_sequence();
3455 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3456 ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3458 ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3459 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3460 ok(!active_child, "wrong active MDI child %p\n", active_child);
3462 SetFocus(0);
3463 flush_sequence();
3465 DestroyWindow(mdi_client);
3466 ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3468 /* test maximization of MDI child with invisible parent */
3469 client_cs.hWindowMenu = 0;
3470 mdi_client = CreateWindow("MDI_client_class",
3471 NULL,
3472 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3473 0, 0, 660, 430,
3474 mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3475 ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3477 ShowWindow(mdi_client, SW_HIDE);
3478 ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3480 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3481 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3482 0, 0, 650, 440,
3483 mdi_client, 0, GetModuleHandleA(0), NULL);
3484 ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3486 SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3487 ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3488 zoomed = IsZoomed(mdi_child);
3489 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3491 ShowWindow(mdi_client, SW_SHOW);
3492 ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3494 DestroyWindow(mdi_child);
3495 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3497 /* end of test for maximization of MDI child with invisible parent */
3499 DestroyWindow(mdi_client);
3500 ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3502 DestroyWindow(mdi_frame);
3503 ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3505 /************************* End of MDI test **********************************/
3507 static void test_WM_SETREDRAW(HWND hwnd)
3509 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3511 flush_sequence();
3513 SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3514 ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3516 ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3517 ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3519 flush_sequence();
3520 SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3521 ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3523 ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3524 ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3526 /* restore original WS_VISIBLE state */
3527 SetWindowLongA(hwnd, GWL_STYLE, style);
3529 flush_sequence();
3532 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3534 struct message msg;
3536 trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
3538 /* explicitly ignore WM_GETICON message */
3539 if (message == WM_GETICON) return 0;
3541 switch (message)
3543 /* ignore */
3544 case WM_MOUSEMOVE:
3545 case WM_SETCURSOR:
3546 case WM_DEVICECHANGE:
3547 return 0;
3548 case WM_NCHITTEST:
3549 return HTCLIENT;
3551 case WM_WINDOWPOSCHANGING:
3552 case WM_WINDOWPOSCHANGED:
3554 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
3556 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
3557 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
3558 winpos->hwnd, winpos->hwndInsertAfter,
3559 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
3560 dump_winpos_flags(winpos->flags);
3562 /* Log only documented flags, win2k uses 0x1000 and 0x2000
3563 * in the high word for internal purposes
3565 wParam = winpos->flags & 0xffff;
3566 /* We are not interested in the flags that don't match under XP and Win9x */
3567 wParam &= ~(SWP_NOZORDER);
3568 break;
3572 msg.message = message;
3573 msg.flags = sent|wparam|lparam;
3574 msg.wParam = wParam;
3575 msg.lParam = lParam;
3576 add_message(&msg);
3578 if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3579 if (message == WM_TIMER) EndDialog( hwnd, 0 );
3580 return 0;
3583 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3585 DWORD style, exstyle;
3586 INT xmin, xmax;
3587 BOOL ret;
3589 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3590 style = GetWindowLongA(hwnd, GWL_STYLE);
3591 /* do not be confused by WS_DLGFRAME set */
3592 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3594 if (clear) ok(style & clear, "style %08x should be set\n", clear);
3595 if (set) ok(!(style & set), "style %08x should not be set\n", set);
3597 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3598 ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3599 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3600 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3601 else
3602 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3604 style = GetWindowLongA(hwnd, GWL_STYLE);
3605 if (set) ok(style & set, "style %08x should be set\n", set);
3606 if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3608 /* a subsequent call should do nothing */
3609 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3610 ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3611 ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3613 xmin = 0xdeadbeef;
3614 xmax = 0xdeadbeef;
3615 trace("Ignore GetScrollRange error below if you are on Win9x\n");
3616 ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
3617 ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
3618 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3619 ok(xmin == min, "unexpected min scroll value %d\n", xmin);
3620 ok(xmax == max, "unexpected max scroll value %d\n", xmax);
3623 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3625 DWORD style, exstyle;
3626 SCROLLINFO si;
3627 BOOL ret;
3629 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3630 style = GetWindowLongA(hwnd, GWL_STYLE);
3631 /* do not be confused by WS_DLGFRAME set */
3632 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3634 if (clear) ok(style & clear, "style %08x should be set\n", clear);
3635 if (set) ok(!(style & set), "style %08x should not be set\n", set);
3637 si.cbSize = sizeof(si);
3638 si.fMask = SIF_RANGE;
3639 si.nMin = min;
3640 si.nMax = max;
3641 SetScrollInfo(hwnd, ctl, &si, TRUE);
3642 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3643 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
3644 else
3645 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
3647 style = GetWindowLongA(hwnd, GWL_STYLE);
3648 if (set) ok(style & set, "style %08x should be set\n", set);
3649 if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3651 /* a subsequent call should do nothing */
3652 SetScrollInfo(hwnd, ctl, &si, TRUE);
3653 if (style & WS_HSCROLL)
3654 ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3655 else if (style & WS_VSCROLL)
3656 ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3657 else
3658 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3660 si.fMask = SIF_PAGE;
3661 si.nPage = 5;
3662 SetScrollInfo(hwnd, ctl, &si, FALSE);
3663 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3665 si.fMask = SIF_POS;
3666 si.nPos = max - 1;
3667 SetScrollInfo(hwnd, ctl, &si, FALSE);
3668 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
3670 si.fMask = SIF_RANGE;
3671 si.nMin = 0xdeadbeef;
3672 si.nMax = 0xdeadbeef;
3673 ret = GetScrollInfo(hwnd, ctl, &si);
3674 ok( ret, "GetScrollInfo error %d\n", GetLastError());
3675 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3676 ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
3677 ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
3680 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
3681 static void test_scroll_messages(HWND hwnd)
3683 SCROLLINFO si;
3684 INT min, max;
3685 BOOL ret;
3687 min = 0xdeadbeef;
3688 max = 0xdeadbeef;
3689 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3690 ok( ret, "GetScrollRange error %d\n", GetLastError());
3691 if (sequence->message != WmGetScrollRangeSeq[0].message)
3692 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3693 /* values of min and max are undefined */
3694 flush_sequence();
3696 ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
3697 ok( ret, "SetScrollRange error %d\n", GetLastError());
3698 if (sequence->message != WmSetScrollRangeSeq[0].message)
3699 trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3700 flush_sequence();
3702 min = 0xdeadbeef;
3703 max = 0xdeadbeef;
3704 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
3705 ok( ret, "GetScrollRange error %d\n", GetLastError());
3706 if (sequence->message != WmGetScrollRangeSeq[0].message)
3707 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
3708 /* values of min and max are undefined */
3709 flush_sequence();
3711 si.cbSize = sizeof(si);
3712 si.fMask = SIF_RANGE;
3713 si.nMin = 20;
3714 si.nMax = 160;
3715 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3716 if (sequence->message != WmSetScrollRangeSeq[0].message)
3717 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3718 flush_sequence();
3720 si.fMask = SIF_PAGE;
3721 si.nPage = 10;
3722 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3723 if (sequence->message != WmSetScrollRangeSeq[0].message)
3724 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3725 flush_sequence();
3727 si.fMask = SIF_POS;
3728 si.nPos = 20;
3729 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
3730 if (sequence->message != WmSetScrollRangeSeq[0].message)
3731 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3732 flush_sequence();
3734 si.fMask = SIF_RANGE;
3735 si.nMin = 0xdeadbeef;
3736 si.nMax = 0xdeadbeef;
3737 ret = GetScrollInfo(hwnd, SB_CTL, &si);
3738 ok( ret, "GetScrollInfo error %d\n", GetLastError());
3739 if (sequence->message != WmGetScrollInfoSeq[0].message)
3740 trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
3741 /* values of min and max are undefined */
3742 flush_sequence();
3744 /* set WS_HSCROLL */
3745 test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
3746 /* clear WS_HSCROLL */
3747 test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
3749 /* set WS_HSCROLL */
3750 test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
3751 /* clear WS_HSCROLL */
3752 test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
3754 /* set WS_VSCROLL */
3755 test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
3756 /* clear WS_VSCROLL */
3757 test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
3759 /* set WS_VSCROLL */
3760 test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
3761 /* clear WS_VSCROLL */
3762 test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
3765 static void test_showwindow(void)
3767 HWND hwnd, hchild;
3768 RECT rc;
3770 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
3771 100, 100, 200, 200, 0, 0, 0, NULL);
3772 ok (hwnd != 0, "Failed to create overlapped window\n");
3773 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
3774 0, 0, 10, 10, hwnd, 0, 0, NULL);
3775 ok (hchild != 0, "Failed to create child\n");
3776 flush_sequence();
3778 /* ShowWindow( SW_SHOWNA) for invisible top level window */
3779 trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
3780 ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3781 ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", TRUE);
3782 trace("done\n");
3784 /* ShowWindow( SW_SHOWNA) for now visible top level window */
3785 trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
3786 ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3787 ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
3788 trace("done\n");
3789 /* back to invisible */
3790 ShowWindow(hchild, SW_HIDE);
3791 ShowWindow(hwnd, SW_HIDE);
3792 flush_sequence();
3793 /* ShowWindow(SW_SHOWNA) with child and parent invisible */
3794 trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
3795 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3796 ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
3797 trace("done\n");
3798 /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */
3799 ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
3800 flush_sequence();
3801 trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
3802 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3803 ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
3804 trace("done\n");
3805 /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
3806 ShowWindow( hwnd, SW_SHOW);
3807 flush_sequence();
3808 trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
3809 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
3810 ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
3811 trace("done\n");
3813 /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
3814 ShowWindow( hchild, SW_HIDE);
3815 flush_sequence();
3816 trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
3817 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
3818 ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
3819 trace("done\n");
3821 SetCapture(hchild);
3822 ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
3823 DestroyWindow(hchild);
3824 ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
3826 DestroyWindow(hwnd);
3827 flush_sequence();
3829 /* Popup windows */
3830 /* Test 1:
3831 * 1. Create invisible maximized popup window.
3832 * 2. Move and resize it.
3833 * 3. Show it maximized.
3835 trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
3836 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
3837 100, 100, 200, 200, 0, 0, 0, NULL);
3838 ok (hwnd != 0, "Failed to create popup window\n");
3839 ok(IsZoomed(hwnd), "window should be maximized\n");
3840 ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
3841 trace("done\n");
3843 GetWindowRect(hwnd, &rc);
3844 ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
3845 rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
3846 "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
3847 rc.left, rc.top, rc.right, rc.bottom);
3848 /* Reset window's size & position */
3849 SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
3850 ok(IsZoomed(hwnd), "window should be maximized\n");
3851 flush_sequence();
3853 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
3854 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3855 ok(IsZoomed(hwnd), "window should be maximized\n");
3856 ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
3857 trace("done\n");
3859 GetWindowRect(hwnd, &rc);
3860 ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
3861 rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
3862 "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
3863 rc.left, rc.top, rc.right, rc.bottom);
3864 DestroyWindow(hwnd);
3865 flush_sequence();
3867 /* Test 2:
3868 * 1. Create invisible maximized popup window.
3869 * 2. Show it maximized.
3871 trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
3872 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
3873 100, 100, 200, 200, 0, 0, 0, NULL);
3874 ok (hwnd != 0, "Failed to create popup window\n");
3875 ok(IsZoomed(hwnd), "window should be maximized\n");
3876 ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
3877 trace("done\n");
3879 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
3880 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3881 ok(IsZoomed(hwnd), "window should be maximized\n");
3882 ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
3883 trace("done\n");
3884 DestroyWindow(hwnd);
3885 flush_sequence();
3887 /* Test 3:
3888 * 1. Create visible maximized popup window.
3890 trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
3891 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
3892 100, 100, 200, 200, 0, 0, 0, NULL);
3893 ok (hwnd != 0, "Failed to create popup window\n");
3894 ok(IsZoomed(hwnd), "window should be maximized\n");
3895 ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
3896 trace("done\n");
3897 DestroyWindow(hwnd);
3898 flush_sequence();
3900 /* Test 4:
3901 * 1. Create visible popup window.
3902 * 2. Maximize it.
3904 trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
3905 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
3906 100, 100, 200, 200, 0, 0, 0, NULL);
3907 ok (hwnd != 0, "Failed to create popup window\n");
3908 ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
3909 ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
3910 trace("done\n");
3912 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
3913 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
3914 ok(IsZoomed(hwnd), "window should be maximized\n");
3915 ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
3916 trace("done\n");
3917 DestroyWindow(hwnd);
3918 flush_sequence();
3921 static void test_sys_menu(void)
3923 HWND hwnd;
3924 HMENU hmenu;
3925 UINT state;
3927 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
3928 100, 100, 200, 200, 0, 0, 0, NULL);
3929 ok (hwnd != 0, "Failed to create overlapped window\n");
3931 flush_sequence();
3933 /* test existing window without CS_NOCLOSE style */
3934 hmenu = GetSystemMenu(hwnd, FALSE);
3935 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
3937 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3938 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3939 ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
3941 EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
3942 ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
3944 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3945 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3946 ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
3948 EnableMenuItem(hmenu, SC_CLOSE, 0);
3949 ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
3951 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3952 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3953 ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
3955 /* test whether removing WS_SYSMENU destroys a system menu */
3956 SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
3957 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
3958 flush_sequence();
3959 hmenu = GetSystemMenu(hwnd, FALSE);
3960 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
3962 DestroyWindow(hwnd);
3964 /* test new window with CS_NOCLOSE style */
3965 hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
3966 100, 100, 200, 200, 0, 0, 0, NULL);
3967 ok (hwnd != 0, "Failed to create overlapped window\n");
3969 hmenu = GetSystemMenu(hwnd, FALSE);
3970 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
3972 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
3973 ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
3975 DestroyWindow(hwnd);
3977 /* test new window without WS_SYSMENU style */
3978 hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
3979 100, 100, 200, 200, 0, 0, 0, NULL);
3980 ok(hwnd != 0, "Failed to create overlapped window\n");
3982 hmenu = GetSystemMenu(hwnd, FALSE);
3983 ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
3985 DestroyWindow(hwnd);
3988 /* For shown WS_OVERLAPPEDWINDOW */
3989 static const struct message WmSetIcon_1[] = {
3990 { WM_SETICON, sent },
3991 { 0x00AE, sent|defwinproc|optional }, /* XP */
3992 { WM_GETTEXT, sent|defwinproc|optional },
3993 { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
3994 { 0 }
3997 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
3998 static const struct message WmSetIcon_2[] = {
3999 { WM_SETICON, sent },
4000 { 0 }
4003 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4004 static const struct message WmInitEndSession[] = {
4005 { 0x003B, sent },
4006 { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4007 { 0 }
4010 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4011 static const struct message WmInitEndSession_2[] = {
4012 { 0x003B, sent },
4013 { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4014 { 0 }
4017 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4018 static const struct message WmInitEndSession_3[] = {
4019 { 0x003B, sent },
4020 { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4021 { 0 }
4024 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4025 static const struct message WmInitEndSession_4[] = {
4026 { 0x003B, sent },
4027 { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4028 { 0 }
4031 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4032 static const struct message WmInitEndSession_5[] = {
4033 { 0x003B, sent },
4034 { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 1, ENDSESSION_LOGOFF },
4035 { 0 }
4038 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4040 DWORD ret;
4041 MSG msg;
4043 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4044 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4046 PostMessageA(hwnd, WM_USER, 0, 0);
4048 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4049 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4051 ok(PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4052 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4054 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4055 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4057 PostMessageA(hwnd, WM_USER, 0, 0);
4059 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4060 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4062 ok(PeekMessageW( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4063 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4065 /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4066 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4067 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4069 PostMessageA(hwnd, WM_USER, 0, 0);
4071 /* new incoming message causes it to become signaled again */
4072 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4073 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4075 ok(PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4076 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4077 ok(PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4078 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4081 /* test if we receive the right sequence of messages */
4082 static void test_messages(void)
4084 HWND hwnd, hparent, hchild;
4085 HWND hchild2, hbutton;
4086 HMENU hmenu;
4087 MSG msg;
4088 LRESULT res;
4090 flush_sequence();
4092 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4093 100, 100, 200, 200, 0, 0, 0, NULL);
4094 ok (hwnd != 0, "Failed to create overlapped window\n");
4095 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4097 /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4098 ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4099 ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4101 /* test WM_SETREDRAW on a not visible top level window */
4102 test_WM_SETREDRAW(hwnd);
4104 SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4105 ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4106 ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4108 ok(GetActiveWindow() == hwnd, "window should be active\n");
4109 ok(GetFocus() == hwnd, "window should have input focus\n");
4110 ShowWindow(hwnd, SW_HIDE);
4111 ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", TRUE);
4113 ShowWindow(hwnd, SW_SHOW);
4114 ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4116 ShowWindow(hwnd, SW_HIDE);
4117 ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4119 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4120 ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4122 ShowWindow(hwnd, SW_RESTORE);
4123 /* FIXME: add ok_sequence() here */
4124 flush_sequence();
4126 ShowWindow(hwnd, SW_MINIMIZE);
4127 ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4128 flush_sequence();
4130 ShowWindow(hwnd, SW_RESTORE);
4131 /* FIXME: add ok_sequence() here */
4132 flush_sequence();
4134 ShowWindow(hwnd, SW_SHOW);
4135 ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4137 ok(GetActiveWindow() == hwnd, "window should be active\n");
4138 ok(GetFocus() == hwnd, "window should have input focus\n");
4139 SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4140 ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4141 ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4142 ok(GetActiveWindow() == hwnd, "window should still be active\n");
4144 /* test WM_SETREDRAW on a visible top level window */
4145 ShowWindow(hwnd, SW_SHOW);
4146 test_WM_SETREDRAW(hwnd);
4148 trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4149 test_scroll_messages(hwnd);
4151 /* test resizing and moving */
4152 SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4153 ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4154 flush_events();
4155 flush_sequence();
4156 SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4157 ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4158 flush_events();
4159 flush_sequence();
4160 SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER );
4161 ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4162 flush_events();
4163 flush_sequence();
4165 /* popups don't get WM_GETMINMAXINFO */
4166 SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4167 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4168 flush_sequence();
4169 SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4170 ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4172 DestroyWindow(hwnd);
4173 ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4175 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4176 100, 100, 200, 200, 0, 0, 0, NULL);
4177 ok (hparent != 0, "Failed to create parent window\n");
4178 flush_sequence();
4180 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4181 0, 0, 10, 10, hparent, 0, 0, NULL);
4182 ok (hchild != 0, "Failed to create child window\n");
4183 ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4184 DestroyWindow(hchild);
4185 flush_sequence();
4187 /* visible child window with a caption */
4188 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4189 WS_CHILD | WS_VISIBLE | WS_CAPTION,
4190 0, 0, 10, 10, hparent, 0, 0, NULL);
4191 ok (hchild != 0, "Failed to create child window\n");
4192 ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4194 trace("testing scroll APIs on a visible child window %p\n", hchild);
4195 test_scroll_messages(hchild);
4197 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4198 ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4200 DestroyWindow(hchild);
4201 flush_sequence();
4203 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4204 0, 0, 10, 10, hparent, 0, 0, NULL);
4205 ok (hchild != 0, "Failed to create child window\n");
4206 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4208 hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4209 100, 100, 50, 50, hparent, 0, 0, NULL);
4210 ok (hchild2 != 0, "Failed to create child2 window\n");
4211 flush_sequence();
4213 hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4214 0, 100, 50, 50, hchild, 0, 0, NULL);
4215 ok (hbutton != 0, "Failed to create button window\n");
4217 /* test WM_SETREDRAW on a not visible child window */
4218 test_WM_SETREDRAW(hchild);
4220 ShowWindow(hchild, SW_SHOW);
4221 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4223 /* check parent messages too */
4224 log_all_parent_messages++;
4225 ShowWindow(hchild, SW_HIDE);
4226 ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4227 log_all_parent_messages--;
4229 ShowWindow(hchild, SW_SHOW);
4230 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4232 ShowWindow(hchild, SW_HIDE);
4233 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4235 ShowWindow(hchild, SW_SHOW);
4236 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4238 /* test WM_SETREDRAW on a visible child window */
4239 test_WM_SETREDRAW(hchild);
4241 log_all_parent_messages++;
4242 MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4243 ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4244 log_all_parent_messages--;
4246 ShowWindow(hchild, SW_HIDE);
4247 flush_sequence();
4248 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4249 ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4251 ShowWindow(hchild, SW_HIDE);
4252 flush_sequence();
4253 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4254 ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4256 /* DestroyWindow sequence below expects that a child has focus */
4257 SetFocus(hchild);
4258 flush_sequence();
4260 DestroyWindow(hchild);
4261 ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4262 DestroyWindow(hchild2);
4263 DestroyWindow(hbutton);
4265 flush_sequence();
4266 hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4267 0, 0, 100, 100, hparent, 0, 0, NULL);
4268 ok (hchild != 0, "Failed to create child popup window\n");
4269 ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4270 DestroyWindow(hchild);
4272 /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4273 flush_sequence();
4274 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4275 0, 0, 100, 100, hparent, 0, 0, NULL);
4276 ok (hchild != 0, "Failed to create popup window\n");
4277 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4278 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4279 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4280 flush_sequence();
4281 ShowWindow(hchild, SW_SHOW);
4282 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4283 flush_sequence();
4284 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4285 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4286 flush_sequence();
4287 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4288 ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", TRUE);
4289 DestroyWindow(hchild);
4291 /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4292 * changes nothing in message sequences.
4294 flush_sequence();
4295 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4296 0, 0, 100, 100, hparent, 0, 0, NULL);
4297 ok (hchild != 0, "Failed to create popup window\n");
4298 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4299 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4300 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4301 flush_sequence();
4302 ShowWindow(hchild, SW_SHOW);
4303 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4304 flush_sequence();
4305 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4306 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4307 DestroyWindow(hchild);
4309 flush_sequence();
4310 hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4311 0, 0, 100, 100, hparent, 0, 0, NULL);
4312 ok(hwnd != 0, "Failed to create custom dialog window\n");
4313 ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4316 trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4317 test_scroll_messages(hwnd);
4320 flush_sequence();
4322 test_def_id = 1;
4323 SendMessage(hwnd, WM_NULL, 0, 0);
4325 flush_sequence();
4326 after_end_dialog = 1;
4327 EndDialog( hwnd, 0 );
4328 ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4330 DestroyWindow(hwnd);
4331 after_end_dialog = 0;
4332 test_def_id = 0;
4334 hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4335 0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4336 ok(hwnd != 0, "Failed to create custom dialog window\n");
4337 flush_sequence();
4338 trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4339 ShowWindow(hwnd, SW_SHOW);
4340 ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4341 DestroyWindow(hwnd);
4343 flush_sequence();
4344 DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4345 ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4347 DestroyWindow(hparent);
4348 flush_sequence();
4350 /* Message sequence for SetMenu */
4351 ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4352 ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4354 hmenu = CreateMenu();
4355 ok (hmenu != 0, "Failed to create menu\n");
4356 ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4357 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4358 100, 100, 200, 200, 0, hmenu, 0, NULL);
4359 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4360 ok (SetMenu(hwnd, 0), "SetMenu\n");
4361 ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4362 ok (SetMenu(hwnd, 0), "SetMenu\n");
4363 ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4364 ShowWindow(hwnd, SW_SHOW);
4365 UpdateWindow( hwnd );
4366 flush_events();
4367 flush_sequence();
4368 ok (SetMenu(hwnd, 0), "SetMenu\n");
4369 ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4370 ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4371 ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4373 UpdateWindow( hwnd );
4374 flush_events();
4375 flush_sequence();
4376 ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4377 flush_events();
4378 ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4380 DestroyWindow(hwnd);
4381 flush_sequence();
4383 /* Message sequence for EnableWindow */
4384 hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4385 100, 100, 200, 200, 0, 0, 0, NULL);
4386 ok (hparent != 0, "Failed to create parent window\n");
4387 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4388 0, 0, 10, 10, hparent, 0, 0, NULL);
4389 ok (hchild != 0, "Failed to create child window\n");
4391 SetFocus(hchild);
4392 flush_events();
4393 flush_sequence();
4395 EnableWindow(hparent, FALSE);
4396 ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4398 EnableWindow(hparent, TRUE);
4399 ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4401 flush_events();
4402 flush_sequence();
4404 test_MsgWaitForMultipleObjects(hparent);
4406 /* the following test causes an exception in user.exe under win9x */
4407 if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4409 DestroyWindow(hparent);
4410 flush_sequence();
4411 return;
4413 PostMessageW( hparent, WM_USER+1, 0, 0 );
4414 /* PeekMessage(NULL) fails, but still removes the message */
4415 SetLastError(0xdeadbeef);
4416 ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4417 ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4418 GetLastError() == 0xdeadbeef, /* NT4 */
4419 "last error is %d\n", GetLastError() );
4420 ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4421 ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4423 DestroyWindow(hchild);
4424 DestroyWindow(hparent);
4425 flush_sequence();
4427 /* Message sequences for WM_SETICON */
4428 trace("testing WM_SETICON\n");
4429 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4430 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4431 NULL, NULL, 0);
4432 ShowWindow(hwnd, SW_SHOW);
4433 UpdateWindow(hwnd);
4434 flush_events();
4435 flush_sequence();
4436 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4437 ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4439 ShowWindow(hwnd, SW_HIDE);
4440 flush_events();
4441 flush_sequence();
4442 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4443 ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4444 DestroyWindow(hwnd);
4445 flush_sequence();
4447 hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4448 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4449 NULL, NULL, 0);
4450 ShowWindow(hwnd, SW_SHOW);
4451 UpdateWindow(hwnd);
4452 flush_events();
4453 flush_sequence();
4454 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4455 ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4457 ShowWindow(hwnd, SW_HIDE);
4458 flush_events();
4459 flush_sequence();
4460 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4461 ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4463 flush_sequence();
4464 res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4465 ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4466 todo_wine
4467 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4468 res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4469 ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4470 todo_wine
4471 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4472 res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4473 ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4474 todo_wine
4475 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4477 flush_sequence();
4478 res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4479 ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4480 todo_wine
4481 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4482 res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4483 ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4484 todo_wine
4485 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4487 res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4488 ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4489 todo_wine
4490 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4492 res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4493 ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4494 todo_wine
4495 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4497 DestroyWindow(hwnd);
4498 flush_sequence();
4501 static void invisible_parent_tests(void)
4503 HWND hparent, hchild;
4505 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4506 100, 100, 200, 200, 0, 0, 0, NULL);
4507 ok (hparent != 0, "Failed to create parent window\n");
4508 flush_sequence();
4510 /* test showing child with hidden parent */
4512 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4513 0, 0, 10, 10, hparent, 0, 0, NULL);
4514 ok (hchild != 0, "Failed to create child window\n");
4515 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4517 ShowWindow( hchild, SW_MINIMIZE );
4518 ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4519 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4520 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4522 /* repeat */
4523 flush_events();
4524 flush_sequence();
4525 ShowWindow( hchild, SW_MINIMIZE );
4526 ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4528 DestroyWindow(hchild);
4529 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4530 0, 0, 10, 10, hparent, 0, 0, NULL);
4531 flush_sequence();
4533 ShowWindow( hchild, SW_MAXIMIZE );
4534 ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4535 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4536 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4538 /* repeat */
4539 flush_events();
4540 flush_sequence();
4541 ShowWindow( hchild, SW_MAXIMIZE );
4542 ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4544 DestroyWindow(hchild);
4545 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4546 0, 0, 10, 10, hparent, 0, 0, NULL);
4547 flush_sequence();
4549 ShowWindow( hchild, SW_RESTORE );
4550 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
4551 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4552 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4554 DestroyWindow(hchild);
4555 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4556 0, 0, 10, 10, hparent, 0, 0, NULL);
4557 flush_sequence();
4559 ShowWindow( hchild, SW_SHOWMINIMIZED );
4560 ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4561 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4562 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4564 /* repeat */
4565 flush_events();
4566 flush_sequence();
4567 ShowWindow( hchild, SW_SHOWMINIMIZED );
4568 ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4570 DestroyWindow(hchild);
4571 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4572 0, 0, 10, 10, hparent, 0, 0, NULL);
4573 flush_sequence();
4575 /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
4576 ShowWindow( hchild, SW_SHOWMAXIMIZED );
4577 ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
4578 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4579 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4581 DestroyWindow(hchild);
4582 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4583 0, 0, 10, 10, hparent, 0, 0, NULL);
4584 flush_sequence();
4586 ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4587 ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4588 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4589 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4591 /* repeat */
4592 flush_events();
4593 flush_sequence();
4594 ShowWindow( hchild, SW_SHOWMINNOACTIVE );
4595 ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
4597 DestroyWindow(hchild);
4598 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4599 0, 0, 10, 10, hparent, 0, 0, NULL);
4600 flush_sequence();
4602 /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
4603 ShowWindow( hchild, SW_FORCEMINIMIZE );
4604 ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
4605 todo_wine {
4606 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4608 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4610 DestroyWindow(hchild);
4611 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4612 0, 0, 10, 10, hparent, 0, 0, NULL);
4613 flush_sequence();
4615 ShowWindow( hchild, SW_SHOWNA );
4616 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4617 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4618 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4620 /* repeat */
4621 flush_events();
4622 flush_sequence();
4623 ShowWindow( hchild, SW_SHOWNA );
4624 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
4626 DestroyWindow(hchild);
4627 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4628 0, 0, 10, 10, hparent, 0, 0, NULL);
4629 flush_sequence();
4631 ShowWindow( hchild, SW_SHOW );
4632 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4633 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4634 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4636 /* repeat */
4637 flush_events();
4638 flush_sequence();
4639 ShowWindow( hchild, SW_SHOW );
4640 ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
4642 ShowWindow( hchild, SW_HIDE );
4643 ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
4644 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
4645 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4647 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4648 ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
4649 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4650 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4652 SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4653 ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
4654 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
4655 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4657 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4658 flush_sequence();
4659 DestroyWindow(hchild);
4660 ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
4662 DestroyWindow(hparent);
4663 flush_sequence();
4666 /****************** button message test *************************/
4667 static const struct message WmSetFocusButtonSeq[] =
4669 { HCBT_SETFOCUS, hook },
4670 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
4671 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4672 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4673 { WM_SETFOCUS, sent|wparam, 0 },
4674 { WM_CTLCOLORBTN, sent|defwinproc },
4675 { 0 }
4677 static const struct message WmKillFocusButtonSeq[] =
4679 { HCBT_SETFOCUS, hook },
4680 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4681 { WM_KILLFOCUS, sent|wparam, 0 },
4682 { WM_CTLCOLORBTN, sent|defwinproc },
4683 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
4684 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
4685 { 0 }
4687 static const struct message WmSetFocusStaticSeq[] =
4689 { HCBT_SETFOCUS, hook },
4690 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
4691 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4692 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4693 { WM_SETFOCUS, sent|wparam, 0 },
4694 { WM_CTLCOLORSTATIC, sent|defwinproc },
4695 { 0 }
4697 static const struct message WmKillFocusStaticSeq[] =
4699 { HCBT_SETFOCUS, hook },
4700 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4701 { WM_KILLFOCUS, sent|wparam, 0 },
4702 { WM_CTLCOLORSTATIC, sent|defwinproc },
4703 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
4704 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
4705 { 0 }
4707 static const struct message WmLButtonDownSeq[] =
4709 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
4710 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
4711 { HCBT_SETFOCUS, hook },
4712 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4713 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4714 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4715 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4716 { WM_CTLCOLORBTN, sent|defwinproc },
4717 { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
4718 { WM_CTLCOLORBTN, sent|defwinproc },
4719 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4720 { 0 }
4722 static const struct message WmLButtonUpSeq[] =
4724 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
4725 { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
4726 { WM_CTLCOLORBTN, sent|defwinproc },
4727 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
4728 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
4729 { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
4730 { 0 }
4732 static const struct message WmSetFontButtonSeq[] =
4734 { WM_SETFONT, sent },
4735 { WM_PAINT, sent },
4736 { WM_ERASEBKGND, sent|defwinproc|optional },
4737 { WM_CTLCOLORBTN, sent|defwinproc },
4738 { 0 }
4741 static WNDPROC old_button_proc;
4743 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4745 static long defwndproc_counter = 0;
4746 LRESULT ret;
4747 struct message msg;
4749 trace("button: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
4751 /* explicitly ignore WM_GETICON message */
4752 if (message == WM_GETICON) return 0;
4754 msg.message = message;
4755 msg.flags = sent|wparam|lparam;
4756 if (defwndproc_counter) msg.flags |= defwinproc;
4757 msg.wParam = wParam;
4758 msg.lParam = lParam;
4759 add_message(&msg);
4761 if (message == BM_SETSTATE)
4762 ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
4764 defwndproc_counter++;
4765 ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
4766 defwndproc_counter--;
4768 return ret;
4771 static void subclass_button(void)
4773 WNDCLASSA cls;
4775 if (!GetClassInfoA(0, "button", &cls)) assert(0);
4777 old_button_proc = cls.lpfnWndProc;
4779 cls.hInstance = GetModuleHandle(0);
4780 cls.lpfnWndProc = button_hook_proc;
4781 cls.lpszClassName = "my_button_class";
4782 UnregisterClass(cls.lpszClassName, cls.hInstance);
4783 if (!RegisterClassA(&cls)) assert(0);
4786 static void test_button_messages(void)
4788 static const struct
4790 DWORD style;
4791 DWORD dlg_code;
4792 const struct message *setfocus;
4793 const struct message *killfocus;
4794 } button[] = {
4795 { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
4796 WmSetFocusButtonSeq, WmKillFocusButtonSeq },
4797 { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
4798 WmSetFocusButtonSeq, WmKillFocusButtonSeq },
4799 { BS_CHECKBOX, DLGC_BUTTON,
4800 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4801 { BS_AUTOCHECKBOX, DLGC_BUTTON,
4802 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4803 { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
4804 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4805 { BS_3STATE, DLGC_BUTTON,
4806 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4807 { BS_AUTO3STATE, DLGC_BUTTON,
4808 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4809 { BS_GROUPBOX, DLGC_STATIC,
4810 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4811 { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
4812 WmSetFocusButtonSeq, WmKillFocusButtonSeq },
4813 { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
4814 WmSetFocusStaticSeq, WmKillFocusStaticSeq },
4815 { BS_OWNERDRAW, DLGC_BUTTON,
4816 WmSetFocusButtonSeq, WmKillFocusButtonSeq }
4818 unsigned int i;
4819 HWND hwnd;
4820 DWORD dlg_code;
4821 HFONT zfont;
4823 subclass_button();
4825 for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
4827 hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_POPUP,
4828 0, 0, 50, 14, 0, 0, 0, NULL);
4829 ok(hwnd != 0, "Failed to create button window\n");
4831 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
4832 ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
4834 ShowWindow(hwnd, SW_SHOW);
4835 UpdateWindow(hwnd);
4836 SetFocus(0);
4837 flush_sequence();
4839 trace("button style %08x\n", button[i].style);
4840 SetFocus(hwnd);
4841 ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
4843 SetFocus(0);
4844 ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
4846 DestroyWindow(hwnd);
4849 hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
4850 0, 0, 50, 14, 0, 0, 0, NULL);
4851 ok(hwnd != 0, "Failed to create button window\n");
4853 SetFocus(0);
4854 flush_events();
4855 flush_sequence();
4857 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
4858 ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
4860 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
4861 ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
4863 flush_sequence();
4864 zfont = (HFONT)GetStockObject(SYSTEM_FONT);
4865 SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
4866 UpdateWindow(hwnd);
4867 ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
4869 DestroyWindow(hwnd);
4872 /****************** static message test *************************/
4873 static const struct message WmSetFontStaticSeq[] =
4875 { WM_SETFONT, sent },
4876 { WM_PAINT, sent|defwinproc },
4877 { WM_ERASEBKGND, sent|defwinproc|optional },
4878 { WM_CTLCOLORSTATIC, sent|defwinproc },
4879 { 0 }
4882 static WNDPROC old_static_proc;
4884 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4886 static long defwndproc_counter = 0;
4887 LRESULT ret;
4888 struct message msg;
4890 trace("static: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
4892 /* explicitly ignore WM_GETICON message */
4893 if (message == WM_GETICON) return 0;
4895 msg.message = message;
4896 msg.flags = sent|wparam|lparam;
4897 if (defwndproc_counter) msg.flags |= defwinproc;
4898 msg.wParam = wParam;
4899 msg.lParam = lParam;
4900 add_message(&msg);
4902 defwndproc_counter++;
4903 ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
4904 defwndproc_counter--;
4906 return ret;
4909 static void subclass_static(void)
4911 WNDCLASSA cls;
4913 if (!GetClassInfoA(0, "static", &cls)) assert(0);
4915 old_static_proc = cls.lpfnWndProc;
4917 cls.hInstance = GetModuleHandle(0);
4918 cls.lpfnWndProc = static_hook_proc;
4919 cls.lpszClassName = "my_static_class";
4920 UnregisterClass(cls.lpszClassName, cls.hInstance);
4921 if (!RegisterClassA(&cls)) assert(0);
4924 static void test_static_messages(void)
4926 /* FIXME: make as comprehensive as the button message test */
4927 static const struct
4929 DWORD style;
4930 DWORD dlg_code;
4931 const struct message *setfont;
4932 } static_ctrl[] = {
4933 { SS_LEFT, DLGC_STATIC,
4934 WmSetFontStaticSeq }
4936 unsigned int i;
4937 HWND hwnd;
4938 DWORD dlg_code;
4940 subclass_static();
4942 for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
4944 hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
4945 0, 0, 50, 14, 0, 0, 0, NULL);
4946 ok(hwnd != 0, "Failed to create static window\n");
4948 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
4949 ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
4951 ShowWindow(hwnd, SW_SHOW);
4952 UpdateWindow(hwnd);
4953 SetFocus(0);
4954 flush_sequence();
4956 trace("static style %08x\n", static_ctrl[i].style);
4957 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
4958 ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
4960 DestroyWindow(hwnd);
4964 /****************** ComboBox message test *************************/
4965 #define ID_COMBOBOX 0x000f
4967 static const struct message WmKeyDownComboSeq[] =
4969 { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
4970 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
4971 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
4972 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
4973 { WM_CTLCOLOREDIT, sent|parent },
4974 { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
4975 { 0 }
4978 static WNDPROC old_combobox_proc;
4980 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
4982 static long defwndproc_counter = 0;
4983 LRESULT ret;
4984 struct message msg;
4986 /* do not log painting messages */
4987 if (message != WM_PAINT &&
4988 message != WM_NCPAINT &&
4989 message != WM_SYNCPAINT &&
4990 message != WM_ERASEBKGND &&
4991 message != WM_NCHITTEST &&
4992 message != WM_GETTEXT &&
4993 message != WM_GETICON &&
4994 message != WM_DEVICECHANGE)
4996 trace("combo: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
4998 msg.message = message;
4999 msg.flags = sent|wparam|lparam;
5000 if (defwndproc_counter) msg.flags |= defwinproc;
5001 msg.wParam = wParam;
5002 msg.lParam = lParam;
5003 add_message(&msg);
5006 defwndproc_counter++;
5007 ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5008 defwndproc_counter--;
5010 return ret;
5013 static void subclass_combobox(void)
5015 WNDCLASSA cls;
5017 if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5019 old_combobox_proc = cls.lpfnWndProc;
5021 cls.hInstance = GetModuleHandle(0);
5022 cls.lpfnWndProc = combobox_hook_proc;
5023 cls.lpszClassName = "my_combobox_class";
5024 UnregisterClass(cls.lpszClassName, cls.hInstance);
5025 if (!RegisterClassA(&cls)) assert(0);
5028 static void test_combobox_messages(void)
5030 HWND parent, combo;
5031 LRESULT ret;
5033 subclass_combobox();
5035 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5036 100, 100, 200, 200, 0, 0, 0, NULL);
5037 ok(parent != 0, "Failed to create parent window\n");
5038 flush_sequence();
5040 combo = CreateWindowEx(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5041 0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5042 ok(combo != 0, "Failed to create combobox window\n");
5044 UpdateWindow(combo);
5046 ret = SendMessage(combo, WM_GETDLGCODE, 0, 0);
5047 ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5049 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5050 ok(ret == 0, "expected 0, got %ld\n", ret);
5051 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5052 ok(ret == 1, "expected 1, got %ld\n", ret);
5053 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5054 ok(ret == 2, "expected 2, got %ld\n", ret);
5056 SendMessage(combo, CB_SETCURSEL, 0, 0);
5057 SetFocus(combo);
5058 flush_sequence();
5060 log_all_parent_messages++;
5061 SendMessage(combo, WM_KEYDOWN, VK_DOWN, 0);
5062 SendMessage(combo, WM_KEYUP, VK_DOWN, 0);
5063 log_all_parent_messages--;
5064 ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5066 DestroyWindow(combo);
5067 DestroyWindow(parent);
5070 /************* painting message test ********************/
5072 void dump_region(HRGN hrgn)
5074 DWORD i, size;
5075 RGNDATA *data = NULL;
5076 RECT *rect;
5078 if (!hrgn)
5080 printf( "null region\n" );
5081 return;
5083 if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5084 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5085 GetRegionData( hrgn, size, data );
5086 printf("%d rects:", data->rdh.nCount );
5087 for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5088 printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
5089 printf("\n");
5090 HeapFree( GetProcessHeap(), 0, data );
5093 static void check_update_rgn( HWND hwnd, HRGN hrgn )
5095 INT ret;
5096 RECT r1, r2;
5097 HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
5098 HRGN update = CreateRectRgn( 0, 0, 0, 0 );
5100 ret = GetUpdateRgn( hwnd, update, FALSE );
5101 ok( ret != ERROR, "GetUpdateRgn failed\n" );
5102 if (ret == NULLREGION)
5104 ok( !hrgn, "Update region shouldn't be empty\n" );
5106 else
5108 if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
5110 ok( 0, "Regions are different\n" );
5111 if (winetest_debug > 0)
5113 printf( "Update region: " );
5114 dump_region( update );
5115 printf( "Wanted region: " );
5116 dump_region( hrgn );
5120 GetRgnBox( update, &r1 );
5121 GetUpdateRect( hwnd, &r2, FALSE );
5122 ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
5123 "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
5124 r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
5126 DeleteObject( tmp );
5127 DeleteObject( update );
5130 static const struct message WmInvalidateRgn[] = {
5131 { WM_NCPAINT, sent },
5132 { WM_GETTEXT, sent|defwinproc|optional },
5133 { 0 }
5136 static const struct message WmGetUpdateRect[] = {
5137 { WM_NCPAINT, sent },
5138 { WM_GETTEXT, sent|defwinproc|optional },
5139 { WM_PAINT, sent },
5140 { 0 }
5143 static const struct message WmInvalidateFull[] = {
5144 { WM_NCPAINT, sent|wparam, 1 },
5145 { WM_GETTEXT, sent|defwinproc|optional },
5146 { 0 }
5149 static const struct message WmInvalidateErase[] = {
5150 { WM_NCPAINT, sent|wparam, 1 },
5151 { WM_GETTEXT, sent|defwinproc|optional },
5152 { WM_ERASEBKGND, sent },
5153 { 0 }
5156 static const struct message WmInvalidatePaint[] = {
5157 { WM_PAINT, sent },
5158 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5159 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5160 { 0 }
5163 static const struct message WmInvalidateErasePaint[] = {
5164 { WM_PAINT, sent },
5165 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5166 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5167 { WM_ERASEBKGND, sent|beginpaint },
5168 { 0 }
5171 static const struct message WmInvalidateErasePaint2[] = {
5172 { WM_PAINT, sent },
5173 { WM_NCPAINT, sent|beginpaint },
5174 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5175 { WM_ERASEBKGND, sent|beginpaint },
5176 { 0 }
5179 static const struct message WmErase[] = {
5180 { WM_ERASEBKGND, sent },
5181 { 0 }
5184 static const struct message WmPaint[] = {
5185 { WM_PAINT, sent },
5186 { 0 }
5189 static const struct message WmParentOnlyPaint[] = {
5190 { WM_PAINT, sent|parent },
5191 { 0 }
5194 static const struct message WmInvalidateParent[] = {
5195 { WM_NCPAINT, sent|parent },
5196 { WM_GETTEXT, sent|defwinproc|parent|optional },
5197 { WM_ERASEBKGND, sent|parent },
5198 { 0 }
5201 static const struct message WmInvalidateParentChild[] = {
5202 { WM_NCPAINT, sent|parent },
5203 { WM_GETTEXT, sent|defwinproc|parent|optional },
5204 { WM_ERASEBKGND, sent|parent },
5205 { WM_NCPAINT, sent },
5206 { WM_GETTEXT, sent|defwinproc|optional },
5207 { WM_ERASEBKGND, sent },
5208 { 0 }
5211 static const struct message WmInvalidateParentChild2[] = {
5212 { WM_ERASEBKGND, sent|parent },
5213 { WM_NCPAINT, sent },
5214 { WM_GETTEXT, sent|defwinproc|optional },
5215 { WM_ERASEBKGND, sent },
5216 { 0 }
5219 static const struct message WmParentPaint[] = {
5220 { WM_PAINT, sent|parent },
5221 { WM_PAINT, sent },
5222 { 0 }
5225 static const struct message WmParentPaintNc[] = {
5226 { WM_PAINT, sent|parent },
5227 { WM_PAINT, sent },
5228 { WM_NCPAINT, sent|beginpaint },
5229 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5230 { WM_ERASEBKGND, sent|beginpaint },
5231 { 0 }
5234 static const struct message WmChildPaintNc[] = {
5235 { WM_PAINT, sent },
5236 { WM_NCPAINT, sent|beginpaint },
5237 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5238 { WM_ERASEBKGND, sent|beginpaint },
5239 { 0 }
5242 static const struct message WmParentErasePaint[] = {
5243 { WM_PAINT, sent|parent },
5244 { WM_NCPAINT, sent|parent|beginpaint },
5245 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5246 { WM_ERASEBKGND, sent|parent|beginpaint },
5247 { WM_PAINT, sent },
5248 { WM_NCPAINT, sent|beginpaint },
5249 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5250 { WM_ERASEBKGND, sent|beginpaint },
5251 { 0 }
5254 static const struct message WmParentOnlyNcPaint[] = {
5255 { WM_PAINT, sent|parent },
5256 { WM_NCPAINT, sent|parent|beginpaint },
5257 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5258 { 0 }
5261 static const struct message WmSetParentStyle[] = {
5262 { WM_STYLECHANGING, sent|parent },
5263 { WM_STYLECHANGED, sent|parent },
5264 { 0 }
5267 static void test_paint_messages(void)
5269 BOOL ret;
5270 RECT rect;
5271 POINT pt;
5272 MSG msg;
5273 HWND hparent, hchild;
5274 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
5275 HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
5276 HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
5277 100, 100, 200, 200, 0, 0, 0, NULL);
5278 ok (hwnd != 0, "Failed to create overlapped window\n");
5280 ShowWindow( hwnd, SW_SHOW );
5281 UpdateWindow( hwnd );
5282 flush_events();
5283 flush_sequence();
5285 check_update_rgn( hwnd, 0 );
5286 SetRectRgn( hrgn, 10, 10, 20, 20 );
5287 ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5288 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5289 check_update_rgn( hwnd, hrgn );
5290 SetRectRgn( hrgn2, 20, 20, 30, 30 );
5291 ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
5292 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5293 CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
5294 check_update_rgn( hwnd, hrgn );
5295 /* validate everything */
5296 ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5297 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5298 check_update_rgn( hwnd, 0 );
5300 /* test empty region */
5301 SetRectRgn( hrgn, 10, 10, 10, 15 );
5302 ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5303 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5304 check_update_rgn( hwnd, 0 );
5305 /* test empty rect */
5306 SetRect( &rect, 10, 10, 10, 15 );
5307 ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
5308 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5309 check_update_rgn( hwnd, 0 );
5311 /* flush pending messages */
5312 flush_events();
5313 flush_sequence();
5315 GetClientRect( hwnd, &rect );
5316 SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
5317 /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
5318 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5320 trace("testing InvalidateRect(0, NULL, FALSE)\n");
5321 SetRectEmpty( &rect );
5322 ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
5323 check_update_rgn( hwnd, hrgn );
5324 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5325 flush_events();
5326 ok_sequence( WmPaint, "Paint", FALSE );
5327 RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5328 check_update_rgn( hwnd, 0 );
5330 /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
5331 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5333 trace("testing ValidateRect(0, NULL)\n");
5334 SetRectEmpty( &rect );
5335 ok(ValidateRect(0, &rect), "ValidateRect(0, &rc) should not fail\n");
5336 check_update_rgn( hwnd, hrgn );
5337 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5338 flush_events();
5339 ok_sequence( WmPaint, "Paint", FALSE );
5340 RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5341 check_update_rgn( hwnd, 0 );
5343 trace("testing InvalidateRgn(0, NULL, FALSE)\n");
5344 SetLastError(0xdeadbeef);
5345 ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
5346 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
5347 "wrong error code %d\n", GetLastError());
5348 check_update_rgn( hwnd, 0 );
5349 flush_events();
5350 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5352 trace("testing ValidateRgn(0, NULL)\n");
5353 SetLastError(0xdeadbeef);
5354 ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
5355 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error code %d\n", GetLastError());
5356 check_update_rgn( hwnd, 0 );
5357 flush_events();
5358 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5360 /* now with frame */
5361 SetRectRgn( hrgn, -5, -5, 20, 20 );
5363 /* flush pending messages */
5364 flush_events();
5365 flush_sequence();
5366 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5367 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5369 SetRectRgn( hrgn, 0, 0, 20, 20 ); /* GetUpdateRgn clips to client area */
5370 check_update_rgn( hwnd, hrgn );
5372 flush_sequence();
5373 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5374 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5376 flush_sequence();
5377 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
5378 ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
5380 GetClientRect( hwnd, &rect );
5381 SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
5382 check_update_rgn( hwnd, hrgn );
5384 flush_sequence();
5385 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
5386 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5388 flush_sequence();
5389 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
5390 ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
5391 check_update_rgn( hwnd, 0 );
5393 flush_sequence();
5394 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
5395 ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
5396 check_update_rgn( hwnd, 0 );
5398 flush_sequence();
5399 SetRectRgn( hrgn, 0, 0, 100, 100 );
5400 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5401 SetRectRgn( hrgn, 0, 0, 50, 100 );
5402 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
5403 SetRectRgn( hrgn, 50, 0, 100, 100 );
5404 check_update_rgn( hwnd, hrgn );
5405 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5406 ok_sequence( WmEmptySeq, "EmptySeq", FALSE ); /* must not generate messages, everything is valid */
5407 check_update_rgn( hwnd, 0 );
5409 flush_sequence();
5410 SetRectRgn( hrgn, 0, 0, 100, 100 );
5411 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5412 SetRectRgn( hrgn, 0, 0, 100, 50 );
5413 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
5414 ok_sequence( WmErase, "Erase", FALSE );
5415 SetRectRgn( hrgn, 0, 50, 100, 100 );
5416 check_update_rgn( hwnd, hrgn );
5418 flush_sequence();
5419 SetRectRgn( hrgn, 0, 0, 100, 100 );
5420 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
5421 SetRectRgn( hrgn, 0, 0, 50, 50 );
5422 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
5423 ok_sequence( WmPaint, "Paint", FALSE );
5425 flush_sequence();
5426 SetRectRgn( hrgn, -4, -4, -2, -2 );
5427 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5428 SetRectRgn( hrgn, -200, -200, -198, -198 );
5429 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
5430 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
5432 flush_sequence();
5433 SetRectRgn( hrgn, -4, -4, -2, -2 );
5434 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5435 SetRectRgn( hrgn, -4, -4, -3, -3 );
5436 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
5437 SetRectRgn( hrgn, 0, 0, 1, 1 );
5438 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
5439 ok_sequence( WmPaint, "Paint", FALSE );
5441 flush_sequence();
5442 SetRectRgn( hrgn, -4, -4, -1, -1 );
5443 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5444 RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
5445 /* make sure no WM_PAINT was generated */
5446 flush_events();
5447 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
5449 flush_sequence();
5450 SetRectRgn( hrgn, -4, -4, -1, -1 );
5451 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
5452 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
5454 if (msg.hwnd == hwnd && msg.message == WM_PAINT)
5456 /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
5457 INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
5458 ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
5459 ret = GetUpdateRect( hwnd, &rect, FALSE );
5460 ok( ret, "Invalid GetUpdateRect result %d\n", ret );
5461 /* this will send WM_NCPAINT and validate the non client area */
5462 ret = GetUpdateRect( hwnd, &rect, TRUE );
5463 ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
5465 DispatchMessage( &msg );
5467 ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
5469 DestroyWindow( hwnd );
5471 /* now test with a child window */
5473 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
5474 100, 100, 200, 200, 0, 0, 0, NULL);
5475 ok (hparent != 0, "Failed to create parent window\n");
5477 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
5478 10, 10, 100, 100, hparent, 0, 0, NULL);
5479 ok (hchild != 0, "Failed to create child window\n");
5481 ShowWindow( hparent, SW_SHOW );
5482 UpdateWindow( hparent );
5483 UpdateWindow( hchild );
5484 flush_events();
5485 flush_sequence();
5486 log_all_parent_messages++;
5488 SetRect( &rect, 0, 0, 50, 50 );
5489 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5490 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5491 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
5493 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5494 pt.x = pt.y = 0;
5495 MapWindowPoints( hchild, hparent, &pt, 1 );
5496 SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
5497 check_update_rgn( hchild, hrgn );
5498 SetRectRgn( hrgn, 0, 0, 50, 50 );
5499 check_update_rgn( hparent, hrgn );
5500 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5501 ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
5502 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5503 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5505 flush_events();
5506 ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
5508 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5509 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5510 ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
5511 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
5512 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
5514 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
5515 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
5516 ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
5518 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
5519 flush_sequence();
5520 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5521 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5522 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
5524 /* flush all paint messages */
5525 flush_events();
5526 flush_sequence();
5528 /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
5529 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
5530 SetRectRgn( hrgn, 0, 0, 50, 50 );
5531 check_update_rgn( hparent, hrgn );
5532 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5533 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5534 SetRectRgn( hrgn, 0, 0, 50, 50 );
5535 check_update_rgn( hparent, hrgn );
5537 /* flush all paint messages */
5538 flush_events();
5539 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
5540 flush_sequence();
5542 /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
5543 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5544 SetRectRgn( hrgn, 0, 0, 50, 50 );
5545 check_update_rgn( hparent, hrgn );
5546 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5547 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5548 SetRectRgn( hrgn2, 10, 10, 50, 50 );
5549 CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
5550 check_update_rgn( hparent, hrgn );
5551 /* flush all paint messages */
5552 flush_events();
5553 flush_sequence();
5555 /* same as above but parent gets completely validated */
5556 SetRect( &rect, 20, 20, 30, 30 );
5557 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5558 SetRectRgn( hrgn, 20, 20, 30, 30 );
5559 check_update_rgn( hparent, hrgn );
5560 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
5561 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5562 check_update_rgn( hparent, 0 ); /* no update region */
5563 flush_events();
5564 ok_sequence( WmEmptySeq, "WmEmpty", FALSE ); /* and no paint messages */
5566 /* make sure RDW_VALIDATE on child doesn't have the same effect */
5567 flush_sequence();
5568 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5569 SetRectRgn( hrgn, 20, 20, 30, 30 );
5570 check_update_rgn( hparent, hrgn );
5571 RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
5572 SetRectRgn( hrgn, 20, 20, 30, 30 );
5573 check_update_rgn( hparent, hrgn );
5575 /* same as above but normal WM_PAINT doesn't validate parent */
5576 flush_sequence();
5577 SetRect( &rect, 20, 20, 30, 30 );
5578 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5579 SetRectRgn( hrgn, 20, 20, 30, 30 );
5580 check_update_rgn( hparent, hrgn );
5581 /* no WM_PAINT in child while parent still pending */
5582 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5583 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
5584 while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5585 ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
5587 flush_sequence();
5588 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5589 /* no WM_PAINT in child while parent still pending */
5590 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5591 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
5592 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
5593 /* now that parent is valid child should get WM_PAINT */
5594 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5595 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
5596 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5597 ok_sequence( WmEmptySeq, "No other message", FALSE );
5599 /* same thing with WS_CLIPCHILDREN in parent */
5600 flush_sequence();
5601 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
5602 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
5603 /* changing style invalidates non client area, but we need to invalidate something else to see it */
5604 RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
5605 ok_sequence( WmEmptySeq, "No message", FALSE );
5606 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
5607 ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
5609 flush_sequence();
5610 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
5611 SetRectRgn( hrgn, 20, 20, 30, 30 );
5612 check_update_rgn( hparent, hrgn );
5613 /* no WM_PAINT in child while parent still pending */
5614 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5615 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
5616 /* WM_PAINT in parent first */
5617 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
5618 ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
5620 /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
5621 flush_sequence();
5622 SetRect( &rect, 0, 0, 30, 30 );
5623 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
5624 SetRectRgn( hrgn, 0, 0, 30, 30 );
5625 check_update_rgn( hparent, hrgn );
5626 flush_events();
5627 ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
5629 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
5630 flush_sequence();
5631 SetRect( &rect, -10, 0, 30, 30 );
5632 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
5633 SetRect( &rect, 0, 0, 20, 20 );
5634 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
5635 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
5636 ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
5638 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
5639 flush_sequence();
5640 SetRect( &rect, -10, 0, 30, 30 );
5641 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
5642 SetRect( &rect, 0, 0, 100, 100 );
5643 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
5644 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
5645 ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
5646 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
5647 ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
5649 /* test RDW_INTERNALPAINT behavior */
5651 flush_sequence();
5652 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
5653 flush_events();
5654 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
5656 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
5657 flush_events();
5658 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
5660 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
5661 flush_events();
5662 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
5664 assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
5665 UpdateWindow( hparent );
5666 flush_events();
5667 flush_sequence();
5668 trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
5669 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5670 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
5671 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5672 flush_events();
5673 ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
5675 UpdateWindow( hparent );
5676 flush_events();
5677 flush_sequence();
5678 trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
5679 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5680 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
5681 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5682 flush_events();
5683 ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
5685 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
5686 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
5687 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
5688 flush_events();
5689 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
5691 assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
5692 UpdateWindow( hparent );
5693 flush_events();
5694 flush_sequence();
5695 trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
5696 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5697 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
5698 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5699 flush_events();
5700 ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
5702 UpdateWindow( hparent );
5703 flush_events();
5704 flush_sequence();
5705 trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
5706 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
5707 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
5708 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
5709 flush_events();
5710 ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
5712 log_all_parent_messages--;
5713 DestroyWindow( hparent );
5714 ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
5716 DeleteObject( hrgn );
5717 DeleteObject( hrgn2 );
5720 struct wnd_event
5722 HWND hwnd;
5723 HANDLE event;
5726 static DWORD WINAPI thread_proc(void *param)
5728 MSG msg;
5729 struct wnd_event *wnd_event = (struct wnd_event *)param;
5731 wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
5732 100, 100, 200, 200, 0, 0, 0, NULL);
5733 ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
5735 SetEvent(wnd_event->event);
5737 while (GetMessage(&msg, 0, 0, 0))
5739 TranslateMessage(&msg);
5740 DispatchMessage(&msg);
5743 ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
5745 return 0;
5748 static void test_interthread_messages(void)
5750 HANDLE hThread;
5751 DWORD tid;
5752 WNDPROC proc;
5753 MSG msg;
5754 char buf[256];
5755 int len, expected_len;
5756 struct wnd_event wnd_event;
5757 BOOL ret;
5759 wnd_event.event = CreateEventW(NULL, 0, 0, NULL);
5760 if (!wnd_event.event)
5762 trace("skipping interthread message test under win9x\n");
5763 return;
5766 hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
5767 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
5769 ok(WaitForSingleObject(wnd_event.event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5771 CloseHandle(wnd_event.event);
5773 SetLastError(0xdeadbeef);
5774 ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
5775 ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
5776 "wrong error code %d\n", GetLastError());
5778 proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
5779 ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
5781 expected_len = lstrlenA("window caption text");
5782 memset(buf, 0, sizeof(buf));
5783 SetLastError(0xdeadbeef);
5784 len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
5785 ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
5786 ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
5788 msg.hwnd = wnd_event.hwnd;
5789 msg.message = WM_GETTEXT;
5790 msg.wParam = sizeof(buf);
5791 msg.lParam = (LPARAM)buf;
5792 memset(buf, 0, sizeof(buf));
5793 SetLastError(0xdeadbeef);
5794 len = DispatchMessageA(&msg);
5795 ok(!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY,
5796 "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
5798 /* the following test causes an exception in user.exe under win9x */
5799 msg.hwnd = wnd_event.hwnd;
5800 msg.message = WM_TIMER;
5801 msg.wParam = 0;
5802 msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
5803 SetLastError(0xdeadbeef);
5804 len = DispatchMessageA(&msg);
5805 ok(!len && GetLastError() == 0xdeadbeef,
5806 "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
5808 ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
5809 ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
5811 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
5812 CloseHandle(hThread);
5814 ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
5818 static const struct message WmVkN[] = {
5819 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5820 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5821 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
5822 { WM_CHAR, wparam|lparam, 'n', 1 },
5823 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
5824 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5825 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5826 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5827 { 0 }
5829 static const struct message WmShiftVkN[] = {
5830 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
5831 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
5832 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
5833 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5834 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5835 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
5836 { WM_CHAR, wparam|lparam, 'N', 1 },
5837 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
5838 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5839 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5840 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5841 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
5842 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
5843 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
5844 { 0 }
5846 static const struct message WmCtrlVkN[] = {
5847 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5848 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5849 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5850 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5851 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5852 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
5853 { WM_CHAR, wparam|lparam, 0x000e, 1 },
5854 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
5855 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5856 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5857 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5858 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5859 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5860 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5861 { 0 }
5863 static const struct message WmCtrlVkN_2[] = {
5864 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5865 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5866 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5867 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5868 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5869 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
5870 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5871 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5872 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5873 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5874 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5875 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5876 { 0 }
5878 static const struct message WmAltVkN[] = {
5879 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5880 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5881 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5882 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
5883 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
5884 { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
5885 { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
5886 { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
5887 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
5888 { HCBT_SYSCOMMAND, hook },
5889 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
5890 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5891 { 0x00AE, sent|defwinproc|optional }, /* XP */
5892 { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
5893 { WM_INITMENU, sent|defwinproc },
5894 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
5895 { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
5896 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5897 { WM_CAPTURECHANGED, sent|defwinproc },
5898 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
5899 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
5900 { WM_EXITMENULOOP, sent|defwinproc },
5901 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
5902 { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
5903 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
5904 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
5905 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
5906 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5907 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5908 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5909 { 0 }
5911 static const struct message WmAltVkN_2[] = {
5912 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5913 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5914 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5915 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
5916 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
5917 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
5918 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
5919 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
5920 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
5921 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5922 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5923 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5924 { 0 }
5926 static const struct message WmCtrlAltVkN[] = {
5927 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5928 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5929 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5930 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5931 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5932 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5933 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
5934 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
5935 { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
5936 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
5937 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
5938 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
5939 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5940 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5941 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5942 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5943 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5944 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5945 { 0 }
5947 static const struct message WmCtrlShiftVkN[] = {
5948 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5949 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5950 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5951 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
5952 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
5953 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
5954 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
5955 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
5956 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
5957 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
5958 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
5959 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
5960 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
5961 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
5962 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
5963 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5964 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5965 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5966 { 0 }
5968 static const struct message WmCtrlAltShiftVkN[] = {
5969 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
5970 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
5971 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
5972 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5973 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5974 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5975 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
5976 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
5977 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
5978 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
5979 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
5980 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
5981 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
5982 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
5983 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
5984 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
5985 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
5986 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
5987 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
5988 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
5989 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
5990 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
5991 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
5992 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
5993 { 0 }
5995 static const struct message WmAltPressRelease[] = {
5996 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
5997 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
5998 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
5999 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6000 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6001 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6002 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
6003 { HCBT_SYSCOMMAND, hook },
6004 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6005 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6006 { WM_INITMENU, sent|defwinproc },
6007 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6008 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6009 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6011 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
6013 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6014 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
6015 { WM_CAPTURECHANGED, sent|defwinproc },
6016 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
6017 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6018 { WM_EXITMENULOOP, sent|defwinproc },
6019 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6020 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6021 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6022 { 0 }
6024 static const struct message WmAltMouseButton[] = {
6025 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6026 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6027 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6028 { WM_MOUSEMOVE, wparam|optional, 0, 0 },
6029 { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
6030 { WM_LBUTTONDOWN, wparam, MK_LBUTTON, 0 },
6031 { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON, 0 },
6032 { WM_LBUTTONUP, wparam, 0, 0 },
6033 { WM_LBUTTONUP, sent|wparam, 0, 0 },
6034 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6035 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6036 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6037 { 0 }
6039 static const struct message WmF1Seq[] = {
6040 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
6041 { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
6042 { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
6043 { WM_KEYF1, wparam|lparam, 0, 0 },
6044 { WM_KEYF1, sent|wparam|lparam, 0, 0 },
6045 { WM_HELP, sent|defwinproc },
6046 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
6047 { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
6048 { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
6049 { 0 }
6051 static const struct message WmVkAppsSeq[] = {
6052 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
6053 { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
6054 { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
6055 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
6056 { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
6057 { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
6058 { WM_CONTEXTMENU, lparam, /*hwnd*/0, (LPARAM)-1 },
6059 { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, (LPARAM)-1 },
6060 { 0 }
6063 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
6065 MSG msg;
6067 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
6069 struct message log_msg;
6071 trace("accel: %p, %04x, %08lx, %08lx\n", msg.hwnd, msg.message, msg.wParam, msg.lParam);
6073 /* ignore some unwanted messages */
6074 if (msg.message == WM_MOUSEMOVE ||
6075 msg.message == WM_GETICON ||
6076 msg.message == WM_DEVICECHANGE)
6077 continue;
6079 log_msg.message = msg.message;
6080 log_msg.flags = wparam|lparam;
6081 log_msg.wParam = msg.wParam;
6082 log_msg.lParam = msg.lParam;
6083 add_message(&log_msg);
6085 if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
6087 TranslateMessage(&msg);
6088 DispatchMessage(&msg);
6093 static void test_accelerators(void)
6095 RECT rc;
6096 SHORT state;
6097 HACCEL hAccel;
6098 HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6099 100, 100, 200, 200, 0, 0, 0, NULL);
6100 BOOL ret;
6102 assert(hwnd != 0);
6103 UpdateWindow(hwnd);
6104 flush_events();
6105 flush_sequence();
6107 SetFocus(hwnd);
6108 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
6110 state = GetKeyState(VK_SHIFT);
6111 ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
6112 state = GetKeyState(VK_CAPITAL);
6113 ok(state == 0, "wrong CapsLock state %04x\n", state);
6115 hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
6116 assert(hAccel != 0);
6118 pump_msg_loop(hwnd, 0);
6119 flush_sequence();
6121 trace("testing VK_N press/release\n");
6122 flush_sequence();
6123 keybd_event('N', 0, 0, 0);
6124 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6125 pump_msg_loop(hwnd, hAccel);
6126 ok_sequence(WmVkN, "VK_N press/release", FALSE);
6128 trace("testing Shift+VK_N press/release\n");
6129 flush_sequence();
6130 keybd_event(VK_SHIFT, 0, 0, 0);
6131 keybd_event('N', 0, 0, 0);
6132 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6133 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6134 pump_msg_loop(hwnd, hAccel);
6135 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6137 trace("testing Ctrl+VK_N press/release\n");
6138 flush_sequence();
6139 keybd_event(VK_CONTROL, 0, 0, 0);
6140 keybd_event('N', 0, 0, 0);
6141 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6142 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6143 pump_msg_loop(hwnd, hAccel);
6144 ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
6146 trace("testing Alt+VK_N press/release\n");
6147 flush_sequence();
6148 keybd_event(VK_MENU, 0, 0, 0);
6149 keybd_event('N', 0, 0, 0);
6150 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6151 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6152 pump_msg_loop(hwnd, hAccel);
6153 ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
6155 trace("testing Ctrl+Alt+VK_N press/release 1\n");
6156 flush_sequence();
6157 keybd_event(VK_CONTROL, 0, 0, 0);
6158 keybd_event(VK_MENU, 0, 0, 0);
6159 keybd_event('N', 0, 0, 0);
6160 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6161 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6162 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6163 pump_msg_loop(hwnd, hAccel);
6164 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
6166 ret = DestroyAcceleratorTable(hAccel);
6167 ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6169 hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
6170 assert(hAccel != 0);
6172 trace("testing VK_N press/release\n");
6173 flush_sequence();
6174 keybd_event('N', 0, 0, 0);
6175 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6176 pump_msg_loop(hwnd, hAccel);
6177 ok_sequence(WmVkN, "VK_N press/release", FALSE);
6179 trace("testing Shift+VK_N press/release\n");
6180 flush_sequence();
6181 keybd_event(VK_SHIFT, 0, 0, 0);
6182 keybd_event('N', 0, 0, 0);
6183 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6184 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6185 pump_msg_loop(hwnd, hAccel);
6186 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6188 trace("testing Ctrl+VK_N press/release 2\n");
6189 flush_sequence();
6190 keybd_event(VK_CONTROL, 0, 0, 0);
6191 keybd_event('N', 0, 0, 0);
6192 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6193 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6194 pump_msg_loop(hwnd, hAccel);
6195 ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
6197 trace("testing Alt+VK_N press/release 2\n");
6198 flush_sequence();
6199 keybd_event(VK_MENU, 0, 0, 0);
6200 keybd_event('N', 0, 0, 0);
6201 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6202 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6203 pump_msg_loop(hwnd, hAccel);
6204 ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
6206 trace("testing Ctrl+Alt+VK_N press/release 2\n");
6207 flush_sequence();
6208 keybd_event(VK_CONTROL, 0, 0, 0);
6209 keybd_event(VK_MENU, 0, 0, 0);
6210 keybd_event('N', 0, 0, 0);
6211 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6212 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6213 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6214 pump_msg_loop(hwnd, hAccel);
6215 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
6217 trace("testing Ctrl+Shift+VK_N press/release\n");
6218 flush_sequence();
6219 keybd_event(VK_CONTROL, 0, 0, 0);
6220 keybd_event(VK_SHIFT, 0, 0, 0);
6221 keybd_event('N', 0, 0, 0);
6222 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6223 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6224 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6225 pump_msg_loop(hwnd, hAccel);
6226 ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
6228 trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
6229 flush_sequence();
6230 keybd_event(VK_CONTROL, 0, 0, 0);
6231 keybd_event(VK_MENU, 0, 0, 0);
6232 keybd_event(VK_SHIFT, 0, 0, 0);
6233 keybd_event('N', 0, 0, 0);
6234 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6235 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6236 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6237 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6238 pump_msg_loop(hwnd, hAccel);
6239 ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
6241 ret = DestroyAcceleratorTable(hAccel);
6242 ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
6244 trace("testing Alt press/release\n");
6245 flush_sequence();
6246 keybd_event(VK_MENU, 0, 0, 0);
6247 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6248 keybd_event(VK_MENU, 0, 0, 0);
6249 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6250 pump_msg_loop(hwnd, 0);
6251 /* this test doesn't pass in Wine for managed windows */
6252 ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
6254 trace("testing Alt+MouseButton press/release\n");
6255 /* first, move mouse pointer inside of the window client area */
6256 GetClientRect(hwnd, &rc);
6257 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
6258 rc.left += (rc.right - rc.left)/2;
6259 rc.top += (rc.bottom - rc.top)/2;
6260 SetCursorPos(rc.left, rc.top);
6262 flush_events();
6263 flush_sequence();
6264 keybd_event(VK_MENU, 0, 0, 0);
6265 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
6266 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
6267 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
6268 pump_msg_loop(hwnd, 0);
6269 ok_sequence(WmAltMouseButton, "Alt+MouseButton press/release", FALSE);
6271 trace("testing VK_F1 press/release\n");
6272 keybd_event(VK_F1, 0, 0, 0);
6273 keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
6274 pump_msg_loop(hwnd, 0);
6275 ok_sequence(WmF1Seq, "F1 press/release", FALSE);
6277 trace("testing VK_APPS press/release\n");
6278 keybd_event(VK_APPS, 0, 0, 0);
6279 keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
6280 pump_msg_loop(hwnd, 0);
6281 ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
6283 DestroyWindow(hwnd);
6286 /************* window procedures ********************/
6288 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message,
6289 WPARAM wParam, LPARAM lParam)
6291 static long defwndproc_counter = 0;
6292 static long beginpaint_counter = 0;
6293 LRESULT ret;
6294 struct message msg;
6296 trace("%p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6298 /* explicitly ignore WM_GETICON message */
6299 if (message == WM_GETICON) return 0;
6301 switch (message)
6303 case WM_ENABLE:
6305 LONG style = GetWindowLongA(hwnd, GWL_STYLE);
6306 ok((BOOL)wParam == !(style & WS_DISABLED),
6307 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
6308 break;
6311 case WM_CAPTURECHANGED:
6312 if (test_DestroyWindow_flag)
6314 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6315 if (style & WS_CHILD)
6316 lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6317 else if (style & WS_POPUP)
6318 lParam = WND_POPUP_ID;
6319 else
6320 lParam = WND_PARENT_ID;
6322 break;
6324 case WM_NCDESTROY:
6326 HWND capture;
6328 ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
6329 capture = GetCapture();
6330 if (capture)
6332 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
6333 trace("current capture %p, releasing...\n", capture);
6334 ReleaseCapture();
6337 /* fall through */
6338 case WM_DESTROY:
6339 if (pGetAncestor)
6340 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
6341 if (test_DestroyWindow_flag)
6343 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
6344 if (style & WS_CHILD)
6345 lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
6346 else if (style & WS_POPUP)
6347 lParam = WND_POPUP_ID;
6348 else
6349 lParam = WND_PARENT_ID;
6351 break;
6353 /* test_accelerators() depends on this */
6354 case WM_NCHITTEST:
6355 return HTCLIENT;
6357 /* ignore */
6358 case WM_MOUSEMOVE:
6359 case WM_SETCURSOR:
6360 case WM_DEVICECHANGE:
6361 return 0;
6363 case WM_WINDOWPOSCHANGING:
6364 case WM_WINDOWPOSCHANGED:
6366 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6368 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6369 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6370 winpos->hwnd, winpos->hwndInsertAfter,
6371 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6372 dump_winpos_flags(winpos->flags);
6374 /* Log only documented flags, win2k uses 0x1000 and 0x2000
6375 * in the high word for internal purposes
6377 wParam = winpos->flags & 0xffff;
6378 /* We are not interested in the flags that don't match under XP and Win9x */
6379 wParam &= ~(SWP_NOZORDER);
6380 break;
6384 msg.message = message;
6385 msg.flags = sent|wparam|lparam;
6386 if (defwndproc_counter) msg.flags |= defwinproc;
6387 if (beginpaint_counter) msg.flags |= beginpaint;
6388 msg.wParam = wParam;
6389 msg.lParam = lParam;
6390 add_message(&msg);
6392 if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
6394 HWND parent = GetParent(hwnd);
6395 RECT rc;
6396 MINMAXINFO *minmax = (MINMAXINFO *)lParam;
6398 GetClientRect(parent, &rc);
6399 trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
6401 trace("ptReserved = (%d,%d)\n"
6402 "ptMaxSize = (%d,%d)\n"
6403 "ptMaxPosition = (%d,%d)\n"
6404 "ptMinTrackSize = (%d,%d)\n"
6405 "ptMaxTrackSize = (%d,%d)\n",
6406 minmax->ptReserved.x, minmax->ptReserved.y,
6407 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
6408 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
6409 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
6410 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
6412 ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
6413 minmax->ptMaxSize.x, rc.right);
6414 ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
6415 minmax->ptMaxSize.y, rc.bottom);
6418 if (message == WM_PAINT)
6420 PAINTSTRUCT ps;
6421 beginpaint_counter++;
6422 BeginPaint( hwnd, &ps );
6423 beginpaint_counter--;
6424 EndPaint( hwnd, &ps );
6425 return 0;
6428 defwndproc_counter++;
6429 ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam)
6430 : DefWindowProcA(hwnd, message, wParam, lParam);
6431 defwndproc_counter--;
6433 return ret;
6436 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6438 return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
6441 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6443 return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
6446 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6448 static long defwndproc_counter = 0;
6449 LRESULT ret;
6450 struct message msg;
6452 trace("popup: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6454 /* explicitly ignore WM_GETICON message */
6455 if (message == WM_GETICON) return 0;
6457 msg.message = message;
6458 msg.flags = sent|wparam|lparam;
6459 if (defwndproc_counter) msg.flags |= defwinproc;
6460 msg.wParam = wParam;
6461 msg.lParam = lParam;
6462 add_message(&msg);
6464 if (message == WM_CREATE)
6466 DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
6467 SetWindowLongA(hwnd, GWL_STYLE, style);
6470 defwndproc_counter++;
6471 ret = DefWindowProcA(hwnd, message, wParam, lParam);
6472 defwndproc_counter--;
6474 return ret;
6477 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6479 static long defwndproc_counter = 0;
6480 static long beginpaint_counter = 0;
6481 LRESULT ret;
6482 struct message msg;
6483 LPARAM logged_lParam;
6485 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6487 /* explicitly ignore WM_GETICON message */
6488 if (message == WM_GETICON) return 0;
6490 logged_lParam=lParam;
6491 if (log_all_parent_messages ||
6492 message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
6493 message == WM_SETFOCUS || message == WM_KILLFOCUS ||
6494 message == WM_ENABLE || message == WM_ENTERIDLE ||
6495 message == WM_DRAWITEM ||
6496 message == WM_IME_SETCONTEXT)
6498 switch (message)
6500 /* ignore */
6501 case WM_NCHITTEST:
6502 return HTCLIENT;
6503 case WM_SETCURSOR:
6504 case WM_MOUSEMOVE:
6505 return 0;
6507 case WM_ERASEBKGND:
6509 RECT rc;
6510 INT ret = GetClipBox((HDC)wParam, &rc);
6512 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
6513 ret, rc.left, rc.top, rc.right, rc.bottom);
6514 break;
6517 case WM_WINDOWPOSCHANGING:
6518 case WM_WINDOWPOSCHANGED:
6520 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6522 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6523 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6524 winpos->hwnd, winpos->hwndInsertAfter,
6525 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6526 dump_winpos_flags(winpos->flags);
6528 /* Log only documented flags, win2k uses 0x1000 and 0x2000
6529 * in the high word for internal purposes
6531 wParam = winpos->flags & 0xffff;
6532 /* We are not interested in the flags that don't match under XP and Win9x */
6533 wParam &= ~(SWP_NOZORDER);
6534 break;
6537 case WM_DRAWITEM:
6539 /* encode DRAWITEMSTRUCT into an LPARAM */
6540 DRAW_ITEM_STRUCT di;
6541 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam;
6543 trace("WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x\n",
6544 dis->CtlType, dis->CtlID, dis->itemID, dis->itemAction, dis->itemState);
6546 di.u.item.type = dis->CtlType;
6547 di.u.item.ctl_id = dis->CtlID;
6548 di.u.item.item_id = dis->itemID;
6549 di.u.item.action = dis->itemAction;
6550 di.u.item.state = dis->itemState;
6552 logged_lParam = di.u.lp;
6553 break;
6557 msg.message = message;
6558 msg.flags = sent|parent|wparam|lparam;
6559 if (defwndproc_counter) msg.flags |= defwinproc;
6560 if (beginpaint_counter) msg.flags |= beginpaint;
6561 msg.wParam = wParam;
6562 msg.lParam = logged_lParam;
6563 add_message(&msg);
6566 if (message == WM_PAINT)
6568 PAINTSTRUCT ps;
6569 beginpaint_counter++;
6570 BeginPaint( hwnd, &ps );
6571 beginpaint_counter--;
6572 EndPaint( hwnd, &ps );
6573 return 0;
6576 defwndproc_counter++;
6577 ret = DefWindowProcA(hwnd, message, wParam, lParam);
6578 defwndproc_counter--;
6580 return ret;
6583 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6585 static long defwndproc_counter = 0;
6586 LRESULT ret;
6587 struct message msg;
6589 trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
6591 /* explicitly ignore WM_GETICON message */
6592 if (message == WM_GETICON) return 0;
6594 if (test_def_id)
6596 DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
6597 ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
6598 if (after_end_dialog)
6599 ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
6600 else
6601 ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
6604 switch (message)
6606 case WM_WINDOWPOSCHANGING:
6607 case WM_WINDOWPOSCHANGED:
6609 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6611 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6612 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6613 winpos->hwnd, winpos->hwndInsertAfter,
6614 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6615 dump_winpos_flags(winpos->flags);
6617 /* Log only documented flags, win2k uses 0x1000 and 0x2000
6618 * in the high word for internal purposes
6620 wParam = winpos->flags & 0xffff;
6621 /* We are not interested in the flags that don't match under XP and Win9x */
6622 wParam &= ~(SWP_NOZORDER);
6623 break;
6627 msg.message = message;
6628 msg.flags = sent|wparam|lparam;
6629 if (defwndproc_counter) msg.flags |= defwinproc;
6630 msg.wParam = wParam;
6631 msg.lParam = lParam;
6632 add_message(&msg);
6634 defwndproc_counter++;
6635 ret = DefDlgProcA(hwnd, message, wParam, lParam);
6636 defwndproc_counter--;
6638 return ret;
6641 static void dump_winpos_flags(UINT flags)
6643 if (!winetest_debug) return;
6645 if (flags & SWP_SHOWWINDOW) printf("|SWP_SHOWWINDOW");
6646 if (flags & SWP_HIDEWINDOW) printf("|SWP_HIDEWINDOW");
6647 if (flags & SWP_NOACTIVATE) printf("|SWP_NOACTIVATE");
6648 if (flags & SWP_FRAMECHANGED) printf("|SWP_FRAMECHANGED");
6649 if (flags & SWP_NOCOPYBITS) printf("|SWP_NOCOPYBITS");
6650 if (flags & SWP_NOOWNERZORDER) printf("|SWP_NOOWNERZORDER");
6651 if (flags & SWP_NOSENDCHANGING) printf("|SWP_NOSENDCHANGING");
6652 if (flags & SWP_DEFERERASE) printf("|SWP_DEFERERASE");
6653 if (flags & SWP_ASYNCWINDOWPOS) printf("|SWP_ASYNCWINDOWPOS");
6654 if (flags & SWP_NOZORDER) printf("|SWP_NOZORDER");
6655 if (flags & SWP_NOREDRAW) printf("|SWP_NOREDRAW");
6656 if (flags & SWP_NOSIZE) printf("|SWP_NOSIZE");
6657 if (flags & SWP_NOMOVE) printf("|SWP_NOMOVE");
6658 if (flags & SWP_NOCLIENTSIZE) printf("|SWP_NOCLIENTSIZE");
6659 if (flags & SWP_NOCLIENTMOVE) printf("|SWP_NOCLIENTMOVE");
6661 #define DUMPED_FLAGS \
6662 (SWP_NOSIZE | \
6663 SWP_NOMOVE | \
6664 SWP_NOZORDER | \
6665 SWP_NOREDRAW | \
6666 SWP_NOACTIVATE | \
6667 SWP_FRAMECHANGED | \
6668 SWP_SHOWWINDOW | \
6669 SWP_HIDEWINDOW | \
6670 SWP_NOCOPYBITS | \
6671 SWP_NOOWNERZORDER | \
6672 SWP_NOSENDCHANGING | \
6673 SWP_DEFERERASE | \
6674 SWP_ASYNCWINDOWPOS | \
6675 SWP_NOCLIENTSIZE | \
6676 SWP_NOCLIENTMOVE)
6678 if(flags & ~DUMPED_FLAGS) printf("|0x%04x", flags & ~DUMPED_FLAGS);
6679 printf("\n");
6680 #undef DUMPED_FLAGS
6683 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6685 static long defwndproc_counter = 0;
6686 LRESULT ret;
6687 struct message msg;
6689 /* log only specific messages we are interested in */
6690 switch (message)
6692 #if 0 /* probably log these as well */
6693 case WM_ACTIVATE:
6694 case WM_SETFOCUS:
6695 case WM_KILLFOCUS:
6696 #endif
6697 case WM_SHOWWINDOW:
6698 trace("WM_SHOWWINDOW %ld\n", wParam);
6699 break;
6700 case WM_SIZE:
6701 trace("WM_SIZE %ld\n", wParam);
6702 break;
6703 case WM_MOVE:
6704 trace("WM_MOVE\n");
6705 break;
6706 case WM_GETMINMAXINFO:
6707 trace("WM_GETMINMAXINFO\n");
6708 break;
6710 case WM_WINDOWPOSCHANGING:
6711 case WM_WINDOWPOSCHANGED:
6713 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
6715 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
6716 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
6717 winpos->hwnd, winpos->hwndInsertAfter,
6718 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
6719 trace("flags: ");
6720 dump_winpos_flags(winpos->flags);
6722 /* Log only documented flags, win2k uses 0x1000 and 0x2000
6723 * in the high word for internal purposes
6725 wParam = winpos->flags & 0xffff;
6726 /* We are not interested in the flags that don't match under XP and Win9x */
6727 wParam &= ~(SWP_NOZORDER);
6728 break;
6731 default: /* ignore */
6732 /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
6733 return DefWindowProcA(hwnd, message, wParam, lParam);
6736 msg.message = message;
6737 msg.flags = sent|wparam|lparam;
6738 if (defwndproc_counter) msg.flags |= defwinproc;
6739 msg.wParam = wParam;
6740 msg.lParam = lParam;
6741 add_message(&msg);
6743 defwndproc_counter++;
6744 ret = DefWindowProcA(hwnd, message, wParam, lParam);
6745 defwndproc_counter--;
6747 return ret;
6750 static BOOL RegisterWindowClasses(void)
6752 WNDCLASSA cls;
6753 WNDCLASSW clsW;
6755 cls.style = 0;
6756 cls.lpfnWndProc = MsgCheckProcA;
6757 cls.cbClsExtra = 0;
6758 cls.cbWndExtra = 0;
6759 cls.hInstance = GetModuleHandleA(0);
6760 cls.hIcon = 0;
6761 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
6762 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6763 cls.lpszMenuName = NULL;
6764 cls.lpszClassName = "TestWindowClass";
6765 if(!RegisterClassA(&cls)) return FALSE;
6767 cls.lpfnWndProc = ShowWindowProcA;
6768 cls.lpszClassName = "ShowWindowClass";
6769 if(!RegisterClassA(&cls)) return FALSE;
6771 cls.lpfnWndProc = PopupMsgCheckProcA;
6772 cls.lpszClassName = "TestPopupClass";
6773 if(!RegisterClassA(&cls)) return FALSE;
6775 cls.lpfnWndProc = ParentMsgCheckProcA;
6776 cls.lpszClassName = "TestParentClass";
6777 if(!RegisterClassA(&cls)) return FALSE;
6779 cls.lpfnWndProc = DefWindowProcA;
6780 cls.lpszClassName = "SimpleWindowClass";
6781 if(!RegisterClassA(&cls)) return FALSE;
6783 cls.style = CS_NOCLOSE;
6784 cls.lpszClassName = "NoCloseWindowClass";
6785 if(!RegisterClassA(&cls)) return FALSE;
6787 ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
6788 cls.style = 0;
6789 cls.hInstance = GetModuleHandleA(0);
6790 cls.hbrBackground = 0;
6791 cls.lpfnWndProc = TestDlgProcA;
6792 cls.lpszClassName = "TestDialogClass";
6793 if(!RegisterClassA(&cls)) return FALSE;
6795 clsW.style = 0;
6796 clsW.lpfnWndProc = MsgCheckProcW;
6797 clsW.cbClsExtra = 0;
6798 clsW.cbWndExtra = 0;
6799 clsW.hInstance = GetModuleHandleW(0);
6800 clsW.hIcon = 0;
6801 clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
6802 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
6803 clsW.lpszMenuName = NULL;
6804 clsW.lpszClassName = testWindowClassW;
6805 RegisterClassW(&clsW); /* ignore error, this fails on Win9x */
6807 return TRUE;
6810 static HHOOK hCBT_hook;
6811 static DWORD cbt_hook_thread_id;
6813 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
6815 static const char * const CBT_code_name[10] = {
6816 "HCBT_MOVESIZE",
6817 "HCBT_MINMAX",
6818 "HCBT_QS",
6819 "HCBT_CREATEWND",
6820 "HCBT_DESTROYWND",
6821 "HCBT_ACTIVATE",
6822 "HCBT_CLICKSKIPPED",
6823 "HCBT_KEYSKIPPED",
6824 "HCBT_SYSCOMMAND",
6825 "HCBT_SETFOCUS" };
6826 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
6827 HWND hwnd;
6828 char buf[256];
6830 trace("CBT: %d (%s), %08lx, %08lx\n", nCode, code_name, wParam, lParam);
6832 ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
6834 if (nCode == HCBT_CLICKSKIPPED)
6836 /* ignore this event, XP sends it a lot when switching focus between windows */
6837 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
6840 if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
6842 struct message msg;
6844 msg.message = nCode;
6845 msg.flags = hook|wparam|lparam;
6846 msg.wParam = wParam;
6847 msg.lParam = lParam;
6848 add_message(&msg);
6850 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
6853 if (nCode == HCBT_DESTROYWND)
6855 if (test_DestroyWindow_flag)
6857 DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
6858 if (style & WS_CHILD)
6859 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
6860 else if (style & WS_POPUP)
6861 lParam = WND_POPUP_ID;
6862 else
6863 lParam = WND_PARENT_ID;
6867 /* Log also SetFocus(0) calls */
6868 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
6870 if (GetClassNameA(hwnd, buf, sizeof(buf)))
6872 if (!lstrcmpiA(buf, "TestWindowClass") ||
6873 !lstrcmpiA(buf, "ShowWindowClass") ||
6874 !lstrcmpiA(buf, "TestParentClass") ||
6875 !lstrcmpiA(buf, "TestPopupClass") ||
6876 !lstrcmpiA(buf, "SimpleWindowClass") ||
6877 !lstrcmpiA(buf, "TestDialogClass") ||
6878 !lstrcmpiA(buf, "MDI_frame_class") ||
6879 !lstrcmpiA(buf, "MDI_client_class") ||
6880 !lstrcmpiA(buf, "MDI_child_class") ||
6881 !lstrcmpiA(buf, "my_button_class") ||
6882 !lstrcmpiA(buf, "my_edit_class") ||
6883 !lstrcmpiA(buf, "static") ||
6884 !lstrcmpiA(buf, "ListBox") ||
6885 !lstrcmpiA(buf, "ComboBox") ||
6886 !lstrcmpiA(buf, "MyDialogClass") ||
6887 !lstrcmpiA(buf, "#32770"))
6889 struct message msg;
6891 msg.message = nCode;
6892 msg.flags = hook|wparam|lparam;
6893 msg.wParam = wParam;
6894 msg.lParam = lParam;
6895 add_message(&msg);
6898 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
6901 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
6902 DWORD event,
6903 HWND hwnd,
6904 LONG object_id,
6905 LONG child_id,
6906 DWORD thread_id,
6907 DWORD event_time)
6909 char buf[256];
6911 trace("WEH:%p,event %08x,hwnd %p,obj %08x,id %08x,thread %08x,time %08x\n",
6912 hevent, event, hwnd, object_id, child_id, thread_id, event_time);
6914 ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
6916 /* ignore mouse cursor events */
6917 if (object_id == OBJID_CURSOR) return;
6919 if (!hwnd || GetClassNameA(hwnd, buf, sizeof(buf)))
6921 if (!hwnd ||
6922 !lstrcmpiA(buf, "TestWindowClass") ||
6923 !lstrcmpiA(buf, "TestParentClass") ||
6924 !lstrcmpiA(buf, "TestPopupClass") ||
6925 !lstrcmpiA(buf, "SimpleWindowClass") ||
6926 !lstrcmpiA(buf, "TestDialogClass") ||
6927 !lstrcmpiA(buf, "MDI_frame_class") ||
6928 !lstrcmpiA(buf, "MDI_client_class") ||
6929 !lstrcmpiA(buf, "MDI_child_class") ||
6930 !lstrcmpiA(buf, "my_button_class") ||
6931 !lstrcmpiA(buf, "my_edit_class") ||
6932 !lstrcmpiA(buf, "static") ||
6933 !lstrcmpiA(buf, "ListBox") ||
6934 !lstrcmpiA(buf, "ComboBox") ||
6935 !lstrcmpiA(buf, "MyDialogClass") ||
6936 !lstrcmpiA(buf, "#32770"))
6938 struct message msg;
6940 msg.message = event;
6941 msg.flags = winevent_hook|wparam|lparam;
6942 msg.wParam = object_id;
6943 msg.lParam = child_id;
6944 add_message(&msg);
6949 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
6950 static const WCHAR wszAnsi[] = {'U',0};
6952 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6954 switch (uMsg)
6956 case CB_FINDSTRINGEXACT:
6957 trace("String: %p\n", (LPCWSTR)lParam);
6958 if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
6959 return 1;
6960 if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
6961 return 0;
6962 return -1;
6964 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
6967 static const struct message WmGetTextLengthAfromW[] = {
6968 { WM_GETTEXTLENGTH, sent },
6969 { WM_GETTEXT, sent },
6970 { 0 }
6973 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
6975 /* dummy window proc for WM_GETTEXTLENGTH test */
6976 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
6978 switch(msg)
6980 case WM_GETTEXTLENGTH:
6981 return lstrlenW(dummy_window_text) + 37; /* some random length */
6982 case WM_GETTEXT:
6983 lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
6984 return lstrlenW( (LPWSTR)lp );
6985 default:
6986 return DefWindowProcW( hwnd, msg, wp, lp );
6990 static void test_message_conversion(void)
6992 static const WCHAR wszMsgConversionClass[] =
6993 {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
6994 WNDCLASSW cls;
6995 LRESULT lRes;
6996 HWND hwnd;
6997 WNDPROC wndproc, newproc;
6998 BOOL ret;
7000 cls.style = 0;
7001 cls.lpfnWndProc = MsgConversionProcW;
7002 cls.cbClsExtra = 0;
7003 cls.cbWndExtra = 0;
7004 cls.hInstance = GetModuleHandleW(NULL);
7005 cls.hIcon = NULL;
7006 cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
7007 cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
7008 cls.lpszMenuName = NULL;
7009 cls.lpszClassName = wszMsgConversionClass;
7010 /* this call will fail on Win9x, but that doesn't matter as this test is
7011 * meaningless on those platforms */
7012 if(!RegisterClassW(&cls)) return;
7014 hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
7015 100, 100, 200, 200, 0, 0, 0, NULL);
7016 ok(hwnd != NULL, "Window creation failed\n");
7018 /* {W, A} -> A */
7020 wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
7021 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7022 ok(lRes == 0, "String should have been converted\n");
7023 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7024 ok(lRes == 1, "String shouldn't have been converted\n");
7026 /* {W, A} -> W */
7028 wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
7029 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7030 ok(lRes == 1, "String shouldn't have been converted\n");
7031 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7032 ok(lRes == 1, "String shouldn't have been converted\n");
7034 /* Synchronous messages */
7036 lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7037 ok(lRes == 0, "String should have been converted\n");
7038 lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7039 ok(lRes == 1, "String shouldn't have been converted\n");
7041 /* Asynchronous messages */
7043 SetLastError(0);
7044 lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7045 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7046 "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7047 SetLastError(0);
7048 lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7049 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7050 "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7051 SetLastError(0);
7052 lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7053 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7054 "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7055 SetLastError(0);
7056 lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7057 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7058 "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7059 SetLastError(0);
7060 lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7061 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7062 "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7063 SetLastError(0);
7064 lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7065 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7066 "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7067 SetLastError(0);
7068 lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7069 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7070 "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7071 SetLastError(0);
7072 lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7073 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7074 "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7076 /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
7078 hwnd = CreateWindowW (testWindowClassW, wszUnicode,
7079 WS_OVERLAPPEDWINDOW,
7080 100, 100, 200, 200, 0, 0, 0, NULL);
7081 assert(hwnd);
7082 flush_sequence();
7083 lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
7084 ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7085 ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7086 "got bad length %ld\n", lRes );
7088 flush_sequence();
7089 lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
7090 hwnd, WM_GETTEXTLENGTH, 0, 0);
7091 ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7092 ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7093 "got bad length %ld\n", lRes );
7095 wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
7096 newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
7097 lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7098 ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7099 NULL, 0, NULL, NULL ),
7100 "got bad length %ld\n", lRes );
7102 SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc ); /* restore old wnd proc */
7103 lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7104 ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7105 NULL, 0, NULL, NULL ),
7106 "got bad length %ld\n", lRes );
7108 ret = DestroyWindow(hwnd);
7109 ok( ret, "DestroyWindow() error %d\n", GetLastError());
7112 struct timer_info
7114 HWND hWnd;
7115 HANDLE handles[2];
7116 DWORD id;
7119 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
7123 #define TIMER_ID 0x19
7125 static DWORD WINAPI timer_thread_proc(LPVOID x)
7127 struct timer_info *info = x;
7128 DWORD r;
7130 r = KillTimer(info->hWnd, 0x19);
7131 ok(r,"KillTimer failed in thread\n");
7132 r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
7133 ok(r,"SetTimer failed in thread\n");
7134 ok(r==TIMER_ID,"SetTimer id different\n");
7135 r = SetEvent(info->handles[0]);
7136 ok(r,"SetEvent failed in thread\n");
7137 return 0;
7140 static void test_timers(void)
7142 struct timer_info info;
7143 DWORD id;
7145 info.hWnd = CreateWindow ("TestWindowClass", NULL,
7146 WS_OVERLAPPEDWINDOW ,
7147 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7148 NULL, NULL, 0);
7150 info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
7151 ok(info.id, "SetTimer failed\n");
7152 ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
7153 info.handles[0] = CreateEvent(NULL,0,0,NULL);
7154 info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
7156 WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
7158 WaitForSingleObject(info.handles[1], INFINITE);
7160 CloseHandle(info.handles[0]);
7161 CloseHandle(info.handles[1]);
7163 ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
7165 ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
7168 static int count = 0;
7169 static VOID CALLBACK callback_count(
7170 HWND hwnd,
7171 UINT uMsg,
7172 UINT_PTR idEvent,
7173 DWORD dwTime
7176 count++;
7179 static void test_timers_no_wnd(void)
7181 UINT_PTR id, id2;
7182 MSG msg;
7184 count = 0;
7185 id = SetTimer(NULL, 0, 100, callback_count);
7186 ok(id != 0, "did not get id from SetTimer.\n");
7187 id2 = SetTimer(NULL, id, 200, callback_count);
7188 ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
7189 Sleep(150);
7190 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7191 ok(count == 0, "did not get zero count as expected (%i).\n", count);
7192 Sleep(150);
7193 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7194 ok(count == 1, "did not get one count as expected (%i).\n", count);
7195 KillTimer(NULL, id);
7196 Sleep(250);
7197 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7198 ok(count == 1, "killing replaced timer did not work (%i).\n", count);
7201 /* Various win events with arbitrary parameters */
7202 static const struct message WmWinEventsSeq[] = {
7203 { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7204 { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7205 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7206 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7207 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7208 { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7209 { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7210 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7211 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7212 /* our win event hook ignores OBJID_CURSOR events */
7213 /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
7214 { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
7215 { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
7216 { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
7217 { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
7218 { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7219 { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7220 { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7221 { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7222 { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7223 { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7224 { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7225 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7226 { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7227 { 0 }
7229 static const struct message WmWinEventCaretSeq[] = {
7230 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7231 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7232 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
7233 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7234 { 0 }
7236 static const struct message WmWinEventCaretSeq_2[] = {
7237 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7238 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7239 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7240 { 0 }
7242 static const struct message WmWinEventAlertSeq[] = {
7243 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
7244 { 0 }
7246 static const struct message WmWinEventAlertSeq_2[] = {
7247 /* create window in the thread proc */
7248 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
7249 /* our test event */
7250 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
7251 { 0 }
7253 static const struct message WmGlobalHookSeq_1[] = {
7254 /* create window in the thread proc */
7255 { HCBT_CREATEWND, hook|lparam, 0, 2 },
7256 /* our test events */
7257 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
7258 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
7259 { 0 }
7261 static const struct message WmGlobalHookSeq_2[] = {
7262 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
7263 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
7264 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
7265 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
7266 { 0 }
7269 static const struct message WmMouseLLHookSeq[] = {
7270 { WM_MOUSEMOVE, hook },
7271 { WM_LBUTTONUP, hook },
7272 { WM_MOUSEMOVE, hook },
7273 { 0 }
7276 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
7277 DWORD event,
7278 HWND hwnd,
7279 LONG object_id,
7280 LONG child_id,
7281 DWORD thread_id,
7282 DWORD event_time)
7284 char buf[256];
7286 trace("WEH_2:%p,event %08x,hwnd %p,obj %08x,id %08x,thread %08x,time %08x\n",
7287 hevent, event, hwnd, object_id, child_id, thread_id, event_time);
7289 if (GetClassNameA(hwnd, buf, sizeof(buf)))
7291 if (!lstrcmpiA(buf, "TestWindowClass") ||
7292 !lstrcmpiA(buf, "static"))
7294 struct message msg;
7296 msg.message = event;
7297 msg.flags = winevent_hook|wparam|lparam;
7298 msg.wParam = object_id;
7299 msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
7300 add_message(&msg);
7305 static HHOOK hCBT_global_hook;
7306 static DWORD cbt_global_hook_thread_id;
7308 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
7310 HWND hwnd;
7311 char buf[256];
7313 trace("CBT_2: %d, %08lx, %08lx\n", nCode, wParam, lParam);
7315 if (nCode == HCBT_SYSCOMMAND)
7317 struct message msg;
7319 msg.message = nCode;
7320 msg.flags = hook|wparam|lparam;
7321 msg.wParam = wParam;
7322 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7323 add_message(&msg);
7325 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7327 /* WH_MOUSE_LL hook */
7328 if (nCode == HC_ACTION)
7330 MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
7332 /* we can't test for real mouse events */
7333 if (mhll->flags & LLMHF_INJECTED)
7335 struct message msg;
7337 memset (&msg, 0, sizeof (msg));
7338 msg.message = wParam;
7339 msg.flags = hook;
7340 add_message(&msg);
7342 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7345 /* Log also SetFocus(0) calls */
7346 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7348 if (GetClassNameA(hwnd, buf, sizeof(buf)))
7350 if (!lstrcmpiA(buf, "TestWindowClass") ||
7351 !lstrcmpiA(buf, "static"))
7353 struct message msg;
7355 msg.message = nCode;
7356 msg.flags = hook|wparam|lparam;
7357 msg.wParam = wParam;
7358 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
7359 add_message(&msg);
7362 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
7365 static DWORD WINAPI win_event_global_thread_proc(void *param)
7367 HWND hwnd;
7368 MSG msg;
7369 HANDLE hevent = *(HANDLE *)param;
7371 assert(pNotifyWinEvent);
7373 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7374 assert(hwnd);
7375 trace("created thread window %p\n", hwnd);
7377 *(HWND *)param = hwnd;
7379 flush_sequence();
7380 /* this event should be received only by our new hook proc,
7381 * an old one does not expect an event from another thread.
7383 pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
7384 SetEvent(hevent);
7386 while (GetMessage(&msg, 0, 0, 0))
7388 TranslateMessage(&msg);
7389 DispatchMessage(&msg);
7391 return 0;
7394 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
7396 HWND hwnd;
7397 MSG msg;
7398 HANDLE hevent = *(HANDLE *)param;
7400 flush_sequence();
7401 /* these events should be received only by our new hook proc,
7402 * an old one does not expect an event from another thread.
7405 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7406 assert(hwnd);
7407 trace("created thread window %p\n", hwnd);
7409 *(HWND *)param = hwnd;
7411 /* Windows doesn't like when a thread plays games with the focus,
7412 that leads to all kinds of misbehaviours and failures to activate
7413 a window. So, better keep next lines commented out.
7414 SetFocus(0);
7415 SetFocus(hwnd);*/
7417 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7418 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7420 SetEvent(hevent);
7422 while (GetMessage(&msg, 0, 0, 0))
7424 TranslateMessage(&msg);
7425 DispatchMessage(&msg);
7427 return 0;
7430 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
7432 HWND hwnd;
7433 MSG msg;
7434 HANDLE hevent = *(HANDLE *)param;
7436 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
7437 assert(hwnd);
7438 trace("created thread window %p\n", hwnd);
7440 *(HWND *)param = hwnd;
7442 flush_sequence();
7444 /* Windows doesn't like when a thread plays games with the focus,
7445 * that leads to all kinds of misbehaviours and failures to activate
7446 * a window. So, better don't generate a mouse click message below.
7448 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7449 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7450 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7452 SetEvent(hevent);
7453 while (GetMessage(&msg, 0, 0, 0))
7455 TranslateMessage(&msg);
7456 DispatchMessage(&msg);
7458 return 0;
7461 static void test_winevents(void)
7463 BOOL ret;
7464 MSG msg;
7465 HWND hwnd, hwnd2;
7466 UINT i;
7467 HANDLE hthread, hevent;
7468 DWORD tid;
7469 HWINEVENTHOOK hhook;
7470 const struct message *events = WmWinEventsSeq;
7472 hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
7473 WS_OVERLAPPEDWINDOW,
7474 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7475 NULL, NULL, 0);
7476 assert(hwnd);
7478 /****** start of global hook test *************/
7479 hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7480 if (!hCBT_global_hook)
7482 ok(DestroyWindow(hwnd), "failed to destroy window\n");
7483 skip( "cannot set global hook\n" );
7484 return;
7487 hevent = CreateEventA(NULL, 0, 0, NULL);
7488 assert(hevent);
7489 hwnd2 = (HWND)hevent;
7491 hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
7492 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7494 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7496 ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
7498 flush_sequence();
7499 /* this one should be received only by old hook proc */
7500 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
7501 /* this one should be received only by old hook proc */
7502 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
7504 ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
7506 ret = UnhookWindowsHookEx(hCBT_global_hook);
7507 ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7509 PostThreadMessageA(tid, WM_QUIT, 0, 0);
7510 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7511 CloseHandle(hthread);
7512 CloseHandle(hevent);
7513 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7514 /****** end of global hook test *************/
7516 if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
7518 ok(DestroyWindow(hwnd), "failed to destroy window\n");
7519 return;
7522 flush_sequence();
7524 if (0)
7526 /* this test doesn't pass under Win9x */
7527 /* win2k ignores events with hwnd == 0 */
7528 SetLastError(0xdeadbeef);
7529 pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
7530 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
7531 GetLastError() == 0xdeadbeef, /* Win9x */
7532 "unexpected error %d\n", GetLastError());
7533 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7536 for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
7537 pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
7539 ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
7541 /****** start of event filtering test *************/
7542 hhook = (HWINEVENTHOOK)pSetWinEventHook(
7543 EVENT_OBJECT_SHOW, /* 0x8002 */
7544 EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
7545 GetModuleHandleA(0), win_event_global_hook_proc,
7546 GetCurrentProcessId(), 0,
7547 WINEVENT_INCONTEXT);
7548 ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7550 hevent = CreateEventA(NULL, 0, 0, NULL);
7551 assert(hevent);
7552 hwnd2 = (HWND)hevent;
7554 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7555 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7557 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7559 ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
7561 flush_sequence();
7562 /* this one should be received only by old hook proc */
7563 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7564 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7565 /* this one should be received only by old hook proc */
7566 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7568 ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
7570 ret = pUnhookWinEvent(hhook);
7571 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7573 PostThreadMessageA(tid, WM_QUIT, 0, 0);
7574 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7575 CloseHandle(hthread);
7576 CloseHandle(hevent);
7577 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7578 /****** end of event filtering test *************/
7580 /****** start of out of context event test *************/
7581 hhook = (HWINEVENTHOOK)pSetWinEventHook(
7582 EVENT_MIN, EVENT_MAX,
7583 0, win_event_global_hook_proc,
7584 GetCurrentProcessId(), 0,
7585 WINEVENT_OUTOFCONTEXT);
7586 ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
7588 hevent = CreateEventA(NULL, 0, 0, NULL);
7589 assert(hevent);
7590 hwnd2 = (HWND)hevent;
7592 flush_sequence();
7594 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
7595 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7597 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7599 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
7600 /* process pending winevent messages */
7601 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7602 ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
7604 flush_sequence();
7605 /* this one should be received only by old hook proc */
7606 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
7607 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
7608 /* this one should be received only by old hook proc */
7609 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
7611 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
7612 /* process pending winevent messages */
7613 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
7614 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
7616 ret = pUnhookWinEvent(hhook);
7617 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7619 PostThreadMessageA(tid, WM_QUIT, 0, 0);
7620 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7621 CloseHandle(hthread);
7622 CloseHandle(hevent);
7623 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7624 /****** end of out of context event test *************/
7626 /****** start of MOUSE_LL hook test *************/
7627 hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
7628 /* WH_MOUSE_LL is not supported on Win9x platforms */
7629 if (!hCBT_global_hook)
7631 trace("Skipping WH_MOUSE_LL test on this platform\n");
7632 goto skip_mouse_ll_hook_test;
7635 hevent = CreateEventA(NULL, 0, 0, NULL);
7636 assert(hevent);
7637 hwnd2 = (HWND)hevent;
7639 hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
7640 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
7642 while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
7643 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
7645 ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
7646 flush_sequence();
7648 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
7649 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7650 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
7652 ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
7654 ret = UnhookWindowsHookEx(hCBT_global_hook);
7655 ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
7657 PostThreadMessageA(tid, WM_QUIT, 0, 0);
7658 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7659 CloseHandle(hthread);
7660 CloseHandle(hevent);
7661 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
7662 /****** end of MOUSE_LL hook test *************/
7663 skip_mouse_ll_hook_test:
7665 ok(DestroyWindow(hwnd), "failed to destroy window\n");
7668 static void test_set_hook(void)
7670 BOOL ret;
7671 HHOOK hhook;
7672 HWINEVENTHOOK hwinevent_hook;
7674 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
7675 ok(hhook != 0, "local hook does not require hModule set to 0\n");
7676 UnhookWindowsHookEx(hhook);
7678 if (0)
7680 /* this test doesn't pass under Win9x: BUG! */
7681 SetLastError(0xdeadbeef);
7682 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
7683 ok(!hhook, "global hook requires hModule != 0\n");
7684 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
7687 SetLastError(0xdeadbeef);
7688 hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
7689 ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
7690 ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
7691 GetLastError() == 0xdeadbeef, /* Win9x */
7692 "unexpected error %d\n", GetLastError());
7694 SetLastError(0xdeadbeef);
7695 ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
7696 ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
7697 GetLastError() == 0xdeadbeef, /* Win9x */
7698 "unexpected error %d\n", GetLastError());
7700 if (!pSetWinEventHook || !pUnhookWinEvent) return;
7702 /* even process local incontext hooks require hmodule */
7703 SetLastError(0xdeadbeef);
7704 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7705 0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
7706 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
7707 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
7708 GetLastError() == 0xdeadbeef, /* Win9x */
7709 "unexpected error %d\n", GetLastError());
7711 /* even thread local incontext hooks require hmodule */
7712 SetLastError(0xdeadbeef);
7713 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7714 0, win_event_proc, GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
7715 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
7716 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
7717 GetLastError() == 0xdeadbeef, /* Win9x */
7718 "unexpected error %d\n", GetLastError());
7720 if (0)
7722 /* these 3 tests don't pass under Win9x */
7723 SetLastError(0xdeadbeef);
7724 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(1, 0,
7725 0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7726 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
7727 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
7729 SetLastError(0xdeadbeef);
7730 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(-1, 1,
7731 0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7732 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
7733 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
7735 SetLastError(0xdeadbeef);
7736 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7737 0, win_event_proc, 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
7738 ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
7739 ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
7742 SetLastError(0xdeadbeef);
7743 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(0, 0,
7744 0, win_event_proc, GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
7745 ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
7746 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
7747 ret = pUnhookWinEvent(hwinevent_hook);
7748 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7750 todo_wine {
7751 /* This call succeeds under win2k SP4, but fails under Wine.
7752 Does win2k test/use passed process id? */
7753 SetLastError(0xdeadbeef);
7754 hwinevent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
7755 0, win_event_proc, 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
7756 ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
7757 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
7758 ret = pUnhookWinEvent(hwinevent_hook);
7759 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
7762 SetLastError(0xdeadbeef);
7763 ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
7764 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
7765 GetLastError() == 0xdeadbeef, /* Win9x */
7766 "unexpected error %d\n", GetLastError());
7769 static const struct message ScrollWindowPaint1[] = {
7770 { WM_PAINT, sent },
7771 { WM_ERASEBKGND, sent|beginpaint },
7772 { 0 }
7775 static const struct message ScrollWindowPaint2[] = {
7776 { WM_PAINT, sent },
7777 { 0 }
7780 static void test_scrollwindowex(void)
7782 HWND hwnd, hchild;
7783 RECT rect={0,0,130,130};
7785 hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
7786 WS_VISIBLE|WS_OVERLAPPEDWINDOW,
7787 100, 100, 200, 200, 0, 0, 0, NULL);
7788 ok (hwnd != 0, "Failed to create overlapped window\n");
7789 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
7790 WS_VISIBLE|WS_CAPTION|WS_CHILD,
7791 10, 10, 150, 150, hwnd, 0, 0, NULL);
7792 ok (hchild != 0, "Failed to create child\n");
7793 UpdateWindow(hwnd);
7794 flush_events();
7795 flush_sequence();
7797 /* scroll without the child window */
7798 trace("start scroll\n");
7799 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
7800 SW_ERASE|SW_INVALIDATE);
7801 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7802 trace("end scroll\n");
7803 flush_sequence();
7804 flush_events();
7805 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
7806 flush_events();
7807 flush_sequence();
7809 /* Now without the SW_ERASE flag */
7810 trace("start scroll\n");
7811 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
7812 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7813 trace("end scroll\n");
7814 flush_sequence();
7815 flush_events();
7816 ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
7817 flush_events();
7818 flush_sequence();
7820 /* now scroll the child window as well */
7821 trace("start scroll\n");
7822 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
7823 SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
7824 todo_wine { /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
7825 /* windows sometimes a WM_MOVE */
7826 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
7828 trace("end scroll\n");
7829 flush_sequence();
7830 flush_events();
7831 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
7832 flush_events();
7833 flush_sequence();
7835 /* now scroll with ScrollWindow() */
7836 trace("start scroll with ScrollWindow\n");
7837 ScrollWindow( hwnd, 5, 5, NULL, NULL);
7838 trace("end scroll\n");
7839 flush_sequence();
7840 flush_events();
7841 ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
7843 ok(DestroyWindow(hchild), "failed to destroy window\n");
7844 ok(DestroyWindow(hwnd), "failed to destroy window\n");
7845 flush_sequence();
7848 static const struct message destroy_window_with_children[] = {
7849 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
7850 { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
7851 { 0x0090, sent|optional },
7852 { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
7853 { 0x0090, sent|optional },
7854 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
7855 { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7856 { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7857 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
7858 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
7859 { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
7860 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
7861 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
7862 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
7863 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
7864 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
7865 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
7866 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
7867 { 0 }
7870 static void test_DestroyWindow(void)
7872 BOOL ret;
7873 HWND parent, child1, child2, child3, child4, test;
7874 UINT child_id = WND_CHILD_ID + 1;
7876 parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
7877 100, 100, 200, 200, 0, 0, 0, NULL);
7878 assert(parent != 0);
7879 child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7880 0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
7881 assert(child1 != 0);
7882 child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7883 0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
7884 assert(child2 != 0);
7885 child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
7886 0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
7887 assert(child3 != 0);
7888 child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
7889 0, 0, 50, 50, parent, 0, 0, NULL);
7890 assert(child4 != 0);
7892 /* test owner/parent of child2 */
7893 test = GetParent(child2);
7894 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7895 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
7896 if(pGetAncestor) {
7897 test = pGetAncestor(child2, GA_PARENT);
7898 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7900 test = GetWindow(child2, GW_OWNER);
7901 ok(!test, "wrong owner %p\n", test);
7903 test = SetParent(child2, parent);
7904 ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
7906 /* test owner/parent of the parent */
7907 test = GetParent(parent);
7908 ok(!test, "wrong parent %p\n", test);
7909 ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
7910 if(pGetAncestor) {
7911 test = pGetAncestor(parent, GA_PARENT);
7912 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7914 test = GetWindow(parent, GW_OWNER);
7915 ok(!test, "wrong owner %p\n", test);
7917 /* test owner/parent of child1 */
7918 test = GetParent(child1);
7919 ok(test == parent, "wrong parent %p\n", test);
7920 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
7921 if(pGetAncestor) {
7922 test = pGetAncestor(child1, GA_PARENT);
7923 ok(test == parent, "wrong parent %p\n", test);
7925 test = GetWindow(child1, GW_OWNER);
7926 ok(!test, "wrong owner %p\n", test);
7928 /* test owner/parent of child2 */
7929 test = GetParent(child2);
7930 ok(test == parent, "wrong parent %p\n", test);
7931 ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
7932 if(pGetAncestor) {
7933 test = pGetAncestor(child2, GA_PARENT);
7934 ok(test == parent, "wrong parent %p\n", test);
7936 test = GetWindow(child2, GW_OWNER);
7937 ok(!test, "wrong owner %p\n", test);
7939 /* test owner/parent of child3 */
7940 test = GetParent(child3);
7941 ok(test == child1, "wrong parent %p\n", test);
7942 ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
7943 if(pGetAncestor) {
7944 test = pGetAncestor(child3, GA_PARENT);
7945 ok(test == child1, "wrong parent %p\n", test);
7947 test = GetWindow(child3, GW_OWNER);
7948 ok(!test, "wrong owner %p\n", test);
7950 /* test owner/parent of child4 */
7951 test = GetParent(child4);
7952 ok(test == parent, "wrong parent %p\n", test);
7953 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
7954 if(pGetAncestor) {
7955 test = pGetAncestor(child4, GA_PARENT);
7956 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
7958 test = GetWindow(child4, GW_OWNER);
7959 ok(test == parent, "wrong owner %p\n", test);
7961 flush_sequence();
7963 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
7964 parent, child1, child2, child3, child4);
7966 SetCapture(child4);
7967 test = GetCapture();
7968 ok(test == child4, "wrong capture window %p\n", test);
7970 test_DestroyWindow_flag = TRUE;
7971 ret = DestroyWindow(parent);
7972 ok( ret, "DestroyWindow() error %d\n", GetLastError());
7973 test_DestroyWindow_flag = FALSE;
7974 ok_sequence(destroy_window_with_children, "destroy window with children", 0);
7976 ok(!IsWindow(parent), "parent still exists\n");
7977 ok(!IsWindow(child1), "child1 still exists\n");
7978 ok(!IsWindow(child2), "child2 still exists\n");
7979 ok(!IsWindow(child3), "child3 still exists\n");
7980 ok(!IsWindow(child4), "child4 still exists\n");
7982 test = GetCapture();
7983 ok(!test, "wrong capture window %p\n", test);
7987 static const struct message WmDispatchPaint[] = {
7988 { WM_NCPAINT, sent },
7989 { WM_GETTEXT, sent|defwinproc|optional },
7990 { WM_GETTEXT, sent|defwinproc|optional },
7991 { WM_ERASEBKGND, sent },
7992 { 0 }
7995 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7997 if (message == WM_PAINT) return 0;
7998 return MsgCheckProcA( hwnd, message, wParam, lParam );
8001 static void test_DispatchMessage(void)
8003 RECT rect;
8004 MSG msg;
8005 int count;
8006 HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8007 100, 100, 200, 200, 0, 0, 0, NULL);
8008 ShowWindow( hwnd, SW_SHOW );
8009 UpdateWindow( hwnd );
8010 flush_events();
8011 flush_sequence();
8012 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
8014 SetRect( &rect, -5, -5, 5, 5 );
8015 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8016 count = 0;
8017 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8019 if (msg.message != WM_PAINT) DispatchMessage( &msg );
8020 else
8022 flush_sequence();
8023 DispatchMessage( &msg );
8024 /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
8025 if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8026 else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
8027 if (++count > 10) break;
8030 ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
8032 trace("now without DispatchMessage\n");
8033 flush_sequence();
8034 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8035 count = 0;
8036 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8038 if (msg.message != WM_PAINT) DispatchMessage( &msg );
8039 else
8041 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
8042 flush_sequence();
8043 /* this will send WM_NCCPAINT just like DispatchMessage does */
8044 GetUpdateRgn( hwnd, hrgn, TRUE );
8045 ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8046 DeleteObject( hrgn );
8047 GetClientRect( hwnd, &rect );
8048 ValidateRect( hwnd, &rect ); /* this will stop WM_PAINTs */
8049 ok( !count, "Got multiple WM_PAINTs\n" );
8050 if (++count > 10) break;
8053 DestroyWindow(hwnd);
8057 static const struct message WmUser[] = {
8058 { WM_USER, sent },
8059 { 0 }
8062 struct sendmsg_info
8064 HWND hwnd;
8065 DWORD timeout;
8066 DWORD ret;
8069 static DWORD CALLBACK send_msg_thread( LPVOID arg )
8071 struct sendmsg_info *info = arg;
8072 info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
8073 if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT, "unexpected error %d\n", GetLastError());
8074 return 0;
8077 static void wait_for_thread( HANDLE thread )
8079 while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
8081 MSG msg;
8082 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
8086 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8088 if (message == WM_USER) Sleep(200);
8089 return MsgCheckProcA( hwnd, message, wParam, lParam );
8092 static void test_SendMessageTimeout(void)
8094 HANDLE thread;
8095 struct sendmsg_info info;
8096 DWORD tid;
8098 info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8099 100, 100, 200, 200, 0, 0, 0, NULL);
8100 flush_events();
8101 flush_sequence();
8103 info.timeout = 1000;
8104 info.ret = 0xdeadbeef;
8105 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8106 wait_for_thread( thread );
8107 CloseHandle( thread );
8108 ok( info.ret == 1, "SendMessageTimeout failed\n" );
8109 ok_sequence( WmUser, "WmUser", FALSE );
8111 info.timeout = 1;
8112 info.ret = 0xdeadbeef;
8113 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8114 Sleep(100); /* SendMessageTimeout should time out here */
8115 wait_for_thread( thread );
8116 CloseHandle( thread );
8117 ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8118 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8120 /* 0 means infinite timeout */
8121 info.timeout = 0;
8122 info.ret = 0xdeadbeef;
8123 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8124 Sleep(100);
8125 wait_for_thread( thread );
8126 CloseHandle( thread );
8127 ok( info.ret == 1, "SendMessageTimeout failed\n" );
8128 ok_sequence( WmUser, "WmUser", FALSE );
8130 /* timeout is treated as signed despite the prototype */
8131 info.timeout = 0x7fffffff;
8132 info.ret = 0xdeadbeef;
8133 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8134 Sleep(100);
8135 wait_for_thread( thread );
8136 CloseHandle( thread );
8137 ok( info.ret == 1, "SendMessageTimeout failed\n" );
8138 ok_sequence( WmUser, "WmUser", FALSE );
8140 info.timeout = 0x80000000;
8141 info.ret = 0xdeadbeef;
8142 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8143 Sleep(100);
8144 wait_for_thread( thread );
8145 CloseHandle( thread );
8146 ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8147 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8149 /* now check for timeout during message processing */
8150 SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
8151 info.timeout = 100;
8152 info.ret = 0xdeadbeef;
8153 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8154 wait_for_thread( thread );
8155 CloseHandle( thread );
8156 /* we should time out but still get the message */
8157 ok( info.ret == 0, "SendMessageTimeout failed\n" );
8158 ok_sequence( WmUser, "WmUser", FALSE );
8160 DestroyWindow( info.hwnd );
8164 /****************** edit message test *************************/
8165 #define ID_EDIT 0x1234
8166 static const struct message sl_edit_setfocus[] =
8168 { HCBT_SETFOCUS, hook },
8169 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8170 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8171 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8172 { WM_SETFOCUS, sent|wparam, 0 },
8173 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8174 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
8175 { WM_CTLCOLOREDIT, sent|parent },
8176 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8177 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8178 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8179 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8180 { 0 }
8182 static const struct message ml_edit_setfocus[] =
8184 { HCBT_SETFOCUS, hook },
8185 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8186 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8187 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8188 { WM_SETFOCUS, sent|wparam, 0 },
8189 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8190 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8191 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8192 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8193 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8194 { 0 }
8196 static const struct message sl_edit_killfocus[] =
8198 { HCBT_SETFOCUS, hook },
8199 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8200 { WM_KILLFOCUS, sent|wparam, 0 },
8201 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8202 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8203 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
8204 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
8205 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
8206 { 0 }
8208 static const struct message sl_edit_lbutton_dblclk[] =
8210 { WM_LBUTTONDBLCLK, sent },
8211 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8212 { 0 }
8214 static const struct message sl_edit_lbutton_down[] =
8216 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8217 { HCBT_SETFOCUS, hook },
8218 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8219 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8220 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8221 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8222 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8223 { WM_CTLCOLOREDIT, sent|parent },
8224 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8225 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8226 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8227 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8228 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8229 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8230 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8231 { WM_CTLCOLOREDIT, sent|parent|optional },
8232 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8233 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8234 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8235 { 0 }
8237 static const struct message ml_edit_lbutton_down[] =
8239 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8240 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8241 { HCBT_SETFOCUS, hook },
8242 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8243 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8244 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8245 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
8246 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8247 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8248 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8249 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8250 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8251 { 0 }
8253 static const struct message sl_edit_lbutton_up[] =
8255 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8256 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8257 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8258 { WM_CAPTURECHANGED, sent|defwinproc },
8259 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8260 { 0 }
8262 static const struct message ml_edit_lbutton_up[] =
8264 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
8265 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
8266 { WM_CAPTURECHANGED, sent|defwinproc },
8267 { 0 }
8270 static WNDPROC old_edit_proc;
8272 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8274 static long defwndproc_counter = 0;
8275 LRESULT ret;
8276 struct message msg;
8278 trace("edit: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
8280 /* explicitly ignore WM_GETICON message */
8281 if (message == WM_GETICON) return 0;
8283 msg.message = message;
8284 msg.flags = sent|wparam|lparam;
8285 if (defwndproc_counter) msg.flags |= defwinproc;
8286 msg.wParam = wParam;
8287 msg.lParam = lParam;
8288 add_message(&msg);
8290 defwndproc_counter++;
8291 ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
8292 defwndproc_counter--;
8294 return ret;
8297 static void subclass_edit(void)
8299 WNDCLASSA cls;
8301 if (!GetClassInfoA(0, "edit", &cls)) assert(0);
8303 old_edit_proc = cls.lpfnWndProc;
8305 cls.hInstance = GetModuleHandle(0);
8306 cls.lpfnWndProc = edit_hook_proc;
8307 cls.lpszClassName = "my_edit_class";
8308 UnregisterClass(cls.lpszClassName, cls.hInstance);
8309 if (!RegisterClassA(&cls)) assert(0);
8312 static void test_edit_messages(void)
8314 HWND hwnd, parent;
8315 DWORD dlg_code;
8317 subclass_edit();
8318 log_all_parent_messages++;
8320 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
8321 100, 100, 200, 200, 0, 0, 0, NULL);
8322 ok (parent != 0, "Failed to create parent window\n");
8324 /* test single line edit */
8325 hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
8326 0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8327 ok(hwnd != 0, "Failed to create edit window\n");
8329 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8330 ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
8332 ShowWindow(hwnd, SW_SHOW);
8333 UpdateWindow(hwnd);
8334 SetFocus(0);
8335 flush_sequence();
8337 SetFocus(hwnd);
8338 ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
8340 SetFocus(0);
8341 ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
8343 SetFocus(0);
8344 ReleaseCapture();
8345 flush_sequence();
8347 SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8348 ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
8350 SetFocus(0);
8351 ReleaseCapture();
8352 flush_sequence();
8354 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8355 ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
8357 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8358 ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
8360 DestroyWindow(hwnd);
8362 /* test multiline edit */
8363 hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
8364 0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
8365 ok(hwnd != 0, "Failed to create edit window\n");
8367 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
8368 ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
8369 "wrong dlg_code %08x\n", dlg_code);
8371 ShowWindow(hwnd, SW_SHOW);
8372 UpdateWindow(hwnd);
8373 SetFocus(0);
8374 flush_sequence();
8376 SetFocus(hwnd);
8377 ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
8379 SetFocus(0);
8380 ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
8382 SetFocus(0);
8383 ReleaseCapture();
8384 flush_sequence();
8386 SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
8387 ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
8389 SetFocus(0);
8390 ReleaseCapture();
8391 flush_sequence();
8393 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
8394 ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
8396 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
8397 ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
8399 DestroyWindow(hwnd);
8400 DestroyWindow(parent);
8402 log_all_parent_messages--;
8405 /**************************** End of Edit test ******************************/
8407 static const struct message WmKeyDownSkippedSeq[] =
8409 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
8410 { 0 }
8412 static const struct message WmKeyUpSkippedSeq[] =
8414 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
8415 { 0 }
8418 #define EV_START_STOP 0
8419 #define EV_SENDMSG 1
8420 #define EV_ACK 2
8422 struct peekmsg_info
8424 HWND hwnd;
8425 HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
8428 static DWORD CALLBACK send_msg_thread_2(void *param)
8430 DWORD ret;
8431 struct peekmsg_info *info = param;
8433 trace("thread: waiting for start\n");
8434 WaitForSingleObject(info->hevent[EV_START_STOP], INFINITE);
8435 trace("thread: looping\n");
8437 while (1)
8439 ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
8441 switch (ret)
8443 case WAIT_OBJECT_0 + EV_START_STOP:
8444 trace("thread: exiting\n");
8445 return 0;
8447 case WAIT_OBJECT_0 + EV_SENDMSG:
8448 trace("thread: sending message\n");
8449 SendNotifyMessageA(info->hwnd, WM_USER, 0, 0);
8450 SetEvent(info->hevent[EV_ACK]);
8451 break;
8453 default:
8454 trace("unexpected return: %04x\n", ret);
8455 assert(0);
8456 break;
8459 return 0;
8462 static void test_PeekMessage(void)
8464 MSG msg;
8465 HANDLE hthread;
8466 DWORD tid, qstatus;
8467 UINT qs_all_input = QS_ALLINPUT;
8468 UINT qs_input = QS_INPUT;
8469 BOOL ret;
8470 struct peekmsg_info info;
8472 info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8473 100, 100, 200, 200, 0, 0, 0, NULL);
8474 assert(info.hwnd);
8475 ShowWindow(info.hwnd, SW_SHOW);
8476 UpdateWindow(info.hwnd);
8477 SetFocus(info.hwnd);
8479 info.hevent[EV_START_STOP] = CreateEventA(NULL, 0, 0, NULL);
8480 info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
8481 info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
8483 hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
8484 Sleep(100);
8486 trace("signalling to start looping\n");
8487 SetEvent(info.hevent[EV_START_STOP]);
8489 flush_events();
8490 flush_sequence();
8492 SetLastError(0xdeadbeef);
8493 qstatus = GetQueueStatus(qs_all_input);
8494 if (GetLastError() == ERROR_INVALID_FLAGS)
8496 trace("QS_RAWINPUT not supported on this platform\n");
8497 qs_all_input &= ~QS_RAWINPUT;
8498 qs_input &= ~QS_RAWINPUT;
8500 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8502 trace("signalling to send message\n");
8503 SetEvent(info.hevent[EV_SENDMSG]);
8504 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8506 /* pass invalid QS_xxxx flags */
8507 SetLastError(0xdeadbeef);
8508 qstatus = GetQueueStatus(0xffffffff);
8509 ok(qstatus == 0, "GetQueueStatus should fail: %08x\n", qstatus);
8510 ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
8512 qstatus = GetQueueStatus(qs_all_input);
8513 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
8514 "wrong qstatus %08x\n", qstatus);
8516 msg.message = 0;
8517 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8518 ok(!ret,
8519 "PeekMessageA should have returned FALSE instead of msg %04x\n",
8520 msg.message);
8521 ok_sequence(WmUser, "WmUser", FALSE);
8523 qstatus = GetQueueStatus(qs_all_input);
8524 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
8526 keybd_event('N', 0, 0, 0);
8527 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
8528 qstatus = GetQueueStatus(qs_all_input);
8529 ok(qstatus == MAKELONG(QS_KEY, QS_KEY),
8530 "wrong qstatus %08x\n", qstatus);
8532 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8533 qstatus = GetQueueStatus(qs_all_input);
8534 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8535 "wrong qstatus %08x\n", qstatus);
8537 InvalidateRect(info.hwnd, NULL, FALSE);
8538 qstatus = GetQueueStatus(qs_all_input);
8539 ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8540 "wrong qstatus %08x\n", qstatus);
8542 trace("signalling to send message\n");
8543 SetEvent(info.hevent[EV_SENDMSG]);
8544 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8546 qstatus = GetQueueStatus(qs_all_input);
8547 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8548 "wrong qstatus %08x\n", qstatus);
8550 msg.message = 0;
8551 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
8552 ok(!ret,
8553 "PeekMessageA should have returned FALSE instead of msg %04x\n",
8554 msg.message);
8555 ok_sequence(WmUser, "WmUser", FALSE);
8557 qstatus = GetQueueStatus(qs_all_input);
8558 ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8559 "wrong qstatus %08x\n", qstatus);
8561 trace("signalling to send message\n");
8562 SetEvent(info.hevent[EV_SENDMSG]);
8563 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8565 qstatus = GetQueueStatus(qs_all_input);
8566 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8567 "wrong qstatus %08x\n", qstatus);
8569 msg.message = 0;
8570 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8571 ok(!ret,
8572 "PeekMessageA should have returned FALSE instead of msg %04x\n",
8573 msg.message);
8574 ok_sequence(WmUser, "WmUser", FALSE);
8576 qstatus = GetQueueStatus(qs_all_input);
8577 ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
8578 "wrong qstatus %08x\n", qstatus);
8580 msg.message = 0;
8581 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8582 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8583 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8584 ret, msg.message, msg.wParam);
8585 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8587 qstatus = GetQueueStatus(qs_all_input);
8588 ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
8589 "wrong qstatus %08x\n", qstatus);
8591 msg.message = 0;
8592 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
8593 ok(!ret,
8594 "PeekMessageA should have returned FALSE instead of msg %04x\n",
8595 msg.message);
8596 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8598 qstatus = GetQueueStatus(qs_all_input);
8599 ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
8600 "wrong qstatus %08x\n", qstatus);
8602 msg.message = 0;
8603 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
8604 ok(ret && msg.message == WM_PAINT,
8605 "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
8606 DispatchMessageA(&msg);
8607 ok_sequence(WmPaint, "WmPaint", FALSE);
8609 qstatus = GetQueueStatus(qs_all_input);
8610 ok(qstatus == MAKELONG(0, QS_KEY),
8611 "wrong qstatus %08x\n", qstatus);
8613 msg.message = 0;
8614 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
8615 ok(!ret,
8616 "PeekMessageA should have returned FALSE instead of msg %04x\n",
8617 msg.message);
8618 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8620 qstatus = GetQueueStatus(qs_all_input);
8621 ok(qstatus == MAKELONG(0, QS_KEY),
8622 "wrong qstatus %08x\n", qstatus);
8624 trace("signalling to send message\n");
8625 SetEvent(info.hevent[EV_SENDMSG]);
8626 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8628 qstatus = GetQueueStatus(qs_all_input);
8629 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
8630 "wrong qstatus %08x\n", qstatus);
8632 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8634 qstatus = GetQueueStatus(qs_all_input);
8635 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
8636 "wrong qstatus %08x\n", qstatus);
8638 msg.message = 0;
8639 ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
8640 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8641 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8642 ret, msg.message, msg.wParam);
8643 ok_sequence(WmUser, "WmUser", FALSE);
8645 qstatus = GetQueueStatus(qs_all_input);
8646 ok(qstatus == MAKELONG(0, QS_KEY),
8647 "wrong qstatus %08x\n", qstatus);
8649 msg.message = 0;
8650 ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
8651 ok(!ret,
8652 "PeekMessageA should have returned FALSE instead of msg %04x\n",
8653 msg.message);
8654 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8656 qstatus = GetQueueStatus(qs_all_input);
8657 ok(qstatus == MAKELONG(0, QS_KEY),
8658 "wrong qstatus %08x\n", qstatus);
8660 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
8662 qstatus = GetQueueStatus(qs_all_input);
8663 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
8664 "wrong qstatus %08x\n", qstatus);
8666 trace("signalling to send message\n");
8667 SetEvent(info.hevent[EV_SENDMSG]);
8668 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
8670 qstatus = GetQueueStatus(qs_all_input);
8671 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
8672 "wrong qstatus %08x\n", qstatus);
8674 msg.message = 0;
8675 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
8676 ok(!ret,
8677 "PeekMessageA should have returned FALSE instead of msg %04x\n",
8678 msg.message);
8679 ok_sequence(WmUser, "WmUser", FALSE);
8681 qstatus = GetQueueStatus(qs_all_input);
8682 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
8683 "wrong qstatus %08x\n", qstatus);
8685 msg.message = 0;
8686 if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
8687 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
8688 else /* workaround for a missing QS_RAWINPUT support */
8689 ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
8690 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
8691 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
8692 ret, msg.message, msg.wParam);
8693 ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
8695 qstatus = GetQueueStatus(qs_all_input);
8696 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
8697 "wrong qstatus %08x\n", qstatus);
8699 msg.message = 0;
8700 if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
8701 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
8702 else /* workaround for a missing QS_RAWINPUT support */
8703 ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
8704 ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
8705 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
8706 ret, msg.message, msg.wParam);
8707 ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
8709 qstatus = GetQueueStatus(qs_all_input);
8710 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8711 "wrong qstatus %08x\n", qstatus);
8713 msg.message = 0;
8714 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
8715 ok(!ret,
8716 "PeekMessageA should have returned FALSE instead of msg %04x\n",
8717 msg.message);
8718 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8720 qstatus = GetQueueStatus(qs_all_input);
8721 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8722 "wrong qstatus %08x\n", qstatus);
8724 msg.message = 0;
8725 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8726 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
8727 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
8728 ret, msg.message, msg.wParam);
8729 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8731 qstatus = GetQueueStatus(qs_all_input);
8732 ok(qstatus == 0,
8733 "wrong qstatus %08x\n", qstatus);
8735 msg.message = 0;
8736 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8737 ok(!ret,
8738 "PeekMessageA should have returned FALSE instead of msg %04x\n",
8739 msg.message);
8740 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8742 qstatus = GetQueueStatus(qs_all_input);
8743 ok(qstatus == 0,
8744 "wrong qstatus %08x\n", qstatus);
8746 /* test whether presence of the quit flag in the queue affects
8747 * the queue state
8749 PostQuitMessage(0x1234abcd);
8751 qstatus = GetQueueStatus(qs_all_input);
8752 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
8753 "wrong qstatus %08x\n", qstatus);
8755 PostMessageA(info.hwnd, WM_USER, 0, 0);
8757 qstatus = GetQueueStatus(qs_all_input);
8758 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
8759 "wrong qstatus %08x\n", qstatus);
8761 msg.message = 0;
8762 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8763 ok(ret && msg.message == WM_USER,
8764 "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
8765 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8767 qstatus = GetQueueStatus(qs_all_input);
8768 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8769 "wrong qstatus %08x\n", qstatus);
8771 msg.message = 0;
8772 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8773 ok(ret && msg.message == WM_QUIT,
8774 "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
8775 ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
8776 ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
8777 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8779 qstatus = GetQueueStatus(qs_all_input);
8780 todo_wine {
8781 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
8782 "wrong qstatus %08x\n", qstatus);
8785 msg.message = 0;
8786 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
8787 ok(!ret,
8788 "PeekMessageA should have returned FALSE instead of msg %04x\n",
8789 msg.message);
8790 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
8792 qstatus = GetQueueStatus(qs_all_input);
8793 ok(qstatus == 0,
8794 "wrong qstatus %08x\n", qstatus);
8796 trace("signalling to exit\n");
8797 SetEvent(info.hevent[EV_START_STOP]);
8799 WaitForSingleObject(hthread, INFINITE);
8801 CloseHandle(hthread);
8802 CloseHandle(info.hevent[0]);
8803 CloseHandle(info.hevent[1]);
8804 CloseHandle(info.hevent[2]);
8806 DestroyWindow(info.hwnd);
8809 static void wait_move_event(HWND hwnd, int x, int y)
8811 MSG msg;
8812 DWORD time;
8813 BOOL ret;
8814 int go = 0;
8816 time = GetTickCount();
8817 while (GetTickCount() - time < 200 && !go) {
8818 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
8819 go = ret && msg.pt.x > x && msg.pt.y > y;
8823 #define STEP 20
8824 static void test_PeekMessage2(void)
8826 HWND hwnd;
8827 BOOL ret;
8828 MSG msg;
8829 UINT message;
8830 DWORD time1, time2, time3;
8831 int x1, y1, x2, y2, x3, y3;
8832 POINT pos;
8834 time1 = time2 = time3 = 0;
8835 x1 = y1 = x2 = y2 = x3 = y3 = 0;
8837 /* Initialise window and make sure it is ready for events */
8838 hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
8839 10, 10, 800, 800, NULL, NULL, NULL, NULL);
8840 assert(hwnd);
8841 trace("Window for test_PeekMessage2 %p\n", hwnd);
8842 ShowWindow(hwnd, SW_SHOW);
8843 UpdateWindow(hwnd);
8844 SetFocus(hwnd);
8845 GetCursorPos(&pos);
8846 SetCursorPos(100, 100);
8847 mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
8848 flush_events();
8850 /* Do initial mousemove, wait until we can see it
8851 and then do our test peek with PM_NOREMOVE. */
8852 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
8853 wait_move_event(hwnd, 80, 80);
8855 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
8856 ok(ret, "no message available\n");
8857 if (ret) {
8858 trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
8859 message = msg.message;
8860 time1 = msg.time;
8861 x1 = msg.pt.x;
8862 y1 = msg.pt.y;
8863 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
8866 /* Allow time to advance a bit, and then simulate the user moving their
8867 * mouse around. After that we peek again with PM_NOREMOVE.
8868 * Although the previous mousemove message was never removed, the
8869 * mousemove we now peek should reflect the recent mouse movements
8870 * because the input queue will merge the move events. */
8871 Sleep(2);
8872 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
8873 wait_move_event(hwnd, x1, y1);
8875 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
8876 ok(ret, "no message available\n");
8877 if (ret) {
8878 trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
8879 message = msg.message;
8880 time2 = msg.time;
8881 x2 = msg.pt.x;
8882 y2 = msg.pt.y;
8883 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
8884 ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
8885 ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
8888 /* Have another go, to drive the point home */
8889 Sleep(2);
8890 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
8891 wait_move_event(hwnd, x2, y2);
8893 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
8894 ok(ret, "no message available\n");
8895 if (ret) {
8896 trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
8897 message = msg.message;
8898 time3 = msg.time;
8899 x3 = msg.pt.x;
8900 y3 = msg.pt.y;
8901 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
8902 ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
8903 ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
8906 DestroyWindow(hwnd);
8907 SetCursorPos(pos.x, pos.y);
8908 flush_events();
8911 static void test_quit_message(void)
8913 MSG msg;
8914 BOOL ret;
8916 /* test using PostQuitMessage */
8917 PostQuitMessage(0xbeef);
8919 ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
8920 ok(ret, "PeekMessage failed with error %d\n", GetLastError());
8921 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8922 ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
8924 ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
8925 ok(ret, "PostMessage failed with error %d\n", GetLastError());
8927 ret = GetMessage(&msg, NULL, 0, 0);
8928 ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
8929 ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
8931 /* note: WM_QUIT message received after WM_USER message */
8932 ret = GetMessage(&msg, NULL, 0, 0);
8933 ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
8934 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8935 ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
8937 ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
8938 ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
8940 /* now test with PostThreadMessage - different behaviour! */
8941 PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
8943 ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
8944 ok(ret, "PeekMessage failed with error %d\n", GetLastError());
8945 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8946 ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
8948 ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
8949 ok(ret, "PostMessage failed with error %d\n", GetLastError());
8951 /* note: we receive the WM_QUIT message first this time */
8952 ret = GetMessage(&msg, NULL, 0, 0);
8953 ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
8954 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
8955 ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
8957 ret = GetMessage(&msg, NULL, 0, 0);
8958 ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
8959 ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
8962 static const struct message WmMouseHoverSeq[] = {
8963 { WM_MOUSEACTIVATE, sent|optional }, /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
8964 { WM_MOUSEACTIVATE, sent|optional },
8965 { WM_TIMER, sent|optional }, /* XP sends it */
8966 { WM_SYSTIMER, sent },
8967 { WM_MOUSEHOVER, sent|wparam, 0 },
8968 { 0 }
8971 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
8973 MSG msg;
8974 DWORD start_ticks, end_ticks;
8976 start_ticks = GetTickCount();
8977 /* add some deviation (5%) to cover not expected delays */
8978 start_ticks += timeout / 20;
8982 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
8984 /* Timer proc messages are not dispatched to the window proc,
8985 * and therefore not logged.
8987 if (msg.message == WM_TIMER || msg.message == WM_SYSTIMER)
8989 struct message s_msg;
8991 s_msg.message = msg.message;
8992 s_msg.flags = sent|wparam|lparam;
8993 s_msg.wParam = msg.wParam;
8994 s_msg.lParam = msg.lParam;
8995 add_message(&s_msg);
8997 DispatchMessage(&msg);
9000 end_ticks = GetTickCount();
9002 /* inject WM_MOUSEMOVE to see how it changes tracking */
9003 if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
9005 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9006 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9008 inject_mouse_move = FALSE;
9010 } while (start_ticks + timeout >= end_ticks);
9013 static void test_TrackMouseEvent(void)
9015 TRACKMOUSEEVENT tme;
9016 BOOL ret;
9017 HWND hwnd, hchild;
9018 RECT rc_parent, rc_child;
9019 UINT default_hover_time, hover_width = 0, hover_height = 0;
9021 #define track_hover(track_hwnd, track_hover_time) \
9022 tme.cbSize = sizeof(tme); \
9023 tme.dwFlags = TME_HOVER; \
9024 tme.hwndTrack = track_hwnd; \
9025 tme.dwHoverTime = track_hover_time; \
9026 SetLastError(0xdeadbeef); \
9027 ret = pTrackMouseEvent(&tme); \
9028 ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
9030 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
9031 tme.cbSize = sizeof(tme); \
9032 tme.dwFlags = TME_QUERY; \
9033 tme.hwndTrack = (HWND)0xdeadbeef; \
9034 tme.dwHoverTime = 0xdeadbeef; \
9035 SetLastError(0xdeadbeef); \
9036 ret = pTrackMouseEvent(&tme); \
9037 ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
9038 ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
9039 ok(tme.dwFlags == (expected_track_flags), \
9040 "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
9041 ok(tme.hwndTrack == (expected_track_hwnd), \
9042 "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
9043 ok(tme.dwHoverTime == (expected_hover_time), \
9044 "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
9046 #define track_hover_cancel(track_hwnd) \
9047 tme.cbSize = sizeof(tme); \
9048 tme.dwFlags = TME_HOVER | TME_CANCEL; \
9049 tme.hwndTrack = track_hwnd; \
9050 tme.dwHoverTime = 0xdeadbeef; \
9051 SetLastError(0xdeadbeef); \
9052 ret = pTrackMouseEvent(&tme); \
9053 ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
9055 default_hover_time = 0xdeadbeef;
9056 SetLastError(0xdeadbeef);
9057 ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
9058 ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
9059 if (!ret) default_hover_time = 400;
9060 trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
9062 SetLastError(0xdeadbeef);
9063 ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
9064 ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
9065 if (!ret) hover_width = 4;
9066 SetLastError(0xdeadbeef);
9067 ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
9068 ok(ret, "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
9069 if (!ret) hover_height = 4;
9070 trace("hover rect is %u x %d\n", hover_width, hover_height);
9072 hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
9073 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9074 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
9075 NULL, NULL, 0);
9076 assert(hwnd);
9078 hchild = CreateWindowEx(0, "TestWindowClass", NULL,
9079 WS_CHILD | WS_BORDER | WS_VISIBLE,
9080 50, 50, 200, 200, hwnd,
9081 NULL, NULL, 0);
9082 assert(hchild);
9084 flush_events();
9085 flush_sequence();
9087 tme.cbSize = 0;
9088 tme.dwFlags = TME_QUERY;
9089 tme.hwndTrack = (HWND)0xdeadbeef;
9090 tme.dwHoverTime = 0xdeadbeef;
9091 SetLastError(0xdeadbeef);
9092 ret = pTrackMouseEvent(&tme);
9093 ok(!ret, "TrackMouseEvent should fail\n");
9094 ok(GetLastError() == ERROR_INVALID_PARAMETER, "not expected error %d\n", GetLastError());
9096 tme.cbSize = sizeof(tme);
9097 tme.dwFlags = TME_HOVER;
9098 tme.hwndTrack = (HWND)0xdeadbeef;
9099 tme.dwHoverTime = 0xdeadbeef;
9100 SetLastError(0xdeadbeef);
9101 ret = pTrackMouseEvent(&tme);
9102 ok(!ret, "TrackMouseEvent should fail\n");
9103 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "not expected error %d\n", GetLastError());
9105 tme.cbSize = sizeof(tme);
9106 tme.dwFlags = TME_HOVER | TME_CANCEL;
9107 tme.hwndTrack = (HWND)0xdeadbeef;
9108 tme.dwHoverTime = 0xdeadbeef;
9109 SetLastError(0xdeadbeef);
9110 ret = pTrackMouseEvent(&tme);
9111 ok(!ret, "TrackMouseEvent should fail\n");
9112 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "not expected error %d\n", GetLastError());
9114 GetWindowRect(hwnd, &rc_parent);
9115 GetWindowRect(hchild, &rc_child);
9116 SetCursorPos(rc_child.left - 10, rc_child.top - 10);
9118 /* Process messages so that the system updates its internal current
9119 * window and hittest, otherwise TrackMouseEvent calls don't have any
9120 * effect.
9122 flush_events();
9123 flush_sequence();
9125 track_query(0, NULL, 0);
9126 track_hover(hchild, 0);
9127 track_query(0, NULL, 0);
9129 flush_events();
9130 flush_sequence();
9132 track_hover(hwnd, 0);
9133 track_query(TME_HOVER, hwnd, default_hover_time);
9135 pump_msg_loop_timeout(default_hover_time, FALSE);
9136 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9138 track_query(0, NULL, 0);
9140 track_hover(hwnd, HOVER_DEFAULT);
9141 track_query(TME_HOVER, hwnd, default_hover_time);
9143 Sleep(default_hover_time / 2);
9144 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9145 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9147 track_query(TME_HOVER, hwnd, default_hover_time);
9149 pump_msg_loop_timeout(default_hover_time / 2, FALSE);
9150 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9152 track_query(0, NULL, 0);
9154 track_hover(hwnd, HOVER_DEFAULT);
9155 track_query(TME_HOVER, hwnd, default_hover_time);
9157 pump_msg_loop_timeout(default_hover_time, TRUE);
9158 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
9160 track_query(0, NULL, 0);
9162 track_hover(hwnd, HOVER_DEFAULT);
9163 track_query(TME_HOVER, hwnd, default_hover_time);
9164 track_hover_cancel(hwnd);
9166 DestroyWindow(hwnd);
9168 #undef track_hover
9169 #undef track_query
9170 #undef track_hover_cancel
9174 static const struct message WmSetWindowRgn[] = {
9175 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9176 { WM_NCCALCSIZE, sent|wparam, 1 },
9177 { WM_NCPAINT, sent }, /* wparam != 1 */
9178 { WM_GETTEXT, sent|defwinproc|optional },
9179 { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
9180 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9181 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9182 { 0 }
9185 static const struct message WmSetWindowRgn_no_redraw[] = {
9186 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9187 { WM_NCCALCSIZE, sent|wparam, 1 },
9188 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
9189 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9190 { 0 }
9193 static const struct message WmSetWindowRgn_clear[] = {
9194 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9195 { WM_NCCALCSIZE, sent|wparam, 1 },
9196 { WM_NCPAINT, sent }, /* wparam != 1 */
9197 { WM_GETTEXT, sent|defwinproc|optional },
9198 { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
9199 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
9200 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
9201 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
9202 { WM_GETTEXT, sent|defwinproc|optional },
9203 { WM_ERASEBKGND, sent|optional },
9204 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9205 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
9206 { 0 }
9209 static void test_SetWindowRgn(void)
9211 HRGN hrgn;
9212 HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
9213 100, 100, 200, 200, 0, 0, 0, NULL);
9214 ok( hwnd != 0, "Failed to create overlapped window\n" );
9216 ShowWindow( hwnd, SW_SHOW );
9217 UpdateWindow( hwnd );
9218 flush_events();
9219 flush_sequence();
9221 trace("testing SetWindowRgn\n");
9222 hrgn = CreateRectRgn( 0, 0, 150, 150 );
9223 SetWindowRgn( hwnd, hrgn, TRUE );
9224 ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
9226 hrgn = CreateRectRgn( 30, 30, 160, 160 );
9227 SetWindowRgn( hwnd, hrgn, FALSE );
9228 ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
9230 hrgn = CreateRectRgn( 0, 0, 180, 180 );
9231 SetWindowRgn( hwnd, hrgn, TRUE );
9232 ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
9234 SetWindowRgn( hwnd, 0, TRUE );
9235 ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
9237 DestroyWindow( hwnd );
9240 /*************************** ShowWindow() test ******************************/
9241 static const struct message WmShowNormal[] = {
9242 { WM_SHOWWINDOW, sent|wparam, 1 },
9243 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9244 { HCBT_ACTIVATE, hook },
9245 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9246 { HCBT_SETFOCUS, hook },
9247 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9248 { 0 }
9250 static const struct message WmShow[] = {
9251 { WM_SHOWWINDOW, sent|wparam, 1 },
9252 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9253 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9254 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9255 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9256 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9257 { 0 }
9259 static const struct message WmShowNoActivate_1[] = {
9260 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9261 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
9262 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
9263 { WM_MOVE, sent|defwinproc },
9264 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9265 { 0 }
9267 static const struct message WmShowNoActivate_2[] = {
9268 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
9269 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9270 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9271 { WM_MOVE, sent|defwinproc },
9272 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9273 { HCBT_SETFOCUS, hook|optional },
9274 { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9275 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9276 { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9277 { 0 }
9279 static const struct message WmShowNA_1[] = {
9280 { WM_SHOWWINDOW, sent|wparam, 1 },
9281 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9282 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9283 { 0 }
9285 static const struct message WmShowNA_2[] = {
9286 { WM_SHOWWINDOW, sent|wparam, 1 },
9287 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9288 { 0 }
9290 static const struct message WmRestore_1[] = {
9291 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9292 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9293 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9294 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9295 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9296 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9297 { WM_MOVE, sent|defwinproc },
9298 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9299 { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9300 { 0 }
9302 static const struct message WmRestore_2[] = {
9303 { WM_SHOWWINDOW, sent|wparam, 1 },
9304 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9305 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9306 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9307 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9308 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9309 { 0 }
9311 static const struct message WmRestore_3[] = {
9312 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9313 { WM_GETMINMAXINFO, sent },
9314 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9315 { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
9316 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
9317 { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
9318 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9319 { WM_MOVE, sent|defwinproc },
9320 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9321 { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9322 { 0 }
9324 static const struct message WmRestore_4[] = {
9325 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
9326 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9327 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9328 { WM_MOVE, sent|defwinproc },
9329 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9330 { 0 }
9332 static const struct message WmRestore_5[] = {
9333 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
9334 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9335 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9336 { WM_MOVE, sent|defwinproc },
9337 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
9338 { 0 }
9340 static const struct message WmHide_1[] = {
9341 { WM_SHOWWINDOW, sent|wparam, 0 },
9342 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9343 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9344 { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
9345 { 0 }
9347 static const struct message WmHide_2[] = {
9348 { WM_SHOWWINDOW, sent|wparam, 0 },
9349 { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9350 { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
9351 { 0 }
9353 static const struct message WmHide_3[] = {
9354 { WM_SHOWWINDOW, sent|wparam, 0 },
9355 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
9356 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9357 { HCBT_SETFOCUS, hook },
9358 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9359 { 0 }
9361 static const struct message WmShowMinimized_1[] = {
9362 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9363 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9364 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9365 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9366 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9367 { WM_MOVE, sent|defwinproc },
9368 { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9369 { 0 }
9371 static const struct message WmMinimize_1[] = {
9372 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9373 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9374 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9375 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9376 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9377 { WM_MOVE, sent|defwinproc },
9378 { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9379 { 0 }
9381 static const struct message WmMinimize_2[] = {
9382 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9383 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9384 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9385 { WM_MOVE, sent|defwinproc },
9386 { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9387 { 0 }
9389 static const struct message WmMinimize_3[] = {
9390 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9391 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9392 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9393 { WM_MOVE, sent|defwinproc },
9394 { WM_SIZE, sent|wparam|defwinproc, SIZE_MINIMIZED },
9395 { 0 }
9397 static const struct message WmShowMinNoActivate[] = {
9398 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9399 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
9400 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9401 { 0 }
9403 static const struct message WmMinMax_1[] = {
9404 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
9405 { 0 }
9407 static const struct message WmMinMax_2[] = {
9408 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9409 { 0 }
9411 static const struct message WmMinMax_3[] = {
9412 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
9413 { 0 }
9415 static const struct message WmMinMax_4[] = {
9416 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
9417 { 0 }
9419 static const struct message WmShowMaximized_1[] = {
9420 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9421 { WM_GETMINMAXINFO, sent },
9422 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9423 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9424 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9425 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9426 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9427 { WM_MOVE, sent|defwinproc },
9428 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9429 { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
9430 { 0 }
9432 static const struct message WmShowMaximized_2[] = {
9433 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9434 { WM_GETMINMAXINFO, sent },
9435 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
9436 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
9437 { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
9438 { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
9439 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9440 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
9441 { WM_MOVE, sent|defwinproc },
9442 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9443 { HCBT_SETFOCUS, hook },
9444 { 0 }
9446 static const struct message WmShowMaximized_3[] = {
9447 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
9448 { WM_GETMINMAXINFO, sent },
9449 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9450 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
9451 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
9452 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
9453 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
9454 { WM_MOVE, sent|defwinproc },
9455 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
9456 { 0 }
9459 static void test_ShowWindow(void)
9461 /* ShowWindow commands in random order */
9462 static const struct
9464 INT cmd; /* ShowWindow command */
9465 LPARAM ret; /* ShowWindow return value */
9466 DWORD style; /* window style after the command */
9467 const struct message *msg; /* message sequence the command produces */
9468 BOOL todo_msg; /* message sequence doesn't match what Wine does */
9469 } sw[] =
9471 /* 1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
9472 /* 2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9473 /* 3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
9474 /* 4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9475 /* 5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
9476 /* 6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
9477 /* 7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
9478 /* 8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
9479 /* 9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
9480 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
9481 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
9482 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
9483 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
9484 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9485 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
9486 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9487 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
9488 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9489 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
9490 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
9491 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9492 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
9493 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
9494 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9495 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
9496 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
9497 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
9498 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9499 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
9500 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
9501 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9502 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, TRUE },
9503 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9504 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE }, /* what does this mean?! */
9505 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE },
9506 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9507 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
9508 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9509 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9510 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, FALSE },
9511 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
9512 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, TRUE },
9513 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
9514 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
9515 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
9516 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
9517 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
9518 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
9519 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
9520 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
9521 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
9522 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
9523 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
9524 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, FALSE },
9525 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
9526 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
9527 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
9529 HWND hwnd;
9530 DWORD style;
9531 LPARAM ret;
9532 INT i;
9534 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
9535 hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
9536 120, 120, 90, 90,
9537 0, 0, 0, NULL);
9538 assert(hwnd);
9540 style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
9541 ok(style == 0, "expected style 0, got %08x\n", style);
9543 flush_events();
9544 flush_sequence();
9546 for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
9548 static const char * const sw_cmd_name[13] =
9550 "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
9551 "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
9552 "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
9553 "SW_NORMALNA" /* 0xCC */
9555 char comment[64];
9556 INT idx; /* index into the above array of names */
9558 idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
9560 style = GetWindowLong(hwnd, GWL_STYLE);
9561 trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
9562 ret = ShowWindow(hwnd, sw[i].cmd);
9563 ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
9564 style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
9565 ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
9567 sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
9568 ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
9570 flush_events();
9571 flush_sequence();
9574 DestroyWindow(hwnd);
9577 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9579 struct message msg;
9581 trace("dialog: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
9583 switch (message)
9585 case WM_WINDOWPOSCHANGING:
9586 case WM_WINDOWPOSCHANGED:
9588 WINDOWPOS *winpos = (WINDOWPOS *)lParam;
9590 trace("%s\n", (message == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
9591 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
9592 winpos->hwnd, winpos->hwndInsertAfter,
9593 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
9594 dump_winpos_flags(winpos->flags);
9596 /* Log only documented flags, win2k uses 0x1000 and 0x2000
9597 * in the high word for internal purposes
9599 wParam = winpos->flags & 0xffff;
9600 /* We are not interested in the flags that don't match under XP and Win9x */
9601 wParam &= ~(SWP_NOZORDER);
9602 break;
9605 /* explicitly ignore WM_GETICON message */
9606 case WM_GETICON:
9607 return 0;
9610 msg.message = message;
9611 msg.flags = sent|wparam|lparam;
9612 msg.wParam = wParam;
9613 msg.lParam = lParam;
9614 add_message(&msg);
9616 /* calling DefDlgProc leads to a recursion under XP */
9618 switch (message)
9620 case WM_INITDIALOG:
9621 case WM_GETDLGCODE:
9622 return 0;
9624 return 1;
9627 static const struct message WmDefDlgSetFocus_1[] = {
9628 { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
9629 { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
9630 { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
9631 { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
9632 { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
9633 { HCBT_SETFOCUS, hook },
9634 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9635 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9636 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9637 { WM_SETFOCUS, sent|wparam, 0 },
9638 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9639 { WM_CTLCOLOREDIT, sent },
9640 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9641 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9642 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9643 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9644 { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
9645 { 0 }
9647 static const struct message WmDefDlgSetFocus_2[] = {
9648 { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
9649 { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
9650 { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
9651 { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
9652 { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
9653 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9654 { WM_CTLCOLOREDIT, sent|optional }, /* XP */
9655 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9656 { 0 }
9658 /* Creation of a dialog */
9659 static const struct message WmCreateDialogParamSeq_1[] = {
9660 { HCBT_CREATEWND, hook },
9661 { WM_NCCREATE, sent },
9662 { WM_NCCALCSIZE, sent|wparam, 0 },
9663 { WM_CREATE, sent },
9664 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
9665 { WM_SIZE, sent|wparam, SIZE_RESTORED },
9666 { WM_MOVE, sent },
9667 { WM_SETFONT, sent },
9668 { WM_INITDIALOG, sent },
9669 { WM_CHANGEUISTATE, sent|optional },
9670 { 0 }
9672 /* Creation of a dialog */
9673 static const struct message WmCreateDialogParamSeq_2[] = {
9674 { HCBT_CREATEWND, hook },
9675 { WM_NCCREATE, sent },
9676 { WM_NCCALCSIZE, sent|wparam, 0 },
9677 { WM_CREATE, sent },
9678 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
9679 { WM_SIZE, sent|wparam, SIZE_RESTORED },
9680 { WM_MOVE, sent },
9681 { WM_CHANGEUISTATE, sent|optional },
9682 { 0 }
9685 static void test_dialog_messages(void)
9687 WNDCLASS cls;
9688 HWND hdlg, hedit1, hedit2, hfocus;
9689 LRESULT ret;
9691 #define set_selection(hctl, start, end) \
9692 ret = SendMessage(hctl, EM_SETSEL, start, end); \
9693 ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
9695 #define check_selection(hctl, start, end) \
9696 ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
9697 ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
9699 subclass_edit();
9701 hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
9702 WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
9703 0, 0, 100, 100, 0, 0, 0, NULL);
9704 ok(hdlg != 0, "Failed to create custom dialog window\n");
9706 hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
9707 WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
9708 0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
9709 ok(hedit1 != 0, "Failed to create edit control\n");
9710 hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
9711 WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
9712 0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
9713 ok(hedit2 != 0, "Failed to create edit control\n");
9715 SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
9716 SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
9718 hfocus = GetFocus();
9719 ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
9721 SetFocus(hedit2);
9722 hfocus = GetFocus();
9723 ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
9725 check_selection(hedit1, 0, 0);
9726 check_selection(hedit2, 0, 0);
9728 set_selection(hedit2, 0, -1);
9729 check_selection(hedit2, 0, 3);
9731 SetFocus(0);
9732 hfocus = GetFocus();
9733 ok(hfocus == 0, "wrong focus %p\n", hfocus);
9735 flush_sequence();
9736 ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
9737 ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
9738 ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
9740 hfocus = GetFocus();
9741 ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
9743 check_selection(hedit1, 0, 5);
9744 check_selection(hedit2, 0, 3);
9746 flush_sequence();
9747 ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
9748 ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
9749 ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
9751 hfocus = GetFocus();
9752 ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
9754 check_selection(hedit1, 0, 5);
9755 check_selection(hedit2, 0, 3);
9757 EndDialog(hdlg, 0);
9758 DestroyWindow(hedit1);
9759 DestroyWindow(hedit2);
9760 DestroyWindow(hdlg);
9761 flush_sequence();
9763 #undef set_selection
9764 #undef check_selection
9766 ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
9767 cls.lpszClassName = "MyDialogClass";
9768 cls.hInstance = GetModuleHandle(0);
9769 /* need a cast since a dlgproc is used as a wndproc */
9770 cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
9771 if (!RegisterClass(&cls)) assert(0);
9773 hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
9774 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
9775 ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
9776 EndDialog(hdlg, 0);
9777 DestroyWindow(hdlg);
9778 flush_sequence();
9780 hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
9781 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
9782 ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
9783 EndDialog(hdlg, 0);
9784 DestroyWindow(hdlg);
9785 flush_sequence();
9787 UnregisterClass(cls.lpszClassName, cls.hInstance);
9790 static void test_nullCallback(void)
9792 HWND hwnd;
9794 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
9795 100, 100, 200, 200, 0, 0, 0, NULL);
9796 ok (hwnd != 0, "Failed to create overlapped window\n");
9798 SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
9799 flush_events();
9800 DestroyWindow(hwnd);
9803 static const struct message SetForegroundWindowSeq[] =
9805 { WM_NCACTIVATE, sent|wparam, 0 },
9806 { WM_GETTEXT, sent|defwinproc|optional },
9807 { WM_ACTIVATE, sent|wparam, 0 },
9808 { WM_ACTIVATEAPP, sent|wparam, 0 },
9809 { WM_KILLFOCUS, sent },
9810 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
9811 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
9812 { 0 }
9815 static void test_SetForegroundWindow(void)
9817 HWND hwnd;
9819 hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
9820 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9821 100, 100, 200, 200, 0, 0, 0, NULL);
9822 ok (hwnd != 0, "Failed to create overlapped window\n");
9823 flush_sequence();
9825 trace("SetForegroundWindow( 0 )\n");
9826 SetForegroundWindow( 0 );
9827 ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
9828 trace("SetForegroundWindow( GetDesktopWindow() )\n");
9829 SetForegroundWindow( GetDesktopWindow() );
9830 ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
9831 "foreground top level window", FALSE);
9832 trace("done\n");
9834 DestroyWindow(hwnd);
9837 static void test_dbcs_wm_char(void)
9839 BYTE dbch[2];
9840 WCHAR wch, bad_wch;
9841 HWND hwnd, hwnd2;
9842 MSG msg;
9843 DWORD time;
9844 POINT pt;
9845 DWORD_PTR res;
9846 CPINFOEXA cpinfo;
9847 UINT i, j, k;
9848 struct message wmCharSeq[2];
9850 if (!pGetCPInfoExA)
9852 skip("GetCPInfoExA is not available\n");
9853 return;
9856 pGetCPInfoExA( CP_ACP, 0, &cpinfo );
9857 if (cpinfo.MaxCharSize != 2)
9859 skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
9860 return;
9863 dbch[0] = dbch[1] = 0;
9864 wch = 0;
9865 bad_wch = cpinfo.UnicodeDefaultChar;
9866 for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
9867 for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
9868 for (k = 128; k <= 255; k++)
9870 char str[2];
9871 WCHAR wstr[2];
9872 str[0] = j;
9873 str[1] = k;
9874 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
9875 WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
9876 (BYTE)str[0] == j && (BYTE)str[1] == k &&
9877 HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
9879 dbch[0] = j;
9880 dbch[1] = k;
9881 wch = wstr[0];
9882 break;
9886 if (!wch)
9888 skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
9889 return;
9891 trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
9892 dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
9894 hwnd = CreateWindowExW(0, testWindowClassW, NULL,
9895 WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
9896 hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
9897 WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
9898 ok (hwnd != 0, "Failed to create overlapped window\n");
9899 ok (hwnd2 != 0, "Failed to create overlapped window\n");
9900 flush_sequence();
9902 memset( wmCharSeq, 0, sizeof(wmCharSeq) );
9903 wmCharSeq[0].message = WM_CHAR;
9904 wmCharSeq[0].flags = sent|wparam;
9905 wmCharSeq[0].wParam = wch;
9907 /* posted message */
9908 PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9909 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9910 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9911 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9912 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9913 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
9914 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9916 /* posted thread message */
9917 PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
9918 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9919 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9920 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9921 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9922 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
9923 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9925 /* sent message */
9926 flush_sequence();
9927 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9928 ok_sequence( WmEmptySeq, "no messages", FALSE );
9929 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9930 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9931 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9933 /* sent message with timeout */
9934 flush_sequence();
9935 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
9936 ok_sequence( WmEmptySeq, "no messages", FALSE );
9937 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
9938 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9939 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9941 /* sent message with timeout and callback */
9942 flush_sequence();
9943 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
9944 ok_sequence( WmEmptySeq, "no messages", FALSE );
9945 SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
9946 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9947 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9949 /* sent message with callback */
9950 flush_sequence();
9951 SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
9952 ok_sequence( WmEmptySeq, "no messages", FALSE );
9953 SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
9954 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9955 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9957 /* direct window proc call */
9958 flush_sequence();
9959 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
9960 ok_sequence( WmEmptySeq, "no messages", FALSE );
9961 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
9962 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9964 /* dispatch message */
9965 msg.hwnd = hwnd;
9966 msg.message = WM_CHAR;
9967 msg.wParam = dbch[0];
9968 msg.lParam = 0;
9969 DispatchMessageA( &msg );
9970 ok_sequence( WmEmptySeq, "no messages", FALSE );
9971 msg.wParam = dbch[1];
9972 DispatchMessageA( &msg );
9973 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9975 /* window handle is irrelevant */
9976 flush_sequence();
9977 SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
9978 ok_sequence( WmEmptySeq, "no messages", FALSE );
9979 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9980 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9981 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9983 /* interleaved post and send */
9984 flush_sequence();
9985 PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
9986 SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
9987 ok_sequence( WmEmptySeq, "no messages", FALSE );
9988 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9989 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9990 ok_sequence( WmEmptySeq, "no messages", FALSE );
9991 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
9992 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
9993 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
9994 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9995 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
9996 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
9997 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
9999 /* interleaved sent message and winproc */
10000 flush_sequence();
10001 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10002 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10003 ok_sequence( WmEmptySeq, "no messages", FALSE );
10004 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10005 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10006 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10007 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10009 /* interleaved winproc and dispatch */
10010 msg.hwnd = hwnd;
10011 msg.message = WM_CHAR;
10012 msg.wParam = dbch[0];
10013 msg.lParam = 0;
10014 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
10015 DispatchMessageA( &msg );
10016 ok_sequence( WmEmptySeq, "no messages", FALSE );
10017 msg.wParam = dbch[1];
10018 DispatchMessageA( &msg );
10019 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10020 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
10021 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10023 /* interleaved sends */
10024 flush_sequence();
10025 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
10026 SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
10027 ok_sequence( WmEmptySeq, "no messages", FALSE );
10028 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
10029 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10030 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
10031 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10033 /* dbcs WM_CHAR */
10034 flush_sequence();
10035 SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
10036 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
10037 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10039 /* other char messages are not magic */
10040 PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
10041 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10042 ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
10043 ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10044 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10045 PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
10046 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10047 ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
10048 ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
10049 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10051 /* test retrieving messages */
10053 PostMessageW( hwnd, WM_CHAR, wch, 0 );
10054 ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10055 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10056 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10057 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10058 ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10059 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10060 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10061 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10062 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10064 /* message filters */
10065 PostMessageW( hwnd, WM_CHAR, wch, 0 );
10066 ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
10067 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10068 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10069 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10070 /* message id is filtered, hwnd is not */
10071 ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
10072 ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
10073 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10074 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10075 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10076 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10078 /* mixing GetMessage and PostMessage */
10079 PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
10080 ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
10081 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10082 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10083 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10084 ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10085 time = msg.time;
10086 pt = msg.pt;
10087 ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
10088 ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10089 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10090 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10091 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10092 ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
10093 ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
10094 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 );
10095 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10097 /* without PM_REMOVE */
10098 PostMessageW( hwnd, WM_CHAR, wch, 0 );
10099 ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10100 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10101 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10102 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10103 ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10104 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10105 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10106 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10107 ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
10108 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10109 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10110 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10111 ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
10112 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
10113 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
10114 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
10115 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
10117 DestroyWindow(hwnd);
10120 #define ID_LISTBOX 0x000f
10122 static const struct message wm_lb_setcursel_0[] =
10124 { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
10125 { WM_CTLCOLORLISTBOX, sent|parent },
10126 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10127 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10128 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10129 { 0 }
10131 static const struct message wm_lb_setcursel_1[] =
10133 { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
10134 { WM_CTLCOLORLISTBOX, sent|parent },
10135 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
10136 { WM_CTLCOLORLISTBOX, sent|parent },
10137 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
10138 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10139 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
10140 { 0 }
10142 static const struct message wm_lb_setcursel_2[] =
10144 { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
10145 { WM_CTLCOLORLISTBOX, sent|parent },
10146 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
10147 { WM_CTLCOLORLISTBOX, sent|parent },
10148 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
10149 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10150 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10151 { 0 }
10153 static const struct message wm_lb_click_0[] =
10155 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
10156 { HCBT_SETFOCUS, hook },
10157 { WM_KILLFOCUS, sent|parent },
10158 { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
10159 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
10160 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10161 { WM_SETFOCUS, sent|defwinproc },
10163 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
10164 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
10165 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
10166 { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
10167 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
10169 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
10170 { WM_CTLCOLORLISTBOX, sent|parent },
10171 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
10172 { WM_CTLCOLORLISTBOX, sent|parent },
10173 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
10174 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
10176 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10177 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
10179 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
10180 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
10181 { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
10182 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
10183 { 0 }
10186 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
10188 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
10190 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
10192 static long defwndproc_counter = 0;
10193 LRESULT ret;
10194 struct message msg;
10196 /* do not log painting messages */
10197 if (message != WM_PAINT &&
10198 message != WM_NCPAINT &&
10199 message != WM_SYNCPAINT &&
10200 message != WM_ERASEBKGND &&
10201 message != WM_NCHITTEST &&
10202 message != WM_GETTEXT &&
10203 message != WM_GETICON &&
10204 message != WM_DEVICECHANGE)
10206 trace("listbox: %p, %04x, %08lx, %08lx\n", hwnd, message, wp, lp);
10208 msg.message = message;
10209 msg.flags = sent|wparam|lparam;
10210 if (defwndproc_counter) msg.flags |= defwinproc;
10211 msg.wParam = wp;
10212 msg.lParam = lp;
10213 add_message(&msg);
10216 defwndproc_counter++;
10217 ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
10218 defwndproc_counter--;
10220 return ret;
10223 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
10224 int caret_index, int top_index, int line)
10226 LRESULT ret;
10228 /* calling an orig proc helps to avoid unnecessary message logging */
10229 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
10230 ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
10231 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
10232 ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
10233 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
10234 ok_(__FILE__, line)(ret == caret_index, "expected caret index %d, got %ld\n", caret_index, ret);
10235 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
10236 ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
10239 static void test_listbox_messages(void)
10241 HWND parent, listbox;
10242 LRESULT ret;
10244 parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10245 100, 100, 200, 200, 0, 0, 0, NULL);
10246 listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
10247 WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
10248 10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
10249 listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
10251 check_lb_state(listbox, 0, LB_ERR, 0, 0);
10253 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
10254 ok(ret == 0, "expected 0, got %ld\n", ret);
10255 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
10256 ok(ret == 1, "expected 1, got %ld\n", ret);
10257 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
10258 ok(ret == 2, "expected 2, got %ld\n", ret);
10260 check_lb_state(listbox, 3, LB_ERR, 0, 0);
10262 flush_sequence();
10264 log_all_parent_messages++;
10266 trace("selecting item 0\n");
10267 ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
10268 ok(ret == 0, "expected 0, got %ld\n", ret);
10269 ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
10270 check_lb_state(listbox, 3, 0, 0, 0);
10271 flush_sequence();
10273 trace("selecting item 1\n");
10274 ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
10275 ok(ret == 1, "expected 1, got %ld\n", ret);
10276 ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
10277 check_lb_state(listbox, 3, 1, 1, 0);
10279 trace("selecting item 2\n");
10280 ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
10281 ok(ret == 2, "expected 2, got %ld\n", ret);
10282 ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
10283 check_lb_state(listbox, 3, 2, 2, 0);
10285 trace("clicking on item 0\n");
10286 ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
10287 ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
10288 ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
10289 ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
10290 ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
10291 check_lb_state(listbox, 3, 0, 0, 0);
10292 flush_sequence();
10294 log_all_parent_messages--;
10296 DestroyWindow(listbox);
10297 DestroyWindow(parent);
10300 START_TEST(msg)
10302 BOOL ret;
10303 FARPROC pIsWinEventHookInstalled = 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
10305 init_procs();
10307 if (!RegisterWindowClasses()) assert(0);
10309 if (pSetWinEventHook)
10311 hEvent_hook = (HWINEVENTHOOK)pSetWinEventHook(EVENT_MIN, EVENT_MAX,
10312 GetModuleHandleA(0),
10313 win_event_proc,
10315 GetCurrentThreadId(),
10316 WINEVENT_INCONTEXT);
10317 assert(hEvent_hook);
10319 if (pIsWinEventHookInstalled)
10321 UINT event;
10322 for (event = EVENT_MIN; event <= EVENT_MAX; event++)
10323 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
10327 cbt_hook_thread_id = GetCurrentThreadId();
10328 hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
10329 assert(hCBT_hook);
10331 test_winevents();
10333 /* Fix message sequences before removing 4 lines below */
10334 #if 1
10335 if (pUnhookWinEvent && hEvent_hook)
10337 ret = pUnhookWinEvent(hEvent_hook);
10338 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
10339 pUnhookWinEvent = 0;
10341 hEvent_hook = 0;
10342 #endif
10344 test_ShowWindow();
10345 test_PeekMessage();
10346 test_PeekMessage2();
10347 test_scrollwindowex();
10348 test_messages();
10349 test_showwindow();
10350 invisible_parent_tests();
10351 test_mdi_messages();
10352 test_button_messages();
10353 test_static_messages();
10354 test_listbox_messages();
10355 test_combobox_messages();
10356 test_paint_messages();
10357 test_interthread_messages();
10358 test_message_conversion();
10359 test_accelerators();
10360 test_timers();
10361 test_timers_no_wnd();
10362 test_set_hook();
10363 test_DestroyWindow();
10364 test_DispatchMessage();
10365 test_SendMessageTimeout();
10366 test_edit_messages();
10367 test_quit_message();
10369 if (!pTrackMouseEvent)
10370 skip("TrackMouseEvent is not available\n");
10371 else
10372 test_TrackMouseEvent();
10374 test_SetWindowRgn();
10375 test_sys_menu();
10376 test_dialog_messages();
10377 test_nullCallback();
10378 test_SetForegroundWindow();
10379 test_dbcs_wm_char();
10381 UnhookWindowsHookEx(hCBT_hook);
10382 if (pUnhookWinEvent)
10384 ret = pUnhookWinEvent(hEvent_hook);
10385 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
10386 SetLastError(0xdeadbeef);
10387 ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
10388 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
10389 GetLastError() == 0xdeadbeef, /* Win9x */
10390 "unexpected error %d\n", GetLastError());
10392 else
10393 skip("UnhookWinEvent is not available\n");