[USER32_WINETEST]
[reactos.git] / rostests / winetests / user32 / msg.c
1 /*
2 * Unit tests for window message handling
3 *
4 * Copyright 1999 Ove Kaaven
5 * Copyright 2003 Dimitrie O. Paun
6 * Copyright 2004, 2005 Dmitry Timoshkov
7 *
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.
12 *
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.
17 *
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
21 */
22
23 //#define _WIN32_WINNT 0x0600 /* For WM_CHANGEUISTATE,QS_RAWINPUT,WM_DWMxxxx */
24 //#define WINVER 0x0600 /* for WM_GETTITLEBARINFOEX */
25
26 #include <assert.h>
27 #include <stdarg.h>
28 #include <stdio.h>
29
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winuser.h"
34 #include "winnls.h"
35
36 #include "wine/test.h"
37
38 #define MDI_FIRST_CHILD_ID 2004
39
40 /* undocumented SWP flags - from SDK 3.1 */
41 #define SWP_NOCLIENTSIZE 0x0800
42 #define SWP_NOCLIENTMOVE 0x1000
43 #define SWP_STATECHANGED 0x8000
44
45 #define SW_NORMALNA 0xCC /* undoc. flag in MinMaximize */
46
47 #ifndef WM_KEYF1
48 #define WM_KEYF1 0x004d
49 #endif
50
51 #ifndef WM_SYSTIMER
52 #define WM_SYSTIMER 0x0118
53 #endif
54
55 #define WND_PARENT_ID 1
56 #define WND_POPUP_ID 2
57 #define WND_CHILD_ID 3
58
59 #ifndef WM_LBTRACKPOINT
60 #define WM_LBTRACKPOINT 0x0131
61 #endif
62
63 /* encoded DRAWITEMSTRUCT into an LPARAM */
64 typedef struct
65 {
66 union
67 {
68 struct
69 {
70 UINT type : 4; /* ODT_* flags */
71 UINT ctl_id : 4; /* Control ID */
72 UINT item_id : 4; /* Menu item ID */
73 UINT action : 4; /* ODA_* flags */
74 UINT state : 16; /* ODS_* flags */
75 } item;
76 LPARAM lp;
77 } u;
78 } DRAW_ITEM_STRUCT;
79
80 static BOOL test_DestroyWindow_flag;
81 static HWINEVENTHOOK hEvent_hook;
82 static HHOOK hKBD_hook;
83 static HHOOK hCBT_hook;
84 static DWORD cbt_hook_thread_id;
85
86 static const WCHAR testWindowClassW[] =
87 { 'T','e','s','t','W','i','n','d','o','w','C','l','a','s','s','W',0 };
88
89 /*
90 FIXME: add tests for these
91 Window Edge Styles (Win31/Win95/98 look), in order of precedence:
92 WS_EX_DLGMODALFRAME: double border, WS_CAPTION allowed
93 WS_THICKFRAME: thick border
94 WS_DLGFRAME: double border, WS_CAPTION not allowed (but possibly shown anyway)
95 WS_BORDER (default for overlapped windows): single black border
96 none (default for child (and popup?) windows): no border
97 */
98
99 typedef enum {
100 sent=0x1,
101 posted=0x2,
102 parent=0x4,
103 wparam=0x8,
104 lparam=0x10,
105 defwinproc=0x20,
106 beginpaint=0x40,
107 optional=0x80,
108 hook=0x100,
109 winevent_hook=0x200,
110 kbd_hook=0x400
111 } msg_flags_t;
112
113 struct message {
114 UINT message; /* the WM_* code */
115 msg_flags_t flags; /* message props */
116 WPARAM wParam; /* expected value of wParam */
117 LPARAM lParam; /* expected value of lParam */
118 WPARAM wp_mask; /* mask for wParam checks */
119 LPARAM lp_mask; /* mask for lParam checks */
120 };
121
122 struct recvd_message {
123 UINT message; /* the WM_* code */
124 msg_flags_t flags; /* message props */
125 HWND hwnd; /* window that received the message */
126 WPARAM wParam; /* expected value of wParam */
127 LPARAM lParam; /* expected value of lParam */
128 int line; /* source line where logged */
129 const char *descr; /* description for trace output */
130 char output[512]; /* trace output */
131 };
132
133 /* Empty message sequence */
134 static const struct message WmEmptySeq[] =
135 {
136 { 0 }
137 };
138 /* CreateWindow (for overlapped window, not initially visible) (16/32) */
139 static const struct message WmCreateOverlappedSeq[] = {
140 { HCBT_CREATEWND, hook },
141 { WM_GETMINMAXINFO, sent },
142 { WM_NCCREATE, sent },
143 { WM_NCCALCSIZE, sent|wparam, 0 },
144 { 0x0093, sent|defwinproc|optional },
145 { 0x0094, sent|defwinproc|optional },
146 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
147 { WM_CREATE, sent },
148 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
149 { 0 }
150 };
151 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
152 * for a not visible overlapped window.
153 */
154 static const struct message WmSWP_ShowOverlappedSeq[] = {
155 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
156 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
157 { WM_NCPAINT, sent|wparam|optional, 1 },
158 { WM_GETTEXT, sent|defwinproc|optional },
159 { WM_ERASEBKGND, sent|optional },
160 { HCBT_ACTIVATE, hook },
161 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
162 { WM_NOTIFYFORMAT, sent|optional },
163 { WM_QUERYUISTATE, sent|optional },
164 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
165 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x: SWP_NOSENDCHANGING */
166 { WM_ACTIVATEAPP, sent|wparam, 1 },
167 { WM_NCACTIVATE, sent },
168 { WM_GETTEXT, sent|defwinproc|optional },
169 { WM_ACTIVATE, sent|wparam, 1 },
170 { HCBT_SETFOCUS, hook },
171 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
172 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
173 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
174 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
175 { WM_GETTEXT, sent|optional },
176 { WM_NCPAINT, sent|wparam|optional, 1 },
177 { WM_GETTEXT, sent|defwinproc|optional },
178 { WM_ERASEBKGND, sent|optional },
179 /* Win9x adds SWP_NOZORDER below */
180 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
181 { WM_GETTEXT, sent|optional },
182 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
183 { WM_NCPAINT, sent|wparam|optional, 1 },
184 { WM_ERASEBKGND, sent|optional },
185 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
186 { WM_SYNCPAINT, sent|optional },
187 { WM_GETTITLEBARINFOEX, sent|optional },
188 { WM_PAINT, sent|optional },
189 { WM_NCPAINT, sent|beginpaint|optional },
190 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
191 { WM_ERASEBKGND, sent|beginpaint|optional },
192 { 0 }
193 };
194 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
195 * for a visible overlapped window.
196 */
197 static const struct message WmSWP_HideOverlappedSeq[] = {
198 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
199 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
200 { HCBT_ACTIVATE, hook|optional },
201 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
202 { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
203 { WM_NCACTIVATE, sent|optional },
204 { WM_ACTIVATE, sent|optional },
205 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
206 { 0 }
207 };
208
209 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
210 * for a visible overlapped window.
211 */
212 static const struct message WmSWP_ResizeSeq[] = {
213 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
214 { WM_GETMINMAXINFO, sent|defwinproc },
215 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
216 { WM_NCPAINT, sent|optional },
217 { WM_GETTEXT, sent|defwinproc|optional },
218 { WM_ERASEBKGND, sent|optional },
219 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
220 { WM_SIZE, sent|defwinproc|optional },
221 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
222 { WM_NCPAINT, sent|optional },
223 { WM_GETTEXT, sent|defwinproc|optional },
224 { WM_ERASEBKGND, sent|optional },
225 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
226 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
227 { 0 }
228 };
229
230 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
231 * for a visible popup window.
232 */
233 static const struct message WmSWP_ResizePopupSeq[] = {
234 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
235 { WM_GETMINMAXINFO, sent|defwinproc|optional }, /* Win9x */
236 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
237 { WM_NCPAINT, sent|optional },
238 { WM_GETTEXT, sent|defwinproc|optional },
239 { WM_ERASEBKGND, sent|optional },
240 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
241 { WM_SIZE, sent|defwinproc|wparam|optional, SIZE_RESTORED },
242 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
243 { WM_NCPAINT, sent|optional },
244 { WM_GETTEXT, sent|defwinproc|optional },
245 { WM_ERASEBKGND, sent|optional },
246 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
247 { 0 }
248 };
249
250 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
251 * for a visible overlapped window.
252 */
253 static const struct message WmSWP_MoveSeq[] = {
254 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE },
255 { WM_NCPAINT, sent|optional },
256 { WM_GETTEXT, sent|defwinproc|optional },
257 { WM_ERASEBKGND, sent|optional },
258 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
259 { WM_MOVE, sent|defwinproc|wparam, 0 },
260 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
261 { 0 }
262 };
263 /* Resize with SetWindowPos(SWP_NOZORDER)
264 * for a visible overlapped window
265 * SWP_NOZORDER is stripped by the logging code
266 */
267 static const struct message WmSWP_ResizeNoZOrder[] = {
268 { WM_WINDOWPOSCHANGING, sent|wparam, /*SWP_NOZORDER|*/SWP_NOACTIVATE },
269 { WM_GETMINMAXINFO, sent|defwinproc },
270 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
271 { WM_NCPAINT, sent|optional },
272 { WM_GETTEXT, sent|defwinproc|optional },
273 { WM_ERASEBKGND, sent|optional },
274 { WM_WINDOWPOSCHANGED, sent|wparam|optional, /*SWP_NOZORDER|*/SWP_NOACTIVATE, 0,
275 SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
276 { WM_MOVE, sent|defwinproc|optional },
277 { WM_SIZE, sent|defwinproc|optional },
278 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
279 { WM_NCPAINT, sent|optional }, /* Win9x doesn't send it */
280 { WM_GETTEXT, sent|defwinproc|optional }, /* Win9x doesn't send it */
281 { WM_ERASEBKGND, sent|optional }, /* Win9x doesn't send it */
282 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
283 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
284 { 0 }
285 };
286
287 /* Switch visible mdi children */
288 static const struct message WmSwitchChild[] = {
289 /* Switch MDI child */
290 { WM_MDIACTIVATE, sent },/* in the MDI client */
291 { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 1st MDI child */
292 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
293 { WM_CHILDACTIVATE, sent },/* in the 1st MDI child */
294 /* Deactivate 2nd MDI child */
295 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
296 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
297 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
298 /* Preparing for maximize and maximize the 1st MDI child */
299 { WM_GETMINMAXINFO, sent|defwinproc }, /* in the 1st MDI child */
300 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED }, /* in the 1st MDI child */
301 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
302 { WM_CHILDACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
303 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 1st MDI child */
304 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED }, /* in the 1st MDI child */
305 /* Lock redraw 2nd MDI child */
306 { WM_SETREDRAW, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
307 { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
308 /* Restore 2nd MDI child */
309 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },/* in the 2nd MDI child */
310 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
311 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
312 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 2nd MDI child */
313 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED }, /* in the 2nd MDI child */
314 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
315 /* Redraw 2nd MDI child */
316 { WM_SETREDRAW, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
317 /* Redraw MDI frame */
318 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },/* in MDI frame */
319 { WM_NCCALCSIZE, sent|wparam, 1 },/* in MDI frame */
320 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in MDI frame */
321 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in MDI frame */
322 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
323 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
324 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
325 { HCBT_SETFOCUS, hook },
326 { WM_KILLFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
327 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },/* in the 1st MDI child */
328 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
329 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
330 { WM_SETFOCUS, sent },/* in the MDI client */
331 { HCBT_SETFOCUS, hook },
332 { WM_KILLFOCUS, sent },/* in the MDI client */
333 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
334 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 }, /* in the 1st MDI child */
335 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
336 { WM_SETFOCUS, sent|defwinproc }, /* in the 1st MDI child */
337 { WM_MDIACTIVATE, sent|defwinproc },/* in the 1st MDI child */
338 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* in the 1st MDI child */
339 { 0 }
340 };
341
342 /* Switch visible not maximized mdi children */
343 static const struct message WmSwitchNotMaximizedChild[] = {
344 /* Switch not maximized MDI child */
345 { WM_MDIACTIVATE, sent },/* in the MDI client */
346 { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 2nd MDI child */
347 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
348 { WM_CHILDACTIVATE, sent },/* in the 2nd MDI child */
349 /* Deactivate 1st MDI child */
350 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
351 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
352 /* Activate 2nd MDI child */
353 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE}, /* in the 2nd MDI child */
354 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 2nd MDI child */
355 { HCBT_SETFOCUS, hook }, /* in the 1st MDI child */
356 { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
357 { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
358 { WM_IME_SETCONTEXT, sent|optional }, /* in the MDI client */
359 { WM_SETFOCUS, sent, 0 }, /* in the MDI client */
360 { HCBT_SETFOCUS, hook },
361 { WM_KILLFOCUS, sent }, /* in the MDI client */
362 { WM_IME_SETCONTEXT, sent|optional }, /* in the MDI client */
363 { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
364 { WM_SETFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
365 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
366 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in the 2nd MDI child */
367 { 0 }
368 };
369
370
371 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
372 SWP_NOZORDER|SWP_FRAMECHANGED)
373 * for a visible overlapped window with WS_CLIPCHILDREN style set.
374 */
375 static const struct message WmSWP_FrameChanged_clip[] = {
376 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
377 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
378 { WM_NCPAINT, sent|parent|optional }, /* wparam != 1 */
379 { WM_GETTEXT, sent|parent|defwinproc|optional },
380 { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
381 { WM_NCPAINT, sent }, /* wparam != 1 */
382 { WM_ERASEBKGND, sent },
383 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
384 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
385 { WM_PAINT, sent },
386 { 0 }
387 };
388 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|
389 SWP_NOZORDER|SWP_FRAMECHANGED)
390 * for a visible overlapped window.
391 */
392 static const struct message WmSWP_FrameChangedDeferErase[] = {
393 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
394 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
395 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
396 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
397 { WM_PAINT, sent|parent|optional },
398 { WM_NCPAINT, sent|beginpaint|parent|optional }, /* wparam != 1 */
399 { WM_GETTEXT, sent|beginpaint|parent|defwinproc|optional },
400 { WM_PAINT, sent },
401 { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
402 { WM_ERASEBKGND, sent|beginpaint|optional },
403 { 0 }
404 };
405
406 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
407 SWP_NOZORDER|SWP_FRAMECHANGED)
408 * for a visible overlapped window without WS_CLIPCHILDREN style set.
409 */
410 static const struct message WmSWP_FrameChanged_noclip[] = {
411 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
412 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
413 { WM_NCPAINT, sent|parent|optional }, /* wparam != 1 */
414 { WM_GETTEXT, sent|parent|defwinproc|optional },
415 { WM_ERASEBKGND, sent|parent|optional },
416 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
417 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
418 { WM_PAINT, sent },
419 { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
420 { WM_ERASEBKGND, sent|beginpaint|optional },
421 { 0 }
422 };
423
424 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
425 static const struct message WmShowOverlappedSeq[] = {
426 { WM_SHOWWINDOW, sent|wparam, 1 },
427 { WM_NCPAINT, sent|wparam|optional, 1 },
428 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
429 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
430 { WM_NCPAINT, sent|wparam|optional, 1 },
431 { WM_GETTEXT, sent|defwinproc|optional },
432 { WM_ERASEBKGND, sent|optional },
433 { HCBT_ACTIVATE, hook },
434 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
435 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
436 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
437 { WM_NCPAINT, sent|wparam|optional, 1 },
438 { WM_ACTIVATEAPP, sent|wparam, 1 },
439 { WM_NCACTIVATE, sent|wparam, 1 },
440 { WM_GETTEXT, sent|defwinproc|optional },
441 { WM_ACTIVATE, sent|wparam, 1 },
442 { HCBT_SETFOCUS, hook },
443 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
444 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
445 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
446 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
447 { WM_GETTEXT, sent|optional },
448 { WM_NCPAINT, sent|wparam|optional, 1 },
449 { WM_GETTEXT, sent|defwinproc|optional },
450 { WM_ERASEBKGND, sent|optional },
451 /* Win9x adds SWP_NOZORDER below */
452 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
453 { WM_NCCALCSIZE, sent|optional },
454 { WM_GETTEXT, sent|optional },
455 { WM_NCPAINT, sent|optional },
456 { WM_ERASEBKGND, sent|optional },
457 { WM_SYNCPAINT, sent|optional },
458 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
459 * messages. Does that mean that CreateWindow doesn't set initial
460 * window dimensions for overlapped windows?
461 */
462 { WM_SIZE, sent },
463 { WM_MOVE, sent },
464 #endif
465 { WM_PAINT, sent|optional },
466 { WM_NCPAINT, sent|beginpaint|optional },
467 { 0 }
468 };
469 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible overlapped window */
470 static const struct message WmShowMaxOverlappedSeq[] = {
471 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
472 { WM_GETMINMAXINFO, sent },
473 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
474 { WM_GETMINMAXINFO, sent|defwinproc },
475 { WM_NCCALCSIZE, sent|wparam, TRUE },
476 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
477 { HCBT_ACTIVATE, hook },
478 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
479 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
480 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
481 { WM_ACTIVATEAPP, sent|wparam, 1 },
482 { WM_NCACTIVATE, sent|wparam, 1 },
483 { WM_GETTEXT, sent|defwinproc|optional },
484 { WM_ACTIVATE, sent|wparam, 1 },
485 { HCBT_SETFOCUS, hook },
486 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
487 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
488 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
489 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
490 { WM_GETTEXT, sent|optional },
491 { WM_NCPAINT, sent|wparam|optional, 1 },
492 { WM_GETTEXT, sent|defwinproc|optional },
493 { WM_ERASEBKGND, sent|optional },
494 /* Win9x adds SWP_NOZORDER below */
495 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
496 { WM_MOVE, sent|defwinproc },
497 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
498 { WM_GETTEXT, sent|optional },
499 { WM_NCCALCSIZE, sent|optional },
500 { WM_NCPAINT, sent|optional },
501 { WM_ERASEBKGND, sent|optional },
502 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
503 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
504 { WM_SYNCPAINT, sent|optional },
505 { WM_GETTITLEBARINFOEX, sent|optional },
506 { WM_PAINT, sent|optional },
507 { WM_NCPAINT, sent|beginpaint|optional },
508 { WM_ERASEBKGND, sent|beginpaint|optional },
509 { 0 }
510 };
511 /* ShowWindow(SW_RESTORE) for a not visible maximized overlapped window */
512 static const struct message WmShowRestoreMaxOverlappedSeq[] = {
513 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
514 { WM_GETTEXT, sent|optional },
515 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
516 { WM_GETMINMAXINFO, sent|defwinproc },
517 { WM_NCCALCSIZE, sent|wparam, TRUE },
518 { WM_NCPAINT, sent|optional },
519 { WM_GETTEXT, sent|defwinproc|optional },
520 { WM_ERASEBKGND, sent|optional },
521 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
522 { WM_MOVE, sent|defwinproc|optional },
523 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
524 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
525 { WM_NCPAINT, sent|optional },
526 { WM_ERASEBKGND, sent|optional },
527 { WM_PAINT, sent|optional },
528 { WM_GETTITLEBARINFOEX, sent|optional },
529 { WM_NCPAINT, sent|beginpaint|optional },
530 { WM_ERASEBKGND, sent|beginpaint|optional },
531 { 0 }
532 };
533 /* ShowWindow(SW_RESTORE) for a not visible minimized overlapped window */
534 static const struct message WmShowRestoreMinOverlappedSeq[] = {
535 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
536 { WM_QUERYOPEN, sent|optional },
537 { WM_GETTEXT, sent|optional },
538 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED|SWP_NOCOPYBITS },
539 { WM_GETMINMAXINFO, sent|defwinproc },
540 { WM_NCCALCSIZE, sent|wparam, TRUE },
541 { HCBT_ACTIVATE, hook },
542 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
543 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
544 { WM_ACTIVATEAPP, sent|wparam, 1 },
545 { WM_NCACTIVATE, sent|wparam, 1 },
546 { WM_GETTEXT, sent|defwinproc|optional },
547 { WM_ACTIVATE, sent|wparam, 1 },
548 { HCBT_SETFOCUS, hook },
549 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
550 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
551 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
552 { WM_GETTEXT, sent|optional },
553 { WM_NCPAINT, sent|wparam|optional, 1 },
554 { WM_GETTEXT, sent|defwinproc|optional },
555 { WM_ERASEBKGND, sent },
556 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_STATECHANGED|SWP_FRAMECHANGED|SWP_NOCOPYBITS },
557 { WM_MOVE, sent|defwinproc },
558 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
559 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
560 { WM_NCPAINT, sent|wparam|optional, 1 },
561 { WM_ERASEBKGND, sent|optional },
562 { WM_ACTIVATE, sent|wparam, 1 },
563 { WM_GETTEXT, sent|optional },
564 { WM_PAINT, sent|optional },
565 { WM_GETTITLEBARINFOEX, sent|optional },
566 { WM_NCPAINT, sent|beginpaint|optional },
567 { WM_ERASEBKGND, sent|beginpaint|optional },
568 { 0 }
569 };
570 /* ShowWindow(SW_SHOWMINIMIZED) for a not visible overlapped window */
571 static const struct message WmShowMinOverlappedSeq[] = {
572 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
573 { HCBT_SETFOCUS, hook },
574 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
575 { WM_KILLFOCUS, sent },
576 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
577 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
578 { WM_GETTEXT, sent|optional },
579 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCOPYBITS|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
580 { WM_GETMINMAXINFO, sent|defwinproc },
581 { WM_NCCALCSIZE, sent|wparam, TRUE },
582 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
583 { WM_NCPAINT, sent|optional },
584 { WM_GETTEXT, sent|defwinproc|optional },
585 { WM_WINDOWPOSCHANGED, sent },
586 { WM_MOVE, sent|defwinproc },
587 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
588 { WM_NCCALCSIZE, sent|optional },
589 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
590 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
591 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
592 { WM_NCACTIVATE, sent|wparam, 0 },
593 { WM_GETTEXT, sent|defwinproc|optional },
594 { WM_ACTIVATE, sent },
595 { WM_ACTIVATEAPP, sent|wparam, 0 },
596
597 /* Vista sometimes restores the window right away... */
598 { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
599 { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
600 { HCBT_MINMAX, hook|optional|lparam, 0, SW_RESTORE },
601 { WM_QUERYOPEN, sent|optional },
602 { WM_WINDOWPOSCHANGING, sent|optional|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
603 { WM_GETMINMAXINFO, sent|optional|defwinproc },
604 { WM_NCCALCSIZE, sent|optional|wparam, TRUE },
605 { HCBT_ACTIVATE, hook|optional },
606 { WM_ACTIVATEAPP, sent|optional|wparam, 1 },
607 { WM_NCACTIVATE, sent|optional },
608 { WM_GETTEXT, sent|optional },
609 { WM_ACTIVATE, sent|optional|wparam, 1 },
610 { HCBT_SETFOCUS, hook|optional },
611 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
612 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
613 { WM_SETFOCUS, sent|optional },
614 { WM_NCPAINT, sent|optional },
615 { WM_GETTEXT, sent|defwinproc|optional },
616 { WM_ERASEBKGND, sent|optional },
617 { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
618 { WM_MOVE, sent|defwinproc|optional },
619 { WM_SIZE, sent|defwinproc|optional|wparam, SIZE_RESTORED },
620 { WM_ACTIVATE, sent|optional|wparam, 1 },
621 { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
622 { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
623
624 { WM_PAINT, sent|optional },
625 { WM_NCPAINT, sent|beginpaint|optional },
626 { WM_ERASEBKGND, sent|beginpaint|optional },
627 { 0 }
628 };
629 /* ShowWindow(SW_HIDE) for a visible overlapped window */
630 static const struct message WmHideOverlappedSeq[] = {
631 { WM_SHOWWINDOW, sent|wparam, 0 },
632 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
633 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
634 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
635 { WM_SIZE, sent|optional }, /* XP doesn't send it */
636 { WM_MOVE, sent|optional }, /* XP doesn't send it */
637 { WM_NCACTIVATE, sent|wparam|optional, 0 },
638 { WM_ACTIVATE, sent|wparam|optional, 0 },
639 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
640 { HCBT_SETFOCUS, hook|optional },
641 { WM_KILLFOCUS, sent|wparam, 0 },
642 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
643 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
644 { 0 }
645 };
646 /* DestroyWindow for a visible overlapped window */
647 static const struct message WmDestroyOverlappedSeq[] = {
648 { HCBT_DESTROYWND, hook },
649 { 0x0090, sent|optional },
650 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
651 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
652 { 0x0090, sent|optional },
653 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
654 { WM_NCACTIVATE, sent|optional|wparam, 0 },
655 { WM_ACTIVATE, sent|optional },
656 { WM_ACTIVATEAPP, sent|optional|wparam, 0 },
657 { WM_KILLFOCUS, sent|optional|wparam, 0 },
658 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
659 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
660 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
661 { WM_DESTROY, sent },
662 { WM_NCDESTROY, sent },
663 { 0 }
664 };
665 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
666 static const struct message WmCreateMaxPopupSeq[] = {
667 { HCBT_CREATEWND, hook },
668 { WM_NCCREATE, sent },
669 { WM_NCCALCSIZE, sent|wparam, 0 },
670 { WM_CREATE, sent },
671 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
672 { WM_SIZE, sent|wparam, SIZE_RESTORED },
673 { WM_MOVE, sent },
674 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
675 { WM_GETMINMAXINFO, sent },
676 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
677 { WM_NCCALCSIZE, sent|wparam, TRUE },
678 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
679 { WM_MOVE, sent|defwinproc },
680 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
681 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
682 { WM_SHOWWINDOW, sent|wparam, 1 },
683 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
684 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
685 { HCBT_ACTIVATE, hook },
686 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
687 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
688 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
689 { WM_NCPAINT, sent|wparam|optional, 1 },
690 { WM_ERASEBKGND, sent|optional },
691 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_NOMOVE|SWP_NOSIZE },
692 { WM_ACTIVATEAPP, sent|wparam, 1 },
693 { WM_NCACTIVATE, sent },
694 { WM_ACTIVATE, sent|wparam, 1 },
695 { HCBT_SETFOCUS, hook },
696 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
697 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
698 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
699 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
700 { WM_GETTEXT, sent|optional },
701 { WM_SYNCPAINT, sent|wparam|optional, 4 },
702 { WM_NCPAINT, sent|wparam|optional, 1 },
703 { WM_ERASEBKGND, sent|optional },
704 { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
705 { WM_ERASEBKGND, sent|defwinproc|optional },
706 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
707 { 0 }
708 };
709 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
710 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
711 { HCBT_CREATEWND, hook },
712 { WM_NCCREATE, sent },
713 { WM_NCCALCSIZE, sent|wparam, 0 },
714 { WM_CREATE, sent },
715 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
716 { WM_SIZE, sent|wparam, SIZE_RESTORED },
717 { WM_MOVE, sent },
718 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
719 { WM_GETMINMAXINFO, sent },
720 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
721 { WM_NCCALCSIZE, sent|wparam, TRUE },
722 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
723 { WM_MOVE, sent|defwinproc },
724 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
725 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
726 { 0 }
727 };
728 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
729 static const struct message WmShowMaxPopupResizedSeq[] = {
730 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
731 { WM_GETMINMAXINFO, sent },
732 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
733 { WM_NCCALCSIZE, sent|wparam, TRUE },
734 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
735 { HCBT_ACTIVATE, hook },
736 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
737 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
738 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
739 { WM_NCPAINT, sent|wparam|optional, 1 },
740 { WM_ERASEBKGND, sent|optional },
741 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
742 { WM_ACTIVATEAPP, sent|wparam, 1 },
743 { WM_NCACTIVATE, sent },
744 { WM_ACTIVATE, sent|wparam, 1 },
745 { HCBT_SETFOCUS, hook },
746 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
747 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
748 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
749 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
750 { WM_GETTEXT, sent|optional },
751 { WM_NCPAINT, sent|wparam|optional, 1 },
752 { WM_ERASEBKGND, sent|optional },
753 { WM_WINDOWPOSCHANGED, sent },
754 /* WinNT4.0 sends WM_MOVE */
755 { WM_MOVE, sent|defwinproc|optional },
756 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
757 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
758 { 0 }
759 };
760 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
761 static const struct message WmShowMaxPopupSeq[] = {
762 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
763 { WM_GETMINMAXINFO, sent },
764 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
765 { WM_NCCALCSIZE, sent|wparam, TRUE },
766 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
767 { HCBT_ACTIVATE, hook },
768 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
769 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
770 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
771 { WM_ACTIVATEAPP, sent|wparam, 1 },
772 { WM_NCACTIVATE, sent },
773 { WM_ACTIVATE, sent|wparam, 1 },
774 { HCBT_SETFOCUS, hook },
775 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
776 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
777 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
778 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
779 { WM_GETTEXT, sent|optional },
780 { WM_SYNCPAINT, sent|wparam|optional, 4 },
781 { WM_NCPAINT, sent|wparam|optional, 1 },
782 { WM_ERASEBKGND, sent|optional },
783 { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
784 { WM_ERASEBKGND, sent|defwinproc|optional },
785 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
786 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
787 { 0 }
788 };
789 /* CreateWindow(WS_VISIBLE) for popup window */
790 static const struct message WmCreatePopupSeq[] = {
791 { HCBT_CREATEWND, hook },
792 { WM_NCCREATE, sent },
793 { WM_NCCALCSIZE, sent|wparam, 0 },
794 { WM_CREATE, sent },
795 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
796 { WM_SIZE, sent|wparam, SIZE_RESTORED },
797 { WM_MOVE, sent },
798 { WM_SHOWWINDOW, sent|wparam, 1 },
799 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
800 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
801 { HCBT_ACTIVATE, hook },
802 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
803 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
804 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
805 { WM_NCPAINT, sent|wparam|optional, 1 },
806 { WM_ERASEBKGND, sent|optional },
807 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
808 { WM_ACTIVATEAPP, sent|wparam, 1 },
809 { WM_NCACTIVATE, sent },
810 { WM_ACTIVATE, sent|wparam, 1 },
811 { HCBT_SETFOCUS, hook },
812 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
813 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
814 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
815 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
816 { WM_GETTEXT, sent|optional },
817 { WM_SYNCPAINT, sent|wparam|optional, 4 },
818 { WM_NCPAINT, sent|wparam|optional, 1 },
819 { WM_ERASEBKGND, sent|optional },
820 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
821 { 0 }
822 };
823 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
824 static const struct message WmShowVisMaxPopupSeq[] = {
825 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
826 { WM_GETMINMAXINFO, sent },
827 { WM_GETTEXT, sent|optional },
828 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
829 { WM_GETTEXT, sent|optional },
830 { WM_NCCALCSIZE, sent|wparam, TRUE },
831 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
832 { WM_NCPAINT, sent|wparam|optional, 1 },
833 { WM_ERASEBKGND, sent|optional },
834 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
835 { WM_MOVE, sent|defwinproc },
836 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
837 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
838 { 0 }
839 };
840 /* CreateWindow (for a child popup window, not initially visible) */
841 static const struct message WmCreateChildPopupSeq[] = {
842 { HCBT_CREATEWND, hook },
843 { WM_NCCREATE, sent },
844 { WM_NCCALCSIZE, sent|wparam, 0 },
845 { WM_CREATE, sent },
846 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
847 { WM_SIZE, sent|wparam, SIZE_RESTORED },
848 { WM_MOVE, sent },
849 { 0 }
850 };
851 /* CreateWindow (for a popup window, not initially visible,
852 * which sets WS_VISIBLE in WM_CREATE handler)
853 */
854 static const struct message WmCreateInvisiblePopupSeq[] = {
855 { HCBT_CREATEWND, hook },
856 { WM_NCCREATE, sent },
857 { WM_NCCALCSIZE, sent|wparam, 0 },
858 { WM_CREATE, sent },
859 { WM_STYLECHANGING, sent },
860 { WM_STYLECHANGED, sent },
861 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
862 { WM_SIZE, sent|wparam, SIZE_RESTORED },
863 { WM_MOVE, sent },
864 { 0 }
865 };
866 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
867 * for a popup window with WS_VISIBLE style set
868 */
869 static const struct message WmShowVisiblePopupSeq_2[] = {
870 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
871 { 0 }
872 };
873 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
874 * for a popup window with WS_VISIBLE style set
875 */
876 static const struct message WmShowVisiblePopupSeq_3[] = {
877 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
878 { HCBT_ACTIVATE, hook },
879 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
880 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
881 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
882 { WM_NCACTIVATE, sent },
883 { WM_ACTIVATE, sent|wparam, 1 },
884 { HCBT_SETFOCUS, hook },
885 { WM_KILLFOCUS, sent|parent },
886 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
887 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
888 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
889 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
890 { WM_SETFOCUS, sent|defwinproc },
891 { WM_GETTEXT, sent|optional },
892 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_SHOWWINDOW },
893 { 0 }
894 };
895 /* CreateWindow (for child window, not initially visible) */
896 static const struct message WmCreateChildSeq[] = {
897 { HCBT_CREATEWND, hook },
898 { WM_NCCREATE, sent },
899 /* child is inserted into parent's child list after WM_NCCREATE returns */
900 { WM_NCCALCSIZE, sent|wparam, 0 },
901 { WM_CREATE, sent },
902 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
903 { WM_SIZE, sent|wparam, SIZE_RESTORED },
904 { WM_MOVE, sent },
905 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
906 { 0 }
907 };
908 /* CreateWindow (for maximized child window, not initially visible) */
909 static const struct message WmCreateMaximizedChildSeq[] = {
910 { HCBT_CREATEWND, hook },
911 { WM_NCCREATE, sent },
912 { WM_NCCALCSIZE, sent|wparam, 0 },
913 { WM_CREATE, sent },
914 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
915 { WM_SIZE, sent|wparam, SIZE_RESTORED },
916 { WM_MOVE, sent },
917 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
918 { WM_GETMINMAXINFO, sent },
919 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
920 { WM_NCCALCSIZE, sent|wparam, 1 },
921 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
922 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
923 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
924 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
925 { 0 }
926 };
927 /* CreateWindow (for a child window, initially visible) */
928 static const struct message WmCreateVisibleChildSeq[] = {
929 { HCBT_CREATEWND, hook },
930 { WM_NCCREATE, sent },
931 /* child is inserted into parent's child list after WM_NCCREATE returns */
932 { WM_NCCALCSIZE, sent|wparam, 0 },
933 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
934 { WM_CREATE, sent },
935 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
936 { WM_SIZE, sent|wparam, SIZE_RESTORED },
937 { WM_MOVE, sent },
938 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
939 { WM_SHOWWINDOW, sent|wparam, 1 },
940 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
941 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
942 { WM_ERASEBKGND, sent|parent|optional },
943 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
944 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
945 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
946 { 0 }
947 };
948 /* ShowWindow(SW_SHOW) for a not visible child window */
949 static const struct message WmShowChildSeq[] = {
950 { WM_SHOWWINDOW, sent|wparam, 1 },
951 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
952 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
953 { WM_ERASEBKGND, sent|parent|optional },
954 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
955 { 0 }
956 };
957 /* ShowWindow(SW_HIDE) for a visible child window */
958 static const struct message WmHideChildSeq[] = {
959 { WM_SHOWWINDOW, sent|wparam, 0 },
960 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
961 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
962 { WM_ERASEBKGND, sent|parent|optional },
963 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
964 { 0 }
965 };
966 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
967 static const struct message WmHideChildSeq2[] = {
968 { WM_SHOWWINDOW, sent|wparam, 0 },
969 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
970 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
971 { WM_ERASEBKGND, sent|parent|optional },
972 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
973 { 0 }
974 };
975 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
976 * for a not visible child window
977 */
978 static const struct message WmShowChildSeq_2[] = {
979 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
980 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
981 { WM_CHILDACTIVATE, sent },
982 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
983 { 0 }
984 };
985 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
986 * for a not visible child window
987 */
988 static const struct message WmShowChildSeq_3[] = {
989 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
990 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
991 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
992 { 0 }
993 };
994 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
995 * for a visible child window with a caption
996 */
997 static const struct message WmShowChildSeq_4[] = {
998 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
999 { WM_CHILDACTIVATE, sent },
1000 { 0 }
1001 };
1002 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
1003 static const struct message WmShowChildInvisibleParentSeq_1[] = {
1004 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
1005 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
1006 { WM_NCCALCSIZE, sent|wparam, 1 },
1007 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1008 { WM_CHILDACTIVATE, sent|optional },
1009 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
1010 { WM_MOVE, sent|defwinproc },
1011 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1012 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1013 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1014 /* FIXME: Wine creates an icon/title window while Windows doesn't */
1015 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1016 { WM_GETTEXT, sent|optional },
1017 { 0 }
1018 };
1019 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
1020 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
1021 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
1022 { 0 }
1023 };
1024 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1025 static const struct message WmShowChildInvisibleParentSeq_2[] = {
1026 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1027 { WM_GETMINMAXINFO, sent },
1028 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
1029 { WM_NCCALCSIZE, sent|wparam, 1 },
1030 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1031 { WM_CHILDACTIVATE, sent },
1032 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
1033 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
1034 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1035 { 0 }
1036 };
1037 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1038 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
1039 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1040 { 0 }
1041 };
1042 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1043 static const struct message WmShowChildInvisibleParentSeq_3[] = {
1044 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1045 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
1046 { WM_NCCALCSIZE, sent|wparam, 1 },
1047 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1048 { WM_CHILDACTIVATE, sent },
1049 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1050 { WM_MOVE, sent|defwinproc },
1051 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1052 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1053 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1054 /* FIXME: Wine creates an icon/title window while Windows doesn't */
1055 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1056 { WM_GETTEXT, sent|optional },
1057 { 0 }
1058 };
1059 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1060 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
1061 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1062 { 0 }
1063 };
1064 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1065 static const struct message WmShowChildInvisibleParentSeq_4[] = {
1066 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1067 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
1068 { WM_NCCALCSIZE, sent|wparam, 1 },
1069 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1070 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1071 { WM_MOVE, sent|defwinproc },
1072 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1073 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1074 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1075 /* FIXME: Wine creates an icon/title window while Windows doesn't */
1076 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1077 { WM_GETTEXT, sent|optional },
1078 { 0 }
1079 };
1080 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1081 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
1082 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1083 { 0 }
1084 };
1085 /* ShowWindow(SW_SHOW) for child with invisible parent */
1086 static const struct message WmShowChildInvisibleParentSeq_5[] = {
1087 { WM_SHOWWINDOW, sent|wparam, 1 },
1088 { 0 }
1089 };
1090 /* ShowWindow(SW_HIDE) for child with invisible parent */
1091 static const struct message WmHideChildInvisibleParentSeq[] = {
1092 { WM_SHOWWINDOW, sent|wparam, 0 },
1093 { 0 }
1094 };
1095 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
1096 static const struct message WmShowChildInvisibleParentSeq_6[] = {
1097 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1098 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1099 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1100 { 0 }
1101 };
1102 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
1103 static const struct message WmHideChildInvisibleParentSeq_2[] = {
1104 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1105 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1106 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1107 { 0 }
1108 };
1109 /* DestroyWindow for a visible child window */
1110 static const struct message WmDestroyChildSeq[] = {
1111 { HCBT_DESTROYWND, hook },
1112 { 0x0090, sent|optional },
1113 { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1114 { WM_SHOWWINDOW, sent|wparam, 0 },
1115 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1116 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1117 { WM_ERASEBKGND, sent|parent|optional },
1118 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1119 { HCBT_SETFOCUS, hook }, /* set focus to a parent */
1120 { WM_KILLFOCUS, sent },
1121 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1122 { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
1123 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1124 { WM_SETFOCUS, sent|parent },
1125 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1126 { WM_DESTROY, sent },
1127 { WM_DESTROY, sent|optional }, /* some other (IME?) window */
1128 { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
1129 { WM_NCDESTROY, sent },
1130 { 0 }
1131 };
1132 /* visible child window destroyed by thread exit */
1133 static const struct message WmExitThreadSeq[] = {
1134 { WM_NCDESTROY, sent }, /* actually in grandchild */
1135 { WM_PAINT, sent|parent },
1136 { WM_ERASEBKGND, sent|parent|beginpaint },
1137 { 0 }
1138 };
1139 /* DestroyWindow for a visible child window with invisible parent */
1140 static const struct message WmDestroyInvisibleChildSeq[] = {
1141 { HCBT_DESTROYWND, hook },
1142 { 0x0090, sent|optional },
1143 { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1144 { WM_SHOWWINDOW, sent|wparam, 0 },
1145 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1146 { WM_DESTROY, sent },
1147 { WM_NCDESTROY, sent },
1148 { 0 }
1149 };
1150 /* Moving the mouse in nonclient area */
1151 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
1152 { WM_NCHITTEST, sent },
1153 { WM_SETCURSOR, sent },
1154 { WM_NCMOUSEMOVE, posted },
1155 { 0 }
1156 };
1157 /* Moving the mouse in client area */
1158 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
1159 { WM_NCHITTEST, sent },
1160 { WM_SETCURSOR, sent },
1161 { WM_MOUSEMOVE, posted },
1162 { 0 }
1163 };
1164 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1165 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
1166 { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
1167 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
1168 { WM_GETMINMAXINFO, sent|defwinproc },
1169 { WM_ENTERSIZEMOVE, sent|defwinproc },
1170 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1171 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1172 { WM_MOVE, sent|defwinproc },
1173 { WM_EXITSIZEMOVE, sent|defwinproc },
1174 { 0 }
1175 };
1176 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1177 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
1178 { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
1179 { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
1180 { WM_GETMINMAXINFO, sent|defwinproc },
1181 { WM_ENTERSIZEMOVE, sent|defwinproc },
1182 { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
1183 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1184 { WM_GETMINMAXINFO, sent|defwinproc },
1185 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1186 { WM_NCPAINT, sent|defwinproc|wparam, 1 },
1187 { WM_GETTEXT, sent|defwinproc },
1188 { WM_ERASEBKGND, sent|defwinproc },
1189 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1190 { WM_MOVE, sent|defwinproc },
1191 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1192 { WM_EXITSIZEMOVE, sent|defwinproc },
1193 { 0 }
1194 };
1195 /* Resizing child window with MoveWindow (32) */
1196 static const struct message WmResizingChildWithMoveWindowSeq[] = {
1197 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1198 { WM_NCCALCSIZE, sent|wparam, 1 },
1199 { WM_ERASEBKGND, sent|parent|optional },
1200 { WM_ERASEBKGND, sent|optional },
1201 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
1202 { WM_MOVE, sent|defwinproc },
1203 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1204 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1205 { 0 }
1206 };
1207 /* Clicking on inactive button */
1208 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
1209 { WM_NCHITTEST, sent },
1210 { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
1211 { WM_MOUSEACTIVATE, sent },
1212 { WM_MOUSEACTIVATE, sent|parent|defwinproc },
1213 { WM_SETCURSOR, sent },
1214 { WM_SETCURSOR, sent|parent|defwinproc },
1215 { WM_LBUTTONDOWN, posted },
1216 { WM_KILLFOCUS, posted|parent },
1217 { WM_SETFOCUS, posted },
1218 { WM_CTLCOLORBTN, posted|parent },
1219 { BM_SETSTATE, posted },
1220 { WM_CTLCOLORBTN, posted|parent },
1221 { WM_LBUTTONUP, posted },
1222 { BM_SETSTATE, posted },
1223 { WM_CTLCOLORBTN, posted|parent },
1224 { WM_COMMAND, posted|parent },
1225 { 0 }
1226 };
1227 /* Reparenting a button (16/32) */
1228 /* The last child (button) reparented gets topmost for its new parent. */
1229 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
1230 { WM_SHOWWINDOW, sent|wparam, 0 },
1231 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1232 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1233 { WM_ERASEBKGND, sent|parent },
1234 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1235 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
1236 { WM_CHILDACTIVATE, sent },
1237 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
1238 { WM_MOVE, sent|defwinproc },
1239 { WM_SHOWWINDOW, sent|wparam, 1 },
1240 { 0 }
1241 };
1242 /* Creation of a custom dialog (32) */
1243 static const struct message WmCreateCustomDialogSeq[] = {
1244 { HCBT_CREATEWND, hook },
1245 { WM_GETMINMAXINFO, sent },
1246 { WM_NCCREATE, sent },
1247 { WM_NCCALCSIZE, sent|wparam, 0 },
1248 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1249 { WM_CREATE, sent },
1250 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1251 { WM_NOTIFYFORMAT, sent|optional },
1252 { WM_QUERYUISTATE, sent|optional },
1253 { WM_WINDOWPOSCHANGING, sent|optional },
1254 { WM_GETMINMAXINFO, sent|optional },
1255 { WM_NCCALCSIZE, sent|optional },
1256 { WM_WINDOWPOSCHANGED, sent|optional },
1257 { WM_SHOWWINDOW, sent|wparam, 1 },
1258 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1259 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1260 { HCBT_ACTIVATE, hook },
1261 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1262
1263
1264 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1265
1266 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1267
1268 { WM_NCACTIVATE, sent },
1269 { WM_GETTEXT, sent|optional|defwinproc },
1270 { WM_GETTEXT, sent|optional|defwinproc },
1271 { WM_GETTEXT, sent|optional|defwinproc },
1272 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1273 { WM_ACTIVATE, sent|wparam, 1 },
1274 { WM_GETTEXT, sent|optional },
1275 { WM_KILLFOCUS, sent|parent },
1276 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1277 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1278 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1279 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1280 { WM_SETFOCUS, sent },
1281 { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1282 { WM_NCPAINT, sent|wparam, 1 },
1283 { WM_GETTEXT, sent|optional|defwinproc },
1284 { WM_GETTEXT, sent|optional|defwinproc },
1285 { WM_ERASEBKGND, sent },
1286 { WM_CTLCOLORDLG, sent|optional|defwinproc },
1287 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1288 { WM_GETTEXT, sent|optional },
1289 { WM_GETTEXT, sent|optional },
1290 { WM_NCCALCSIZE, sent|optional },
1291 { WM_NCPAINT, sent|optional },
1292 { WM_GETTEXT, sent|optional|defwinproc },
1293 { WM_GETTEXT, sent|optional|defwinproc },
1294 { WM_ERASEBKGND, sent|optional },
1295 { WM_CTLCOLORDLG, sent|optional|defwinproc },
1296 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1297 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1298 { WM_MOVE, sent },
1299 { 0 }
1300 };
1301 /* Calling EndDialog for a custom dialog (32) */
1302 static const struct message WmEndCustomDialogSeq[] = {
1303 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1304 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1305 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1306 { WM_GETTEXT, sent|optional },
1307 { HCBT_ACTIVATE, hook },
1308 { WM_NCACTIVATE, sent|wparam, 0 },
1309 { WM_GETTEXT, sent|optional|defwinproc },
1310 { WM_GETTEXT, sent|optional|defwinproc },
1311 { WM_ACTIVATE, sent|wparam, 0 },
1312 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1313 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1314 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1315 { WM_GETTEXT, sent|optional|defwinproc },
1316 { WM_GETTEXT, sent|optional|defwinproc },
1317 { HCBT_SETFOCUS, hook },
1318 { WM_KILLFOCUS, sent },
1319 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1320 { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1321 { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1322 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1323 { WM_SETFOCUS, sent|parent|defwinproc },
1324 { 0 }
1325 };
1326 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1327 static const struct message WmShowCustomDialogSeq[] = {
1328 { WM_SHOWWINDOW, sent|wparam, 1 },
1329 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1330 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1331 { HCBT_ACTIVATE, hook },
1332 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1333
1334 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1335
1336 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1337 { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1338 { WM_NCACTIVATE, sent },
1339 { WM_ACTIVATE, sent|wparam, 1 },
1340 { WM_GETTEXT, sent|optional },
1341
1342 { WM_KILLFOCUS, sent|parent },
1343 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1344 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1345 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1346 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1347 { WM_SETFOCUS, sent },
1348 { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1349 { WM_NCPAINT, sent|wparam, 1 },
1350 { WM_ERASEBKGND, sent },
1351 { WM_CTLCOLORDLG, sent|defwinproc },
1352 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1353 { 0 }
1354 };
1355 /* Creation and destruction of a modal dialog (32) */
1356 static const struct message WmModalDialogSeq[] = {
1357 { WM_CANCELMODE, sent|parent },
1358 { HCBT_SETFOCUS, hook },
1359 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1360 { WM_KILLFOCUS, sent|parent },
1361 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1362 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1363 { WM_ENABLE, sent|parent|wparam, 0 },
1364 { HCBT_CREATEWND, hook },
1365 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1366 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1367 { WM_SETFONT, sent },
1368 { WM_INITDIALOG, sent },
1369 { WM_CHANGEUISTATE, sent|optional },
1370 { WM_UPDATEUISTATE, sent|optional },
1371 { WM_SHOWWINDOW, sent },
1372 { HCBT_ACTIVATE, hook },
1373 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1374 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1375 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1376 { WM_NCACTIVATE, sent },
1377 { WM_GETTEXT, sent|optional },
1378 { WM_ACTIVATE, sent|wparam, 1 },
1379 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1380 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1381 { WM_NCPAINT, sent|optional },
1382 { WM_GETTEXT, sent|optional },
1383 { WM_ERASEBKGND, sent|optional },
1384 { WM_CTLCOLORDLG, sent|optional },
1385 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1386 { WM_GETTEXT, sent|optional },
1387 { WM_NCCALCSIZE, sent|optional },
1388 { WM_NCPAINT, sent|optional },
1389 { WM_GETTEXT, sent|optional },
1390 { WM_ERASEBKGND, sent|optional },
1391 { WM_CTLCOLORDLG, sent|optional },
1392 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1393 { WM_PAINT, sent|optional },
1394 { WM_CTLCOLORBTN, sent|optional },
1395 { WM_GETTITLEBARINFOEX, sent|optional },
1396 { WM_ENTERIDLE, sent|parent|optional },
1397 { WM_ENTERIDLE, sent|parent|optional },
1398 { WM_ENTERIDLE, sent|parent|optional },
1399 { WM_ENTERIDLE, sent|parent|optional },
1400 { WM_ENTERIDLE, sent|parent|optional },
1401 { WM_ENTERIDLE, sent|parent|optional },
1402 { WM_ENTERIDLE, sent|parent|optional },
1403 { WM_ENTERIDLE, sent|parent|optional },
1404 { WM_ENTERIDLE, sent|parent|optional },
1405 { WM_ENTERIDLE, sent|parent|optional },
1406 { WM_ENTERIDLE, sent|parent|optional },
1407 { WM_ENTERIDLE, sent|parent|optional },
1408 { WM_ENTERIDLE, sent|parent|optional },
1409 { WM_ENTERIDLE, sent|parent|optional },
1410 { WM_ENTERIDLE, sent|parent|optional },
1411 { WM_ENTERIDLE, sent|parent|optional },
1412 { WM_ENTERIDLE, sent|parent|optional },
1413 { WM_ENTERIDLE, sent|parent|optional },
1414 { WM_ENTERIDLE, sent|parent|optional },
1415 { WM_ENTERIDLE, sent|parent|optional },
1416 { WM_TIMER, sent },
1417 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1418 { WM_ENABLE, sent|parent|wparam, 1 },
1419 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1420 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1421 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1422 { WM_GETTEXT, sent|optional },
1423 { HCBT_ACTIVATE, hook },
1424 { WM_NCACTIVATE, sent|wparam, 0 },
1425 { WM_GETTEXT, sent|optional },
1426 { WM_ACTIVATE, sent|wparam, 0 },
1427 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1428 { WM_WINDOWPOSCHANGING, sent|optional },
1429 { WM_WINDOWPOSCHANGED, sent|optional },
1430 { HCBT_SETFOCUS, hook },
1431 { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1432 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1433 { WM_SETFOCUS, sent|parent|defwinproc },
1434 { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1435 { HCBT_DESTROYWND, hook },
1436 { 0x0090, sent|optional },
1437 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1438 { WM_DESTROY, sent },
1439 { WM_NCDESTROY, sent },
1440 { 0 }
1441 };
1442 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1443 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1444 /* (inside dialog proc, handling WM_INITDIALOG) */
1445 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1446 { WM_NCCALCSIZE, sent },
1447 { WM_NCACTIVATE, sent|parent|wparam, 0 },
1448 { WM_GETTEXT, sent|defwinproc },
1449 { WM_ACTIVATE, sent|parent|wparam, 0 },
1450 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1451 { WM_WINDOWPOSCHANGING, sent|parent },
1452 { WM_NCACTIVATE, sent|wparam, 1 },
1453 { WM_ACTIVATE, sent|wparam, 1 },
1454 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1455 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1456 /* (setting focus) */
1457 { WM_SHOWWINDOW, sent|wparam, 1 },
1458 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1459 { WM_NCPAINT, sent },
1460 { WM_GETTEXT, sent|defwinproc },
1461 { WM_ERASEBKGND, sent },
1462 { WM_CTLCOLORDLG, sent|defwinproc },
1463 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1464 { WM_PAINT, sent },
1465 /* (bunch of WM_CTLCOLOR* for each control) */
1466 { WM_PAINT, sent|parent },
1467 { WM_ENTERIDLE, sent|parent|wparam, 0 },
1468 { WM_SETCURSOR, sent|parent },
1469 { 0 }
1470 };
1471 /* SetMenu for NonVisible windows with size change*/
1472 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1473 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1474 { WM_NCCALCSIZE, sent|wparam, 1 },
1475 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1476 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1477 { WM_MOVE, sent|defwinproc },
1478 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1479 { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1480 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1481 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1482 { WM_GETTEXT, sent|optional },
1483 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1484 { 0 }
1485 };
1486 /* SetMenu for NonVisible windows with no size change */
1487 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1488 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1489 { WM_NCCALCSIZE, sent|wparam, 1 },
1490 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1491 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1492 { 0 }
1493 };
1494 /* SetMenu for Visible windows with size change */
1495 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1496 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1497 { WM_NCCALCSIZE, sent|wparam, 1 },
1498 { 0x0093, sent|defwinproc|optional },
1499 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1500 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1501 { 0x0093, sent|defwinproc|optional },
1502 { 0x0093, sent|defwinproc|optional },
1503 { 0x0091, sent|defwinproc|optional },
1504 { 0x0092, sent|defwinproc|optional },
1505 { WM_GETTEXT, sent|defwinproc|optional },
1506 { WM_ERASEBKGND, sent|optional },
1507 { WM_ACTIVATE, sent|optional },
1508 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1509 { WM_MOVE, sent|defwinproc },
1510 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1511 { 0x0093, sent|optional },
1512 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1513 { 0x0093, sent|defwinproc|optional },
1514 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1515 { 0x0093, sent|defwinproc|optional },
1516 { 0x0093, sent|defwinproc|optional },
1517 { 0x0091, sent|defwinproc|optional },
1518 { 0x0092, sent|defwinproc|optional },
1519 { WM_ERASEBKGND, sent|optional },
1520 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1521 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1522 { 0 }
1523 };
1524 /* SetMenu for Visible windows with no size change */
1525 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1526 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1527 { WM_NCCALCSIZE, sent|wparam, 1 },
1528 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1529 { WM_GETTEXT, sent|defwinproc|optional },
1530 { WM_ERASEBKGND, sent|optional },
1531 { WM_ACTIVATE, sent|optional },
1532 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1533 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1534 { 0 }
1535 };
1536 /* DrawMenuBar for a visible window */
1537 static const struct message WmDrawMenuBarSeq[] =
1538 {
1539 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1540 { WM_NCCALCSIZE, sent|wparam, 1 },
1541 { 0x0093, sent|defwinproc|optional },
1542 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1543 { 0x0093, sent|defwinproc|optional },
1544 { 0x0093, sent|defwinproc|optional },
1545 { 0x0091, sent|defwinproc|optional },
1546 { 0x0092, sent|defwinproc|optional },
1547 { WM_GETTEXT, sent|defwinproc|optional },
1548 { WM_ERASEBKGND, sent|optional },
1549 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1550 { 0x0093, sent|optional },
1551 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1552 { 0 }
1553 };
1554
1555 static const struct message WmSetRedrawFalseSeq[] =
1556 {
1557 { WM_SETREDRAW, sent|wparam, 0 },
1558 { 0 }
1559 };
1560
1561 static const struct message WmSetRedrawTrueSeq[] =
1562 {
1563 { WM_SETREDRAW, sent|wparam, 1 },
1564 { 0 }
1565 };
1566
1567 static const struct message WmEnableWindowSeq_1[] =
1568 {
1569 { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1570 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1571 { HCBT_SETFOCUS, hook|optional },
1572 { WM_KILLFOCUS, sent|optional },
1573 { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1574 { 0 }
1575 };
1576
1577 static const struct message WmEnableWindowSeq_2[] =
1578 {
1579 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1580 { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1581 { 0 }
1582 };
1583
1584 static const struct message WmGetScrollRangeSeq[] =
1585 {
1586 { SBM_GETRANGE, sent },
1587 { 0 }
1588 };
1589 static const struct message WmGetScrollInfoSeq[] =
1590 {
1591 { SBM_GETSCROLLINFO, sent },
1592 { 0 }
1593 };
1594 static const struct message WmSetScrollRangeSeq[] =
1595 {
1596 /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1597 sends SBM_SETSCROLLINFO.
1598 */
1599 { SBM_SETSCROLLINFO, sent },
1600 { 0 }
1601 };
1602 /* SetScrollRange for a window without a non-client area */
1603 static const struct message WmSetScrollRangeHSeq_empty[] =
1604 {
1605 { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1606 { 0 }
1607 };
1608 static const struct message WmSetScrollRangeVSeq_empty[] =
1609 {
1610 { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1611 { 0 }
1612 };
1613 static const struct message WmSetScrollRangeHVSeq[] =
1614 {
1615 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1616 { WM_NCCALCSIZE, sent|wparam, 1 },
1617 { WM_GETTEXT, sent|defwinproc|optional },
1618 { WM_ERASEBKGND, sent|optional },
1619 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1620 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1621 { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1622 { 0 }
1623 };
1624 /* SetScrollRange for a window with a non-client area */
1625 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1626 {
1627 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1628 { WM_NCCALCSIZE, sent|wparam, 1 },
1629 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1630 { WM_NCPAINT, sent|optional },
1631 { WM_STYLECHANGING, sent|defwinproc|optional },
1632 { WM_STYLECHANGED, sent|defwinproc|optional },
1633 { WM_STYLECHANGING, sent|defwinproc|optional },
1634 { WM_STYLECHANGED, sent|defwinproc|optional },
1635 { WM_STYLECHANGING, sent|defwinproc|optional },
1636 { WM_STYLECHANGED, sent|defwinproc|optional },
1637 { WM_STYLECHANGING, sent|defwinproc|optional },
1638 { WM_STYLECHANGED, sent|defwinproc|optional },
1639 { WM_GETTEXT, sent|defwinproc|optional },
1640 { WM_GETTEXT, sent|defwinproc|optional },
1641 { WM_ERASEBKGND, sent|optional },
1642 { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1643 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOCLIENTSIZE },
1644 { WM_SIZE, sent|defwinproc|optional },
1645 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1646 { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1647 { WM_GETTEXT, sent|optional },
1648 { WM_GETTEXT, sent|optional },
1649 { WM_GETTEXT, sent|optional },
1650 { WM_GETTEXT, sent|optional },
1651 { 0 }
1652 };
1653 /* test if we receive the right sequence of messages */
1654 /* after calling ShowWindow( SW_SHOWNA) */
1655 static const struct message WmSHOWNAChildInvisParInvis[] = {
1656 { WM_SHOWWINDOW, sent|wparam, 1 },
1657 { 0 }
1658 };
1659 static const struct message WmSHOWNAChildVisParInvis[] = {
1660 { WM_SHOWWINDOW, sent|wparam, 1 },
1661 { 0 }
1662 };
1663 static const struct message WmSHOWNAChildVisParVis[] = {
1664 { WM_SHOWWINDOW, sent|wparam, 1 },
1665 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1666 { 0 }
1667 };
1668 static const struct message WmSHOWNAChildInvisParVis[] = {
1669 { WM_SHOWWINDOW, sent|wparam, 1 },
1670 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1671 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1672 { WM_ERASEBKGND, sent|optional },
1673 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1674 { 0 }
1675 };
1676 static const struct message WmSHOWNATopVisible[] = {
1677 { WM_SHOWWINDOW, sent|wparam, 1 },
1678 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1679 { WM_NCPAINT, sent|wparam|optional, 1 },
1680 { WM_GETTEXT, sent|defwinproc|optional },
1681 { WM_ERASEBKGND, sent|optional },
1682 { WM_WINDOWPOSCHANGED, sent|optional },
1683 { 0 }
1684 };
1685 static const struct message WmSHOWNATopInvisible[] = {
1686 { WM_NOTIFYFORMAT, sent|optional },
1687 { WM_QUERYUISTATE, sent|optional },
1688 { WM_WINDOWPOSCHANGING, sent|optional },
1689 { WM_GETMINMAXINFO, sent|optional },
1690 { WM_NCCALCSIZE, sent|optional },
1691 { WM_WINDOWPOSCHANGED, sent|optional },
1692 { WM_SHOWWINDOW, sent|wparam, 1 },
1693 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1694 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1695 { WM_NCPAINT, sent|wparam|optional, 1 },
1696 { WM_GETTEXT, sent|defwinproc|optional },
1697 { WM_ERASEBKGND, sent|optional },
1698 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1699 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1700 { WM_NCPAINT, sent|wparam|optional, 1 },
1701 { WM_ERASEBKGND, sent|optional },
1702 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1703 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1704 { WM_MOVE, sent },
1705 { 0 }
1706 };
1707
1708 static int after_end_dialog, test_def_id;
1709 static int sequence_cnt, sequence_size;
1710 static struct recvd_message* sequence;
1711 static int log_all_parent_messages;
1712 static int paint_loop_done;
1713
1714 /* user32 functions */
1715 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1716 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
1717 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1718 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
1719 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1720 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1721 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1722 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
1723 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
1724 static BOOL (WINAPI *pUpdateLayeredWindow)(HWND,HDC,POINT*,SIZE*,HDC,POINT*,COLORREF,BLENDFUNCTION*,DWORD);
1725 static UINT_PTR (WINAPI *pSetSystemTimer)(HWND, UINT_PTR, UINT, TIMERPROC);
1726 static UINT_PTR (WINAPI *pKillSystemTimer)(HWND, UINT_PTR);
1727 /* kernel32 functions */
1728 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1729
1730 static void init_procs(void)
1731 {
1732 HMODULE user32 = GetModuleHandleA("user32.dll");
1733 HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1734
1735 #define GET_PROC(dll, func) \
1736 p ## func = (void*)GetProcAddress(dll, #func); \
1737 if(!p ## func) { \
1738 trace("GetProcAddress(%s) failed\n", #func); \
1739 }
1740
1741 GET_PROC(user32, GetAncestor)
1742 GET_PROC(user32, GetMenuInfo)
1743 GET_PROC(user32, NotifyWinEvent)
1744 GET_PROC(user32, SetMenuInfo)
1745 GET_PROC(user32, SetWinEventHook)
1746 GET_PROC(user32, TrackMouseEvent)
1747 GET_PROC(user32, UnhookWinEvent)
1748 GET_PROC(user32, GetMonitorInfoA)
1749 GET_PROC(user32, MonitorFromPoint)
1750 GET_PROC(user32, UpdateLayeredWindow)
1751 GET_PROC(user32, SetSystemTimer)
1752 GET_PROC(user32, KillSystemTimer)
1753
1754 GET_PROC(kernel32, GetCPInfoExA)
1755
1756 #undef GET_PROC
1757 }
1758
1759 static const char *get_winpos_flags(UINT flags)
1760 {
1761 static char buffer[300];
1762
1763 buffer[0] = 0;
1764 #define DUMP(flag) do { if (flags & flag) { strcat( buffer, "|" #flag ); flags &= ~flag; } } while(0)
1765 DUMP( SWP_SHOWWINDOW );
1766 DUMP( SWP_HIDEWINDOW );
1767 DUMP( SWP_NOACTIVATE );
1768 DUMP( SWP_FRAMECHANGED );
1769 DUMP( SWP_NOCOPYBITS );
1770 DUMP( SWP_NOOWNERZORDER );
1771 DUMP( SWP_NOSENDCHANGING );
1772 DUMP( SWP_DEFERERASE );
1773 DUMP( SWP_ASYNCWINDOWPOS );
1774 DUMP( SWP_NOZORDER );
1775 DUMP( SWP_NOREDRAW );
1776 DUMP( SWP_NOSIZE );
1777 DUMP( SWP_NOMOVE );
1778 DUMP( SWP_NOCLIENTSIZE );
1779 DUMP( SWP_NOCLIENTMOVE );
1780 if (flags) sprintf(buffer + strlen(buffer),"|0x%04x", flags);
1781 return buffer + 1;
1782 #undef DUMP
1783 }
1784
1785 static BOOL ignore_message( UINT message )
1786 {
1787 /* these are always ignored */
1788 return (message >= 0xc000 ||
1789 message == WM_GETICON ||
1790 message == WM_GETOBJECT ||
1791 message == WM_TIMECHANGE ||
1792 message == WM_DISPLAYCHANGE ||
1793 message == WM_DEVICECHANGE ||
1794 message == WM_DWMNCRENDERINGCHANGED);
1795 }
1796
1797
1798 #define add_message(msg) add_message_(__LINE__,msg);
1799 static void add_message_(int line, const struct recvd_message *msg)
1800 {
1801 struct recvd_message *seq;
1802
1803 if (!sequence)
1804 {
1805 sequence_size = 10;
1806 sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof(*sequence) );
1807 }
1808 if (sequence_cnt == sequence_size)
1809 {
1810 sequence_size *= 2;
1811 sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof(*sequence) );
1812 }
1813 assert(sequence);
1814
1815 seq = &sequence[sequence_cnt];
1816 seq->hwnd = msg->hwnd;
1817 seq->message = msg->message;
1818 seq->flags = msg->flags;
1819 seq->wParam = msg->wParam;
1820 seq->lParam = msg->lParam;
1821 seq->line = line;
1822 seq->descr = msg->descr;
1823 seq->output[0] = 0;
1824
1825 if (msg->descr)
1826 {
1827 if (msg->flags & hook)
1828 {
1829 static const char * const CBT_code_name[10] =
1830 {
1831 "HCBT_MOVESIZE",
1832 "HCBT_MINMAX",
1833 "HCBT_QS",
1834 "HCBT_CREATEWND",
1835 "HCBT_DESTROYWND",
1836 "HCBT_ACTIVATE",
1837 "HCBT_CLICKSKIPPED",
1838 "HCBT_KEYSKIPPED",
1839 "HCBT_SYSCOMMAND",
1840 "HCBT_SETFOCUS"
1841 };
1842 const char *code_name = (msg->message <= HCBT_SETFOCUS) ? CBT_code_name[msg->message] : "Unknown";
1843
1844 sprintf( seq->output, "%s: hook %d (%s) wp %08lx lp %08lx",
1845 msg->descr, msg->message, code_name, msg->wParam, msg->lParam );
1846 }
1847 else if (msg->flags & winevent_hook)
1848 {
1849 sprintf( seq->output, "%s: winevent %p %08x %08lx %08lx",
1850 msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1851 }
1852 else
1853 {
1854 switch (msg->message)
1855 {
1856 case WM_WINDOWPOSCHANGING:
1857 case WM_WINDOWPOSCHANGED:
1858 {
1859 WINDOWPOS *winpos = (WINDOWPOS *)msg->lParam;
1860
1861 sprintf( seq->output, "%s: %p WM_WINDOWPOS%s wp %08lx lp %08lx after %p x %d y %d cx %d cy %d flags %s",
1862 msg->descr, msg->hwnd,
1863 (msg->message == WM_WINDOWPOSCHANGING) ? "CHANGING" : "CHANGED",
1864 msg->wParam, msg->lParam, winpos->hwndInsertAfter,
1865 winpos->x, winpos->y, winpos->cx, winpos->cy,
1866 get_winpos_flags(winpos->flags) );
1867
1868 /* Log only documented flags, win2k uses 0x1000 and 0x2000
1869 * in the high word for internal purposes
1870 */
1871 seq->wParam = winpos->flags & 0xffff;
1872 /* We are not interested in the flags that don't match under XP and Win9x */
1873 seq->wParam &= ~SWP_NOZORDER;
1874 break;
1875 }
1876
1877 case WM_DRAWITEM:
1878 {
1879 DRAW_ITEM_STRUCT di;
1880 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)msg->lParam;
1881
1882 sprintf( seq->output, "%s: %p WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x",
1883 msg->descr, msg->hwnd, dis->CtlType, dis->CtlID,
1884 dis->itemID, dis->itemAction, dis->itemState);
1885
1886 di.u.lp = 0;
1887 di.u.item.type = dis->CtlType;
1888 di.u.item.ctl_id = dis->CtlID;
1889 if (dis->CtlType == ODT_LISTBOX ||
1890 dis->CtlType == ODT_COMBOBOX ||
1891 dis->CtlType == ODT_MENU)
1892 di.u.item.item_id = dis->itemID;
1893 di.u.item.action = dis->itemAction;
1894 di.u.item.state = dis->itemState;
1895
1896 seq->lParam = di.u.lp;
1897 break;
1898 }
1899 default:
1900 if (msg->message >= 0xc000) return; /* ignore registered messages */
1901 sprintf( seq->output, "%s: %p %04x wp %08lx lp %08lx",
1902 msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1903 }
1904 if (msg->flags & (sent|posted|parent|defwinproc|beginpaint))
1905 sprintf( seq->output + strlen(seq->output), " (flags %x)", msg->flags );
1906 }
1907 }
1908
1909 sequence_cnt++;
1910 }
1911
1912 /* try to make sure pending X events have been processed before continuing */
1913 static void flush_events(void)
1914 {
1915 MSG msg;
1916 int diff = 200;
1917 int min_timeout = 100;
1918 DWORD time = GetTickCount() + diff;
1919
1920 while (diff > 0)
1921 {
1922 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1923 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1924 diff = time - GetTickCount();
1925 }
1926 }
1927
1928 static void flush_sequence(void)
1929 {
1930 HeapFree(GetProcessHeap(), 0, sequence);
1931 sequence = 0;
1932 sequence_cnt = sequence_size = 0;
1933 }
1934
1935 static void dump_sequence(const struct message *expected, const char *context, const char *file, int line)
1936 {
1937 const struct recvd_message *actual = sequence;
1938 unsigned int count = 0;
1939
1940 trace_(file, line)("Failed sequence %s:\n", context );
1941 while (expected->message && actual->message)
1942 {
1943 if (actual->output[0])
1944 {
1945 if (expected->flags & hook)
1946 {
1947 trace_(file, line)( " %u: expected: hook %04x - actual: %s\n",
1948 count, expected->message, actual->output );
1949 }
1950 else if (expected->flags & winevent_hook)
1951 {
1952 trace_(file, line)( " %u: expected: winevent %04x - actual: %s\n",
1953 count, expected->message, actual->output );
1954 }
1955 else if (expected->flags & kbd_hook)
1956 {
1957 trace_(file, line)( " %u: expected: kbd %04x - actual: %s\n",
1958 count, expected->message, actual->output );
1959 }
1960 else
1961 {
1962 trace_(file, line)( " %u: expected: msg %04x - actual: %s\n",
1963 count, expected->message, actual->output );
1964 }
1965 }
1966
1967 if (expected->message == actual->message)
1968 {
1969 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) &&
1970 (expected->flags & optional))
1971 {
1972 /* don't match messages if their defwinproc status differs */
1973 expected++;
1974 }
1975 else
1976 {
1977 expected++;
1978 actual++;
1979 }
1980 }
1981 /* silently drop winevent messages if there is no support for them */
1982 else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1983 expected++;
1984 else
1985 {
1986 expected++;
1987 actual++;
1988 }
1989 count++;
1990 }
1991
1992 /* optional trailing messages */
1993 while (expected->message && ((expected->flags & optional) ||
1994 ((expected->flags & winevent_hook) && !hEvent_hook)))
1995 {
1996 trace_(file, line)( " %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1997 expected++;
1998 count++;
1999 }
2000
2001 if (expected->message)
2002 {
2003 trace_(file, line)( " %u: expected: msg %04x - actual: nothing\n", count, expected->message );
2004 return;
2005 }
2006
2007 while (actual->message && actual->output[0])
2008 {
2009 trace_(file, line)( " %u: expected: nothing - actual: %s\n", count, actual->output );
2010 actual++;
2011 count++;
2012 }
2013 }
2014
2015 #define ok_sequence( exp, contx, todo) \
2016 ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
2017
2018
2019 static void ok_sequence_(const struct message *expected_list, const char *context, int todo,
2020 const char *file, int line)
2021 {
2022 static const struct recvd_message end_of_sequence;
2023 const struct message *expected = expected_list;
2024 const struct recvd_message *actual;
2025 int failcount = 0, dump = 0;
2026 unsigned int count = 0;
2027
2028 add_message(&end_of_sequence);
2029
2030 actual = sequence;
2031
2032 while (expected->message && actual->message)
2033 {
2034 if (expected->message == actual->message &&
2035 !((expected->flags ^ actual->flags) & (hook|winevent_hook|kbd_hook)))
2036 {
2037 if (expected->flags & wparam)
2038 {
2039 if (((expected->wParam ^ actual->wParam) & ~expected->wp_mask) && todo)
2040 {
2041 todo_wine {
2042 failcount ++;
2043 if (strcmp(winetest_platform, "wine")) dump++;
2044 ok_( file, line) (FALSE,
2045 "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2046 context, count, expected->message, expected->wParam, actual->wParam);
2047 }
2048 }
2049 else
2050 {
2051 ok_( file, line)( ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) == 0,
2052 "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2053 context, count, expected->message, expected->wParam, actual->wParam);
2054 if ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) dump++;
2055 }
2056
2057 }
2058 if (expected->flags & lparam)
2059 {
2060 if (((expected->lParam ^ actual->lParam) & ~expected->lp_mask) && todo)
2061 {
2062 todo_wine {
2063 failcount ++;
2064 if (strcmp(winetest_platform, "wine")) dump++;
2065 ok_( file, line) (FALSE,
2066 "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2067 context, count, expected->message, expected->lParam, actual->lParam);
2068 }
2069 }
2070 else
2071 {
2072 ok_( file, line)(((expected->lParam ^ actual->lParam) & ~expected->lp_mask) == 0,
2073 "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2074 context, count, expected->message, expected->lParam, actual->lParam);
2075 if ((expected->lParam ^ actual->lParam) & ~expected->lp_mask) dump++;
2076 }
2077 }
2078 if ((expected->flags & optional) &&
2079 ((expected->flags ^ actual->flags) & (defwinproc|parent)))
2080 {
2081 /* don't match optional messages if their defwinproc or parent status differs */
2082 expected++;
2083 count++;
2084 continue;
2085 }
2086 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
2087 {
2088 todo_wine {
2089 failcount ++;
2090 if (strcmp(winetest_platform, "wine")) dump++;
2091 ok_( file, line) (FALSE,
2092 "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2093 context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2094 }
2095 }
2096 else
2097 {
2098 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
2099 "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2100 context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2101 if ((expected->flags & defwinproc) != (actual->flags & defwinproc)) dump++;
2102 }
2103
2104 ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
2105 "%s: %u: the msg 0x%04x should %shave been sent by BeginPaint\n",
2106 context, count, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
2107 if ((expected->flags & beginpaint) != (actual->flags & beginpaint)) dump++;
2108
2109 ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
2110 "%s: %u: the msg 0x%04x should have been %s\n",
2111 context, count, expected->message, (expected->flags & posted) ? "posted" : "sent");
2112 if ((expected->flags & (sent|posted)) != (actual->flags & (sent|posted))) dump++;
2113
2114 ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
2115 "%s: %u: the msg 0x%04x was expected in %s\n",
2116 context, count, expected->message, (expected->flags & parent) ? "parent" : "child");
2117 if ((expected->flags & parent) != (actual->flags & parent)) dump++;
2118
2119 ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
2120 "%s: %u: the msg 0x%04x should have been sent by a hook\n",
2121 context, count, expected->message);
2122 if ((expected->flags & hook) != (actual->flags & hook)) dump++;
2123
2124 ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
2125 "%s: %u: the msg 0x%04x should have been sent by a winevent hook\n",
2126 context, count, expected->message);
2127 if ((expected->flags & winevent_hook) != (actual->flags & winevent_hook)) dump++;
2128
2129 ok_( file, line) ((expected->flags & kbd_hook) == (actual->flags & kbd_hook),
2130 "%s: %u: the msg 0x%04x should have been sent by a keyboard hook\n",
2131 context, count, expected->message);
2132 if ((expected->flags & kbd_hook) != (actual->flags & kbd_hook)) dump++;
2133
2134 expected++;
2135 actual++;
2136 }
2137 /* silently drop hook messages if there is no support for them */
2138 else if ((expected->flags & optional) ||
2139 ((expected->flags & hook) && !hCBT_hook) ||
2140 ((expected->flags & winevent_hook) && !hEvent_hook) ||
2141 ((expected->flags & kbd_hook) && !hKBD_hook))
2142 expected++;
2143 else if (todo)
2144 {
2145 failcount++;
2146 todo_wine {
2147 if (strcmp(winetest_platform, "wine")) dump++;
2148 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2149 context, count, expected->message, actual->message);
2150 }
2151 goto done;
2152 }
2153 else
2154 {
2155 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2156 context, count, expected->message, actual->message);
2157 dump++;
2158 expected++;
2159 actual++;
2160 }
2161 count++;
2162 }
2163
2164 /* skip all optional trailing messages */
2165 while (expected->message && ((expected->flags & optional) ||
2166 ((expected->flags & hook) && !hCBT_hook) ||
2167 ((expected->flags & winevent_hook) && !hEvent_hook)))
2168 expected++;
2169
2170 if (todo)
2171 {
2172 todo_wine {
2173 if (expected->message || actual->message) {
2174 failcount++;
2175 if (strcmp(winetest_platform, "wine")) dump++;
2176 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2177 context, count, expected->message, actual->message);
2178 }
2179 }
2180 }
2181 else
2182 {
2183 if (expected->message || actual->message)
2184 {
2185 dump++;
2186 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2187 context, count, expected->message, actual->message);
2188 }
2189 }
2190 if( todo && !failcount) /* succeeded yet marked todo */
2191 todo_wine {
2192 if (!strcmp(winetest_platform, "wine")) dump++;
2193 ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
2194 }
2195
2196 done:
2197 if (dump) dump_sequence(expected_list, context, file, line);
2198 flush_sequence();
2199 }
2200
2201 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
2202
2203 /******************************** MDI test **********************************/
2204
2205 /* CreateWindow for MDI frame window, initially visible */
2206 static const struct message WmCreateMDIframeSeq[] = {
2207 { HCBT_CREATEWND, hook },
2208 { WM_GETMINMAXINFO, sent },
2209 { WM_NCCREATE, sent },
2210 { WM_NCCALCSIZE, sent|wparam, 0 },
2211 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2212 { WM_CREATE, sent },
2213 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2214 { WM_NOTIFYFORMAT, sent|optional },
2215 { WM_QUERYUISTATE, sent|optional },
2216 { WM_WINDOWPOSCHANGING, sent|optional },
2217 { WM_GETMINMAXINFO, sent|optional },
2218 { WM_NCCALCSIZE, sent|optional },
2219 { WM_WINDOWPOSCHANGED, sent|optional },
2220 { WM_SHOWWINDOW, sent|wparam, 1 },
2221 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2222 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2223 { HCBT_ACTIVATE, hook },
2224 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
2225 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
2226 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
2227 { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
2228 { WM_NCACTIVATE, sent },
2229 { WM_GETTEXT, sent|defwinproc|optional },
2230 { WM_ACTIVATE, sent|wparam, 1 },
2231 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
2232 { HCBT_SETFOCUS, hook },
2233 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2234 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2235 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2236 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
2237 /* Win9x adds SWP_NOZORDER below */
2238 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2239 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2240 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2241 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2242 { WM_MOVE, sent },
2243 { 0 }
2244 };
2245 /* DestroyWindow for MDI frame window, initially visible */
2246 static const struct message WmDestroyMDIframeSeq[] = {
2247 { HCBT_DESTROYWND, hook },
2248 { 0x0090, sent|optional },
2249 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2250 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2251 { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2252 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2253 { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
2254 { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2255 { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
2256 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
2257 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2258 { WM_DESTROY, sent },
2259 { WM_NCDESTROY, sent },
2260 { 0 }
2261 };
2262 /* CreateWindow for MDI client window, initially visible */
2263 static const struct message WmCreateMDIclientSeq[] = {
2264 { HCBT_CREATEWND, hook },
2265 { WM_NCCREATE, sent },
2266 { WM_NCCALCSIZE, sent|wparam, 0 },
2267 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2268 { WM_CREATE, sent },
2269 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2270 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2271 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2272 { WM_MOVE, sent },
2273 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
2274 { WM_SHOWWINDOW, sent|wparam, 1 },
2275 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2276 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2277 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2278 { 0 }
2279 };
2280 /* ShowWindow(SW_SHOW) for MDI client window */
2281 static const struct message WmShowMDIclientSeq[] = {
2282 { WM_SHOWWINDOW, sent|wparam, 1 },
2283 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2284 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2285 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2286 { 0 }
2287 };
2288 /* ShowWindow(SW_HIDE) for MDI client window */
2289 static const struct message WmHideMDIclientSeq[] = {
2290 { WM_SHOWWINDOW, sent|wparam, 0 },
2291 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2292 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
2293 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
2294 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2295 { 0 }
2296 };
2297 /* DestroyWindow for MDI client window, initially visible */
2298 static const struct message WmDestroyMDIclientSeq[] = {
2299 { HCBT_DESTROYWND, hook },
2300 { 0x0090, sent|optional },
2301 { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
2302 { WM_SHOWWINDOW, sent|wparam, 0 },
2303 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2304 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2305 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2306 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2307 { WM_DESTROY, sent },
2308 { WM_NCDESTROY, sent },
2309 { 0 }
2310 };
2311 /* CreateWindow for MDI child window, initially visible */
2312 static const struct message WmCreateMDIchildVisibleSeq[] = {
2313 { HCBT_CREATEWND, hook },
2314 { WM_NCCREATE, sent },
2315 { WM_NCCALCSIZE, sent|wparam, 0 },
2316 { WM_CREATE, sent },
2317 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2318 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2319 { WM_MOVE, sent },
2320 /* Win2k sends wparam set to
2321 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2322 * while Win9x doesn't bother to set child window id according to
2323 * CLIENTCREATESTRUCT.idFirstChild
2324 */
2325 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2326 { WM_SHOWWINDOW, sent|wparam, 1 },
2327 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2328 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2329 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2330 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2331 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2332 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2333 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2334
2335 /* Win9x: message sequence terminates here. */
2336
2337 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2338 { HCBT_SETFOCUS, hook }, /* in MDI client */
2339 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2340 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2341 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2342 { WM_SETFOCUS, sent }, /* in MDI client */
2343 { HCBT_SETFOCUS, hook },
2344 { WM_KILLFOCUS, sent }, /* in MDI client */
2345 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2346 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2347 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2348 { WM_SETFOCUS, sent|defwinproc },
2349 { WM_MDIACTIVATE, sent|defwinproc },
2350 { 0 }
2351 };
2352 /* CreateWindow for MDI child window with invisible parent */
2353 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
2354 { HCBT_CREATEWND, hook },
2355 { WM_GETMINMAXINFO, sent },
2356 { WM_NCCREATE, sent },
2357 { WM_NCCALCSIZE, sent|wparam, 0 },
2358 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2359 { WM_CREATE, sent },
2360 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2361 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2362 { WM_MOVE, sent },
2363 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2364 { WM_SHOWWINDOW, sent|wparam, 1 },
2365 { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2366 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2367 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2368 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2369
2370 /* Win9x: message sequence terminates here. */
2371
2372 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2373 { HCBT_SETFOCUS, hook }, /* in MDI client */
2374 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2375 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2376 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2377 { WM_SETFOCUS, sent }, /* in MDI client */
2378 { HCBT_SETFOCUS, hook },
2379 { WM_KILLFOCUS, sent }, /* in MDI client */
2380 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2381 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2382 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2383 { WM_SETFOCUS, sent|defwinproc },
2384 { WM_MDIACTIVATE, sent|defwinproc },
2385 { 0 }
2386 };
2387 /* DestroyWindow for MDI child window, initially visible */
2388 static const struct message WmDestroyMDIchildVisibleSeq[] = {
2389 { HCBT_DESTROYWND, hook },
2390 /* Win2k sends wparam set to
2391 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2392 * while Win9x doesn't bother to set child window id according to
2393 * CLIENTCREATESTRUCT.idFirstChild
2394 */
2395 { 0x0090, sent|optional },
2396 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2397 { WM_SHOWWINDOW, sent|wparam, 0 },
2398 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2399 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2400 { WM_ERASEBKGND, sent|parent|optional },
2401 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2402
2403 /* { WM_DESTROY, sent }
2404 * Win9x: message sequence terminates here.
2405 */
2406
2407 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2408 { WM_KILLFOCUS, sent },
2409 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2410 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2411 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2412 { WM_SETFOCUS, sent }, /* in MDI client */
2413
2414 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2415 { WM_KILLFOCUS, sent }, /* in MDI client */
2416 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2417 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2418 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2419 { WM_SETFOCUS, sent }, /* in MDI client */
2420
2421 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2422
2423 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2424 { WM_KILLFOCUS, sent },
2425 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2426 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2427 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2428 { WM_SETFOCUS, sent }, /* in MDI client */
2429
2430 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2431 { WM_KILLFOCUS, sent }, /* in MDI client */
2432 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2433 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2434 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2435 { WM_SETFOCUS, sent }, /* in MDI client */
2436
2437 { WM_DESTROY, sent },
2438
2439 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2440 { WM_KILLFOCUS, sent },
2441 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2442 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2443 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2444 { WM_SETFOCUS, sent }, /* in MDI client */
2445
2446 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2447 { WM_KILLFOCUS, sent }, /* in MDI client */
2448 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2449 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2450 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2451 { WM_SETFOCUS, sent }, /* in MDI client */
2452
2453 { WM_NCDESTROY, sent },
2454 { 0 }
2455 };
2456 /* CreateWindow for MDI child window, initially invisible */
2457 static const struct message WmCreateMDIchildInvisibleSeq[] = {
2458 { HCBT_CREATEWND, hook },
2459 { WM_NCCREATE, sent },
2460 { WM_NCCALCSIZE, sent|wparam, 0 },
2461 { WM_CREATE, sent },
2462 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2463 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2464 { WM_MOVE, sent },
2465 /* Win2k sends wparam set to
2466 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2467 * while Win9x doesn't bother to set child window id according to
2468 * CLIENTCREATESTRUCT.idFirstChild
2469 */
2470 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2471 { 0 }
2472 };
2473 /* DestroyWindow for MDI child window, initially invisible */
2474 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
2475 { HCBT_DESTROYWND, hook },
2476 /* Win2k sends wparam set to
2477 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2478 * while Win9x doesn't bother to set child window id according to
2479 * CLIENTCREATESTRUCT.idFirstChild
2480 */
2481 { 0x0090, sent|optional },
2482 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2483 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2484 { WM_DESTROY, sent },
2485 { WM_NCDESTROY, sent },
2486 /* FIXME: Wine destroys an icon/title window while Windows doesn't */
2487 { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
2488 { 0 }
2489 };
2490 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
2491 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
2492 { HCBT_CREATEWND, hook },
2493 { WM_NCCREATE, sent },
2494 { WM_NCCALCSIZE, sent|wparam, 0 },
2495 { WM_CREATE, sent },
2496 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2497 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2498 { WM_MOVE, sent },
2499 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2500 { WM_GETMINMAXINFO, sent },
2501 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2502 { WM_NCCALCSIZE, sent|wparam, 1 },
2503 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2504 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2505 /* in MDI frame */
2506 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2507 { WM_NCCALCSIZE, sent|wparam, 1 },
2508 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2509 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2510 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2511 /* Win2k sends wparam set to
2512 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2513 * while Win9x doesn't bother to set child window id according to
2514 * CLIENTCREATESTRUCT.idFirstChild
2515 */
2516 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2517 { WM_SHOWWINDOW, sent|wparam, 1 },
2518 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2519 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2520 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2521 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2522 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2523 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2524 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_FRAMECHANGED },
2525
2526 /* Win9x: message sequence terminates here. */
2527
2528 { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2529 { HCBT_SETFOCUS, hook|optional }, /* in MDI client */
2530 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2531 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2532 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2533 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2534 { HCBT_SETFOCUS, hook|optional },
2535 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2536 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2537 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2538 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2539 { WM_SETFOCUS, sent|defwinproc|optional },
2540 { WM_MDIACTIVATE, sent|defwinproc|optional },
2541 /* in MDI frame */
2542 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2543 { WM_NCCALCSIZE, sent|wparam, 1 },
2544 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2545 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2546 { 0 }
2547 };
2548 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2549 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2550 /* restore the 1st MDI child */
2551 { WM_SETREDRAW, sent|wparam, 0 },
2552 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2553 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2554 { WM_NCCALCSIZE, sent|wparam, 1 },
2555 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2556 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2557 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2558 /* in MDI frame */
2559 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2560 { WM_NCCALCSIZE, sent|wparam, 1 },
2561 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2562 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2563 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2564 { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2565 /* create the 2nd MDI child */
2566 { HCBT_CREATEWND, hook },
2567 { WM_NCCREATE, sent },
2568 { WM_NCCALCSIZE, sent|wparam, 0 },
2569 { WM_CREATE, sent },
2570 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2571 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2572 { WM_MOVE, sent },
2573 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2574 { WM_GETMINMAXINFO, sent },
2575 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2576 { WM_NCCALCSIZE, sent|wparam, 1 },
2577 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2578 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2579 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2580 /* in MDI frame */
2581 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2582 { WM_NCCALCSIZE, sent|wparam, 1 },
2583 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2584 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2585 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2586 /* Win2k sends wparam set to
2587 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2588 * while Win9x doesn't bother to set child window id according to
2589 * CLIENTCREATESTRUCT.idFirstChild
2590 */
2591 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2592 { WM_SHOWWINDOW, sent|wparam, 1 },
2593 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2594 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2595 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2596 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2597 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2598 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2599
2600 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2601 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2602
2603 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2604
2605 /* Win9x: message sequence terminates here. */
2606
2607 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2608 { HCBT_SETFOCUS, hook },
2609 { WM_KILLFOCUS, sent|defwinproc|optional }, /* in the 1st MDI child */
2610 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2611 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2612 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2613 { WM_SETFOCUS, sent }, /* in MDI client */
2614 { HCBT_SETFOCUS, hook },
2615 { WM_KILLFOCUS, sent }, /* in MDI client */
2616 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2617 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2618 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2619 { WM_SETFOCUS, sent|defwinproc },
2620
2621 { WM_MDIACTIVATE, sent|defwinproc },
2622 /* in MDI frame */
2623 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2624 { WM_NCCALCSIZE, sent|wparam, 1 },
2625 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2626 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2627 { 0 }
2628 };
2629 /* WM_MDICREATE MDI child window, initially visible and maximized */
2630 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2631 { WM_MDICREATE, sent },
2632 { HCBT_CREATEWND, hook },
2633 { WM_NCCREATE, sent },
2634 { WM_NCCALCSIZE, sent|wparam, 0 },
2635 { WM_CREATE, sent },
2636 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2637 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2638 { WM_MOVE, sent },
2639 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2640 { WM_GETMINMAXINFO, sent },
2641 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2642 { WM_NCCALCSIZE, sent|wparam, 1 },
2643 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2644 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2645
2646 /* in MDI frame */
2647 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2648 { WM_NCCALCSIZE, sent|wparam, 1 },
2649 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2650 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2651 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2652
2653 /* Win2k sends wparam set to
2654 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2655 * while Win9x doesn't bother to set child window id according to
2656 * CLIENTCREATESTRUCT.idFirstChild
2657 */
2658 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2659 { WM_SHOWWINDOW, sent|wparam, 1 },
2660 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2661
2662 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2663
2664 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2665 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2666 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2667
2668 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2669 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2670
2671 /* Win9x: message sequence terminates here. */
2672
2673 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2674 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2675 { HCBT_SETFOCUS, hook }, /* in MDI client */
2676 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2677 { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2678 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2679 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2680 { HCBT_SETFOCUS, hook|optional },
2681 { WM_KILLFOCUS, sent }, /* in MDI client */
2682 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2683 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2684 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2685 { WM_SETFOCUS, sent|defwinproc },
2686
2687 { WM_MDIACTIVATE, sent|defwinproc },
2688
2689 /* in MDI child */
2690 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2691 { WM_NCCALCSIZE, sent|wparam, 1 },
2692 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2693 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2694
2695 /* in MDI frame */
2696 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2697 { WM_NCCALCSIZE, sent|wparam, 1 },
2698 { 0x0093, sent|defwinproc|optional },
2699 { 0x0093, sent|defwinproc|optional },
2700 { 0x0093, sent|defwinproc|optional },
2701 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2702 { WM_MOVE, sent|defwinproc },
2703 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2704
2705 /* in MDI client */
2706 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2707 { WM_NCCALCSIZE, sent|wparam, 1 },
2708 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2709 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2710
2711 /* in MDI child */
2712 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2713 { WM_NCCALCSIZE, sent|wparam, 1 },
2714 { 0x0093, sent|optional },
2715 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2716 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2717
2718 { 0x0093, sent|optional },
2719 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2720 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2721 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2722 { 0x0093, sent|defwinproc|optional },
2723 { 0x0093, sent|defwinproc|optional },
2724 { 0x0093, sent|defwinproc|optional },
2725 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2726 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2727
2728 { 0 }
2729 };
2730 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2731 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2732 { HCBT_CREATEWND, hook },
2733 { WM_GETMINMAXINFO, sent },
2734 { WM_NCCREATE, sent },
2735 { WM_NCCALCSIZE, sent|wparam, 0 },
2736 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2737 { WM_CREATE, sent },
2738 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2739 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2740 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2741 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI frame */
2742 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2743 { WM_MOVE, sent },
2744 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2745 { WM_GETMINMAXINFO, sent },
2746 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2747 { WM_GETMINMAXINFO, sent|defwinproc },
2748 { WM_NCCALCSIZE, sent|wparam, 1 },
2749 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_STATECHANGED },
2750 { WM_MOVE, sent|defwinproc },
2751 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2752 /* in MDI frame */
2753 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2754 { WM_NCCALCSIZE, sent|wparam, 1 },
2755 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2756 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2757 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2758 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2759 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2760 /* Win2k sends wparam set to
2761 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2762 * while Win9x doesn't bother to set child window id according to
2763 * CLIENTCREATESTRUCT.idFirstChild
2764 */
2765 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2766 { 0 }
2767 };
2768 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2769 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2770 { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2771 { HCBT_SYSCOMMAND, hook },
2772 { WM_CLOSE, sent|defwinproc },
2773 { WM_MDIDESTROY, sent }, /* in MDI client */
2774
2775 /* bring the 1st MDI child to top */
2776 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2777 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2778
2779 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2780
2781 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2782 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2783 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2784
2785 /* maximize the 1st MDI child */
2786 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2787 { WM_GETMINMAXINFO, sent|defwinproc },
2788 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED },
2789 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2790 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2791 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2792 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2793
2794 /* restore the 2nd MDI child */
2795 { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2796 { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2797 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2798 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2799
2800 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2801
2802 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2803 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2804
2805 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2806
2807 { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2808 /* in MDI frame */
2809 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2810 { WM_NCCALCSIZE, sent|wparam, 1 },
2811 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2812 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2813 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2814
2815 /* bring the 1st MDI child to top */
2816 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2817 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2818 { HCBT_SETFOCUS, hook },
2819 { WM_KILLFOCUS, sent|defwinproc },
2820 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2821 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2822 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2823 { WM_SETFOCUS, sent }, /* in MDI client */
2824 { HCBT_SETFOCUS, hook },
2825 { WM_KILLFOCUS, sent }, /* in MDI client */
2826 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2827 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2828 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2829 { WM_SETFOCUS, sent|defwinproc },
2830 { WM_MDIACTIVATE, sent|defwinproc },
2831 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2832
2833 /* apparently ShowWindow(SW_SHOW) on an MDI client */
2834 { WM_SHOWWINDOW, sent|wparam, 1 },
2835 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2836 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2837 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2838 { WM_MDIREFRESHMENU, sent },
2839
2840 { HCBT_DESTROYWND, hook },
2841 /* Win2k sends wparam set to
2842 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2843 * while Win9x doesn't bother to set child window id according to
2844 * CLIENTCREATESTRUCT.idFirstChild
2845 */
2846 { 0x0090, sent|defwinproc|optional },
2847 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2848 { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2849 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2850 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2851 { WM_ERASEBKGND, sent|parent|optional },
2852 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2853
2854 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2855 { WM_DESTROY, sent|defwinproc },
2856 { WM_NCDESTROY, sent|defwinproc },
2857 { 0 }
2858 };
2859 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2860 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2861 { WM_MDIDESTROY, sent }, /* in MDI client */
2862 { WM_SHOWWINDOW, sent|wparam, 0 },
2863 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2864 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2865 { WM_ERASEBKGND, sent|parent|optional },
2866 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2867
2868 { HCBT_SETFOCUS, hook },
2869 { WM_KILLFOCUS, sent },
2870 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2871 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2872 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2873 { WM_SETFOCUS, sent }, /* in MDI client */
2874 { HCBT_SETFOCUS, hook },
2875 { WM_KILLFOCUS, sent }, /* in MDI client */
2876 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2877 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2878 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2879 { WM_SETFOCUS, sent },
2880
2881 /* in MDI child */
2882 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2883 { WM_NCCALCSIZE, sent|wparam, 1 },
2884 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2885 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2886
2887 /* in MDI frame */
2888 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2889 { WM_NCCALCSIZE, sent|wparam, 1 },
2890 { 0x0093, sent|defwinproc|optional },
2891 { 0x0093, sent|defwinproc|optional },
2892 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2893 { WM_MOVE, sent|defwinproc },
2894 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2895
2896 /* in MDI client */
2897 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2898 { WM_NCCALCSIZE, sent|wparam, 1 },
2899 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2900 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2901
2902 /* in MDI child */
2903 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2904 { WM_NCCALCSIZE, sent|wparam, 1 },
2905 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2906 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2907
2908 /* in MDI child */
2909 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2910 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2911 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2912 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2913
2914 /* in MDI frame */
2915 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2916 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2917 { 0x0093, sent|defwinproc|optional },
2918 { 0x0093, sent|defwinproc|optional },
2919 { 0x0093, sent|defwinproc|optional },
2920 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2921 { WM_MOVE, sent|defwinproc },
2922 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2923
2924 /* in MDI client */
2925 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2926 { WM_NCCALCSIZE, sent|wparam, 1 },
2927 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2928 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2929
2930 /* in MDI child */
2931 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2932 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2933 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2934 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2935 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2936 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2937
2938 { 0x0093, sent|defwinproc|optional },
2939 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2940 { 0x0093, sent|defwinproc|optional },
2941 { 0x0093, sent|defwinproc|optional },
2942 { 0x0093, sent|defwinproc|optional },
2943 { 0x0093, sent|optional },
2944
2945 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2946 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2947 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2948 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2949 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2950
2951 /* in MDI frame */
2952 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2953 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2954 { 0x0093, sent|defwinproc|optional },
2955 { 0x0093, sent|defwinproc|optional },
2956 { 0x0093, sent|defwinproc|optional },
2957 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2958 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2959 { 0x0093, sent|optional },
2960
2961 { WM_NCACTIVATE, sent|wparam, 0 },
2962 { WM_MDIACTIVATE, sent },
2963
2964 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2965 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2966 { WM_NCCALCSIZE, sent|wparam, 1 },
2967
2968 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2969
2970 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2971 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2972 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2973
2974 /* in MDI child */
2975 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2976 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2977 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2978 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2979
2980 /* in MDI frame */
2981 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2982 { WM_NCCALCSIZE, sent|wparam, 1 },
2983 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2984 { WM_MOVE, sent|defwinproc },
2985 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2986
2987 /* in MDI client */
2988 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2989 { WM_NCCALCSIZE, sent|wparam, 1 },
2990 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2991 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2992 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2993 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2994 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2995 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2996 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2997
2998 { HCBT_SETFOCUS, hook },
2999 { WM_KILLFOCUS, sent },
3000 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
3001 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3002 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3003 { WM_SETFOCUS, sent }, /* in MDI client */
3004
3005 { WM_MDIREFRESHMENU, sent }, /* in MDI client */
3006
3007 { HCBT_DESTROYWND, hook },
3008 /* Win2k sends wparam set to
3009 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
3010 * while Win9x doesn't bother to set child window id according to
3011 * CLIENTCREATESTRUCT.idFirstChild
3012 */
3013 { 0x0090, sent|optional },
3014 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
3015
3016 { WM_SHOWWINDOW, sent|wparam, 0 },
3017 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3018 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
3019 { WM_ERASEBKGND, sent|parent|optional },
3020 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3021
3022 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
3023 { WM_DESTROY, sent },
3024 { WM_NCDESTROY, sent },
3025 { 0 }
3026 };
3027 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
3028 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
3029 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3030 { WM_GETMINMAXINFO, sent },
3031 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
3032 { WM_NCCALCSIZE, sent|wparam, 1 },
3033 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3034 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3035
3036 { WM_WINDOWPOSCHANGING, sent|wparam|optional|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3037 { WM_NCACTIVATE, sent|wparam|optional|defwinproc, 1 },
3038 { HCBT_SETFOCUS, hook|optional },
3039 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3040 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3041 { WM_SETFOCUS, sent|optional }, /* in MDI client */
3042 { HCBT_SETFOCUS, hook|optional },
3043 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3044 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3045 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3046 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3047 { WM_SETFOCUS, sent|optional|defwinproc },
3048 { WM_MDIACTIVATE, sent|optional|defwinproc },
3049 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3050 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3051 /* in MDI frame */
3052 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3053 { WM_NCCALCSIZE, sent|wparam, 1 },
3054 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3055 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3056 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3057 { 0 }
3058 };
3059 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
3060 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
3061 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3062 { WM_GETMINMAXINFO, sent },
3063 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
3064 { WM_GETMINMAXINFO, sent|defwinproc },
3065 { WM_NCCALCSIZE, sent|wparam, 1 },
3066 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3067 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3068
3069 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3070 { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
3071 { HCBT_SETFOCUS, hook|optional },
3072 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3073 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3074 { WM_SETFOCUS, sent|optional }, /* in MDI client */
3075 { HCBT_SETFOCUS, hook|optional },
3076 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3077 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3078 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3079 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3080 { WM_SETFOCUS, sent|defwinproc|optional },
3081 { WM_MDIACTIVATE, sent|defwinproc|optional },
3082 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3083 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3084 { 0 }
3085 };
3086 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
3087 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
3088 { WM_MDIMAXIMIZE, sent }, /* in MDI client */
3089 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3090 { WM_GETMINMAXINFO, sent },
3091 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3092 { WM_GETMINMAXINFO, sent|defwinproc },
3093 { WM_NCCALCSIZE, sent|wparam, 1 },
3094 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
3095 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3096 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
3097 { WM_MOVE, sent|defwinproc },
3098 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3099
3100 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3101 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3102 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3103 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3104 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3105 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3106 /* in MDI frame */
3107 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3108 { WM_NCCALCSIZE, sent|wparam, 1 },
3109 { 0x0093, sent|defwinproc|optional },
3110 { 0x0094, sent|defwinproc|optional },
3111 { 0x0094, sent|defwinproc|optional },
3112 { 0x0094, sent|defwinproc|optional },
3113 { 0x0094, sent|defwinproc|optional },
3114 { 0x0093, sent|defwinproc|optional },
3115 { 0x0093, sent|defwinproc|optional },
3116 { 0x0091, sent|defwinproc|optional },
3117 { 0x0092, sent|defwinproc|optional },
3118 { 0x0092, sent|defwinproc|optional },
3119 { 0x0092, sent|defwinproc|optional },
3120 { 0x0092, sent|defwinproc|optional },
3121 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3122 { WM_MOVE, sent|defwinproc },
3123 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3124 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
3125 /* in MDI client */
3126 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
3127 { WM_NCCALCSIZE, sent|wparam, 1 },
3128 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3129 { WM_SIZE, sent|wparam, SIZE_RESTORED },
3130 /* in MDI child */
3131 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
3132 { WM_GETMINMAXINFO, sent|defwinproc },
3133 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3134 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3135 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3136 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
3137 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3138 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3139 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3140 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3141 /* in MDI frame */
3142 { 0x0093, sent|optional },
3143 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
3144 { 0x0093, sent|defwinproc|optional },
3145 { 0x0093, sent|defwinproc|optional },
3146 { 0x0093, sent|defwinproc|optional },
3147 { 0x0091, sent|defwinproc|optional },
3148 { 0x0092, sent|defwinproc|optional },
3149 { 0x0092, sent|defwinproc|optional },
3150 { 0x0092, sent|defwinproc|optional },
3151 { 0x0092, sent|defwinproc|optional },
3152 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3153 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3154 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3155 { 0 }
3156 };
3157 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
3158 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
3159 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3160 { WM_GETMINMAXINFO, sent },
3161 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3162 { WM_NCCALCSIZE, sent|wparam, 1 },
3163 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3164 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3165 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3166 /* in MDI frame */
3167 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3168 { WM_NCCALCSIZE, sent|wparam, 1 },
3169 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3170 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3171 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3172 { 0 }
3173 };
3174 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
3175 static const struct message WmRestoreMDIchildVisibleSeq[] = {
3176 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3177 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3178 { WM_NCCALCSIZE, sent|wparam, 1 },
3179 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3180 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3181 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3182 /* in MDI frame */
3183 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3184 { WM_NCCALCSIZE, sent|wparam, 1 },
3185 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3186 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3187 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3188 { 0 }
3189 };
3190 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
3191 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
3192 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3193 { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
3194 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3195 { WM_NCCALCSIZE, sent|wparam, 1 },
3196 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3197 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3198 { WM_MOVE, sent|defwinproc },
3199 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3200 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3201 { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3202 { HCBT_SETFOCUS, hook },
3203 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3204 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
3205 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3206 { WM_SETFOCUS, sent },
3207 { 0 }
3208 };
3209 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
3210 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
3211 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
3212 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3213 { WM_NCCALCSIZE, sent|wparam, 1 },
3214 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3215 { WM_MOVE, sent|defwinproc },
3216 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
3217 { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
3218 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3219 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3220 /* FIXME: Wine creates an icon/title window while Windows doesn't */
3221 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
3222 { 0 }
3223 };
3224 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
3225 static const struct message WmRestoreMDIchildInisibleSeq[] = {
3226 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3227 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
3228 { WM_NCCALCSIZE, sent|wparam, 1 },
3229 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3230 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3231 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3232 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3233 /* in MDI frame */
3234 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3235 { WM_NCCALCSIZE, sent|wparam, 1 },
3236 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3237 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3238 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3239 { 0 }
3240 };
3241
3242 static HWND mdi_client;
3243 static WNDPROC old_mdi_client_proc;
3244
3245 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3246 {
3247 struct recvd_message msg;
3248
3249 /* do not log painting messages */
3250 if (message != WM_PAINT &&
3251 message != WM_NCPAINT &&
3252 message != WM_SYNCPAINT &&
3253 message != WM_ERASEBKGND &&
3254 message != WM_NCHITTEST &&
3255 message != WM_GETTEXT &&
3256 message != WM_MDIGETACTIVE &&
3257 !ignore_message( message ))
3258 {
3259 msg.hwnd = hwnd;
3260 msg.message = message;
3261 msg.flags = sent|wparam|lparam;
3262 msg.wParam = wParam;
3263 msg.lParam = lParam;
3264 msg.descr = "mdi client";
3265 add_message(&msg);
3266 }
3267
3268 return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
3269 }
3270
3271 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3272 {
3273 static LONG defwndproc_counter = 0;
3274 LRESULT ret;
3275 struct recvd_message msg;
3276
3277 /* do not log painting messages */
3278 if (message != WM_PAINT &&
3279 message != WM_NCPAINT &&
3280 message != WM_SYNCPAINT &&
3281 message != WM_ERASEBKGND &&
3282 message != WM_NCHITTEST &&
3283 message != WM_GETTEXT &&
3284 !ignore_message( message ))
3285 {
3286 switch (message)
3287 {
3288 case WM_MDIACTIVATE:
3289 {
3290 HWND active, client = GetParent(hwnd);
3291
3292 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
3293
3294 if (hwnd == (HWND)lParam) /* if we are being activated */
3295 ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
3296 else
3297 ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
3298 break;
3299 }
3300 }
3301
3302 msg.hwnd = hwnd;
3303 msg.message = message;
3304 msg.flags = sent|wparam|lparam;
3305 if (defwndproc_counter) msg.flags |= defwinproc;
3306 msg.wParam = wParam;
3307 msg.lParam = lParam;
3308 msg.descr = "mdi child";
3309 add_message(&msg);
3310 }
3311
3312 defwndproc_counter++;
3313 ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
3314 defwndproc_counter--;
3315
3316 return ret;
3317 }
3318
3319 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3320 {
3321 static LONG defwndproc_counter = 0;
3322 LRESULT ret;
3323 struct recvd_message msg;
3324
3325 /* do not log painting messages */
3326 if (message != WM_PAINT &&
3327 message != WM_NCPAINT &&
3328 message != WM_SYNCPAINT &&
3329 message != WM_ERASEBKGND &&
3330 message != WM_NCHITTEST &&
3331 message != WM_GETTEXT &&
3332 !ignore_message( message ))
3333 {
3334 msg.hwnd = hwnd;
3335 msg.message = message;
3336 msg.flags = sent|wparam|lparam;
3337 if (defwndproc_counter) msg.flags |= defwinproc;
3338 msg.wParam = wParam;
3339 msg.lParam = lParam;
3340 msg.descr = "mdi frame";
3341 add_message(&msg);
3342 }
3343
3344 defwndproc_counter++;
3345 ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
3346 defwndproc_counter--;
3347
3348 return ret;
3349 }
3350
3351 static BOOL mdi_RegisterWindowClasses(void)
3352 {
3353 WNDCLASSA cls;
3354
3355 cls.style = 0;
3356 cls.lpfnWndProc = mdi_frame_wnd_proc;
3357 cls.cbClsExtra = 0;
3358 cls.cbWndExtra = 0;
3359 cls.hInstance = GetModuleHandleA(0);
3360 cls.hIcon = 0;
3361 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3362 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3363 cls.lpszMenuName = NULL;
3364 cls.lpszClassName = "MDI_frame_class";
3365 if (!RegisterClassA(&cls)) return FALSE;
3366
3367 cls.lpfnWndProc = mdi_child_wnd_proc;
3368 cls.lpszClassName = "MDI_child_class";
3369 if (!RegisterClassA(&cls)) return FALSE;
3370
3371 if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
3372 old_mdi_client_proc = cls.lpfnWndProc;
3373 cls.hInstance = GetModuleHandleA(0);
3374 cls.lpfnWndProc = mdi_client_hook_proc;
3375 cls.lpszClassName = "MDI_client_class";
3376 if (!RegisterClassA(&cls)) assert(0);
3377
3378 return TRUE;
3379 }
3380
3381 static void test_mdi_messages(void)
3382 {
3383 MDICREATESTRUCTA mdi_cs;
3384 CLIENTCREATESTRUCT client_cs;
3385 HWND mdi_frame, mdi_child, mdi_child2, active_child;
3386 BOOL zoomed;
3387 RECT rc;
3388 HMENU hMenu = CreateMenu();
3389
3390 if (!mdi_RegisterWindowClasses()) assert(0);
3391
3392 flush_sequence();
3393
3394 trace("creating MDI frame window\n");
3395 mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
3396 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3397 WS_MAXIMIZEBOX | WS_VISIBLE,
3398 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
3399 GetDesktopWindow(), hMenu,
3400 GetModuleHandleA(0), NULL);
3401 assert(mdi_frame);
3402 ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
3403
3404 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3405 ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
3406
3407 trace("creating MDI client window\n");
3408 GetClientRect(mdi_frame, &rc);
3409 client_cs.hWindowMenu = 0;
3410 client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
3411 mdi_client = CreateWindowExA(0, "MDI_client_class",
3412 NULL,
3413 WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
3414 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
3415 mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3416 assert(mdi_client);
3417 ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
3418
3419 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3420 ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
3421
3422 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3423 ok(!active_child, "wrong active MDI child %p\n", active_child);
3424 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3425
3426 SetFocus(0);
3427 flush_sequence();
3428
3429 trace("creating invisible MDI child window\n");
3430 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3431 WS_CHILD,
3432 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3433 mdi_client, 0, GetModuleHandleA(0), NULL);
3434 assert(mdi_child);
3435
3436 flush_sequence();
3437 ShowWindow(mdi_child, SW_SHOWNORMAL);
3438 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
3439
3440 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3441 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3442
3443 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3444 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3445
3446 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3447 ok(!active_child, "wrong active MDI child %p\n", active_child);
3448 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3449
3450 ShowWindow(mdi_child, SW_HIDE);
3451 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
3452 flush_sequence();
3453
3454 ShowWindow(mdi_child, SW_SHOW);
3455 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
3456
3457 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3458 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3459
3460 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3461 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3462
3463 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3464 ok(!active_child, "wrong active MDI child %p\n", active_child);
3465 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3466
3467 DestroyWindow(mdi_child);
3468 flush_sequence();
3469
3470 trace("creating visible MDI child window\n");
3471 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3472 WS_CHILD | WS_VISIBLE,
3473 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3474 mdi_client, 0, GetModuleHandleA(0), NULL);
3475 assert(mdi_child);
3476 ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
3477
3478 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3479 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3480
3481 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3482 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3483
3484 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3485 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3486 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3487 flush_sequence();
3488
3489 DestroyWindow(mdi_child);
3490 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3491
3492 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3493 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3494
3495 /* Win2k: MDI client still returns a just destroyed child as active
3496 * Win9x: MDI client returns 0
3497 */
3498 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3499 ok(active_child == mdi_child || /* win2k */
3500 !active_child, /* win9x */
3501 "wrong active MDI child %p\n", active_child);
3502 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3503
3504 flush_sequence();
3505
3506 trace("creating invisible MDI child window\n");
3507 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3508 WS_CHILD,
3509 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3510 mdi_client, 0, GetModuleHandleA(0), NULL);
3511 assert(mdi_child2);
3512 ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
3513
3514 ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
3515 ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
3516
3517 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3518 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3519
3520 /* Win2k: MDI client still returns a just destroyed child as active
3521 * Win9x: MDI client returns mdi_child2
3522 */
3523 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3524 ok(active_child == mdi_child || /* win2k */
3525 active_child == mdi_child2, /* win9x */
3526 "wrong active MDI child %p\n", active_child);
3527 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3528 flush_sequence();
3529
3530 ShowWindow(mdi_child2, SW_MAXIMIZE);
3531 ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3532
3533 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3534 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3535
3536 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3537 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3538 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3539 flush_sequence();
3540
3541 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3542 ok(GetFocus() == mdi_child2 || /* win2k */
3543 GetFocus() == 0, /* win9x */
3544 "wrong focus window %p\n", GetFocus());
3545
3546 SetFocus(0);
3547 flush_sequence();
3548
3549 ShowWindow(mdi_child2, SW_HIDE);
3550 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3551
3552 ShowWindow(mdi_child2, SW_RESTORE);
3553 ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3554 flush_sequence();
3555
3556 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3557 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3558
3559 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3560 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3561 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3562 flush_sequence();
3563
3564 SetFocus(0);
3565 flush_sequence();
3566
3567 ShowWindow(mdi_child2, SW_HIDE);
3568 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3569
3570 ShowWindow(mdi_child2, SW_SHOW);
3571 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3572
3573 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3574 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3575
3576 ShowWindow(mdi_child2, SW_MAXIMIZE);
3577 ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3578
3579 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3580 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3581
3582 ShowWindow(mdi_child2, SW_RESTORE);
3583 ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3584
3585 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3586 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3587
3588 ShowWindow(mdi_child2, SW_MINIMIZE);
3589 ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3590
3591 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3592 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3593
3594 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3595 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3596 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3597 flush_sequence();
3598
3599 ShowWindow(mdi_child2, SW_RESTORE);
3600 ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", FALSE);
3601
3602 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3603 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3604
3605 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3606 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3607 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3608 flush_sequence();
3609
3610 SetFocus(0);
3611 flush_sequence();
3612
3613 ShowWindow(mdi_child2, SW_HIDE);
3614 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3615
3616 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3617 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3618
3619 DestroyWindow(mdi_child2);
3620 ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3621
3622 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3623 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3624
3625 /* test for maximized MDI children */
3626 trace("creating maximized visible MDI child window 1\n");
3627 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3628 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3629 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3630 mdi_client, 0, GetModuleHandleA(0), NULL);
3631 assert(mdi_child);
3632 ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3633 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3634
3635 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3636 ok(GetFocus() == mdi_child || /* win2k */
3637 GetFocus() == 0, /* win9x */
3638 "wrong focus window %p\n", GetFocus());
3639
3640 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3641 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3642 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3643 flush_sequence();
3644
3645 trace("creating maximized visible MDI child window 2\n");
3646 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3647 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3648 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3649 mdi_client, 0, GetModuleHandleA(0), NULL);
3650 assert(mdi_child2);
3651 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3652 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3653 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3654
3655 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3656 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3657
3658 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3659 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3660 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3661 flush_sequence();
3662
3663 trace("destroying maximized visible MDI child window 2\n");
3664 DestroyWindow(mdi_child2);
3665 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3666
3667 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3668
3669 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3670 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3671
3672 /* Win2k: MDI client still returns a just destroyed child as active
3673 * Win9x: MDI client returns 0
3674 */
3675 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3676 ok(active_child == mdi_child2 || /* win2k */
3677 !active_child, /* win9x */
3678 "wrong active MDI child %p\n", active_child);
3679 flush_sequence();
3680
3681 ShowWindow(mdi_child, SW_MAXIMIZE);
3682 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3683 flush_sequence();
3684
3685 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3686 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3687
3688 trace("re-creating maximized visible MDI child window 2\n");
3689 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3690 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3691 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3692 mdi_client, 0, GetModuleHandleA(0), NULL);
3693 assert(mdi_child2);
3694 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3695 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3696 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3697
3698 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3699 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3700
3701 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3702 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3703 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3704 flush_sequence();
3705
3706 SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3707 ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3708 ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3709
3710 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3711 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3712 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3713
3714 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3715 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3716 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3717 flush_sequence();
3718
3719 DestroyWindow(mdi_child);
3720 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3721
3722 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3723 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3724
3725 /* Win2k: MDI client still returns a just destroyed child as active
3726 * Win9x: MDI client returns 0
3727 */
3728 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3729 ok(active_child == mdi_child || /* win2k */
3730 !active_child, /* win9x */
3731 "wrong active MDI child %p\n", active_child);
3732 flush_sequence();
3733
3734 trace("creating maximized invisible MDI child window\n");
3735 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3736 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3737 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3738 mdi_client, 0, GetModuleHandleA(0), NULL);
3739 assert(mdi_child2);
3740 ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", FALSE);
3741 ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3742 ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3743 ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3744
3745 /* Win2k: MDI client still returns a just destroyed child as active
3746 * Win9x: MDI client returns 0
3747 */
3748 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3749 ok(active_child == mdi_child || /* win2k */
3750 !active_child || active_child == mdi_child2, /* win9x */
3751 "wrong active MDI child %p\n", active_child);
3752 flush_sequence();
3753
3754 trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3755 ShowWindow(mdi_child2, SW_MAXIMIZE);
3756 ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3757 ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3758 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3759 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3760
3761 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3762 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3763 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3764 flush_sequence();
3765
3766 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3767 flush_sequence();
3768
3769 /* end of test for maximized MDI children */
3770 SetFocus(0);
3771 flush_sequence();
3772 trace("creating maximized visible MDI child window 1(Switch test)\n");
3773 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3774 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3775 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3776 mdi_client, 0, GetModuleHandleA(0), NULL);
3777 assert(mdi_child);
3778 ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3779 ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3780
3781 ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3782 ok(GetFocus() == mdi_child || /* win2k */
3783 GetFocus() == 0, /* win9x */
3784 "wrong focus window %p(Switch test)\n", GetFocus());
3785
3786 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3787 ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3788 ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3789 flush_sequence();
3790
3791 trace("creating maximized visible MDI child window 2(Switch test)\n");
3792 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3793 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3794 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3795 mdi_client, 0, GetModuleHandleA(0), NULL);
3796 assert(mdi_child2);
3797 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3798
3799 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3800 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3801
3802 ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3803 ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3804
3805 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3806 ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3807 ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3808 flush_sequence();
3809
3810 trace("Switch child window.\n");
3811 SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3812 ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3813 trace("end of test for switch maximized MDI children\n");
3814 flush_sequence();
3815
3816 /* Prepare for switching test of not maximized MDI children */
3817 ShowWindow( mdi_child, SW_NORMAL );
3818 ok(!IsZoomed(mdi_child), "wrong zoomed state for %p(Switch test)\n", mdi_child);
3819 ok(!IsZoomed(mdi_child2), "wrong zoomed state for %p(Switch test)\n", mdi_child2);
3820 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
3821 ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3822 flush_sequence();
3823
3824 SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child2, 0);
3825 ok_sequence(WmSwitchNotMaximizedChild, "Not maximized child did not switch correctly", FALSE);
3826 trace("end of test for switch not maximized MDI children\n");
3827 flush_sequence();
3828
3829 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3830 flush_sequence();
3831
3832 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3833 flush_sequence();
3834
3835 SetFocus(0);
3836 flush_sequence();
3837 /* end of tests for switch maximized/not maximized MDI children */
3838
3839 mdi_cs.szClass = "MDI_child_Class";
3840 mdi_cs.szTitle = "MDI child";
3841 mdi_cs.hOwner = GetModuleHandleA(0);
3842 mdi_cs.x = 0;
3843 mdi_cs.y = 0;
3844 mdi_cs.cx = CW_USEDEFAULT;
3845 mdi_cs.cy = CW_USEDEFAULT;
3846 mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3847 mdi_cs.lParam = 0;
3848 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3849 ok(mdi_child != 0, "MDI child creation failed\n");
3850 ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3851
3852 ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3853
3854 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3855 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3856
3857 ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3858 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3859 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3860
3861 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3862 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3863 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3864 flush_sequence();
3865
3866 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3867 ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3868
3869 ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3870 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3871 ok(!active_child, "wrong active MDI child %p\n", active_child);
3872
3873 SetFocus(0);
3874 flush_sequence();
3875
3876 DestroyWindow(mdi_client);
3877 ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3878
3879 /* test maximization of MDI child with invisible parent */
3880 client_cs.hWindowMenu = 0;
3881 mdi_client = CreateWindow("MDI_client_class",
3882 NULL,
3883 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3884 0, 0, 660, 430,
3885 mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3886 ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3887
3888 ShowWindow(mdi_client, SW_HIDE);
3889 ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3890
3891 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3892 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3893 0, 0, 650, 440,
3894 mdi_client, 0, GetModuleHandleA(0), NULL);
3895 ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3896
3897 SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3898 ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3899 zoomed = IsZoomed(mdi_child);
3900 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3901
3902 ShowWindow(mdi_client, SW_SHOW);
3903 ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3904
3905 DestroyWindow(mdi_child);
3906 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3907
3908 /* end of test for maximization of MDI child with invisible parent */
3909
3910 DestroyWindow(mdi_client);
3911 ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3912
3913 DestroyWindow(mdi_frame);
3914 ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3915 }
3916 /************************* End of MDI test **********************************/
3917
3918 static void test_WM_SETREDRAW(HWND hwnd)
3919 {
3920 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3921
3922 flush_events();
3923 flush_sequence();
3924
3925 SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3926 ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3927
3928 ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3929 ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3930
3931 flush_sequence();
3932 SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3933 ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3934
3935 ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3936 ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3937
3938 /* restore original WS_VISIBLE state */
3939 SetWindowLongA(hwnd, GWL_STYLE, style);
3940
3941 flush_events();
3942 flush_sequence();
3943 }
3944
3945 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3946 {
3947 struct recvd_message msg;
3948
3949 if (ignore_message( message )) return 0;
3950
3951 switch (message)
3952 {
3953 /* ignore */
3954 case WM_MOUSEMOVE:
3955 case WM_NCMOUSEMOVE:
3956 case WM_NCMOUSELEAVE:
3957 case WM_SETCURSOR:
3958 return 0;
3959 case WM_NCHITTEST:
3960 return HTCLIENT;
3961 }
3962
3963 msg.hwnd = hwnd;
3964 msg.message = message;
3965 msg.flags = sent|wparam|lparam;
3966 msg.wParam = wParam;
3967 msg.lParam = lParam;
3968 msg.descr = "dialog";
3969 add_message(&msg);
3970
3971 if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3972 if (message == WM_TIMER) EndDialog( hwnd, 0 );
3973 return 0;
3974 }
3975
3976 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3977 {
3978 DWORD style, exstyle;
3979 INT xmin, xmax;
3980 BOOL ret;
3981
3982 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3983 style = GetWindowLongA(hwnd, GWL_STYLE);
3984 /* do not be confused by WS_DLGFRAME set */
3985 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3986
3987 if (clear) ok(style & clear, "style %08x should be set\n", clear);
3988 if (set) ok(!(style & set), "style %08x should not be set\n", set);
3989
3990 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3991 ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3992 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3993 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3994 else
3995 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3996
3997 style = GetWindowLongA(hwnd, GWL_STYLE);
3998 if (set) ok(style & set, "style %08x should be set\n", set);
3999 if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
4000
4001 /* a subsequent call should do nothing */
4002 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
4003 ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
4004 ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
4005
4006 xmin = 0xdeadbeef;
4007 xmax = 0xdeadbeef;
4008 ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
4009 ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
4010 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
4011 ok(xmin == min, "unexpected min scroll value %d\n", xmin);
4012 ok(xmax == max, "unexpected max scroll value %d\n", xmax);
4013 }
4014
4015 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
4016 {
4017 DWORD style, exstyle;
4018 SCROLLINFO si;
4019 BOOL ret;
4020
4021 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
4022 style = GetWindowLongA(hwnd, GWL_STYLE);
4023 /* do not be confused by WS_DLGFRAME set */
4024 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
4025
4026 if (clear) ok(style & clear, "style %08x should be set\n", clear);
4027 if (set) ok(!(style & set), "style %08x should not be set\n", set);
4028
4029 si.cbSize = sizeof(si);
4030 si.fMask = SIF_RANGE;
4031 si.nMin = min;
4032 si.nMax = max;
4033 SetScrollInfo(hwnd, ctl, &si, TRUE);
4034 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
4035 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
4036 else
4037 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
4038
4039 style = GetWindowLongA(hwnd, GWL_STYLE);
4040 if (set) ok(style & set, "style %08x should be set\n", set);
4041 if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
4042
4043 /* a subsequent call should do nothing */
4044 SetScrollInfo(hwnd, ctl, &si, TRUE);
4045 if (style & WS_HSCROLL)
4046 ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4047 else if (style & WS_VSCROLL)
4048 ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4049 else
4050 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4051
4052 si.fMask = SIF_PAGE;
4053 si.nPage = 5;
4054 SetScrollInfo(hwnd, ctl, &si, FALSE);
4055 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4056
4057 si.fMask = SIF_POS;
4058 si.nPos = max - 1;
4059 SetScrollInfo(hwnd, ctl, &si, FALSE);
4060 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4061
4062 si.fMask = SIF_RANGE;
4063 si.nMin = 0xdeadbeef;
4064 si.nMax = 0xdeadbeef;
4065 ret = GetScrollInfo(hwnd, ctl, &si);
4066 ok( ret, "GetScrollInfo error %d\n", GetLastError());
4067 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
4068 ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
4069 ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
4070 }
4071
4072 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
4073 static void test_scroll_messages(HWND hwnd)
4074 {
4075 SCROLLINFO si;
4076 INT min, max;
4077 BOOL ret;
4078
4079 flush_events();
4080 flush_sequence();
4081
4082 min = 0xdeadbeef;
4083 max = 0xdeadbeef;
4084 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4085 ok( ret, "GetScrollRange error %d\n", GetLastError());
4086 if (sequence->message != WmGetScrollRangeSeq[0].message)
4087 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4088 /* values of min and max are undefined */
4089 flush_sequence();
4090
4091 ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
4092 ok( ret, "SetScrollRange error %d\n", GetLastError());
4093 if (sequence->message != WmSetScrollRangeSeq[0].message)
4094 trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4095 flush_sequence();
4096
4097 min = 0xdeadbeef;
4098 max = 0xdeadbeef;
4099 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4100 ok( ret, "GetScrollRange error %d\n", GetLastError());
4101 if (sequence->message != WmGetScrollRangeSeq[0].message)
4102 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4103 /* values of min and max are undefined */
4104 flush_sequence();
4105
4106 si.cbSize = sizeof(si);
4107 si.fMask = SIF_RANGE;
4108 si.nMin = 20;
4109 si.nMax = 160;
4110 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4111 if (sequence->message != WmSetScrollRangeSeq[0].message)
4112 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4113 flush_sequence();
4114
4115 si.fMask = SIF_PAGE;
4116 si.nPage = 10;
4117 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4118 if (sequence->message != WmSetScrollRangeSeq[0].message)
4119 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4120 flush_sequence();
4121
4122 si.fMask = SIF_POS;
4123 si.nPos = 20;
4124 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4125 if (sequence->message != WmSetScrollRangeSeq[0].message)
4126 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4127 flush_sequence();
4128
4129 si.fMask = SIF_RANGE;
4130 si.nMin = 0xdeadbeef;
4131 si.nMax = 0xdeadbeef;
4132 ret = GetScrollInfo(hwnd, SB_CTL, &si);
4133 ok( ret, "GetScrollInfo error %d\n", GetLastError());
4134 if (sequence->message != WmGetScrollInfoSeq[0].message)
4135 trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4136 /* values of min and max are undefined */
4137 flush_sequence();
4138
4139 /* set WS_HSCROLL */
4140 test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4141 /* clear WS_HSCROLL */
4142 test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4143
4144 /* set WS_HSCROLL */
4145 test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4146 /* clear WS_HSCROLL */
4147 test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4148
4149 /* set WS_VSCROLL */
4150 test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4151 /* clear WS_VSCROLL */
4152 test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4153
4154 /* set WS_VSCROLL */
4155 test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4156 /* clear WS_VSCROLL */
4157 test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4158 }
4159
4160 static void test_showwindow(void)
4161 {
4162 HWND hwnd, hchild;
4163 RECT rc;
4164
4165 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4166 100, 100, 200, 200, 0, 0, 0, NULL);
4167 ok (hwnd != 0, "Failed to create overlapped window\n");
4168 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4169 0, 0, 10, 10, hwnd, 0, 0, NULL);
4170 ok (hchild != 0, "Failed to create child\n");
4171 flush_sequence();
4172
4173 /* ShowWindow( SW_SHOWNA) for invisible top level window */
4174 trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
4175 ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4176 ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", FALSE);
4177
4178 /* ShowWindow( SW_SHOWNA) for now visible top level window */
4179 trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
4180 ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4181 ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
4182 /* back to invisible */
4183 ShowWindow(hchild, SW_HIDE);
4184 ShowWindow(hwnd, SW_HIDE);
4185 flush_sequence();
4186 /* ShowWindow(SW_SHOWNA) with child and parent invisible */
4187 trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
4188 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4189 ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
4190 /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */
4191 ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
4192 flush_sequence();
4193 trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
4194 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4195 ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
4196 /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
4197 ShowWindow( hwnd, SW_SHOW);
4198 flush_sequence();
4199 trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
4200 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4201 ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
4202
4203 /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
4204 ShowWindow( hchild, SW_HIDE);
4205 flush_sequence();
4206 trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
4207 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4208 ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
4209
4210 SetCapture(hchild);
4211 ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
4212 DestroyWindow(hchild);
4213 ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
4214
4215 DestroyWindow(hwnd);
4216 flush_sequence();
4217
4218 /* Popup windows */
4219 /* Test 1:
4220 * 1. Create invisible maximized popup window.
4221 * 2. Move and resize it.
4222 * 3. Show it maximized.
4223 */
4224 trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4225 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4226 100, 100, 200, 200, 0, 0, 0, NULL);
4227 ok (hwnd != 0, "Failed to create popup window\n");
4228 ok(IsZoomed(hwnd), "window should be maximized\n");
4229 ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4230
4231 GetWindowRect(hwnd, &rc);
4232 ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4233 rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4234 "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
4235 rc.left, rc.top, rc.right, rc.bottom);
4236 /* Reset window's size & position */
4237 SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
4238 ok(IsZoomed(hwnd), "window should be maximized\n");
4239 flush_sequence();
4240
4241 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4242 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4243 ok(IsZoomed(hwnd), "window should be maximized\n");
4244 ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
4245
4246 GetWindowRect(hwnd, &rc);
4247 ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4248 rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4249 "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
4250 rc.left, rc.top, rc.right, rc.bottom);
4251 DestroyWindow(hwnd);
4252 flush_sequence();
4253
4254 /* Test 2:
4255 * 1. Create invisible maximized popup window.
4256 * 2. Show it maximized.
4257 */
4258 trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4259 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4260 100, 100, 200, 200, 0, 0, 0, NULL);
4261 ok (hwnd != 0, "Failed to create popup window\n");
4262 ok(IsZoomed(hwnd), "window should be maximized\n");
4263 ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4264
4265 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4266 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4267 ok(IsZoomed(hwnd), "window should be maximized\n");
4268 ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
4269 DestroyWindow(hwnd);
4270 flush_sequence();
4271
4272 /* Test 3:
4273 * 1. Create visible maximized popup window.
4274 */
4275 trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
4276 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4277 100, 100, 200, 200, 0, 0, 0, NULL);
4278 ok (hwnd != 0, "Failed to create popup window\n");
4279 ok(IsZoomed(hwnd), "window should be maximized\n");
4280 ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4281 DestroyWindow(hwnd);
4282 flush_sequence();
4283
4284 /* Test 4:
4285 * 1. Create visible popup window.
4286 * 2. Maximize it.
4287 */
4288 trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
4289 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
4290 100, 100, 200, 200, 0, 0, 0, NULL);
4291 ok (hwnd != 0, "Failed to create popup window\n");
4292 ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
4293 ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
4294
4295 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
4296 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4297 ok(IsZoomed(hwnd), "window should be maximized\n");
4298 ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
4299 DestroyWindow(hwnd);
4300 flush_sequence();
4301 }
4302
4303 static void test_sys_menu(void)
4304 {
4305 HWND hwnd;
4306 HMENU hmenu;
4307 UINT state;
4308
4309 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4310 100, 100, 200, 200, 0, 0, 0, NULL);
4311 ok (hwnd != 0, "Failed to create overlapped window\n");
4312
4313 flush_sequence();
4314
4315 /* test existing window without CS_NOCLOSE style */
4316 hmenu = GetSystemMenu(hwnd, FALSE);
4317 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4318
4319 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4320 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4321 ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4322
4323 EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
4324 ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4325
4326 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4327 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4328 ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
4329
4330 EnableMenuItem(hmenu, SC_CLOSE, 0);
4331 ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4332
4333 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4334 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4335 ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4336
4337 /* test whether removing WS_SYSMENU destroys a system menu */
4338 SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
4339 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4340 flush_sequence();
4341 hmenu = GetSystemMenu(hwnd, FALSE);
4342 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4343
4344 DestroyWindow(hwnd);
4345
4346 /* test new window with CS_NOCLOSE style */
4347 hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4348 100, 100, 200, 200, 0, 0, 0, NULL);
4349 ok (hwnd != 0, "Failed to create overlapped window\n");
4350
4351 hmenu = GetSystemMenu(hwnd, FALSE);
4352 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4353
4354 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4355 ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4356
4357 DestroyWindow(hwnd);
4358
4359 /* test new window without WS_SYSMENU style */
4360 hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
4361 100, 100, 200, 200, 0, 0, 0, NULL);
4362 ok(hwnd != 0, "Failed to create overlapped window\n");
4363
4364 hmenu = GetSystemMenu(hwnd, FALSE);
4365 ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
4366
4367 DestroyWindow(hwnd);
4368 }
4369
4370 /* For shown WS_OVERLAPPEDWINDOW */
4371 static const struct message WmSetIcon_1[] = {
4372 { WM_SETICON, sent },
4373 { 0x00AE, sent|defwinproc|optional }, /* XP */
4374 { WM_GETTEXT, sent|defwinproc|optional },
4375 { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
4376 { 0 }
4377 };
4378
4379 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
4380 static const struct message WmSetIcon_2[] = {
4381 { WM_SETICON, sent },
4382 { 0 }
4383 };
4384
4385 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4386 static const struct message WmInitEndSession[] = {
4387 { 0x003B, sent },
4388 { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4389 { 0 }
4390 };
4391
4392 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4393 static const struct message WmInitEndSession_2[] = {
4394 { 0x003B, sent },
4395 { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4396 { 0 }
4397 };
4398
4399 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4400 static const struct message WmInitEndSession_3[] = {
4401 { 0x003B, sent },
4402 { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4403 { 0 }
4404 };
4405
4406 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4407 static const struct message WmInitEndSession_4[] = {
4408 { 0x003B, sent },
4409 { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4410 { 0 }
4411 };
4412
4413 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4414 static const struct message WmInitEndSession_5[] = {
4415 { 0x003B, sent },
4416 { WM_ENDSESSION, sent|defwinproc/*|wparam*/|lparam, 1, ENDSESSION_LOGOFF },
4417 { 0 }
4418 };
4419
4420 static const struct message WmOptionalPaint[] = {
4421 { WM_PAINT, sent|optional },
4422 { WM_NCPAINT, sent|beginpaint|optional },
4423 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4424 { WM_ERASEBKGND, sent|beginpaint|optional },
4425 { 0 }
4426 };
4427
4428 static const struct message WmZOrder[] = {
4429 { WM_WINDOWPOSCHANGING, sent|wparam, 0, 0 },
4430 { WM_GETMINMAXINFO, sent|defwinproc|wparam, 0, 0 },
4431 { HCBT_ACTIVATE, hook },
4432 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
4433 { WM_WINDOWPOSCHANGING, sent|wparam, 3, 0 },
4434 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0 },
4435 { WM_GETTEXT, sent|optional },
4436 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
4437 { WM_ACTIVATEAPP, sent|wparam, 1, 0 },
4438 { WM_NCACTIVATE, sent|lparam, 1, 0 },
4439 { WM_GETTEXT, sent|defwinproc|optional },
4440 { WM_GETTEXT, sent|defwinproc|optional },
4441 { WM_ACTIVATE, sent|wparam|lparam, 1, 0 },
4442 { HCBT_SETFOCUS, hook },
4443 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4444 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4445 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4446 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
4447 { WM_GETTEXT, sent|optional },
4448 { WM_NCCALCSIZE, sent|optional },
4449 { 0 }
4450 };
4451
4452 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4453 {
4454 DWORD ret;
4455 MSG msg;
4456
4457 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4458 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4459
4460 PostMessageA(hwnd, WM_USER, 0, 0);
4461
4462 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4463 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4464
4465 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4466 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4467
4468 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4469 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4470
4471 PostMessageA(hwnd, WM_USER, 0, 0);
4472
4473 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4474 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4475
4476 ok(PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4477 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4478
4479 /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4480 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4481 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4482
4483 PostMessageA(hwnd, WM_USER, 0, 0);
4484
4485 /* new incoming message causes it to become signaled again */
4486 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4487 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4488
4489 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4490 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4491 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4492 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4493 }
4494
4495 /* test if we receive the right sequence of messages */
4496 static void test_messages(void)
4497 {
4498 HWND hwnd, hparent, hchild;
4499 HWND hchild2, hbutton;
4500 HMENU hmenu;
4501 MSG msg;
4502 LRESULT res;
4503
4504 flush_sequence();
4505
4506 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4507 100, 100, 200, 200, 0, 0, 0, NULL);
4508 ok (hwnd != 0, "Failed to create overlapped window\n");
4509 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4510
4511 /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4512 ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4513 ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4514
4515 /* test WM_SETREDRAW on a not visible top level window */
4516 test_WM_SETREDRAW(hwnd);
4517
4518 SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4519 flush_events();
4520 ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4521 ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4522
4523 ok(GetActiveWindow() == hwnd, "window should be active\n");
4524 ok(GetFocus() == hwnd, "window should have input focus\n");
4525 ShowWindow(hwnd, SW_HIDE);
4526 flush_events();
4527 ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4528
4529 ShowWindow(hwnd, SW_SHOW);
4530 flush_events();
4531 ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4532
4533 ShowWindow(hwnd, SW_HIDE);
4534 flush_events();
4535 ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4536
4537 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4538 flush_events();
4539 ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4540 flush_sequence();
4541
4542 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MAXIMIZE)
4543 {
4544 ShowWindow(hwnd, SW_RESTORE);
4545 flush_events();
4546 ok_sequence(WmShowRestoreMaxOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4547 flush_sequence();
4548 }
4549
4550 ShowWindow(hwnd, SW_MINIMIZE);
4551 flush_events();
4552 ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4553 flush_sequence();
4554
4555 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MINIMIZE)
4556 {
4557 ShowWindow(hwnd, SW_RESTORE);
4558 flush_events();
4559 ok_sequence(WmShowRestoreMinOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4560 flush_sequence();
4561 }
4562
4563 ShowWindow(hwnd, SW_SHOW);
4564 flush_events();
4565 ok_sequence(WmOptionalPaint, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4566
4567 SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4568 ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4569 ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4570 ok(GetActiveWindow() == hwnd, "window should still be active\n");
4571
4572 /* test WM_SETREDRAW on a visible top level window */
4573 ShowWindow(hwnd, SW_SHOW);
4574 flush_events();
4575 test_WM_SETREDRAW(hwnd);
4576
4577 trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4578 test_scroll_messages(hwnd);
4579
4580 /* test resizing and moving */
4581 SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4582 ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4583 flush_events();
4584 flush_sequence();
4585 SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4586 ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4587 flush_events();
4588 flush_sequence();
4589 SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER|SWP_NOACTIVATE );
4590 ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4591 flush_events();
4592 flush_sequence();
4593
4594 /* popups don't get WM_GETMINMAXINFO */
4595 SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4596 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4597 flush_sequence();
4598 SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4599 ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4600
4601 DestroyWindow(hwnd);
4602 ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4603
4604 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4605 100, 100, 200, 200, 0, 0, 0, NULL);
4606 ok (hparent != 0, "Failed to create parent window\n");
4607 flush_sequence();
4608
4609 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4610 0, 0, 10, 10, hparent, 0, 0, NULL);
4611 ok (hchild != 0, "Failed to create child window\n");
4612 ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4613 DestroyWindow(hchild);
4614 flush_sequence();
4615
4616 /* visible child window with a caption */
4617 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4618 WS_CHILD | WS_VISIBLE | WS_CAPTION,
4619 0, 0, 10, 10, hparent, 0, 0, NULL);
4620 ok (hchild != 0, "Failed to create child window\n");
4621 ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4622
4623 trace("testing scroll APIs on a visible child window %p\n", hchild);
4624 test_scroll_messages(hchild);
4625
4626 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4627 ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4628
4629 DestroyWindow(hchild);
4630 flush_sequence();
4631
4632 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4633 0, 0, 10, 10, hparent, 0, 0, NULL);
4634 ok (hchild != 0, "Failed to create child window\n");
4635 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4636
4637 hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4638 100, 100, 50, 50, hparent, 0, 0, NULL);
4639 ok (hchild2 != 0, "Failed to create child2 window\n");
4640 flush_sequence();
4641
4642 hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4643 0, 100, 50, 50, hchild, 0, 0, NULL);
4644 ok (hbutton != 0, "Failed to create button window\n");
4645
4646 /* test WM_SETREDRAW on a not visible child window */
4647 test_WM_SETREDRAW(hchild);
4648
4649 ShowWindow(hchild, SW_SHOW);
4650 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4651
4652 /* check parent messages too */
4653 log_all_parent_messages++;
4654 ShowWindow(hchild, SW_HIDE);
4655 ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4656 log_all_parent_messages--;
4657
4658 ShowWindow(hchild, SW_SHOW);
4659 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4660
4661 ShowWindow(hchild, SW_HIDE);
4662 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4663
4664 ShowWindow(hchild, SW_SHOW);
4665 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4666
4667 /* test WM_SETREDRAW on a visible child window */
4668 test_WM_SETREDRAW(hchild);
4669
4670 log_all_parent_messages++;
4671 MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4672 ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4673 log_all_parent_messages--;
4674
4675 ShowWindow(hchild, SW_HIDE);
4676 flush_sequence();
4677 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4678 ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4679
4680 ShowWindow(hchild, SW_HIDE);
4681 flush_sequence();
4682 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4683 ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4684
4685 /* DestroyWindow sequence below expects that a child has focus */
4686 SetFocus(hchild);
4687 flush_sequence();
4688
4689 DestroyWindow(hchild);
4690 ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4691 DestroyWindow(hchild2);
4692 DestroyWindow(hbutton);
4693
4694 flush_sequence();
4695 hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4696 0, 0, 100, 100, hparent, 0, 0, NULL);
4697 ok (hchild != 0, "Failed to create child popup window\n");
4698 ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4699 DestroyWindow(hchild);
4700
4701 /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4702 flush_sequence();
4703 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4704 0, 0, 100, 100, hparent, 0, 0, NULL);
4705 ok (hchild != 0, "Failed to create popup window\n");
4706 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4707 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4708 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4709 flush_sequence();
4710 ShowWindow(hchild, SW_SHOW);
4711 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4712 flush_sequence();
4713 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4714 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4715 flush_sequence();
4716 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4717 ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
4718 DestroyWindow(hchild);
4719
4720 /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4721 * changes nothing in message sequences.
4722 */
4723 flush_sequence();
4724 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4725 0, 0, 100, 100, hparent, 0, 0, NULL);
4726 ok (hchild != 0, "Failed to create popup window\n");
4727 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4728 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4729 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4730 flush_sequence();
4731 ShowWindow(hchild, SW_SHOW);
4732 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4733 flush_sequence();
4734 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4735 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4736 DestroyWindow(hchild);
4737
4738 flush_sequence();
4739 hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4740 0, 0, 100, 100, hparent, 0, 0, NULL);
4741 ok(hwnd != 0, "Failed to create custom dialog window\n");
4742 ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4743
4744 if(0) {
4745 trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4746 test_scroll_messages(hwnd);
4747 }
4748
4749 flush_sequence();
4750
4751 test_def_id = 1;
4752 SendMessage(hwnd, WM_NULL, 0, 0);
4753
4754 flush_sequence();
4755 after_end_dialog = 1;
4756 EndDialog( hwnd, 0 );
4757 ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4758
4759 DestroyWindow(hwnd);
4760 after_end_dialog = 0;
4761 test_def_id = 0;
4762
4763 hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4764 0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4765 ok(hwnd != 0, "Failed to create custom dialog window\n");
4766 flush_sequence();
4767 trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4768 ShowWindow(hwnd, SW_SHOW);
4769 ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4770 DestroyWindow(hwnd);
4771
4772 flush_sequence();
4773 DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4774 ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4775
4776 DestroyWindow(hparent);
4777 flush_sequence();
4778
4779 /* Message sequence for SetMenu */
4780 ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4781 ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4782
4783 hmenu = CreateMenu();
4784 ok (hmenu != 0, "Failed to create menu\n");
4785 ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4786 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4787 100, 100, 200, 200, 0, hmenu, 0, NULL);
4788 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4789 ok (SetMenu(hwnd, 0), "SetMenu\n");
4790 ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4791 ok (SetMenu(hwnd, 0), "SetMenu\n");
4792 ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4793 ShowWindow(hwnd, SW_SHOW);
4794 UpdateWindow( hwnd );
4795 flush_events();
4796 flush_sequence();
4797 ok (SetMenu(hwnd, 0), "SetMenu\n");
4798 ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4799 ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4800 ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4801
4802 UpdateWindow( hwnd );
4803 flush_events();
4804 flush_sequence();
4805 ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4806 flush_events();
4807 ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4808
4809 DestroyWindow(hwnd);
4810 flush_sequence();
4811
4812 /* Message sequence for EnableWindow */
4813 hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4814 100, 100, 200, 200, 0, 0, 0, NULL);
4815 ok (hparent != 0, "Failed to create parent window\n");
4816 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4817 0, 0, 10, 10, hparent, 0, 0, NULL);
4818 ok (hchild != 0, "Failed to create child window\n");
4819
4820 SetFocus(hchild);
4821 flush_events();
4822 flush_sequence();
4823
4824 EnableWindow(hparent, FALSE);
4825 ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4826
4827 EnableWindow(hparent, TRUE);
4828 ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4829
4830 flush_events();
4831 flush_sequence();
4832
4833 test_MsgWaitForMultipleObjects(hparent);
4834
4835 /* the following test causes an exception in user.exe under win9x */
4836 if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4837 {
4838 DestroyWindow(hparent);
4839 flush_sequence();
4840 return;
4841 }
4842 PostMessageW( hparent, WM_USER+1, 0, 0 );
4843 /* PeekMessage(NULL) fails, but still removes the message */
4844 SetLastError(0xdeadbeef);
4845 ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4846 ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4847 GetLastError() == 0xdeadbeef, /* NT4 */
4848 "last error is %d\n", GetLastError() );
4849 ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4850 ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4851
4852 DestroyWindow(hchild);
4853 DestroyWindow(hparent);
4854 flush_sequence();
4855
4856 /* Message sequences for WM_SETICON */
4857 trace("testing WM_SETICON\n");
4858 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4859 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4860 NULL, NULL, 0);
4861 ShowWindow(hwnd, SW_SHOW);
4862 UpdateWindow(hwnd);
4863 flush_events();
4864 flush_sequence();
4865 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4866 ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4867
4868 ShowWindow(hwnd, SW_HIDE);
4869 flush_events();
4870 flush_sequence();
4871 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4872 ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4873 DestroyWindow(hwnd);
4874 flush_sequence();
4875
4876 hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4877 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4878 NULL, NULL, 0);
4879 ShowWindow(hwnd, SW_SHOW);
4880 UpdateWindow(hwnd);
4881 flush_events();
4882 flush_sequence();
4883 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4884 ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4885
4886 ShowWindow(hwnd, SW_HIDE);
4887 flush_events();
4888 flush_sequence();
4889 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4890 ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4891
4892 flush_sequence();
4893 res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4894 if (!res)
4895 {
4896 todo_wine win_skip( "Message 0x3b not supported\n" );
4897 goto done;
4898 }
4899 ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4900 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4901 res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4902 ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4903 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4904 res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4905 ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4906 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4907
4908 flush_sequence();
4909 res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4910 ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4911 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4912 res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4913 ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4914 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4915
4916 res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4917 ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4918 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4919
4920 res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4921 ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4922 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4923
4924 done:
4925 DestroyWindow(hwnd);
4926 flush_sequence();
4927 }
4928
4929 static void test_setwindowpos(void)
4930 {
4931 HWND hwnd;
4932 RECT rc;
4933 LRESULT res;
4934 const INT winX = 100;
4935 const INT winY = 100;
4936 const INT sysX = GetSystemMetrics(SM_CXMINTRACK);
4937
4938 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
4939 0, 0, winX, winY, 0,
4940 NULL, NULL, 0);
4941
4942 GetWindowRect(hwnd, &rc);
4943 expect(sysX, rc.right);
4944 expect(winY, rc.bottom);
4945
4946 flush_events();
4947 flush_sequence();
4948 res = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, winX, winY, 0);
4949 ok_sequence(WmZOrder, "Z-Order", TRUE);
4950 ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
4951
4952 GetWindowRect(hwnd, &rc);
4953 expect(sysX, rc.right);
4954 expect(winY, rc.bottom);
4955 DestroyWindow(hwnd);
4956 }
4957
4958 static void invisible_parent_tests(void)
4959 {
4960 HWND hparent, hchild;
4961
4962 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4963 100, 100, 200, 200, 0, 0, 0, NULL);
4964 ok (hparent != 0, "Failed to create parent window\n");
4965 flush_sequence();
4966
4967 /* test showing child with hidden parent */
4968
4969 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4970 0, 0, 10, 10, hparent, 0, 0, NULL);
4971 ok (hchild != 0, "Failed to create child window\n");
4972 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4973
4974 ShowWindow( hchild, SW_MINIMIZE );
4975 ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4976 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4977 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4978
4979 /* repeat */
4980 flush_events();
4981 flush_sequence();
4982 ShowWindow( hchild, SW_MINIMIZE );
4983 ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4984
4985 DestroyWindow(hchild);
4986 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4987 0, 0, 10, 10, hparent, 0, 0, NULL);
4988 flush_sequence();
4989
4990 ShowWindow( hchild, SW_MAXIMIZE );
4991 ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4992 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4993 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4994
4995 /* repeat */
4996 flush_events();
4997 flush_sequence();
4998 ShowWindow( hchild, SW_MAXIMIZE );
4999 ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
5000
5001 DestroyWindow(hchild);
5002 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5003 0, 0, 10, 10, hparent, 0, 0, NULL);
5004 flush_sequence();
5005
5006 ShowWindow( hchild, SW_RESTORE );
5007 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
5008 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5009 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5010
5011 DestroyWindow(hchild);
5012 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5013 0, 0, 10, 10, hparent, 0, 0, NULL);
5014 flush_sequence();
5015
5016 ShowWindow( hchild, SW_SHOWMINIMIZED );
5017 ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
5018 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5019 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5020
5021 /* repeat */
5022 flush_events();
5023 flush_sequence();
5024 ShowWindow( hchild, SW_SHOWMINIMIZED );
5025 ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
5026
5027 DestroyWindow(hchild);
5028 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5029 0, 0, 10, 10, hparent, 0, 0, NULL);
5030 flush_sequence();
5031
5032 /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
5033 ShowWindow( hchild, SW_SHOWMAXIMIZED );
5034 ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
5035 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5036 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5037
5038 DestroyWindow(hchild);
5039 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5040 0, 0, 10, 10, hparent, 0, 0, NULL);
5041 flush_sequence();
5042
5043 ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5044 ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5045 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5046 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5047
5048 /* repeat */
5049 flush_events();
5050 flush_sequence();
5051 ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5052 ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5053
5054 DestroyWindow(hchild);
5055 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5056 0, 0, 10, 10, hparent, 0, 0, NULL);
5057 flush_sequence();
5058
5059 /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
5060 ShowWindow( hchild, SW_FORCEMINIMIZE );
5061 ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
5062 todo_wine {
5063 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5064 }
5065 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5066
5067 DestroyWindow(hchild);
5068 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5069 0, 0, 10, 10, hparent, 0, 0, NULL);
5070 flush_sequence();
5071
5072 ShowWindow( hchild, SW_SHOWNA );
5073 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5074 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5075 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5076
5077 /* repeat */
5078 flush_events();
5079 flush_sequence();
5080 ShowWindow( hchild, SW_SHOWNA );
5081 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5082
5083 DestroyWindow(hchild);
5084 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5085 0, 0, 10, 10, hparent, 0, 0, NULL);
5086 flush_sequence();
5087
5088 ShowWindow( hchild, SW_SHOW );
5089 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5090 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5091 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5092
5093 /* repeat */
5094 flush_events();
5095 flush_sequence();
5096 ShowWindow( hchild, SW_SHOW );
5097 ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5098
5099 ShowWindow( hchild, SW_HIDE );
5100 ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
5101 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5102 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5103
5104 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5105 ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
5106 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5107 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5108
5109 SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5110 ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
5111 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
5112 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5113
5114 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5115 flush_sequence();
5116 DestroyWindow(hchild);
5117 ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
5118
5119 DestroyWindow(hparent);
5120 flush_sequence();
5121 }
5122
5123 /****************** button message test *************************/
5124 #define ID_BUTTON 0x000e
5125
5126 static const struct message WmSetFocusButtonSeq[] =
5127 {
5128 { HCBT_SETFOCUS, hook },
5129 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5130 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5131 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5132 { WM_SETFOCUS, sent|wparam, 0 },
5133 { WM_CTLCOLORBTN, sent|parent },
5134 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5135 { WM_APP, sent|wparam|lparam, 0, 0 },
5136 { 0 }
5137 };
5138 static const struct message WmKillFocusButtonSeq[] =
5139 {
5140 { HCBT_SETFOCUS, hook },
5141 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5142 { WM_KILLFOCUS, sent|wparam, 0 },
5143 { WM_CTLCOLORBTN, sent|parent },
5144 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5145 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5146 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5147 { WM_APP, sent|wparam|lparam, 0, 0 },
5148 { WM_PAINT, sent },
5149 { WM_CTLCOLORBTN, sent|parent },
5150 { 0 }
5151 };
5152 static const struct message WmSetFocusStaticSeq[] =
5153 {
5154 { HCBT_SETFOCUS, hook },
5155 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5156 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5157 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5158 { WM_SETFOCUS, sent|wparam, 0 },
5159 { WM_CTLCOLORSTATIC, sent|parent },
5160 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5161 { WM_COMMAND, sent|wparam|parent|optional, MAKEWPARAM(ID_BUTTON, BN_CLICKED) }, /* radio button */
5162 { WM_APP, sent|wparam|lparam, 0, 0 },
5163 { 0 }
5164 };
5165 static const struct message WmKillFocusStaticSeq[] =
5166 {
5167 { HCBT_SETFOCUS, hook },
5168 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5169 { WM_KILLFOCUS, sent|wparam, 0 },
5170 { WM_CTLCOLORSTATIC, sent|parent },
5171 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5172 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5173 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5174 { WM_APP, sent|wparam|lparam, 0, 0 },
5175 { WM_PAINT, sent },
5176 { WM_CTLCOLORSTATIC, sent|parent },
5177 { 0 }
5178 };
5179 static const struct message WmSetFocusOwnerdrawSeq[] =
5180 {
5181 { HCBT_SETFOCUS, hook },
5182 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5183 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5184 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5185 { WM_SETFOCUS, sent|wparam, 0 },
5186 { WM_CTLCOLORBTN, sent|parent },
5187 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x001040e4 },
5188 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5189 { WM_APP, sent|wparam|lparam, 0, 0 },
5190 { 0 }
5191 };
5192 static const struct message WmKillFocusOwnerdrawSeq[] =
5193 {
5194 { HCBT_SETFOCUS, hook },
5195 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5196 { WM_KILLFOCUS, sent|wparam, 0 },
5197 { WM_CTLCOLORBTN, sent|parent },
5198 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000040e4 },
5199 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5200 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5201 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5202 { WM_APP, sent|wparam|lparam, 0, 0 },
5203 { WM_PAINT, sent },
5204 { WM_CTLCOLORBTN, sent|parent },
5205 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 },
5206 { 0 }
5207 };
5208 static const struct message WmLButtonDownSeq[] =
5209 {
5210 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
5211 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5212 { HCBT_SETFOCUS, hook },
5213 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
5214 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5215 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5216 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
5217 { WM_CTLCOLORBTN, sent|defwinproc },
5218 { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
5219 { WM_CTLCOLORBTN, sent|defwinproc },
5220 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5221 { 0 }
5222 };
5223 static const struct message WmLButtonUpSeq[] =
5224 {
5225 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
5226 { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
5227 { WM_CTLCOLORBTN, sent|defwinproc },
5228 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5229 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5230 { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
5231 { 0 }
5232 };
5233 static const struct message WmSetFontButtonSeq[] =
5234 {
5235 { WM_SETFONT, sent },
5236 { WM_PAINT, sent },
5237 { WM_ERASEBKGND, sent|defwinproc|optional },
5238 { WM_CTLCOLORBTN, sent|defwinproc },
5239 { 0 }
5240 };
5241 static const struct message WmSetStyleButtonSeq[] =
5242 {
5243 { BM_SETSTYLE, sent },
5244 { WM_APP, sent|wparam|lparam, 0, 0 },
5245 { WM_PAINT, sent },
5246 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5247 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5248 { WM_CTLCOLORBTN, sent|parent },
5249 { 0 }
5250 };
5251 static const struct message WmSetStyleStaticSeq[] =
5252 {
5253 { BM_SETSTYLE, sent },
5254 { WM_APP, sent|wparam|lparam, 0, 0 },
5255 { WM_PAINT, sent },
5256 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5257 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5258 { WM_CTLCOLORSTATIC, sent|parent },
5259 { 0 }
5260 };
5261 static const struct message WmSetStyleUserSeq[] =
5262 {
5263 { BM_SETSTYLE, sent },
5264 { WM_APP, sent|wparam|lparam, 0, 0 },
5265 { WM_PAINT, sent },
5266 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5267 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5268 { WM_CTLCOLORBTN, sent|parent },
5269 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_PAINT) },
5270 { 0 }
5271 };
5272 static const struct message WmSetStyleOwnerdrawSeq[] =
5273 {
5274 { BM_SETSTYLE, sent },
5275 { WM_APP, sent|wparam|lparam, 0, 0 },
5276 { WM_PAINT, sent },
5277 { WM_NCPAINT, sent|optional }, /* FIXME: Wine sends it */
5278 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5279 { WM_CTLCOLORBTN, sent|parent },
5280 { WM_CTLCOLORBTN, sent|parent|optional }, /* Win9x doesn't send it */
5281 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 },
5282 { 0 }
5283 };
5284 static const struct message WmSetStateButtonSeq[] =
5285 {
5286 { BM_SETSTATE, sent },
5287 { WM_CTLCOLORBTN, sent|parent },
5288 { WM_APP, sent|wparam|lparam, 0, 0 },
5289 { 0 }
5290 };
5291 static const struct message WmSetStateStaticSeq[] =
5292 {
5293 { BM_SETSTATE, sent },
5294 { WM_CTLCOLORSTATIC, sent|parent },
5295 { WM_APP, sent|wparam|lparam, 0, 0 },
5296 { 0 }
5297 };
5298 static const struct message WmSetStateUserSeq[] =
5299 {
5300 { BM_SETSTATE, sent },
5301 { WM_CTLCOLORBTN, sent|parent },
5302 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_HILITE) },
5303 { WM_APP, sent|wparam|lparam, 0, 0 },
5304 { 0 }
5305 };
5306 static const struct message WmSetStateOwnerdrawSeq[] =
5307 {
5308 { BM_SETSTATE, sent },
5309 { WM_CTLCOLORBTN, sent|parent },
5310 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000120e4 },
5311 { WM_APP, sent|wparam|lparam, 0, 0 },
5312 { 0 }
5313 };
5314 static const struct message WmClearStateButtonSeq[] =
5315 {
5316 { BM_SETSTATE, sent },
5317 { WM_CTLCOLORBTN, sent|parent },
5318 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_UNHILITE) },
5319 { WM_APP, sent|wparam|lparam, 0, 0 },
5320 { 0 }
5321 };
5322 static const struct message WmClearStateOwnerdrawSeq[] =
5323 {
5324 { BM_SETSTATE, sent },
5325 { WM_CTLCOLORBTN, sent|parent },
5326 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000020e4 },
5327 { WM_APP, sent|wparam|lparam, 0, 0 },
5328 { 0 }
5329 };
5330 static const struct message WmSetCheckIgnoredSeq[] =
5331 {
5332 { BM_SETCHECK, sent },
5333 { WM_APP, sent|wparam|lparam, 0, 0 },
5334 { 0 }
5335 };
5336 static const struct message WmSetCheckStaticSeq[] =
5337 {
5338 { BM_SETCHECK, sent },
5339 { WM_CTLCOLORSTATIC, sent|parent },
5340 { WM_APP, sent|wparam|lparam, 0, 0 },
5341 { 0 }
5342 };
5343
5344 static WNDPROC old_button_proc;
5345
5346 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5347 {
5348 static LONG defwndproc_counter = 0;
5349 LRESULT ret;
5350 struct recvd_message msg;
5351
5352 if (ignore_message( message )) return 0;
5353
5354 switch (message)
5355 {
5356 case WM_SYNCPAINT:
5357 break;
5358 case BM_SETSTATE:
5359 if (GetCapture())
5360 ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
5361 /* fall through */
5362 default:
5363 msg.hwnd = hwnd;
5364 msg.message = message;
5365 msg.flags = sent|wparam|lparam;
5366 if (defwndproc_counter) msg.flags |= defwinproc;
5367 msg.wParam = wParam;
5368 msg.lParam = lParam;
5369 msg.descr = "button";
5370 add_message(&msg);
5371 }
5372
5373 defwndproc_counter++;
5374 ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
5375 defwndproc_counter--;
5376
5377 return ret;
5378 }
5379
5380 static void subclass_button(void)
5381 {
5382 WNDCLASSA cls;
5383
5384 if (!GetClassInfoA(0, "button", &cls)) assert(0);
5385
5386 old_button_proc = cls.lpfnWndProc;
5387
5388 cls.hInstance = GetModuleHandle(0);
5389 cls.lpfnWndProc = button_hook_proc;
5390 cls.lpszClassName = "my_button_class";
5391 UnregisterClass(cls.lpszClassName, cls.hInstance);
5392 if (!RegisterClassA(&cls)) assert(0);
5393 }
5394
5395 static void test_button_messages(void)
5396 {
5397 static const struct
5398 {
5399 DWORD style;
5400 DWORD dlg_code;
5401 const struct message *setfocus;
5402 const struct message *killfocus;
5403 const struct message *setstyle;
5404 const struct message *setstate;
5405 const struct message *clearstate;
5406 const struct message *setcheck;
5407 } button[] = {
5408 { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5409 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq,
5410 WmSetStateButtonSeq, WmSetStateButtonSeq, WmSetCheckIgnoredSeq },
5411 { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
5412 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq,
5413 WmSetStateButtonSeq, WmSetStateButtonSeq, WmSetCheckIgnoredSeq },
5414 { BS_CHECKBOX, DLGC_BUTTON,
5415 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5416 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5417 { BS_AUTOCHECKBOX, DLGC_BUTTON,
5418 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5419 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5420 { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5421 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5422 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5423 { BS_3STATE, DLGC_BUTTON,
5424 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5425 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5426 { BS_AUTO3STATE, DLGC_BUTTON,
5427 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5428 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5429 { BS_GROUPBOX, DLGC_STATIC,
5430 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5431 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckIgnoredSeq },
5432 { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5433 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleUserSeq,
5434 WmSetStateUserSeq, WmClearStateButtonSeq, WmSetCheckIgnoredSeq },
5435 { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5436 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5437 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5438 { BS_OWNERDRAW, DLGC_BUTTON,
5439 WmSetFocusOwnerdrawSeq, WmKillFocusOwnerdrawSeq, WmSetStyleOwnerdrawSeq,
5440 WmSetStateOwnerdrawSeq, WmClearStateOwnerdrawSeq, WmSetCheckIgnoredSeq },
5441 };
5442 unsigned int i;
5443 HWND hwnd, parent;
5444 DWORD dlg_code;
5445 HFONT zfont;
5446
5447 /* selection with VK_SPACE should capture button window */
5448 hwnd = CreateWindowExA(0, "button", "test", BS_CHECKBOX | WS_VISIBLE | WS_POPUP,
5449 0, 0, 50, 14, 0, 0, 0, NULL);
5450 ok(hwnd != 0, "Failed to create button window\n");
5451 ReleaseCapture();
5452 SetFocus(hwnd);
5453 SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
5454 ok(GetCapture() == hwnd, "Should be captured on VK_SPACE WM_KEYDOWN\n");
5455 SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
5456 DestroyWindow(hwnd);
5457
5458 subclass_button();
5459
5460 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5461 100, 100, 200, 200, 0, 0, 0, NULL);
5462 ok(parent != 0, "Failed to create parent window\n");
5463
5464 for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
5465 {
5466 MSG msg;
5467 DWORD style, state;
5468
5469 trace("button style %08x\n", button[i].style);
5470
5471 hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_CHILD | BS_NOTIFY,
5472 0, 0, 50, 14, parent, (HMENU)ID_BUTTON, 0, NULL);
5473 ok(hwnd != 0, "Failed to create button window\n");
5474
5475 style = GetWindowLongA(hwnd, GWL_STYLE);
5476 style &= ~(WS_CHILD | BS_NOTIFY);
5477 /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
5478 if (button[i].style == BS_USERBUTTON)
5479 ok(style == BS_PUSHBUTTON, "expected style BS_PUSHBUTTON got %x\n", style);
5480 else
5481 ok(style == button[i].style, "expected style %x got %x\n", button[i].style, style);
5482
5483 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5484 ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5485
5486 ShowWindow(hwnd, SW_SHOW);
5487 UpdateWindow(hwnd);
5488 SetFocus(0);
5489 flush_events();
5490 SetFocus(0);
5491 flush_sequence();
5492
5493 log_all_parent_messages++;
5494
5495 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
5496 SetFocus(hwnd);
5497 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5498 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5499 ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
5500
5501 SetFocus(0);
5502 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5503 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5504 ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
5505
5506 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
5507
5508 SendMessage(hwnd, BM_SETSTYLE, button[i].style | BS_BOTTOM, TRUE);
5509 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5510 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5511 ok_sequence(button[i].setstyle, "BM_SETSTYLE on a button", FALSE);
5512
5513 style = GetWindowLongA(hwnd, GWL_STYLE);
5514 style &= ~(WS_VISIBLE | WS_CHILD | BS_NOTIFY);
5515 /* XP doesn't turn a BS_USERBUTTON into BS_PUSHBUTTON here! */
5516 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5517
5518 state = SendMessage(hwnd, BM_GETSTATE, 0, 0);
5519 ok(state == 0, "expected state 0, got %04x\n", state);
5520
5521 flush_sequence();
5522
5523 SendMessage(hwnd, BM_SETSTATE, TRUE, 0);
5524 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5525 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5526 ok_sequence(button[i].setstate, "BM_SETSTATE/TRUE on a button", FALSE);
5527
5528 state = SendMessage(hwnd, BM_GETSTATE, 0, 0);
5529 ok(state == 0x0004, "expected state 0x0004, got %04x\n", state);
5530
5531 style = GetWindowLongA(hwnd, GWL_STYLE);
5532 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5533 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5534
5535 flush_sequence();
5536
5537 SendMessage(hwnd, BM_SETSTATE, FALSE, 0);
5538 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5539 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5540 ok_sequence(button[i].clearstate, "BM_SETSTATE/FALSE on a button", FALSE);
5541
5542 state = SendMessage(hwnd, BM_GETSTATE, 0, 0);
5543 ok(state == 0, "expected state 0, got %04x\n", state);
5544
5545 style = GetWindowLongA(hwnd, GWL_STYLE);
5546 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5547 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5548
5549 state = SendMessage(hwnd, BM_GETCHECK, 0, 0);
5550 ok(state == BST_UNCHECKED, "expected BST_UNCHECKED, got %04x\n", state);
5551
5552 flush_sequence();
5553
5554 SendMessage(hwnd, BM_SETCHECK, BST_UNCHECKED, 0);
5555 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5556 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5557 ok_sequence(WmSetCheckIgnoredSeq, "BM_SETCHECK on a button", FALSE);
5558
5559 state = SendMessage(hwnd, BM_GETCHECK, 0, 0);
5560 ok(state == BST_UNCHECKED, "expected BST_UNCHECKED, got %04x\n", state);
5561
5562 style = GetWindowLongA(hwnd, GWL_STYLE);
5563 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5564 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5565
5566 flush_sequence();
5567
5568 SendMessage(hwnd, BM_SETCHECK, BST_CHECKED, 0);
5569 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5570 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5571 ok_sequence(button[i].setcheck, "BM_SETCHECK on a button", FALSE);
5572
5573 state = SendMessage(hwnd, BM_GETCHECK, 0, 0);
5574 if (button[i].style == BS_PUSHBUTTON ||
5575 button[i].style == BS_DEFPUSHBUTTON ||
5576 button[i].style == BS_GROUPBOX ||
5577 button[i].style == BS_USERBUTTON ||
5578 button[i].style == BS_OWNERDRAW)
5579 ok(state == BST_UNCHECKED, "expected check 0, got %04x\n", state);
5580 else
5581 ok(state == BST_CHECKED, "expected check 1, got %04x\n", state);
5582
5583 style = GetWindowLongA(hwnd, GWL_STYLE);
5584 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5585 if (button[i].style == BS_RADIOBUTTON ||
5586 button[i].style == BS_AUTORADIOBUTTON)
5587 ok(style == (button[i].style | WS_TABSTOP), "expected style %04x | WS_TABSTOP got %04x\n", button[i].style, style);
5588 else
5589 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5590
5591 log_all_parent_messages--;
5592
5593 DestroyWindow(hwnd);
5594 }
5595
5596 DestroyWindow(parent);
5597
5598 hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
5599 0, 0, 50, 14, 0, 0, 0, NULL);
5600 ok(hwnd != 0, "Failed to create button window\n");
5601
5602 SetForegroundWindow(hwnd);
5603 flush_events();
5604
5605 SetActiveWindow(hwnd);
5606 SetFocus(0);
5607 flush_sequence();
5608
5609 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
5610 ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
5611
5612 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
5613 ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
5614
5615 flush_sequence();
5616 zfont = GetStockObject(SYSTEM_FONT);
5617 SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
5618 UpdateWindow(hwnd);
5619 ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
5620
5621 DestroyWindow(hwnd);
5622 }
5623
5624 /****************** static message test *************************/
5625 static const struct message WmSetFontStaticSeq[] =
5626 {
5627 { WM_SETFONT, sent },
5628 { WM_PAINT, sent|defwinproc|optional },
5629 { WM_ERASEBKGND, sent|defwinproc|optional },
5630 { WM_CTLCOLORSTATIC, sent|defwinproc|optional },
5631 { 0 }
5632 };
5633
5634 static WNDPROC old_static_proc;
5635
5636 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5637 {
5638 static LONG defwndproc_counter = 0;
5639 LRESULT ret;
5640 struct recvd_message msg;
5641
5642 if (ignore_message( message )) return 0;
5643
5644 msg.hwnd = hwnd;
5645 msg.message = message;
5646 msg.flags = sent|wparam|lparam;
5647 if (defwndproc_counter) msg.flags |= defwinproc;
5648 msg.wParam = wParam;
5649 msg.lParam = lParam;
5650 msg.descr = "static";
5651 add_message(&msg);
5652
5653 defwndproc_counter++;
5654 ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
5655 defwndproc_counter--;
5656
5657 return ret;
5658 }
5659
5660 static void subclass_static(void)
5661 {
5662 WNDCLASSA cls;
5663
5664 if (!GetClassInfoA(0, "static", &cls)) assert(0);
5665
5666 old_static_proc = cls.lpfnWndProc;
5667
5668 cls.hInstance = GetModuleHandle(0);
5669 cls.lpfnWndProc = static_hook_proc;
5670 cls.lpszClassName = "my_static_class";
5671 UnregisterClass(cls.lpszClassName, cls.hInstance);
5672 if (!RegisterClassA(&cls)) assert(0);
5673 }
5674
5675 static void test_static_messages(void)
5676 {
5677 /* FIXME: make as comprehensive as the button message test */
5678 static const struct
5679 {
5680 DWORD style;
5681 DWORD dlg_code;
5682 const struct message *setfont;
5683 } static_ctrl[] = {
5684 { SS_LEFT, DLGC_STATIC,
5685 WmSetFontStaticSeq }
5686 };
5687 unsigned int i;
5688 HWND hwnd;
5689 DWORD dlg_code;
5690
5691 subclass_static();
5692
5693 for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
5694 {
5695 hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
5696 0, 0, 50, 14, 0, 0, 0, NULL);
5697 ok(hwnd != 0, "Failed to create static window\n");
5698
5699 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5700 ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5701
5702 ShowWindow(hwnd, SW_SHOW);
5703 UpdateWindow(hwnd);
5704 SetFocus(0);
5705 flush_sequence();
5706
5707 trace("static style %08x\n", static_ctrl[i].style);
5708 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
5709 ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
5710
5711 DestroyWindow(hwnd);
5712 }
5713 }
5714
5715 /****************** ComboBox message test *************************/
5716 #define ID_COMBOBOX 0x000f
5717
5718 static const struct message WmKeyDownComboSeq[] =
5719 {
5720 { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
5721 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
5722 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
5723 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
5724 { WM_CTLCOLOREDIT, sent|parent },
5725 { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
5726 { 0 }
5727 };
5728
5729 static const struct message WmSetPosComboSeq[] =
5730 {
5731 { WM_WINDOWPOSCHANGING, sent },
5732 { WM_NCCALCSIZE, sent|wparam, TRUE },
5733 { WM_CHILDACTIVATE, sent },
5734 { WM_WINDOWPOSCHANGED, sent },
5735 { WM_MOVE, sent|defwinproc },
5736 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
5737 { WM_WINDOWPOSCHANGING, sent|defwinproc },
5738 { WM_NCCALCSIZE, sent|defwinproc|wparam, TRUE },
5739 { WM_WINDOWPOSCHANGED, sent|defwinproc },
5740 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
5741 { 0 }
5742 };
5743
5744 static WNDPROC old_combobox_proc;
5745
5746 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5747 {
5748 static LONG defwndproc_counter = 0;
5749 LRESULT ret;
5750 struct recvd_message msg;
5751
5752 /* do not log painting messages */
5753 if (message != WM_PAINT &&
5754 message != WM_NCPAINT &&
5755 message != WM_SYNCPAINT &&
5756 message != WM_ERASEBKGND &&
5757 message != WM_NCHITTEST &&
5758 message != WM_GETTEXT &&
5759 !ignore_message( message ))
5760 {
5761 msg.hwnd = hwnd;
5762 msg.message = message;
5763 msg.flags = sent|wparam|lparam;
5764 if (defwndproc_counter) msg.flags |= defwinproc;
5765 msg.wParam = wParam;
5766 msg.lParam = lParam;
5767 msg.descr = "combo";
5768 add_message(&msg);
5769 }
5770
5771 defwndproc_counter++;
5772 ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5773 defwndproc_counter--;
5774
5775 return ret;
5776 }
5777
5778 static void subclass_combobox(void)
5779 {
5780 WNDCLASSA cls;
5781
5782 if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5783
5784 old_combobox_proc = cls.lpfnWndProc;
5785
5786 cls.hInstance = GetModuleHandle(0);
5787 cls.lpfnWndProc = combobox_hook_proc;
5788 cls.lpszClassName = "my_combobox_class";
5789 UnregisterClass(cls.lpszClassName, cls.hInstance);
5790 if (!RegisterClassA(&cls)) assert(0);
5791 }
5792
5793 static void test_combobox_messages(void)
5794 {
5795 HWND parent, combo;
5796 LRESULT ret;
5797
5798 subclass_combobox();
5799
5800 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5801 100, 100, 200, 200, 0, 0, 0, NULL);
5802 ok(parent != 0, "Failed to create parent window\n");
5803 flush_sequence();
5804
5805 combo = CreateWindowEx(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5806 0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5807 ok(combo != 0, "Failed to create combobox window\n");
5808
5809 UpdateWindow(combo);
5810
5811 ret = SendMessage(combo, WM_GETDLGCODE, 0, 0);
5812 ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5813
5814 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5815 ok(ret == 0, "expected 0, got %ld\n", ret);
5816 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5817 ok(ret == 1, "expected 1, got %ld\n", ret);
5818 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5819 ok(ret == 2, "expected 2, got %ld\n", ret);
5820
5821 SendMessage(combo, CB_SETCURSEL, 0, 0);
5822 SetFocus(combo);
5823 flush_sequence();
5824
5825 log_all_parent_messages++;
5826 SendMessage(combo, WM_KEYDOWN, VK_DOWN, 0);
5827 SendMessage(combo, WM_KEYUP, VK_DOWN, 0);
5828 log_all_parent_messages--;
5829 ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5830
5831 flush_sequence();
5832 SetWindowPos(combo, 0, 10, 10, 120, 130, SWP_NOZORDER);
5833 ok_sequence(WmSetPosComboSeq, "repositioning messages on a ComboBox", FALSE);
5834
5835 DestroyWindow(combo);
5836 DestroyWindow(parent);
5837 }
5838
5839 /****************** WM_IME_KEYDOWN message test *******************/
5840
5841 static const struct message WmImeKeydownMsgSeq_0[] =
5842 {
5843 { WM_IME_KEYDOWN, wparam, VK_RETURN },
5844 { WM_CHAR, wparam, 'A' },
5845 { 0 }
5846 };
5847
5848 static const struct message WmImeKeydownMsgSeq_1[] =
5849 {
5850 { WM_KEYDOWN, optional|wparam, VK_RETURN },
5851 { WM_CHAR, optional|wparam, VK_RETURN },
5852 { 0 }
5853 };
5854
5855 static LRESULT WINAPI wmime_keydown_procA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5856 {
5857 struct recvd_message msg;
5858
5859 msg.hwnd = hwnd;
5860 msg.message = message;
5861 msg.flags = wparam|lparam;
5862 msg.wParam = wParam;
5863 msg.lParam = lParam;
5864 msg.descr = "wmime_keydown";
5865 add_message(&msg);
5866
5867 return DefWindowProcA(hwnd, message, wParam, lParam);
5868 }
5869
5870 static void register_wmime_keydown_class(void)
5871 {
5872 WNDCLASSA cls;
5873
5874 ZeroMemory(&cls, sizeof(WNDCLASSA));
5875 cls.lpfnWndProc = wmime_keydown_procA;
5876 cls.hInstance = GetModuleHandleA(0);
5877 cls.lpszClassName = "wmime_keydown_class";
5878 if (!RegisterClassA(&cls)) assert(0);
5879 }
5880
5881 static void test_wmime_keydown_message(void)
5882 {
5883 HWND hwnd;
5884 MSG msg;
5885
5886 trace("Message sequences by WM_IME_KEYDOWN\n");
5887
5888 register_wmime_keydown_class();
5889 hwnd = CreateWindowExA(0, "wmime_keydown_class", NULL, WS_OVERLAPPEDWINDOW,
5890 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5891 NULL, NULL, 0);
5892 flush_events();
5893 flush_sequence();
5894
5895 SendMessage(hwnd, WM_IME_KEYDOWN, VK_RETURN, 0x1c0001);
5896 SendMessage(hwnd, WM_CHAR, 'A', 1);
5897 ok_sequence(WmImeKeydownMsgSeq_0, "WM_IME_KEYDOWN 0", FALSE);
5898
5899 while ( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
5900 {
5901 TranslateMessage(&msg);
5902 DispatchMessage(&msg);
5903 }
5904 ok_sequence(WmImeKeydownMsgSeq_1, "WM_IME_KEYDOWN 1", FALSE);
5905
5906 DestroyWindow(hwnd);
5907 }
5908
5909 /************* painting message test ********************/
5910
5911 void dump_region(HRGN hrgn)
5912 {
5913 DWORD i, size;
5914 RGNDATA *data = NULL;
5915 RECT *rect;
5916
5917 if (!hrgn)
5918 {
5919 printf( "null region\n" );
5920 return;
5921 }
5922 if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5923 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5924 GetRegionData( hrgn, size, data );
5925 printf("%d rects:", data->rdh.nCount );
5926 for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5927 printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
5928 printf("\n");
5929 HeapFree( GetProcessHeap(), 0, data );
5930 }
5931
5932 static void check_update_rgn( HWND hwnd, HRGN hrgn )
5933 {
5934 INT ret;
5935 RECT r1, r2;
5936 HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
5937 HRGN update = CreateRectRgn( 0, 0, 0, 0 );
5938
5939 ret = GetUpdateRgn( hwnd, update, FALSE );
5940 ok( ret != ERROR, "GetUpdateRgn failed\n" );
5941 if (ret == NULLREGION)
5942 {
5943 ok( !hrgn, "Update region shouldn't be empty\n" );
5944 }
5945 else
5946 {
5947 if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
5948 {
5949 ok( 0, "Regions are different\n" );
5950 if (winetest_debug > 0)
5951 {
5952 printf( "Update region: " );
5953 dump_region( update );
5954 printf( "Wanted region: " );
5955 dump_region( hrgn );
5956 }
5957 }
5958 }
5959 GetRgnBox( update, &r1 );
5960 GetUpdateRect( hwnd, &r2, FALSE );
5961 ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
5962 "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
5963 r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
5964
5965 DeleteObject( tmp );
5966 DeleteObject( update );
5967 }
5968
5969 static const struct message WmInvalidateRgn[] = {
5970 { WM_NCPAINT, sent },
5971 { WM_GETTEXT, sent|defwinproc|optional },
5972 { 0 }
5973 };
5974
5975 static const struct message WmGetUpdateRect[] = {
5976 { WM_NCPAINT, sent },
5977 { WM_GETTEXT, sent|defwinproc|optional },
5978 { WM_PAINT, sent },
5979 { 0 }
5980 };
5981
5982 static const struct message WmInvalidateFull[] = {
5983 { WM_NCPAINT, sent|wparam, 1 },
5984 { WM_GETTEXT, sent|defwinproc|optional },
5985 { 0 }
5986 };
5987
5988 static const struct message WmInvalidateErase[] = {
5989 { WM_NCPAINT, sent|wparam, 1 },
5990 { WM_GETTEXT, sent|defwinproc|optional },
5991 { WM_ERASEBKGND, sent },
5992 { 0 }
5993 };
5994
5995 static const struct message WmInvalidatePaint[] = {
5996 { WM_PAINT, sent },
5997 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5998 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5999 { 0 }
6000 };
6001
6002 static const struct message WmInvalidateErasePaint[] = {
6003 { WM_PAINT, sent },
6004 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
6005 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6006 { WM_ERASEBKGND, sent|beginpaint|optional },
6007 { 0 }
6008 };
6009
6010 static const struct message WmInvalidateErasePaint2[] = {
6011 { WM_PAINT, sent },
6012 { WM_NCPAINT, sent|beginpaint },
6013 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6014 { WM_ERASEBKGND, sent|beginpaint|optional },
6015 { 0 }
6016 };
6017
6018 static const struct message WmErase[] = {
6019 { WM_ERASEBKGND, sent },
6020 { 0 }
6021 };
6022
6023 static const struct message WmPaint[] = {
6024 { WM_PAINT, sent },
6025 { 0 }
6026 };
6027
6028 static const struct message WmParentOnlyPaint[] = {
6029 { WM_PAINT, sent|parent },
6030 { 0 }
6031 };
6032
6033 static const struct message WmInvalidateParent[] = {
6034 { WM_NCPAINT, sent|parent },
6035 { WM_GETTEXT, sent|defwinproc|parent|optional },
6036 { WM_ERASEBKGND, sent|parent },
6037 { 0 }
6038 };
6039
6040 static const struct message WmInvalidateParentChild[] = {
6041 { WM_NCPAINT, sent|parent },
6042 { WM_GETTEXT, sent|defwinproc|parent|optional },
6043 { WM_ERASEBKGND, sent|parent },
6044 { WM_NCPAINT, sent },
6045 { WM_GETTEXT, sent|defwinproc|optional },
6046 { WM_ERASEBKGND, sent },
6047 { 0 }
6048 };
6049
6050 static const struct message WmInvalidateParentChild2[] = {
6051 { WM_ERASEBKGND, sent|parent },
6052 { WM_NCPAINT, sent },
6053 { WM_GETTEXT, sent|defwinproc|optional },
6054 { WM_ERASEBKGND, sent },
6055 { 0 }
6056 };
6057
6058 static const struct message WmParentPaint[] = {
6059 { WM_PAINT, sent|parent },
6060 { WM_PAINT, sent },
6061 { 0 }
6062 };
6063
6064 static const struct message WmParentPaintNc[] = {
6065 { WM_PAINT, sent|parent },
6066 { WM_PAINT, sent },
6067 { WM_NCPAINT, sent|beginpaint },
6068 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6069 { WM_ERASEBKGND, sent|beginpaint|optional },
6070 { 0 }
6071 };
6072
6073 static const struct message WmChildPaintNc[] = {
6074 { WM_PAINT, sent },
6075 { WM_NCPAINT, sent|beginpaint },
6076 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6077 { WM_ERASEBKGND, sent|beginpaint|optional },
6078 { 0 }
6079 };
6080
6081 static const struct message WmParentErasePaint[] = {
6082 { WM_PAINT, sent|parent },
6083 { WM_NCPAINT, sent|parent|beginpaint },
6084 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
6085 { WM_ERASEBKGND, sent|parent|beginpaint|optional },
6086 { WM_PAINT, sent },
6087 { WM_NCPAINT, sent|beginpaint },
6088 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6089 { WM_ERASEBKGND, sent|beginpaint|optional },
6090 { 0 }
6091 };
6092
6093 static const struct message WmParentOnlyNcPaint[] = {
6094 { WM_PAINT, sent|parent },
6095 { WM_NCPAINT, sent|parent|beginpaint },
6096 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
6097 { 0 }
6098 };
6099
6100 static const struct message WmSetParentStyle[] = {
6101 { WM_STYLECHANGING, sent|parent },
6102 { WM_STYLECHANGED, sent|parent },
6103 { 0 }
6104 };
6105
6106 static void test_paint_messages(void)
6107 {
6108 BOOL ret;
6109 RECT rect;
6110 POINT pt;
6111 MSG msg;
6112 HWND hparent, hchild;
6113 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
6114 HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
6115 HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
6116 100, 100, 200, 200, 0, 0, 0, NULL);
6117 ok (hwnd != 0, "Failed to create overlapped window\n");
6118
6119 ShowWindow( hwnd, SW_SHOW );
6120 UpdateWindow( hwnd );
6121 flush_events();
6122 flush_sequence();
6123
6124 check_update_rgn( hwnd, 0 );
6125 SetRectRgn( hrgn, 10, 10, 20, 20 );
6126 ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6127 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6128 check_update_rgn( hwnd, hrgn );
6129 SetRectRgn( hrgn2, 20, 20, 30, 30 );
6130 ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
6131 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6132 CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
6133 check_update_rgn( hwnd, hrgn );
6134 /* validate everything */
6135 ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6136 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6137 check_update_rgn( hwnd, 0 );
6138
6139 /* test empty region */
6140 SetRectRgn( hrgn, 10, 10, 10, 15 );
6141 ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6142 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6143 check_update_rgn( hwnd, 0 );
6144 /* test empty rect */
6145 SetRect( &rect, 10, 10, 10, 15 );
6146 ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
6147 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6148 check_update_rgn( hwnd, 0 );
6149
6150 /* flush pending messages */
6151 flush_events();
6152 flush_sequence();
6153
6154 GetClientRect( hwnd, &rect );
6155 SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
6156 /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
6157 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
6158 */
6159 trace("testing InvalidateRect(0, NULL, FALSE)\n");
6160 SetRectEmpty( &rect );
6161 ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
6162 check_update_rgn( hwnd, hrgn );
6163 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6164 flush_events();
6165 ok_sequence( WmPaint, "Paint", FALSE );
6166 RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6167 check_update_rgn( hwnd, 0 );
6168
6169 /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
6170 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
6171 */
6172 trace("testing ValidateRect(0, NULL)\n");
6173 SetRectEmpty( &rect );
6174 if (ValidateRect(0, &rect)) /* not supported on Win9x */
6175 {
6176 check_update_rgn( hwnd, hrgn );
6177 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6178 flush_events();
6179 ok_sequence( WmPaint, "Paint", FALSE );
6180 RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6181 check_update_rgn( hwnd, 0 );
6182 }
6183
6184 trace("testing InvalidateRgn(0, NULL, FALSE)\n");
6185 SetLastError(0xdeadbeef);
6186 ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
6187 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
6188 "wrong error code %d\n", GetLastError());
6189 check_update_rgn( hwnd, 0 );
6190 flush_events();
6191 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6192
6193 trace("testing ValidateRgn(0, NULL)\n");
6194 SetLastError(0xdeadbeef);
6195 ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
6196 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
6197 broken( GetLastError() == 0xdeadbeef ) /* win9x */,
6198 "wrong error code %d\n", GetLastError());
6199 check_update_rgn( hwnd, 0 );
6200 flush_events();
6201 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6202
6203 trace("testing UpdateWindow(NULL)\n");
6204 SetLastError(0xdeadbeef);
6205 ok(!UpdateWindow(NULL), "UpdateWindow(NULL) should fail\n");
6206 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
6207 broken( GetLastError() == 0xdeadbeef ) /* win9x */,
6208 "wrong error code %d\n", GetLastError());
6209 check_update_rgn( hwnd, 0 );
6210 flush_events();
6211 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6212
6213 /* now with frame */
6214 SetRectRgn( hrgn, -5, -5, 20, 20 );
6215
6216 /* flush pending messages */
6217 flush_events();
6218 flush_sequence();
6219 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6220 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
6221
6222 SetRectRgn( hrgn, 0, 0, 20, 20 ); /* GetUpdateRgn clips to client area */
6223 check_update_rgn( hwnd, hrgn );
6224
6225 flush_sequence();
6226 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
6227 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
6228
6229 flush_sequence();
6230 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
6231 ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
6232
6233 GetClientRect( hwnd, &rect );
6234 SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
6235 check_update_rgn( hwnd, hrgn );
6236
6237 flush_sequence();
6238 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
6239 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6240
6241 flush_sequence();
6242 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
6243 ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
6244 check_update_rgn( hwnd, 0 );
6245
6246 flush_sequence();
6247 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
6248 ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
6249 check_update_rgn( hwnd, 0 );
6250
6251 flush_sequence();
6252 SetRectRgn( hrgn, 0, 0, 100, 100 );
6253 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6254 SetRectRgn( hrgn, 0, 0, 50, 100 );
6255 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
6256 SetRectRgn( hrgn, 50, 0, 100, 100 );
6257 check_update_rgn( hwnd, hrgn );
6258 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
6259 ok_sequence( WmEmptySeq, "EmptySeq", FALSE ); /* must not generate messages, everything is valid */
6260 check_update_rgn( hwnd, 0 );
6261
6262 flush_sequence();
6263 SetRectRgn( hrgn, 0, 0, 100, 100 );
6264 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
6265 SetRectRgn( hrgn, 0, 0, 100, 50 );
6266 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
6267 ok_sequence( WmErase, "Erase", FALSE );
6268 SetRectRgn( hrgn, 0, 50, 100, 100 );
6269 check_update_rgn( hwnd, hrgn );
6270
6271 flush_sequence();
6272 SetRectRgn( hrgn, 0, 0, 100, 100 );
6273 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
6274 SetRectRgn( hrgn, 0, 0, 50, 50 );
6275 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
6276 ok_sequence( WmPaint, "Paint", FALSE );
6277
6278 flush_sequence();
6279 SetRectRgn( hrgn, -4, -4, -2, -2 );
6280 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6281 SetRectRgn( hrgn, -200, -200, -198, -198 );
6282 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
6283 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
6284
6285 flush_sequence();
6286 SetRectRgn( hrgn, -4, -4, -2, -2 );
6287 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6288 SetRectRgn( hrgn, -4, -4, -3, -3 );
6289 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
6290 SetRectRgn( hrgn, 0, 0, 1, 1 );
6291 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
6292 ok_sequence( WmPaint, "Paint", FALSE );
6293
6294 flush_sequence();
6295 SetRectRgn( hrgn, -4, -4, -1, -1 );
6296 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6297 RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
6298 /* make sure no WM_PAINT was generated */
6299 flush_events();
6300 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
6301
6302 flush_sequence();
6303 SetRectRgn( hrgn, -4, -4, -1, -1 );
6304 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6305 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
6306 {
6307 if (msg.hwnd == hwnd && msg.message == WM_PAINT)
6308 {
6309 /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
6310 INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
6311 ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
6312 ret = GetUpdateRect( hwnd, &rect, FALSE );
6313 ok( ret, "Invalid GetUpdateRect result %d\n", ret );
6314 /* this will send WM_NCPAINT and validate the non client area */
6315 ret = GetUpdateRect( hwnd, &rect, TRUE );
6316 ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
6317 }
6318 DispatchMessage( &msg );
6319 }
6320 ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
6321
6322 DestroyWindow( hwnd );
6323
6324 /* now test with a child window */
6325
6326 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
6327 100, 100, 200, 200, 0, 0, 0, NULL);
6328 ok (hparent != 0, "Failed to create parent window\n");
6329
6330 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
6331 10, 10, 100, 100, hparent, 0, 0, NULL);
6332 ok (hchild != 0, "Failed to create child window\n");
6333
6334 ShowWindow( hparent, SW_SHOW );
6335 UpdateWindow( hparent );
6336 UpdateWindow( hchild );
6337 flush_events();
6338 flush_sequence();
6339 log_all_parent_messages++;
6340
6341 SetRect( &rect, 0, 0, 50, 50 );
6342 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6343 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6344 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
6345
6346 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6347 pt.x = pt.y = 0;
6348 MapWindowPoints( hchild, hparent, &pt, 1 );
6349 SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
6350 check_update_rgn( hchild, hrgn );
6351 SetRectRgn( hrgn, 0, 0, 50, 50 );
6352 check_update_rgn( hparent, hrgn );
6353 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6354 ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
6355 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6356 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6357
6358 flush_events();
6359 ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
6360
6361 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6362 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6363 ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
6364 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6365 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6366
6367 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6368 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6369 ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
6370
6371 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6372 flush_sequence();
6373 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6374 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6375 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
6376
6377 /* flush all paint messages */
6378 flush_events();
6379 flush_sequence();
6380
6381 /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
6382 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6383 SetRectRgn( hrgn, 0, 0, 50, 50 );
6384 check_update_rgn( hparent, hrgn );
6385 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6386 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6387 SetRectRgn( hrgn, 0, 0, 50, 50 );
6388 check_update_rgn( hparent, hrgn );
6389
6390 /* flush all paint messages */
6391 flush_events();
6392 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6393 flush_sequence();
6394
6395 /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
6396 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6397 SetRectRgn( hrgn, 0, 0, 50, 50 );
6398 check_update_rgn( hparent, hrgn );
6399 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6400 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6401 SetRectRgn( hrgn2, 10, 10, 50, 50 );
6402 CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
6403 check_update_rgn( hparent, hrgn );
6404 /* flush all paint messages */
6405 flush_events();
6406 flush_sequence();
6407
6408 /* same as above but parent gets completely validated */
6409 SetRect( &rect, 20, 20, 30, 30 );
6410 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6411 SetRectRgn( hrgn, 20, 20, 30, 30 );
6412 check_update_rgn( hparent, hrgn );
6413 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6414 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6415 check_update_rgn( hparent, 0 ); /* no update region */
6416 flush_events();
6417 ok_sequence( WmEmptySeq, "WmEmpty", FALSE ); /* and no paint messages */
6418
6419 /* make sure RDW_VALIDATE on child doesn't have the same effect */
6420 flush_sequence();
6421 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6422 SetRectRgn( hrgn, 20, 20, 30, 30 );
6423 check_update_rgn( hparent, hrgn );
6424 RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
6425 SetRectRgn( hrgn, 20, 20, 30, 30 );
6426 check_update_rgn( hparent, hrgn );
6427
6428 /* same as above but normal WM_PAINT doesn't validate parent */
6429 flush_sequence();
6430 SetRect( &rect, 20, 20, 30, 30 );
6431 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6432 SetRectRgn( hrgn, 20, 20, 30, 30 );
6433 check_update_rgn( hparent, hrgn );
6434 /* no WM_PAINT in child while parent still pending */
6435 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6436 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6437 while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6438 ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
6439
6440 flush_sequence();
6441 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6442 /* no WM_PAINT in child while parent still pending */
6443 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6444 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6445 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
6446 /* now that parent is valid child should get WM_PAINT */
6447 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6448 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6449 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6450 ok_sequence( WmEmptySeq, "No other message", FALSE );
6451
6452 /* same thing with WS_CLIPCHILDREN in parent */
6453 flush_sequence();
6454 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6455 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6456 /* changing style invalidates non client area, but we need to invalidate something else to see it */
6457 RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
6458 ok_sequence( WmEmptySeq, "No message", FALSE );
6459 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
6460 ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
6461
6462 flush_sequence();
6463 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
6464 SetRectRgn( hrgn, 20, 20, 30, 30 );
6465 check_update_rgn( hparent, hrgn );
6466 /* no WM_PAINT in child while parent still pending */
6467 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6468 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6469 /* WM_PAINT in parent first */
6470 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6471 ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
6472
6473 /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
6474 flush_sequence();
6475 SetRect( &rect, 0, 0, 30, 30 );
6476 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
6477 SetRectRgn( hrgn, 0, 0, 30, 30 );
6478 check_update_rgn( hparent, hrgn );
6479 flush_events();
6480 ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
6481
6482 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6483 flush_sequence();
6484 SetRect( &rect, -10, 0, 30, 30 );
6485 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6486 SetRect( &rect, 0, 0, 20, 20 );
6487 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6488 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6489 ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
6490
6491 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6492 flush_sequence();
6493 SetRect( &rect, -10, 0, 30, 30 );
6494 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6495 SetRect( &rect, 0, 0, 100, 100 );
6496 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6497 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6498 ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
6499 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6500 ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
6501
6502 /* test RDW_INTERNALPAINT behavior */
6503
6504 flush_sequence();
6505 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
6506 flush_events();
6507 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6508
6509 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
6510 flush_events();
6511 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6512
6513 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6514 flush_events();
6515 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6516
6517 assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
6518 UpdateWindow( hparent );
6519 flush_events();
6520 flush_sequence();
6521 trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
6522 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6523 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6524 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6525 flush_events();
6526 ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
6527
6528 UpdateWindow( hparent );
6529 flush_events();
6530 flush_sequence();
6531 trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
6532 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6533 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6534 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6535 flush_events();
6536 ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6537
6538 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6539 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6540 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6541 flush_events();
6542 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6543
6544 assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
6545 UpdateWindow( hparent );
6546 flush_events();
6547 flush_sequence();
6548 trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
6549 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6550 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6551 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6552 flush_events();
6553 ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
6554
6555 UpdateWindow( hparent );
6556 flush_events();
6557 flush_sequence();
6558 trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
6559 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6560 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6561 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6562 flush_events();
6563 ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6564
6565 ok(GetWindowLong( hparent, GWL_STYLE ) & WS_VISIBLE, "parent should be visible\n");
6566 ok(GetWindowLong( hchild, GWL_STYLE ) & WS_VISIBLE, "child should be visible\n");
6567
6568 UpdateWindow( hparent );
6569 flush_events();
6570 flush_sequence();
6571 trace("testing SetWindowPos(-10000, -10000) on child\n");
6572 SetWindowPos( hchild, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6573 check_update_rgn( hchild, 0 );
6574 flush_events();
6575
6576 #if 0 /* this one doesn't pass under Wine yet */
6577 UpdateWindow( hparent );
6578 flush_events();
6579 flush_sequence();
6580 trace("testing ShowWindow(SW_MINIMIZE) on child\n");
6581 ShowWindow( hchild, SW_MINIMIZE );
6582 check_update_rgn( hchild, 0 );
6583 flush_events();
6584 #endif
6585
6586 UpdateWindow( hparent );
6587 flush_events();
6588 flush_sequence();
6589 trace("testing SetWindowPos(-10000, -10000) on parent\n");
6590 SetWindowPos( hparent, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6591 check_update_rgn( hparent, 0 );
6592 flush_events();
6593
6594 log_all_parent_messages--;
6595 DestroyWindow( hparent );
6596 ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6597
6598 /* tests for moving windows off-screen (needs simple WS_POPUP windows) */
6599
6600 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_POPUP | WS_VISIBLE,
6601 100, 100, 200, 200, 0, 0, 0, NULL);
6602 ok (hparent != 0, "Failed to create parent window\n");
6603
6604 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
6605 10, 10, 100, 100, hparent, 0, 0, NULL);
6606 ok (hchild != 0, "Failed to create child window\n");
6607
6608 ShowWindow( hparent, SW_SHOW );
6609 UpdateWindow( hparent );
6610 UpdateWindow( hchild );
6611 flush_events();
6612 flush_sequence();
6613
6614 /* moving child outside of parent boundaries changes update region */
6615 SetRect( &rect, 0, 0, 40, 40 );
6616 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6617 SetRectRgn( hrgn, 0, 0, 40, 40 );
6618 check_update_rgn( hchild, hrgn );
6619 MoveWindow( hchild, -10, 10, 100, 100, FALSE );
6620 SetRectRgn( hrgn, 10, 0, 40, 40 );
6621 check_update_rgn( hchild, hrgn );
6622 MoveWindow( hchild, -10, -10, 100, 100, FALSE );
6623 SetRectRgn( hrgn, 10, 10, 40, 40 );
6624 check_update_rgn( hchild, hrgn );
6625
6626 /* moving parent off-screen does too */
6627 SetRect( &rect, 0, 0, 100, 100 );
6628 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
6629 SetRectRgn( hrgn, 0, 0, 100, 100 );
6630 check_update_rgn( hparent, hrgn );
6631 SetRectRgn( hrgn, 10, 10, 40, 40 );
6632 check_update_rgn( hchild, hrgn );
6633 MoveWindow( hparent, -20, -20, 200, 200, FALSE );
6634 SetRectRgn( hrgn, 20, 20, 100, 100 );
6635 check_update_rgn( hparent, hrgn );
6636 SetRectRgn( hrgn, 30, 30, 40, 40 );
6637 check_update_rgn( hchild, hrgn );
6638
6639 /* invalidated region is cropped by the parent rects */
6640 SetRect( &rect, 0, 0, 50, 50 );
6641 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6642 SetRectRgn( hrgn, 30, 30, 50, 50 );
6643 check_update_rgn( hchild, hrgn );
6644
6645 DestroyWindow( hparent );
6646 ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6647 flush_sequence();
6648
6649 DeleteObject( hrgn );
6650 DeleteObject( hrgn2 );
6651 }
6652
6653 struct wnd_event
6654 {
6655 HWND hwnd;
6656 HANDLE grand_child;
6657 HANDLE start_event;
6658 HANDLE stop_event;
6659 };
6660
6661 static DWORD WINAPI thread_proc(void *param)
6662 {
6663 MSG msg;
6664 struct wnd_event *wnd_event = param;
6665
6666 wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
6667 100, 100, 200, 200, 0, 0, 0, NULL);
6668 ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
6669
6670 SetEvent(wnd_event->start_event);
6671
6672 while (GetMessage(&msg, 0, 0, 0))
6673 {
6674 TranslateMessage(&msg);
6675 DispatchMessage(&msg);
6676 }
6677
6678 ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
6679
6680 return 0;
6681 }
6682
6683 static DWORD CALLBACK create_grand_child_thread( void *param )
6684 {
6685 struct wnd_event *wnd_event = param;
6686 HWND hchild;
6687 MSG msg;
6688
6689 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
6690 WS_CHILD | WS_VISIBLE, 0, 0, 10, 10, wnd_event->hwnd, 0, 0, NULL);
6691 ok (hchild != 0, "Failed to create child window\n");
6692 flush_events();
6693 flush_sequence();
6694 SetEvent( wnd_event->start_event );
6695
6696 for (;;)
6697 {
6698 MsgWaitForMultipleObjects(0, NULL, FALSE, 1000, QS_ALLINPUT);
6699 if (!IsWindow( hchild )) break; /* will be destroyed when parent thread exits */
6700 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6701 }
6702 return 0;
6703 }
6704
6705 static DWORD CALLBACK create_child_thread( void *param )
6706 {
6707 struct wnd_event *wnd_event = param;
6708 struct wnd_event child_event;
6709 DWORD ret, tid;
6710 MSG msg;
6711
6712 child_event.hwnd = CreateWindowExA(0, "TestWindowClass", "Test child",
6713 WS_CHILD | WS_VISIBLE, 0, 0, 10, 10, wnd_event->hwnd, 0, 0, NULL);
6714 ok (child_event.hwnd != 0, "Failed to create child window\n");
6715 SetFocus( child_event.hwnd );
6716 flush_events();
6717 flush_sequence();
6718 child_event.start_event = wnd_event->start_event;
6719 wnd_event->grand_child = CreateThread(NULL, 0, create_grand_child_thread, &child_event, 0, &tid);
6720 for (;;)
6721 {
6722 DWORD ret = MsgWaitForMultipleObjects(1, &child_event.start_event, FALSE, 1000, QS_SENDMESSAGE);
6723 if (ret != 1) break;
6724 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6725 }
6726 ret = WaitForSingleObject( wnd_event->stop_event, 5000 );
6727 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6728 return 0;
6729 }
6730
6731 static void test_interthread_messages(void)
6732 {
6733 HANDLE hThread;
6734 DWORD tid;
6735 WNDPROC proc;
6736 MSG msg;
6737 char buf[256];
6738 int len, expected_len;
6739 struct wnd_event wnd_event;
6740 BOOL ret;
6741
6742 wnd_event.start_event = CreateEventW(NULL, 0, 0, NULL);
6743 if (!wnd_event.start_event)
6744 {
6745 win_skip("skipping interthread message test under win9x\n");
6746 return;
6747 }
6748
6749 hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
6750 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
6751
6752 ok(WaitForSingleObject(wnd_event.start_event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6753
6754 CloseHandle(wnd_event.start_event);
6755
6756 SetLastError(0xdeadbeef);
6757 ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeeded\n");
6758 ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
6759 "wrong error code %d\n", GetLastError());
6760
6761 proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6762 ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
6763
6764 expected_len = lstrlenA("window caption text");
6765 memset(buf, 0, sizeof(buf));
6766 SetLastError(0xdeadbeef);
6767 len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
6768 ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
6769 ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
6770
6771 msg.hwnd = wnd_event.hwnd;
6772 msg.message = WM_GETTEXT;
6773 msg.wParam = sizeof(buf);
6774 msg.lParam = (LPARAM)buf;
6775 memset(buf, 0, sizeof(buf));
6776 SetLastError(0xdeadbeef);
6777 len = DispatchMessageA(&msg);
6778 ok((!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY) || broken(len), /* nt4 */
6779 "DispatchMessageA(WM_GETTEXT) succeeded on another thread window: ret %d, error %d\n", len, GetLastError());
6780
6781 /* the following test causes an exception in user.exe under win9x */
6782 msg.hwnd = wnd_event.hwnd;
6783 msg.message = WM_TIMER;
6784 msg.wParam = 0;
6785 msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6786 SetLastError(0xdeadbeef);
6787 len = DispatchMessageA(&msg);
6788 ok(!len && GetLastError() == 0xdeadbeef,
6789 "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
6790
6791 ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
6792 ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
6793
6794 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6795 CloseHandle(hThread);
6796
6797 ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
6798
6799 wnd_event.hwnd = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6800 100, 100, 200, 200, 0, 0, 0, NULL);
6801 ok (wnd_event.hwnd != 0, "Failed to create parent window\n");
6802 flush_events();
6803 flush_sequence();
6804 log_all_parent_messages++;
6805 wnd_event.start_event = CreateEventA( NULL, TRUE, FALSE, NULL );
6806 wnd_event.stop_event = CreateEventA( NULL, TRUE, FALSE, NULL );
6807 hThread = CreateThread( NULL, 0, create_child_thread, &wnd_event, 0, &tid );
6808 for (;;)
6809 {
6810 ret = MsgWaitForMultipleObjects(1, &wnd_event.start_event, FALSE, 1000, QS_SENDMESSAGE);
6811 if (ret != 1) break;
6812 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6813 }
6814 ok( !ret, "MsgWaitForMultipleObjects failed %x\n", ret );
6815 /* now wait for the thread without processing messages; this shouldn't deadlock */
6816 SetEvent( wnd_event.stop_event );
6817 ret = WaitForSingleObject( hThread, 5000 );
6818 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6819 CloseHandle( hThread );
6820
6821 ret = WaitForSingleObject( wnd_event.grand_child, 5000 );
6822 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6823 CloseHandle( wnd_event.grand_child );
6824
6825 CloseHandle( wnd_event.start_event );
6826 CloseHandle( wnd_event.stop_event );
6827 flush_events();
6828 ok_sequence(WmExitThreadSeq, "destroy child on thread exit", FALSE);
6829 log_all_parent_messages--;
6830 DestroyWindow( wnd_event.hwnd );
6831 }
6832
6833
6834 static const struct message WmVkN[] = {
6835 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6836 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6837 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6838 { WM_CHAR, wparam|lparam, 'n', 1 },
6839 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
6840 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6841 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6842 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6843 { 0 }
6844 };
6845 static const struct message WmShiftVkN[] = {
6846 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6847 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6848 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6849 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6850 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6851 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6852 { WM_CHAR, wparam|lparam, 'N', 1 },
6853 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
6854 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6855 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6856 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6857 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6858 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6859 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6860 { 0 }
6861 };
6862 static const struct message WmCtrlVkN[] = {
6863 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6864 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6865 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6866 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6867 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6868 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6869 { WM_CHAR, wparam|lparam, 0x000e, 1 },
6870 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6871 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6872 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6873 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6874 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6875 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6876 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6877 { 0 }
6878 };
6879 static const struct message WmCtrlVkN_2[] = {
6880 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6881 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6882 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6883 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6884 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6885 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6886 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6887 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6888 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6889 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6890 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6891 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6892 { 0 }
6893 };
6894 static const struct message WmAltVkN[] = {
6895 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6896 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6897 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6898 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6899 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6900 { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6901 { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
6902 { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
6903 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
6904 { HCBT_SYSCOMMAND, hook },
6905 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6906 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6907 { 0x00AE, sent|defwinproc|optional }, /* XP */
6908 { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
6909 { WM_INITMENU, sent|defwinproc },
6910 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6911 { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
6912 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
6913 { WM_CAPTURECHANGED, sent|defwinproc },
6914 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
6915 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6916 { WM_EXITMENULOOP, sent|defwinproc },
6917 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
6918 { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
6919 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6920 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6921 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6922 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6923 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6924 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6925 { 0 }
6926 };
6927 static const struct message WmAltVkN_2[] = {
6928 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6929 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6930 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6931 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6932 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6933 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
6934 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6935 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6936 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6937 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6938 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6939 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6940 { 0 }
6941 };
6942 static const struct message WmCtrlAltVkN[] = {
6943 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6944 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6945 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6946 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6947 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6948 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6949 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6950 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6951 { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6952 { WM_CHAR, optional },
6953 { WM_CHAR, sent|optional },
6954 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6955 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6956 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6957 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6958 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6959 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6960 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6961 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6962 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6963 { 0 }
6964 };
6965 static const struct message WmCtrlShiftVkN[] = {
6966 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6967 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6968 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6969 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6970 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6971 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6972 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6973 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6974 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
6975 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6976 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6977 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6978 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6979 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6980 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6981 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6982 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6983 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6984 { 0 }
6985 };
6986 static const struct message WmCtrlAltShiftVkN[] = {
6987 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6988 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6989 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6990 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6991 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6992 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6993 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
6994 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
6995 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
6996 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6997 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6998 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
6999 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
7000 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
7001 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
7002 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
7003 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
7004 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
7005 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
7006 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
7007 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
7008 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
7009 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
7010 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
7011 { 0 }
7012 };
7013 static const struct message WmAltPressRelease[] = {
7014 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
7015 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
7016 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
7017 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
7018 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
7019 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
7020 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
7021 { HCBT_SYSCOMMAND, hook },
7022 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7023 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7024 { WM_INITMENU, sent|defwinproc },
7025 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7026 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
7027 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7028
7029 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
7030
7031 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7032 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
7033 { WM_CAPTURECHANGED, sent|defwinproc },
7034 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
7035 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7036 { WM_EXITMENULOOP, sent|defwinproc },
7037 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
7038 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
7039 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
7040 { 0 }
7041 };
7042 static const struct message WmShiftMouseButton[] = {
7043 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
7044 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
7045 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
7046 { WM_MOUSEMOVE, wparam|optional, 0, 0 },
7047 { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
7048 { WM_LBUTTONDOWN, wparam, MK_LBUTTON|MK_SHIFT, 0 },
7049 { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON|MK_SHIFT, 0 },
7050 { WM_LBUTTONUP, wparam, MK_SHIFT, 0 },
7051 { WM_LBUTTONUP, sent|wparam, MK_SHIFT, 0 },
7052 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
7053 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
7054 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
7055 { 0 }
7056 };
7057 static const struct message WmF1Seq[] = {
7058 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
7059 { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
7060 { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
7061 { WM_KEYF1, wparam|lparam, 0, 0 },
7062 { WM_KEYF1, sent|wparam|lparam, 0, 0 },
7063 { WM_HELP, sent|defwinproc },
7064 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
7065 { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
7066 { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
7067 { 0 }
7068 };
7069 static const struct message WmVkAppsSeq[] = {
7070 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
7071 { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
7072 { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
7073 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
7074 { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
7075 { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
7076 { WM_CONTEXTMENU, lparam, /*hwnd*/0, -1 },
7077 { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, -1 },
7078 { 0 }
7079 };
7080 static const struct message WmVkF10Seq[] = {
7081 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7082 { WM_SYSKEYDOWN, wparam|lparam, VK_F10, 1 },
7083 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_F10, 0x00000001 },
7084 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7085 { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7086 { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7087 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_KEYMENU },
7088 { HCBT_SYSCOMMAND, hook },
7089 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7090 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7091 { WM_INITMENU, sent|defwinproc },
7092 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7093 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
7094 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7095
7096 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0x10000001 }, /* XP */
7097
7098 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7099 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7100 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
7101 { WM_CAPTURECHANGED, sent|defwinproc },
7102 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
7103 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7104 { WM_EXITMENULOOP, sent|defwinproc },
7105 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7106 { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7107 { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7108 { 0 }
7109 };
7110 static const struct message WmShiftF10Seq[] = {
7111 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
7112 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
7113 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x00000001 },
7114 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7115 { WM_SYSKEYDOWN, wparam|lparam, VK_F10, 1 },
7116 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_F10, 0x00000001 },
7117 { WM_CONTEXTMENU, sent|defwinproc|lparam, /*hwnd*/0, -1 },
7118 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7119 { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7120 { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7121 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_KEYMENU },
7122 { HCBT_SYSCOMMAND, hook },
7123 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7124 { WM_INITMENU, sent|defwinproc },
7125 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
7126 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xd0000001 }, /* XP */
7127 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0x10000001 }, /* XP */
7128 { WM_CAPTURECHANGED, sent|defwinproc|wparam|lparam, 0, 0 },
7129 { WM_MENUSELECT, sent|defwinproc|wparam|lparam, 0xffff0000, 0 },
7130 { WM_EXITMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7131 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0xc0000001 }, /* XP */
7132 { WM_KEYUP, wparam|lparam, VK_ESCAPE, 0xc0000001 },
7133 { WM_KEYUP, sent|wparam|lparam, VK_ESCAPE, 0xc0000001 },
7134 { 0 }
7135 };
7136
7137 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
7138 {
7139 MSG msg;
7140
7141 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
7142 {
7143 struct recvd_message log_msg;
7144
7145 /* ignore some unwanted messages */
7146 if (msg.message == WM_MOUSEMOVE ||
7147 msg.message == WM_TIMER ||
7148 ignore_message( msg.message ))
7149 continue;
7150
7151 log_msg.hwnd = msg.hwnd;
7152 log_msg.message = msg.message;
7153 log_msg.flags = wparam|lparam;
7154 log_msg.wParam = msg.wParam;
7155 log_msg.lParam = msg.lParam;
7156 log_msg.descr = "accel";
7157 add_message(&log_msg);
7158
7159 if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
7160 {
7161 TranslateMessage(&msg);
7162 DispatchMessage(&msg);
7163 }
7164 }
7165 }
7166
7167 static void test_accelerators(void)
7168 {
7169 RECT rc;
7170 POINT pt;
7171 SHORT state;
7172 HACCEL hAccel;
7173 HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7174 100, 100, 200, 200, 0, 0, 0, NULL);
7175 BOOL ret;
7176
7177 assert(hwnd != 0);
7178 UpdateWindow(hwnd);
7179 flush_events();
7180 flush_sequence();
7181
7182 SetFocus(hwnd);
7183 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
7184
7185 state = GetKeyState(VK_SHIFT);
7186 ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
7187 state = GetKeyState(VK_CAPITAL);
7188 ok(state == 0, "wrong CapsLock state %04x\n", state);
7189
7190 hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
7191 assert(hAccel != 0);
7192
7193 flush_events();
7194 pump_msg_loop(hwnd, 0);
7195 flush_sequence();
7196
7197 trace("testing VK_N press/release\n");
7198 flush_sequence();
7199 keybd_event('N', 0, 0, 0);
7200 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7201 pump_msg_loop(hwnd, hAccel);
7202 if (!sequence_cnt) /* we didn't get any message */
7203 {
7204 skip( "queuing key events not supported\n" );
7205 goto done;
7206 }
7207 ok_sequence(WmVkN, "VK_N press/release", FALSE);
7208
7209 trace("testing Shift+VK_N press/release\n");
7210 flush_sequence();
7211 keybd_event(VK_SHIFT, 0, 0, 0);
7212 keybd_event('N', 0, 0, 0);
7213 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7214 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7215 pump_msg_loop(hwnd, hAccel);
7216 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
7217
7218 trace("testing Ctrl+VK_N press/release\n");
7219 flush_sequence();
7220 keybd_event(VK_CONTROL, 0, 0, 0);
7221 keybd_event('N', 0, 0, 0);
7222 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7223 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7224 pump_msg_loop(hwnd, hAccel);
7225 ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
7226
7227 trace("testing Alt+VK_N press/release\n");
7228 flush_sequence();
7229 keybd_event(VK_MENU, 0, 0, 0);
7230 keybd_event('N', 0, 0, 0);
7231 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7232 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7233 pump_msg_loop(hwnd, hAccel);
7234 ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
7235
7236 trace("testing Ctrl+Alt+VK_N press/release 1\n");
7237 flush_sequence();
7238 keybd_event(VK_CONTROL, 0, 0, 0);
7239 keybd_event(VK_MENU, 0, 0, 0);
7240 keybd_event('N', 0, 0, 0);
7241 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7242 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7243 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7244 pump_msg_loop(hwnd, hAccel);
7245 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
7246
7247 ret = DestroyAcceleratorTable(hAccel);
7248 ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7249
7250 hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
7251 assert(hAccel != 0);
7252
7253 trace("testing VK_N press/release\n");
7254 flush_sequence();
7255 keybd_event('N', 0, 0, 0);
7256 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7257 pump_msg_loop(hwnd, hAccel);
7258 ok_sequence(WmVkN, "VK_N press/release", FALSE);
7259
7260 trace("testing Shift+VK_N press/release\n");
7261 flush_sequence();
7262 keybd_event(VK_SHIFT, 0, 0, 0);
7263 keybd_event('N', 0, 0, 0);
7264 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7265 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7266 pump_msg_loop(hwnd, hAccel);
7267 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
7268
7269 trace("testing Ctrl+VK_N press/release 2\n");
7270 flush_sequence();
7271 keybd_event(VK_CONTROL, 0, 0, 0);
7272 keybd_event('N', 0, 0, 0);
7273 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7274 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7275 pump_msg_loop(hwnd, hAccel);
7276 ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
7277
7278 trace("testing Alt+VK_N press/release 2\n");
7279 flush_sequence();
7280 keybd_event(VK_MENU, 0, 0, 0);
7281 keybd_event('N', 0, 0, 0);
7282 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7283 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7284 pump_msg_loop(hwnd, hAccel);
7285 ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
7286
7287 trace("testing Ctrl+Alt+VK_N press/release 2\n");
7288 flush_sequence();
7289 keybd_event(VK_CONTROL, 0, 0, 0);
7290 keybd_event(VK_MENU, 0, 0, 0);
7291 keybd_event('N', 0, 0, 0);
7292 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7293 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7294 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7295 pump_msg_loop(hwnd, hAccel);
7296 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
7297
7298 trace("testing Ctrl+Shift+VK_N press/release\n");
7299 flush_sequence();
7300 keybd_event(VK_CONTROL, 0, 0, 0);
7301 keybd_event(VK_SHIFT, 0, 0, 0);
7302 keybd_event('N', 0, 0, 0);
7303 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7304 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7305 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7306 pump_msg_loop(hwnd, hAccel);
7307 ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
7308
7309 trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
7310 flush_sequence();
7311 keybd_event(VK_CONTROL, 0, 0, 0);
7312 keybd_event(VK_MENU, 0, 0, 0);
7313 keybd_event(VK_SHIFT, 0, 0, 0);
7314 keybd_event('N', 0, 0, 0);
7315 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7316 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7317 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7318 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7319 pump_msg_loop(hwnd, hAccel);
7320 ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
7321
7322 ret = DestroyAcceleratorTable(hAccel);
7323 ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7324 hAccel = 0;
7325
7326 trace("testing Alt press/release\n");
7327 flush_sequence();
7328 keybd_event(VK_MENU, 0, 0, 0);
7329 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7330 keybd_event(VK_MENU, 0, 0, 0);
7331 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7332 pump_msg_loop(hwnd, 0);
7333 /* this test doesn't pass in Wine for managed windows */
7334 ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
7335
7336 trace("testing VK_F1 press/release\n");
7337 keybd_event(VK_F1, 0, 0, 0);
7338 keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
7339 pump_msg_loop(hwnd, 0);
7340 ok_sequence(WmF1Seq, "F1 press/release", FALSE);
7341
7342 trace("testing VK_APPS press/release\n");
7343 keybd_event(VK_APPS, 0, 0, 0);
7344 keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
7345 pump_msg_loop(hwnd, 0);
7346 ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
7347
7348 trace("testing VK_F10 press/release\n");
7349 keybd_event(VK_F10, 0, 0, 0);
7350 keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7351 keybd_event(VK_F10, 0, 0, 0);
7352 keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7353 pump_msg_loop(hwnd, 0);
7354 ok_sequence(WmVkF10Seq, "VK_F10 press/release", TRUE);
7355
7356 trace("testing SHIFT+F10 press/release\n");
7357 keybd_event(VK_SHIFT, 0, 0, 0);
7358 keybd_event(VK_F10, 0, 0, 0);
7359 keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7360 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7361 keybd_event(VK_ESCAPE, 0, 0, 0);
7362 keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0);
7363 pump_msg_loop(hwnd, 0);
7364 ok_sequence(WmShiftF10Seq, "SHIFT+F10 press/release", TRUE);
7365
7366 trace("testing Shift+MouseButton press/release\n");
7367 /* first, move mouse pointer inside of the window client area */
7368 GetClientRect(hwnd, &rc);
7369 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
7370 rc.left += (rc.right - rc.left)/2;
7371 rc.top += (rc.bottom - rc.top)/2;
7372 SetCursorPos(rc.left, rc.top);
7373 SetActiveWindow(hwnd);
7374
7375 flush_events();
7376 flush_sequence();
7377 GetCursorPos(&pt);
7378 if (pt.x == rc.left && pt.y == rc.top)
7379 {
7380 int i;
7381 keybd_event(VK_SHIFT, 0, 0, 0);
7382 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
7383 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7384 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7385 pump_msg_loop(hwnd, 0);
7386 for (i = 0; i < sequence_cnt; i++) if (sequence[i].message == WM_LBUTTONDOWN) break;
7387 if (i < sequence_cnt)
7388 ok_sequence(WmShiftMouseButton, "Shift+MouseButton press/release", FALSE);
7389 else
7390 skip( "Shift+MouseButton event didn't get to the window\n" );
7391 }
7392
7393 done:
7394 if (hAccel) DestroyAcceleratorTable(hAccel);
7395 DestroyWindow(hwnd);
7396 }
7397
7398 /************* window procedures ********************/
7399
7400 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message,
7401 WPARAM wParam, LPARAM lParam)
7402 {
7403 static LONG defwndproc_counter = 0;
7404 static LONG beginpaint_counter = 0;
7405 LRESULT ret;
7406 struct recvd_message msg;
7407
7408 if (ignore_message( message )) return 0;
7409
7410 switch (message)
7411 {
7412 case WM_ENABLE:
7413 {
7414 LONG style = GetWindowLongA(hwnd, GWL_STYLE);
7415 ok((BOOL)wParam == !(style & WS_DISABLED),
7416 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
7417 break;
7418 }
7419
7420 case WM_CAPTURECHANGED:
7421 if (test_DestroyWindow_flag)
7422 {
7423 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7424 if (style & WS_CHILD)
7425 lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7426 else if (style & WS_POPUP)
7427 lParam = WND_POPUP_ID;
7428 else
7429 lParam = WND_PARENT_ID;
7430 }
7431 break;
7432
7433 case WM_NCDESTROY:
7434 {
7435 HWND capture;
7436
7437 ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
7438 capture = GetCapture();
7439 if (capture)
7440 {
7441 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
7442 trace("current capture %p, releasing...\n", capture);
7443 ReleaseCapture();
7444 }
7445 }
7446 /* fall through */
7447 case WM_DESTROY:
7448 if (pGetAncestor)
7449 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
7450 if (test_DestroyWindow_flag)
7451 {
7452 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7453 if (style & WS_CHILD)
7454 lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7455 else if (style & WS_POPUP)
7456 lParam = WND_POPUP_ID;
7457 else
7458 lParam = WND_PARENT_ID;
7459 }
7460 break;
7461
7462 /* test_accelerators() depends on this */
7463 case WM_NCHITTEST:
7464 return HTCLIENT;
7465
7466 /* ignore */
7467 case WM_MOUSEMOVE:
7468 case WM_MOUSEACTIVATE:
7469 case WM_NCMOUSEMOVE:
7470 case WM_SETCURSOR:
7471 case WM_IME_SELECT:
7472 return 0;
7473 }
7474
7475 msg.hwnd = hwnd;
7476 msg.message = message;
7477 msg.flags = sent|wparam|lparam;
7478 if (defwndproc_counter) msg.flags |= defwinproc;
7479 if (beginpaint_counter) msg.flags |= beginpaint;
7480 msg.wParam = wParam;
7481 msg.lParam = lParam;
7482 msg.descr = "MsgCheckProc";
7483 add_message(&msg);
7484
7485 if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
7486 {
7487 HWND parent = GetParent(hwnd);
7488 RECT rc;
7489 MINMAXINFO *minmax = (MINMAXINFO *)lParam;
7490
7491 GetClientRect(parent, &rc);
7492 trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
7493 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
7494 minmax->ptReserved.x, minmax->ptReserved.y,
7495 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
7496 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
7497 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
7498 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
7499
7500 ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
7501 minmax->ptMaxSize.x, rc.right);
7502 ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
7503 minmax->ptMaxSize.y, rc.bottom);
7504 }
7505
7506 if (message == WM_PAINT)
7507 {
7508 PAINTSTRUCT ps;
7509 beginpaint_counter++;
7510 BeginPaint( hwnd, &ps );
7511 beginpaint_counter--;
7512 EndPaint( hwnd, &ps );
7513 return 0;
7514 }
7515
7516 defwndproc_counter++;
7517 ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam)
7518 : DefWindowProcA(hwnd, message, wParam, lParam);
7519 defwndproc_counter--;
7520
7521 return ret;
7522 }
7523
7524 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7525 {
7526 return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
7527 }
7528
7529 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7530 {
7531 return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
7532 }
7533
7534 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7535 {
7536 static LONG defwndproc_counter = 0;
7537 LRESULT ret;
7538 struct recvd_message msg;
7539
7540 if (ignore_message( message )) return 0;
7541
7542 switch (message)
7543 {
7544 case WM_QUERYENDSESSION:
7545 case WM_ENDSESSION:
7546 lParam &= ~0x01; /* Vista adds a 0x01 flag */
7547 break;
7548 }
7549
7550 msg.hwnd = hwnd;
7551 msg.message = message;
7552 msg.flags = sent|wparam|lparam;
7553 if (defwndproc_counter) msg.flags |= defwinproc;
7554 msg.wParam = wParam;
7555 msg.lParam = lParam;
7556 msg.descr = "popup";
7557 add_message(&msg);
7558
7559 if (message == WM_CREATE)
7560 {
7561 DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
7562 SetWindowLongA(hwnd, GWL_STYLE, style);
7563 }
7564
7565 defwndproc_counter++;
7566 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7567 defwndproc_counter--;
7568
7569 return ret;
7570 }
7571
7572 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7573 {
7574 static LONG defwndproc_counter = 0;
7575 static LONG beginpaint_counter = 0;
7576 LRESULT ret;
7577 struct recvd_message msg;
7578
7579 if (ignore_message( message )) return 0;
7580
7581 if (log_all_parent_messages ||
7582 message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
7583 message == WM_SETFOCUS || message == WM_KILLFOCUS ||
7584 message == WM_ENABLE || message == WM_ENTERIDLE ||
7585 message == WM_DRAWITEM || message == WM_COMMAND ||
7586 message == WM_IME_SETCONTEXT)
7587 {
7588 switch (message)
7589 {
7590 /* ignore */
7591 case WM_NCHITTEST:
7592 return HTCLIENT;
7593 case WM_SETCURSOR:
7594 case WM_MOUSEMOVE:
7595 case WM_NCMOUSEMOVE:
7596 return 0;
7597
7598 case WM_ERASEBKGND:
7599 {
7600 RECT rc;
7601 INT ret = GetClipBox((HDC)wParam, &rc);
7602
7603 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
7604 ret, rc.left, rc.top, rc.right, rc.bottom);
7605 break;
7606 }
7607 }
7608
7609 msg.hwnd = hwnd;
7610 msg.message = message;
7611 msg.flags = sent|parent|wparam|lparam;
7612 if (defwndproc_counter) msg.flags |= defwinproc;
7613 if (beginpaint_counter) msg.flags |= beginpaint;
7614 msg.wParam = wParam;
7615 msg.lParam = lParam;
7616 msg.descr = "parent";
7617 add_message(&msg);
7618 }
7619
7620 if (message == WM_PAINT)
7621 {
7622 PAINTSTRUCT ps;
7623 beginpaint_counter++;
7624 BeginPaint( hwnd, &ps );
7625 beginpaint_counter--;
7626 EndPaint( hwnd, &ps );
7627 return 0;
7628 }
7629
7630 defwndproc_counter++;
7631 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7632 defwndproc_counter--;
7633
7634 return ret;
7635 }
7636
7637 static INT_PTR CALLBACK StopQuitMsgCheckProcA(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
7638 {
7639 if (message == WM_CREATE)
7640 PostMessage(hwnd, WM_CLOSE, 0, 0);
7641 else if (message == WM_CLOSE)
7642 {
7643 /* Only the first WM_QUIT will survive the window destruction */
7644 PostMessage(hwnd, WM_USER, 0x1234, 0x5678);
7645 PostMessage(hwnd, WM_QUIT, 0x1234, 0x5678);
7646 PostMessage(hwnd, WM_QUIT, 0x4321, 0x8765);
7647 }
7648
7649 return DefWindowProcA(hwnd, message, wp, lp);
7650 }
7651
7652 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7653 {
7654 static LONG defwndproc_counter = 0;
7655 LRESULT ret;
7656 struct recvd_message msg;
7657
7658 if (ignore_message( message )) return 0;
7659
7660 if (test_def_id)
7661 {
7662 DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
7663 ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
7664 if (after_end_dialog)
7665 ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
7666 else
7667 ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
7668 }
7669
7670 msg.hwnd = hwnd;
7671 msg.message = message;
7672 msg.flags = sent|wparam|lparam;
7673 if (defwndproc_counter) msg.flags |= defwinproc;
7674 msg.wParam = wParam;
7675 msg.lParam = lParam;
7676 msg.descr = "dialog";
7677 add_message(&msg);
7678
7679 defwndproc_counter++;
7680 ret = DefDlgProcA(hwnd, message, wParam, lParam);
7681 defwndproc_counter--;
7682
7683 return ret;
7684 }
7685
7686 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7687 {
7688 static LONG defwndproc_counter = 0;
7689 LRESULT ret;
7690 struct recvd_message msg;
7691
7692 /* log only specific messages we are interested in */
7693 switch (message)
7694 {
7695 #if 0 /* probably log these as well */
7696 case WM_ACTIVATE:
7697 case WM_SETFOCUS:
7698 case WM_KILLFOCUS:
7699 #endif
7700 case WM_SHOWWINDOW:
7701 case WM_SIZE:
7702 case WM_MOVE:
7703 case WM_GETMINMAXINFO:
7704 case WM_WINDOWPOSCHANGING:
7705 case WM_WINDOWPOSCHANGED:
7706 break;
7707
7708 default: /* ignore */
7709 /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
7710 return DefWindowProcA(hwnd, message, wParam, lParam);
7711 }
7712
7713 msg.hwnd = hwnd;
7714 msg.message = message;
7715 msg.flags = sent|wparam|lparam;
7716 if (defwndproc_counter) msg.flags |= defwinproc;
7717 msg.wParam = wParam;
7718 msg.lParam = lParam;
7719 msg.descr = "show";
7720 add_message(&msg);
7721
7722 defwndproc_counter++;
7723 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7724 defwndproc_counter--;
7725
7726 return ret;
7727 }
7728
7729 static LRESULT WINAPI PaintLoopProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
7730 {
7731 switch (msg)
7732 {
7733 case WM_CREATE: return 0;
7734 case WM_PAINT:
7735 {
7736 MSG msg2;
7737 static int i = 0;
7738
7739 if (i < 256)
7740 {
7741 i++;
7742 if (PeekMessageA(&msg2, 0, 0, 0, 1))
7743 {
7744 TranslateMessage(&msg2);
7745 DispatchMessage(&msg2);
7746 }
7747 i--;
7748 }
7749 else ok(broken(1), "infinite loop\n");
7750 if ( i == 0)
7751 paint_loop_done = 1;
7752 return DefWindowProcA(hWnd,msg,wParam,lParam);
7753 }
7754 }
7755 return DefWindowProcA(hWnd,msg,wParam,lParam);
7756 }
7757
7758 static LRESULT WINAPI HotkeyMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7759 {
7760 static LONG defwndproc_counter = 0;
7761 LRESULT ret;
7762 struct recvd_message msg;
7763 DWORD queue_status;
7764
7765 if (ignore_message( message )) return 0;
7766
7767 if ((message >= WM_KEYFIRST && message <= WM_KEYLAST) ||
7768 message == WM_HOTKEY || message >= WM_APP)
7769 {
7770 msg.hwnd = hwnd;
7771 msg.message = message;
7772 msg.flags = sent|wparam|lparam;
7773 if (defwndproc_counter) msg.flags |= defwinproc;
7774 msg.wParam = wParam;
7775 msg.lParam = lParam;
7776 msg.descr = "HotkeyMsgCheckProcA";
7777 add_message(&msg);
7778 }
7779
7780 defwndproc_counter++;
7781 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7782 defwndproc_counter--;
7783
7784 if (message == WM_APP)
7785 {
7786 queue_status = GetQueueStatus(QS_HOTKEY);
7787 ok((queue_status & (QS_HOTKEY << 16)) == QS_HOTKEY << 16, "expected QS_HOTKEY << 16 set, got %x\n", queue_status);
7788 queue_status = GetQueueStatus(QS_POSTMESSAGE);
7789 ok((queue_status & (QS_POSTMESSAGE << 16)) == QS_POSTMESSAGE << 16, "expected QS_POSTMESSAGE << 16 set, got %x\n", queue_status);
7790 PostMessageA(hwnd, WM_APP+1, 0, 0);
7791 }
7792 else if (message == WM_APP+1)
7793 {
7794 queue_status = GetQueueStatus(QS_HOTKEY);
7795 ok((queue_status & (QS_HOTKEY << 16)) == 0, "expected QS_HOTKEY << 16 cleared, got %x\n", queue_status);
7796 }
7797
7798 return ret;
7799 }
7800
7801 static BOOL RegisterWindowClasses(void)
7802 {
7803 WNDCLASSA cls;
7804 WNDCLASSW clsW;
7805
7806 cls.style = 0;
7807 cls.lpfnWndProc = MsgCheckProcA;
7808 cls.cbClsExtra = 0;
7809 cls.cbWndExtra = 0;
7810 cls.hInstance = GetModuleHandleA(0);
7811 cls.hIcon = 0;
7812 cls.hCursor = LoadCursorA(0, IDC_ARROW);
7813 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7814 cls.lpszMenuName = NULL;
7815 cls.lpszClassName = "TestWindowClass";
7816 if(!RegisterClassA(&cls)) return FALSE;
7817
7818 cls.lpfnWndProc = HotkeyMsgCheckProcA;
7819 cls.lpszClassName = "HotkeyWindowClass";
7820 if(!RegisterClassA(&cls)) return FALSE;
7821
7822 cls.lpfnWndProc = ShowWindowProcA;
7823 cls.lpszClassName = "ShowWindowClass";
7824 if(!RegisterClassA(&cls)) return FALSE;
7825
7826 cls.lpfnWndProc = PopupMsgCheckProcA;
7827 cls.lpszClassName = "TestPopupClass";
7828 if(!RegisterClassA(&cls)) return FALSE;
7829
7830 cls.lpfnWndProc = ParentMsgCheckProcA;
7831 cls.lpszClassName = "TestParentClass";
7832 if(!RegisterClassA(&cls)) return FALSE;
7833
7834 cls.lpfnWndProc = StopQuitMsgCheckProcA;
7835 cls.lpszClassName = "StopQuitClass";
7836 if(!RegisterClassA(&cls)) return FALSE;
7837
7838 cls.lpfnWndProc = DefWindowProcA;
7839 cls.lpszClassName = "SimpleWindowClass";
7840 if(!RegisterClassA(&cls)) return FALSE;
7841
7842 cls.lpfnWndProc = PaintLoopProcA;
7843 cls.lpszClassName = "PaintLoopWindowClass";
7844 if(!RegisterClassA(&cls)) return FALSE;
7845
7846 cls.style = CS_NOCLOSE;
7847 cls.lpszClassName = "NoCloseWindowClass";
7848 if(!RegisterClassA(&cls)) return FALSE;
7849
7850 ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
7851 cls.style = 0;
7852 cls.hInstance = GetModuleHandleA(0);
7853 cls.hbrBackground = 0;
7854 cls.lpfnWndProc = TestDlgProcA;
7855 cls.lpszClassName = "TestDialogClass";
7856 if(!RegisterClassA(&cls)) return FALSE;
7857
7858 clsW.style = 0;
7859 clsW.lpfnWndProc = MsgCheckProcW;
7860 clsW.cbClsExtra = 0;
7861 clsW.cbWndExtra = 0;
7862 clsW.hInstance = GetModuleHandleW(0);
7863 clsW.hIcon = 0;
7864 clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
7865 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
7866 clsW.lpszMenuName = NULL;
7867 clsW.lpszClassName = testWindowClassW;
7868 RegisterClassW(&clsW); /* ignore error, this fails on Win9x */
7869
7870 return TRUE;
7871 }
7872
7873 static BOOL is_our_logged_class(HWND hwnd)
7874 {
7875 char buf[256];
7876
7877 if (GetClassNameA(hwnd, buf, sizeof(buf)))
7878 {
7879 if (!lstrcmpiA(buf, "TestWindowClass") ||
7880 !lstrcmpiA(buf, "ShowWindowClass") ||
7881 !lstrcmpiA(buf, "TestParentClass") ||
7882 !lstrcmpiA(buf, "TestPopupClass") ||
7883 !lstrcmpiA(buf, "SimpleWindowClass") ||
7884 !lstrcmpiA(buf, "TestDialogClass") ||
7885 !lstrcmpiA(buf, "MDI_frame_class") ||
7886 !lstrcmpiA(buf, "MDI_client_class") ||
7887 !lstrcmpiA(buf, "MDI_child_class") ||
7888 !lstrcmpiA(buf, "my_button_class") ||
7889 !lstrcmpiA(buf, "my_edit_class") ||
7890 !lstrcmpiA(buf, "static") ||
7891 !lstrcmpiA(buf, "ListBox") ||
7892 !lstrcmpiA(buf, "ComboBox") ||
7893 !lstrcmpiA(buf, "MyDialogClass") ||
7894 !lstrcmpiA(buf, "#32770") ||
7895 !lstrcmpiA(buf, "#32768"))
7896 return TRUE;
7897 }
7898 return FALSE;
7899 }
7900
7901 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
7902 {
7903 HWND hwnd;
7904
7905 ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7906
7907 if (nCode == HCBT_CLICKSKIPPED)
7908 {
7909 /* ignore this event, XP sends it a lot when switching focus between windows */
7910 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7911 }
7912
7913 if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
7914 {
7915 struct recvd_message msg;
7916
7917 msg.hwnd = 0;
7918 msg.message = nCode;
7919 msg.flags = hook|wparam|lparam;
7920 msg.wParam = wParam;
7921 msg.lParam = lParam;
7922 msg.descr = "CBT";
7923 add_message(&msg);
7924
7925 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7926 }
7927
7928 if (nCode == HCBT_DESTROYWND)
7929 {
7930 if (test_DestroyWindow_flag)
7931 {
7932 DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
7933 if (style & WS_CHILD)
7934 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
7935 else if (style & WS_POPUP)
7936 lParam = WND_POPUP_ID;
7937 else
7938 lParam = WND_PARENT_ID;
7939 }
7940 }
7941
7942 /* Log also SetFocus(0) calls */
7943 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7944
7945 if (is_our_logged_class(hwnd))
7946 {
7947 struct recvd_message msg;
7948
7949 msg.hwnd = hwnd;
7950 msg.message = nCode;
7951 msg.flags = hook|wparam|lparam;
7952 msg.wParam = wParam;
7953 msg.lParam = lParam;
7954 msg.descr = "CBT";
7955 add_message(&msg);
7956 }
7957 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7958 }
7959
7960 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
7961 DWORD event,
7962 HWND hwnd,
7963 LONG object_id,
7964 LONG child_id,
7965 DWORD thread_id,
7966 DWORD event_time)
7967 {
7968 ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7969
7970 /* ignore mouse cursor events */
7971 if (object_id == OBJID_CURSOR) return;
7972
7973 if (!hwnd || is_our_logged_class(hwnd))
7974 {
7975 struct recvd_message msg;
7976
7977 msg.hwnd = hwnd;
7978 msg.message = event;
7979 msg.flags = winevent_hook|wparam|lparam;
7980 msg.wParam = object_id;
7981 msg.lParam = child_id;
7982 msg.descr = "WEH";
7983 add_message(&msg);
7984 }
7985 }
7986
7987 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
7988 static const WCHAR wszAnsi[] = {'U',0};
7989
7990 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
7991 {
7992 switch (uMsg)
7993 {
7994 case CB_FINDSTRINGEXACT:
7995 trace("String: %p\n", (LPCWSTR)lParam);
7996 if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
7997 return 1;
7998 if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
7999 return 0;
8000 return -1;
8001 }
8002 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
8003 }
8004
8005 static const struct message WmGetTextLengthAfromW[] = {
8006 { WM_GETTEXTLENGTH, sent },
8007 { WM_GETTEXT, sent|optional },
8008 { 0 }
8009 };
8010
8011 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
8012
8013 /* dummy window proc for WM_GETTEXTLENGTH test */
8014 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
8015 {
8016 switch(msg)
8017 {
8018 case WM_GETTEXTLENGTH:
8019 return lstrlenW(dummy_window_text) + 37; /* some random length */
8020 case WM_GETTEXT:
8021 lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
8022 return lstrlenW( (LPWSTR)lp );
8023 default:
8024 return DefWindowProcW( hwnd, msg, wp, lp );
8025 }
8026 }
8027
8028 static void test_message_conversion(void)
8029 {
8030 static const WCHAR wszMsgConversionClass[] =
8031 {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
8032 WNDCLASSW cls;
8033 LRESULT lRes;
8034 HWND hwnd;
8035 WNDPROC wndproc, newproc;
8036 BOOL ret;
8037
8038 cls.style = 0;
8039 cls.lpfnWndProc = MsgConversionProcW;
8040 cls.cbClsExtra = 0;
8041 cls.cbWndExtra = 0;
8042 cls.hInstance = GetModuleHandleW(NULL);
8043 cls.hIcon = NULL;
8044 cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
8045 cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
8046 cls.lpszMenuName = NULL;
8047 cls.lpszClassName = wszMsgConversionClass;
8048 /* this call will fail on Win9x, but that doesn't matter as this test is
8049 * meaningless on those platforms */
8050 if(!RegisterClassW(&cls)) return;
8051
8052 hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
8053 100, 100, 200, 200, 0, 0, 0, NULL);
8054 ok(hwnd != NULL, "Window creation failed\n");
8055
8056 /* {W, A} -> A */
8057
8058 wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
8059 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8060 ok(lRes == 0, "String should have been converted\n");
8061 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8062 ok(lRes == 1, "String shouldn't have been converted\n");
8063
8064 /* {W, A} -> W */
8065
8066 wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
8067 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8068 ok(lRes == 1, "String shouldn't have been converted\n");
8069 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8070 ok(lRes == 1, "String shouldn't have been converted\n");
8071
8072 /* Synchronous messages */
8073
8074 lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8075 ok(lRes == 0, "String should have been converted\n");
8076 lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8077 ok(lRes == 1, "String shouldn't have been converted\n");
8078
8079 /* Asynchronous messages */
8080
8081 SetLastError(0);
8082 lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8083 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8084 "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8085 SetLastError(0);
8086 lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8087 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8088 "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8089 SetLastError(0);
8090 lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8091 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8092 "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8093 SetLastError(0);
8094 lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8095 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8096 "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8097 SetLastError(0);
8098 lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8099 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8100 "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8101 SetLastError(0);
8102 lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8103 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8104 "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8105 SetLastError(0);
8106 lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
8107 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8108 "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8109 SetLastError(0);
8110 lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
8111 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8112 "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8113
8114 /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
8115
8116 hwnd = CreateWindowW (testWindowClassW, wszUnicode,
8117 WS_OVERLAPPEDWINDOW,
8118 100, 100, 200, 200, 0, 0, 0, NULL);
8119 assert(hwnd);
8120 flush_sequence();
8121 lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
8122 ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
8123 ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
8124 "got bad length %ld\n", lRes );
8125
8126 flush_sequence();
8127 lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
8128 hwnd, WM_GETTEXTLENGTH, 0, 0);
8129 ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
8130 ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
8131 "got bad length %ld\n", lRes );
8132
8133 wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
8134 newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
8135 lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
8136 ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
8137 NULL, 0, NULL, NULL ) ||
8138 broken(lRes == lstrlenW(dummy_window_text) + 37),
8139 "got bad length %ld\n", lRes );
8140
8141 SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc ); /* restore old wnd proc */
8142 lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
8143 ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
8144 NULL, 0, NULL, NULL ) ||
8145 broken(lRes == lstrlenW(dummy_window_text) + 37),
8146 "got bad length %ld\n", lRes );
8147
8148 ret = DestroyWindow(hwnd);
8149 ok( ret, "DestroyWindow() error %d\n", GetLastError());
8150 }
8151
8152 struct timer_info
8153 {
8154 HWND hWnd;
8155 HANDLE handles[2];
8156 DWORD id;
8157 };
8158
8159 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
8160 {
8161 }
8162
8163 #define TIMER_ID 0x19
8164 #define TIMER_COUNT_EXPECTED 64
8165 #define TIMER_COUNT_TOLERANCE 9
8166
8167 static int count = 0;
8168 static void CALLBACK callback_count(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
8169 {
8170 count++;
8171 }
8172
8173 static DWORD WINAPI timer_thread_proc(LPVOID x)
8174 {
8175 struct timer_info *info = x;
8176 DWORD r;
8177
8178 r = KillTimer(info->hWnd, 0x19);
8179 ok(r,"KillTimer failed in thread\n");
8180 r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
8181 ok(r,"SetTimer failed in thread\n");
8182 ok(r==TIMER_ID,"SetTimer id different\n");
8183 r = SetEvent(info->handles[0]);
8184 ok(r,"SetEvent failed in thread\n");
8185 return 0;
8186 }
8187
8188 static void test_timers(void)
8189 {
8190 struct timer_info info;
8191 DWORD start;
8192 DWORD id;
8193 MSG msg;
8194
8195 info.hWnd = CreateWindow ("TestWindowClass", NULL,
8196 WS_OVERLAPPEDWINDOW ,
8197 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8198 NULL, NULL, 0);
8199
8200 info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
8201 ok(info.id, "SetTimer failed\n");
8202 ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
8203 info.handles[0] = CreateEvent(NULL,0,0,NULL);
8204 info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
8205
8206 WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
8207
8208 WaitForSingleObject(info.handles[1], INFINITE);
8209
8210 CloseHandle(info.handles[0]);
8211 CloseHandle(info.handles[1]);
8212
8213 ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
8214
8215 /* Check the minimum allowed timeout for a timer. MSDN indicates that it should be 10.0 ms,
8216 * but testing indicates that the minimum timeout is actually about 15.6 ms. Since there is
8217 * some measurement error between test runs we're allowing for ±8 counts (~2 ms).
8218 */
8219 count = 0;
8220 id = SetTimer(info.hWnd, TIMER_ID, 0, callback_count);
8221 ok(id != 0, "did not get id from SetTimer.\n");
8222 ok(id==TIMER_ID, "SetTimer timer ID different\n");
8223 start = GetTickCount();
8224 while (GetTickCount()-start < 1001 && GetMessage(&msg, info.hWnd, 0, 0))
8225 DispatchMessage(&msg);
8226 ok(abs(count-TIMER_COUNT_EXPECTED) < TIMER_COUNT_TOLERANCE
8227 || broken(abs(count-43) < TIMER_COUNT_TOLERANCE) /* w2k3 */,
8228 "did not get expected count for minimum timeout (%d != ~%d).\n",
8229 count, TIMER_COUNT_EXPECTED);
8230 ok(KillTimer(info.hWnd, id), "KillTimer failed\n");
8231 /* Perform the same check on SetSystemTimer (only available on w2k3 and older) */
8232 if (pSetSystemTimer)
8233 {
8234 int syscount = 0;
8235
8236 count = 0;
8237 id = pSetSystemTimer(info.hWnd, TIMER_ID, 0, callback_count);
8238 ok(id != 0, "did not get id from SetSystemTimer.\n");
8239 ok(id==TIMER_ID, "SetTimer timer ID different\n");
8240 start = GetTickCount();
8241 while (GetTickCount()-start < 1001 && GetMessage(&msg, info.hWnd, 0, 0))
8242 {
8243 if (msg.message == WM_SYSTIMER)
8244 syscount++;
8245 DispatchMessage(&msg);
8246 }
8247 ok(abs(syscount-TIMER_COUNT_EXPECTED) < TIMER_COUNT_TOLERANCE,
8248 "did not get expected count for minimum timeout (%d != ~%d).\n",
8249 syscount, TIMER_COUNT_EXPECTED);
8250 todo_wine ok(count == 0, "did not get expected count for callback timeout (%d != 0).\n",
8251 count);
8252 ok(pKillSystemTimer(info.hWnd, id), "KillSystemTimer failed\n");
8253 }
8254
8255 ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
8256 }
8257
8258 static void test_timers_no_wnd(void)
8259 {
8260 UINT_PTR id, id2;
8261 DWORD start;
8262 MSG msg;
8263
8264 count = 0;
8265 id = SetTimer(NULL, 0, 100, callback_count);
8266 ok(id != 0, "did not get id from SetTimer.\n");
8267 id2 = SetTimer(NULL, id, 200, callback_count);
8268 ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
8269 Sleep(150);
8270 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8271 ok(count == 0, "did not get zero count as expected (%i).\n", count);
8272 Sleep(150);
8273 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8274 ok(count == 1, "did not get one count as expected (%i).\n", count);
8275 KillTimer(NULL, id);
8276 Sleep(250);
8277 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
8278 ok(count == 1, "killing replaced timer did not work (%i).\n", count);
8279
8280 /* Check the minimum allowed timeout for a timer. MSDN indicates that it should be 10.0 ms,
8281 * but testing indicates that the minimum timeout is actually about 15.6 ms. Since there is
8282 * some measurement error between test runs we're allowing for ±8 counts (~2 ms).
8283 */
8284 count = 0;
8285 id = SetTimer(NULL, 0, 0, callback_count);
8286 ok(id != 0, "did not get id from SetTimer.\n");
8287 start = GetTickCount();
8288 while (GetTickCount()-start < 1001 && GetMessage(&msg, NULL, 0, 0))
8289 DispatchMessage(&msg);
8290 ok(abs(count-TIMER_COUNT_EXPECTED) < TIMER_COUNT_TOLERANCE,
8291 "did not get expected count for minimum timeout (%d != ~%d).\n",
8292 count, TIMER_COUNT_EXPECTED);
8293 KillTimer(NULL, id);
8294 /* Note: SetSystemTimer doesn't support a NULL window, see test_timers */
8295 }
8296
8297 /* Various win events with arbitrary parameters */
8298 static const struct message WmWinEventsSeq[] = {
8299 { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
8300 { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
8301 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
8302 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
8303 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
8304 { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
8305 { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
8306 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
8307 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
8308 /* our win event hook ignores OBJID_CURSOR events */
8309 /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
8310 { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
8311 { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
8312 { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
8313 { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
8314 { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
8315 { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
8316 { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
8317 { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
8318 { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
8319 { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
8320 { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
8321 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
8322 { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
8323 { 0 }
8324 };
8325 static const struct message WmWinEventCaretSeq[] = {
8326 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8327 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8328 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
8329 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8330 { 0 }
8331 };
8332 static const struct message WmWinEventCaretSeq_2[] = {
8333 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8334 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8335 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8336 { 0 }
8337 };
8338 static const struct message WmWinEventAlertSeq[] = {
8339 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
8340 { 0 }
8341 };
8342 static const struct message WmWinEventAlertSeq_2[] = {
8343 /* create window in the thread proc */
8344 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
8345 /* our test event */
8346 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
8347 { 0 }
8348 };
8349 static const struct message WmGlobalHookSeq_1[] = {
8350 /* create window in the thread proc */
8351 { HCBT_CREATEWND, hook|lparam, 0, 2 },
8352 /* our test events */
8353 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
8354 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
8355 { 0 }
8356 };
8357 static const struct message WmGlobalHookSeq_2[] = {
8358 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
8359 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
8360 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
8361 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
8362 { 0 }
8363 };
8364
8365 static const struct message WmMouseLLHookSeq[] = {
8366 { WM_MOUSEMOVE, hook },
8367 { WM_LBUTTONUP, hook },
8368 { WM_MOUSEMOVE, hook },
8369 { 0 }
8370 };
8371
8372 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
8373 DWORD event,
8374 HWND hwnd,
8375 LONG object_id,
8376 LONG child_id,
8377 DWORD thread_id,
8378 DWORD event_time)
8379 {
8380 char buf[256];
8381
8382 if (GetClassNameA(hwnd, buf, sizeof(buf)))
8383 {
8384 if (!lstrcmpiA(buf, "TestWindowClass") ||
8385 !lstrcmpiA(buf, "static"))
8386 {
8387 struct recvd_message msg;
8388
8389 msg.hwnd = hwnd;
8390 msg.message = event;
8391 msg.flags = winevent_hook|wparam|lparam;
8392 msg.wParam = object_id;
8393 msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
8394 msg.descr = "WEH_2";
8395 add_message(&msg);
8396 }
8397 }
8398 }
8399
8400 static HHOOK hCBT_global_hook;
8401 static DWORD cbt_global_hook_thread_id;
8402
8403 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
8404 {
8405 HWND hwnd;
8406 char buf[256];
8407
8408 if (nCode == HCBT_SYSCOMMAND)
8409 {
8410 struct recvd_message msg;
8411
8412 msg.hwnd = 0;
8413 msg.message = nCode;
8414 msg.flags = hook|wparam|lparam;
8415 msg.wParam = wParam;
8416 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8417 msg.descr = "CBT_2";
8418 add_message(&msg);
8419
8420 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8421 }
8422 /* WH_MOUSE_LL hook */
8423 if (nCode == HC_ACTION)
8424 {
8425 MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
8426
8427 /* we can't test for real mouse events */
8428 if (mhll->flags & LLMHF_INJECTED)
8429 {
8430 struct recvd_message msg;
8431
8432 memset (&msg, 0, sizeof (msg));
8433 msg.message = wParam;
8434 msg.flags = hook;
8435 msg.descr = "CBT_2";
8436 add_message(&msg);
8437 }
8438 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8439 }
8440
8441 /* Log also SetFocus(0) calls */
8442 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
8443
8444 if (GetClassNameA(hwnd, buf, sizeof(buf)))
8445 {
8446 if (!lstrcmpiA(buf, "TestWindowClass") ||
8447 !lstrcmpiA(buf, "static"))
8448 {
8449 struct recvd_message msg;
8450
8451 msg.hwnd = hwnd;
8452 msg.message = nCode;
8453 msg.flags = hook|wparam|lparam;
8454 msg.wParam = wParam;
8455 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8456 msg.descr = "CBT_2";
8457 add_message(&msg);
8458 }
8459 }
8460 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8461 }
8462
8463 static DWORD WINAPI win_event_global_thread_proc(void *param)
8464 {
8465 HWND hwnd;
8466 MSG msg;
8467 HANDLE hevent = *(HANDLE *)param;
8468
8469 assert(pNotifyWinEvent);
8470
8471 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8472 assert(hwnd);
8473 trace("created thread window %p\n", hwnd);
8474
8475 *(HWND *)param = hwnd;
8476
8477 flush_sequence();
8478 /* this event should be received only by our new hook proc,
8479 * an old one does not expect an event from another thread.
8480 */
8481 pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
8482 SetEvent(hevent);
8483
8484 while (GetMessage(&msg, 0, 0, 0))
8485 {
8486 TranslateMessage(&msg);
8487 DispatchMessage(&msg);
8488 }
8489 return 0;
8490 }
8491
8492 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
8493 {
8494 HWND hwnd;
8495 MSG msg;
8496 HANDLE hevent = *(HANDLE *)param;
8497
8498 flush_sequence();
8499 /* these events should be received only by our new hook proc,
8500 * an old one does not expect an event from another thread.
8501 */
8502
8503 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8504 assert(hwnd);
8505 trace("created thread window %p\n", hwnd);
8506
8507 *(HWND *)param = hwnd;
8508
8509 /* Windows doesn't like when a thread plays games with the focus,
8510 that leads to all kinds of misbehaviours and failures to activate
8511 a window. So, better keep next lines commented out.
8512 SetFocus(0);
8513 SetFocus(hwnd);*/
8514
8515 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8516 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8517
8518 SetEvent(hevent);
8519
8520 while (GetMessage(&msg, 0, 0, 0))
8521 {
8522 TranslateMessage(&msg);
8523 DispatchMessage(&msg);
8524 }
8525 return 0;
8526 }
8527
8528 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
8529 {
8530 HWND hwnd;
8531 MSG msg;
8532 HANDLE hevent = *(HANDLE *)param;
8533
8534 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8535 assert(hwnd);
8536 trace("created thread window %p\n", hwnd);
8537
8538 *(HWND *)param = hwnd;
8539
8540 flush_sequence();
8541
8542 /* Windows doesn't like when a thread plays games with the focus,
8543 * that leads to all kinds of misbehaviours and failures to activate
8544 * a window. So, better don't generate a mouse click message below.
8545 */
8546 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8547 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8548 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8549
8550 SetEvent(hevent);
8551 while (GetMessage(&msg, 0, 0, 0))
8552 {
8553 TranslateMessage(&msg);
8554 DispatchMessage(&msg);
8555 }
8556 return 0;
8557 }
8558
8559 static void test_winevents(void)
8560 {
8561 BOOL ret;
8562 MSG msg;
8563 HWND hwnd, hwnd2;
8564 UINT i;
8565 HANDLE hthread, hevent;
8566 DWORD tid;
8567 HWINEVENTHOOK hhook;
8568 const struct message *events = WmWinEventsSeq;
8569
8570 hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
8571 WS_OVERLAPPEDWINDOW,
8572 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8573 NULL, NULL, 0);
8574 assert(hwnd);
8575
8576 /****** start of global hook test *************/
8577 hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8578 if (!hCBT_global_hook)
8579 {
8580 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8581 skip( "cannot set global hook\n" );
8582 return;
8583 }
8584
8585 hevent = CreateEventA(NULL, 0, 0, NULL);
8586 assert(hevent);
8587 hwnd2 = hevent;
8588
8589 hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
8590 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8591
8592 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8593
8594 ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
8595
8596 flush_sequence();
8597 /* this one should be received only by old hook proc */
8598 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8599 /* this one should be received only by old hook proc */
8600 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8601
8602 ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
8603
8604 ret = UnhookWindowsHookEx(hCBT_global_hook);
8605 ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8606
8607 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8608 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8609 CloseHandle(hthread);
8610 CloseHandle(hevent);
8611 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8612 /****** end of global hook test *************/
8613
8614 if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
8615 {
8616 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8617 return;
8618 }
8619
8620 flush_sequence();
8621
8622 if (0)
8623 {
8624 /* this test doesn't pass under Win9x */
8625 /* win2k ignores events with hwnd == 0 */
8626 SetLastError(0xdeadbeef);
8627 pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
8628 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
8629 GetLastError() == 0xdeadbeef, /* Win9x */
8630 "unexpected error %d\n", GetLastError());
8631 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8632 }
8633
8634 for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
8635 pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
8636
8637 ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
8638
8639 /****** start of event filtering test *************/
8640 hhook = pSetWinEventHook(
8641 EVENT_OBJECT_SHOW, /* 0x8002 */
8642 EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
8643 GetModuleHandleA(0), win_event_global_hook_proc,
8644 GetCurrentProcessId(), 0,
8645 WINEVENT_INCONTEXT);
8646 ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8647
8648 hevent = CreateEventA(NULL, 0, 0, NULL);
8649 assert(hevent);
8650 hwnd2 = hevent;
8651
8652 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8653 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8654
8655 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8656
8657 ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
8658
8659 flush_sequence();
8660 /* this one should be received only by old hook proc */
8661 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8662 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8663 /* this one should be received only by old hook proc */
8664 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8665
8666 ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
8667
8668 ret = pUnhookWinEvent(hhook);
8669 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8670
8671 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8672 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8673 CloseHandle(hthread);
8674 CloseHandle(hevent);
8675 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8676 /****** end of event filtering test *************/
8677
8678 /****** start of out of context event test *************/
8679 hhook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0,
8680 win_event_global_hook_proc, GetCurrentProcessId(), 0,
8681 WINEVENT_OUTOFCONTEXT);
8682 ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8683
8684 hevent = CreateEventA(NULL, 0, 0, NULL);
8685 assert(hevent);
8686 hwnd2 = hevent;
8687
8688 flush_sequence();
8689
8690 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8691 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8692
8693 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8694
8695 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8696 /* process pending winevent messages */
8697 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8698 ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
8699
8700 flush_sequence();
8701 /* this one should be received only by old hook proc */
8702 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8703 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8704 /* this one should be received only by old hook proc */
8705 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8706
8707 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
8708 /* process pending winevent messages */
8709 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8710 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
8711
8712 ret = pUnhookWinEvent(hhook);
8713 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8714
8715 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8716 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8717 CloseHandle(hthread);
8718 CloseHandle(hevent);
8719 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8720 /****** end of out of context event test *************/
8721
8722 /****** start of MOUSE_LL hook test *************/
8723 hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8724 /* WH_MOUSE_LL is not supported on Win9x platforms */
8725 if (!hCBT_global_hook)
8726 {
8727 win_skip("Skipping WH_MOUSE_LL test on this platform\n");
8728 goto skip_mouse_ll_hook_test;
8729 }
8730
8731 hevent = CreateEventA(NULL, 0, 0, NULL);
8732 assert(hevent);
8733 hwnd2 = hevent;
8734
8735 hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
8736 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8737
8738 while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
8739 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
8740
8741 ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
8742 flush_sequence();
8743
8744 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8745 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8746 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8747
8748 ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
8749
8750 ret = UnhookWindowsHookEx(hCBT_global_hook);
8751 ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8752
8753 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8754 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8755 CloseHandle(hthread);
8756 CloseHandle(hevent);
8757 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8758 /****** end of MOUSE_LL hook test *************/
8759 skip_mouse_ll_hook_test:
8760
8761 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8762 }
8763
8764 static void test_set_hook(void)
8765 {
8766 BOOL ret;
8767 HHOOK hhook;
8768 HWINEVENTHOOK hwinevent_hook;
8769
8770 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
8771 ok(hhook != 0, "local hook does not require hModule set to 0\n");
8772 UnhookWindowsHookEx(hhook);
8773
8774 if (0)
8775 {
8776 /* this test doesn't pass under Win9x: BUG! */
8777 SetLastError(0xdeadbeef);
8778 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
8779 ok(!hhook, "global hook requires hModule != 0\n");
8780 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
8781 }
8782
8783 SetLastError(0xdeadbeef);
8784 hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
8785 ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
8786 ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
8787 GetLastError() == 0xdeadbeef, /* Win9x */
8788 "unexpected error %d\n", GetLastError());
8789
8790 SetLastError(0xdeadbeef);
8791 ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
8792 ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
8793 GetLastError() == 0xdeadbeef, /* Win9x */
8794 "unexpected error %d\n", GetLastError());
8795
8796 if (!pSetWinEventHook || !pUnhookWinEvent) return;
8797
8798 /* even process local incontext hooks require hmodule */
8799 SetLastError(0xdeadbeef);
8800 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8801 GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
8802 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8803 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8804 GetLastError() == 0xdeadbeef, /* Win9x */
8805 "unexpected error %d\n", GetLastError());
8806
8807 /* even thread local incontext hooks require hmodule */
8808 SetLastError(0xdeadbeef);
8809 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8810 GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
8811 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8812 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8813 GetLastError() == 0xdeadbeef, /* Win9x */
8814 "unexpected error %d\n", GetLastError());
8815
8816 if (0)
8817 {
8818 /* these 3 tests don't pass under Win9x */
8819 SetLastError(0xdeadbeef);
8820 hwinevent_hook = pSetWinEventHook(1, 0, 0, win_event_proc,
8821 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8822 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8823 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8824
8825 SetLastError(0xdeadbeef);
8826 hwinevent_hook = pSetWinEventHook(-1, 1, 0, win_event_proc,
8827 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8828 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8829 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8830
8831 SetLastError(0xdeadbeef);
8832 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8833 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
8834 ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
8835 ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
8836 }
8837
8838 SetLastError(0xdeadbeef);
8839 hwinevent_hook = pSetWinEventHook(0, 0, 0, win_event_proc,
8840 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8841 ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8842 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8843 ret = pUnhookWinEvent(hwinevent_hook);
8844 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8845
8846 todo_wine {
8847 /* This call succeeds under win2k SP4, but fails under Wine.
8848 Does win2k test/use passed process id? */
8849 SetLastError(0xdeadbeef);
8850 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8851 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
8852 ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8853 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8854 ret = pUnhookWinEvent(hwinevent_hook);
8855 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8856 }
8857
8858 SetLastError(0xdeadbeef);
8859 ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
8860 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
8861 GetLastError() == 0xdeadbeef, /* Win9x */
8862 "unexpected error %d\n", GetLastError());
8863 }
8864
8865 static const struct message ScrollWindowPaint1[] = {
8866 { WM_PAINT, sent },
8867 { WM_ERASEBKGND, sent|beginpaint },
8868 { WM_GETTEXTLENGTH, sent|optional },
8869 { WM_PAINT, sent|optional },
8870 { WM_NCPAINT, sent|beginpaint|optional },
8871 { WM_GETTEXT, sent|beginpaint|optional },
8872 { WM_GETTEXT, sent|beginpaint|optional },
8873 { WM_GETTEXT, sent|beginpaint|optional },
8874 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
8875 { WM_ERASEBKGND, sent|beginpaint|optional },
8876 { 0 }
8877 };
8878
8879 static const struct message ScrollWindowPaint2[] = {
8880 { WM_PAINT, sent },
8881 { 0 }
8882 };
8883
8884 static void test_scrollwindowex(void)
8885 {
8886 HWND hwnd, hchild;
8887 RECT rect={0,0,130,130};
8888
8889 hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
8890 WS_VISIBLE|WS_OVERLAPPEDWINDOW,
8891 100, 100, 200, 200, 0, 0, 0, NULL);
8892 ok (hwnd != 0, "Failed to create overlapped window\n");
8893 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
8894 WS_VISIBLE|WS_CAPTION|WS_CHILD,
8895 10, 10, 150, 150, hwnd, 0, 0, NULL);
8896 ok (hchild != 0, "Failed to create child\n");
8897 UpdateWindow(hwnd);
8898 flush_events();
8899 flush_sequence();
8900
8901 /* scroll without the child window */
8902 trace("start scroll\n");
8903 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8904 SW_ERASE|SW_INVALIDATE);
8905 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8906 trace("end scroll\n");
8907 flush_sequence();
8908 flush_events();
8909 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8910 flush_events();
8911 flush_sequence();
8912
8913 /* Now without the SW_ERASE flag */
8914 trace("start scroll\n");
8915 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
8916 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8917 trace("end scroll\n");
8918 flush_sequence();
8919 flush_events();
8920 ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
8921 flush_events();
8922 flush_sequence();
8923
8924 /* now scroll the child window as well */
8925 trace("start scroll\n");
8926 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8927 SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
8928 /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
8929 /* windows sometimes a WM_MOVE */
8930 ok_sequence(WmEmptySeq, "ScrollWindowEx", TRUE);
8931 trace("end scroll\n");
8932 flush_sequence();
8933 flush_events();
8934 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8935 flush_events();
8936 flush_sequence();
8937
8938 /* now scroll with ScrollWindow() */
8939 trace("start scroll with ScrollWindow\n");
8940 ScrollWindow( hwnd, 5, 5, NULL, NULL);
8941 trace("end scroll\n");
8942 flush_sequence();
8943 flush_events();
8944 ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
8945
8946 ok(DestroyWindow(hchild), "failed to destroy window\n");
8947 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8948 flush_sequence();
8949 }
8950
8951 static const struct message destroy_window_with_children[] = {
8952 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8953 { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
8954 { 0x0090, sent|optional },
8955 { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
8956 { 0x0090, sent|optional },
8957 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8958 { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8959 { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8960 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8961 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
8962 { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8963 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8964 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8965 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8966 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8967 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8968 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8969 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8970 { 0 }
8971 };
8972
8973 static void test_DestroyWindow(void)
8974 {
8975 BOOL ret;
8976 HWND parent, child1, child2, child3, child4, test;
8977 UINT_PTR child_id = WND_CHILD_ID + 1;
8978
8979 parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8980 100, 100, 200, 200, 0, 0, 0, NULL);
8981 assert(parent != 0);
8982 child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8983 0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
8984 assert(child1 != 0);
8985 child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8986 0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
8987 assert(child2 != 0);
8988 child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8989 0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
8990 assert(child3 != 0);
8991 child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
8992 0, 0, 50, 50, parent, 0, 0, NULL);
8993 assert(child4 != 0);
8994
8995 /* test owner/parent of child2 */
8996 test = GetParent(child2);
8997 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8998 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8999 if(pGetAncestor) {
9000 test = pGetAncestor(child2, GA_PARENT);
9001 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
9002 }
9003 test = GetWindow(child2, GW_OWNER);
9004 ok(!test, "wrong owner %p\n", test);
9005
9006 test = SetParent(child2, parent);
9007 ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
9008
9009 /* test owner/parent of the parent */
9010 test = GetParent(parent);
9011 ok(!test, "wrong parent %p\n", test);
9012 ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
9013 if(pGetAncestor) {
9014 test = pGetAncestor(parent, GA_PARENT);
9015 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
9016 }
9017 test = GetWindow(parent, GW_OWNER);
9018 ok(!test, "wrong owner %p\n", test);
9019
9020 /* test owner/parent of child1 */
9021 test = GetParent(child1);
9022 ok(test == parent, "wrong parent %p\n", test);
9023 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
9024 if(pGetAncestor) {
9025 test = pGetAncestor(child1, GA_PARENT);
9026 ok(test == parent, "wrong parent %p\n", test);
9027 }
9028 test = GetWindow(child1, GW_OWNER);
9029 ok(!test, "wrong owner %p\n", test);
9030
9031 /* test owner/parent of child2 */
9032 test = GetParent(child2);
9033 ok(test == parent, "wrong parent %p\n", test);
9034 ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
9035 if(pGetAncestor) {
9036 test = pGetAncestor(child2, GA_PARENT);
9037 ok(test == parent, "wrong parent %p\n", test);
9038 }
9039 test = GetWindow(child2, GW_OWNER);
9040 ok(!test, "wrong owner %p\n", test);
9041
9042 /* test owner/parent of child3 */
9043 test = GetParent(child3);
9044 ok(test == child1, "wrong parent %p\n", test);
9045 ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
9046 if(pGetAncestor) {
9047 test = pGetAncestor(child3, GA_PARENT);
9048 ok(test == child1, "wrong parent %p\n", test);
9049 }
9050 test = GetWindow(child3, GW_OWNER);
9051 ok(!test, "wrong owner %p\n", test);
9052
9053 /* test owner/parent of child4 */
9054 test = GetParent(child4);
9055 ok(test == parent, "wrong parent %p\n", test);
9056 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
9057 if(pGetAncestor) {
9058 test = pGetAncestor(child4, GA_PARENT);
9059 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
9060 }
9061 test = GetWindow(child4, GW_OWNER);
9062 ok(test == parent, "wrong owner %p\n", test);
9063
9064 flush_sequence();
9065
9066 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
9067 parent, child1, child2, child3, child4);
9068
9069 SetCapture(child4);
9070 test = GetCapture();
9071 ok(test == child4, "wrong capture window %p\n", test);
9072
9073 test_DestroyWindow_flag = TRUE;
9074 ret = DestroyWindow(parent);
9075 ok( ret, "DestroyWindow() error %d\n", GetLastError());
9076 test_DestroyWindow_flag = FALSE;
9077 ok_sequence(destroy_window_with_children, "destroy window with children", 0);
9078
9079 ok(!IsWindow(parent), "parent still exists\n");
9080 ok(!IsWindow(child1), "child1 still exists\n");
9081 ok(!IsWindow(child2), "child2 still exists\n");
9082 ok(!IsWindow(child3), "child3 still exists\n");
9083 ok(!IsWindow(child4), "child4 still exists\n");
9084
9085 test = GetCapture();
9086 ok(!test, "wrong capture window %p\n", test);
9087 }
9088
9089
9090 static const struct message WmDispatchPaint[] = {
9091 { WM_NCPAINT, sent },
9092 { WM_GETTEXT, sent|defwinproc|optional },
9093 { WM_GETTEXT, sent|defwinproc|optional },
9094 { WM_ERASEBKGND, sent },
9095 { 0 }
9096 };
9097
9098 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9099 {
9100 if (message == WM_PAINT) return 0;
9101 return MsgCheckProcA( hwnd, message, wParam, lParam );
9102 }
9103
9104 static void test_DispatchMessage(void)
9105 {
9106 RECT rect;
9107 MSG msg;
9108 int count;
9109 HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9110 100, 100, 200, 200, 0, 0, 0, NULL);
9111 ShowWindow( hwnd, SW_SHOW );
9112 UpdateWindow( hwnd );
9113 flush_events();
9114 flush_sequence();
9115 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
9116
9117 SetRect( &rect, -5, -5, 5, 5 );
9118 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
9119 count = 0;
9120 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
9121 {
9122 if (msg.message != WM_PAINT) DispatchMessage( &msg );
9123 else
9124 {
9125 flush_sequence();
9126 DispatchMessage( &msg );
9127 /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
9128 if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
9129 else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
9130 if (++count > 10) break;
9131 }
9132 }
9133 ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
9134
9135 trace("now without DispatchMessage\n");
9136 flush_sequence();
9137 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
9138 count = 0;
9139 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
9140 {
9141 if (msg.message != WM_PAINT) DispatchMessage( &msg );
9142 else
9143 {
9144 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
9145 flush_sequence();
9146 /* this will send WM_NCCPAINT just like DispatchMessage does */
9147 GetUpdateRgn( hwnd, hrgn, TRUE );
9148 ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
9149 DeleteObject( hrgn );
9150 GetClientRect( hwnd, &rect );
9151 ValidateRect( hwnd, &rect ); /* this will stop WM_PAINTs */
9152 ok( !count, "Got multiple WM_PAINTs\n" );
9153 if (++count > 10) break;
9154 }
9155 }
9156
9157 flush_sequence();
9158 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
9159 count = 0;
9160 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
9161 {
9162 if (msg.message != WM_PAINT) DispatchMessage( &msg );
9163 else
9164 {
9165 HDC hdc;
9166
9167 flush_sequence();
9168 hdc = BeginPaint( hwnd, NULL );
9169 ok( !hdc, "got valid hdc %p from BeginPaint\n", hdc );
9170 ok( !EndPaint( hwnd, NULL ), "EndPaint succeeded\n" );
9171 ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
9172 ok( !count, "Got multiple WM_PAINTs\n" );
9173 if (++count > 10) break;
9174 }
9175 }
9176 DestroyWindow(hwnd);
9177 }
9178
9179
9180 static const struct message WmUser[] = {
9181 { WM_USER, sent },
9182 { 0 }
9183 };
9184
9185 struct sendmsg_info
9186 {
9187 HWND hwnd;
9188 DWORD timeout;
9189 DWORD ret;
9190 };
9191
9192 static DWORD CALLBACK send_msg_thread( LPVOID arg )
9193 {
9194 struct sendmsg_info *info = arg;
9195 SetLastError( 0xdeadbeef );
9196 info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
9197 if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT ||
9198 broken(GetLastError() == 0), /* win9x */
9199 "unexpected error %d\n", GetLastError());
9200 return 0;
9201 }
9202
9203 static void wait_for_thread( HANDLE thread )
9204 {
9205 while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
9206 {
9207 MSG msg;
9208 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
9209 }
9210 }
9211
9212 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9213 {
9214 if (message == WM_USER) Sleep(200);
9215 return MsgCheckProcA( hwnd, message, wParam, lParam );
9216 }
9217
9218 static void test_SendMessageTimeout(void)
9219 {
9220 HANDLE thread;
9221 struct sendmsg_info info;
9222 DWORD tid;
9223 BOOL is_win9x;
9224
9225 info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9226 100, 100, 200, 200, 0, 0, 0, NULL);
9227 flush_events();
9228 flush_sequence();
9229
9230 info.timeout = 1000;
9231 info.ret = 0xdeadbeef;
9232 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9233 wait_for_thread( thread );
9234 CloseHandle( thread );
9235 ok( info.ret == 1, "SendMessageTimeout failed\n" );
9236 ok_sequence( WmUser, "WmUser", FALSE );
9237
9238 info.timeout = 1;
9239 info.ret = 0xdeadbeef;
9240 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9241 Sleep(100); /* SendMessageTimeout should time out here */
9242 wait_for_thread( thread );
9243 CloseHandle( thread );
9244 ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
9245 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9246
9247 /* 0 means infinite timeout (but not on win9x) */
9248 info.timeout = 0;
9249 info.ret = 0xdeadbeef;
9250 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9251 Sleep(100);
9252 wait_for_thread( thread );
9253 CloseHandle( thread );
9254 is_win9x = !info.ret;
9255 if (is_win9x) ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9256 else ok_sequence( WmUser, "WmUser", FALSE );
9257
9258 /* timeout is treated as signed despite the prototype (but not on win9x) */
9259 info.timeout = 0x7fffffff;
9260 info.ret = 0xdeadbeef;
9261 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9262 Sleep(100);
9263 wait_for_thread( thread );
9264 CloseHandle( thread );
9265 ok( info.ret == 1, "SendMessageTimeout failed\n" );
9266 ok_sequence( WmUser, "WmUser", FALSE );
9267
9268 info.timeout = 0x80000000;
9269 info.ret = 0xdeadbeef;
9270 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9271 Sleep(100);
9272 wait_for_thread( thread );
9273 CloseHandle( thread );
9274 if (is_win9x)
9275 {
9276 ok( info.ret == 1, "SendMessageTimeout failed\n" );
9277 ok_sequence( WmUser, "WmUser", FALSE );
9278 }
9279 else
9280 {
9281 ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
9282 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9283 }
9284
9285 /* now check for timeout during message processing */
9286 SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
9287 info.timeout = 100;
9288 info.ret = 0xdeadbeef;
9289 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9290 wait_for_thread( thread );
9291 CloseHandle( thread );
9292 /* we should time out but still get the message */
9293 ok( info.ret == 0, "SendMessageTimeout failed\n" );
9294 ok_sequence( WmUser, "WmUser", FALSE );
9295
9296 DestroyWindow( info.hwnd );
9297 }
9298
9299
9300 /****************** edit message test *************************/
9301 #define ID_EDIT 0x1234
9302 static const struct message sl_edit_setfocus[] =
9303 {
9304 { HCBT_SETFOCUS, hook },
9305 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9306 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9307 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9308 { WM_SETFOCUS, sent|wparam, 0 },
9309 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9310 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
9311 { WM_CTLCOLOREDIT, sent|parent },
9312 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9313 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9314 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9315 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9316 { 0 }
9317 };
9318 static const struct message ml_edit_setfocus[] =
9319 {
9320 { HCBT_SETFOCUS, hook },
9321 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9322 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9323 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9324 { WM_SETFOCUS, sent|wparam, 0 },
9325 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9326 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9327 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9328 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9329 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9330 { 0 }
9331 };
9332 static const struct message sl_edit_killfocus[] =
9333 {
9334 { HCBT_SETFOCUS, hook },
9335 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9336 { WM_KILLFOCUS, sent|wparam, 0 },
9337 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9338 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9339 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
9340 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
9341 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
9342 { 0 }
9343 };
9344 static const struct message sl_edit_lbutton_dblclk[] =
9345 {
9346 { WM_LBUTTONDBLCLK, sent },
9347 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9348 { 0 }
9349 };
9350 static const struct message sl_edit_lbutton_down[] =
9351 {
9352 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
9353 { HCBT_SETFOCUS, hook },
9354 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9355 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9356 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9357 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9358 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9359 { WM_CTLCOLOREDIT, sent|parent },
9360 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9361 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9362 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9363 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9364 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9365 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9366 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9367 { WM_CTLCOLOREDIT, sent|parent|optional },
9368 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9369 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9370 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9371 { 0 }
9372 };
9373 static const struct message ml_edit_lbutton_down[] =
9374 {
9375 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
9376 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9377 { HCBT_SETFOCUS, hook },
9378 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9379 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9380 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9381 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9382 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9383 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9384 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9385 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9386 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9387 { 0 }
9388 };
9389 static const struct message sl_edit_lbutton_up[] =
9390 {
9391 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9392 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9393 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9394 { WM_CAPTURECHANGED, sent|defwinproc },
9395 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9396 { 0 }
9397 };
9398 static const struct message ml_edit_lbutton_up[] =
9399 {
9400 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9401 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9402 { WM_CAPTURECHANGED, sent|defwinproc },
9403 { 0 }
9404 };
9405
9406 static WNDPROC old_edit_proc;
9407
9408 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9409 {
9410 static LONG defwndproc_counter = 0;
9411 LRESULT ret;
9412 struct recvd_message msg;
9413
9414 if (ignore_message( message )) return 0;
9415
9416 msg.hwnd = hwnd;
9417 msg.message = message;
9418 msg.flags = sent|wparam|lparam;
9419 if (defwndproc_counter) msg.flags |= defwinproc;
9420 msg.wParam = wParam;
9421 msg.lParam = lParam;
9422 msg.descr = "edit";
9423 add_message(&msg);
9424
9425 defwndproc_counter++;
9426 ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
9427 defwndproc_counter--;
9428
9429 return ret;
9430 }
9431
9432 static void subclass_edit(void)
9433 {
9434 WNDCLASSA cls;
9435
9436 if (!GetClassInfoA(0, "edit", &cls)) assert(0);
9437
9438 old_edit_proc = cls.lpfnWndProc;
9439
9440 cls.hInstance = GetModuleHandle(0);
9441 cls.lpfnWndProc = edit_hook_proc;
9442 cls.lpszClassName = "my_edit_class";
9443 UnregisterClass(cls.lpszClassName, cls.hInstance);
9444 if (!RegisterClassA(&cls)) assert(0);
9445 }
9446
9447 static void test_edit_messages(void)
9448 {
9449 HWND hwnd, parent;
9450 DWORD dlg_code;
9451
9452 subclass_edit();
9453 log_all_parent_messages++;
9454
9455 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9456 100, 100, 200, 200, 0, 0, 0, NULL);
9457 ok (parent != 0, "Failed to create parent window\n");
9458
9459 /* test single line edit */
9460 hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
9461 0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9462 ok(hwnd != 0, "Failed to create edit window\n");
9463
9464 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9465 ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
9466
9467 ShowWindow(hwnd, SW_SHOW);
9468 UpdateWindow(hwnd);
9469 SetFocus(0);
9470 flush_sequence();
9471
9472 SetFocus(hwnd);
9473 ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
9474
9475 SetFocus(0);
9476 ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
9477
9478 SetFocus(0);
9479 ReleaseCapture();
9480 flush_sequence();
9481
9482 SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9483 ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
9484
9485 SetFocus(0);
9486 ReleaseCapture();
9487 flush_sequence();
9488
9489 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9490 ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
9491
9492 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9493 ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
9494
9495 DestroyWindow(hwnd);
9496
9497 /* test multiline edit */
9498 hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
9499 0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9500 ok(hwnd != 0, "Failed to create edit window\n");
9501
9502 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9503 ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
9504 "wrong dlg_code %08x\n", dlg_code);
9505
9506 ShowWindow(hwnd, SW_SHOW);
9507 UpdateWindow(hwnd);
9508 SetFocus(0);
9509 flush_sequence();
9510
9511 SetFocus(hwnd);
9512 ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
9513
9514 SetFocus(0);
9515 ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
9516
9517 SetFocus(0);
9518 ReleaseCapture();
9519 flush_sequence();
9520
9521 SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9522 ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
9523
9524 SetFocus(0);
9525 ReleaseCapture();
9526 flush_sequence();
9527
9528 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9529 ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
9530
9531 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9532 ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
9533
9534 DestroyWindow(hwnd);
9535 DestroyWindow(parent);
9536
9537 log_all_parent_messages--;
9538 }
9539
9540 /**************************** End of Edit test ******************************/
9541
9542 static const struct message WmKeyDownSkippedSeq[] =
9543 {
9544 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
9545 { 0 }
9546 };
9547 static const struct message WmKeyDownWasDownSkippedSeq[] =
9548 {
9549 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x40000001 }, /* XP */
9550 { 0 }
9551 };
9552 static const struct message WmKeyUpSkippedSeq[] =
9553 {
9554 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9555 { 0 }
9556 };
9557 static const struct message WmUserKeyUpSkippedSeq[] =
9558 {
9559 { WM_USER, sent },
9560 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9561 { 0 }
9562 };
9563
9564 #define EV_STOP 0
9565 #define EV_SENDMSG 1
9566 #define EV_ACK 2
9567
9568 struct peekmsg_info
9569 {
9570 HWND hwnd;
9571 HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
9572 };
9573
9574 static DWORD CALLBACK send_msg_thread_2(void *param)
9575 {
9576 DWORD ret;
9577 struct peekmsg_info *info = param;
9578
9579 trace("thread: looping\n");
9580 SetEvent(info->hevent[EV_ACK]);
9581
9582 while (1)
9583 {
9584 ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
9585
9586 switch (ret)
9587 {
9588 case WAIT_OBJECT_0 + EV_STOP:
9589 trace("thread: exiting\n");
9590 return 0;
9591
9592 case WAIT_OBJECT_0 + EV_SENDMSG:
9593 trace("thread: sending message\n");
9594 ret = SendNotifyMessageA(info->hwnd, WM_USER, 0, 0);
9595 ok(ret, "SendNotifyMessageA failed error %u\n", GetLastError());
9596 SetEvent(info->hevent[EV_ACK]);
9597 break;
9598
9599 default:
9600 trace("unexpected return: %04x\n", ret);
9601 assert(0);
9602 break;
9603 }
9604 }
9605 return 0;
9606 }
9607
9608 static void test_PeekMessage(void)
9609 {
9610 MSG msg;
9611 HANDLE hthread;
9612 DWORD tid, qstatus;
9613 UINT qs_all_input = QS_ALLINPUT;
9614 UINT qs_input = QS_INPUT;
9615 BOOL ret;
9616 struct peekmsg_info info;
9617
9618 info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9619 100, 100, 200, 200, 0, 0, 0, NULL);
9620 assert(info.hwnd);
9621 ShowWindow(info.hwnd, SW_SHOW);
9622 UpdateWindow(info.hwnd);
9623 SetFocus(info.hwnd);
9624
9625 info.hevent[EV_STOP] = CreateEventA(NULL, 0, 0, NULL);
9626 info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
9627 info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
9628
9629 hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
9630 WaitForSingleObject(info.hevent[EV_ACK], 10000);
9631
9632 flush_events();
9633 flush_sequence();
9634
9635 SetLastError(0xdeadbeef);
9636 qstatus = GetQueueStatus(qs_all_input);
9637 if (GetLastError() == ERROR_INVALID_FLAGS)
9638 {
9639 trace("QS_RAWINPUT not supported on this platform\n");
9640 qs_all_input &= ~QS_RAWINPUT;
9641 qs_input &= ~QS_RAWINPUT;
9642 }
9643 if (qstatus & QS_POSTMESSAGE)
9644 {
9645 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) /* nothing */ ;
9646 qstatus = GetQueueStatus(qs_all_input);
9647 }
9648 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9649
9650 trace("signalling to send message\n");
9651 SetEvent(info.hevent[EV_SENDMSG]);
9652 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9653
9654 /* pass invalid QS_xxxx flags */
9655 SetLastError(0xdeadbeef);
9656 qstatus = GetQueueStatus(0xffffffff);
9657 ok(qstatus == 0 || broken(qstatus) /* win9x */, "GetQueueStatus should fail: %08x\n", qstatus);
9658 if (!qstatus)
9659 {
9660 ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
9661 qstatus = GetQueueStatus(qs_all_input);
9662 }
9663 qstatus &= ~MAKELONG( 0x4000, 0x4000 ); /* sometimes set on Win95 */
9664 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
9665 "wrong qstatus %08x\n", qstatus);
9666
9667 msg.message = 0;
9668 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9669 ok(!ret,
9670 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9671 msg.message);
9672 ok_sequence(WmUser, "WmUser", FALSE);
9673
9674 qstatus = GetQueueStatus(qs_all_input);
9675 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9676
9677 keybd_event('N', 0, 0, 0);
9678 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9679 qstatus = GetQueueStatus(qs_all_input);
9680 if (!(qstatus & MAKELONG(QS_KEY, QS_KEY)))
9681 {
9682 skip( "queuing key events not supported\n" );
9683 goto done;
9684 }
9685 ok(qstatus == MAKELONG(QS_KEY, QS_KEY) ||
9686 /* keybd_event seems to trigger a sent message on NT4 */
9687 qstatus == MAKELONG(QS_KEY|QS_SENDMESSAGE, QS_KEY|QS_SENDMESSAGE),
9688 "wrong qstatus %08x\n", qstatus);
9689
9690 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9691 qstatus = GetQueueStatus(qs_all_input);
9692 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY) ||
9693 qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY|QS_SENDMESSAGE),
9694 "wrong qstatus %08x\n", qstatus);
9695
9696 InvalidateRect(info.hwnd, NULL, FALSE);
9697 qstatus = GetQueueStatus(qs_all_input);
9698 ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY) ||
9699 qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY|QS_SENDMESSAGE),
9700 "wrong qstatus %08x\n", qstatus);
9701
9702 trace("signalling to send message\n");
9703 SetEvent(info.hevent[EV_SENDMSG]);
9704 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9705
9706 qstatus = GetQueueStatus(qs_all_input);
9707 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9708 "wrong qstatus %08x\n", qstatus);
9709
9710 msg.message = 0;
9711 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
9712 if (ret && msg.message == WM_CHAR)
9713 {
9714 win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9715 goto done;
9716 }
9717 ok(!ret,
9718 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9719 msg.message);
9720 if (!sequence_cnt) /* nt4 doesn't fetch anything with PM_QS_* flags */
9721 {
9722 win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9723 goto done;
9724 }
9725 ok_sequence(WmUser, "WmUser", FALSE);
9726
9727 qstatus = GetQueueStatus(qs_all_input);
9728 ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9729 "wrong qstatus %08x\n", qstatus);
9730
9731 trace("signalling to send message\n");
9732 SetEvent(info.hevent[EV_SENDMSG]);
9733 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9734
9735 qstatus = GetQueueStatus(qs_all_input);
9736 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9737 "wrong qstatus %08x\n", qstatus);
9738
9739 msg.message = 0;
9740 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE );
9741 ok(!ret,
9742 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9743 msg.message);
9744 ok_sequence(WmUser, "WmUser", FALSE);
9745
9746 qstatus = GetQueueStatus(qs_all_input);
9747 ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9748 "wrong qstatus %08x\n", qstatus);
9749
9750 msg.message = 0;
9751 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9752 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9753 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9754 ret, msg.message, msg.wParam);
9755 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9756
9757 qstatus = GetQueueStatus(qs_all_input);
9758 ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9759 "wrong qstatus %08x\n", qstatus);
9760
9761 msg.message = 0;
9762 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9763 ok(!ret,
9764 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9765 msg.message);
9766 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9767
9768 qstatus = GetQueueStatus(qs_all_input);
9769 ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9770 "wrong qstatus %08x\n", qstatus);
9771
9772 msg.message = 0;
9773 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9774 ok(ret && msg.message == WM_PAINT,
9775 "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
9776 DispatchMessageA(&msg);
9777 ok_sequence(WmPaint, "WmPaint", FALSE);
9778
9779 qstatus = GetQueueStatus(qs_all_input);
9780 ok(qstatus == MAKELONG(0, QS_KEY),
9781 "wrong qstatus %08x\n", qstatus);
9782
9783 msg.message = 0;
9784 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9785 ok(!ret,
9786 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9787 msg.message);
9788 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9789
9790 qstatus = GetQueueStatus(qs_all_input);
9791 ok(qstatus == MAKELONG(0, QS_KEY),
9792 "wrong qstatus %08x\n", qstatus);
9793
9794 trace("signalling to send message\n");
9795 SetEvent(info.hevent[EV_SENDMSG]);
9796 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9797
9798 qstatus = GetQueueStatus(qs_all_input);
9799 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
9800 "wrong qstatus %08x\n", qstatus);
9801
9802 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9803
9804 qstatus = GetQueueStatus(qs_all_input);
9805 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9806 "wrong qstatus %08x\n", qstatus);
9807
9808 msg.message = 0;
9809 ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9810 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9811 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9812 ret, msg.message, msg.wParam);
9813 ok_sequence(WmUser, "WmUser", FALSE);
9814
9815 qstatus = GetQueueStatus(qs_all_input);
9816 ok(qstatus == MAKELONG(0, QS_KEY),
9817 "wrong qstatus %08x\n", qstatus);
9818
9819 msg.message = 0;
9820 ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9821 ok(!ret,
9822 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9823 msg.message);
9824 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9825
9826 qstatus = GetQueueStatus(qs_all_input);
9827 ok(qstatus == MAKELONG(0, QS_KEY),
9828 "wrong qstatus %08x\n", qstatus);
9829
9830 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9831
9832 qstatus = GetQueueStatus(qs_all_input);
9833 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9834 "wrong qstatus %08x\n", qstatus);
9835
9836 trace("signalling to send message\n");
9837 SetEvent(info.hevent[EV_SENDMSG]);
9838 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9839
9840 qstatus = GetQueueStatus(qs_all_input);
9841 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9842 "wrong qstatus %08x\n", qstatus);
9843
9844 msg.message = 0;
9845 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
9846 ok(!ret,
9847 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9848 msg.message);
9849 ok_sequence(WmUser, "WmUser", FALSE);
9850
9851 qstatus = GetQueueStatus(qs_all_input);
9852 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9853 "wrong qstatus %08x\n", qstatus);
9854
9855 msg.message = 0;
9856 if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9857 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9858 else /* workaround for a missing QS_RAWINPUT support */
9859 ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
9860 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9861 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9862 ret, msg.message, msg.wParam);
9863 ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9864
9865 qstatus = GetQueueStatus(qs_all_input);
9866 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9867 "wrong qstatus %08x\n", qstatus);
9868
9869 msg.message = 0;
9870 if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9871 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9872 else /* workaround for a missing QS_RAWINPUT support */
9873 ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
9874 ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9875 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
9876 ret, msg.message, msg.wParam);
9877 ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
9878
9879 qstatus = GetQueueStatus(qs_all_input);
9880 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9881 "wrong qstatus %08x\n", qstatus);
9882
9883 msg.message = 0;
9884 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
9885 ok(!ret,
9886 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9887 msg.message);
9888 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9889
9890 qstatus = GetQueueStatus(qs_all_input);
9891 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9892 "wrong qstatus %08x\n", qstatus);
9893
9894 msg.message = 0;
9895 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9896 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9897 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9898 ret, msg.message, msg.wParam);
9899 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9900
9901 qstatus = GetQueueStatus(qs_all_input);
9902 ok(qstatus == 0,
9903 "wrong qstatus %08x\n", qstatus);
9904
9905 msg.message = 0;
9906 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9907 ok(!ret,
9908 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9909 msg.message);
9910 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9911
9912 qstatus = GetQueueStatus(qs_all_input);
9913 ok(qstatus == 0,
9914 "wrong qstatus %08x\n", qstatus);
9915
9916 /* test whether presence of the quit flag in the queue affects
9917 * the queue state
9918 */
9919 PostQuitMessage(0x1234abcd);
9920
9921 qstatus = GetQueueStatus(qs_all_input);
9922 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9923 "wrong qstatus %08x\n", qstatus);
9924
9925 PostMessageA(info.hwnd, WM_USER, 0, 0);
9926
9927 qstatus = GetQueueStatus(qs_all_input);
9928 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9929 "wrong qstatus %08x\n", qstatus);
9930
9931 msg.message = 0;
9932 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9933 ok(ret && msg.message == WM_USER,
9934 "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
9935 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9936
9937 qstatus = GetQueueStatus(qs_all_input);
9938 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9939 "wrong qstatus %08x\n", qstatus);
9940
9941 msg.message = 0;
9942 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9943 ok(ret && msg.message == WM_QUIT,
9944 "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
9945 ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
9946 ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
9947 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9948
9949 qstatus = GetQueueStatus(qs_all_input);
9950 todo_wine {
9951 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9952 "wrong qstatus %08x\n", qstatus);
9953 }
9954
9955 msg.message = 0;
9956 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9957 ok(!ret,
9958 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9959 msg.message);
9960 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9961
9962 qstatus = GetQueueStatus(qs_all_input);
9963 ok(qstatus == 0,
9964 "wrong qstatus %08x\n", qstatus);
9965
9966 /* some GetMessage tests */
9967
9968 keybd_event('N', 0, 0, 0);
9969 qstatus = GetQueueStatus(qs_all_input);
9970 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9971
9972 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9973 qstatus = GetQueueStatus(qs_all_input);
9974 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9975
9976 if (qstatus)
9977 {
9978 ret = GetMessageA( &msg, 0, 0, 0 );
9979 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9980 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9981 ret, msg.message, msg.wParam);
9982 qstatus = GetQueueStatus(qs_all_input);
9983 ok(qstatus == MAKELONG(0, QS_KEY), "wrong qstatus %08x\n", qstatus);
9984 }
9985
9986 if (qstatus)
9987 {
9988 ret = GetMessageA( &msg, 0, 0, 0 );
9989 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9990 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9991 ret, msg.message, msg.wParam);
9992 ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9993 qstatus = GetQueueStatus(qs_all_input);
9994 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9995 }
9996
9997 keybd_event('N', 0, 0, 0);
9998 qstatus = GetQueueStatus(qs_all_input);
9999 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
10000
10001 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
10002 qstatus = GetQueueStatus(qs_all_input);
10003 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
10004
10005 if (qstatus & (QS_KEY << 16))
10006 {
10007 ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
10008 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
10009 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
10010 ret, msg.message, msg.wParam);
10011 ok_sequence(WmKeyDownWasDownSkippedSeq, "WmKeyDownWasDownSkippedSeq", FALSE);
10012 qstatus = GetQueueStatus(qs_all_input);
10013 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
10014 }
10015
10016 if (qstatus)
10017 {
10018 ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
10019 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
10020 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
10021 ret, msg.message, msg.wParam);
10022 qstatus = GetQueueStatus(qs_all_input);
10023 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
10024 }
10025
10026 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
10027 qstatus = GetQueueStatus(qs_all_input);
10028 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
10029
10030 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
10031 qstatus = GetQueueStatus(qs_all_input);
10032 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
10033
10034 trace("signalling to send message\n");
10035 SetEvent(info.hevent[EV_SENDMSG]);
10036 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
10037 qstatus = GetQueueStatus(qs_all_input);
10038 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
10039 "wrong qstatus %08x\n", qstatus);
10040
10041 if (qstatus & (QS_KEY << 16))
10042 {
10043 ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
10044 ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
10045 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
10046 ret, msg.message, msg.wParam);
10047 ok_sequence(WmUserKeyUpSkippedSeq, "WmUserKeyUpSkippedSeq", FALSE);
10048 qstatus = GetQueueStatus(qs_all_input);
10049 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
10050 }
10051
10052 if (qstatus)
10053 {
10054 ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
10055 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
10056 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
10057 ret, msg.message, msg.wParam);
10058 qstatus = GetQueueStatus(qs_all_input);
10059 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
10060 }
10061 done:
10062 trace("signalling to exit\n");
10063 SetEvent(info.hevent[EV_STOP]);
10064
10065 WaitForSingleObject(hthread, INFINITE);
10066
10067 CloseHandle(hthread);
10068 CloseHandle(info.hevent[0]);
10069 CloseHandle(info.hevent[1]);
10070 CloseHandle(info.hevent[2]);
10071
10072 DestroyWindow(info.hwnd);
10073 }
10074
10075 static void wait_move_event(HWND hwnd, int x, int y)
10076 {
10077 MSG msg;
10078 DWORD time;
10079 BOOL ret;
10080 int go = 0;
10081
10082 time = GetTickCount();
10083 while (GetTickCount() - time < 200 && !go) {
10084 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
10085 go = ret && msg.pt.x > x && msg.pt.y > y;
10086 if (!ret) MsgWaitForMultipleObjects( 0, NULL, FALSE, GetTickCount() - time, QS_ALLINPUT );
10087 }
10088 }
10089
10090 #define STEP 5
10091 static void test_PeekMessage2(void)
10092 {
10093 HWND hwnd;
10094 BOOL ret;
10095 MSG msg;
10096 UINT message;
10097 DWORD time1, time2, time3;
10098 int x1, y1, x2, y2, x3, y3;
10099 POINT pos;
10100
10101 time1 = time2 = time3 = 0;
10102 x1 = y1 = x2 = y2 = x3 = y3 = 0;
10103
10104 /* Initialise window and make sure it is ready for events */
10105 hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
10106 10, 10, 800, 800, NULL, NULL, NULL, NULL);
10107 assert(hwnd);
10108 trace("Window for test_PeekMessage2 %p\n", hwnd);
10109 ShowWindow(hwnd, SW_SHOW);
10110 UpdateWindow(hwnd);
10111 SetFocus(hwnd);
10112 GetCursorPos(&pos);
10113 SetCursorPos(100, 100);
10114 mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
10115 flush_events();
10116
10117 /* Do initial mousemove, wait until we can see it
10118 and then do our test peek with PM_NOREMOVE. */
10119 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
10120 wait_move_event(hwnd, 100-STEP, 100-STEP);
10121
10122 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
10123 if (!ret)
10124 {
10125 skip( "queuing mouse events not supported\n" );
10126 goto done;
10127 }
10128 else
10129 {
10130 trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
10131 message = msg.message;
10132 time1 = msg.time;
10133 x1 = msg.pt.x;
10134 y1 = msg.pt.y;
10135 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
10136 }
10137
10138 /* Allow time to advance a bit, and then simulate the user moving their
10139 * mouse around. After that we peek again with PM_NOREMOVE.
10140 * Although the previous mousemove message was never removed, the
10141 * mousemove we now peek should reflect the recent mouse movements
10142 * because the input queue will merge the move events. */
10143 Sleep(100);
10144 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
10145 wait_move_event(hwnd, x1, y1);
10146
10147 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
10148 ok(ret, "no message available\n");
10149 if (ret) {
10150 trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
10151 message = msg.message;
10152 time2 = msg.time;
10153 x2 = msg.pt.x;
10154 y2 = msg.pt.y;
10155 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
10156 ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
10157 ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
10158 }
10159
10160 /* Have another go, to drive the point home */
10161 Sleep(100);
10162 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
10163 wait_move_event(hwnd, x2, y2);
10164
10165 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
10166 ok(ret, "no message available\n");
10167 if (ret) {
10168 trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
10169 message = msg.message;
10170 time3 = msg.time;
10171 x3 = msg.pt.x;
10172 y3 = msg.pt.y;
10173 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
10174 ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
10175 ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
10176 }
10177
10178 done:
10179 DestroyWindow(hwnd);
10180 SetCursorPos(pos.x, pos.y);
10181 flush_events();
10182 }
10183
10184 static INT_PTR CALLBACK wm_quit_dlg_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
10185 {
10186 struct recvd_message msg;
10187
10188 if (ignore_message( message )) return 0;
10189
10190 msg.hwnd = hwnd;
10191 msg.message = message;
10192 msg.flags = sent|wparam|lparam;
10193 msg.wParam = wp;
10194 msg.lParam = lp;
10195 msg.descr = "dialog";
10196 add_message(&msg);
10197
10198 switch (message)
10199 {
10200 case WM_INITDIALOG:
10201 PostMessage(hwnd, WM_QUIT, 0x1234, 0x5678);
10202 PostMessage(hwnd, WM_USER, 0xdead, 0xbeef);
10203 return 0;
10204
10205 case WM_GETDLGCODE:
10206 return 0;
10207
10208 case WM_USER:
10209 EndDialog(hwnd, 0);
10210 break;
10211 }
10212
10213 return 1;
10214 }
10215
10216 static const struct message WmQuitDialogSeq[] = {
10217 { HCBT_CREATEWND, hook },
10218 { WM_SETFONT, sent },
10219 { WM_INITDIALOG, sent },
10220 { WM_CHANGEUISTATE, sent|optional },
10221 { HCBT_DESTROYWND, hook },
10222 { 0x0090, sent|optional }, /* Vista */
10223 { WM_DESTROY, sent },
10224 { WM_NCDESTROY, sent },
10225 { 0 }
10226 };
10227
10228 static const struct message WmStopQuitSeq[] = {
10229 { WM_DWMNCRENDERINGCHANGED, posted|optional },
10230 { WM_CLOSE, posted },
10231 { WM_QUIT, posted|wparam|lparam, 0x1234, 0 },
10232 { 0 }
10233 };
10234
10235 static void test_quit_message(void)
10236 {
10237 MSG msg;
10238 BOOL ret;
10239
10240 /* test using PostQuitMessage */
10241 flush_events();
10242 PostQuitMessage(0xbeef);
10243
10244 ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
10245 ok(ret, "PeekMessage failed with error %d\n", GetLastError());
10246 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10247 ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
10248
10249 ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
10250 ok(ret, "PostMessage failed with error %d\n", GetLastError());
10251
10252 ret = GetMessage(&msg, NULL, 0, 0);
10253 ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
10254 ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
10255
10256 /* note: WM_QUIT message received after WM_USER message */
10257 ret = GetMessage(&msg, NULL, 0, 0);
10258 ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
10259 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10260 ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
10261
10262 ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
10263 ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
10264
10265 /* now test with PostThreadMessage - different behaviour! */
10266 PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
10267
10268 ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
10269 ok(ret, "PeekMessage failed with error %d\n", GetLastError());
10270 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10271 ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
10272
10273 ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
10274 ok(ret, "PostMessage failed with error %d\n", GetLastError());
10275
10276 /* note: we receive the WM_QUIT message first this time */
10277 ret = GetMessage(&msg, NULL, 0, 0);
10278 ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
10279 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10280 ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
10281
10282 ret = GetMessage(&msg, NULL, 0, 0);
10283 ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
10284 ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
10285
10286 flush_events();
10287 flush_sequence();
10288 ret = DialogBoxParam(GetModuleHandle(0), "TEST_EMPTY_DIALOG", 0, wm_quit_dlg_proc, 0);
10289 ok(ret == 1, "expected 1, got %d\n", ret);
10290 ok_sequence(WmQuitDialogSeq, "WmQuitDialogSeq", FALSE);
10291 memset(&msg, 0xab, sizeof(msg));
10292 ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
10293 ok(ret, "PeekMessage failed\n");
10294 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10295 ok(msg.wParam == 0x1234, "wParam was 0x%lx instead of 0x1234\n", msg.wParam);
10296 ok(msg.lParam == 0, "lParam was 0x%lx instead of 0\n", msg.lParam);
10297
10298 /* Check what happens to a WM_QUIT message posted to a window that gets
10299 * destroyed.
10300 */
10301 CreateWindowExA(0, "StopQuitClass", "Stop Quit Test", WS_OVERLAPPEDWINDOW,
10302 0, 0, 100, 100, NULL, NULL, NULL, NULL);
10303 flush_sequence();
10304 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
10305 {
10306 struct recvd_message rmsg;
10307 rmsg.hwnd = msg.hwnd;
10308 rmsg.message = msg.message;
10309 rmsg.flags = posted|wparam|lparam;
10310 rmsg.wParam = msg.wParam;
10311 rmsg.lParam = msg.lParam;
10312 rmsg.descr = "stop/quit";
10313 if (msg.message == WM_QUIT)
10314 /* The hwnd can only be checked here */
10315 ok(!msg.hwnd, "The WM_QUIT hwnd was %p instead of NULL\n", msg.hwnd);
10316 add_message(&rmsg);
10317 DispatchMessage(&msg);
10318 }
10319 ok_sequence(WmStopQuitSeq, "WmStopQuitSeq", FALSE);
10320 }
10321
10322 static const struct message WmMouseHoverSeq[] = {
10323 { WM_MOUSEACTIVATE, sent|optional }, /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
10324 { WM_MOUSEACTIVATE, sent|optional },
10325 { WM_TIMER, sent|optional }, /* XP sends it */
10326 { WM_SYSTIMER, sent },
10327 { WM_MOUSEHOVER, sent|wparam, 0 },
10328 { 0 }
10329 };
10330
10331 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
10332 {
10333 MSG msg;
10334 DWORD start_ticks, end_ticks;
10335
10336 start_ticks = GetTickCount();
10337 /* add some deviation (50%) to cover not expected delays */
10338 start_ticks += timeout / 2;
10339
10340 do
10341 {
10342 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
10343 {
10344 /* Timer proc messages are not dispatched to the window proc,
10345 * and therefore not logged.
10346 */
10347 if ((msg.message == WM_TIMER || msg.message == WM_SYSTIMER) && msg.hwnd)
10348 {
10349 struct recvd_message s_msg;
10350
10351 s_msg.hwnd = msg.hwnd;
10352 s_msg.message = msg.message;
10353 s_msg.flags = sent|wparam|lparam;
10354 s_msg.wParam = msg.wParam;
10355 s_msg.lParam = msg.lParam;
10356 s_msg.descr = "msg_loop";
10357 add_message(&s_msg);
10358 }
10359 DispatchMessage(&msg);
10360 }
10361
10362 end_ticks = GetTickCount();
10363
10364 /* inject WM_MOUSEMOVE to see how it changes tracking */
10365 if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
10366 {
10367 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
10368 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
10369
10370 inject_mouse_move = FALSE;
10371 }
10372 } while (start_ticks + timeout >= end_ticks);
10373 }
10374
10375 static void test_TrackMouseEvent(void)
10376 {
10377 TRACKMOUSEEVENT tme;
10378 BOOL ret;
10379 HWND hwnd, hchild;
10380 RECT rc_parent, rc_child;
10381 UINT default_hover_time, hover_width = 0, hover_height = 0;
10382
10383 #define track_hover(track_hwnd, track_hover_time) \
10384 tme.cbSize = sizeof(tme); \
10385 tme.dwFlags = TME_HOVER; \
10386 tme.hwndTrack = track_hwnd; \
10387 tme.dwHoverTime = track_hover_time; \
10388 SetLastError(0xdeadbeef); \
10389 ret = pTrackMouseEvent(&tme); \
10390 ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
10391
10392 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
10393 tme.cbSize = sizeof(tme); \
10394 tme.dwFlags = TME_QUERY; \
10395 tme.hwndTrack = (HWND)0xdeadbeef; \
10396 tme.dwHoverTime = 0xdeadbeef; \
10397 SetLastError(0xdeadbeef); \
10398 ret = pTrackMouseEvent(&tme); \
10399 ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
10400 ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
10401 ok(tme.dwFlags == (expected_track_flags), \
10402 "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
10403 ok(tme.hwndTrack == (expected_track_hwnd), \
10404 "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
10405 ok(tme.dwHoverTime == (expected_hover_time), \
10406 "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
10407
10408 #define track_hover_cancel(track_hwnd) \
10409 tme.cbSize = sizeof(tme); \
10410 tme.dwFlags = TME_HOVER | TME_CANCEL; \
10411 tme.hwndTrack = track_hwnd; \
10412 tme.dwHoverTime = 0xdeadbeef; \
10413 SetLastError(0xdeadbeef); \
10414 ret = pTrackMouseEvent(&tme); \
10415 ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
10416
10417 default_hover_time = 0xdeadbeef;
10418 SetLastError(0xdeadbeef);
10419 ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
10420 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
10421 "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
10422 if (!ret) default_hover_time = 400;
10423 trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
10424
10425 SetLastError(0xdeadbeef);
10426 ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
10427 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
10428 "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
10429 if (!ret) hover_width = 4;
10430 SetLastError(0xdeadbeef);
10431 ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
10432 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
10433 "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
10434 if (!ret) hover_height = 4;
10435 trace("hover rect is %u x %d\n", hover_width, hover_height);
10436
10437 hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
10438 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10439 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
10440 NULL, NULL, 0);
10441 assert(hwnd);
10442
10443 hchild = CreateWindowEx(0, "TestWindowClass", NULL,
10444 WS_CHILD | WS_BORDER | WS_VISIBLE,
10445 50, 50, 200, 200, hwnd,
10446 NULL, NULL, 0);
10447 assert(hchild);
10448
10449 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
10450 flush_events();
10451 flush_sequence();
10452
10453 tme.cbSize = 0;
10454 tme.dwFlags = TME_QUERY;
10455 tme.hwndTrack = (HWND)0xdeadbeef;
10456 tme.dwHoverTime = 0xdeadbeef;
10457 SetLastError(0xdeadbeef);
10458 ret = pTrackMouseEvent(&tme);
10459 ok(!ret, "TrackMouseEvent should fail\n");
10460 ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef),
10461 "not expected error %u\n", GetLastError());
10462
10463 tme.cbSize = sizeof(tme);
10464 tme.dwFlags = TME_HOVER;
10465 tme.hwndTrack = (HWND)0xdeadbeef;
10466 tme.dwHoverTime = 0xdeadbeef;
10467 SetLastError(0xdeadbeef);
10468 ret = pTrackMouseEvent(&tme);
10469 ok(!ret, "TrackMouseEvent should fail\n");
10470 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10471 "not expected error %u\n", GetLastError());
10472
10473 tme.cbSize = sizeof(tme);
10474 tme.dwFlags = TME_HOVER | TME_CANCEL;
10475 tme.hwndTrack = (HWND)0xdeadbeef;
10476 tme.dwHoverTime = 0xdeadbeef;
10477 SetLastError(0xdeadbeef);
10478 ret = pTrackMouseEvent(&tme);
10479 ok(!ret, "TrackMouseEvent should fail\n");
10480 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10481 "not expected error %u\n", GetLastError());
10482
10483 GetWindowRect(hwnd, &rc_parent);
10484 GetWindowRect(hchild, &rc_child);
10485 SetCursorPos(rc_child.left - 10, rc_child.top - 10);
10486
10487 /* Process messages so that the system updates its internal current
10488 * window and hittest, otherwise TrackMouseEvent calls don't have any
10489 * effect.
10490 */
10491 flush_events();
10492 flush_sequence();
10493
10494 track_query(0, NULL, 0);
10495 track_hover(hchild, 0);
10496 track_query(0, NULL, 0);
10497
10498 flush_events();
10499 flush_sequence();
10500
10501 track_hover(hwnd, 0);
10502 tme.cbSize = sizeof(tme);
10503 tme.dwFlags = TME_QUERY;
10504 tme.hwndTrack = (HWND)0xdeadbeef;
10505 tme.dwHoverTime = 0xdeadbeef;
10506 SetLastError(0xdeadbeef);
10507 ret = pTrackMouseEvent(&tme);
10508 ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());
10509 ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize);
10510 if (!tme.dwFlags)
10511 {
10512 skip( "Cursor not inside window, skipping TrackMouseEvent tests\n" );
10513 DestroyWindow( hwnd );
10514 return;
10515 }
10516 ok(tme.dwFlags == TME_HOVER, "wrong tme.dwFlags %08x, expected TME_HOVER\n", tme.dwFlags);
10517 ok(tme.hwndTrack == hwnd, "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, hwnd);
10518 ok(tme.dwHoverTime == default_hover_time, "wrong tme.dwHoverTime %u, expected %u\n",
10519 tme.dwHoverTime, default_hover_time);
10520
10521 pump_msg_loop_timeout(default_hover_time, FALSE);
10522 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10523
10524 track_query(0, NULL, 0);
10525
10526 track_hover(hwnd, HOVER_DEFAULT);
10527 track_query(TME_HOVER, hwnd, default_hover_time);
10528
10529 Sleep(default_hover_time / 2);
10530 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
10531 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
10532
10533 track_query(TME_HOVER, hwnd, default_hover_time);
10534
10535 pump_msg_loop_timeout(default_hover_time, FALSE);
10536 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10537
10538 track_query(0, NULL, 0);
10539
10540 track_hover(hwnd, HOVER_DEFAULT);
10541 track_query(TME_HOVER, hwnd, default_hover_time);
10542
10543 pump_msg_loop_timeout(default_hover_time, TRUE);
10544 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10545
10546 track_query(0, NULL, 0);
10547
10548 track_hover(hwnd, HOVER_DEFAULT);
10549 track_query(TME_HOVER, hwnd, default_hover_time);
10550 track_hover_cancel(hwnd);
10551
10552 DestroyWindow(hwnd);
10553
10554 #undef track_hover
10555 #undef track_query
10556 #undef track_hover_cancel
10557 }
10558
10559
10560 static const struct message WmSetWindowRgn[] = {
10561 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10562 { WM_NCCALCSIZE, sent|wparam, 1 },
10563 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
10564 { WM_GETTEXT, sent|defwinproc|optional },
10565 { WM_ERASEBKGND, sent|optional },
10566 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10567 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10568 { 0 }
10569 };
10570
10571 static const struct message WmSetWindowRgn_no_redraw[] = {
10572 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10573 { WM_NCCALCSIZE, sent|wparam, 1 },
10574 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10575 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10576 { 0 }
10577 };
10578
10579 static const struct message WmSetWindowRgn_clear[] = {
10580 { WM_WINDOWPOSCHANGING, sent/*|wparam*/, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE/*|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE only on some Windows versions */ },
10581 { WM_NCCALCSIZE, sent|wparam, 1 },
10582 { WM_NCPAINT, sent|optional },
10583 { WM_GETTEXT, sent|defwinproc|optional },
10584 { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
10585 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10586 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
10587 { WM_NCPAINT, sent|optional },
10588 { WM_GETTEXT, sent|defwinproc|optional },
10589 { WM_ERASEBKGND, sent|optional },
10590 { WM_WINDOWPOSCHANGING, sent|optional },
10591 { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10592 { WM_NCPAINT, sent|optional },
10593 { WM_GETTEXT, sent|defwinproc|optional },
10594 { WM_ERASEBKGND, sent|optional },
10595 { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10596 { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10597 { WM_NCPAINT, sent|optional },
10598 { WM_GETTEXT, sent|defwinproc|optional },
10599 { WM_ERASEBKGND, sent|optional },
10600 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10601 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10602 { 0 }
10603 };
10604
10605 static void test_SetWindowRgn(void)
10606 {
10607 HRGN hrgn;
10608 HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10609 100, 100, 200, 200, 0, 0, 0, NULL);
10610 ok( hwnd != 0, "Failed to create overlapped window\n" );
10611
10612 ShowWindow( hwnd, SW_SHOW );
10613 UpdateWindow( hwnd );
10614 flush_events();
10615 flush_sequence();
10616
10617 trace("testing SetWindowRgn\n");
10618 hrgn = CreateRectRgn( 0, 0, 150, 150 );
10619 SetWindowRgn( hwnd, hrgn, TRUE );
10620 ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
10621
10622 hrgn = CreateRectRgn( 30, 30, 160, 160 );
10623 SetWindowRgn( hwnd, hrgn, FALSE );
10624 ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
10625
10626 hrgn = CreateRectRgn( 0, 0, 180, 180 );
10627 SetWindowRgn( hwnd, hrgn, TRUE );
10628 ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
10629
10630 SetWindowRgn( hwnd, 0, TRUE );
10631 ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
10632
10633 DestroyWindow( hwnd );
10634 }
10635
10636 /*************************** ShowWindow() test ******************************/
10637 static const struct message WmShowNormal[] = {
10638 { WM_SHOWWINDOW, sent|wparam, 1 },
10639 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10640 { HCBT_ACTIVATE, hook },
10641 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10642 { HCBT_SETFOCUS, hook },
10643 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10644 { 0 }
10645 };
10646 static const struct message WmShow[] = {
10647 { WM_SHOWWINDOW, sent|wparam, 1 },
10648 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10649 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10650 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10651 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10652 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10653 { 0 }
10654 };
10655 static const struct message WmShowNoActivate_1[] = {
10656 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10657 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10658 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10659 { WM_MOVE, sent|defwinproc|optional },
10660 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10661 { 0 }
10662 };
10663 static const struct message WmShowNoActivate_2[] = {
10664 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10665 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10666 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10667 { WM_MOVE, sent|defwinproc },
10668 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10669 { HCBT_SETFOCUS, hook|optional },
10670 { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10671 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10672 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10673 { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10674 { 0 }
10675 };
10676 static const struct message WmShowNA_1[] = {
10677 { WM_SHOWWINDOW, sent|wparam, 1 },
10678 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10679 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10680 { 0 }
10681 };
10682 static const struct message WmShowNA_2[] = {
10683 { WM_SHOWWINDOW, sent|wparam, 1 },
10684 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10685 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10686 { 0 }
10687 };
10688 static const struct message WmRestore_1[] = {
10689 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10690 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10691 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10692 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10693 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10694 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10695 { WM_MOVE, sent|defwinproc },
10696 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10697 { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10698 { 0 }
10699 };
10700 static const struct message WmRestore_2[] = {
10701 { WM_SHOWWINDOW, sent|wparam, 1 },
10702 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10703 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10704 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10705 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10706 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10707 { 0 }
10708 };
10709 static const struct message WmRestore_3[] = {
10710 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10711 { WM_GETMINMAXINFO, sent },
10712 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10713 { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10714 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10715 { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10716 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10717 { WM_MOVE, sent|defwinproc },
10718 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10719 { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10720 { 0 }
10721 };
10722 static const struct message WmRestore_4[] = {
10723 { HCBT_MINMAX, hook|lparam|optional, 0, SW_RESTORE },
10724 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10725 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10726 { WM_MOVE, sent|defwinproc|optional },
10727 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10728 { 0 }
10729 };
10730 static const struct message WmRestore_5[] = {
10731 { HCBT_MINMAX, hook|lparam|optional, 0, SW_SHOWNORMAL },
10732 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10733 { HCBT_ACTIVATE, hook|optional },
10734 { HCBT_SETFOCUS, hook|optional },
10735 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10736 { WM_MOVE, sent|defwinproc|optional },
10737 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10738 { 0 }
10739 };
10740 static const struct message WmHide_1[] = {
10741 { WM_SHOWWINDOW, sent|wparam, 0 },
10742 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOACTIVATE },
10743 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOACTIVATE },
10744 { HCBT_ACTIVATE, hook|optional },
10745 { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10746 { 0 }
10747 };
10748 static const struct message WmHide_2[] = {
10749 { WM_SHOWWINDOW, sent|wparam, 0 },
10750 { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10751 { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10752 { HCBT_ACTIVATE, hook|optional },
10753 { 0 }
10754 };
10755 static const struct message WmHide_3[] = {
10756 { WM_SHOWWINDOW, sent|wparam, 0 },
10757 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10758 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10759 { HCBT_SETFOCUS, hook|optional },
10760 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10761 { 0 }
10762 };
10763 static const struct message WmShowMinimized_1[] = {
10764 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10765 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10766 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10767 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10768 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10769 { WM_MOVE, sent|defwinproc },
10770 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10771 { 0 }
10772 };
10773 static const struct message WmMinimize_1[] = {
10774 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10775 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10776 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10777 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10778 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10779 { WM_MOVE, sent|defwinproc },
10780 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10781 { 0 }
10782 };
10783 static const struct message WmMinimize_2[] = {
10784 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10785 { HCBT_SETFOCUS, hook|optional },
10786 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10787 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10788 { WM_MOVE, sent|defwinproc },
10789 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10790 { 0 }
10791 };
10792 static const struct message WmMinimize_3[] = {
10793 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10794 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10795 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10796 { WM_MOVE, sent|defwinproc },
10797 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10798 { 0 }
10799 };
10800 static const struct message WmShowMinNoActivate[] = {
10801 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10802 { WM_WINDOWPOSCHANGING, sent },
10803 { WM_WINDOWPOSCHANGED, sent },
10804 { WM_MOVE, sent|defwinproc|optional },
10805 { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
10806 { 0 }
10807 };
10808 static const struct message WmMinMax_1[] = {
10809 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10810 { 0 }
10811 };
10812 static const struct message WmMinMax_2[] = {
10813 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10814 { WM_GETMINMAXINFO, sent|optional },
10815 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED },
10816 { HCBT_ACTIVATE, hook|optional },
10817 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10818 { HCBT_SETFOCUS, hook|optional },
10819 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10820 { WM_MOVE, sent|defwinproc|optional },
10821 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MAXIMIZED },
10822 { HCBT_SETFOCUS, hook|optional },
10823 { 0 }
10824 };
10825 static const struct message WmMinMax_3[] = {
10826 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10827 { HCBT_SETFOCUS, hook|optional },
10828 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10829 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10830 { WM_MOVE, sent|defwinproc|optional },
10831 { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
10832 { 0 }
10833 };
10834 static const struct message WmMinMax_4[] = {
10835 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10836 { 0 }
10837 };
10838 static const struct message WmShowMaximized_1[] = {
10839 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10840 { WM_GETMINMAXINFO, sent },
10841 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10842 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10843 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10844 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10845 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10846 { WM_MOVE, sent|defwinproc },
10847 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10848 { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10849 { 0 }
10850 };
10851 static const struct message WmShowMaximized_2[] = {
10852 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10853 { WM_GETMINMAXINFO, sent },
10854 { WM_WINDOWPOSCHANGING, sent|optional },
10855 { HCBT_ACTIVATE, hook|optional },
10856 { WM_WINDOWPOSCHANGED, sent|optional },
10857 { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
10858 { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
10859 { WM_WINDOWPOSCHANGING, sent|optional },
10860 { HCBT_SETFOCUS, hook|optional },
10861 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10862 { WM_MOVE, sent|defwinproc },
10863 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10864 { HCBT_SETFOCUS, hook|optional },
10865 { 0 }
10866 };
10867 static const struct message WmShowMaximized_3[] = {
10868 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10869 { WM_GETMINMAXINFO, sent|optional },
10870 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10871 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10872 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10873 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10874 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10875 { WM_MOVE, sent|defwinproc|optional },
10876 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10877 { 0 }
10878 };
10879
10880 static void test_ShowWindow(void)
10881 {
10882 /* ShowWindow commands in random order */
10883 static const struct
10884 {
10885 INT cmd; /* ShowWindow command */
10886 LPARAM ret; /* ShowWindow return value */
10887 DWORD style; /* window style after the command */
10888 const struct message *msg; /* message sequence the command produces */
10889 INT wp_cmd, wp_flags; /* window placement after the command */
10890 POINT wp_min, wp_max; /* window placement after the command */
10891 BOOL todo_msg; /* message sequence doesn't match what Wine does */
10892 } sw[] =
10893 {
10894 /* 1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal,
10895 SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10896 /* 2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq,
10897 SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10898 /* 3 */ { SW_HIDE, TRUE, 0, WmHide_1,
10899 SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10900 /* 4 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10901 SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
10902 /* 5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1,
10903 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10904 /* 6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1,
10905 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10906 /* 7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1,
10907 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10908 /* 8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq,
10909 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10910 /* 9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1,
10911 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10912 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2,
10913 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10914 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1,
10915 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10916 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq,
10917 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10918 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1,
10919 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10920 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq,
10921 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10922 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2,
10923 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10924 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10925 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10926 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow,
10927 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10928 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq,
10929 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10930 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1,
10931 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10932 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3,
10933 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10934 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
10935 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10936 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate,
10937 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, TRUE },
10938 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4,
10939 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10940 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
10941 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10942 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq,
10943 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10944 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1,
10945 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10946 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2,
10947 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10948 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
10949 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10950 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq,
10951 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10952 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1,
10953 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10954 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq,
10955 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10956 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3,
10957 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10958 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10959 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10960 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, /* what does this mean?! */
10961 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10962 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq,
10963 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10964 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10965 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10966 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2,
10967 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10968 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq,
10969 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10970 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq,
10971 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
10972 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2,
10973 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10974 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3,
10975 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
10976 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2,
10977 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10978 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2,
10979 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10980 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1,
10981 SW_SHOWMINIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10982 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3,
10983 SW_SHOWMINIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10984 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3,
10985 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10986 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4,
10987 SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10988 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3,
10989 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10990 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq,
10991 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10992 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5,
10993 SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10994 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5,
10995 SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10996 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1,
10997 SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
10998 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
10999 SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
11000 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3,
11001 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
11002 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
11003 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
11004 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2,
11005 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
11006 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq,
11007 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE }
11008 };
11009 HWND hwnd;
11010 DWORD style;
11011 LPARAM ret;
11012 INT i;
11013 WINDOWPLACEMENT wp;
11014 RECT win_rc, work_rc = {0, 0, 0, 0};
11015
11016 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
11017 hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
11018 120, 120, 90, 90,
11019 0, 0, 0, NULL);
11020 assert(hwnd);
11021
11022 style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
11023 ok(style == 0, "expected style 0, got %08x\n", style);
11024
11025 flush_events();
11026 flush_sequence();
11027
11028 if (pGetMonitorInfoA && pMonitorFromPoint)
11029 {
11030 HMONITOR hmon;
11031 MONITORINFO mi;
11032 POINT pt = {0, 0};
11033
11034 SetLastError(0xdeadbeef);
11035 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
11036 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
11037
11038 mi.cbSize = sizeof(mi);
11039 SetLastError(0xdeadbeef);
11040 ret = pGetMonitorInfoA(hmon, &mi);
11041 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
11042 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
11043 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
11044 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
11045 work_rc = mi.rcWork;
11046 }
11047
11048 GetWindowRect(hwnd, &win_rc);
11049 OffsetRect(&win_rc, -work_rc.left, -work_rc.top);
11050
11051 wp.length = sizeof(wp);
11052 SetLastError(0xdeadbeaf);
11053 ret = GetWindowPlacement(hwnd, &wp);
11054 ok(ret, "GetWindowPlacement error %u\n", GetLastError());
11055 ok(wp.flags == 0, "expected 0, got %#x\n", wp.flags);
11056 ok(wp.showCmd == SW_SHOWNORMAL, "expected SW_SHOWNORMAL, got %d\n", wp.showCmd);
11057 ok(wp.ptMinPosition.x == -1 && wp.ptMinPosition.y == -1,
11058 "expected -1,-1 got %d,%d\n", wp.ptMinPosition.x, wp.ptMinPosition.y);
11059 ok(wp.ptMaxPosition.x == -1 && wp.ptMaxPosition.y == -1,
11060 "expected -1,-1 got %d,%d\n", wp.ptMaxPosition.x, wp.ptMaxPosition.y);
11061 if (work_rc.left || work_rc.top) todo_wine /* FIXME: remove once Wine is fixed */
11062 ok(EqualRect(&win_rc, &wp.rcNormalPosition),
11063 "expected %d,%d-%d,%d got %d,%d-%d,%d\n",
11064 win_rc.left, win_rc.top, win_rc.right, win_rc.bottom,
11065 wp.rcNormalPosition.left, wp.rcNormalPosition.top,
11066 wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
11067 else
11068 ok(EqualRect(&win_rc, &wp.rcNormalPosition),
11069 "expected %d,%d-%d,%d got %d,%d-%d,%d\n",
11070 win_rc.left, win_rc.top, win_rc.right, win_rc.bottom,
11071 wp.rcNormalPosition.left, wp.rcNormalPosition.top,
11072 wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
11073
11074 for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
11075 {
11076 static const char * const sw_cmd_name[13] =
11077 {
11078 "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
11079 "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
11080 "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
11081 "SW_NORMALNA" /* 0xCC */
11082 };
11083 char comment[64];
11084 INT idx; /* index into the above array of names */
11085
11086 idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
11087
11088 style = GetWindowLong(hwnd, GWL_STYLE);
11089 trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
11090 ret = ShowWindow(hwnd, sw[i].cmd);
11091 ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
11092 style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
11093 ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
11094
11095 sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
11096 ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
11097
11098 wp.length = sizeof(wp);
11099 SetLastError(0xdeadbeaf);
11100 ret = GetWindowPlacement(hwnd, &wp);
11101 ok(ret, "GetWindowPlacement error %u\n", GetLastError());
11102 ok(wp.flags == sw[i].wp_flags, "expected %#x, got %#x\n", sw[i].wp_flags, wp.flags);
11103 ok(wp.showCmd == sw[i].wp_cmd, "expected %d, got %d\n", sw[i].wp_cmd, wp.showCmd);
11104
11105 /* NT moves the minimized window to -32000,-32000, win9x to 3000,3000 */
11106 if ((wp.ptMinPosition.x + work_rc.left == -32000 && wp.ptMinPosition.y + work_rc.top == -32000) ||
11107 (wp.ptMinPosition.x + work_rc.left == 3000 && wp.ptMinPosition.y + work_rc.top == 3000))
11108 {
11109 ok((wp.ptMinPosition.x + work_rc.left == sw[i].wp_min.x && wp.ptMinPosition.y + work_rc.top == sw[i].wp_min.y) ||
11110 (wp.ptMinPosition.x + work_rc.left == 3000 && wp.ptMinPosition.y + work_rc.top == 3000),
11111 "expected %d,%d got %d,%d\n", sw[i].wp_min.x, sw[i].wp_min.y, wp.ptMinPosition.x, wp.ptMinPosition.y);
11112 }
11113 else
11114 {
11115 ok(wp.ptMinPosition.x == sw[i].wp_min.x && wp.ptMinPosition.y == sw[i].wp_min.y,
11116 "expected %d,%d got %d,%d\n", sw[i].wp_min.x, sw[i].wp_min.y, wp.ptMinPosition.x, wp.ptMinPosition.y);
11117 }
11118
11119 if (wp.ptMaxPosition.x != sw[i].wp_max.x || wp.ptMaxPosition.y != sw[i].wp_max.y)
11120 todo_wine
11121 ok(wp.ptMaxPosition.x == sw[i].wp_max.x && wp.ptMaxPosition.y == sw[i].wp_max.y,
11122 "expected %d,%d got %d,%d\n", sw[i].wp_max.x, sw[i].wp_max.y, wp.ptMaxPosition.x, wp.ptMaxPosition.y);
11123 else
11124 ok(wp.ptMaxPosition.x == sw[i].wp_max.x && wp.ptMaxPosition.y == sw[i].wp_max.y,
11125 "expected %d,%d got %d,%d\n", sw[i].wp_max.x, sw[i].wp_max.y, wp.ptMaxPosition.x, wp.ptMaxPosition.y);
11126
11127 if (0) /* FIXME: Wine behaves completely different here */
11128 ok(EqualRect(&win_rc, &wp.rcNormalPosition),
11129 "expected %d,%d-%d,%d got %d,%d-%d,%d\n",
11130 win_rc.left, win_rc.top, win_rc.right, win_rc.bottom,
11131 wp.rcNormalPosition.left, wp.rcNormalPosition.top,
11132 wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
11133
11134 flush_events();
11135 flush_sequence();
11136 }
11137
11138 DestroyWindow(hwnd);
11139 }
11140
11141 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
11142 {
11143 struct recvd_message msg;
11144
11145 if (ignore_message( message )) return 0;
11146
11147 msg.hwnd = hwnd;
11148 msg.message = message;
11149 msg.flags = sent|wparam|lparam;
11150 msg.wParam = wParam;
11151 msg.lParam = lParam;
11152 msg.descr = "dialog";
11153 add_message(&msg);
11154
11155 /* calling DefDlgProc leads to a recursion under XP */
11156
11157 switch (message)
11158 {
11159 case WM_INITDIALOG:
11160 case WM_GETDLGCODE:
11161 return 0;
11162 }
11163 return 1;
11164 }
11165
11166 static const struct message WmDefDlgSetFocus_1[] = {
11167 { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
11168 { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
11169 { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
11170 { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
11171 { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
11172 { HCBT_SETFOCUS, hook },
11173 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
11174 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11175 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
11176 { WM_SETFOCUS, sent|wparam, 0 },
11177 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
11178 { WM_CTLCOLOREDIT, sent },
11179 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
11180 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11181 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11182 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11183 { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
11184 { 0 }
11185 };
11186 static const struct message WmDefDlgSetFocus_2[] = {
11187 { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
11188 { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
11189 { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
11190 { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
11191 { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
11192 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11193 { WM_CTLCOLOREDIT, sent|optional }, /* XP */
11194 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11195 { 0 }
11196 };
11197 /* Creation of a dialog */
11198 static const struct message WmCreateDialogParamSeq_1[] = {
11199 { HCBT_CREATEWND, hook },
11200 { WM_NCCREATE, sent },
11201 { WM_NCCALCSIZE, sent|wparam, 0 },
11202 { WM_CREATE, sent },
11203 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
11204 { WM_SIZE, sent|wparam, SIZE_RESTORED },
11205 { WM_MOVE, sent },
11206 { WM_SETFONT, sent },
11207 { WM_INITDIALOG, sent },
11208 { WM_CHANGEUISTATE, sent|optional },
11209 { 0 }
11210 };
11211 /* Creation of a dialog */
11212 static const struct message WmCreateDialogParamSeq_2[] = {
11213 { HCBT_CREATEWND, hook },
11214 { WM_NCCREATE, sent },
11215 { WM_NCCALCSIZE, sent|wparam, 0 },
11216 { WM_CREATE, sent },
11217 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
11218 { WM_SIZE, sent|wparam, SIZE_RESTORED },
11219 { WM_MOVE, sent },
11220 { WM_CHANGEUISTATE, sent|optional },
11221 { 0 }
11222 };
11223
11224 static void test_dialog_messages(void)
11225 {
11226 WNDCLASS cls;
11227 HWND hdlg, hedit1, hedit2, hfocus;
11228 LRESULT ret;
11229
11230 #define set_selection(hctl, start, end) \
11231 ret = SendMessage(hctl, EM_SETSEL, start, end); \
11232 ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
11233
11234 #define check_selection(hctl, start, end) \
11235 ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
11236 ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
11237
11238 subclass_edit();
11239
11240 hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
11241 WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
11242 0, 0, 100, 100, 0, 0, 0, NULL);
11243 ok(hdlg != 0, "Failed to create custom dialog window\n");
11244
11245 hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
11246 WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
11247 0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
11248 ok(hedit1 != 0, "Failed to create edit control\n");
11249 hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
11250 WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
11251 0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
11252 ok(hedit2 != 0, "Failed to create edit control\n");
11253
11254 SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
11255 SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
11256
11257 hfocus = GetFocus();
11258 ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
11259
11260 SetFocus(hedit2);
11261 hfocus = GetFocus();
11262 ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
11263
11264 check_selection(hedit1, 0, 0);
11265 check_selection(hedit2, 0, 0);
11266
11267 set_selection(hedit2, 0, -1);
11268 check_selection(hedit2, 0, 3);
11269
11270 SetFocus(0);
11271 hfocus = GetFocus();
11272 ok(hfocus == 0, "wrong focus %p\n", hfocus);
11273
11274 flush_sequence();
11275 ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
11276 ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
11277 ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
11278
11279 hfocus = GetFocus();
11280 ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
11281
11282 check_selection(hedit1, 0, 5);
11283 check_selection(hedit2, 0, 3);
11284
11285 flush_sequence();
11286 ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
11287 ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
11288 ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
11289
11290 hfocus = GetFocus();
11291 ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
11292
11293 check_selection(hedit1, 0, 5);
11294 check_selection(hedit2, 0, 3);
11295
11296 EndDialog(hdlg, 0);
11297 DestroyWindow(hedit1);
11298 DestroyWindow(hedit2);
11299 DestroyWindow(hdlg);
11300 flush_sequence();
11301
11302 #undef set_selection
11303 #undef check_selection
11304
11305 ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
11306 cls.lpszClassName = "MyDialogClass";
11307 cls.hInstance = GetModuleHandle(0);
11308 /* need a cast since a dlgproc is used as a wndproc */
11309 cls.lpfnWndProc = test_dlg_proc;
11310 if (!RegisterClass(&cls)) assert(0);
11311
11312 hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
11313 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
11314 ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
11315 EndDialog(hdlg, 0);
11316 DestroyWindow(hdlg);
11317 flush_sequence();
11318
11319 hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
11320 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
11321 ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
11322 EndDialog(hdlg, 0);
11323 DestroyWindow(hdlg);
11324 flush_sequence();
11325
11326 UnregisterClass(cls.lpszClassName, cls.hInstance);
11327 }
11328
11329 static void test_EndDialog(void)
11330 {
11331 HWND hparent, hother, hactive, hdlg;
11332 WNDCLASS cls;
11333
11334 hparent = CreateWindowExA(0, "TestParentClass", "Test parent",
11335 WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_DISABLED,
11336 100, 100, 200, 200, 0, 0, 0, NULL);
11337 ok (hparent != 0, "Failed to create parent window\n");
11338
11339 hother = CreateWindowExA(0, "TestParentClass", "Test parent 2",
11340 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11341 100, 100, 200, 200, 0, 0, 0, NULL);
11342 ok (hother != 0, "Failed to create parent window\n");
11343
11344 ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
11345 cls.lpszClassName = "MyDialogClass";
11346 cls.hInstance = GetModuleHandle(0);
11347 cls.lpfnWndProc = test_dlg_proc;
11348 if (!RegisterClass(&cls)) assert(0);
11349
11350 flush_sequence();
11351 SetForegroundWindow(hother);
11352 hactive = GetForegroundWindow();
11353 ok(hother == hactive, "Wrong window has focus (%p != %p)\n", hother, hactive);
11354
11355 /* create a dialog where the parent is disabled, this parent should still
11356 receive the focus when the dialog exits (even though "normally" a
11357 disabled window should not receive the focus) */
11358 hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", hparent, test_dlg_proc, 0);
11359 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
11360 SetForegroundWindow(hdlg);
11361 hactive = GetForegroundWindow();
11362 ok(hdlg == hactive, "Wrong window has focus (%p != %p)\n", hdlg, hactive);
11363 EndDialog(hdlg, 0);
11364 hactive = GetForegroundWindow();
11365 ok(hparent == hactive, "Wrong window has focus (parent != active) (active: %p, parent: %p, dlg: %p, other: %p)\n", hactive, hparent, hdlg, hother);
11366 DestroyWindow(hdlg);
11367 flush_sequence();
11368
11369 DestroyWindow( hother );
11370 DestroyWindow( hparent );
11371 UnregisterClass(cls.lpszClassName, cls.hInstance);
11372 }
11373
11374 static void test_nullCallback(void)
11375 {
11376 HWND hwnd;
11377
11378 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
11379 100, 100, 200, 200, 0, 0, 0, NULL);
11380 ok (hwnd != 0, "Failed to create overlapped window\n");
11381
11382 SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
11383 flush_events();
11384 DestroyWindow(hwnd);
11385 }
11386
11387 /* SetActiveWindow( 0 ) hwnd visible */
11388 static const struct message SetActiveWindowSeq0[] =
11389 {
11390 { HCBT_ACTIVATE, hook|optional },
11391 { WM_NCACTIVATE, sent|wparam, 0 },
11392 { WM_GETTEXT, sent|defwinproc|optional },
11393 { WM_ACTIVATE, sent|wparam, 0 },
11394 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
11395 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
11396 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11397 { WM_KILLFOCUS, sent|optional },
11398 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11399 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
11400 { WM_NCACTIVATE, sent|wparam|optional, 1 },
11401 { WM_GETTEXT, sent|defwinproc|optional },
11402 { WM_ACTIVATE, sent|wparam|optional, 1 },
11403 { HCBT_SETFOCUS, hook|optional },
11404 { WM_KILLFOCUS, sent|defwinproc|optional },
11405 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
11406 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
11407 { WM_IME_SETCONTEXT, sent|optional },
11408 { WM_IME_SETCONTEXT, sent|optional },
11409 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
11410 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11411 { WM_SETFOCUS, sent|defwinproc|optional },
11412 { WM_GETTEXT, sent|optional },
11413 { 0 }
11414 };
11415 /* SetActiveWindow( hwnd ) hwnd visible */
11416 static const struct message SetActiveWindowSeq1[] =
11417 {
11418 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11419 { 0 }
11420 };
11421 /* SetActiveWindow( popup ) hwnd visible, popup visible */
11422 static const struct message SetActiveWindowSeq2[] =
11423 {
11424 { HCBT_ACTIVATE, hook },
11425 { WM_NCACTIVATE, sent|wparam, 0 },
11426 { WM_GETTEXT, sent|defwinproc|optional },
11427 { WM_ACTIVATE, sent|wparam, 0 },
11428 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11429 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
11430 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11431 { WM_NCPAINT, sent|optional },
11432 { WM_GETTEXT, sent|defwinproc|optional },
11433 { WM_ERASEBKGND, sent|optional },
11434 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11435 { WM_NCACTIVATE, sent|wparam, 1 },
11436 { WM_GETTEXT, sent|defwinproc|optional },
11437 { WM_ACTIVATE, sent|wparam, 1 },
11438 { HCBT_SETFOCUS, hook },
11439 { WM_KILLFOCUS, sent|defwinproc },
11440 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
11441 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11442 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
11443 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11444 { WM_SETFOCUS, sent|defwinproc },
11445 { WM_GETTEXT, sent|optional },
11446 { 0 }
11447 };
11448
11449 /* SetActiveWindow( hwnd ) hwnd not visible */
11450 static const struct message SetActiveWindowSeq3[] =
11451 {
11452 { HCBT_ACTIVATE, hook },
11453 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11454 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11455 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
11456 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11457 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11458 { WM_ACTIVATEAPP, sent|wparam, 1 },
11459 { WM_ACTIVATEAPP, sent|wparam, 1 },
11460 { WM_NCACTIVATE, sent|wparam, 1 },
11461 { WM_ACTIVATE, sent|wparam, 1 },
11462 { HCBT_SETFOCUS, hook },
11463 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11464 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11465 { WM_SETFOCUS, sent|defwinproc },
11466 { 0 }
11467 };
11468 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
11469 static const struct message SetActiveWindowSeq4[] =
11470 {
11471 { HCBT_ACTIVATE, hook },
11472 { WM_NCACTIVATE, sent|wparam, 0 },
11473 { WM_GETTEXT, sent|defwinproc|optional },
11474 { WM_ACTIVATE, sent|wparam, 0 },
11475 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11476 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
11477 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11478 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11479 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11480 { WM_NCACTIVATE, sent|wparam, 1 },
11481 { WM_GETTEXT, sent|defwinproc|optional },
11482 { WM_ACTIVATE, sent|wparam, 1 },
11483 { HCBT_SETFOCUS, hook },
11484 { WM_KILLFOCUS, sent|defwinproc },
11485 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
11486 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11487 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
11488 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11489 { WM_SETFOCUS, sent|defwinproc },
11490 { 0 }
11491 };
11492
11493
11494 static void test_SetActiveWindow(void)
11495 {
11496 HWND hwnd, popup, ret;
11497
11498 hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
11499 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11500 100, 100, 200, 200, 0, 0, 0, NULL);
11501
11502 popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
11503 WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
11504 100, 100, 200, 200, hwnd, 0, 0, NULL);
11505
11506 ok(hwnd != 0, "Failed to create overlapped window\n");
11507 ok(popup != 0, "Failed to create popup window\n");
11508 SetForegroundWindow( popup );
11509 flush_sequence();
11510
11511 trace("SetActiveWindow(0)\n");
11512 ret = SetActiveWindow(0);
11513 ok( ret == popup, "Failed to SetActiveWindow(0)\n");
11514 ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", FALSE);
11515 flush_sequence();
11516
11517 trace("SetActiveWindow(hwnd), hwnd visible\n");
11518 ret = SetActiveWindow(hwnd);
11519 if (ret == hwnd) ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
11520 flush_sequence();
11521
11522 trace("SetActiveWindow(popup), hwnd visible, popup visible\n");
11523 ret = SetActiveWindow(popup);
11524 ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visible\n");
11525 ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visible", FALSE);
11526 flush_sequence();
11527
11528 ShowWindow(hwnd, SW_HIDE);
11529 ShowWindow(popup, SW_HIDE);
11530 flush_sequence();
11531
11532 trace("SetActiveWindow(hwnd), hwnd not visible\n");
11533 ret = SetActiveWindow(hwnd);
11534 ok( ret == NULL, "SetActiveWindow(hwnd), hwnd not visible, previous is %p\n", ret );
11535 ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
11536 flush_sequence();
11537
11538 trace("SetActiveWindow(popup), hwnd not visible, popup not visible\n");
11539 ret = SetActiveWindow(popup);
11540 ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
11541 ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visible", TRUE);
11542 flush_sequence();
11543
11544 trace("done\n");
11545
11546 DestroyWindow(hwnd);
11547 }
11548
11549 static const struct message SetForegroundWindowSeq[] =
11550 {
11551 { WM_NCACTIVATE, sent|wparam, 0 },
11552 { WM_GETTEXT, sent|defwinproc|optional },
11553 { WM_ACTIVATE, sent|wparam, 0 },
11554 { WM_ACTIVATEAPP, sent|wparam, 0 },
11555 { WM_KILLFOCUS, sent },
11556 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
11557 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
11558 { 0 }
11559 };
11560
11561 static void test_SetForegroundWindow(void)
11562 {
11563 HWND hwnd;
11564
11565 hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
11566 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11567 100, 100, 200, 200, 0, 0, 0, NULL);
11568 ok (hwnd != 0, "Failed to create overlapped window\n");
11569 SetForegroundWindow( hwnd );
11570 flush_sequence();
11571
11572 trace("SetForegroundWindow( 0 )\n");
11573 SetForegroundWindow( 0 );
11574 ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
11575 trace("SetForegroundWindow( GetDesktopWindow() )\n");
11576 SetForegroundWindow( GetDesktopWindow() );
11577 ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
11578 "foreground top level window", FALSE);
11579 trace("done\n");
11580
11581 DestroyWindow(hwnd);
11582 }
11583
11584 static void test_dbcs_wm_char(void)
11585 {
11586 BYTE dbch[2];
11587 WCHAR wch, bad_wch;
11588 HWND hwnd, hwnd2;
11589 MSG msg;
11590 DWORD time;
11591 POINT pt;
11592 DWORD_PTR res;
11593 CPINFOEXA cpinfo;
11594 UINT i, j, k;
11595 struct message wmCharSeq[2];
11596 BOOL ret;
11597
11598 if (!pGetCPInfoExA)
11599 {
11600 win_skip("GetCPInfoExA is not available\n");
11601 return;
11602 }
11603
11604 pGetCPInfoExA( CP_ACP, 0, &cpinfo );
11605 if (cpinfo.MaxCharSize != 2)
11606 {
11607 skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
11608 return;
11609 }
11610
11611 dbch[0] = dbch[1] = 0;
11612 wch = 0;
11613 bad_wch = cpinfo.UnicodeDefaultChar;
11614 for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
11615 for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
11616 for (k = 128; k <= 255; k++)
11617 {
11618 char str[2];
11619 WCHAR wstr[2];
11620 str[0] = j;
11621 str[1] = k;
11622 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
11623 WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
11624 (BYTE)str[0] == j && (BYTE)str[1] == k &&
11625 HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
11626 {
11627 dbch[0] = j;
11628 dbch[1] = k;
11629 wch = wstr[0];
11630 break;
11631 }
11632 }
11633
11634 if (!wch)
11635 {
11636 skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
11637 return;
11638 }
11639 trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
11640 dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
11641
11642 hwnd = CreateWindowExW(0, testWindowClassW, NULL,
11643 WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11644 hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
11645 WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11646 ok (hwnd != 0, "Failed to create overlapped window\n");
11647 ok (hwnd2 != 0, "Failed to create overlapped window\n");
11648 flush_sequence();
11649
11650 memset( wmCharSeq, 0, sizeof(wmCharSeq) );
11651 wmCharSeq[0].message = WM_CHAR;
11652 wmCharSeq[0].flags = sent|wparam;
11653 wmCharSeq[0].wParam = wch;
11654
11655 /* posted message */
11656 PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11657 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11658 ok( !ret, "got message %x\n", msg.message );
11659 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11660 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11661 ok( ret, "no message\n" );
11662 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11663 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11664 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11665 ok( !ret, "got message %x\n", msg.message );
11666
11667 /* posted thread message */
11668 PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
11669 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11670 ok( !ret, "got message %x\n", msg.message );
11671 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11672 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11673 ok( ret, "no message\n" );
11674 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11675 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11676 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11677 ok( !ret, "got message %x\n", msg.message );
11678
11679 /* sent message */
11680 flush_sequence();
11681 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11682 ok_sequence( WmEmptySeq, "no messages", FALSE );
11683 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11684 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11685 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11686 ok( !ret, "got message %x\n", msg.message );
11687
11688 /* sent message with timeout */
11689 flush_sequence();
11690 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11691 ok_sequence( WmEmptySeq, "no messages", FALSE );
11692 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11693 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11694 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11695 ok( !ret, "got message %x\n", msg.message );
11696
11697 /* sent message with timeout and callback */
11698 flush_sequence();
11699 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11700 ok_sequence( WmEmptySeq, "no messages", FALSE );
11701 SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11702 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11703 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11704 ok( !ret, "got message %x\n", msg.message );
11705
11706 /* sent message with callback */
11707 flush_sequence();
11708 SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11709 ok_sequence( WmEmptySeq, "no messages", FALSE );
11710 SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11711 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11712 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11713 ok( !ret, "got message %x\n", msg.message );
11714
11715 /* direct window proc call */
11716 flush_sequence();
11717 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11718 ok_sequence( WmEmptySeq, "no messages", FALSE );
11719 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11720 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11721
11722 /* dispatch message */
11723 msg.hwnd = hwnd;
11724 msg.message = WM_CHAR;
11725 msg.wParam = dbch[0];
11726 msg.lParam = 0;
11727 DispatchMessageA( &msg );
11728 ok_sequence( WmEmptySeq, "no messages", FALSE );
11729 msg.wParam = dbch[1];
11730 DispatchMessageA( &msg );
11731 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11732
11733 /* window handle is irrelevant */
11734 flush_sequence();
11735 SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11736 ok_sequence( WmEmptySeq, "no messages", FALSE );
11737 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11738 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11739 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11740 ok( !ret, "got message %x\n", msg.message );
11741
11742 /* interleaved post and send */
11743 flush_sequence();
11744 PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11745 SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11746 ok_sequence( WmEmptySeq, "no messages", FALSE );
11747 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11748 ok( !ret, "got message %x\n", msg.message );
11749 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11750 ok_sequence( WmEmptySeq, "no messages", FALSE );
11751 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11752 ok( ret, "no message\n" );
11753 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11754 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11755 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11756 ok( !ret, "got message %x\n", msg.message );
11757 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11758 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11759 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11760 ok( !ret, "got message %x\n", msg.message );
11761
11762 /* interleaved sent message and winproc */
11763 flush_sequence();
11764 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11765 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11766 ok_sequence( WmEmptySeq, "no messages", FALSE );
11767 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11768 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11769 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11770 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11771
11772 /* interleaved winproc and dispatch */
11773 msg.hwnd = hwnd;
11774 msg.message = WM_CHAR;
11775 msg.wParam = dbch[0];
11776 msg.lParam = 0;
11777 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11778 DispatchMessageA( &msg );
11779 ok_sequence( WmEmptySeq, "no messages", FALSE );
11780 msg.wParam = dbch[1];
11781 DispatchMessageA( &msg );
11782 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11783 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11784 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11785
11786 /* interleaved sends */
11787 flush_sequence();
11788 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11789 SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
11790 ok_sequence( WmEmptySeq, "no messages", FALSE );
11791 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11792 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11793 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11794 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11795
11796 /* dbcs WM_CHAR */
11797 flush_sequence();
11798 SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
11799 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11800 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11801 ok( !ret, "got message %x\n", msg.message );
11802
11803 /* other char messages are not magic */
11804 PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
11805 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11806 ok( ret, "no message\n" );
11807 ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
11808 ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
11809 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11810 ok( !ret, "got message %x\n", msg.message );
11811 PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
11812 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11813 ok( ret, "no message\n" );
11814 ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
11815 ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
11816 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11817 ok( !ret, "got message %x\n", msg.message );
11818
11819 /* test retrieving messages */
11820
11821 PostMessageW( hwnd, WM_CHAR, wch, 0 );
11822 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
11823 ok( ret, "no message\n" );
11824 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11825 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11826 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11827 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
11828 ok( ret, "no message\n" );
11829 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11830 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11831 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11832 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
11833 ok( !ret, "got message %x\n", msg.message );
11834
11835 /* message filters */
11836 PostMessageW( hwnd, WM_CHAR, wch, 0 );
11837 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
11838 ok( ret, "no message\n" );
11839 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11840 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11841 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11842 /* message id is filtered, hwnd is not */
11843 ret = PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE );
11844 ok( !ret, "no message\n" );
11845 ret = PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE );
11846 ok( ret, "no message\n" );
11847 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11848 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11849 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11850 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
11851 ok( !ret, "got message %x\n", msg.message );
11852
11853 /* mixing GetMessage and PostMessage */
11854 PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
11855 ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
11856 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11857 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11858 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11859 ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
11860 time = msg.time;
11861 pt = msg.pt;
11862 ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
11863 ret = PeekMessageA( &msg, 0, 0, 0, PM_REMOVE );
11864 ok( ret, "no message\n" );
11865 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11866 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11867 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11868 ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
11869 ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
11870 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 );
11871 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
11872 ok( !ret, "got message %x\n", msg.message );
11873
11874 /* without PM_REMOVE */
11875 PostMessageW( hwnd, WM_CHAR, wch, 0 );
11876 ret = PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE );
11877 ok( ret, "no message\n" );
11878 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11879 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11880 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11881 ret = PeekMessageA( &msg, 0, 0, 0, PM_REMOVE );
11882 ok( ret, "no message\n" );
11883 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11884 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11885 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11886 ret = PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE );
11887 ok( ret, "no message\n" );
11888 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11889 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11890 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11891 ret = PeekMessageA( &msg, 0, 0, 0, PM_REMOVE );
11892 ok( ret, "no message\n" );
11893 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11894 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11895 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11896 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
11897 ok( !ret, "got message %x\n", msg.message );
11898
11899 DestroyWindow(hwnd);
11900 DestroyWindow(hwnd2);
11901 }
11902
11903 static void test_unicode_wm_char(void)
11904 {
11905 HWND hwnd;
11906 MSG msg;
11907 struct message seq[2];
11908 HKL hkl_orig, hkl_greek;
11909 DWORD cp;
11910 LCID thread_locale;
11911
11912 hkl_orig = GetKeyboardLayout( 0 );
11913 GetLocaleInfoW( LOWORD( hkl_orig ), LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER, (WCHAR*)&cp, sizeof(cp) / sizeof(WCHAR) );
11914 if (cp != 1252)
11915 {
11916 skip( "Default codepage %d\n", cp );
11917 return;
11918 }
11919
11920 hkl_greek = LoadKeyboardLayout( "00000408", 0 );
11921 if (!hkl_greek || hkl_greek == hkl_orig /* win2k */)
11922 {
11923 skip( "Unable to load Greek keyboard layout\n" );
11924 return;
11925 }
11926
11927 hwnd = CreateWindowExW( 0, testWindowClassW, NULL, WS_OVERLAPPEDWINDOW,
11928 100, 100, 200, 200, 0, 0, 0, NULL );
11929 flush_sequence();
11930
11931 PostMessageW( hwnd, WM_CHAR, 0x3b1, 0 );
11932
11933 ok( GetMessageW( &msg, hwnd, 0, 0 ), "no message\n" );
11934 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11935 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11936 ok( msg.wParam == 0x3b1, "bad wparam %lx\n", msg.wParam );
11937 ok( msg.lParam == 0, "bad lparam %lx\n", msg.lParam );
11938
11939 DispatchMessageW( &msg );
11940
11941 memset( seq, 0, sizeof(seq) );
11942 seq[0].message = WM_CHAR;
11943 seq[0].flags = sent|wparam;
11944 seq[0].wParam = 0x3b1;
11945
11946 ok_sequence( seq, "unicode WM_CHAR", FALSE );
11947
11948 flush_sequence();
11949
11950 /* greek alpha -> 'a' in cp1252 */
11951 PostMessageW( hwnd, WM_CHAR, 0x3b1, 0 );
11952
11953 ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
11954 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11955 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11956 ok( msg.wParam == 0x61, "bad wparam %lx\n", msg.wParam );
11957 ok( msg.lParam == 0, "bad lparam %lx\n", msg.lParam );
11958
11959 DispatchMessageA( &msg );
11960
11961 seq[0].wParam = 0x61;
11962 ok_sequence( seq, "unicode WM_CHAR", FALSE );
11963
11964 thread_locale = GetThreadLocale();
11965 ActivateKeyboardLayout( hkl_greek, 0 );
11966 ok( GetThreadLocale() == thread_locale, "locale changed from %08x to %08x\n",
11967 thread_locale, GetThreadLocale() );
11968
11969 flush_sequence();
11970
11971 /* greek alpha -> 0xe1 in cp1253 */
11972 PostMessageW( hwnd, WM_CHAR, 0x3b1, 0 );
11973
11974 ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
11975 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11976 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11977 ok( msg.wParam == 0xe1, "bad wparam %lx\n", msg.wParam );
11978 ok( msg.lParam == 0, "bad lparam %lx\n", msg.lParam );
11979
11980 DispatchMessageA( &msg );
11981
11982 seq[0].wParam = 0x3b1;
11983 ok_sequence( seq, "unicode WM_CHAR", FALSE );
11984
11985 DestroyWindow( hwnd );
11986 ActivateKeyboardLayout( hkl_orig, 0 );
11987 UnloadKeyboardLayout( hkl_greek );
11988 }
11989
11990 #define ID_LISTBOX 0x000f
11991
11992 static const struct message wm_lb_setcursel_0[] =
11993 {
11994 { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
11995 { WM_CTLCOLORLISTBOX, sent|parent },
11996 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
11997 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11998 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11999 { 0 }
12000 };
12001 static const struct message wm_lb_setcursel_1[] =
12002 {
12003 { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
12004 { WM_CTLCOLORLISTBOX, sent|parent },
12005 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
12006 { WM_CTLCOLORLISTBOX, sent|parent },
12007 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
12008 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
12009 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
12010 { 0 }
12011 };
12012 static const struct message wm_lb_setcursel_2[] =
12013 {
12014 { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
12015 { WM_CTLCOLORLISTBOX, sent|parent },
12016 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
12017 { WM_CTLCOLORLISTBOX, sent|parent },
12018 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
12019 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
12020 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
12021 { 0 }
12022 };
12023 static const struct message wm_lb_click_0[] =
12024 {
12025 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
12026 { HCBT_SETFOCUS, hook },
12027 { WM_KILLFOCUS, sent|parent },
12028 { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
12029 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
12030 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
12031 { WM_SETFOCUS, sent|defwinproc },
12032
12033 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
12034 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
12035 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
12036 { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
12037 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
12038
12039 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
12040 { WM_CTLCOLORLISTBOX, sent|parent },
12041 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
12042 { WM_CTLCOLORLISTBOX, sent|parent },
12043 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
12044 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
12045
12046 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
12047 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
12048
12049 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
12050 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
12051 { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
12052 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
12053 { 0 }
12054 };
12055 static const struct message wm_lb_deletestring[] =
12056 {
12057 { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
12058 { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
12059 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
12060 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
12061 { 0 }
12062 };
12063 static const struct message wm_lb_deletestring_reset[] =
12064 {
12065 { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
12066 { LB_RESETCONTENT, sent|wparam|lparam|defwinproc|optional, 0, 0 },
12067 { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
12068 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
12069 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
12070 { 0 }
12071 };
12072
12073 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
12074
12075 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
12076
12077 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
12078 {
12079 static LONG defwndproc_counter = 0;
12080 LRESULT ret;
12081 struct recvd_message msg;
12082
12083 /* do not log painting messages */
12084 if (message != WM_PAINT &&
12085 message != WM_NCPAINT &&
12086 message != WM_SYNCPAINT &&
12087 message != WM_ERASEBKGND &&
12088 message != WM_NCHITTEST &&
12089 message != WM_GETTEXT &&
12090 !ignore_message( message ))
12091 {
12092 msg.hwnd = hwnd;
12093 msg.message = message;
12094 msg.flags = sent|wparam|lparam;
12095 if (defwndproc_counter) msg.flags |= defwinproc;
12096 msg.wParam = wp;
12097 msg.lParam = lp;
12098 msg.descr = "listbox";
12099 add_message(&msg);
12100 }
12101
12102 defwndproc_counter++;
12103 ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
12104 defwndproc_counter--;
12105
12106 return ret;
12107 }
12108
12109 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
12110 int caret_index, int top_index, int line)
12111 {
12112 LRESULT ret;
12113
12114 /* calling an orig proc helps to avoid unnecessary message logging */
12115 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
12116 ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
12117 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
12118 ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
12119 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
12120 ok_(__FILE__, line)(ret == caret_index ||
12121 broken(cur_sel == -1 && caret_index == 0 && ret == -1), /* nt4 */
12122 "expected caret index %d, got %ld\n", caret_index, ret);
12123 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
12124 ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
12125 }
12126
12127 static void test_listbox_messages(void)
12128 {
12129 HWND parent, listbox;
12130 LRESULT ret;
12131
12132 parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
12133 100, 100, 200, 200, 0, 0, 0, NULL);
12134 listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
12135 WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
12136 10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
12137 listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
12138
12139 check_lb_state(listbox, 0, LB_ERR, 0, 0);
12140
12141 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
12142 ok(ret == 0, "expected 0, got %ld\n", ret);
12143 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
12144 ok(ret == 1, "expected 1, got %ld\n", ret);
12145 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
12146 ok(ret == 2, "expected 2, got %ld\n", ret);
12147
12148 check_lb_state(listbox, 3, LB_ERR, 0, 0);
12149
12150 flush_sequence();
12151
12152 log_all_parent_messages++;
12153
12154 trace("selecting item 0\n");
12155 ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
12156 ok(ret == 0, "expected 0, got %ld\n", ret);
12157 ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
12158 check_lb_state(listbox, 3, 0, 0, 0);
12159 flush_sequence();
12160
12161 trace("selecting item 1\n");
12162 ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
12163 ok(ret == 1, "expected 1, got %ld\n", ret);
12164 ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
12165 check_lb_state(listbox, 3, 1, 1, 0);
12166
12167 trace("selecting item 2\n");
12168 ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
12169 ok(ret == 2, "expected 2, got %ld\n", ret);
12170 ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
12171 check_lb_state(listbox, 3, 2, 2, 0);
12172
12173 trace("clicking on item 0\n");
12174 ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
12175 ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
12176 ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
12177 ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
12178 ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
12179 check_lb_state(listbox, 3, 0, 0, 0);
12180 flush_sequence();
12181
12182 trace("deleting item 0\n");
12183 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
12184 ok(ret == 2, "expected 2, got %ld\n", ret);
12185 ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
12186 check_lb_state(listbox, 2, -1, 0, 0);
12187 flush_sequence();
12188
12189 trace("deleting item 0\n");
12190 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
12191 ok(ret == 1, "expected 1, got %ld\n", ret);
12192 ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
12193 check_lb_state(listbox, 1, -1, 0, 0);
12194 flush_sequence();
12195
12196 trace("deleting item 0\n");
12197 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
12198 ok(ret == 0, "expected 0, got %ld\n", ret);
12199 ok_sequence(wm_lb_deletestring_reset, "LB_DELETESTRING 0", FALSE );
12200 check_lb_state(listbox, 0, -1, 0, 0);
12201 flush_sequence();
12202
12203 trace("deleting item 0\n");
12204 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
12205 ok(ret == LB_ERR, "expected LB_ERR, got %ld\n", ret);
12206 check_lb_state(listbox, 0, -1, 0, 0);
12207 flush_sequence();
12208
12209 log_all_parent_messages--;
12210
12211 DestroyWindow(listbox);
12212 DestroyWindow(parent);
12213 }
12214
12215 /*************************** Menu test ******************************/
12216 static const struct message wm_popup_menu_1[] =
12217 {
12218 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
12219 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
12220 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
12221 { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
12222 { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
12223 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
12224 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
12225 { WM_INITMENU, sent|lparam, 0, 0 },
12226 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
12227 { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
12228 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
12229 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
12230 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
12231 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
12232 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001, 0, 0x40000000 },
12233 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
12234 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
12235 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
12236 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
12237 { WM_MENUCOMMAND, sent }, /* |wparam, 200 - Win9x */
12238 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
12239 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
12240 { 0 }
12241 };
12242 static const struct message wm_popup_menu_2[] =
12243 {
12244 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
12245 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
12246 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
12247 { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
12248 { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
12249 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
12250 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
12251 { WM_INITMENU, sent|lparam, 0, 0 },
12252 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
12253 { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
12254 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
12255 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
12256 { HCBT_CREATEWND, hook },
12257 { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
12258 |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
12259 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
12260 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
12261 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
12262 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
12263 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
12264 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
12265 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
12266 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
12267 { HCBT_DESTROYWND, hook },
12268 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
12269 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
12270 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
12271 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
12272 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
12273 { WM_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
12274 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
12275 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
12276 { 0 }
12277 };
12278 static const struct message wm_popup_menu_3[] =
12279 {
12280 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
12281 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
12282 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
12283 { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
12284 { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
12285 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
12286 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
12287 { WM_INITMENU, sent|lparam, 0, 0 },
12288 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
12289 { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
12290 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
12291 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
12292 { HCBT_CREATEWND, hook },
12293 { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
12294 |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
12295 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
12296 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
12297 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
12298 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
12299 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
12300 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
12301 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
12302 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
12303 { HCBT_DESTROYWND, hook },
12304 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
12305 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
12306 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
12307 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
12308 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
12309 { WM_COMMAND, sent|wparam|lparam, 100, 0 },
12310 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
12311 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
12312 { 0 }
12313 };
12314
12315 static const struct message wm_single_menu_item[] =
12316 {
12317 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
12318 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
12319 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'Q', 0x20000001 },
12320 { WM_SYSKEYDOWN, sent|wparam|lparam, 'Q', 0x20000001 },
12321 { WM_SYSCHAR, sent|wparam|lparam, 'q', 0x20000001 },
12322 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'q' },
12323 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
12324 { WM_INITMENU, sent|lparam, 0, 0 },
12325 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(300,MF_HILITE) },
12326 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
12327 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
12328 { WM_MENUCOMMAND, sent },
12329 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'Q', 0xe0000001 },
12330 { WM_SYSKEYUP, sent|wparam|lparam, 'Q', 0xe0000001 },
12331 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 },
12332 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
12333
12334 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 1 },
12335 { WM_KEYDOWN, sent|wparam|lparam, VK_ESCAPE, 1 },
12336 { WM_CHAR, sent|wparam|lparam, VK_ESCAPE, 0x00000001 },
12337 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0xc0000001 },
12338 { WM_KEYUP, sent|wparam|lparam, VK_ESCAPE, 0xc0000001 },
12339 { 0 }
12340 };
12341
12342 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
12343 {
12344 if (message == WM_ENTERIDLE ||
12345 message == WM_INITMENU ||
12346 message == WM_INITMENUPOPUP ||
12347 message == WM_MENUSELECT ||
12348 message == WM_PARENTNOTIFY ||
12349 message == WM_ENTERMENULOOP ||
12350 message == WM_EXITMENULOOP ||
12351 message == WM_UNINITMENUPOPUP ||
12352 message == WM_KEYDOWN ||
12353 message == WM_KEYUP ||
12354 message == WM_CHAR ||
12355 message == WM_SYSKEYDOWN ||
12356 message == WM_SYSKEYUP ||
12357 message == WM_SYSCHAR ||
12358 message == WM_COMMAND ||
12359 message == WM_MENUCOMMAND)
12360 {
12361 struct recvd_message msg;
12362
12363 msg.hwnd = hwnd;
12364 msg.message = message;
12365 msg.flags = sent|wparam|lparam;
12366 msg.wParam = wp;
12367 msg.lParam = lp;
12368 msg.descr = "parent_menu_proc";
12369 add_message(&msg);
12370 }
12371
12372 return DefWindowProcA(hwnd, message, wp, lp);
12373 }
12374
12375 static void set_menu_style(HMENU hmenu, DWORD style)
12376 {
12377 MENUINFO mi;
12378 BOOL ret;
12379
12380 mi.cbSize = sizeof(mi);
12381 mi.fMask = MIM_STYLE;
12382 mi.dwStyle = style;
12383 SetLastError(0xdeadbeef);
12384 ret = pSetMenuInfo(hmenu, &mi);
12385 ok(ret, "SetMenuInfo error %u\n", GetLastError());
12386 }
12387
12388 static DWORD get_menu_style(HMENU hmenu)
12389 {
12390 MENUINFO mi;
12391 BOOL ret;
12392
12393 mi.cbSize = sizeof(mi);
12394 mi.fMask = MIM_STYLE;
12395 mi.dwStyle = 0;
12396 SetLastError(0xdeadbeef);
12397 ret = pGetMenuInfo(hmenu, &mi);
12398 ok(ret, "GetMenuInfo error %u\n", GetLastError());
12399
12400 return mi.dwStyle;
12401 }
12402
12403 static void test_menu_messages(void)
12404 {
12405 MSG msg;
12406 WNDCLASSA cls;
12407 HMENU hmenu, hmenu_popup;
12408 HWND hwnd;
12409 DWORD style;
12410
12411 if (!pGetMenuInfo || !pSetMenuInfo)
12412 {
12413 win_skip("GetMenuInfo and/or SetMenuInfo are not available\n");
12414 return;
12415 }
12416 cls.style = 0;
12417 cls.lpfnWndProc = parent_menu_proc;
12418 cls.cbClsExtra = 0;
12419 cls.cbWndExtra = 0;
12420 cls.hInstance = GetModuleHandleA(0);
12421 cls.hIcon = 0;
12422 cls.hCursor = LoadCursorA(0, IDC_ARROW);
12423 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
12424 cls.lpszMenuName = NULL;
12425 cls.lpszClassName = "TestMenuClass";
12426 UnregisterClass(cls.lpszClassName, cls.hInstance);
12427 if (!RegisterClassA(&cls)) assert(0);
12428
12429 SetLastError(0xdeadbeef);
12430 hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
12431 100, 100, 200, 200, 0, 0, 0, NULL);
12432 ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
12433
12434 SetLastError(0xdeadbeef);
12435 hmenu = LoadMenuA(GetModuleHandle(0), MAKEINTRESOURCE(1));
12436 ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
12437
12438 SetMenu(hwnd, hmenu);
12439 SetForegroundWindow( hwnd );
12440
12441 set_menu_style(hmenu, MNS_NOTIFYBYPOS);
12442 style = get_menu_style(hmenu);
12443 ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
12444
12445 hmenu_popup = GetSubMenu(hmenu, 0);
12446 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12447 style = get_menu_style(hmenu_popup);
12448 ok(style == 0, "expected 0, got %u\n", style);
12449
12450 hmenu_popup = GetSubMenu(hmenu_popup, 0);
12451 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12452 style = get_menu_style(hmenu_popup);
12453 ok(style == 0, "expected 0, got %u\n", style);
12454
12455 /* Alt+E, Enter */
12456 trace("testing a popup menu command\n");
12457 flush_sequence();
12458 keybd_event(VK_MENU, 0, 0, 0);
12459 keybd_event('E', 0, 0, 0);
12460 keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
12461 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12462 keybd_event(VK_RETURN, 0, 0, 0);
12463 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
12464 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
12465 {
12466 TranslateMessage(&msg);
12467 DispatchMessage(&msg);
12468 }
12469 if (!sequence_cnt) /* we didn't get any message */
12470 {
12471 skip( "queuing key events not supported\n" );
12472 goto done;
12473 }
12474 /* win98 queues only a WM_KEYUP and doesn't start menu tracking */
12475 if (sequence[0].message == WM_KEYUP && sequence[0].wParam == VK_MENU)
12476 {
12477 win_skip( "menu tracking through VK_MENU not supported\n" );
12478 goto done;
12479 }
12480 ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
12481
12482 /* Alt+F, Right, Enter */
12483 trace("testing submenu of a popup menu command\n");
12484 flush_sequence();
12485 keybd_event(VK_MENU, 0, 0, 0);
12486 keybd_event('F', 0, 0, 0);
12487 keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
12488 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12489 keybd_event(VK_RIGHT, 0, 0, 0);
12490 keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
12491 keybd_event(VK_RETURN, 0, 0, 0);
12492 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
12493 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
12494 {
12495 TranslateMessage(&msg);
12496 DispatchMessage(&msg);
12497 }
12498 ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
12499
12500 trace("testing single menu item command\n");
12501 flush_sequence();
12502 keybd_event(VK_MENU, 0, 0, 0);
12503 keybd_event('Q', 0, 0, 0);
12504 keybd_event('Q', 0, KEYEVENTF_KEYUP, 0);
12505 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12506 keybd_event(VK_ESCAPE, 0, 0, 0);
12507 keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0);
12508 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
12509 {
12510 TranslateMessage(&msg);
12511 DispatchMessage(&msg);
12512 }
12513 ok_sequence(wm_single_menu_item, "single menu item command", FALSE);
12514
12515 set_menu_style(hmenu, 0);
12516 style = get_menu_style(hmenu);
12517 ok(style == 0, "expected 0, got %u\n", style);
12518
12519 hmenu_popup = GetSubMenu(hmenu, 0);
12520 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12521 set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
12522 style = get_menu_style(hmenu_popup);
12523 ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
12524
12525 hmenu_popup = GetSubMenu(hmenu_popup, 0);
12526 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12527 style = get_menu_style(hmenu_popup);
12528 ok(style == 0, "expected 0, got %u\n", style);
12529
12530 /* Alt+F, Right, Enter */
12531 trace("testing submenu of a popup menu command\n");
12532 flush_sequence();
12533 keybd_event(VK_MENU, 0, 0, 0);
12534 keybd_event('F', 0, 0, 0);
12535 keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
12536 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12537 keybd_event(VK_RIGHT, 0, 0, 0);
12538 keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
12539 keybd_event(VK_RETURN, 0, 0, 0);
12540 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
12541 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
12542 {
12543 TranslateMessage(&msg);
12544 DispatchMessage(&msg);
12545 }
12546 ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
12547
12548 done:
12549 DestroyWindow(hwnd);
12550 DestroyMenu(hmenu);
12551 }
12552
12553
12554 static void test_paintingloop(void)
12555 {
12556 HWND hwnd;
12557
12558 paint_loop_done = 0;
12559 hwnd = CreateWindowExA(0x0,"PaintLoopWindowClass",
12560 "PaintLoopWindowClass",WS_OVERLAPPEDWINDOW,
12561 100, 100, 100, 100, 0, 0, 0, NULL );
12562 ok(hwnd != 0, "PaintLoop window error %u\n", GetLastError());
12563 ShowWindow(hwnd,SW_NORMAL);
12564 SetFocus(hwnd);
12565
12566 while (!paint_loop_done)
12567 {
12568 MSG msg;
12569 if (PeekMessageA(&msg, 0, 0, 0, 1))
12570 {
12571 TranslateMessage(&msg);
12572 DispatchMessage(&msg);
12573 }
12574 }
12575 DestroyWindow(hwnd);
12576 }
12577
12578 static void test_defwinproc(void)
12579 {
12580 HWND hwnd;
12581 MSG msg;
12582 int gotwmquit = FALSE;
12583 hwnd = CreateWindowExA(0, "static", "test_defwndproc", WS_POPUP, 0,0,0,0,0,0,0, NULL);
12584 assert(hwnd);
12585 DefWindowProcA( hwnd, WM_ENDSESSION, 1, 0);
12586 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) {
12587 if( msg.message == WM_QUIT) gotwmquit = TRUE;
12588 DispatchMessageA( &msg );
12589 }
12590 ok( gotwmquit == FALSE, "Unexpected WM_QUIT message!\n");
12591 DestroyWindow( hwnd);
12592 }
12593
12594 #define clear_clipboard(hwnd) clear_clipboard_(__LINE__, (hwnd))
12595 static void clear_clipboard_(int line, HWND hWnd)
12596 {
12597 BOOL succ;
12598 succ = OpenClipboard(hWnd);
12599 ok_(__FILE__, line)(succ, "OpenClipboard failed, err=%u\n", GetLastError());
12600 succ = EmptyClipboard();
12601 ok_(__FILE__, line)(succ, "EmptyClipboard failed, err=%u\n", GetLastError());
12602 succ = CloseClipboard();
12603 ok_(__FILE__, line)(succ, "CloseClipboard failed, err=%u\n", GetLastError());
12604 }
12605
12606 #define expect_HWND(expected, got) expect_HWND_(__LINE__, (expected), (got))
12607 static void expect_HWND_(int line, HWND expected, HWND got)
12608 {
12609 ok_(__FILE__, line)(got==expected, "Expected %p, got %p\n", expected, got);
12610 }
12611
12612 static WNDPROC pOldViewerProc;
12613
12614 static LRESULT CALLBACK recursive_viewer_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
12615 {
12616 static BOOL recursion_guard;
12617
12618 if (message == WM_DRAWCLIPBOARD && !recursion_guard)
12619 {
12620 recursion_guard = TRUE;
12621 clear_clipboard(hWnd);
12622 recursion_guard = FALSE;
12623 }
12624 return CallWindowProcA(pOldViewerProc, hWnd, message, wParam, lParam);
12625 }
12626
12627 static void test_clipboard_viewers(void)
12628 {
12629 static struct message wm_change_cb_chain[] =
12630 {
12631 { WM_CHANGECBCHAIN, sent|wparam|lparam, 0, 0 },
12632 { 0 }
12633 };
12634 static const struct message wm_clipboard_destroyed[] =
12635 {
12636 { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
12637 { 0 }
12638 };
12639 static struct message wm_clipboard_changed[] =
12640 {
12641 { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
12642 { 0 }
12643 };
12644 static struct message wm_clipboard_changed_and_owned[] =
12645 {
12646 { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
12647 { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
12648 { 0 }
12649 };
12650
12651 HINSTANCE hInst = GetModuleHandleA(NULL);
12652 HWND hWnd1, hWnd2, hWnd3;
12653 HWND hOrigViewer;
12654 HWND hRet;
12655
12656 hWnd1 = CreateWindowExA(0, "TestWindowClass", "Clipboard viewer test wnd 1",
12657 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12658 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12659 GetDesktopWindow(), NULL, hInst, NULL);
12660 hWnd2 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 2",
12661 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12662 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12663 GetDesktopWindow(), NULL, hInst, NULL);
12664 hWnd3 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 3",
12665 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12666 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12667 GetDesktopWindow(), NULL, hInst, NULL);
12668 trace("clipbd viewers: hWnd1=%p, hWnd2=%p, hWnd3=%p\n", hWnd1, hWnd2, hWnd3);
12669 assert(hWnd1 && hWnd2 && hWnd3);
12670
12671 flush_sequence();
12672
12673 /* Test getting the clipboard viewer and setting the viewer to NULL. */
12674 hOrigViewer = GetClipboardViewer();
12675 hRet = SetClipboardViewer(NULL);
12676 ok_sequence(WmEmptySeq, "set viewer to NULL", FALSE);
12677 expect_HWND(hOrigViewer, hRet);
12678 expect_HWND(NULL, GetClipboardViewer());
12679
12680 /* Test registering hWnd1 as a viewer. */
12681 hRet = SetClipboardViewer(hWnd1);
12682 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12683 ok_sequence(wm_clipboard_changed, "set viewer NULL->1", FALSE);
12684 expect_HWND(NULL, hRet);
12685 expect_HWND(hWnd1, GetClipboardViewer());
12686
12687 /* Test that changing the clipboard actually refreshes the registered viewer. */
12688 clear_clipboard(hWnd1);
12689 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12690 ok_sequence(wm_clipboard_changed, "clear clipbd (viewer=owner=1)", FALSE);
12691
12692 /* Again, but with different owner. */
12693 clear_clipboard(hWnd2);
12694 wm_clipboard_changed_and_owned[1].wParam = (WPARAM) GetClipboardOwner();
12695 ok_sequence(wm_clipboard_changed_and_owned, "clear clipbd (viewer=1, owner=2)", FALSE);
12696
12697 /* Test re-registering same window. */
12698 hRet = SetClipboardViewer(hWnd1);
12699 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12700 ok_sequence(wm_clipboard_changed, "set viewer 1->1", FALSE);
12701 expect_HWND(hWnd1, hRet);
12702 expect_HWND(hWnd1, GetClipboardViewer());
12703
12704 /* Test ChangeClipboardChain. */
12705 ChangeClipboardChain(hWnd2, hWnd3);
12706 wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
12707 wm_change_cb_chain[0].lParam = (LPARAM) hWnd3;
12708 ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=3)", FALSE);
12709 expect_HWND(hWnd1, GetClipboardViewer());
12710
12711 ChangeClipboardChain(hWnd2, NULL);
12712 wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
12713 wm_change_cb_chain[0].lParam = 0;
12714 ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=NULL)", FALSE);
12715 expect_HWND(hWnd1, GetClipboardViewer());
12716
12717 ChangeClipboardChain(NULL, hWnd2);
12718 ok_sequence(WmEmptySeq, "change chain (viewer=1, remove=NULL, next=2)", TRUE);
12719 expect_HWND(hWnd1, GetClipboardViewer());
12720
12721 /* Actually change clipboard viewer with ChangeClipboardChain. */
12722 ChangeClipboardChain(hWnd1, hWnd2);
12723 ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=2)", FALSE);
12724 expect_HWND(hWnd2, GetClipboardViewer());
12725
12726 /* Test that no refresh messages are sent when viewer has unregistered. */
12727 clear_clipboard(hWnd2);
12728 ok_sequence(WmEmptySeq, "clear clipd (viewer=2, owner=1)", FALSE);
12729
12730 /* Register hWnd1 again. */
12731 ChangeClipboardChain(hWnd2, hWnd1);
12732 ok_sequence(WmEmptySeq, "change chain (viewer=remove=2, next=1)", FALSE);
12733 expect_HWND(hWnd1, GetClipboardViewer());
12734
12735 /* Subclass hWnd1 so that when it receives a WM_DRAWCLIPBOARD message, it
12736 * changes the clipboard. When this happens, the system shouldn't send
12737 * another WM_DRAWCLIPBOARD (as this could cause an infinite loop).
12738 */
12739 pOldViewerProc = (WNDPROC) SetWindowLongPtrA(hWnd1, GWLP_WNDPROC, (LONG_PTR) recursive_viewer_proc);
12740 clear_clipboard(hWnd2);
12741 /* The clipboard owner is changed in recursive_viewer_proc: */
12742 wm_clipboard_changed[0].wParam = (WPARAM) hWnd2;
12743 ok_sequence(wm_clipboard_changed, "recursive clear clipbd (viewer=1, owner=2)", TRUE);
12744
12745 /* Test unregistering. */
12746 ChangeClipboardChain(hWnd1, NULL);
12747 ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=NULL)", FALSE);
12748 expect_HWND(NULL, GetClipboardViewer());
12749
12750 clear_clipboard(hWnd1);
12751 ok_sequence(wm_clipboard_destroyed, "clear clipbd (no viewer, owner=1)", FALSE);
12752
12753 DestroyWindow(hWnd1);
12754 DestroyWindow(hWnd2);
12755 DestroyWindow(hWnd3);
12756 SetClipboardViewer(hOrigViewer);
12757 }
12758
12759 static void test_PostMessage(void)
12760 {
12761 static const struct
12762 {
12763 HWND hwnd;
12764 BOOL ret;
12765 } data[] =
12766 {
12767 { HWND_TOP /* 0 */, TRUE },
12768 { HWND_BROADCAST, TRUE },
12769 { HWND_BOTTOM, TRUE },
12770 { HWND_TOPMOST, TRUE },
12771 { HWND_NOTOPMOST, FALSE },
12772 { HWND_MESSAGE, FALSE },
12773 { (HWND)0xdeadbeef, FALSE }
12774 };
12775 int i;
12776 HWND hwnd;
12777 BOOL ret;
12778 MSG msg;
12779 static const WCHAR staticW[] = {'s','t','a','t','i','c',0};
12780
12781 SetLastError(0xdeadbeef);
12782 hwnd = CreateWindowExW(0, staticW, NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
12783 if (!hwnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
12784 {
12785 win_skip("Skipping some PostMessage tests on Win9x/WinMe\n");
12786 return;
12787 }
12788 assert(hwnd);
12789
12790 flush_events();
12791
12792 PostMessage(hwnd, WM_USER+1, 0x1234, 0x5678);
12793 PostMessage(0, WM_USER+2, 0x5678, 0x1234);
12794
12795 for (i = 0; i < sizeof(data)/sizeof(data[0]); i++)
12796 {
12797 memset(&msg, 0xab, sizeof(msg));
12798 ret = PeekMessageA(&msg, data[i].hwnd, 0, 0, PM_NOREMOVE);
12799 ok(ret == data[i].ret, "%d: hwnd %p expected %d, got %d\n", i, data[i].hwnd, data[i].ret, ret);
12800 if (data[i].ret)
12801 {
12802 if (data[i].hwnd)
12803 ok(ret && msg.hwnd == 0 && msg.message == WM_USER+2 &&
12804 msg.wParam == 0x5678 && msg.lParam == 0x1234,
12805 "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/0/WM_USER+2/0x5678/0x1234\n",
12806 i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam);
12807 else
12808 ok(ret && msg.hwnd == hwnd && msg.message == WM_USER+1 &&
12809 msg.wParam == 0x1234 && msg.lParam == 0x5678,
12810 "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/%p/WM_USER+1/0x1234/0x5678\n",
12811 i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam, msg.hwnd);
12812 }
12813 }
12814
12815 DestroyWindow(hwnd);
12816 flush_events();
12817 }
12818
12819 static const struct
12820 {
12821 DWORD exp, broken;
12822 BOOL todo;
12823 } wait_idle_expect[] =
12824 {
12825 /* 0 */ { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12826 { WAIT_TIMEOUT, 0, FALSE },
12827 { WAIT_TIMEOUT, 0, FALSE },
12828 { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12829 { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12830 /* 5 */ { WAIT_TIMEOUT, 0, FALSE },
12831 { WAIT_TIMEOUT, 0, FALSE },
12832 { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
12833 { 0, 0, FALSE },
12834 { 0, 0, FALSE },
12835 /* 10 */ { 0, 0, FALSE },
12836 { 0, 0, FALSE },
12837 { 0, WAIT_TIMEOUT, FALSE },
12838 { 0, 0, FALSE },
12839 { 0, 0, FALSE },
12840 /* 15 */ { 0, 0, FALSE },
12841 { WAIT_TIMEOUT, 0, FALSE },
12842 { WAIT_TIMEOUT, 0, FALSE },
12843 { WAIT_TIMEOUT, 0, FALSE },
12844 { WAIT_TIMEOUT, 0, FALSE },
12845 /* 20 */ { WAIT_TIMEOUT, 0, FALSE },
12846 };
12847
12848 static DWORD CALLBACK do_wait_idle_child_thread( void *arg )
12849 {
12850 MSG msg;
12851
12852 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12853 Sleep( 200 );
12854 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12855 return 0;
12856 }
12857
12858 static void do_wait_idle_child( int arg )
12859 {
12860 WNDCLASS cls;
12861 MSG msg;
12862 HWND hwnd = 0;
12863 HANDLE thread;
12864 DWORD id;
12865 HANDLE start_event = OpenEventA( EVENT_ALL_ACCESS, FALSE, "test_WaitForInputIdle_start" );
12866 HANDLE end_event = OpenEventA( EVENT_ALL_ACCESS, FALSE, "test_WaitForInputIdle_end" );
12867
12868 memset( &cls, 0, sizeof(cls) );
12869 cls.lpfnWndProc = DefWindowProc;
12870 cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
12871 cls.hCursor = LoadCursor(0, IDC_ARROW);
12872 cls.lpszClassName = "TestClass";
12873 RegisterClass( &cls );
12874
12875 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ); /* create the msg queue */
12876
12877 ok( start_event != 0, "failed to create start event, error %u\n", GetLastError() );
12878 ok( end_event != 0, "failed to create end event, error %u\n", GetLastError() );
12879
12880 switch (arg)
12881 {
12882 case 0:
12883 SetEvent( start_event );
12884 break;
12885 case 1:
12886 SetEvent( start_event );
12887 Sleep( 200 );
12888 PeekMessage( &msg, 0, 0, 0, PM_REMOVE );
12889 break;
12890 case 2:
12891 SetEvent( start_event );
12892 Sleep( 200 );
12893 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12894 PostThreadMessage( GetCurrentThreadId(), WM_COMMAND, 0x1234, 0xabcd );
12895 PeekMessage( &msg, 0, 0, 0, PM_REMOVE );
12896 break;
12897 case 3:
12898 SetEvent( start_event );
12899 Sleep( 200 );
12900 SendMessage( HWND_BROADCAST, WM_WININICHANGE, 0, 0 );
12901 break;
12902 case 4:
12903 SetEvent( start_event );
12904 Sleep( 200 );
12905 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12906 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessage( &msg );
12907 break;
12908 case 5:
12909 SetEvent( start_event );
12910 Sleep( 200 );
12911 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12912 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12913 break;
12914 case 6:
12915 SetEvent( start_event );
12916 Sleep( 200 );
12917 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12918 while (PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ))
12919 {
12920 GetMessage( &msg, 0, 0, 0 );
12921 DispatchMessage( &msg );
12922 }
12923 break;
12924 case 7:
12925 SetEvent( start_event );
12926 Sleep( 200 );
12927 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12928 SetTimer( hwnd, 3, 1, NULL );
12929 Sleep( 200 );
12930 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessage( &msg );
12931 break;
12932 case 8:
12933 SetEvent( start_event );
12934 Sleep( 200 );
12935 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12936 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12937 break;
12938 case 9:
12939 SetEvent( start_event );
12940 Sleep( 200 );
12941 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12942 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12943 for (;;) GetMessage( &msg, 0, 0, 0 );
12944 break;
12945 case 10:
12946 SetEvent( start_event );
12947 Sleep( 200 );
12948 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
12949 SetTimer( hwnd, 3, 1, NULL );
12950 Sleep( 200 );
12951 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
12952 break;
12953 case 11:
12954 SetEvent( start_event );
12955 Sleep( 200 );
12956 return; /* exiting the process makes WaitForInputIdle return success too */
12957 case 12:
12958 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12959 Sleep( 200 );
12960 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
12961 SetEvent( start_event );
12962 break;
12963 case 13:
12964 SetEvent( start_event );
12965 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );
12966 Sleep( 200 );
12967 thread = CreateThread( NULL, 0, do_wait_idle_child_thread, NULL, 0, &id );
12968 WaitForSingleObject( thread, 10000 );
12969 CloseHandle( thread );
12970 break;
12971 case 14:
12972 SetEvent( start_event );
12973 Sleep( 200 );
12974 PeekMessage( &msg, HWND_TOPMOST, 0, 0, PM_NOREMOVE );
12975 break;
12976 case 15:
12977 SetEvent( start_event );
12978 Sleep( 200 );
12979 PeekMessage( &msg, HWND_BROADCAST, 0, 0, PM_NOREMOVE );
12980 break;
12981 case 16:
12982 SetEvent( start_event );
12983 Sleep( 200 );
12984 PeekMessage( &msg, HWND_BOTTOM, 0, 0, PM_NOREMOVE );
12985 break;
12986 case 17:
12987 SetEvent( start_event );
12988 Sleep( 200 );
12989 PeekMessage( &msg, (HWND)0xdeadbeef, 0, 0, PM_NOREMOVE );
12990 break;
12991 case 18:
12992 SetEvent( start_event );
12993 Sleep( 200 );
12994 PeekMessage( &msg, HWND_NOTOPMOST, 0, 0, PM_NOREMOVE );
12995 break;
12996 case 19:
12997 SetEvent( start_event );
12998 Sleep( 200 );
12999 PeekMessage( &msg, HWND_MESSAGE, 0, 0, PM_NOREMOVE );
13000 break;
13001 case 20:
13002 SetEvent( start_event );
13003 Sleep( 200 );
13004 PeekMessage( &msg, GetDesktopWindow(), 0, 0, PM_NOREMOVE );
13005 break;
13006 }
13007 WaitForSingleObject( end_event, 2000 );
13008 CloseHandle( start_event );
13009 CloseHandle( end_event );
13010 if (hwnd) DestroyWindow( hwnd );
13011 }
13012
13013 static LRESULT CALLBACK wait_idle_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
13014 {
13015 if (msg == WM_WININICHANGE) Sleep( 200 ); /* make sure the child waits */
13016 return DefWindowProcA( hwnd, msg, wp, lp );
13017 }
13018
13019 static DWORD CALLBACK wait_idle_thread( void *arg )
13020 {
13021 WNDCLASS cls;
13022 MSG msg;
13023 HWND hwnd;
13024
13025 memset( &cls, 0, sizeof(cls) );
13026 cls.lpfnWndProc = wait_idle_proc;
13027 cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
13028 cls.hCursor = LoadCursor(0, IDC_ARROW);
13029 cls.lpszClassName = "TestClass";
13030 RegisterClass( &cls );
13031
13032 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
13033 while (GetMessage( &msg, 0, 0, 0 )) DispatchMessage( &msg );
13034 DestroyWindow(hwnd);
13035 return 0;
13036 }
13037
13038 static void test_WaitForInputIdle( char *argv0 )
13039 {
13040 char path[MAX_PATH];
13041 PROCESS_INFORMATION pi;
13042 STARTUPINFOA startup;
13043 BOOL ret;
13044 HANDLE start_event, end_event, thread;
13045 unsigned int i;
13046 DWORD id;
13047 const IMAGE_DOS_HEADER *dos = (const IMAGE_DOS_HEADER *)GetModuleHandleA(0);
13048 const IMAGE_NT_HEADERS *nt = (const IMAGE_NT_HEADERS *)((const char *)dos + dos->e_lfanew);
13049 BOOL console_app = (nt->OptionalHeader.Subsystem != IMAGE_SUBSYSTEM_WINDOWS_GUI);
13050
13051 if (console_app) /* build the test with -mwindows for better coverage */
13052 trace( "not built as a GUI app, WaitForInputIdle may not be fully tested\n" );
13053
13054 start_event = CreateEventA(NULL, 0, 0, "test_WaitForInputIdle_start");
13055 end_event = CreateEventA(NULL, 0, 0, "test_WaitForInputIdle_end");
13056 ok(start_event != 0, "failed to create start event, error %u\n", GetLastError());
13057 ok(end_event != 0, "failed to create end event, error %u\n", GetLastError());
13058
13059 memset( &startup, 0, sizeof(startup) );
13060 startup.cb = sizeof(startup);
13061 startup.dwFlags = STARTF_USESHOWWINDOW;
13062 startup.wShowWindow = SW_SHOWNORMAL;
13063
13064 thread = CreateThread( NULL, 0, wait_idle_thread, NULL, 0, &id );
13065
13066 for (i = 0; i < sizeof(wait_idle_expect)/sizeof(wait_idle_expect[0]); i++)
13067 {
13068 ResetEvent( start_event );
13069 ResetEvent( end_event );
13070 sprintf( path, "%s msg %u", argv0, i );
13071 ret = CreateProcessA( NULL, path, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &pi );
13072 ok( ret, "CreateProcess '%s' failed err %u.\n", path, GetLastError() );
13073 if (ret)
13074 {
13075 ret = WaitForSingleObject( start_event, 5000 );
13076 ok( ret == WAIT_OBJECT_0, "%u: WaitForSingleObject failed\n", i );
13077 if (ret == WAIT_OBJECT_0)
13078 {
13079 ret = WaitForInputIdle( pi.hProcess, 1000 );
13080 if (ret == WAIT_FAILED)
13081 ok( console_app ||
13082 ret == wait_idle_expect[i].exp ||
13083 broken(ret == wait_idle_expect[i].broken),
13084 "%u: WaitForInputIdle error %08x expected %08x\n",
13085 i, ret, wait_idle_expect[i].exp );
13086 else if (wait_idle_expect[i].todo)
13087 todo_wine
13088 ok( ret == wait_idle_expect[i].exp || broken(ret == wait_idle_expect[i].broken),
13089 "%u: WaitForInputIdle error %08x expected %08x\n",
13090 i, ret, wait_idle_expect[i].exp );
13091 else
13092 ok( ret == wait_idle_expect[i].exp || broken(ret == wait_idle_expect[i].broken),
13093 "%u: WaitForInputIdle error %08x expected %08x\n",
13094 i, ret, wait_idle_expect[i].exp );
13095 SetEvent( end_event );
13096 WaitForSingleObject( pi.hProcess, 1000 ); /* give it a chance to exit on its own */
13097 }
13098 TerminateProcess( pi.hProcess, 0 ); /* just in case */
13099 winetest_wait_child_process( pi.hProcess );
13100 ret = WaitForInputIdle( pi.hProcess, 100 );
13101 ok( ret == WAIT_FAILED, "%u: WaitForInputIdle after exit error %08x\n", i, ret );
13102 CloseHandle( pi.hProcess );
13103 CloseHandle( pi.hThread );
13104 }
13105 }
13106 CloseHandle( start_event );
13107 PostThreadMessage( id, WM_QUIT, 0, 0 );
13108 WaitForSingleObject( thread, 10000 );
13109 CloseHandle( thread );
13110 }
13111
13112 static const struct message WmSetParentSeq_1[] = {
13113 { WM_SHOWWINDOW, sent|wparam, 0 },
13114 { EVENT_OBJECT_PARENTCHANGE, winevent_hook|wparam|lparam, 0, 0 },
13115 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
13116 { WM_CHILDACTIVATE, sent },
13117 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW|SWP_NOCLIENTSIZE },
13118 { WM_MOVE, sent|defwinproc|wparam, 0 },
13119 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
13120 { WM_SHOWWINDOW, sent|wparam, 1 },
13121 { 0 }
13122 };
13123
13124 static const struct message WmSetParentSeq_2[] = {
13125 { WM_SHOWWINDOW, sent|wparam, 0 },
13126 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
13127 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
13128 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
13129 { HCBT_SETFOCUS, hook|optional },
13130 { WM_NCACTIVATE, sent|wparam|optional, 0 },
13131 { WM_ACTIVATE, sent|wparam|optional, 0 },
13132 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
13133 { WM_KILLFOCUS, sent|wparam, 0 },
13134 { EVENT_OBJECT_PARENTCHANGE, winevent_hook|wparam|lparam, 0, 0 },
13135 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
13136 { HCBT_ACTIVATE, hook|optional },
13137 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
13138 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
13139 { WM_NCACTIVATE, sent|wparam|optional, 1 },
13140 { WM_ACTIVATE, sent|wparam|optional, 1 },
13141 { HCBT_SETFOCUS, hook|optional },
13142 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
13143 { WM_SETFOCUS, sent|optional|defwinproc },
13144 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOREDRAW|SWP_NOSIZE|SWP_NOCLIENTSIZE },
13145 { WM_MOVE, sent|defwinproc|wparam, 0 },
13146 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
13147 { WM_SHOWWINDOW, sent|wparam, 1 },
13148 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
13149 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
13150 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
13151 { 0 }
13152 };
13153
13154
13155 static void test_SetParent(void)
13156 {
13157 HWND parent1, parent2, child, popup;
13158 RECT rc, rc_old;
13159
13160 parent1 = CreateWindowEx(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW,
13161 100, 100, 200, 200, 0, 0, 0, NULL);
13162 ok(parent1 != 0, "Failed to create parent1 window\n");
13163
13164 parent2 = CreateWindowEx(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW,
13165 400, 100, 200, 200, 0, 0, 0, NULL);
13166 ok(parent2 != 0, "Failed to create parent2 window\n");
13167
13168 /* WS_CHILD window */
13169 child = CreateWindowEx(0, "TestWindowClass", NULL, WS_CHILD | WS_VISIBLE,
13170 10, 10, 150, 150, parent1, 0, 0, NULL);
13171 ok(child != 0, "Failed to create child window\n");
13172
13173 GetWindowRect(parent1, &rc);
13174 trace("parent1 (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
13175 GetWindowRect(child, &rc_old);
13176 MapWindowPoints(0, parent1, (POINT *)&rc_old, 2);
13177 trace("child (%d,%d)-(%d,%d)\n", rc_old.left, rc_old.top, rc_old.right, rc_old.bottom);
13178
13179 flush_sequence();
13180
13181 SetParent(child, parent2);
13182 flush_events();
13183 ok_sequence(WmSetParentSeq_1, "SetParent() visible WS_CHILD", TRUE);
13184
13185 ok(GetWindowLongA(child, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
13186 ok(!IsWindowVisible(child), "IsWindowVisible() should return FALSE\n");
13187
13188 GetWindowRect(parent2, &rc);
13189 trace("parent2 (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
13190 GetWindowRect(child, &rc);
13191 MapWindowPoints(0, parent2, (POINT *)&rc, 2);
13192 trace("child (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
13193
13194 ok(EqualRect(&rc_old, &rc), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
13195 rc_old.left, rc_old.top, rc_old.right, rc_old.bottom,
13196 rc.left, rc.top, rc.right, rc.bottom );
13197
13198 /* WS_POPUP window */
13199 popup = CreateWindowEx(0, "TestWindowClass", NULL, WS_POPUP | WS_VISIBLE,
13200 20, 20, 100, 100, 0, 0, 0, NULL);
13201 ok(popup != 0, "Failed to create popup window\n");
13202
13203 GetWindowRect(popup, &rc_old);
13204 trace("popup (%d,%d)-(%d,%d)\n", rc_old.left, rc_old.top, rc_old.right, rc_old.bottom);
13205
13206 flush_sequence();
13207
13208 SetParent(popup, child);
13209 flush_events();
13210 ok_sequence(WmSetParentSeq_2, "SetParent() visible WS_POPUP", TRUE);
13211
13212 ok(GetWindowLongA(popup, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
13213 ok(!IsWindowVisible(popup), "IsWindowVisible() should return FALSE\n");
13214
13215 GetWindowRect(child, &rc);
13216 trace("parent2 (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
13217 GetWindowRect(popup, &rc);
13218 MapWindowPoints(0, child, (POINT *)&rc, 2);
13219 trace("popup (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
13220
13221 ok(EqualRect(&rc_old, &rc), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
13222 rc_old.left, rc_old.top, rc_old.right, rc_old.bottom,
13223 rc.left, rc.top, rc.right, rc.bottom );
13224
13225 DestroyWindow(popup);
13226 DestroyWindow(child);
13227 DestroyWindow(parent1);
13228 DestroyWindow(parent2);
13229
13230 flush_sequence();
13231 }
13232
13233 static const struct message WmKeyReleaseOnly[] = {
13234 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 0x41, 0x80000001 },
13235 { WM_KEYUP, sent|wparam|lparam, 0x41, 0x80000001 },
13236 { 0 }
13237 };
13238 static const struct message WmKeyPressNormal[] = {
13239 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 0x41, 0x1 },
13240 { WM_KEYDOWN, sent|wparam|lparam, 0x41, 0x1 },
13241 { 0 }
13242 };
13243 static const struct message WmKeyPressRepeat[] = {
13244 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 0x41, 0x40000001 },
13245 { WM_KEYDOWN, sent|wparam|lparam, 0x41, 0x40000001 },
13246 { 0 }
13247 };
13248 static const struct message WmKeyReleaseNormal[] = {
13249 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 0x41, 0xc0000001 },
13250 { WM_KEYUP, sent|wparam|lparam, 0x41, 0xc0000001 },
13251 { 0 }
13252 };
13253
13254 static void test_keyflags(void)
13255 {
13256 HWND test_window;
13257 SHORT key_state;
13258 BYTE keyboard_state[256];
13259 MSG msg;
13260
13261 test_window = CreateWindowEx(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
13262 100, 100, 200, 200, 0, 0, 0, NULL);
13263
13264 flush_events();
13265 flush_sequence();
13266
13267 /* keyup without a keydown */
13268 keybd_event(0x41, 0, KEYEVENTF_KEYUP, 0);
13269 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13270 DispatchMessage(&msg);
13271 ok_sequence(WmKeyReleaseOnly, "key release only", TRUE);
13272
13273 key_state = GetAsyncKeyState(0x41);
13274 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13275
13276 key_state = GetKeyState(0x41);
13277 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13278
13279 /* keydown */
13280 keybd_event(0x41, 0, 0, 0);
13281 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13282 DispatchMessage(&msg);
13283 ok_sequence(WmKeyPressNormal, "key press only", FALSE);
13284
13285 key_state = GetAsyncKeyState(0x41);
13286 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13287
13288 key_state = GetKeyState(0x41);
13289 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13290
13291 /* keydown repeat */
13292 keybd_event(0x41, 0, 0, 0);
13293 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13294 DispatchMessage(&msg);
13295 ok_sequence(WmKeyPressRepeat, "key press repeat", FALSE);
13296
13297 key_state = GetAsyncKeyState(0x41);
13298 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13299
13300 key_state = GetKeyState(0x41);
13301 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13302
13303 /* keyup */
13304 keybd_event(0x41, 0, KEYEVENTF_KEYUP, 0);
13305 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13306 DispatchMessage(&msg);
13307 ok_sequence(WmKeyReleaseNormal, "key release repeat", FALSE);
13308
13309 key_state = GetAsyncKeyState(0x41);
13310 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13311
13312 key_state = GetKeyState(0x41);
13313 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13314
13315 /* set the key state in this thread */
13316 GetKeyboardState(keyboard_state);
13317 keyboard_state[0x41] = 0x80;
13318 SetKeyboardState(keyboard_state);
13319
13320 key_state = GetAsyncKeyState(0x41);
13321 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13322
13323 /* keydown */
13324 keybd_event(0x41, 0, 0, 0);
13325 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13326 DispatchMessage(&msg);
13327 ok_sequence(WmKeyPressRepeat, "key press after setkeyboardstate", TRUE);
13328
13329 key_state = GetAsyncKeyState(0x41);
13330 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13331
13332 key_state = GetKeyState(0x41);
13333 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13334
13335 /* clear the key state in this thread */
13336 GetKeyboardState(keyboard_state);
13337 keyboard_state[0x41] = 0;
13338 SetKeyboardState(keyboard_state);
13339
13340 key_state = GetAsyncKeyState(0x41);
13341 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13342
13343 /* keyup */
13344 keybd_event(0x41, 0, KEYEVENTF_KEYUP, 0);
13345 while (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13346 DispatchMessage(&msg);
13347 ok_sequence(WmKeyReleaseOnly, "key release after setkeyboardstate", TRUE);
13348
13349 key_state = GetAsyncKeyState(0x41);
13350 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13351
13352 key_state = GetKeyState(0x41);
13353 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13354
13355 DestroyWindow(test_window);
13356 flush_sequence();
13357 }
13358
13359 static const struct message WmHotkeyPressLWIN[] = {
13360 { WM_KEYDOWN, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED },
13361 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 1 },
13362 { WM_KEYDOWN, sent|wparam|lparam, VK_LWIN, 1 },
13363 { 0 }
13364 };
13365 static const struct message WmHotkeyPress[] = {
13366 { WM_KEYDOWN, kbd_hook|lparam, 0, LLKHF_INJECTED },
13367 { WM_HOTKEY, sent|wparam, 5 },
13368 { 0 }
13369 };
13370 static const struct message WmHotkeyRelease[] = {
13371 { WM_KEYUP, kbd_hook|lparam, 0, LLKHF_INJECTED|LLKHF_UP },
13372 { HCBT_KEYSKIPPED, hook|lparam|optional, 0, 0x80000001 },
13373 { WM_KEYUP, sent|lparam, 0, 0x80000001 },
13374 { 0 }
13375 };
13376 static const struct message WmHotkeyReleaseLWIN[] = {
13377 { WM_KEYUP, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED|LLKHF_UP },
13378 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 0xc0000001 },
13379 { WM_KEYUP, sent|wparam|lparam, VK_LWIN, 0xc0000001 },
13380 { 0 }
13381 };
13382 static const struct message WmHotkeyCombined[] = {
13383 { WM_KEYDOWN, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED },
13384 { WM_KEYDOWN, kbd_hook|lparam, 0, LLKHF_INJECTED },
13385 { WM_KEYUP, kbd_hook|lparam, 0, LLKHF_INJECTED|LLKHF_UP },
13386 { WM_KEYUP, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED|LLKHF_UP },
13387 { WM_APP, sent, 0, 0 },
13388 { WM_HOTKEY, sent|wparam, 5 },
13389 { WM_APP+1, sent, 0, 0 },
13390 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 1 },
13391 { WM_KEYDOWN, sent|wparam|lparam, VK_LWIN, 1 },
13392 { HCBT_KEYSKIPPED, hook|optional, 0, 0x80000001 },
13393 { WM_KEYUP, sent, 0, 0x80000001 }, /* lparam not checked so the sequence isn't a todo */
13394 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 0xc0000001 },
13395 { WM_KEYUP, sent|wparam|lparam, VK_LWIN, 0xc0000001 },
13396 { 0 }
13397 };
13398 static const struct message WmHotkeyPrevious[] = {
13399 { WM_KEYDOWN, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED },
13400 { WM_KEYDOWN, kbd_hook|lparam, 0, LLKHF_INJECTED },
13401 { WM_KEYUP, kbd_hook|lparam, 0, LLKHF_INJECTED|LLKHF_UP },
13402 { WM_KEYUP, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED|LLKHF_UP },
13403 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 1 },
13404 { WM_KEYDOWN, sent|wparam|lparam, VK_LWIN, 1 },
13405 { HCBT_KEYSKIPPED, hook|lparam|optional, 0, 1 },
13406 { WM_KEYDOWN, sent|lparam, 0, 1 },
13407 { HCBT_KEYSKIPPED, hook|optional|lparam, 0, 0xc0000001 },
13408 { WM_KEYUP, sent|lparam, 0, 0xc0000001 },
13409 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 0xc0000001 },
13410 { WM_KEYUP, sent|wparam|lparam, VK_LWIN, 0xc0000001 },
13411 { 0 }
13412 };
13413 static const struct message WmHotkeyNew[] = {
13414 { WM_KEYDOWN, kbd_hook|lparam, 0, LLKHF_INJECTED },
13415 { WM_KEYUP, kbd_hook|lparam, 0, LLKHF_INJECTED|LLKHF_UP },
13416 { WM_HOTKEY, sent|wparam, 5 },
13417 { HCBT_KEYSKIPPED, hook|optional, 0, 0x80000001 },
13418 { WM_KEYUP, sent, 0, 0x80000001 }, /* lparam not checked so the sequence isn't a todo */
13419 { 0 }
13420 };
13421
13422 static int hotkey_letter;
13423
13424 static LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
13425 {
13426 struct recvd_message msg;
13427
13428 if (nCode == HC_ACTION)
13429 {
13430 KBDLLHOOKSTRUCT *kdbhookstruct = (KBDLLHOOKSTRUCT*)lParam;
13431
13432 msg.hwnd = 0;
13433 msg.message = wParam;
13434 msg.flags = kbd_hook|wparam|lparam;
13435 msg.wParam = kdbhookstruct->vkCode;
13436 msg.lParam = kdbhookstruct->flags;
13437 msg.descr = "KeyboardHookProc";
13438 add_message(&msg);
13439
13440 if (wParam == WM_KEYUP || wParam == WM_KEYDOWN)
13441 {
13442 ok(kdbhookstruct->vkCode == VK_LWIN || kdbhookstruct->vkCode == hotkey_letter,
13443 "unexpected keycode %x\n", kdbhookstruct->vkCode);
13444 }
13445 }
13446
13447 return CallNextHookEx(hKBD_hook, nCode, wParam, lParam);
13448 }
13449
13450 static void test_hotkey(void)
13451 {
13452 HWND test_window, taskbar_window;
13453 BOOL ret;
13454 MSG msg;
13455 DWORD queue_status;
13456 SHORT key_state;
13457
13458 SetLastError(0xdeadbeef);
13459 ret = UnregisterHotKey(NULL, 0);
13460 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13461 ok(GetLastError() == ERROR_HOTKEY_NOT_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13462 "unexpected error %d\n", GetLastError());
13463
13464 if (ret == TRUE)
13465 {
13466 skip("hotkeys not supported\n");
13467 return;
13468 }
13469
13470 test_window = CreateWindowEx(0, "HotkeyWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
13471 100, 100, 200, 200, 0, 0, 0, NULL);
13472
13473 flush_sequence();
13474
13475 SetLastError(0xdeadbeef);
13476 ret = UnregisterHotKey(test_window, 0);
13477 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13478 ok(GetLastError() == ERROR_HOTKEY_NOT_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13479 "unexpected error %d\n", GetLastError());
13480
13481 /* Search for a Windows Key + letter combination that hasn't been registered */
13482 for (hotkey_letter = 0x41; hotkey_letter <= 0x51; hotkey_letter ++)
13483 {
13484 SetLastError(0xdeadbeef);
13485 ret = RegisterHotKey(test_window, 5, MOD_WIN, hotkey_letter);
13486
13487 if (ret == TRUE)
13488 {
13489 break;
13490 }
13491 else
13492 {
13493 ok(GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13494 "unexpected error %d\n", GetLastError());
13495 }
13496 }
13497
13498 if (hotkey_letter == 0x52)
13499 {
13500 ok(0, "Couldn't find any free Windows Key + letter combination\n");
13501 goto end;
13502 }
13503
13504 hKBD_hook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProc, GetModuleHandle(NULL), 0);
13505 if (!hKBD_hook) win_skip("WH_KEYBOARD_LL is not supported\n");
13506
13507 /* Same key combination, different id */
13508 SetLastError(0xdeadbeef);
13509 ret = RegisterHotKey(test_window, 4, MOD_WIN, hotkey_letter);
13510 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13511 ok(GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13512 "unexpected error %d\n", GetLastError());
13513
13514 /* Same key combination, different window */
13515 SetLastError(0xdeadbeef);
13516 ret = RegisterHotKey(NULL, 5, MOD_WIN, hotkey_letter);
13517 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13518 ok(GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13519 "unexpected error %d\n", GetLastError());
13520
13521 /* Register the same hotkey twice */
13522 SetLastError(0xdeadbeef);
13523 ret = RegisterHotKey(test_window, 5, MOD_WIN, hotkey_letter);
13524 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13525 ok(GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13526 "unexpected error %d\n", GetLastError());
13527
13528 /* Window on another thread */
13529 taskbar_window = FindWindowA("Shell_TrayWnd", NULL);
13530 if (!taskbar_window)
13531 {
13532 skip("no taskbar?\n");
13533 }
13534 else
13535 {
13536 SetLastError(0xdeadbeef);
13537 ret = RegisterHotKey(taskbar_window, 5, 0, hotkey_letter);
13538 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13539 ok(GetLastError() == ERROR_WINDOW_OF_OTHER_THREAD || broken(GetLastError() == 0xdeadbeef),
13540 "unexpected error %d\n", GetLastError());
13541 }
13542
13543 /* Inject the appropriate key sequence */
13544 keybd_event(VK_LWIN, 0, 0, 0);
13545 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13546 DispatchMessage(&msg);
13547 ok_sequence(WmHotkeyPressLWIN, "window hotkey press LWIN", FALSE);
13548
13549 keybd_event(hotkey_letter, 0, 0, 0);
13550 queue_status = GetQueueStatus(QS_HOTKEY);
13551 ok((queue_status & (QS_HOTKEY << 16)) == QS_HOTKEY << 16, "expected QS_HOTKEY << 16 set, got %x\n", queue_status);
13552 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13553 {
13554 if (msg.message == WM_HOTKEY)
13555 {
13556 ok(msg.hwnd == test_window, "unexpected hwnd %p\n", msg.hwnd);
13557 ok(msg.lParam == MAKELPARAM(MOD_WIN, hotkey_letter), "unexpected WM_HOTKEY lparam %lx\n", msg.lParam);
13558 }
13559 DispatchMessage(&msg);
13560 }
13561 ok_sequence(WmHotkeyPress, "window hotkey press", FALSE);
13562
13563 queue_status = GetQueueStatus(QS_HOTKEY);
13564 ok((queue_status & (QS_HOTKEY << 16)) == 0, "expected QS_HOTKEY << 16 cleared, got %x\n", queue_status);
13565
13566 key_state = GetAsyncKeyState(hotkey_letter);
13567 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13568
13569 keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13570 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13571 DispatchMessage(&msg);
13572 ok_sequence(WmHotkeyRelease, "window hotkey release", TRUE);
13573
13574 keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
13575 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13576 DispatchMessage(&msg);
13577 ok_sequence(WmHotkeyReleaseLWIN, "window hotkey release LWIN", FALSE);
13578
13579 /* normal posted WM_HOTKEY messages set QS_HOTKEY */
13580 PostMessage(test_window, WM_HOTKEY, 0, 0);
13581 queue_status = GetQueueStatus(QS_HOTKEY);
13582 ok((queue_status & (QS_HOTKEY << 16)) == QS_HOTKEY << 16, "expected QS_HOTKEY << 16 set, got %x\n", queue_status);
13583 queue_status = GetQueueStatus(QS_POSTMESSAGE);
13584 ok((queue_status & (QS_POSTMESSAGE << 16)) == QS_POSTMESSAGE << 16, "expected QS_POSTMESSAGE << 16 set, got %x\n", queue_status);
13585 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13586 DispatchMessage(&msg);
13587 flush_sequence();
13588
13589 /* Send and process all messages at once */
13590 PostMessage(test_window, WM_APP, 0, 0);
13591 keybd_event(VK_LWIN, 0, 0, 0);
13592 keybd_event(hotkey_letter, 0, 0, 0);
13593 keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13594 keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
13595
13596 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13597 {
13598 if (msg.message == WM_HOTKEY)
13599 {
13600 ok(msg.hwnd == test_window, "unexpected hwnd %p\n", msg.hwnd);
13601 ok(msg.lParam == MAKELPARAM(MOD_WIN, hotkey_letter), "unexpected WM_HOTKEY lparam %lx\n", msg.lParam);
13602 }
13603 DispatchMessage(&msg);
13604 }
13605 ok_sequence(WmHotkeyCombined, "window hotkey combined", FALSE);
13606
13607 /* Register same hwnd/id with different key combination */
13608 ret = RegisterHotKey(test_window, 5, 0, hotkey_letter);
13609 ok(ret == TRUE, "expected TRUE, got %i, err=%d\n", ret, GetLastError());
13610
13611 /* Previous key combination does not work */
13612 keybd_event(VK_LWIN, 0, 0, 0);
13613 keybd_event(hotkey_letter, 0, 0, 0);
13614 keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13615 keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
13616
13617 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13618 DispatchMessage(&msg);
13619 ok_sequence(WmHotkeyPrevious, "window hotkey previous", FALSE);
13620
13621 /* New key combination works */
13622 keybd_event(hotkey_letter, 0, 0, 0);
13623 keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13624
13625 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13626 {
13627 if (msg.message == WM_HOTKEY)
13628 {
13629 ok(msg.hwnd == test_window, "unexpected hwnd %p\n", msg.hwnd);
13630 ok(msg.lParam == MAKELPARAM(0, hotkey_letter), "unexpected WM_HOTKEY lparam %lx\n", msg.lParam);
13631 }
13632 DispatchMessage(&msg);
13633 }
13634 ok_sequence(WmHotkeyNew, "window hotkey new", FALSE);
13635
13636 /* Unregister hotkey properly */
13637 ret = UnregisterHotKey(test_window, 5);
13638 ok(ret == TRUE, "expected TRUE, got %i, err=%d\n", ret, GetLastError());
13639
13640 /* Unregister hotkey again */
13641 SetLastError(0xdeadbeef);
13642 ret = UnregisterHotKey(test_window, 5);
13643 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13644 ok(GetLastError() == ERROR_HOTKEY_NOT_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13645 "unexpected error %d\n", GetLastError());
13646
13647 /* Register thread hotkey */
13648 ret = RegisterHotKey(NULL, 5, MOD_WIN, hotkey_letter);
13649 ok(ret == TRUE, "expected TRUE, got %i, err=%d\n", ret, GetLastError());
13650
13651 /* Inject the appropriate key sequence */
13652 keybd_event(VK_LWIN, 0, 0, 0);
13653 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13654 {
13655 ok(msg.hwnd != NULL, "unexpected thread message %x\n", msg.message);
13656 DispatchMessage(&msg);
13657 }
13658 ok_sequence(WmHotkeyPressLWIN, "thread hotkey press LWIN", FALSE);
13659
13660 keybd_event(hotkey_letter, 0, 0, 0);
13661 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13662 {
13663 if (msg.message == WM_HOTKEY)
13664 {
13665 struct recvd_message message;
13666 ok(msg.hwnd == NULL, "unexpected hwnd %p\n", msg.hwnd);
13667 ok(msg.lParam == MAKELPARAM(MOD_WIN, hotkey_letter), "unexpected WM_HOTKEY lparam %lx\n", msg.lParam);
13668 message.message = msg.message;
13669 message.flags = sent|wparam|lparam;
13670 message.wParam = msg.wParam;
13671 message.lParam = msg.lParam;
13672 message.descr = "test_hotkey thread message";
13673 add_message(&message);
13674 }
13675 else
13676 ok(msg.hwnd != NULL, "unexpected thread message %x\n", msg.message);
13677 DispatchMessage(&msg);
13678 }
13679 ok_sequence(WmHotkeyPress, "thread hotkey press", FALSE);
13680
13681 keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13682 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13683 {
13684 ok(msg.hwnd != NULL, "unexpected thread message %x\n", msg.message);
13685 DispatchMessage(&msg);
13686 }
13687 ok_sequence(WmHotkeyRelease, "thread hotkey release", TRUE);
13688
13689 keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
13690 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
13691 {
13692 ok(msg.hwnd != NULL, "unexpected thread message %x\n", msg.message);
13693 DispatchMessage(&msg);
13694 }
13695 ok_sequence(WmHotkeyReleaseLWIN, "thread hotkey release LWIN", FALSE);
13696
13697 /* Unregister thread hotkey */
13698 ret = UnregisterHotKey(NULL, 5);
13699 ok(ret == TRUE, "expected TRUE, got %i, err=%d\n", ret, GetLastError());
13700
13701 if (hKBD_hook) UnhookWindowsHookEx(hKBD_hook);
13702 hKBD_hook = NULL;
13703
13704 end:
13705 UnregisterHotKey(NULL, 5);
13706 UnregisterHotKey(test_window, 5);
13707 DestroyWindow(test_window);
13708 flush_sequence();
13709 }
13710
13711
13712 static const struct message WmSetFocus_1[] = {
13713 { HCBT_SETFOCUS, hook }, /* child */
13714 { HCBT_ACTIVATE, hook }, /* parent */
13715 { WM_QUERYNEWPALETTE, sent|wparam|lparam|parent|optional, 0, 0 },
13716 { WM_WINDOWPOSCHANGING, sent|parent, 0, SWP_NOSIZE|SWP_NOMOVE },
13717 { WM_ACTIVATEAPP, sent|wparam|parent, 1 },
13718 { WM_NCACTIVATE, sent|parent },
13719 { WM_GETTEXT, sent|defwinproc|parent|optional },
13720 { WM_GETTEXT, sent|defwinproc|parent|optional },
13721 { WM_ACTIVATE, sent|wparam|parent, 1 },
13722 { HCBT_SETFOCUS, hook }, /* parent */
13723 { WM_SETFOCUS, sent|defwinproc|parent },
13724 { WM_KILLFOCUS, sent|parent },
13725 { WM_SETFOCUS, sent },
13726 { 0 }
13727 };
13728 static const struct message WmSetFocus_2[] = {
13729 { HCBT_SETFOCUS, hook }, /* parent */
13730 { WM_KILLFOCUS, sent },
13731 { WM_SETFOCUS, sent|parent },
13732 { 0 }
13733 };
13734 static const struct message WmSetFocus_3[] = {
13735 { HCBT_SETFOCUS, hook }, /* child */
13736 { 0 }
13737 };
13738 static const struct message WmSetFocus_4[] = {
13739 { 0 }
13740 };
13741
13742 static void test_SetFocus(void)
13743 {
13744 HWND parent, old_parent, child, old_focus, old_active;
13745 MSG msg;
13746 struct wnd_event wnd_event;
13747 HANDLE hthread;
13748 DWORD ret, tid;
13749
13750 wnd_event.start_event = CreateEvent(NULL, 0, 0, NULL);
13751 ok(wnd_event.start_event != 0, "CreateEvent error %d\n", GetLastError());
13752 hthread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
13753 ok(hthread != 0, "CreateThread error %d\n", GetLastError());
13754 ret = WaitForSingleObject(wnd_event.start_event, INFINITE);
13755 ok(ret == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
13756 CloseHandle(wnd_event.start_event);
13757
13758 parent = CreateWindowEx(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW,
13759 0, 0, 0, 0, 0, 0, 0, NULL);
13760 ok(parent != 0, "failed to create parent window\n");
13761 child = CreateWindowEx(0, "TestWindowClass", NULL, WS_CHILD,
13762 0, 0, 0, 0, parent, 0, 0, NULL);
13763 ok(child != 0, "failed to create child window\n");
13764
13765 trace("parent %p, child %p, thread window %p\n", parent, child, wnd_event.hwnd);
13766
13767 SetFocus(0);
13768 SetActiveWindow(0);
13769
13770 flush_events();
13771 flush_sequence();
13772
13773 ok(GetActiveWindow() == 0, "expected active 0, got %p\n", GetActiveWindow());
13774 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
13775
13776 log_all_parent_messages++;
13777
13778 old_focus = SetFocus(child);
13779 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13780 ok_sequence(WmSetFocus_1, "SetFocus on a child window", TRUE);
13781 ok(old_focus == parent, "expected old focus %p, got %p\n", parent, old_focus);
13782 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13783 ok(GetFocus() == child, "expected focus %p, got %p\n", child, GetFocus());
13784
13785 old_focus = SetFocus(parent);
13786 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13787 ok_sequence(WmSetFocus_2, "SetFocus on a parent window", FALSE);
13788 ok(old_focus == child, "expected old focus %p, got %p\n", child, old_focus);
13789 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13790 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13791
13792 SetLastError(0xdeadbeef);
13793 old_focus = SetFocus((HWND)0xdeadbeef);
13794 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
13795 "expected ERROR_INVALID_WINDOW_HANDLE, got %d\n", GetLastError());
13796 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13797 ok_sequence(WmEmptySeq, "SetFocus on an invalid window", FALSE);
13798 ok(old_focus == 0, "expected old focus 0, got %p\n", old_focus);
13799 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13800 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13801
13802 SetLastError(0xdeadbeef);
13803 old_focus = SetFocus(GetDesktopWindow());
13804 ok(GetLastError() == ERROR_ACCESS_DENIED /* Vista+ */ ||
13805 broken(GetLastError() == 0xdeadbeef), "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
13806 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13807 ok_sequence(WmEmptySeq, "SetFocus on a desktop window", TRUE);
13808 ok(old_focus == 0, "expected old focus 0, got %p\n", old_focus);
13809 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13810 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13811
13812 SetLastError(0xdeadbeef);
13813 old_focus = SetFocus(wnd_event.hwnd);
13814 ok(GetLastError() == ERROR_ACCESS_DENIED /* Vista+ */ ||
13815 broken(GetLastError() == 0xdeadbeef), "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
13816 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13817 ok_sequence(WmEmptySeq, "SetFocus on another thread window", TRUE);
13818 ok(old_focus == 0, "expected old focus 0, got %p\n", old_focus);
13819 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13820 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13821
13822 SetLastError(0xdeadbeef);
13823 old_active = SetActiveWindow((HWND)0xdeadbeef);
13824 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
13825 "expected ERROR_INVALID_WINDOW_HANDLE, got %d\n", GetLastError());
13826 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13827 ok_sequence(WmEmptySeq, "SetActiveWindow on an invalid window", FALSE);
13828 ok(old_active == 0, "expected old focus 0, got %p\n", old_active);
13829 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13830 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13831
13832 SetLastError(0xdeadbeef);
13833 old_active = SetActiveWindow(GetDesktopWindow());
13834 todo_wine
13835 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
13836 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13837 ok_sequence(WmEmptySeq, "SetActiveWindow on a desktop window", TRUE);
13838 ok(old_active == 0, "expected old focus 0, got %p\n", old_focus);
13839 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13840 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13841
13842 SetLastError(0xdeadbeef);
13843 old_active = SetActiveWindow(wnd_event.hwnd);
13844 todo_wine
13845 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
13846 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13847 ok_sequence(WmEmptySeq, "SetActiveWindow on another thread window", TRUE);
13848 ok(old_active == 0, "expected old focus 0, got %p\n", old_active);
13849 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13850 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13851
13852 SetLastError(0xdeadbeef);
13853 ret = AttachThreadInput(GetCurrentThreadId(), tid, TRUE);
13854 ok(ret, "AttachThreadInput error %d\n", GetLastError());
13855
13856 todo_wine {
13857 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13858 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13859 }
13860 flush_events();
13861 flush_sequence();
13862
13863 old_focus = SetFocus(wnd_event.hwnd);
13864 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13865 ok(old_focus == wnd_event.hwnd, "expected old focus %p, got %p\n", wnd_event.hwnd, old_focus);
13866 ok(GetActiveWindow() == wnd_event.hwnd, "expected active %p, got %p\n", wnd_event.hwnd, GetActiveWindow());
13867 ok(GetFocus() == wnd_event.hwnd, "expected focus %p, got %p\n", wnd_event.hwnd, GetFocus());
13868
13869 old_focus = SetFocus(parent);
13870 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13871 ok(old_focus == parent, "expected old focus %p, got %p\n", parent, old_focus);
13872 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13873 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13874
13875 flush_events();
13876 flush_sequence();
13877
13878 old_active = SetActiveWindow(wnd_event.hwnd);
13879 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13880 ok(old_active == parent, "expected old focus %p, got %p\n", parent, old_active);
13881 ok(GetActiveWindow() == wnd_event.hwnd, "expected active %p, got %p\n", wnd_event.hwnd, GetActiveWindow());
13882 ok(GetFocus() == wnd_event.hwnd, "expected focus %p, got %p\n", wnd_event.hwnd, GetFocus());
13883
13884 SetLastError(0xdeadbeef);
13885 ret = AttachThreadInput(GetCurrentThreadId(), tid, FALSE);
13886 ok(ret, "AttachThreadInput error %d\n", GetLastError());
13887
13888 ok(GetActiveWindow() == 0, "expected active 0, got %p\n", GetActiveWindow());
13889 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
13890
13891 old_parent = SetParent(child, GetDesktopWindow());
13892 ok(old_parent == parent, "expected old parent %p, got %p\n", parent, old_parent);
13893
13894 ok(GetActiveWindow() == 0, "expected active 0, got %p\n", GetActiveWindow());
13895 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
13896
13897 old_focus = SetFocus(parent);
13898 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13899 ok(old_focus == parent, "expected old focus %p, got %p\n", parent, old_focus);
13900 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13901 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13902
13903 flush_events();
13904 flush_sequence();
13905
13906 SetLastError(0xdeadbeef);
13907 old_focus = SetFocus(child);
13908 todo_wine
13909 ok(GetLastError() == ERROR_INVALID_PARAMETER /* Vista+ */ ||
13910 broken(GetLastError() == 0) /* XP */ ||
13911 broken(GetLastError() == 0xdeadbeef), "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
13912 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13913 ok_sequence(WmSetFocus_3, "SetFocus on a child window", TRUE);
13914 ok(old_focus == 0, "expected old focus 0, got %p\n", old_focus);
13915 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13916 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13917
13918 SetLastError(0xdeadbeef);
13919 old_active = SetActiveWindow(child);
13920 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
13921 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
13922 ok_sequence(WmEmptySeq, "SetActiveWindow on a child window", FALSE);
13923 ok(old_active == parent, "expected old active %p, got %p\n", parent, old_active);
13924 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
13925 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
13926
13927 log_all_parent_messages--;
13928
13929 DestroyWindow(child);
13930 DestroyWindow(parent);
13931
13932 ret = PostMessage(wnd_event.hwnd, WM_QUIT, 0, 0);
13933 ok(ret, "PostMessage(WM_QUIT) error %d\n", GetLastError());
13934 ret = WaitForSingleObject(hthread, INFINITE);
13935 ok(ret == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
13936 CloseHandle(hthread);
13937 }
13938
13939 static const struct message WmSetLayeredStyle[] = {
13940 { WM_STYLECHANGING, sent },
13941 { WM_STYLECHANGED, sent },
13942 { WM_GETTEXT, sent|defwinproc|optional },
13943 { 0 }
13944 };
13945
13946 static const struct message WmSetLayeredStyle2[] = {
13947 { WM_STYLECHANGING, sent },
13948 { WM_STYLECHANGED, sent },
13949 { WM_WINDOWPOSCHANGING, sent|optional|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
13950 { WM_NCCALCSIZE, sent|optional|wparam|defwinproc, 1 },
13951 { WM_WINDOWPOSCHANGED, sent|optional|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
13952 { WM_MOVE, sent|optional|defwinproc|wparam, 0 },
13953 { WM_SIZE, sent|optional|defwinproc|wparam, SIZE_RESTORED },
13954 { 0 }
13955 };
13956
13957 struct layered_window_info
13958 {
13959 HWND hwnd;
13960 HDC hdc;
13961 SIZE size;
13962 HANDLE event;
13963 BOOL ret;
13964 };
13965
13966 static DWORD CALLBACK update_layered_proc( void *param )
13967 {
13968 struct layered_window_info *info = param;
13969 POINT src = { 0, 0 };
13970
13971 info->ret = pUpdateLayeredWindow( info->hwnd, 0, NULL, &info->size,
13972 info->hdc, &src, 0, NULL, ULW_OPAQUE );
13973 ok( info->ret, "failed\n");
13974 SetEvent( info->event );
13975 return 0;
13976 }
13977
13978 static void test_layered_window(void)
13979 {
13980 HWND hwnd;
13981 HDC hdc;
13982 HBITMAP bmp;
13983 BOOL ret;
13984 SIZE size;
13985 POINT pos, src;
13986 RECT rect, client;
13987 HANDLE thread;
13988 DWORD tid;
13989 struct layered_window_info info;
13990
13991 if (!pUpdateLayeredWindow)
13992 {
13993 win_skip( "UpdateLayeredWindow not supported\n" );
13994 return;
13995 }
13996
13997 hdc = CreateCompatibleDC( 0 );
13998 bmp = CreateCompatibleBitmap( hdc, 300, 300 );
13999 SelectObject( hdc, bmp );
14000
14001 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_CAPTION | WS_THICKFRAME | WS_SYSMENU,
14002 100, 100, 300, 300, 0, 0, 0, NULL);
14003 ok( hwnd != 0, "failed to create window\n" );
14004 ShowWindow( hwnd, SW_SHOWNORMAL );
14005 UpdateWindow( hwnd );
14006 flush_events();
14007 flush_sequence();
14008
14009 GetWindowRect( hwnd, &rect );
14010 GetClientRect( hwnd, &client );
14011 ok( client.right < rect.right - rect.left, "wrong client area\n" );
14012 ok( client.bottom < rect.bottom - rect.top, "wrong client area\n" );
14013
14014 src.x = src.y = 0;
14015 pos.x = pos.y = 300;
14016 size.cx = size.cy = 250;
14017 ret = pUpdateLayeredWindow( hwnd, 0, &pos, &size, hdc, &src, 0, NULL, ULW_OPAQUE );
14018 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
14019 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
14020 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
14021 ok_sequence( WmSetLayeredStyle, "WmSetLayeredStyle", FALSE );
14022
14023 ret = pUpdateLayeredWindow( hwnd, 0, &pos, &size, hdc, &src, 0, NULL, ULW_OPAQUE );
14024 ok( ret, "UpdateLayeredWindow failed err %u\n", GetLastError() );
14025 ok_sequence( WmEmptySeq, "UpdateLayeredWindow", FALSE );
14026 GetWindowRect( hwnd, &rect );
14027 ok( rect.left == 300 && rect.top == 300 && rect.right == 550 && rect.bottom == 550,
14028 "wrong window rect %d,%d,%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
14029 GetClientRect( hwnd, &rect );
14030 ok( rect.right == client.right - 50 && rect.bottom == client.bottom - 50,
14031 "wrong client rect %d,%d,%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
14032
14033 size.cx = 150;
14034 pos.y = 200;
14035 ret = pUpdateLayeredWindow( hwnd, 0, &pos, &size, hdc, &src, 0, NULL, ULW_OPAQUE );
14036 ok( ret, "UpdateLayeredWindow failed err %u\n", GetLastError() );
14037 ok_sequence( WmEmptySeq, "UpdateLayeredWindow", FALSE );
14038 GetWindowRect( hwnd, &rect );
14039 ok( rect.left == 300 && rect.top == 200 && rect.right == 450 && rect.bottom == 450,
14040 "wrong window rect %d,%d,%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
14041 GetClientRect( hwnd, &rect );
14042 ok( rect.right == client.right - 150 && rect.bottom == client.bottom - 50,
14043 "wrong client rect %d,%d,%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
14044
14045 SetWindowLong( hwnd, GWL_STYLE,
14046 GetWindowLong(hwnd, GWL_STYLE) & ~(WS_CAPTION | WS_THICKFRAME | WS_SYSMENU) );
14047 ok_sequence( WmSetLayeredStyle2, "WmSetLayeredStyle2", FALSE );
14048
14049 size.cx = 200;
14050 pos.x = 200;
14051 ret = pUpdateLayeredWindow( hwnd, 0, &pos, &size, hdc, &src, 0, NULL, ULW_OPAQUE );
14052 ok( ret, "UpdateLayeredWindow failed err %u\n", GetLastError() );
14053 ok_sequence( WmEmptySeq, "UpdateLayeredWindow", FALSE );
14054 GetWindowRect( hwnd, &rect );
14055 ok( rect.left == 200 && rect.top == 200 && rect.right == 400 && rect.bottom == 450,
14056 "wrong window rect %d,%d,%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
14057 GetClientRect( hwnd, &rect );
14058 ok( (rect.right == 200 && rect.bottom == 250) ||
14059 broken(rect.right == client.right - 100 && rect.bottom == client.bottom - 50),
14060 "wrong client rect %d,%d,%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
14061
14062 size.cx = 0;
14063 ret = pUpdateLayeredWindow( hwnd, 0, &pos, &size, hdc, &src, 0, NULL, ULW_OPAQUE );
14064 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
14065 ok( GetLastError() == ERROR_INVALID_PARAMETER || broken(ERROR_MR_MID_NOT_FOUND) /* win7 */,
14066 "wrong error %u\n", GetLastError() );
14067 size.cx = 1;
14068 size.cy = -1;
14069 ret = pUpdateLayeredWindow( hwnd, 0, &pos, &size, hdc, &src, 0, NULL, ULW_OPAQUE );
14070 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
14071 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
14072
14073 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
14074 ok_sequence( WmSetLayeredStyle, "WmSetLayeredStyle", FALSE );
14075 GetWindowRect( hwnd, &rect );
14076 ok( rect.left == 200 && rect.top == 200 && rect.right == 400 && rect.bottom == 450,
14077 "wrong window rect %d,%d,%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
14078 GetClientRect( hwnd, &rect );
14079 ok( (rect.right == 200 && rect.bottom == 250) ||
14080 broken(rect.right == client.right - 100 && rect.bottom == client.bottom - 50),
14081 "wrong client rect %d,%d,%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
14082
14083 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
14084 info.hwnd = hwnd;
14085 info.hdc = hdc;
14086 info.size.cx = 250;
14087 info.size.cy = 300;
14088 info.event = CreateEventA( NULL, TRUE, FALSE, NULL );
14089 info.ret = FALSE;
14090 thread = CreateThread( NULL, 0, update_layered_proc, &info, 0, &tid );
14091 ok( WaitForSingleObject( info.event, 1000 ) == 0, "wait failed\n" );
14092 ok( info.ret, "UpdateLayeredWindow failed in other thread\n" );
14093 WaitForSingleObject( thread, 1000 );
14094 CloseHandle( thread );
14095 GetWindowRect( hwnd, &rect );
14096 ok( rect.left == 200 && rect.top == 200 && rect.right == 450 && rect.bottom == 500,
14097 "wrong window rect %d,%d,%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
14098 GetClientRect( hwnd, &rect );
14099 ok( (rect.right == 250 && rect.bottom == 300) ||
14100 broken(rect.right == client.right - 50 && rect.bottom == client.bottom),
14101 "wrong client rect %d,%d,%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
14102
14103 DestroyWindow( hwnd );
14104 DeleteDC( hdc );
14105 DeleteObject( bmp );
14106 }
14107
14108 START_TEST(msg)
14109 {
14110 char **test_argv;
14111 BOOL ret;
14112 BOOL (WINAPI *pIsWinEventHookInstalled)(DWORD)= 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
14113 HMODULE hModuleImm32;
14114 BOOL (WINAPI *pImmDisableIME)(DWORD);
14115
14116 int argc = winetest_get_mainargs( &test_argv );
14117 if (argc >= 3)
14118 {
14119 unsigned int arg;
14120 /* Child process. */
14121 sscanf (test_argv[2], "%d", (unsigned int *) &arg);
14122 do_wait_idle_child( arg );
14123 return;
14124 }
14125
14126 init_procs();
14127
14128 hModuleImm32 = LoadLibrary("imm32.dll");
14129 if (hModuleImm32) {
14130 pImmDisableIME = (void *)GetProcAddress(hModuleImm32, "ImmDisableIME");
14131 if (pImmDisableIME)
14132 pImmDisableIME(0);
14133 }
14134 pImmDisableIME = NULL;
14135 FreeLibrary(hModuleImm32);
14136
14137 if (!RegisterWindowClasses()) assert(0);
14138
14139 if (pSetWinEventHook)
14140 {
14141 hEvent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX,
14142 GetModuleHandleA(0), win_event_proc,
14143 0, GetCurrentThreadId(),
14144 WINEVENT_INCONTEXT);
14145 if (pIsWinEventHookInstalled && hEvent_hook)
14146 {
14147 UINT event;
14148 for (event = EVENT_MIN; event <= EVENT_MAX; event++)
14149 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
14150 }
14151 }
14152 if (!hEvent_hook) win_skip( "no win event hook support\n" );
14153
14154 cbt_hook_thread_id = GetCurrentThreadId();
14155 hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
14156 if (!hCBT_hook) win_skip( "cannot set global hook, will skip hook tests\n" );
14157
14158 test_winevents();
14159
14160 /* Fix message sequences before removing 4 lines below */
14161 #if 1
14162 if (pUnhookWinEvent && hEvent_hook)
14163 {
14164 ret = pUnhookWinEvent(hEvent_hook);
14165 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
14166 pUnhookWinEvent = 0;
14167 }
14168 hEvent_hook = 0;
14169 #endif
14170
14171 test_SetFocus();
14172 test_SetParent();
14173 test_PostMessage();
14174 test_ShowWindow();
14175 test_PeekMessage();
14176 test_PeekMessage2();
14177 test_WaitForInputIdle( test_argv[0] );
14178 test_scrollwindowex();
14179 test_messages();
14180 test_setwindowpos();
14181 test_showwindow();
14182 invisible_parent_tests();
14183 test_mdi_messages();
14184 test_button_messages();
14185 test_static_messages();
14186 test_listbox_messages();
14187 test_combobox_messages();
14188 test_wmime_keydown_message();
14189 test_paint_messages();
14190 test_interthread_messages();
14191 test_message_conversion();
14192 test_accelerators();
14193 test_timers();
14194 test_timers_no_wnd();
14195 if (hCBT_hook) test_set_hook();
14196 test_DestroyWindow();
14197 test_DispatchMessage();
14198 test_SendMessageTimeout();
14199 test_edit_messages();
14200 test_quit_message();
14201 test_SetActiveWindow();
14202
14203 if (!pTrackMouseEvent)
14204 win_skip("TrackMouseEvent is not available\n");
14205 else
14206 test_TrackMouseEvent();
14207
14208 test_SetWindowRgn();
14209 test_sys_menu();
14210 test_dialog_messages();
14211 test_EndDialog();
14212 test_nullCallback();
14213 test_dbcs_wm_char();
14214 test_unicode_wm_char();
14215 test_menu_messages();
14216 test_paintingloop();
14217 test_defwinproc();
14218 test_clipboard_viewers();
14219 test_keyflags();
14220 test_hotkey();
14221 test_layered_window();
14222 /* keep it the last test, under Windows it tends to break the tests
14223 * which rely on active/foreground windows being correct.
14224 */
14225 test_SetForegroundWindow();
14226
14227 UnhookWindowsHookEx(hCBT_hook);
14228 if (pUnhookWinEvent && hEvent_hook)
14229 {
14230 ret = pUnhookWinEvent(hEvent_hook);
14231 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
14232 SetLastError(0xdeadbeef);
14233 ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
14234 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
14235 GetLastError() == 0xdeadbeef, /* Win9x */
14236 "unexpected error %d\n", GetLastError());
14237 }
14238 }