9dca54c4a19f0cf3ca7b9bd2f447a3c2d23800f5
[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 #ifdef __i386__
64 #define ARCH "x86"
65 #elif defined __x86_64__
66 #define ARCH "amd64"
67 #else
68 #define ARCH "none"
69 #endif
70
71 static BOOL (WINAPI *pActivateActCtx)(HANDLE,ULONG_PTR*);
72 static HANDLE (WINAPI *pCreateActCtxW)(PCACTCTXW);
73 static BOOL (WINAPI *pDeactivateActCtx)(DWORD,ULONG_PTR);
74 static BOOL (WINAPI *pGetCurrentActCtx)(HANDLE *);
75 static void (WINAPI *pReleaseActCtx)(HANDLE);
76
77 /* encoded DRAWITEMSTRUCT into an LPARAM */
78 typedef struct
79 {
80 union
81 {
82 struct
83 {
84 UINT type : 4; /* ODT_* flags */
85 UINT ctl_id : 4; /* Control ID */
86 UINT item_id : 4; /* Menu item ID */
87 UINT action : 4; /* ODA_* flags */
88 UINT state : 16; /* ODS_* flags */
89 } item;
90 LPARAM lp;
91 } u;
92 } DRAW_ITEM_STRUCT;
93
94 static BOOL test_DestroyWindow_flag;
95 static HWINEVENTHOOK hEvent_hook;
96 static HHOOK hKBD_hook;
97 static HHOOK hCBT_hook;
98 static DWORD cbt_hook_thread_id;
99
100 static const WCHAR testWindowClassW[] =
101 { 'T','e','s','t','W','i','n','d','o','w','C','l','a','s','s','W',0 };
102
103 /*
104 FIXME: add tests for these
105 Window Edge Styles (Win31/Win95/98 look), in order of precedence:
106 WS_EX_DLGMODALFRAME: double border, WS_CAPTION allowed
107 WS_THICKFRAME: thick border
108 WS_DLGFRAME: double border, WS_CAPTION not allowed (but possibly shown anyway)
109 WS_BORDER (default for overlapped windows): single black border
110 none (default for child (and popup?) windows): no border
111 */
112
113 typedef enum {
114 sent=0x1,
115 posted=0x2,
116 parent=0x4,
117 wparam=0x8,
118 lparam=0x10,
119 defwinproc=0x20,
120 beginpaint=0x40,
121 optional=0x80,
122 hook=0x100,
123 winevent_hook=0x200,
124 kbd_hook=0x400
125 } msg_flags_t;
126
127 struct message {
128 UINT message; /* the WM_* code */
129 msg_flags_t flags; /* message props */
130 WPARAM wParam; /* expected value of wParam */
131 LPARAM lParam; /* expected value of lParam */
132 WPARAM wp_mask; /* mask for wParam checks */
133 LPARAM lp_mask; /* mask for lParam checks */
134 };
135
136 struct recvd_message {
137 UINT message; /* the WM_* code */
138 msg_flags_t flags; /* message props */
139 HWND hwnd; /* window that received the message */
140 WPARAM wParam; /* expected value of wParam */
141 LPARAM lParam; /* expected value of lParam */
142 int line; /* source line where logged */
143 const char *descr; /* description for trace output */
144 char output[512]; /* trace output */
145 };
146
147 /* Empty message sequence */
148 static const struct message WmEmptySeq[] =
149 {
150 { 0 }
151 };
152 /* CreateWindow (for overlapped window, not initially visible) (16/32) */
153 static const struct message WmCreateOverlappedSeq[] = {
154 { HCBT_CREATEWND, hook },
155 { WM_GETMINMAXINFO, sent },
156 { WM_NCCREATE, sent },
157 { WM_NCCALCSIZE, sent|wparam, 0 },
158 { 0x0093, sent|defwinproc|optional },
159 { 0x0094, sent|defwinproc|optional },
160 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
161 { WM_CREATE, sent },
162 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
163 { 0 }
164 };
165 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
166 * for a not visible overlapped window.
167 */
168 static const struct message WmSWP_ShowOverlappedSeq[] = {
169 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
170 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
171 { WM_NCPAINT, sent|wparam|optional, 1 },
172 { WM_GETTEXT, sent|defwinproc|optional },
173 { WM_ERASEBKGND, sent|optional },
174 { HCBT_ACTIVATE, hook },
175 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
176 { WM_NOTIFYFORMAT, sent|optional },
177 { WM_QUERYUISTATE, sent|optional },
178 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
179 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x: SWP_NOSENDCHANGING */
180 { WM_ACTIVATEAPP, sent|wparam, 1 },
181 { WM_NCACTIVATE, sent },
182 { WM_GETTEXT, sent|defwinproc|optional },
183 { WM_ACTIVATE, sent|wparam, 1 },
184 { HCBT_SETFOCUS, hook },
185 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
186 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
187 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
188 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
189 { WM_GETTEXT, sent|optional },
190 { WM_NCPAINT, sent|wparam|optional, 1 },
191 { WM_GETTEXT, sent|defwinproc|optional },
192 { WM_ERASEBKGND, sent|optional },
193 /* Win9x adds SWP_NOZORDER below */
194 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
195 { WM_GETTEXT, sent|optional },
196 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
197 { WM_NCPAINT, sent|wparam|optional, 1 },
198 { WM_ERASEBKGND, sent|optional },
199 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
200 { WM_SYNCPAINT, sent|optional },
201 { WM_GETTITLEBARINFOEX, sent|optional },
202 { WM_PAINT, sent|optional },
203 { WM_NCPAINT, sent|beginpaint|optional },
204 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
205 { WM_ERASEBKGND, sent|beginpaint|optional },
206 { 0 }
207 };
208 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
209 * for a visible overlapped window.
210 */
211 static const struct message WmSWP_HideOverlappedSeq[] = {
212 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
213 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
214 { HCBT_ACTIVATE, hook|optional },
215 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
216 { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
217 { WM_NCACTIVATE, sent|optional },
218 { WM_ACTIVATE, sent|optional },
219 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
220 { 0 }
221 };
222
223 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
224 * for a visible overlapped window.
225 */
226 static const struct message WmSWP_ResizeSeq[] = {
227 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
228 { WM_GETMINMAXINFO, sent|defwinproc },
229 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
230 { WM_NCPAINT, sent|optional },
231 { WM_GETTEXT, sent|defwinproc|optional },
232 { WM_ERASEBKGND, sent|optional },
233 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
234 { WM_SIZE, sent|defwinproc|optional },
235 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
236 { WM_NCPAINT, sent|optional },
237 { WM_GETTEXT, sent|defwinproc|optional },
238 { WM_ERASEBKGND, sent|optional },
239 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
240 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
241 { 0 }
242 };
243
244 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
245 * for a visible popup window.
246 */
247 static const struct message WmSWP_ResizePopupSeq[] = {
248 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
249 { WM_GETMINMAXINFO, sent|defwinproc|optional }, /* Win9x */
250 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
251 { WM_NCPAINT, sent|optional },
252 { WM_GETTEXT, sent|defwinproc|optional },
253 { WM_ERASEBKGND, sent|optional },
254 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
255 { WM_SIZE, sent|defwinproc|wparam|optional, SIZE_RESTORED },
256 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
257 { WM_NCPAINT, sent|optional },
258 { WM_GETTEXT, sent|defwinproc|optional },
259 { WM_ERASEBKGND, sent|optional },
260 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
261 { 0 }
262 };
263
264 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
265 * for a visible overlapped window.
266 */
267 static const struct message WmSWP_MoveSeq[] = {
268 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE },
269 { WM_NCPAINT, sent|optional },
270 { WM_GETTEXT, sent|defwinproc|optional },
271 { WM_ERASEBKGND, sent|optional },
272 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
273 { WM_MOVE, sent|defwinproc|wparam, 0 },
274 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
275 { 0 }
276 };
277 /* Resize with SetWindowPos(SWP_NOZORDER)
278 * for a visible overlapped window
279 * SWP_NOZORDER is stripped by the logging code
280 */
281 static const struct message WmSWP_ResizeNoZOrder[] = {
282 { WM_WINDOWPOSCHANGING, sent|wparam, /*SWP_NOZORDER|*/SWP_NOACTIVATE },
283 { WM_GETMINMAXINFO, sent|defwinproc },
284 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
285 { WM_NCPAINT, sent|optional },
286 { WM_GETTEXT, sent|defwinproc|optional },
287 { WM_ERASEBKGND, sent|optional },
288 { WM_WINDOWPOSCHANGED, sent|wparam|optional, /*SWP_NOZORDER|*/SWP_NOACTIVATE, 0,
289 SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
290 { WM_MOVE, sent|defwinproc|optional },
291 { WM_SIZE, sent|defwinproc|optional },
292 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
293 { WM_NCPAINT, sent|optional }, /* Win9x doesn't send it */
294 { WM_GETTEXT, sent|defwinproc|optional }, /* Win9x doesn't send it */
295 { WM_ERASEBKGND, sent|optional }, /* Win9x doesn't send it */
296 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
297 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
298 { 0 }
299 };
300
301 /* Switch visible mdi children */
302 static const struct message WmSwitchChild[] = {
303 /* Switch MDI child */
304 { WM_MDIACTIVATE, sent },/* in the MDI client */
305 { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 1st MDI child */
306 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
307 { WM_CHILDACTIVATE, sent },/* in the 1st MDI child */
308 /* Deactivate 2nd MDI child */
309 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
310 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
311 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
312 /* Preparing for maximize and maximize the 1st MDI child */
313 { WM_GETMINMAXINFO, sent|defwinproc }, /* in the 1st MDI child */
314 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED }, /* in the 1st MDI child */
315 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
316 { WM_CHILDACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
317 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 1st MDI child */
318 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED }, /* in the 1st MDI child */
319 /* Lock redraw 2nd MDI child */
320 { WM_SETREDRAW, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
321 { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
322 /* Restore 2nd MDI child */
323 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },/* in the 2nd MDI child */
324 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
325 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
326 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 2nd MDI child */
327 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED }, /* in the 2nd MDI child */
328 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
329 /* Redraw 2nd MDI child */
330 { WM_SETREDRAW, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
331 /* Redraw MDI frame */
332 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },/* in MDI frame */
333 { WM_NCCALCSIZE, sent|wparam, 1 },/* in MDI frame */
334 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in MDI frame */
335 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in MDI frame */
336 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
337 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
338 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
339 { HCBT_SETFOCUS, hook },
340 { WM_KILLFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
341 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },/* in the 1st MDI child */
342 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
343 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
344 { WM_SETFOCUS, sent },/* in the MDI client */
345 { HCBT_SETFOCUS, hook },
346 { WM_KILLFOCUS, sent },/* in the MDI client */
347 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
348 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 }, /* in the 1st MDI child */
349 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
350 { WM_SETFOCUS, sent|defwinproc }, /* in the 1st MDI child */
351 { WM_MDIACTIVATE, sent|defwinproc },/* in the 1st MDI child */
352 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* in the 1st MDI child */
353 { 0 }
354 };
355
356 /* Switch visible not maximized mdi children */
357 static const struct message WmSwitchNotMaximizedChild[] = {
358 /* Switch not maximized MDI child */
359 { WM_MDIACTIVATE, sent },/* in the MDI client */
360 { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 2nd MDI child */
361 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
362 { WM_CHILDACTIVATE, sent },/* in the 2nd MDI child */
363 /* Deactivate 1st MDI child */
364 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
365 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
366 /* Activate 2nd MDI child */
367 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE}, /* in the 2nd MDI child */
368 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 2nd MDI child */
369 { HCBT_SETFOCUS, hook }, /* in the 1st MDI child */
370 { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
371 { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
372 { WM_IME_SETCONTEXT, sent|optional }, /* in the MDI client */
373 { WM_SETFOCUS, sent, 0 }, /* in the MDI client */
374 { HCBT_SETFOCUS, hook },
375 { WM_KILLFOCUS, sent }, /* in the MDI client */
376 { WM_IME_SETCONTEXT, sent|optional }, /* in the MDI client */
377 { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
378 { WM_SETFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
379 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
380 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in the 2nd MDI child */
381 { 0 }
382 };
383
384
385 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
386 SWP_NOZORDER|SWP_FRAMECHANGED)
387 * for a visible overlapped window with WS_CLIPCHILDREN style set.
388 */
389 static const struct message WmSWP_FrameChanged_clip[] = {
390 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
391 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
392 { WM_NCPAINT, sent|parent|optional }, /* wparam != 1 */
393 { WM_GETTEXT, sent|parent|defwinproc|optional },
394 { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
395 { WM_NCPAINT, sent }, /* wparam != 1 */
396 { WM_ERASEBKGND, sent },
397 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
398 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
399 { WM_PAINT, sent },
400 { 0 }
401 };
402 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|
403 SWP_NOZORDER|SWP_FRAMECHANGED)
404 * for a visible overlapped window.
405 */
406 static const struct message WmSWP_FrameChangedDeferErase[] = {
407 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
408 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
409 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
410 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
411 { WM_PAINT, sent|parent|optional },
412 { WM_NCPAINT, sent|beginpaint|parent|optional }, /* wparam != 1 */
413 { WM_GETTEXT, sent|beginpaint|parent|defwinproc|optional },
414 { WM_PAINT, sent },
415 { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
416 { WM_ERASEBKGND, sent|beginpaint|optional },
417 { 0 }
418 };
419
420 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
421 SWP_NOZORDER|SWP_FRAMECHANGED)
422 * for a visible overlapped window without WS_CLIPCHILDREN style set.
423 */
424 static const struct message WmSWP_FrameChanged_noclip[] = {
425 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
426 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
427 { WM_NCPAINT, sent|parent|optional }, /* wparam != 1 */
428 { WM_GETTEXT, sent|parent|defwinproc|optional },
429 { WM_ERASEBKGND, sent|parent|optional },
430 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
431 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
432 { WM_PAINT, sent },
433 { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
434 { WM_ERASEBKGND, sent|beginpaint|optional },
435 { 0 }
436 };
437
438 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
439 static const struct message WmShowOverlappedSeq[] = {
440 { WM_SHOWWINDOW, sent|wparam, 1 },
441 { WM_NCPAINT, sent|wparam|optional, 1 },
442 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
443 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
444 { WM_NCPAINT, sent|wparam|optional, 1 },
445 { WM_GETTEXT, sent|defwinproc|optional },
446 { WM_ERASEBKGND, sent|optional },
447 { HCBT_ACTIVATE, hook|optional },
448 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
449 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
450 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
451 { WM_NCPAINT, sent|wparam|optional, 1 },
452 { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
453 { WM_NCACTIVATE, sent|wparam|optional, 1 },
454 { WM_GETTEXT, sent|defwinproc|optional },
455 { WM_ACTIVATE, sent|wparam|optional, 1 },
456 { HCBT_SETFOCUS, hook|optional },
457 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
458 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
459 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
460 { WM_SETFOCUS, sent|wparam|defwinproc|optional, 0 },
461 { WM_GETTEXT, sent|optional },
462 { WM_NCPAINT, sent|wparam|optional, 1 },
463 { WM_GETTEXT, sent|defwinproc|optional },
464 { WM_ERASEBKGND, sent|optional },
465 /* Win9x adds SWP_NOZORDER below */
466 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
467 { WM_NCCALCSIZE, sent|optional },
468 { WM_GETTEXT, sent|optional },
469 { WM_NCPAINT, sent|optional },
470 { WM_ERASEBKGND, sent|optional },
471 { WM_SYNCPAINT, sent|optional },
472 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
473 * messages. Does that mean that CreateWindow doesn't set initial
474 * window dimensions for overlapped windows?
475 */
476 { WM_SIZE, sent },
477 { WM_MOVE, sent },
478 #endif
479 { WM_PAINT, sent|optional },
480 { WM_NCPAINT, sent|beginpaint|optional },
481 { 0 }
482 };
483 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible overlapped window */
484 static const struct message WmShowMaxOverlappedSeq[] = {
485 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
486 { WM_GETMINMAXINFO, sent },
487 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
488 { WM_GETMINMAXINFO, sent|defwinproc },
489 { WM_NCCALCSIZE, sent|wparam, TRUE },
490 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
491 { HCBT_ACTIVATE, hook|optional },
492 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
493 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
494 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
495 { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
496 { WM_NCACTIVATE, sent|wparam|optional, 1 },
497 { WM_GETTEXT, sent|defwinproc|optional },
498 { WM_ACTIVATE, sent|wparam|optional, 1 },
499 { HCBT_SETFOCUS, hook|optional },
500 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
501 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
502 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
503 { WM_SETFOCUS, sent|wparam|defwinproc|optional, 0 },
504 { WM_GETTEXT, sent|optional },
505 { WM_NCPAINT, sent|wparam|optional, 1 },
506 { WM_GETTEXT, sent|defwinproc|optional },
507 { WM_ERASEBKGND, sent|optional },
508 /* Win9x adds SWP_NOZORDER below */
509 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
510 { WM_MOVE, sent|defwinproc },
511 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
512 { WM_GETTEXT, sent|optional },
513 { WM_NCCALCSIZE, sent|optional },
514 { WM_NCPAINT, sent|optional },
515 { WM_ERASEBKGND, sent|optional },
516 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
517 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
518 { WM_SYNCPAINT, sent|optional },
519 { WM_GETTITLEBARINFOEX, sent|optional },
520 { WM_PAINT, sent|optional },
521 { WM_NCPAINT, sent|beginpaint|optional },
522 { WM_ERASEBKGND, sent|beginpaint|optional },
523 { 0 }
524 };
525 /* ShowWindow(SW_RESTORE) for a not visible maximized overlapped window */
526 static const struct message WmShowRestoreMaxOverlappedSeq[] = {
527 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
528 { WM_GETTEXT, sent|optional },
529 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
530 { WM_GETMINMAXINFO, sent|defwinproc },
531 { WM_NCCALCSIZE, sent|wparam, TRUE },
532 { WM_NCPAINT, sent|optional },
533 { WM_GETTEXT, sent|defwinproc|optional },
534 { WM_ERASEBKGND, sent|optional },
535 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
536 { WM_MOVE, sent|defwinproc|optional },
537 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
538 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
539 { WM_NCPAINT, sent|optional },
540 { WM_ERASEBKGND, sent|optional },
541 { WM_PAINT, sent|optional },
542 { WM_GETTITLEBARINFOEX, sent|optional },
543 { WM_NCPAINT, sent|beginpaint|optional },
544 { WM_ERASEBKGND, sent|beginpaint|optional },
545 { 0 }
546 };
547 /* ShowWindow(SW_RESTORE) for a not visible minimized overlapped window */
548 static const struct message WmShowRestoreMinOverlappedSeq[] = {
549 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
550 { WM_QUERYOPEN, sent|optional },
551 { WM_GETTEXT, sent|optional },
552 { WM_NCACTIVATE, sent|wparam|optional, 1 },
553 { WM_WINDOWPOSCHANGING, sent|optional }, /* SWP_NOSIZE|SWP_NOMOVE */
554 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
555 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
556 { WM_MOVE, sent|optional },
557 { WM_SIZE, sent|wparam|optional, SIZE_RESTORED },
558 { WM_GETTEXT, sent|optional },
559 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED|SWP_NOCOPYBITS },
560 { WM_GETMINMAXINFO, sent|defwinproc|optional },
561 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
562 { HCBT_ACTIVATE, hook|optional },
563 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
564 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
565 { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
566 { WM_NCACTIVATE, sent|wparam|optional, 1 },
567 { WM_GETTEXT, sent|defwinproc|optional },
568 { WM_ACTIVATE, sent|wparam|optional, 1 },
569 { HCBT_SETFOCUS, hook|optional },
570 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
571 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
572 { WM_SETFOCUS, sent|wparam|defwinproc|optional, 0 },
573 { WM_GETTEXT, sent|optional },
574 { WM_NCPAINT, sent|wparam|optional, 1 },
575 { WM_GETTEXT, sent|defwinproc|optional },
576 { WM_ERASEBKGND, sent },
577 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_STATECHANGED|SWP_FRAMECHANGED|SWP_NOCOPYBITS },
578 { WM_MOVE, sent|defwinproc },
579 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
580 { HCBT_SETFOCUS, hook|optional },
581 { WM_SETFOCUS, sent|wparam|optional, 0 },
582 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
583 { WM_NCPAINT, sent|wparam|optional, 1 },
584 { WM_ERASEBKGND, sent|optional },
585 { HCBT_SETFOCUS, hook|optional },
586 { WM_SETFOCUS, sent|wparam|optional, 0 },
587 { WM_ACTIVATE, sent|wparam, 1 },
588 { WM_GETTEXT, sent|optional },
589 { WM_PAINT, sent|optional },
590 { WM_GETTITLEBARINFOEX, sent|optional },
591 { WM_NCPAINT, sent|beginpaint|optional },
592 { WM_ERASEBKGND, sent|beginpaint|optional },
593 { 0 }
594 };
595 /* ShowWindow(SW_SHOWMINIMIZED) for a not visible overlapped window */
596 static const struct message WmShowMinOverlappedSeq[] = {
597 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
598 { HCBT_SETFOCUS, hook|optional },
599 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
600 { WM_KILLFOCUS, sent|optional },
601 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
602 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
603 { WM_GETTEXT, sent|optional },
604 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCOPYBITS|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
605 { WM_GETMINMAXINFO, sent|defwinproc },
606 { WM_NCCALCSIZE, sent|wparam, TRUE },
607 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
608 { WM_NCPAINT, sent|optional },
609 { WM_GETTEXT, sent|defwinproc|optional },
610 { WM_WINDOWPOSCHANGED, sent },
611 { WM_MOVE, sent|defwinproc },
612 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
613 { WM_NCCALCSIZE, sent|optional },
614 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
615 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
616 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
617 { WM_NCACTIVATE, sent|wparam|optional, 0 },
618 { WM_GETTEXT, sent|defwinproc|optional },
619 { WM_ACTIVATE, sent|optional },
620 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
621
622 /* Vista sometimes restores the window right away... */
623 { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
624 { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
625 { HCBT_MINMAX, hook|optional|lparam, 0, SW_RESTORE },
626 { WM_QUERYOPEN, sent|optional },
627 { WM_WINDOWPOSCHANGING, sent|optional|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
628 { WM_GETMINMAXINFO, sent|optional|defwinproc },
629 { WM_NCCALCSIZE, sent|optional|wparam, TRUE },
630 { HCBT_ACTIVATE, hook|optional },
631 { WM_ACTIVATEAPP, sent|optional|wparam, 1 },
632 { WM_NCACTIVATE, sent|optional },
633 { WM_GETTEXT, sent|optional },
634 { WM_ACTIVATE, sent|optional|wparam, 1 },
635 { HCBT_SETFOCUS, hook|optional },
636 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
637 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
638 { WM_SETFOCUS, sent|optional },
639 { WM_NCPAINT, sent|optional },
640 { WM_GETTEXT, sent|defwinproc|optional },
641 { WM_ERASEBKGND, sent|optional },
642 { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
643 { WM_MOVE, sent|defwinproc|optional },
644 { WM_SIZE, sent|defwinproc|optional|wparam, SIZE_RESTORED },
645 { WM_ACTIVATE, sent|optional|wparam, 1 },
646 { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
647 { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
648
649 { WM_PAINT, sent|optional },
650 { WM_NCPAINT, sent|beginpaint|optional },
651 { WM_ERASEBKGND, sent|beginpaint|optional },
652 { 0 }
653 };
654 /* ShowWindow(SW_HIDE) for a visible overlapped window */
655 static const struct message WmHideOverlappedSeq[] = {
656 { WM_SHOWWINDOW, sent|wparam, 0 },
657 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
658 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
659 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
660 { WM_SIZE, sent|optional }, /* XP doesn't send it */
661 { WM_MOVE, sent|optional }, /* XP doesn't send it */
662 { WM_NCACTIVATE, sent|wparam|optional, 0 },
663 { WM_ACTIVATE, sent|wparam|optional, 0 },
664 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
665 { HCBT_SETFOCUS, hook|optional },
666 { WM_KILLFOCUS, sent|wparam|optional, 0 },
667 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
668 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
669 { 0 }
670 };
671 /* DestroyWindow for a visible overlapped window */
672 static const struct message WmDestroyOverlappedSeq[] = {
673 { HCBT_DESTROYWND, hook },
674 { 0x0090, sent|optional },
675 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
676 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
677 { 0x0090, sent|optional },
678 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
679 { WM_NCACTIVATE, sent|optional|wparam, 0 },
680 { WM_ACTIVATE, sent|optional },
681 { WM_ACTIVATEAPP, sent|optional|wparam, 0 },
682 { WM_KILLFOCUS, sent|optional|wparam, 0 },
683 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
684 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
685 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
686 { WM_DESTROY, sent },
687 { WM_NCDESTROY, sent },
688 { 0 }
689 };
690 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
691 static const struct message WmCreateMaxPopupSeq[] = {
692 { HCBT_CREATEWND, hook },
693 { WM_NCCREATE, sent },
694 { WM_NCCALCSIZE, sent|wparam, 0 },
695 { WM_CREATE, sent },
696 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
697 { WM_SIZE, sent|wparam, SIZE_RESTORED },
698 { WM_MOVE, sent },
699 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
700 { WM_GETMINMAXINFO, sent },
701 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
702 { WM_NCCALCSIZE, sent|wparam, TRUE },
703 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
704 { WM_MOVE, sent|defwinproc },
705 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
706 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
707 { WM_SHOWWINDOW, sent|wparam, 1 },
708 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
709 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
710 { HCBT_ACTIVATE, hook },
711 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
712 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
713 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
714 { WM_NCPAINT, sent|wparam|optional, 1 },
715 { WM_ERASEBKGND, sent|optional },
716 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_NOMOVE|SWP_NOSIZE },
717 { WM_ACTIVATEAPP, sent|wparam, 1 },
718 { WM_NCACTIVATE, sent },
719 { WM_ACTIVATE, sent|wparam, 1 },
720 { HCBT_SETFOCUS, hook },
721 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
722 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
723 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
724 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
725 { WM_GETTEXT, sent|optional },
726 { WM_SYNCPAINT, sent|wparam|optional, 4 },
727 { WM_NCPAINT, sent|wparam|optional, 1 },
728 { WM_ERASEBKGND, sent|optional },
729 { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
730 { WM_ERASEBKGND, sent|defwinproc|optional },
731 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
732 { 0 }
733 };
734 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
735 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
736 { HCBT_CREATEWND, hook },
737 { WM_NCCREATE, sent },
738 { WM_NCCALCSIZE, sent|wparam, 0 },
739 { WM_CREATE, sent },
740 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
741 { WM_SIZE, sent|wparam, SIZE_RESTORED },
742 { WM_MOVE, sent },
743 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
744 { WM_GETMINMAXINFO, sent },
745 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
746 { WM_NCCALCSIZE, sent|wparam, TRUE },
747 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
748 { WM_MOVE, sent|defwinproc },
749 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
750 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
751 { 0 }
752 };
753 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
754 static const struct message WmShowMaxPopupResizedSeq[] = {
755 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
756 { WM_GETMINMAXINFO, sent },
757 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
758 { WM_NCCALCSIZE, sent|wparam, TRUE },
759 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
760 { HCBT_ACTIVATE, hook },
761 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
762 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
763 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
764 { WM_NCPAINT, sent|wparam|optional, 1 },
765 { WM_ERASEBKGND, sent|optional },
766 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
767 { WM_ACTIVATEAPP, sent|wparam, 1 },
768 { WM_NCACTIVATE, sent },
769 { WM_ACTIVATE, sent|wparam, 1 },
770 { HCBT_SETFOCUS, hook },
771 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
772 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
773 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
774 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
775 { WM_GETTEXT, sent|optional },
776 { WM_NCPAINT, sent|wparam|optional, 1 },
777 { WM_ERASEBKGND, sent|optional },
778 { WM_WINDOWPOSCHANGED, sent },
779 /* WinNT4.0 sends WM_MOVE */
780 { WM_MOVE, sent|defwinproc|optional },
781 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
782 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
783 { 0 }
784 };
785 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
786 static const struct message WmShowMaxPopupSeq[] = {
787 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
788 { WM_GETMINMAXINFO, sent },
789 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
790 { WM_NCCALCSIZE, sent|wparam, TRUE },
791 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
792 { HCBT_ACTIVATE, hook },
793 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
794 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
795 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
796 { WM_ACTIVATEAPP, sent|wparam, 1 },
797 { WM_NCACTIVATE, sent },
798 { WM_ACTIVATE, sent|wparam, 1 },
799 { HCBT_SETFOCUS, hook },
800 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
801 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
802 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
803 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
804 { WM_GETTEXT, sent|optional },
805 { WM_SYNCPAINT, sent|wparam|optional, 4 },
806 { WM_NCPAINT, sent|wparam|optional, 1 },
807 { WM_ERASEBKGND, sent|optional },
808 { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
809 { WM_ERASEBKGND, sent|defwinproc|optional },
810 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
811 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
812 { 0 }
813 };
814 /* CreateWindow(WS_VISIBLE) for popup window */
815 static const struct message WmCreatePopupSeq[] = {
816 { HCBT_CREATEWND, hook },
817 { WM_NCCREATE, sent },
818 { WM_NCCALCSIZE, sent|wparam, 0 },
819 { WM_CREATE, sent },
820 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
821 { WM_SIZE, sent|wparam, SIZE_RESTORED },
822 { WM_MOVE, sent },
823 { WM_SHOWWINDOW, sent|wparam, 1 },
824 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
825 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
826 { HCBT_ACTIVATE, hook },
827 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
828 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
829 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
830 { WM_NCPAINT, sent|wparam|optional, 1 },
831 { WM_ERASEBKGND, sent|optional },
832 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
833 { WM_ACTIVATEAPP, sent|wparam, 1 },
834 { WM_NCACTIVATE, sent },
835 { WM_ACTIVATE, sent|wparam, 1 },
836 { HCBT_SETFOCUS, hook },
837 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
838 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
839 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
840 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
841 { WM_GETTEXT, sent|optional },
842 { WM_SYNCPAINT, sent|wparam|optional, 4 },
843 { WM_NCPAINT, sent|wparam|optional, 1 },
844 { WM_ERASEBKGND, sent|optional },
845 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
846 { 0 }
847 };
848 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
849 static const struct message WmShowVisMaxPopupSeq[] = {
850 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
851 { WM_GETMINMAXINFO, sent },
852 { WM_GETTEXT, sent|optional },
853 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
854 { WM_GETTEXT, sent|optional },
855 { WM_NCCALCSIZE, sent|wparam, TRUE },
856 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
857 { WM_NCPAINT, sent|wparam|optional, 1 },
858 { WM_ERASEBKGND, sent|optional },
859 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
860 { WM_MOVE, sent|defwinproc },
861 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
862 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
863 { 0 }
864 };
865 /* CreateWindow (for a child popup window, not initially visible) */
866 static const struct message WmCreateChildPopupSeq[] = {
867 { HCBT_CREATEWND, hook },
868 { WM_NCCREATE, sent },
869 { WM_NCCALCSIZE, sent|wparam, 0 },
870 { WM_CREATE, sent },
871 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
872 { WM_SIZE, sent|wparam, SIZE_RESTORED },
873 { WM_MOVE, sent },
874 { 0 }
875 };
876 /* CreateWindow (for a popup window, not initially visible,
877 * which sets WS_VISIBLE in WM_CREATE handler)
878 */
879 static const struct message WmCreateInvisiblePopupSeq[] = {
880 { HCBT_CREATEWND, hook },
881 { WM_NCCREATE, sent },
882 { WM_NCCALCSIZE, sent|wparam, 0 },
883 { WM_CREATE, sent },
884 { WM_STYLECHANGING, sent },
885 { WM_STYLECHANGED, sent },
886 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
887 { WM_SIZE, sent|wparam, SIZE_RESTORED },
888 { WM_MOVE, sent },
889 { 0 }
890 };
891 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
892 * for a popup window with WS_VISIBLE style set
893 */
894 static const struct message WmShowVisiblePopupSeq_2[] = {
895 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
896 { 0 }
897 };
898 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
899 * for a popup window with WS_VISIBLE style set
900 */
901 static const struct message WmShowVisiblePopupSeq_3[] = {
902 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
903 { HCBT_ACTIVATE, hook },
904 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
905 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
906 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
907 { WM_NCACTIVATE, sent },
908 { WM_ACTIVATE, sent|wparam, 1 },
909 { HCBT_SETFOCUS, hook },
910 { WM_KILLFOCUS, sent|parent },
911 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
912 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
913 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
914 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
915 { WM_SETFOCUS, sent|defwinproc },
916 { WM_GETTEXT, sent|optional },
917 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_SHOWWINDOW },
918 { 0 }
919 };
920 /* CreateWindow (for child window, not initially visible) */
921 static const struct message WmCreateChildSeq[] = {
922 { HCBT_CREATEWND, hook },
923 { WM_NCCREATE, sent },
924 /* child is inserted into parent's child list after WM_NCCREATE returns */
925 { WM_NCCALCSIZE, sent|wparam, 0 },
926 { WM_CREATE, sent },
927 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
928 { WM_SIZE, sent|wparam, SIZE_RESTORED },
929 { WM_MOVE, sent },
930 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
931 { 0 }
932 };
933 /* CreateWindow (for maximized child window, not initially visible) */
934 static const struct message WmCreateMaximizedChildSeq[] = {
935 { HCBT_CREATEWND, hook },
936 { WM_NCCREATE, sent },
937 { WM_NCCALCSIZE, sent|wparam, 0 },
938 { WM_CREATE, sent },
939 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
940 { WM_SIZE, sent|wparam, SIZE_RESTORED },
941 { WM_MOVE, sent },
942 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
943 { WM_GETMINMAXINFO, sent },
944 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
945 { WM_NCCALCSIZE, sent|wparam, 1 },
946 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
947 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
948 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
949 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
950 { 0 }
951 };
952 /* CreateWindow (for a child window, initially visible) */
953 static const struct message WmCreateVisibleChildSeq[] = {
954 { HCBT_CREATEWND, hook },
955 { WM_NCCREATE, sent },
956 /* child is inserted into parent's child list after WM_NCCREATE returns */
957 { WM_NCCALCSIZE, sent|wparam, 0 },
958 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
959 { WM_CREATE, sent },
960 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
961 { WM_SIZE, sent|wparam, SIZE_RESTORED },
962 { WM_MOVE, sent },
963 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
964 { WM_SHOWWINDOW, sent|wparam, 1 },
965 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
966 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
967 { WM_ERASEBKGND, sent|parent|optional },
968 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
969 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
970 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
971 { 0 }
972 };
973 /* ShowWindow(SW_SHOW) for a not visible child window */
974 static const struct message WmShowChildSeq[] = {
975 { WM_SHOWWINDOW, sent|wparam, 1 },
976 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
977 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
978 { WM_ERASEBKGND, sent|parent|optional },
979 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
980 { 0 }
981 };
982 /* ShowWindow(SW_HIDE) for a visible child window */
983 static const struct message WmHideChildSeq[] = {
984 { WM_SHOWWINDOW, sent|wparam, 0 },
985 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
986 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
987 { WM_ERASEBKGND, sent|parent|optional },
988 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
989 { 0 }
990 };
991 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
992 static const struct message WmHideChildSeq2[] = {
993 { WM_SHOWWINDOW, sent|wparam, 0 },
994 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
995 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
996 { WM_ERASEBKGND, sent|parent|optional },
997 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
998 { 0 }
999 };
1000 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
1001 * for a not visible child window
1002 */
1003 static const struct message WmShowChildSeq_2[] = {
1004 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1005 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1006 { WM_CHILDACTIVATE, sent },
1007 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1008 { 0 }
1009 };
1010 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
1011 * for a not visible child window
1012 */
1013 static const struct message WmShowChildSeq_3[] = {
1014 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1015 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1016 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1017 { 0 }
1018 };
1019 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
1020 * for a visible child window with a caption
1021 */
1022 static const struct message WmShowChildSeq_4[] = {
1023 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1024 { WM_CHILDACTIVATE, sent },
1025 { 0 }
1026 };
1027 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
1028 static const struct message WmShowChildInvisibleParentSeq_1[] = {
1029 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
1030 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
1031 { WM_NCCALCSIZE, sent|wparam, 1 },
1032 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1033 { WM_CHILDACTIVATE, sent|optional },
1034 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
1035 { WM_MOVE, sent|defwinproc },
1036 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1037 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1038 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1039 /* FIXME: Wine creates an icon/title window while Windows doesn't */
1040 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1041 { WM_GETTEXT, sent|optional },
1042 { 0 }
1043 };
1044 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
1045 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
1046 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
1047 { 0 }
1048 };
1049 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1050 static const struct message WmShowChildInvisibleParentSeq_2[] = {
1051 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1052 { WM_GETMINMAXINFO, sent },
1053 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
1054 { WM_NCCALCSIZE, sent|wparam, 1 },
1055 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1056 { WM_CHILDACTIVATE, sent },
1057 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
1058 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
1059 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1060 { 0 }
1061 };
1062 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1063 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
1064 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1065 { 0 }
1066 };
1067 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1068 static const struct message WmShowChildInvisibleParentSeq_3[] = {
1069 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1070 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
1071 { WM_NCCALCSIZE, sent|wparam, 1 },
1072 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1073 { WM_CHILDACTIVATE, sent },
1074 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1075 { WM_MOVE, sent|defwinproc },
1076 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1077 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1078 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1079 /* FIXME: Wine creates an icon/title window while Windows doesn't */
1080 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1081 { WM_GETTEXT, sent|optional },
1082 { 0 }
1083 };
1084 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1085 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
1086 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1087 { 0 }
1088 };
1089 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1090 static const struct message WmShowChildInvisibleParentSeq_4[] = {
1091 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1092 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
1093 { WM_NCCALCSIZE, sent|wparam, 1 },
1094 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1095 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1096 { WM_MOVE, sent|defwinproc },
1097 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1098 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1099 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1100 /* FIXME: Wine creates an icon/title window while Windows doesn't */
1101 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1102 { WM_GETTEXT, sent|optional },
1103 { 0 }
1104 };
1105 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1106 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
1107 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1108 { 0 }
1109 };
1110 /* ShowWindow(SW_SHOW) for child with invisible parent */
1111 static const struct message WmShowChildInvisibleParentSeq_5[] = {
1112 { WM_SHOWWINDOW, sent|wparam, 1 },
1113 { 0 }
1114 };
1115 /* ShowWindow(SW_HIDE) for child with invisible parent */
1116 static const struct message WmHideChildInvisibleParentSeq[] = {
1117 { WM_SHOWWINDOW, sent|wparam, 0 },
1118 { 0 }
1119 };
1120 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
1121 static const struct message WmShowChildInvisibleParentSeq_6[] = {
1122 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1123 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1124 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1125 { 0 }
1126 };
1127 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
1128 static const struct message WmHideChildInvisibleParentSeq_2[] = {
1129 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1130 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1131 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1132 { 0 }
1133 };
1134 /* DestroyWindow for a visible child window */
1135 static const struct message WmDestroyChildSeq[] = {
1136 { HCBT_DESTROYWND, hook },
1137 { 0x0090, sent|optional },
1138 { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1139 { WM_SHOWWINDOW, sent|wparam, 0 },
1140 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1141 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1142 { WM_ERASEBKGND, sent|parent|optional },
1143 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1144 { HCBT_SETFOCUS, hook }, /* set focus to a parent */
1145 { WM_KILLFOCUS, sent },
1146 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1147 { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
1148 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1149 { WM_SETFOCUS, sent|parent },
1150 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1151 { WM_DESTROY, sent },
1152 { WM_DESTROY, sent|optional }, /* some other (IME?) window */
1153 { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
1154 { WM_NCDESTROY, sent },
1155 { 0 }
1156 };
1157 /* visible child window destroyed by thread exit */
1158 static const struct message WmExitThreadSeq[] = {
1159 { WM_NCDESTROY, sent }, /* actually in grandchild */
1160 { WM_PAINT, sent|parent },
1161 { WM_ERASEBKGND, sent|parent|beginpaint },
1162 { 0 }
1163 };
1164 /* DestroyWindow for a visible child window with invisible parent */
1165 static const struct message WmDestroyInvisibleChildSeq[] = {
1166 { HCBT_DESTROYWND, hook },
1167 { 0x0090, sent|optional },
1168 { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1169 { WM_SHOWWINDOW, sent|wparam, 0 },
1170 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1171 { WM_DESTROY, sent },
1172 { WM_NCDESTROY, sent },
1173 { 0 }
1174 };
1175 /* Resizing child window with MoveWindow (32) */
1176 static const struct message WmResizingChildWithMoveWindowSeq[] = {
1177 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1178 { WM_NCCALCSIZE, sent|wparam, 1 },
1179 { WM_ERASEBKGND, sent|parent|optional },
1180 { WM_ERASEBKGND, sent|optional },
1181 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
1182 { WM_MOVE, sent|defwinproc },
1183 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1184 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1185 { 0 }
1186 };
1187 /* Creation of a custom dialog (32) */
1188 static const struct message WmCreateCustomDialogSeq[] = {
1189 { HCBT_CREATEWND, hook },
1190 { WM_GETMINMAXINFO, sent },
1191 { WM_NCCREATE, sent },
1192 { WM_NCCALCSIZE, sent|wparam, 0 },
1193 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1194 { WM_CREATE, sent },
1195 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1196 { WM_NOTIFYFORMAT, sent|optional },
1197 { WM_QUERYUISTATE, sent|optional },
1198 { WM_WINDOWPOSCHANGING, sent|optional },
1199 { WM_GETMINMAXINFO, sent|optional },
1200 { WM_NCCALCSIZE, sent|optional },
1201 { WM_WINDOWPOSCHANGED, sent|optional },
1202 { WM_SHOWWINDOW, sent|wparam, 1 },
1203 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1204 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1205 { HCBT_ACTIVATE, hook },
1206 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1207
1208
1209 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1210
1211 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1212
1213 { WM_NCACTIVATE, sent },
1214 { WM_GETTEXT, sent|optional|defwinproc },
1215 { WM_GETTEXT, sent|optional|defwinproc },
1216 { WM_GETTEXT, sent|optional|defwinproc },
1217 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1218 { WM_ACTIVATE, sent|wparam, 1 },
1219 { WM_GETTEXT, sent|optional },
1220 { WM_KILLFOCUS, sent|parent },
1221 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1222 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1223 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1224 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1225 { WM_SETFOCUS, sent },
1226 { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1227 { WM_NCPAINT, sent|wparam, 1 },
1228 { WM_GETTEXT, sent|optional|defwinproc },
1229 { WM_GETTEXT, sent|optional|defwinproc },
1230 { WM_ERASEBKGND, sent },
1231 { WM_CTLCOLORDLG, sent|optional|defwinproc },
1232 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1233 { WM_GETTEXT, sent|optional },
1234 { WM_GETTEXT, sent|optional },
1235 { WM_NCCALCSIZE, sent|optional },
1236 { WM_NCPAINT, sent|optional },
1237 { WM_GETTEXT, sent|optional|defwinproc },
1238 { WM_GETTEXT, sent|optional|defwinproc },
1239 { WM_ERASEBKGND, sent|optional },
1240 { WM_CTLCOLORDLG, sent|optional|defwinproc },
1241 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1242 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1243 { WM_MOVE, sent },
1244 { 0 }
1245 };
1246 /* Calling EndDialog for a custom dialog (32) */
1247 static const struct message WmEndCustomDialogSeq[] = {
1248 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1249 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1250 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1251 { WM_GETTEXT, sent|optional },
1252 { HCBT_ACTIVATE, hook },
1253 { WM_NCACTIVATE, sent|wparam, 0 },
1254 { WM_GETTEXT, sent|optional|defwinproc },
1255 { WM_GETTEXT, sent|optional|defwinproc },
1256 { WM_ACTIVATE, sent|wparam, 0 },
1257 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1258 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1259 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1260 { WM_GETTEXT, sent|optional|defwinproc },
1261 { WM_GETTEXT, sent|optional|defwinproc },
1262 { HCBT_SETFOCUS, hook },
1263 { WM_KILLFOCUS, sent },
1264 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1265 { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1266 { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1267 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1268 { WM_SETFOCUS, sent|parent|defwinproc },
1269 { 0 }
1270 };
1271 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1272 static const struct message WmShowCustomDialogSeq[] = {
1273 { WM_SHOWWINDOW, sent|wparam, 1 },
1274 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1275 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1276 { HCBT_ACTIVATE, hook },
1277 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1278
1279 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1280
1281 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1282 { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1283 { WM_NCACTIVATE, sent },
1284 { WM_ACTIVATE, sent|wparam, 1 },
1285 { WM_GETTEXT, sent|optional },
1286
1287 { WM_KILLFOCUS, sent|parent },
1288 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1289 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1290 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1291 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1292 { WM_SETFOCUS, sent },
1293 { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1294 { WM_NCPAINT, sent|wparam, 1 },
1295 { WM_ERASEBKGND, sent },
1296 { WM_CTLCOLORDLG, sent|defwinproc },
1297 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1298 { 0 }
1299 };
1300 /* Creation and destruction of a modal dialog (32) */
1301 static const struct message WmModalDialogSeq[] = {
1302 { WM_CANCELMODE, sent|parent },
1303 { HCBT_SETFOCUS, hook },
1304 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1305 { WM_KILLFOCUS, sent|parent },
1306 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1307 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1308 { WM_ENABLE, sent|parent|wparam, 0 },
1309 { HCBT_CREATEWND, hook },
1310 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1311 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1312 { WM_SETFONT, sent },
1313 { WM_INITDIALOG, sent },
1314 { WM_CHANGEUISTATE, sent|optional },
1315 { WM_UPDATEUISTATE, sent|optional },
1316 { WM_SHOWWINDOW, sent },
1317 { HCBT_ACTIVATE, hook },
1318 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1319 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1320 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1321 { WM_NCACTIVATE, sent },
1322 { WM_GETTEXT, sent|optional },
1323 { WM_ACTIVATE, sent|wparam, 1 },
1324 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1325 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1326 { WM_NCPAINT, sent|optional },
1327 { WM_GETTEXT, sent|optional },
1328 { WM_ERASEBKGND, sent|optional },
1329 { WM_CTLCOLORDLG, sent|optional },
1330 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1331 { WM_GETTEXT, sent|optional },
1332 { WM_NCCALCSIZE, sent|optional },
1333 { WM_NCPAINT, sent|optional },
1334 { WM_GETTEXT, sent|optional },
1335 { WM_ERASEBKGND, sent|optional },
1336 { WM_CTLCOLORDLG, sent|optional },
1337 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1338 { WM_PAINT, sent|optional },
1339 { WM_CTLCOLORBTN, sent|optional },
1340 { WM_GETTITLEBARINFOEX, sent|optional },
1341 { WM_ENTERIDLE, sent|parent|optional },
1342 { WM_ENTERIDLE, sent|parent|optional },
1343 { WM_ENTERIDLE, sent|parent|optional },
1344 { WM_ENTERIDLE, sent|parent|optional },
1345 { WM_ENTERIDLE, sent|parent|optional },
1346 { WM_ENTERIDLE, sent|parent|optional },
1347 { WM_ENTERIDLE, sent|parent|optional },
1348 { WM_ENTERIDLE, sent|parent|optional },
1349 { WM_ENTERIDLE, sent|parent|optional },
1350 { WM_ENTERIDLE, sent|parent|optional },
1351 { WM_ENTERIDLE, sent|parent|optional },
1352 { WM_ENTERIDLE, sent|parent|optional },
1353 { WM_ENTERIDLE, sent|parent|optional },
1354 { WM_ENTERIDLE, sent|parent|optional },
1355 { WM_ENTERIDLE, sent|parent|optional },
1356 { WM_ENTERIDLE, sent|parent|optional },
1357 { WM_ENTERIDLE, sent|parent|optional },
1358 { WM_ENTERIDLE, sent|parent|optional },
1359 { WM_ENTERIDLE, sent|parent|optional },
1360 { WM_ENTERIDLE, sent|parent|optional },
1361 { WM_TIMER, sent },
1362 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1363 { WM_ENABLE, sent|parent|wparam, 1 },
1364 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1365 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1366 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1367 { WM_GETTEXT, sent|optional },
1368 { HCBT_ACTIVATE, hook },
1369 { WM_NCACTIVATE, sent|wparam, 0 },
1370 { WM_GETTEXT, sent|optional },
1371 { WM_ACTIVATE, sent|wparam, 0 },
1372 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1373 { WM_WINDOWPOSCHANGING, sent|optional },
1374 { WM_WINDOWPOSCHANGED, sent|optional },
1375 { HCBT_SETFOCUS, hook },
1376 { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1377 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1378 { WM_SETFOCUS, sent|parent|defwinproc },
1379 { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1380 { HCBT_DESTROYWND, hook },
1381 { 0x0090, sent|optional },
1382 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1383 { WM_DESTROY, sent },
1384 { WM_NCDESTROY, sent },
1385 { 0 }
1386 };
1387 /* SetMenu for NonVisible windows with size change*/
1388 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1389 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1390 { WM_NCCALCSIZE, sent|wparam, 1 },
1391 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1392 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1393 { WM_MOVE, sent|defwinproc },
1394 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1395 { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1396 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1397 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1398 { WM_GETTEXT, sent|optional },
1399 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1400 { 0 }
1401 };
1402 /* SetMenu for NonVisible windows with no size change */
1403 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1404 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1405 { WM_NCCALCSIZE, sent|wparam, 1 },
1406 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1407 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1408 { 0 }
1409 };
1410 /* SetMenu for Visible windows with size change */
1411 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1412 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1413 { WM_NCCALCSIZE, sent|wparam, 1 },
1414 { 0x0093, sent|defwinproc|optional },
1415 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1416 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1417 { 0x0093, sent|defwinproc|optional },
1418 { 0x0093, sent|defwinproc|optional },
1419 { 0x0091, sent|defwinproc|optional },
1420 { 0x0092, sent|defwinproc|optional },
1421 { WM_GETTEXT, sent|defwinproc|optional },
1422 { WM_ERASEBKGND, sent|optional },
1423 { WM_ACTIVATE, sent|optional },
1424 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1425 { WM_MOVE, sent|defwinproc },
1426 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1427 { 0x0093, sent|optional },
1428 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1429 { 0x0093, sent|defwinproc|optional },
1430 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1431 { 0x0093, sent|defwinproc|optional },
1432 { 0x0093, sent|defwinproc|optional },
1433 { 0x0091, sent|defwinproc|optional },
1434 { 0x0092, sent|defwinproc|optional },
1435 { WM_ERASEBKGND, sent|optional },
1436 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1437 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1438 { 0 }
1439 };
1440 /* SetMenu for Visible windows with no size change */
1441 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1442 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1443 { WM_NCCALCSIZE, sent|wparam, 1 },
1444 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1445 { WM_GETTEXT, sent|defwinproc|optional },
1446 { WM_ERASEBKGND, sent|optional },
1447 { WM_ACTIVATE, sent|optional },
1448 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1449 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1450 { 0 }
1451 };
1452 /* DrawMenuBar for a visible window */
1453 static const struct message WmDrawMenuBarSeq[] =
1454 {
1455 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1456 { WM_NCCALCSIZE, sent|wparam, 1 },
1457 { 0x0093, sent|defwinproc|optional },
1458 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1459 { 0x0093, sent|defwinproc|optional },
1460 { 0x0093, sent|defwinproc|optional },
1461 { 0x0091, sent|defwinproc|optional },
1462 { 0x0092, sent|defwinproc|optional },
1463 { WM_GETTEXT, sent|defwinproc|optional },
1464 { WM_ERASEBKGND, sent|optional },
1465 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1466 { 0x0093, sent|optional },
1467 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1468 { 0 }
1469 };
1470
1471 static const struct message WmSetRedrawFalseSeq[] =
1472 {
1473 { WM_SETREDRAW, sent|wparam, 0 },
1474 { 0 }
1475 };
1476
1477 static const struct message WmSetRedrawTrueSeq[] =
1478 {
1479 { WM_SETREDRAW, sent|wparam, 1 },
1480 { 0 }
1481 };
1482
1483 static const struct message WmEnableWindowSeq_1[] =
1484 {
1485 { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1486 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1487 { HCBT_SETFOCUS, hook|optional },
1488 { WM_KILLFOCUS, sent|optional },
1489 { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1490 { 0 }
1491 };
1492
1493 static const struct message WmEnableWindowSeq_2[] =
1494 {
1495 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1496 { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1497 { 0 }
1498 };
1499
1500 static const struct message WmGetScrollRangeSeq[] =
1501 {
1502 { SBM_GETRANGE, sent },
1503 { 0 }
1504 };
1505 static const struct message WmGetScrollInfoSeq[] =
1506 {
1507 { SBM_GETSCROLLINFO, sent },
1508 { 0 }
1509 };
1510 static const struct message WmSetScrollRangeSeq[] =
1511 {
1512 /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1513 sends SBM_SETSCROLLINFO.
1514 */
1515 { SBM_SETSCROLLINFO, sent },
1516 { 0 }
1517 };
1518 /* SetScrollRange for a window without a non-client area */
1519 static const struct message WmSetScrollRangeHSeq_empty[] =
1520 {
1521 { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1522 { 0 }
1523 };
1524 static const struct message WmSetScrollRangeVSeq_empty[] =
1525 {
1526 { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1527 { 0 }
1528 };
1529 static const struct message WmSetScrollRangeHVSeq[] =
1530 {
1531 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1532 { WM_NCCALCSIZE, sent|wparam, 1 },
1533 { WM_GETTEXT, sent|defwinproc|optional },
1534 { WM_ERASEBKGND, sent|optional },
1535 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1536 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1537 { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1538 { 0 }
1539 };
1540 /* SetScrollRange for a window with a non-client area */
1541 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1542 {
1543 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1544 { WM_NCCALCSIZE, sent|wparam, 1 },
1545 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1546 { WM_NCPAINT, sent|optional },
1547 { WM_STYLECHANGING, sent|defwinproc|optional },
1548 { WM_STYLECHANGED, sent|defwinproc|optional },
1549 { WM_STYLECHANGING, sent|defwinproc|optional },
1550 { WM_STYLECHANGED, sent|defwinproc|optional },
1551 { WM_STYLECHANGING, sent|defwinproc|optional },
1552 { WM_STYLECHANGED, sent|defwinproc|optional },
1553 { WM_STYLECHANGING, sent|defwinproc|optional },
1554 { WM_STYLECHANGED, sent|defwinproc|optional },
1555 { WM_GETTEXT, sent|defwinproc|optional },
1556 { WM_GETTEXT, sent|defwinproc|optional },
1557 { WM_ERASEBKGND, sent|optional },
1558 { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1559 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOCLIENTSIZE },
1560 { WM_SIZE, sent|defwinproc|optional },
1561 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1562 { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1563 { WM_GETTEXT, sent|optional },
1564 { WM_GETTEXT, sent|optional },
1565 { WM_GETTEXT, sent|optional },
1566 { WM_GETTEXT, sent|optional },
1567 { 0 }
1568 };
1569 /* test if we receive the right sequence of messages */
1570 /* after calling ShowWindow( SW_SHOWNA) */
1571 static const struct message WmSHOWNAChildInvisParInvis[] = {
1572 { WM_SHOWWINDOW, sent|wparam, 1 },
1573 { 0 }
1574 };
1575 static const struct message WmSHOWNAChildVisParInvis[] = {
1576 { WM_SHOWWINDOW, sent|wparam, 1 },
1577 { 0 }
1578 };
1579 static const struct message WmSHOWNAChildVisParVis[] = {
1580 { WM_SHOWWINDOW, sent|wparam, 1 },
1581 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1582 { 0 }
1583 };
1584 static const struct message WmSHOWNAChildInvisParVis[] = {
1585 { WM_SHOWWINDOW, sent|wparam, 1 },
1586 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1587 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1588 { WM_ERASEBKGND, sent|optional },
1589 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1590 { 0 }
1591 };
1592 static const struct message WmSHOWNATopVisible[] = {
1593 { WM_SHOWWINDOW, sent|wparam, 1 },
1594 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1595 { WM_NCPAINT, sent|wparam|optional, 1 },
1596 { WM_GETTEXT, sent|defwinproc|optional },
1597 { WM_ERASEBKGND, sent|optional },
1598 { WM_WINDOWPOSCHANGED, sent|optional },
1599 { 0 }
1600 };
1601 static const struct message WmSHOWNATopInvisible[] = {
1602 { WM_NOTIFYFORMAT, sent|optional },
1603 { WM_QUERYUISTATE, sent|optional },
1604 { WM_WINDOWPOSCHANGING, sent|optional },
1605 { WM_GETMINMAXINFO, sent|optional },
1606 { WM_NCCALCSIZE, sent|optional },
1607 { WM_WINDOWPOSCHANGED, sent|optional },
1608 { WM_SHOWWINDOW, sent|wparam, 1 },
1609 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1610 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1611 { WM_NCPAINT, sent|wparam|optional, 1 },
1612 { WM_GETTEXT, sent|defwinproc|optional },
1613 { WM_ERASEBKGND, sent|optional },
1614 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1615 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1616 { WM_NCPAINT, sent|wparam|optional, 1 },
1617 { WM_ERASEBKGND, sent|optional },
1618 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1619 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1620 { WM_MOVE, sent },
1621 { 0 }
1622 };
1623
1624 static const struct message WmTrackPopupMenu[] = {
1625 { HCBT_CREATEWND, hook },
1626 { WM_ENTERMENULOOP, sent|wparam|lparam, TRUE, 0 },
1627 { WM_INITMENU, sent|lparam, 0, 0 },
1628 { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
1629 { 0x0093, sent|optional },
1630 { 0x0094, sent|optional },
1631 { 0x0094, sent|optional },
1632 { WM_ENTERIDLE, sent|wparam, 2 },
1633 { WM_CAPTURECHANGED, sent },
1634 { HCBT_DESTROYWND, hook },
1635 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
1636 { WM_MENUSELECT, sent|wparam|lparam, 0xffff0000, 0 },
1637 { WM_EXITMENULOOP, sent|wparam|lparam, 1, 0 },
1638 { 0 }
1639 };
1640
1641 static const struct message WmTrackPopupMenuCapture[] = {
1642 { HCBT_CREATEWND, hook },
1643 { WM_ENTERMENULOOP, sent|wparam|lparam, TRUE, 0 },
1644 { WM_CAPTURECHANGED, sent },
1645 { WM_INITMENU, sent|lparam, 0, 0 },
1646 { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
1647 { 0x0093, sent|optional },
1648 { 0x0094, sent|optional },
1649 { 0x0094, sent|optional },
1650 { WM_ENTERIDLE, sent|wparam, 2 },
1651 { WM_CAPTURECHANGED, sent },
1652 { HCBT_DESTROYWND, hook },
1653 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
1654 { WM_MENUSELECT, sent|wparam|lparam, 0xffff0000, 0 },
1655 { WM_EXITMENULOOP, sent|wparam|lparam, 1, 0 },
1656 { 0 }
1657 };
1658
1659 static const struct message WmTrackPopupMenuEmpty[] = {
1660 { HCBT_CREATEWND, hook },
1661 { WM_ENTERMENULOOP, sent|wparam|lparam, TRUE, 0 },
1662 { WM_INITMENU, sent|lparam, 0, 0 },
1663 { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
1664 { 0x0093, sent|optional },
1665 { 0x0094, sent|optional },
1666 { 0x0094, sent|optional },
1667 { WM_CAPTURECHANGED, sent },
1668 { WM_EXITMENULOOP, sent|wparam|lparam, 1, 0 },
1669 { HCBT_DESTROYWND, hook },
1670 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
1671 { 0 }
1672 };
1673
1674 static const struct message WmTrackPopupMenuAbort[] = {
1675 { HCBT_CREATEWND, hook },
1676 { WM_ENTERMENULOOP, sent|wparam|lparam, TRUE, 0 },
1677 { WM_INITMENU, sent|lparam, 0, 0 },
1678 { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
1679 { 0x0093, sent|optional },
1680 { 0x0094, sent|optional },
1681 { 0x0094, sent|optional },
1682 { WM_CAPTURECHANGED, sent },
1683 { HCBT_DESTROYWND, hook },
1684 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
1685 { WM_MENUSELECT, sent|wparam|lparam, 0xffff0000, 0 },
1686 { WM_EXITMENULOOP, sent|wparam|lparam, 1, 0 },
1687 { 0 }
1688 };
1689
1690 static BOOL after_end_dialog, test_def_id, paint_loop_done;
1691 static int sequence_cnt, sequence_size;
1692 static struct recvd_message* sequence;
1693 static int log_all_parent_messages;
1694 static CRITICAL_SECTION sequence_cs;
1695
1696 /* user32 functions */
1697 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1698 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
1699 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1700 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
1701 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1702 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1703 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1704 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
1705 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
1706 static BOOL (WINAPI *pUpdateLayeredWindow)(HWND,HDC,POINT*,SIZE*,HDC,POINT*,COLORREF,BLENDFUNCTION*,DWORD);
1707 static UINT_PTR (WINAPI *pSetSystemTimer)(HWND, UINT_PTR, UINT, TIMERPROC);
1708 static UINT_PTR (WINAPI *pKillSystemTimer)(HWND, UINT_PTR);
1709 /* kernel32 functions */
1710 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1711
1712 static void init_procs(void)
1713 {
1714 HMODULE user32 = GetModuleHandleA("user32.dll");
1715 HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1716
1717 #define GET_PROC(dll, func) \
1718 p ## func = (void*)GetProcAddress(dll, #func); \
1719 if(!p ## func) { \
1720 trace("GetProcAddress(%s) failed\n", #func); \
1721 }
1722
1723 GET_PROC(user32, GetAncestor)
1724 GET_PROC(user32, GetMenuInfo)
1725 GET_PROC(user32, NotifyWinEvent)
1726 GET_PROC(user32, SetMenuInfo)
1727 GET_PROC(user32, SetWinEventHook)
1728 GET_PROC(user32, TrackMouseEvent)
1729 GET_PROC(user32, UnhookWinEvent)
1730 GET_PROC(user32, GetMonitorInfoA)
1731 GET_PROC(user32, MonitorFromPoint)
1732 GET_PROC(user32, UpdateLayeredWindow)
1733 GET_PROC(user32, SetSystemTimer)
1734 GET_PROC(user32, KillSystemTimer)
1735
1736 GET_PROC(kernel32, GetCPInfoExA)
1737
1738 #undef GET_PROC
1739 }
1740
1741 static const char *get_winpos_flags(UINT flags)
1742 {
1743 static char buffer[300];
1744
1745 buffer[0] = 0;
1746 #define DUMP(flag) do { if (flags & flag) { strcat( buffer, "|" #flag ); flags &= ~flag; } } while(0)
1747 DUMP( SWP_SHOWWINDOW );
1748 DUMP( SWP_HIDEWINDOW );
1749 DUMP( SWP_NOACTIVATE );
1750 DUMP( SWP_FRAMECHANGED );
1751 DUMP( SWP_NOCOPYBITS );
1752 DUMP( SWP_NOOWNERZORDER );
1753 DUMP( SWP_NOSENDCHANGING );
1754 DUMP( SWP_DEFERERASE );
1755 DUMP( SWP_ASYNCWINDOWPOS );
1756 DUMP( SWP_NOZORDER );
1757 DUMP( SWP_NOREDRAW );
1758 DUMP( SWP_NOSIZE );
1759 DUMP( SWP_NOMOVE );
1760 DUMP( SWP_NOCLIENTSIZE );
1761 DUMP( SWP_NOCLIENTMOVE );
1762 if (flags) sprintf(buffer + strlen(buffer),"|0x%04x", flags);
1763 return buffer + 1;
1764 #undef DUMP
1765 }
1766
1767 static BOOL ignore_message( UINT message )
1768 {
1769 /* these are always ignored */
1770 return (message >= 0xc000 ||
1771 message == WM_GETICON ||
1772 message == WM_GETOBJECT ||
1773 message == WM_TIMECHANGE ||
1774 message == WM_DISPLAYCHANGE ||
1775 message == WM_DEVICECHANGE ||
1776 message == WM_DWMNCRENDERINGCHANGED);
1777 }
1778
1779
1780 #define add_message(msg) add_message_(__LINE__,msg);
1781 static void add_message_(int line, const struct recvd_message *msg)
1782 {
1783 struct recvd_message *seq;
1784
1785 EnterCriticalSection( &sequence_cs );
1786 if (!sequence)
1787 {
1788 sequence_size = 10;
1789 sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof(*sequence) );
1790 }
1791 if (sequence_cnt == sequence_size)
1792 {
1793 sequence_size *= 2;
1794 sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof(*sequence) );
1795 }
1796 assert(sequence);
1797
1798 seq = &sequence[sequence_cnt++];
1799 seq->hwnd = msg->hwnd;
1800 seq->message = msg->message;
1801 seq->flags = msg->flags;
1802 seq->wParam = msg->wParam;
1803 seq->lParam = msg->lParam;
1804 seq->line = line;
1805 seq->descr = msg->descr;
1806 seq->output[0] = 0;
1807 LeaveCriticalSection( &sequence_cs );
1808
1809 if (msg->descr)
1810 {
1811 if (msg->flags & hook)
1812 {
1813 static const char * const CBT_code_name[10] =
1814 {
1815 "HCBT_MOVESIZE",
1816 "HCBT_MINMAX",
1817 "HCBT_QS",
1818 "HCBT_CREATEWND",
1819 "HCBT_DESTROYWND",
1820 "HCBT_ACTIVATE",
1821 "HCBT_CLICKSKIPPED",
1822 "HCBT_KEYSKIPPED",
1823 "HCBT_SYSCOMMAND",
1824 "HCBT_SETFOCUS"
1825 };
1826 const char *code_name = (msg->message <= HCBT_SETFOCUS) ? CBT_code_name[msg->message] : "Unknown";
1827
1828 sprintf( seq->output, "%s: hook %d (%s) wp %08lx lp %08lx",
1829 msg->descr, msg->message, code_name, msg->wParam, msg->lParam );
1830 }
1831 else if (msg->flags & winevent_hook)
1832 {
1833 sprintf( seq->output, "%s: winevent %p %08x %08lx %08lx",
1834 msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1835 }
1836 else
1837 {
1838 switch (msg->message)
1839 {
1840 case WM_WINDOWPOSCHANGING:
1841 case WM_WINDOWPOSCHANGED:
1842 {
1843 WINDOWPOS *winpos = (WINDOWPOS *)msg->lParam;
1844
1845 sprintf( seq->output, "%s: %p WM_WINDOWPOS%s wp %08lx lp %08lx after %p x %d y %d cx %d cy %d flags %s",
1846 msg->descr, msg->hwnd,
1847 (msg->message == WM_WINDOWPOSCHANGING) ? "CHANGING" : "CHANGED",
1848 msg->wParam, msg->lParam, winpos->hwndInsertAfter,
1849 winpos->x, winpos->y, winpos->cx, winpos->cy,
1850 get_winpos_flags(winpos->flags) );
1851
1852 /* Log only documented flags, win2k uses 0x1000 and 0x2000
1853 * in the high word for internal purposes
1854 */
1855 seq->wParam = winpos->flags & 0xffff;
1856 /* We are not interested in the flags that don't match under XP and Win9x */
1857 seq->wParam &= ~SWP_NOZORDER;
1858 break;
1859 }
1860
1861 case WM_DRAWITEM:
1862 {
1863 DRAW_ITEM_STRUCT di;
1864 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)msg->lParam;
1865
1866 sprintf( seq->output, "%s: %p WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x",
1867 msg->descr, msg->hwnd, dis->CtlType, dis->CtlID,
1868 dis->itemID, dis->itemAction, dis->itemState);
1869
1870 di.u.lp = 0;
1871 di.u.item.type = dis->CtlType;
1872 di.u.item.ctl_id = dis->CtlID;
1873 if (dis->CtlType == ODT_LISTBOX ||
1874 dis->CtlType == ODT_COMBOBOX ||
1875 dis->CtlType == ODT_MENU)
1876 di.u.item.item_id = dis->itemID;
1877 di.u.item.action = dis->itemAction;
1878 di.u.item.state = dis->itemState;
1879
1880 seq->lParam = di.u.lp;
1881 break;
1882 }
1883 default:
1884 if (msg->message >= 0xc000) return; /* ignore registered messages */
1885 sprintf( seq->output, "%s: %p %04x wp %08lx lp %08lx",
1886 msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1887 }
1888 if (msg->flags & (sent|posted|parent|defwinproc|beginpaint))
1889 sprintf( seq->output + strlen(seq->output), " (flags %x)", msg->flags );
1890 }
1891 }
1892 }
1893
1894 /* try to make sure pending X events have been processed before continuing */
1895 static void flush_events(void)
1896 {
1897 MSG msg;
1898 int diff = 200;
1899 int min_timeout = 100;
1900 DWORD time = GetTickCount() + diff;
1901
1902 while (diff > 0)
1903 {
1904 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1905 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
1906 diff = time - GetTickCount();
1907 }
1908 }
1909
1910 static void flush_sequence(void)
1911 {
1912 EnterCriticalSection( &sequence_cs );
1913 HeapFree(GetProcessHeap(), 0, sequence);
1914 sequence = 0;
1915 sequence_cnt = sequence_size = 0;
1916 LeaveCriticalSection( &sequence_cs );
1917 }
1918
1919 static void dump_sequence(const struct message *expected, const char *context, const char *file, int line)
1920 {
1921 const struct recvd_message *actual = sequence;
1922 unsigned int count = 0;
1923
1924 trace_(file, line)("Failed sequence %s:\n", context );
1925 while (expected->message && actual->message)
1926 {
1927 if (actual->output[0])
1928 {
1929 if (expected->flags & hook)
1930 {
1931 trace_(file, line)( " %u: expected: hook %04x - actual: %s\n",
1932 count, expected->message, actual->output );
1933 }
1934 else if (expected->flags & winevent_hook)
1935 {
1936 trace_(file, line)( " %u: expected: winevent %04x - actual: %s\n",
1937 count, expected->message, actual->output );
1938 }
1939 else if (expected->flags & kbd_hook)
1940 {
1941 trace_(file, line)( " %u: expected: kbd %04x - actual: %s\n",
1942 count, expected->message, actual->output );
1943 }
1944 else
1945 {
1946 trace_(file, line)( " %u: expected: msg %04x - actual: %s\n",
1947 count, expected->message, actual->output );
1948 }
1949 }
1950
1951 if (expected->message == actual->message)
1952 {
1953 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) &&
1954 (expected->flags & optional))
1955 {
1956 /* don't match messages if their defwinproc status differs */
1957 expected++;
1958 }
1959 else
1960 {
1961 expected++;
1962 actual++;
1963 }
1964 }
1965 /* silently drop winevent messages if there is no support for them */
1966 else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1967 expected++;
1968 else
1969 {
1970 expected++;
1971 actual++;
1972 }
1973 count++;
1974 }
1975
1976 /* optional trailing messages */
1977 while (expected->message && ((expected->flags & optional) ||
1978 ((expected->flags & winevent_hook) && !hEvent_hook)))
1979 {
1980 trace_(file, line)( " %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1981 expected++;
1982 count++;
1983 }
1984
1985 if (expected->message)
1986 {
1987 trace_(file, line)( " %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1988 return;
1989 }
1990
1991 while (actual->message && actual->output[0])
1992 {
1993 trace_(file, line)( " %u: expected: nothing - actual: %s\n", count, actual->output );
1994 actual++;
1995 count++;
1996 }
1997 }
1998
1999 #define ok_sequence( exp, contx, todo) \
2000 ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
2001
2002
2003 static void ok_sequence_(const struct message *expected_list, const char *context, BOOL todo,
2004 const char *file, int line)
2005 {
2006 static const struct recvd_message end_of_sequence;
2007 const struct message *expected = expected_list;
2008 const struct recvd_message *actual;
2009 int failcount = 0, dump = 0;
2010 unsigned int count = 0;
2011
2012 add_message(&end_of_sequence);
2013
2014 actual = sequence;
2015
2016 while (expected->message && actual->message)
2017 {
2018 if (expected->message == actual->message &&
2019 !((expected->flags ^ actual->flags) & (hook|winevent_hook|kbd_hook)))
2020 {
2021 if (expected->flags & wparam)
2022 {
2023 if (((expected->wParam ^ actual->wParam) & ~expected->wp_mask) && todo)
2024 {
2025 todo_wine {
2026 failcount ++;
2027 if (strcmp(winetest_platform, "wine")) dump++;
2028 ok_( file, line) (FALSE,
2029 "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2030 context, count, expected->message, expected->wParam, actual->wParam);
2031 }
2032 }
2033 else
2034 {
2035 ok_( file, line)( ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) == 0,
2036 "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2037 context, count, expected->message, expected->wParam, actual->wParam);
2038 if ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) dump++;
2039 }
2040
2041 }
2042 if (expected->flags & lparam)
2043 {
2044 if (((expected->lParam ^ actual->lParam) & ~expected->lp_mask) && todo)
2045 {
2046 todo_wine {
2047 failcount ++;
2048 if (strcmp(winetest_platform, "wine")) dump++;
2049 ok_( file, line) (FALSE,
2050 "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2051 context, count, expected->message, expected->lParam, actual->lParam);
2052 }
2053 }
2054 else
2055 {
2056 ok_( file, line)(((expected->lParam ^ actual->lParam) & ~expected->lp_mask) == 0,
2057 "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2058 context, count, expected->message, expected->lParam, actual->lParam);
2059 if ((expected->lParam ^ actual->lParam) & ~expected->lp_mask) dump++;
2060 }
2061 }
2062 if ((expected->flags & optional) &&
2063 ((expected->flags ^ actual->flags) & (defwinproc|parent)))
2064 {
2065 /* don't match optional messages if their defwinproc or parent status differs */
2066 expected++;
2067 count++;
2068 continue;
2069 }
2070 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
2071 {
2072 todo_wine {
2073 failcount ++;
2074 if (strcmp(winetest_platform, "wine")) dump++;
2075 ok_( file, line) (FALSE,
2076 "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2077 context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2078 }
2079 }
2080 else
2081 {
2082 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
2083 "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2084 context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2085 if ((expected->flags & defwinproc) != (actual->flags & defwinproc)) dump++;
2086 }
2087
2088 ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
2089 "%s: %u: the msg 0x%04x should %shave been sent by BeginPaint\n",
2090 context, count, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
2091 if ((expected->flags & beginpaint) != (actual->flags & beginpaint)) dump++;
2092
2093 ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
2094 "%s: %u: the msg 0x%04x should have been %s\n",
2095 context, count, expected->message, (expected->flags & posted) ? "posted" : "sent");
2096 if ((expected->flags & (sent|posted)) != (actual->flags & (sent|posted))) dump++;
2097
2098 ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
2099 "%s: %u: the msg 0x%04x was expected in %s\n",
2100 context, count, expected->message, (expected->flags & parent) ? "parent" : "child");
2101 if ((expected->flags & parent) != (actual->flags & parent)) dump++;
2102
2103 ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
2104 "%s: %u: the msg 0x%04x should have been sent by a hook\n",
2105 context, count, expected->message);
2106 if ((expected->flags & hook) != (actual->flags & hook)) dump++;
2107
2108 ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
2109 "%s: %u: the msg 0x%04x should have been sent by a winevent hook\n",
2110 context, count, expected->message);
2111 if ((expected->flags & winevent_hook) != (actual->flags & winevent_hook)) dump++;
2112
2113 ok_( file, line) ((expected->flags & kbd_hook) == (actual->flags & kbd_hook),
2114 "%s: %u: the msg 0x%04x should have been sent by a keyboard hook\n",
2115 context, count, expected->message);
2116 if ((expected->flags & kbd_hook) != (actual->flags & kbd_hook)) dump++;
2117
2118 expected++;
2119 actual++;
2120 }
2121 /* silently drop hook messages if there is no support for them */
2122 else if ((expected->flags & optional) ||
2123 ((expected->flags & hook) && !hCBT_hook) ||
2124 ((expected->flags & winevent_hook) && !hEvent_hook) ||
2125 ((expected->flags & kbd_hook) && !hKBD_hook))
2126 expected++;
2127 else if (todo)
2128 {
2129 failcount++;
2130 todo_wine {
2131 if (strcmp(winetest_platform, "wine")) dump++;
2132 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2133 context, count, expected->message, actual->message);
2134 }
2135 goto done;
2136 }
2137 else
2138 {
2139 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2140 context, count, expected->message, actual->message);
2141 dump++;
2142 expected++;
2143 actual++;
2144 }
2145 count++;
2146 }
2147
2148 /* skip all optional trailing messages */
2149 while (expected->message && ((expected->flags & optional) ||
2150 ((expected->flags & hook) && !hCBT_hook) ||
2151 ((expected->flags & winevent_hook) && !hEvent_hook)))
2152 expected++;
2153
2154 if (todo)
2155 {
2156 todo_wine {
2157 if (expected->message || actual->message) {
2158 failcount++;
2159 if (strcmp(winetest_platform, "wine")) dump++;
2160 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2161 context, count, expected->message, actual->message);
2162 }
2163 }
2164 }
2165 else
2166 {
2167 if (expected->message || actual->message)
2168 {
2169 dump++;
2170 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2171 context, count, expected->message, actual->message);
2172 }
2173 }
2174 if( todo && !failcount) /* succeeded yet marked todo */
2175 todo_wine {
2176 if (!strcmp(winetest_platform, "wine")) dump++;
2177 ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
2178 }
2179
2180 done:
2181 if (dump) dump_sequence(expected_list, context, file, line);
2182 flush_sequence();
2183 }
2184
2185 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
2186
2187 /******************************** MDI test **********************************/
2188
2189 /* CreateWindow for MDI frame window, initially visible */
2190 static const struct message WmCreateMDIframeSeq[] = {
2191 { HCBT_CREATEWND, hook },
2192 { WM_GETMINMAXINFO, sent },
2193 { WM_NCCREATE, sent },
2194 { WM_NCCALCSIZE, sent|wparam, 0 },
2195 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2196 { WM_CREATE, sent },
2197 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2198 { WM_NOTIFYFORMAT, sent|optional },
2199 { WM_QUERYUISTATE, sent|optional },
2200 { WM_WINDOWPOSCHANGING, sent|optional },
2201 { WM_GETMINMAXINFO, sent|optional },
2202 { WM_NCCALCSIZE, sent|optional },
2203 { WM_WINDOWPOSCHANGED, sent|optional },
2204 { WM_SHOWWINDOW, sent|wparam, 1 },
2205 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2206 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2207 { HCBT_ACTIVATE, hook },
2208 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
2209 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
2210 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
2211 { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
2212 { WM_NCACTIVATE, sent },
2213 { WM_GETTEXT, sent|defwinproc|optional },
2214 { WM_ACTIVATE, sent|wparam, 1 },
2215 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
2216 { HCBT_SETFOCUS, hook },
2217 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2218 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2219 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2220 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
2221 /* Win9x adds SWP_NOZORDER below */
2222 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2223 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2224 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2225 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2226 { WM_MOVE, sent },
2227 { 0 }
2228 };
2229 /* DestroyWindow for MDI frame window, initially visible */
2230 static const struct message WmDestroyMDIframeSeq[] = {
2231 { HCBT_DESTROYWND, hook },
2232 { 0x0090, sent|optional },
2233 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2234 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2235 { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2236 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2237 { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
2238 { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2239 { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
2240 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
2241 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2242 { WM_DESTROY, sent },
2243 { WM_NCDESTROY, sent },
2244 { 0 }
2245 };
2246 /* CreateWindow for MDI client window, initially visible */
2247 static const struct message WmCreateMDIclientSeq[] = {
2248 { HCBT_CREATEWND, hook },
2249 { WM_NCCREATE, sent },
2250 { WM_NCCALCSIZE, sent|wparam, 0 },
2251 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2252 { WM_CREATE, sent },
2253 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2254 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2255 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2256 { WM_MOVE, sent },
2257 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
2258 { WM_SHOWWINDOW, sent|wparam, 1 },
2259 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2260 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2261 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2262 { 0 }
2263 };
2264 /* ShowWindow(SW_SHOW) for MDI client window */
2265 static const struct message WmShowMDIclientSeq[] = {
2266 { WM_SHOWWINDOW, sent|wparam, 1 },
2267 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2268 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2269 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2270 { 0 }
2271 };
2272 /* ShowWindow(SW_HIDE) for MDI client window */
2273 static const struct message WmHideMDIclientSeq[] = {
2274 { WM_SHOWWINDOW, sent|wparam, 0 },
2275 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2276 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
2277 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
2278 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2279 { 0 }
2280 };
2281 /* DestroyWindow for MDI client window, initially visible */
2282 static const struct message WmDestroyMDIclientSeq[] = {
2283 { HCBT_DESTROYWND, hook },
2284 { 0x0090, sent|optional },
2285 { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
2286 { WM_SHOWWINDOW, sent|wparam, 0 },
2287 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2288 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2289 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2290 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2291 { WM_DESTROY, sent },
2292 { WM_NCDESTROY, sent },
2293 { 0 }
2294 };
2295 /* CreateWindow for MDI child window, initially visible */
2296 static const struct message WmCreateMDIchildVisibleSeq[] = {
2297 { HCBT_CREATEWND, hook },
2298 { WM_NCCREATE, sent },
2299 { WM_NCCALCSIZE, sent|wparam, 0 },
2300 { WM_CREATE, sent },
2301 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2302 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2303 { WM_MOVE, sent },
2304 /* Win2k sends wparam set to
2305 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2306 * while Win9x doesn't bother to set child window id according to
2307 * CLIENTCREATESTRUCT.idFirstChild
2308 */
2309 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2310 { WM_SHOWWINDOW, sent|wparam, 1 },
2311 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2312 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2313 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2314 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2315 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2316 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2317 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2318
2319 /* Win9x: message sequence terminates here. */
2320
2321 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2322 { HCBT_SETFOCUS, hook }, /* in MDI client */
2323 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2324 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2325 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2326 { WM_SETFOCUS, sent }, /* in MDI client */
2327 { HCBT_SETFOCUS, hook },
2328 { WM_KILLFOCUS, sent }, /* in MDI client */
2329 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2330 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2331 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2332 { WM_SETFOCUS, sent|defwinproc },
2333 { WM_MDIACTIVATE, sent|defwinproc },
2334 { 0 }
2335 };
2336 /* CreateWindow for MDI child window with invisible parent */
2337 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
2338 { HCBT_CREATEWND, hook },
2339 { WM_GETMINMAXINFO, sent },
2340 { WM_NCCREATE, sent },
2341 { WM_NCCALCSIZE, sent|wparam, 0 },
2342 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2343 { WM_CREATE, sent },
2344 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2345 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2346 { WM_MOVE, sent },
2347 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2348 { WM_SHOWWINDOW, sent|wparam, 1 },
2349 { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2350 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2351 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2352 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2353
2354 /* Win9x: message sequence terminates here. */
2355
2356 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2357 { HCBT_SETFOCUS, hook }, /* in MDI client */
2358 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2359 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2360 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2361 { WM_SETFOCUS, sent }, /* in MDI client */
2362 { HCBT_SETFOCUS, hook },
2363 { WM_KILLFOCUS, sent }, /* in MDI client */
2364 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2365 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2366 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2367 { WM_SETFOCUS, sent|defwinproc },
2368 { WM_MDIACTIVATE, sent|defwinproc },
2369 { 0 }
2370 };
2371 /* DestroyWindow for MDI child window, initially visible */
2372 static const struct message WmDestroyMDIchildVisibleSeq[] = {
2373 { HCBT_DESTROYWND, hook },
2374 /* Win2k sends wparam set to
2375 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2376 * while Win9x doesn't bother to set child window id according to
2377 * CLIENTCREATESTRUCT.idFirstChild
2378 */
2379 { 0x0090, sent|optional },
2380 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2381 { WM_SHOWWINDOW, sent|wparam, 0 },
2382 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2383 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2384 { WM_ERASEBKGND, sent|parent|optional },
2385 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2386
2387 /* { WM_DESTROY, sent }
2388 * Win9x: message sequence terminates here.
2389 */
2390
2391 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2392 { WM_KILLFOCUS, sent },
2393 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2394 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2395 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2396 { WM_SETFOCUS, sent }, /* in MDI client */
2397
2398 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2399 { WM_KILLFOCUS, sent }, /* in MDI client */
2400 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2401 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2402 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2403 { WM_SETFOCUS, sent }, /* in MDI client */
2404
2405 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
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 { WM_DESTROY, sent },
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_NCDESTROY, sent },
2438 { 0 }
2439 };
2440 /* CreateWindow for MDI child window, initially invisible */
2441 static const struct message WmCreateMDIchildInvisibleSeq[] = {
2442 { HCBT_CREATEWND, hook },
2443 { WM_NCCREATE, sent },
2444 { WM_NCCALCSIZE, sent|wparam, 0 },
2445 { WM_CREATE, sent },
2446 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2447 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2448 { WM_MOVE, sent },
2449 /* Win2k sends wparam set to
2450 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2451 * while Win9x doesn't bother to set child window id according to
2452 * CLIENTCREATESTRUCT.idFirstChild
2453 */
2454 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2455 { 0 }
2456 };
2457 /* DestroyWindow for MDI child window, initially invisible */
2458 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
2459 { HCBT_DESTROYWND, hook },
2460 /* Win2k sends wparam set to
2461 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2462 * while Win9x doesn't bother to set child window id according to
2463 * CLIENTCREATESTRUCT.idFirstChild
2464 */
2465 { 0x0090, sent|optional },
2466 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2467 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2468 { WM_DESTROY, sent },
2469 { WM_NCDESTROY, sent },
2470 /* FIXME: Wine destroys an icon/title window while Windows doesn't */
2471 { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
2472 { 0 }
2473 };
2474 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
2475 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
2476 { HCBT_CREATEWND, hook },
2477 { WM_NCCREATE, sent },
2478 { WM_NCCALCSIZE, sent|wparam, 0 },
2479 { WM_CREATE, sent },
2480 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2481 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2482 { WM_MOVE, sent },
2483 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2484 { WM_GETMINMAXINFO, sent },
2485 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2486 { WM_NCCALCSIZE, sent|wparam, 1 },
2487 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2488 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2489 /* in MDI frame */
2490 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2491 { WM_NCCALCSIZE, sent|wparam, 1 },
2492 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2493 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2494 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2495 /* Win2k sends wparam set to
2496 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2497 * while Win9x doesn't bother to set child window id according to
2498 * CLIENTCREATESTRUCT.idFirstChild
2499 */
2500 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2501 { WM_SHOWWINDOW, sent|wparam, 1 },
2502 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2503 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2504 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2505 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2506 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2507 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2508 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_FRAMECHANGED },
2509
2510 /* Win9x: message sequence terminates here. */
2511
2512 { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2513 { HCBT_SETFOCUS, hook|optional }, /* in MDI client */
2514 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2515 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2516 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2517 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2518 { HCBT_SETFOCUS, hook|optional },
2519 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2520 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2521 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2522 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2523 { WM_SETFOCUS, sent|defwinproc|optional },
2524 { WM_MDIACTIVATE, sent|defwinproc|optional },
2525 /* in MDI frame */
2526 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2527 { WM_NCCALCSIZE, sent|wparam, 1 },
2528 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2529 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2530 { 0 }
2531 };
2532 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2533 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2534 /* restore the 1st MDI child */
2535 { WM_SETREDRAW, sent|wparam, 0 },
2536 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2537 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2538 { WM_NCCALCSIZE, sent|wparam, 1 },
2539 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2540 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2541 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2542 /* in MDI frame */
2543 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2544 { WM_NCCALCSIZE, sent|wparam, 1 },
2545 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2546 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2547 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2548 { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2549 /* create the 2nd MDI child */
2550 { HCBT_CREATEWND, hook },
2551 { WM_NCCREATE, sent },
2552 { WM_NCCALCSIZE, sent|wparam, 0 },
2553 { WM_CREATE, sent },
2554 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2555 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2556 { WM_MOVE, sent },
2557 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2558 { WM_GETMINMAXINFO, sent },
2559 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2560 { WM_NCCALCSIZE, sent|wparam, 1 },
2561 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2562 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2563 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2564 /* in MDI frame */
2565 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2566 { WM_NCCALCSIZE, sent|wparam, 1 },
2567 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2568 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2569 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2570 /* Win2k sends wparam set to
2571 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2572 * while Win9x doesn't bother to set child window id according to
2573 * CLIENTCREATESTRUCT.idFirstChild
2574 */
2575 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2576 { WM_SHOWWINDOW, sent|wparam, 1 },
2577 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2578 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2579 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2580 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2581 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2582 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2583
2584 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2585 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2586
2587 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2588
2589 /* Win9x: message sequence terminates here. */
2590
2591 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2592 { HCBT_SETFOCUS, hook },
2593 { WM_KILLFOCUS, sent|defwinproc|optional }, /* in the 1st MDI child */
2594 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2595 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2596 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2597 { WM_SETFOCUS, sent }, /* in MDI client */
2598 { HCBT_SETFOCUS, hook },
2599 { WM_KILLFOCUS, sent }, /* in MDI client */
2600 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2601 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2602 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2603 { WM_SETFOCUS, sent|defwinproc },
2604
2605 { WM_MDIACTIVATE, sent|defwinproc },
2606 /* in MDI frame */
2607 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2608 { WM_NCCALCSIZE, sent|wparam, 1 },
2609 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2610 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2611 { 0 }
2612 };
2613 /* WM_MDICREATE MDI child window, initially visible and maximized */
2614 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2615 { WM_MDICREATE, sent },
2616 { HCBT_CREATEWND, hook },
2617 { WM_NCCREATE, sent },
2618 { WM_NCCALCSIZE, sent|wparam, 0 },
2619 { WM_CREATE, sent },
2620 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2621 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2622 { WM_MOVE, sent },
2623 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2624 { WM_GETMINMAXINFO, sent },
2625 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2626 { WM_NCCALCSIZE, sent|wparam, 1 },
2627 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2628 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2629
2630 /* in MDI frame */
2631 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2632 { WM_NCCALCSIZE, sent|wparam, 1 },
2633 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2634 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2635 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2636
2637 /* Win2k sends wparam set to
2638 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2639 * while Win9x doesn't bother to set child window id according to
2640 * CLIENTCREATESTRUCT.idFirstChild
2641 */
2642 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2643 { WM_SHOWWINDOW, sent|wparam, 1 },
2644 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2645
2646 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2647
2648 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2649 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2650 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2651
2652 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2653 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2654
2655 /* Win9x: message sequence terminates here. */
2656
2657 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2658 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2659 { HCBT_SETFOCUS, hook }, /* in MDI client */
2660 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2661 { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2662 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2663 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2664 { HCBT_SETFOCUS, hook|optional },
2665 { WM_KILLFOCUS, sent }, /* in MDI client */
2666 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2667 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2668 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2669 { WM_SETFOCUS, sent|defwinproc },
2670
2671 { WM_MDIACTIVATE, sent|defwinproc },
2672
2673 /* in MDI child */
2674 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2675 { WM_NCCALCSIZE, sent|wparam, 1 },
2676 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2677 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2678
2679 /* in MDI frame */
2680 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2681 { WM_NCCALCSIZE, sent|wparam, 1 },
2682 { 0x0093, sent|defwinproc|optional },
2683 { 0x0093, sent|defwinproc|optional },
2684 { 0x0093, sent|defwinproc|optional },
2685 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2686 { WM_MOVE, sent|defwinproc },
2687 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2688
2689 /* in MDI client */
2690 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2691 { WM_NCCALCSIZE, sent|wparam, 1 },
2692 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2693 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2694
2695 /* in MDI child */
2696 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2697 { WM_NCCALCSIZE, sent|wparam, 1 },
2698 { 0x0093, sent|optional },
2699 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2700 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2701
2702 { 0x0093, sent|optional },
2703 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2704 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2705 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2706 { 0x0093, sent|defwinproc|optional },
2707 { 0x0093, sent|defwinproc|optional },
2708 { 0x0093, sent|defwinproc|optional },
2709 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2710 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2711
2712 { 0 }
2713 };
2714 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2715 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2716 { HCBT_CREATEWND, hook },
2717 { WM_GETMINMAXINFO, sent },
2718 { WM_NCCREATE, sent },
2719 { WM_NCCALCSIZE, sent|wparam, 0 },
2720 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2721 { WM_CREATE, sent },
2722 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2723 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2724 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2725 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI frame */
2726 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2727 { WM_MOVE, sent },
2728 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2729 { WM_GETMINMAXINFO, sent },
2730 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2731 { WM_GETMINMAXINFO, sent|defwinproc },
2732 { WM_NCCALCSIZE, sent|wparam, 1 },
2733 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_STATECHANGED },
2734 { WM_MOVE, sent|defwinproc },
2735 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2736 /* in MDI frame */
2737 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2738 { WM_NCCALCSIZE, sent|wparam, 1 },
2739 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2740 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2741 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2742 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2743 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2744 /* Win2k sends wparam set to
2745 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2746 * while Win9x doesn't bother to set child window id according to
2747 * CLIENTCREATESTRUCT.idFirstChild
2748 */
2749 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2750 { 0 }
2751 };
2752 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2753 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2754 { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2755 { HCBT_SYSCOMMAND, hook },
2756 { WM_CLOSE, sent|defwinproc },
2757 { WM_MDIDESTROY, sent }, /* in MDI client */
2758
2759 /* bring the 1st MDI child to top */
2760 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2761 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2762
2763 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2764
2765 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2766 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2767 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2768
2769 /* maximize the 1st MDI child */
2770 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2771 { WM_GETMINMAXINFO, sent|defwinproc },
2772 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED },
2773 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2774 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2775 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2776 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2777
2778 /* restore the 2nd MDI child */
2779 { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2780 { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2781 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2782 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2783
2784 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2785
2786 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2787 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2788
2789 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2790
2791 { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2792 /* in MDI frame */
2793 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2794 { WM_NCCALCSIZE, sent|wparam, 1 },
2795 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2796 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2797 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2798
2799 /* bring the 1st MDI child to top */
2800 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2801 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2802 { HCBT_SETFOCUS, hook },
2803 { WM_KILLFOCUS, sent|defwinproc },
2804 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2805 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2806 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2807 { WM_SETFOCUS, sent }, /* in MDI client */
2808 { HCBT_SETFOCUS, hook },
2809 { WM_KILLFOCUS, sent }, /* in MDI client */
2810 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2811 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2812 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2813 { WM_SETFOCUS, sent|defwinproc },
2814 { WM_MDIACTIVATE, sent|defwinproc },
2815 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2816
2817 /* apparently ShowWindow(SW_SHOW) on an MDI client */
2818 { WM_SHOWWINDOW, sent|wparam, 1 },
2819 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2820 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2821 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2822 { WM_MDIREFRESHMENU, sent },
2823
2824 { HCBT_DESTROYWND, hook },
2825 /* Win2k sends wparam set to
2826 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2827 * while Win9x doesn't bother to set child window id according to
2828 * CLIENTCREATESTRUCT.idFirstChild
2829 */
2830 { 0x0090, sent|defwinproc|optional },
2831 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2832 { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2833 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2834 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2835 { WM_ERASEBKGND, sent|parent|optional },
2836 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2837
2838 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2839 { WM_DESTROY, sent|defwinproc },
2840 { WM_NCDESTROY, sent|defwinproc },
2841 { 0 }
2842 };
2843 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2844 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2845 { WM_MDIDESTROY, sent }, /* in MDI client */
2846 { WM_SHOWWINDOW, sent|wparam, 0 },
2847 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2848 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2849 { WM_ERASEBKGND, sent|parent|optional },
2850 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2851
2852 { HCBT_SETFOCUS, hook },
2853 { WM_KILLFOCUS, sent },
2854 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2855 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2856 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2857 { WM_SETFOCUS, sent }, /* in MDI client */
2858 { HCBT_SETFOCUS, hook },
2859 { WM_KILLFOCUS, sent }, /* in MDI client */
2860 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2861 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2862 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2863 { WM_SETFOCUS, sent },
2864
2865 /* in MDI child */
2866 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2867 { WM_NCCALCSIZE, sent|wparam, 1 },
2868 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2869 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2870
2871 /* in MDI frame */
2872 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2873 { WM_NCCALCSIZE, sent|wparam, 1 },
2874 { 0x0093, sent|defwinproc|optional },
2875 { 0x0093, sent|defwinproc|optional },
2876 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2877 { WM_MOVE, sent|defwinproc },
2878 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2879
2880 /* in MDI client */
2881 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2882 { WM_NCCALCSIZE, sent|wparam, 1 },
2883 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2884 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2885
2886 /* in MDI child */
2887 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2888 { WM_NCCALCSIZE, sent|wparam, 1 },
2889 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2890 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2891
2892 /* in MDI child */
2893 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2894 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2895 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2896 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2897
2898 /* in MDI frame */
2899 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2900 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2901 { 0x0093, sent|defwinproc|optional },
2902 { 0x0093, sent|defwinproc|optional },
2903 { 0x0093, sent|defwinproc|optional },
2904 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2905 { WM_MOVE, sent|defwinproc },
2906 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2907
2908 /* in MDI client */
2909 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2910 { WM_NCCALCSIZE, sent|wparam, 1 },
2911 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2912 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2913
2914 /* in MDI child */
2915 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2916 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2917 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2918 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2919 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2920 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2921
2922 { 0x0093, sent|defwinproc|optional },
2923 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2924 { 0x0093, sent|defwinproc|optional },
2925 { 0x0093, sent|defwinproc|optional },
2926 { 0x0093, sent|defwinproc|optional },
2927 { 0x0093, sent|optional },
2928
2929 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2930 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2931 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2932 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2933 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2934
2935 /* in MDI frame */
2936 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2937 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2938 { 0x0093, sent|defwinproc|optional },
2939 { 0x0093, sent|defwinproc|optional },
2940 { 0x0093, sent|defwinproc|optional },
2941 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2942 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2943 { 0x0093, sent|optional },
2944
2945 { WM_NCACTIVATE, sent|wparam, 0 },
2946 { WM_MDIACTIVATE, sent },
2947
2948 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2949 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2950 { WM_NCCALCSIZE, sent|wparam, 1 },
2951
2952 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2953
2954 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2955 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2956 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2957
2958 /* in MDI child */
2959 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2960 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2961 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2962 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2963
2964 /* in MDI frame */
2965 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2966 { WM_NCCALCSIZE, sent|wparam, 1 },
2967 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2968 { WM_MOVE, sent|defwinproc },
2969 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2970
2971 /* in MDI client */
2972 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2973 { WM_NCCALCSIZE, sent|wparam, 1 },
2974 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2975 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2976 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2977 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2978 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2979 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2980 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2981
2982 { HCBT_SETFOCUS, hook },
2983 { WM_KILLFOCUS, sent },
2984 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2985 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2986 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2987 { WM_SETFOCUS, sent }, /* in MDI client */
2988
2989 { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2990
2991 { HCBT_DESTROYWND, hook },
2992 /* Win2k sends wparam set to
2993 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2994 * while Win9x doesn't bother to set child window id according to
2995 * CLIENTCREATESTRUCT.idFirstChild
2996 */
2997 { 0x0090, sent|optional },
2998 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2999
3000 { WM_SHOWWINDOW, sent|wparam, 0 },
3001 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3002 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
3003 { WM_ERASEBKGND, sent|parent|optional },
3004 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3005
3006 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
3007 { WM_DESTROY, sent },
3008 { WM_NCDESTROY, sent },
3009 { 0 }
3010 };
3011 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
3012 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
3013 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3014 { WM_GETMINMAXINFO, sent },
3015 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
3016 { WM_NCCALCSIZE, sent|wparam, 1 },
3017 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3018 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3019
3020 { WM_WINDOWPOSCHANGING, sent|wparam|optional|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3021 { WM_NCACTIVATE, sent|wparam|optional|defwinproc, 1 },
3022 { HCBT_SETFOCUS, hook|optional },
3023 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3024 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3025 { WM_SETFOCUS, sent|optional }, /* in MDI client */
3026 { HCBT_SETFOCUS, hook|optional },
3027 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3028 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3029 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3030 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3031 { WM_SETFOCUS, sent|optional|defwinproc },
3032 { WM_MDIACTIVATE, sent|optional|defwinproc },
3033 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3034 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3035 /* in MDI frame */
3036 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3037 { WM_NCCALCSIZE, sent|wparam, 1 },
3038 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3039 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3040 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3041 { 0 }
3042 };
3043 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
3044 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
3045 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3046 { WM_GETMINMAXINFO, sent },
3047 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
3048 { WM_GETMINMAXINFO, sent|defwinproc },
3049 { WM_NCCALCSIZE, sent|wparam, 1 },
3050 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3051 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3052
3053 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3054 { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
3055 { HCBT_SETFOCUS, hook|optional },
3056 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3057 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3058 { WM_SETFOCUS, sent|optional }, /* in MDI client */
3059 { HCBT_SETFOCUS, hook|optional },
3060 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3061 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3062 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3063 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3064 { WM_SETFOCUS, sent|defwinproc|optional },
3065 { WM_MDIACTIVATE, sent|defwinproc|optional },
3066 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3067 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3068 { 0 }
3069 };
3070 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
3071 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
3072 { WM_MDIMAXIMIZE, sent }, /* in MDI client */
3073 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3074 { WM_GETMINMAXINFO, sent },
3075 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3076 { WM_GETMINMAXINFO, sent|defwinproc },
3077 { WM_NCCALCSIZE, sent|wparam, 1 },
3078 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
3079 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3080 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
3081 { WM_MOVE, sent|defwinproc },
3082 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3083
3084 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3085 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3086 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3087 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3088 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3089 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3090 /* in MDI frame */
3091 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3092 { WM_NCCALCSIZE, sent|wparam, 1 },
3093 { 0x0093, sent|defwinproc|optional },
3094 { 0x0094, sent|defwinproc|optional },
3095 { 0x0094, sent|defwinproc|optional },
3096 { 0x0094, sent|defwinproc|optional },
3097 { 0x0094, sent|defwinproc|optional },
3098 { 0x0093, sent|defwinproc|optional },
3099 { 0x0093, sent|defwinproc|optional },
3100 { 0x0091, sent|defwinproc|optional },
3101 { 0x0092, sent|defwinproc|optional },
3102 { 0x0092, sent|defwinproc|optional },
3103 { 0x0092, sent|defwinproc|optional },
3104 { 0x0092, sent|defwinproc|optional },
3105 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3106 { WM_MOVE, sent|defwinproc },
3107 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3108 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
3109 /* in MDI client */
3110 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
3111 { WM_NCCALCSIZE, sent|wparam, 1 },
3112 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3113 { WM_SIZE, sent|wparam, SIZE_RESTORED },
3114 /* in MDI child */
3115 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
3116 { WM_GETMINMAXINFO, sent|defwinproc },
3117 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3118 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3119 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3120 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
3121 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3122 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3123 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3124 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3125 /* in MDI frame */
3126 { 0x0093, sent|optional },
3127 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
3128 { 0x0093, sent|defwinproc|optional },
3129 { 0x0093, sent|defwinproc|optional },
3130 { 0x0093, sent|defwinproc|optional },
3131 { 0x0091, sent|defwinproc|optional },
3132 { 0x0092, sent|defwinproc|optional },
3133 { 0x0092, sent|defwinproc|optional },
3134 { 0x0092, sent|defwinproc|optional },
3135 { 0x0092, sent|defwinproc|optional },
3136 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3137 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3138 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3139 { 0 }
3140 };
3141 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
3142 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
3143 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3144 { WM_GETMINMAXINFO, sent },
3145 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3146 { WM_NCCALCSIZE, sent|wparam, 1 },
3147 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3148 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3149 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3150 /* in MDI frame */
3151 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3152 { WM_NCCALCSIZE, sent|wparam, 1 },
3153 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3154 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3155 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3156 { 0 }
3157 };
3158 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
3159 static const struct message WmRestoreMDIchildVisibleSeq[] = {
3160 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
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_RESTORED },
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 minimized MDI child window */
3175 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
3176 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3177 { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
3178 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3179 { WM_NCCALCSIZE, sent|wparam, 1 },
3180 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3181 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3182 { WM_MOVE, sent|defwinproc },
3183 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3184 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3185 { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3186 { HCBT_SETFOCUS, hook },
3187 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3188 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
3189 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3190 { WM_SETFOCUS, sent },
3191 { 0 }
3192 };
3193 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
3194 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
3195 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
3196 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3197 { WM_NCCALCSIZE, sent|wparam, 1 },
3198 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3199 { WM_MOVE, sent|defwinproc },
3200 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
3201 { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
3202 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3203 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3204 /* FIXME: Wine creates an icon/title window while Windows doesn't */
3205 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
3206 { 0 }
3207 };
3208 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
3209 static const struct message WmRestoreMDIchildInisibleSeq[] = {
3210 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3211 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
3212 { WM_NCCALCSIZE, sent|wparam, 1 },
3213 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3214 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3215 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3216 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3217 /* in MDI frame */
3218 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3219 { WM_NCCALCSIZE, sent|wparam, 1 },
3220 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3221 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3222 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3223 { 0 }
3224 };
3225
3226 static HWND mdi_client;
3227 static WNDPROC old_mdi_client_proc;
3228
3229 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3230 {
3231 struct recvd_message msg;
3232
3233 /* do not log painting messages */
3234 if (message != WM_PAINT &&
3235 message != WM_NCPAINT &&
3236 message != WM_SYNCPAINT &&
3237 message != WM_ERASEBKGND &&
3238 message != WM_NCHITTEST &&
3239 message != WM_GETTEXT &&
3240 message != WM_MDIGETACTIVE &&
3241 !ignore_message( message ))
3242 {
3243 msg.hwnd = hwnd;
3244 msg.message = message;
3245 msg.flags = sent|wparam|lparam;
3246 msg.wParam = wParam;
3247 msg.lParam = lParam;
3248 msg.descr = "mdi client";
3249 add_message(&msg);
3250 }
3251
3252 return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
3253 }
3254
3255 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3256 {
3257 static LONG defwndproc_counter = 0;
3258 LRESULT ret;
3259 struct recvd_message msg;
3260
3261 /* do not log painting messages */
3262 if (message != WM_PAINT &&
3263 message != WM_NCPAINT &&
3264 message != WM_SYNCPAINT &&
3265 message != WM_ERASEBKGND &&
3266 message != WM_NCHITTEST &&
3267 message != WM_GETTEXT &&
3268 !ignore_message( message ))
3269 {
3270 switch (message)
3271 {
3272 case WM_MDIACTIVATE:
3273 {
3274 HWND active, client = GetParent(hwnd);
3275
3276 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
3277
3278 if (hwnd == (HWND)lParam) /* if we are being activated */
3279 ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
3280 else
3281 ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
3282 break;
3283 }
3284 }
3285
3286 msg.hwnd = hwnd;
3287 msg.message = message;
3288 msg.flags = sent|wparam|lparam;
3289 if (defwndproc_counter) msg.flags |= defwinproc;
3290 msg.wParam = wParam;
3291 msg.lParam = lParam;
3292 msg.descr = "mdi child";
3293 add_message(&msg);
3294 }
3295
3296 defwndproc_counter++;
3297 ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
3298 defwndproc_counter--;
3299
3300 return ret;
3301 }
3302
3303 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3304 {
3305 static LONG defwndproc_counter = 0;
3306 LRESULT ret;
3307 struct recvd_message msg;
3308
3309 /* do not log painting messages */
3310 if (message != WM_PAINT &&
3311 message != WM_NCPAINT &&
3312 message != WM_SYNCPAINT &&
3313 message != WM_ERASEBKGND &&
3314 message != WM_NCHITTEST &&
3315 message != WM_GETTEXT &&
3316 !ignore_message( message ))
3317 {
3318 msg.hwnd = hwnd;
3319 msg.message = message;
3320 msg.flags = sent|wparam|lparam;
3321 if (defwndproc_counter) msg.flags |= defwinproc;
3322 msg.wParam = wParam;
3323 msg.lParam = lParam;
3324 msg.descr = "mdi frame";
3325 add_message(&msg);
3326 }
3327
3328 defwndproc_counter++;
3329 ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
3330 defwndproc_counter--;
3331
3332 return ret;
3333 }
3334
3335 static BOOL mdi_RegisterWindowClasses(void)
3336 {
3337 WNDCLASSA cls;
3338
3339 cls.style = 0;
3340 cls.lpfnWndProc = mdi_frame_wnd_proc;
3341 cls.cbClsExtra = 0;
3342 cls.cbWndExtra = 0;
3343 cls.hInstance = GetModuleHandleA(0);
3344 cls.hIcon = 0;
3345 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
3346 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3347 cls.lpszMenuName = NULL;
3348 cls.lpszClassName = "MDI_frame_class";
3349 if (!RegisterClassA(&cls)) return FALSE;
3350
3351 cls.lpfnWndProc = mdi_child_wnd_proc;
3352 cls.lpszClassName = "MDI_child_class";
3353 if (!RegisterClassA(&cls)) return FALSE;
3354
3355 if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
3356 old_mdi_client_proc = cls.lpfnWndProc;
3357 cls.hInstance = GetModuleHandleA(0);
3358 cls.lpfnWndProc = mdi_client_hook_proc;
3359 cls.lpszClassName = "MDI_client_class";
3360 if (!RegisterClassA(&cls)) assert(0);
3361
3362 return TRUE;
3363 }
3364
3365 static void test_mdi_messages(void)
3366 {
3367 MDICREATESTRUCTA mdi_cs;
3368 CLIENTCREATESTRUCT client_cs;
3369 HWND mdi_frame, mdi_child, mdi_child2, active_child;
3370 BOOL zoomed;
3371 RECT rc;
3372 HMENU hMenu = CreateMenu();
3373
3374 if (!mdi_RegisterWindowClasses()) assert(0);
3375
3376 flush_sequence();
3377
3378 trace("creating MDI frame window\n");
3379 mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
3380 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3381 WS_MAXIMIZEBOX | WS_VISIBLE,
3382 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
3383 GetDesktopWindow(), hMenu,
3384 GetModuleHandleA(0), NULL);
3385 assert(mdi_frame);
3386 ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
3387
3388 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3389 ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
3390
3391 trace("creating MDI client window\n");
3392 GetClientRect(mdi_frame, &rc);
3393 client_cs.hWindowMenu = 0;
3394 client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
3395 mdi_client = CreateWindowExA(0, "MDI_client_class",
3396 NULL,
3397 WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
3398 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
3399 mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3400 assert(mdi_client);
3401 ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
3402
3403 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3404 ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
3405
3406 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3407 ok(!active_child, "wrong active MDI child %p\n", active_child);
3408 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3409
3410 SetFocus(0);
3411 flush_sequence();
3412
3413 trace("creating invisible MDI child window\n");
3414 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3415 WS_CHILD,
3416 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3417 mdi_client, 0, GetModuleHandleA(0), NULL);
3418 assert(mdi_child);
3419
3420 flush_sequence();
3421 ShowWindow(mdi_child, SW_SHOWNORMAL);
3422 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
3423
3424 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3425 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3426
3427 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3428 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3429
3430 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3431 ok(!active_child, "wrong active MDI child %p\n", active_child);
3432 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3433
3434 ShowWindow(mdi_child, SW_HIDE);
3435 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
3436 flush_sequence();
3437
3438 ShowWindow(mdi_child, SW_SHOW);
3439 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
3440
3441 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3442 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3443
3444 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3445 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3446
3447 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3448 ok(!active_child, "wrong active MDI child %p\n", active_child);
3449 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3450
3451 DestroyWindow(mdi_child);
3452 flush_sequence();
3453
3454 trace("creating visible MDI child window\n");
3455 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3456 WS_CHILD | WS_VISIBLE,
3457 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3458 mdi_client, 0, GetModuleHandleA(0), NULL);
3459 assert(mdi_child);
3460 ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
3461
3462 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3463 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3464
3465 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3466 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3467
3468 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3469 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3470 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3471 flush_sequence();
3472
3473 DestroyWindow(mdi_child);
3474 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3475
3476 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3477 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3478
3479 /* Win2k: MDI client still returns a just destroyed child as active
3480 * Win9x: MDI client returns 0
3481 */
3482 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3483 ok(active_child == mdi_child || /* win2k */
3484 !active_child, /* win9x */
3485 "wrong active MDI child %p\n", active_child);
3486 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3487
3488 flush_sequence();
3489
3490 trace("creating invisible MDI child window\n");
3491 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3492 WS_CHILD,
3493 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3494 mdi_client, 0, GetModuleHandleA(0), NULL);
3495 assert(mdi_child2);
3496 ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
3497
3498 ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
3499 ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
3500
3501 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3502 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3503
3504 /* Win2k: MDI client still returns a just destroyed child as active
3505 * Win9x: MDI client returns mdi_child2
3506 */
3507 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3508 ok(active_child == mdi_child || /* win2k */
3509 active_child == mdi_child2, /* win9x */
3510 "wrong active MDI child %p\n", active_child);
3511 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3512 flush_sequence();
3513
3514 ShowWindow(mdi_child2, SW_MAXIMIZE);
3515 ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3516
3517 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3518 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3519
3520 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3521 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3522 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3523 flush_sequence();
3524
3525 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3526 ok(GetFocus() == mdi_child2 || /* win2k */
3527 GetFocus() == 0, /* win9x */
3528 "wrong focus window %p\n", GetFocus());
3529
3530 SetFocus(0);
3531 flush_sequence();
3532
3533 ShowWindow(mdi_child2, SW_HIDE);
3534 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3535
3536 ShowWindow(mdi_child2, SW_RESTORE);
3537 ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3538 flush_sequence();
3539
3540 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3541 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3542
3543 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3544 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3545 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3546 flush_sequence();
3547
3548 SetFocus(0);
3549 flush_sequence();
3550
3551 ShowWindow(mdi_child2, SW_HIDE);
3552 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3553
3554 ShowWindow(mdi_child2, SW_SHOW);
3555 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3556
3557 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3558 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3559
3560 ShowWindow(mdi_child2, SW_MAXIMIZE);
3561 ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3562
3563 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3564 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3565
3566 ShowWindow(mdi_child2, SW_RESTORE);
3567 ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3568
3569 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3570 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3571
3572 ShowWindow(mdi_child2, SW_MINIMIZE);
3573 ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3574
3575 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3576 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3577
3578 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3579 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3580 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3581 flush_sequence();
3582
3583 ShowWindow(mdi_child2, SW_RESTORE);
3584 ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", FALSE);
3585
3586 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3587 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3588
3589 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3590 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3591 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3592 flush_sequence();
3593
3594 SetFocus(0);
3595 flush_sequence();
3596
3597 ShowWindow(mdi_child2, SW_HIDE);
3598 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3599
3600 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3601 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3602
3603 DestroyWindow(mdi_child2);
3604 ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3605
3606 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3607 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3608
3609 /* test for maximized MDI children */
3610 trace("creating maximized visible MDI child window 1\n");
3611 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3612 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3613 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3614 mdi_client, 0, GetModuleHandleA(0), NULL);
3615 assert(mdi_child);
3616 ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3617 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3618
3619 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3620 ok(GetFocus() == mdi_child || /* win2k */
3621 GetFocus() == 0, /* win9x */
3622 "wrong focus window %p\n", GetFocus());
3623
3624 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3625 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3626 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3627 flush_sequence();
3628
3629 trace("creating maximized visible MDI child window 2\n");
3630 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3631 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3632 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3633 mdi_client, 0, GetModuleHandleA(0), NULL);
3634 assert(mdi_child2);
3635 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3636 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3637 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3638
3639 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3640 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3641
3642 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3643 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3644 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3645 flush_sequence();
3646
3647 trace("destroying maximized visible MDI child window 2\n");
3648 DestroyWindow(mdi_child2);
3649 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3650
3651 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3652
3653 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3654 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3655
3656 /* Win2k: MDI client still returns a just destroyed child as active
3657 * Win9x: MDI client returns 0
3658 */
3659 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3660 ok(active_child == mdi_child2 || /* win2k */
3661 !active_child, /* win9x */
3662 "wrong active MDI child %p\n", active_child);
3663 flush_sequence();
3664
3665 ShowWindow(mdi_child, SW_MAXIMIZE);
3666 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3667 flush_sequence();
3668
3669 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3670 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3671
3672 trace("re-creating maximized visible MDI child window 2\n");
3673 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3674 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3675 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3676 mdi_client, 0, GetModuleHandleA(0), NULL);
3677 assert(mdi_child2);
3678 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3679 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3680 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3681
3682 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3683 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3684
3685 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3686 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3687 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3688 flush_sequence();
3689
3690 SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3691 ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3692 ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3693
3694 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3695 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3696 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3697
3698 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3699 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3700 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3701 flush_sequence();
3702
3703 DestroyWindow(mdi_child);
3704 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3705
3706 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3707 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3708
3709 /* Win2k: MDI client still returns a just destroyed child as active
3710 * Win9x: MDI client returns 0
3711 */
3712 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3713 ok(active_child == mdi_child || /* win2k */
3714 !active_child, /* win9x */
3715 "wrong active MDI child %p\n", active_child);
3716 flush_sequence();
3717
3718 trace("creating maximized invisible MDI child window\n");
3719 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3720 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3721 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3722 mdi_client, 0, GetModuleHandleA(0), NULL);
3723 assert(mdi_child2);
3724 ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", FALSE);
3725 ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3726 ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3727 ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3728
3729 /* Win2k: MDI client still returns a just destroyed child as active
3730 * Win9x: MDI client returns 0
3731 */
3732 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3733 ok(active_child == mdi_child || /* win2k */
3734 !active_child || active_child == mdi_child2, /* win9x */
3735 "wrong active MDI child %p\n", active_child);
3736 flush_sequence();
3737
3738 trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3739 ShowWindow(mdi_child2, SW_MAXIMIZE);
3740 ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", 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 visible\n");
3743 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3744
3745 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3746 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3747 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3748 flush_sequence();
3749
3750 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3751 flush_sequence();
3752
3753 /* end of test for maximized MDI children */
3754 SetFocus(0);
3755 flush_sequence();
3756 trace("creating maximized visible MDI child window 1(Switch test)\n");
3757 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3758 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3759 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3760 mdi_client, 0, GetModuleHandleA(0), NULL);
3761 assert(mdi_child);
3762 ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3763 ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3764
3765 ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3766 ok(GetFocus() == mdi_child || /* win2k */
3767 GetFocus() == 0, /* win9x */
3768 "wrong focus window %p(Switch test)\n", GetFocus());
3769
3770 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3771 ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3772 ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3773 flush_sequence();
3774
3775 trace("creating maximized visible MDI child window 2(Switch test)\n");
3776 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3777 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3778 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3779 mdi_client, 0, GetModuleHandleA(0), NULL);
3780 assert(mdi_child2);
3781 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3782
3783 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3784 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3785
3786 ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3787 ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3788
3789 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3790 ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3791 ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3792 flush_sequence();
3793
3794 trace("Switch child window.\n");
3795 SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3796 ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3797 trace("end of test for switch maximized MDI children\n");
3798 flush_sequence();
3799
3800 /* Prepare for switching test of not maximized MDI children */
3801 ShowWindow( mdi_child, SW_NORMAL );
3802 ok(!IsZoomed(mdi_child), "wrong zoomed state for %p(Switch test)\n", mdi_child);
3803 ok(!IsZoomed(mdi_child2), "wrong zoomed state for %p(Switch test)\n", mdi_child2);
3804 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
3805 ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3806 flush_sequence();
3807
3808 SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child2, 0);
3809 ok_sequence(WmSwitchNotMaximizedChild, "Not maximized child did not switch correctly", FALSE);
3810 trace("end of test for switch not maximized MDI children\n");
3811 flush_sequence();
3812
3813 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3814 flush_sequence();
3815
3816 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3817 flush_sequence();
3818
3819 SetFocus(0);
3820 flush_sequence();
3821 /* end of tests for switch maximized/not maximized MDI children */
3822
3823 mdi_cs.szClass = "MDI_child_Class";
3824 mdi_cs.szTitle = "MDI child";
3825 mdi_cs.hOwner = GetModuleHandleA(0);
3826 mdi_cs.x = 0;
3827 mdi_cs.y = 0;
3828 mdi_cs.cx = CW_USEDEFAULT;
3829 mdi_cs.cy = CW_USEDEFAULT;
3830 mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3831 mdi_cs.lParam = 0;
3832 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3833 ok(mdi_child != 0, "MDI child creation failed\n");
3834 ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3835
3836 ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3837
3838 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3839 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3840
3841 ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3842 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3843 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3844
3845 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3846 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3847 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3848 flush_sequence();
3849
3850 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3851 ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3852
3853 ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3854 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3855 ok(!active_child, "wrong active MDI child %p\n", active_child);
3856
3857 SetFocus(0);
3858 flush_sequence();
3859
3860 DestroyWindow(mdi_client);
3861 ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3862
3863 /* test maximization of MDI child with invisible parent */
3864 client_cs.hWindowMenu = 0;
3865 mdi_client = CreateWindowA("MDI_client_class",
3866 NULL,
3867 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3868 0, 0, 660, 430,
3869 mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3870 ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3871
3872 ShowWindow(mdi_client, SW_HIDE);
3873 ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3874
3875 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3876 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3877 0, 0, 650, 440,
3878 mdi_client, 0, GetModuleHandleA(0), NULL);
3879 ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3880
3881 SendMessageA(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3882 ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3883 zoomed = IsZoomed(mdi_child);
3884 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3885
3886 ShowWindow(mdi_client, SW_SHOW);
3887 ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3888
3889 DestroyWindow(mdi_child);
3890 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3891
3892 /* end of test for maximization of MDI child with invisible parent */
3893
3894 DestroyWindow(mdi_client);
3895 ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3896
3897 DestroyWindow(mdi_frame);
3898 ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3899 }
3900 /************************* End of MDI test **********************************/
3901
3902 static void test_WM_SETREDRAW(HWND hwnd)
3903 {
3904 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3905
3906 flush_events();
3907 flush_sequence();
3908
3909 SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3910 ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3911
3912 ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3913 ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3914
3915 flush_sequence();
3916 SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3917 ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3918
3919 ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3920 ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3921
3922 /* restore original WS_VISIBLE state */
3923 SetWindowLongA(hwnd, GWL_STYLE, style);
3924
3925 flush_events();
3926 flush_sequence();
3927 }
3928
3929 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3930 {
3931 struct recvd_message msg;
3932
3933 if (ignore_message( message )) return 0;
3934
3935 switch (message)
3936 {
3937 /* ignore */
3938 case WM_MOUSEMOVE:
3939 case WM_NCMOUSEMOVE:
3940 case WM_NCMOUSELEAVE:
3941 case WM_SETCURSOR:
3942 return 0;
3943 case WM_NCHITTEST:
3944 return HTCLIENT;
3945 }
3946
3947 msg.hwnd = hwnd;
3948 msg.message = message;
3949 msg.flags = sent|wparam|lparam;
3950 msg.wParam = wParam;
3951 msg.lParam = lParam;
3952 msg.descr = "dialog";
3953 add_message(&msg);
3954
3955 if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3956 if (message == WM_TIMER) EndDialog( hwnd, 0 );
3957 return 0;
3958 }
3959
3960 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3961 {
3962 DWORD style, exstyle;
3963 INT xmin, xmax;
3964 BOOL ret;
3965
3966 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3967 style = GetWindowLongA(hwnd, GWL_STYLE);
3968 /* do not be confused by WS_DLGFRAME set */
3969 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3970
3971 if (clear) ok(style & clear, "style %08x should be set\n", clear);
3972 if (set) ok(!(style & set), "style %08x should not be set\n", set);
3973
3974 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3975 ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3976 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3977 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3978 else
3979 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3980
3981 style = GetWindowLongA(hwnd, GWL_STYLE);
3982 if (set) ok(style & set, "style %08x should be set\n", set);
3983 if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3984
3985 /* a subsequent call should do nothing */
3986 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3987 ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3988 ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3989
3990 xmin = 0xdeadbeef;
3991 xmax = 0xdeadbeef;
3992 ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
3993 ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
3994 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3995 ok(xmin == min, "unexpected min scroll value %d\n", xmin);
3996 ok(xmax == max, "unexpected max scroll value %d\n", xmax);
3997 }
3998
3999 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
4000 {
4001 DWORD style, exstyle;
4002 SCROLLINFO si;
4003 BOOL ret;
4004
4005 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
4006 style = GetWindowLongA(hwnd, GWL_STYLE);
4007 /* do not be confused by WS_DLGFRAME set */
4008 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
4009
4010 if (clear) ok(style & clear, "style %08x should be set\n", clear);
4011 if (set) ok(!(style & set), "style %08x should not be set\n", set);
4012
4013 si.cbSize = sizeof(si);
4014 si.fMask = SIF_RANGE;
4015 si.nMin = min;
4016 si.nMax = max;
4017 SetScrollInfo(hwnd, ctl, &si, TRUE);
4018 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
4019 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
4020 else
4021 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
4022
4023 style = GetWindowLongA(hwnd, GWL_STYLE);
4024 if (set) ok(style & set, "style %08x should be set\n", set);
4025 if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
4026
4027 /* a subsequent call should do nothing */
4028 SetScrollInfo(hwnd, ctl, &si, TRUE);
4029 if (style & WS_HSCROLL)
4030 ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4031 else if (style & WS_VSCROLL)
4032 ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4033 else
4034 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4035
4036 si.fMask = SIF_PAGE;
4037 si.nPage = 5;
4038 SetScrollInfo(hwnd, ctl, &si, FALSE);
4039 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4040
4041 si.fMask = SIF_POS;
4042 si.nPos = max - 1;
4043 SetScrollInfo(hwnd, ctl, &si, FALSE);
4044 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4045
4046 si.fMask = SIF_RANGE;
4047 si.nMin = 0xdeadbeef;
4048 si.nMax = 0xdeadbeef;
4049 ret = GetScrollInfo(hwnd, ctl, &si);
4050 ok( ret, "GetScrollInfo error %d\n", GetLastError());
4051 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
4052 ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
4053 ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
4054 }
4055
4056 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
4057 static void test_scroll_messages(HWND hwnd)
4058 {
4059 SCROLLINFO si;
4060 INT min, max;
4061 BOOL ret;
4062
4063 flush_events();
4064 flush_sequence();
4065
4066 min = 0xdeadbeef;
4067 max = 0xdeadbeef;
4068 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4069 ok( ret, "GetScrollRange error %d\n", GetLastError());
4070 if (sequence->message != WmGetScrollRangeSeq[0].message)
4071 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4072 /* values of min and max are undefined */
4073 flush_sequence();
4074
4075 ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
4076 ok( ret, "SetScrollRange error %d\n", GetLastError());
4077 if (sequence->message != WmSetScrollRangeSeq[0].message)
4078 trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4079 flush_sequence();
4080
4081 min = 0xdeadbeef;
4082 max = 0xdeadbeef;
4083 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4084 ok( ret, "GetScrollRange error %d\n", GetLastError());
4085 if (sequence->message != WmGetScrollRangeSeq[0].message)
4086 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4087 /* values of min and max are undefined */
4088 flush_sequence();
4089
4090 si.cbSize = sizeof(si);
4091 si.fMask = SIF_RANGE;
4092 si.nMin = 20;
4093 si.nMax = 160;
4094 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4095 if (sequence->message != WmSetScrollRangeSeq[0].message)
4096 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4097 flush_sequence();
4098
4099 si.fMask = SIF_PAGE;
4100 si.nPage = 10;
4101 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4102 if (sequence->message != WmSetScrollRangeSeq[0].message)
4103 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4104 flush_sequence();
4105
4106 si.fMask = SIF_POS;
4107 si.nPos = 20;
4108 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4109 if (sequence->message != WmSetScrollRangeSeq[0].message)
4110 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4111 flush_sequence();
4112
4113 si.fMask = SIF_RANGE;
4114 si.nMin = 0xdeadbeef;
4115 si.nMax = 0xdeadbeef;
4116 ret = GetScrollInfo(hwnd, SB_CTL, &si);
4117 ok( ret, "GetScrollInfo error %d\n", GetLastError());
4118 if (sequence->message != WmGetScrollInfoSeq[0].message)
4119 trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4120 /* values of min and max are undefined */
4121 flush_sequence();
4122
4123 /* set WS_HSCROLL */
4124 test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4125 /* clear WS_HSCROLL */
4126 test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4127
4128 /* set WS_HSCROLL */
4129 test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4130 /* clear WS_HSCROLL */
4131 test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4132
4133 /* set WS_VSCROLL */
4134 test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4135 /* clear WS_VSCROLL */
4136 test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4137
4138 /* set WS_VSCROLL */
4139 test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4140 /* clear WS_VSCROLL */
4141 test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4142 }
4143
4144 static void test_showwindow(void)
4145 {
4146 HWND hwnd, hchild;
4147 RECT rc;
4148
4149 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4150 100, 100, 200, 200, 0, 0, 0, NULL);
4151 ok (hwnd != 0, "Failed to create overlapped window\n");
4152 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4153 0, 0, 10, 10, hwnd, 0, 0, NULL);
4154 ok (hchild != 0, "Failed to create child\n");
4155 flush_sequence();
4156
4157 /* ShowWindow( SW_SHOWNA) for invisible top level window */
4158 trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
4159 ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4160 ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", FALSE);
4161
4162 /* ShowWindow( SW_SHOWNA) for now visible top level window */
4163 trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
4164 ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4165 ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
4166 /* back to invisible */
4167 ShowWindow(hchild, SW_HIDE);
4168 ShowWindow(hwnd, SW_HIDE);
4169 flush_sequence();
4170 /* ShowWindow(SW_SHOWNA) with child and parent invisible */
4171 trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
4172 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4173 ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
4174 /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */
4175 ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
4176 flush_sequence();
4177 trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
4178 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4179 ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
4180 /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
4181 ShowWindow( hwnd, SW_SHOW);
4182 flush_sequence();
4183 trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
4184 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4185 ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
4186
4187 /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
4188 ShowWindow( hchild, SW_HIDE);
4189 flush_sequence();
4190 trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
4191 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4192 ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
4193
4194 SetCapture(hchild);
4195 ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
4196 DestroyWindow(hchild);
4197 ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
4198
4199 DestroyWindow(hwnd);
4200 flush_sequence();
4201
4202 /* Popup windows */
4203 /* Test 1:
4204 * 1. Create invisible maximized popup window.
4205 * 2. Move and resize it.
4206 * 3. Show it maximized.
4207 */
4208 trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4209 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4210 100, 100, 200, 200, 0, 0, 0, NULL);
4211 ok (hwnd != 0, "Failed to create popup window\n");
4212 ok(IsZoomed(hwnd), "window should be maximized\n");
4213 ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4214
4215 GetWindowRect(hwnd, &rc);
4216 ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4217 rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4218 "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
4219 rc.left, rc.top, rc.right, rc.bottom);
4220 /* Reset window's size & position */
4221 SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
4222 ok(IsZoomed(hwnd), "window should be maximized\n");
4223 flush_sequence();
4224
4225 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4226 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4227 ok(IsZoomed(hwnd), "window should be maximized\n");
4228 ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
4229
4230 GetWindowRect(hwnd, &rc);
4231 ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4232 rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4233 "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
4234 rc.left, rc.top, rc.right, rc.bottom);
4235 DestroyWindow(hwnd);
4236 flush_sequence();
4237
4238 /* Test 2:
4239 * 1. Create invisible maximized popup window.
4240 * 2. Show it maximized.
4241 */
4242 trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4243 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4244 100, 100, 200, 200, 0, 0, 0, NULL);
4245 ok (hwnd != 0, "Failed to create popup window\n");
4246 ok(IsZoomed(hwnd), "window should be maximized\n");
4247 ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4248
4249 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4250 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4251 ok(IsZoomed(hwnd), "window should be maximized\n");
4252 ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
4253 DestroyWindow(hwnd);
4254 flush_sequence();
4255
4256 /* Test 3:
4257 * 1. Create visible maximized popup window.
4258 */
4259 trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
4260 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4261 100, 100, 200, 200, 0, 0, 0, NULL);
4262 ok (hwnd != 0, "Failed to create popup window\n");
4263 ok(IsZoomed(hwnd), "window should be maximized\n");
4264 ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4265 DestroyWindow(hwnd);
4266 flush_sequence();
4267
4268 /* Test 4:
4269 * 1. Create visible popup window.
4270 * 2. Maximize it.
4271 */
4272 trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
4273 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_VISIBLE,
4274 100, 100, 200, 200, 0, 0, 0, NULL);
4275 ok (hwnd != 0, "Failed to create popup window\n");
4276 ok(!IsZoomed(hwnd), "window should NOT be maximized\n");
4277 ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
4278
4279 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
4280 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4281 ok(IsZoomed(hwnd), "window should be maximized\n");
4282 ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
4283 DestroyWindow(hwnd);
4284 flush_sequence();
4285 }
4286
4287 static void test_sys_menu(void)
4288 {
4289 HWND hwnd;
4290 HMENU hmenu;
4291 UINT state;
4292
4293 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4294 100, 100, 200, 200, 0, 0, 0, NULL);
4295 ok (hwnd != 0, "Failed to create overlapped window\n");
4296
4297 flush_sequence();
4298
4299 /* test existing window without CS_NOCLOSE style */
4300 hmenu = GetSystemMenu(hwnd, FALSE);
4301 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4302
4303 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4304 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4305 ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4306
4307 EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
4308 ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4309
4310 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4311 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4312 ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
4313
4314 EnableMenuItem(hmenu, SC_CLOSE, 0);
4315 ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4316
4317 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4318 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4319 ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4320
4321 /* test whether removing WS_SYSMENU destroys a system menu */
4322 SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
4323 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4324 flush_sequence();
4325 hmenu = GetSystemMenu(hwnd, FALSE);
4326 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4327
4328 DestroyWindow(hwnd);
4329
4330 /* test new window with CS_NOCLOSE style */
4331 hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4332 100, 100, 200, 200, 0, 0, 0, NULL);
4333 ok (hwnd != 0, "Failed to create overlapped window\n");
4334
4335 hmenu = GetSystemMenu(hwnd, FALSE);
4336 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4337
4338 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4339 ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4340
4341 DestroyWindow(hwnd);
4342
4343 /* test new window without WS_SYSMENU style */
4344 hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
4345 100, 100, 200, 200, 0, 0, 0, NULL);
4346 ok(hwnd != 0, "Failed to create overlapped window\n");
4347
4348 hmenu = GetSystemMenu(hwnd, FALSE);
4349 ok(!hmenu, "GetSystemMenu error %d\n", GetLastError());
4350
4351 DestroyWindow(hwnd);
4352 }
4353
4354 /* For shown WS_OVERLAPPEDWINDOW */
4355 static const struct message WmSetIcon_1[] = {
4356 { WM_SETICON, sent },
4357 { 0x00AE, sent|defwinproc|optional }, /* XP */
4358 { WM_GETTEXT, sent|defwinproc|optional },
4359 { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
4360 { 0 }
4361 };
4362
4363 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
4364 static const struct message WmSetIcon_2[] = {
4365 { WM_SETICON, sent },
4366 { 0 }
4367 };
4368
4369 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4370 static const struct message WmInitEndSession[] = {
4371 { 0x003B, sent },
4372 { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4373 { 0 }
4374 };
4375
4376 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4377 static const struct message WmInitEndSession_2[] = {
4378 { 0x003B, sent },
4379 { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4380 { 0 }
4381 };
4382
4383 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4384 static const struct message WmInitEndSession_3[] = {
4385 { 0x003B, sent },
4386 { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4387 { 0 }
4388 };
4389
4390 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4391 static const struct message WmInitEndSession_4[] = {
4392 { 0x003B, sent },
4393 { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4394 { 0 }
4395 };
4396
4397 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4398 static const struct message WmInitEndSession_5[] = {
4399 { 0x003B, sent },
4400 { WM_ENDSESSION, sent|defwinproc/*|wparam*/|lparam, 1, ENDSESSION_LOGOFF },
4401 { 0 }
4402 };
4403
4404 static const struct message WmOptionalPaint[] = {
4405 { WM_PAINT, sent|optional },
4406 { WM_NCPAINT, sent|beginpaint|optional },
4407 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4408 { WM_ERASEBKGND, sent|beginpaint|optional },
4409 { 0 }
4410 };
4411
4412 static const struct message WmZOrder[] = {
4413 { WM_WINDOWPOSCHANGING, sent|wparam, 0, 0 },
4414 { WM_GETMINMAXINFO, sent|defwinproc|wparam, 0, 0 },
4415 { HCBT_ACTIVATE, hook },
4416 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
4417 { WM_WINDOWPOSCHANGING, sent|wparam, 3, 0 },
4418 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0 },
4419 { WM_GETTEXT, sent|optional },
4420 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
4421 { WM_ACTIVATEAPP, sent|wparam, 1, 0 },
4422 { WM_NCACTIVATE, sent|lparam, 1, 0 },
4423 { WM_GETTEXT, sent|defwinproc|optional },
4424 { WM_GETTEXT, sent|defwinproc|optional },
4425 { WM_ACTIVATE, sent|wparam|lparam, 1, 0 },
4426 { HCBT_SETFOCUS, hook },
4427 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4428 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4429 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4430 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
4431 { WM_GETTEXT, sent|optional },
4432 { WM_NCCALCSIZE, sent|optional },
4433 { 0 }
4434 };
4435
4436 static void CALLBACK apc_test_proc(ULONG_PTR param)
4437 {
4438 /* nothing */
4439 }
4440
4441 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4442 {
4443 DWORD ret;
4444 MSG msg;
4445
4446 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4447 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4448
4449 PostMessageA(hwnd, WM_USER, 0, 0);
4450
4451 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4452 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4453
4454 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4455 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
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_NOREMOVE ), "PeekMessage should succeed\n");
4466 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4467
4468 /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4469 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4470 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4471
4472 PostMessageA(hwnd, WM_USER, 0, 0);
4473
4474 /* new incoming message causes it to become signaled again */
4475 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4476 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4477
4478 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4479 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4480 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4481 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4482
4483 /* MWMO_INPUTAVAILABLE should succeed even if the message was already seen */
4484 PostMessageA( hwnd, WM_USER, 0, 0 );
4485 ok(PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4486 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4487
4488 ret = MsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_POSTMESSAGE, MWMO_INPUTAVAILABLE );
4489 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjectsEx returned %x\n", ret);
4490
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 /* without MWMO_ALERTABLE the result is never WAIT_IO_COMPLETION */
4495 ret = QueueUserAPC( apc_test_proc, GetCurrentThread(), 0 );
4496 ok(ret, "QueueUserAPC failed %u\n", GetLastError());
4497
4498 ret = MsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_POSTMESSAGE, 0 );
4499 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjectsEx returned %x\n", ret);
4500
4501 /* but even with MWMO_ALERTABLE window events are preferred */
4502 PostMessageA( hwnd, WM_USER, 0, 0 );
4503
4504 ret = MsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_POSTMESSAGE, MWMO_ALERTABLE );
4505 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjectsEx returned %x\n", ret);
4506
4507 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4508 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4509
4510 /* the APC call is still queued */
4511 ret = MsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_POSTMESSAGE, MWMO_ALERTABLE );
4512 ok(ret == WAIT_IO_COMPLETION, "MsgWaitForMultipleObjectsEx returned %x\n", ret);
4513 }
4514
4515 static DWORD CALLBACK show_window_thread(LPVOID arg)
4516 {
4517 HWND hwnd = arg;
4518
4519 /* function will not return if ShowWindow(SW_HIDE) calls SendMessage() */
4520 ok(ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow(SW_HIDE) expected FALSE\n");
4521
4522 return 0;
4523 }
4524
4525 /* test if we receive the right sequence of messages */
4526 static void test_messages(void)
4527 {
4528 DWORD tid;
4529 HANDLE hthread;
4530 HWND hwnd, hparent, hchild;
4531 HWND hchild2, hbutton;
4532 HMENU hmenu;
4533 MSG msg;
4534 LRESULT res;
4535 POINT pos;
4536 BOOL ret;
4537
4538 flush_sequence();
4539
4540 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4541 100, 100, 200, 200, 0, 0, 0, NULL);
4542 ok (hwnd != 0, "Failed to create overlapped window\n");
4543 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4544
4545 /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4546 ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4547 ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4548
4549 /* test WM_SETREDRAW on a not visible top level window */
4550 test_WM_SETREDRAW(hwnd);
4551
4552 SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4553 flush_events();
4554 ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4555 ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4556
4557 ok(GetActiveWindow() == hwnd, "window should be active\n");
4558 ok(GetFocus() == hwnd, "window should have input focus\n");
4559 ShowWindow(hwnd, SW_HIDE);
4560 flush_events();
4561 ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4562
4563 /* test ShowWindow(SW_HIDE) on a hidden window - single threaded */
4564 ok(ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow(SW_HIDE) expected FALSE\n");
4565 flush_events();
4566 ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4567
4568 /* test ShowWindow(SW_HIDE) on a hidden window - multi-threaded */
4569 hthread = CreateThread(NULL, 0, show_window_thread, hwnd, 0, &tid);
4570 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
4571 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
4572 CloseHandle(hthread);
4573 flush_events();
4574 ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4575
4576 ShowWindow(hwnd, SW_SHOW);
4577 flush_events();
4578 ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4579
4580 ShowWindow(hwnd, SW_HIDE);
4581 flush_events();
4582 ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4583
4584 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4585 flush_events();
4586 ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4587 flush_sequence();
4588
4589 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MAXIMIZE)
4590 {
4591 ShowWindow(hwnd, SW_RESTORE);
4592 flush_events();
4593 ok_sequence(WmShowRestoreMaxOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4594 flush_sequence();
4595 }
4596
4597 ShowWindow(hwnd, SW_MINIMIZE);
4598 flush_events();
4599 ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4600 flush_sequence();
4601
4602 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MINIMIZE)
4603 {
4604 ShowWindow(hwnd, SW_RESTORE);
4605 flush_events();
4606 ok_sequence(WmShowRestoreMinOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4607 flush_sequence();
4608 }
4609
4610 ShowWindow(hwnd, SW_SHOW);
4611 flush_events();
4612 ok_sequence(WmOptionalPaint, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4613
4614 SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4615 ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4616 ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4617 ok(GetActiveWindow() == hwnd, "window should still be active\n");
4618
4619 /* test WM_SETREDRAW on a visible top level window */
4620 ShowWindow(hwnd, SW_SHOW);
4621 flush_events();
4622 test_WM_SETREDRAW(hwnd);
4623
4624 trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4625 test_scroll_messages(hwnd);
4626
4627 /* test resizing and moving */
4628 SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4629 ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4630 flush_events();
4631 flush_sequence();
4632 SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4633 ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4634 flush_events();
4635 flush_sequence();
4636 SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER|SWP_NOACTIVATE );
4637 ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4638 flush_events();
4639 flush_sequence();
4640
4641 /* popups don't get WM_GETMINMAXINFO */
4642 SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4643 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4644 flush_sequence();
4645 SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4646 ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4647
4648 DestroyWindow(hwnd);
4649 ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4650
4651 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4652 100, 100, 200, 200, 0, 0, 0, NULL);
4653 ok (hparent != 0, "Failed to create parent window\n");
4654 flush_sequence();
4655
4656 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4657 0, 0, 10, 10, hparent, 0, 0, NULL);
4658 ok (hchild != 0, "Failed to create child window\n");
4659 ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4660 DestroyWindow(hchild);
4661 flush_sequence();
4662
4663 /* visible child window with a caption */
4664 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4665 WS_CHILD | WS_VISIBLE | WS_CAPTION,
4666 0, 0, 10, 10, hparent, 0, 0, NULL);
4667 ok (hchild != 0, "Failed to create child window\n");
4668 ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4669
4670 trace("testing scroll APIs on a visible child window %p\n", hchild);
4671 test_scroll_messages(hchild);
4672
4673 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4674 ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4675
4676 DestroyWindow(hchild);
4677 flush_sequence();
4678
4679 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4680 0, 0, 10, 10, hparent, 0, 0, NULL);
4681 ok (hchild != 0, "Failed to create child window\n");
4682 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4683
4684 hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4685 100, 100, 50, 50, hparent, 0, 0, NULL);
4686 ok (hchild2 != 0, "Failed to create child2 window\n");
4687 flush_sequence();
4688
4689 hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4690 0, 100, 50, 50, hchild, 0, 0, NULL);
4691 ok (hbutton != 0, "Failed to create button window\n");
4692
4693 /* test WM_SETREDRAW on a not visible child window */
4694 test_WM_SETREDRAW(hchild);
4695
4696 ShowWindow(hchild, SW_SHOW);
4697 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4698
4699 /* check parent messages too */
4700 log_all_parent_messages++;
4701 ShowWindow(hchild, SW_HIDE);
4702 ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4703 log_all_parent_messages--;
4704
4705 ShowWindow(hchild, SW_SHOW);
4706 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4707
4708 ShowWindow(hchild, SW_HIDE);
4709 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4710
4711 ShowWindow(hchild, SW_SHOW);
4712 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4713
4714 /* test WM_SETREDRAW on a visible child window */
4715 test_WM_SETREDRAW(hchild);
4716
4717 log_all_parent_messages++;
4718 MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4719 ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4720 log_all_parent_messages--;
4721
4722 ShowWindow(hchild, SW_HIDE);
4723 flush_sequence();
4724 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4725 ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4726
4727 ShowWindow(hchild, SW_HIDE);
4728 flush_sequence();
4729 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4730 ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4731
4732 /* DestroyWindow sequence below expects that a child has focus */
4733 SetFocus(hchild);
4734 flush_sequence();
4735
4736 DestroyWindow(hchild);
4737 ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4738 DestroyWindow(hchild2);
4739 DestroyWindow(hbutton);
4740
4741 flush_sequence();
4742 hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4743 0, 0, 100, 100, hparent, 0, 0, NULL);
4744 ok (hchild != 0, "Failed to create child popup window\n");
4745 ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4746 DestroyWindow(hchild);
4747
4748 /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4749 flush_sequence();
4750 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4751 0, 0, 100, 100, hparent, 0, 0, NULL);
4752 ok (hchild != 0, "Failed to create popup window\n");
4753 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4754 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4755 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4756 flush_sequence();
4757 ShowWindow(hchild, SW_SHOW);
4758 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4759 flush_sequence();
4760 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4761 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4762 flush_sequence();
4763 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4764 ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
4765 DestroyWindow(hchild);
4766
4767 /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4768 * changes nothing in message sequences.
4769 */
4770 flush_sequence();
4771 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4772 0, 0, 100, 100, hparent, 0, 0, NULL);
4773 ok (hchild != 0, "Failed to create popup window\n");
4774 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4775 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4776 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4777 flush_sequence();
4778 ShowWindow(hchild, SW_SHOW);
4779 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4780 flush_sequence();
4781 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4782 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4783 DestroyWindow(hchild);
4784
4785 flush_sequence();
4786 hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4787 0, 0, 100, 100, hparent, 0, 0, NULL);
4788 ok(hwnd != 0, "Failed to create custom dialog window\n");
4789 ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4790
4791 if(0) {
4792 trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4793 test_scroll_messages(hwnd);
4794 }
4795
4796 flush_sequence();
4797
4798 test_def_id = TRUE;
4799 SendMessageA(hwnd, WM_NULL, 0, 0);
4800
4801 flush_sequence();
4802 after_end_dialog = TRUE;
4803 EndDialog( hwnd, 0 );
4804 ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4805
4806 DestroyWindow(hwnd);
4807 after_end_dialog = FALSE;
4808 test_def_id = FALSE;
4809
4810 ok(GetCursorPos(&pos), "GetCursorPos failed\n");
4811 ok(SetCursorPos(109, 109), "SetCursorPos failed\n");
4812
4813 hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP|WS_CHILD,
4814 0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4815 ok(hwnd != 0, "Failed to create custom dialog window\n");
4816 flush_sequence();
4817 trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4818 ShowWindow(hwnd, SW_SHOW);
4819 ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4820
4821 flush_events();
4822 flush_sequence();
4823 ret = DrawMenuBar(hwnd);
4824 ok(ret, "DrawMenuBar failed: %d\n", GetLastError());
4825 flush_events();
4826 ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4827 ok(SetCursorPos(pos.x, pos.y), "SetCursorPos failed\n");
4828
4829 DestroyWindow(hwnd);
4830
4831 hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_CHILD|WS_VISIBLE,
4832 0, 0, 100, 100, hparent, 0, GetModuleHandleA(0), NULL);
4833 ok(hwnd != 0, "Failed to create custom dialog window\n");
4834 flush_events();
4835 flush_sequence();
4836 ret = DrawMenuBar(hwnd);
4837 ok(ret, "DrawMenuBar failed: %d\n", GetLastError());
4838 flush_events();
4839 ok_sequence(WmEmptySeq, "DrawMenuBar for a child window", FALSE);
4840
4841 DestroyWindow(hwnd);
4842
4843 flush_sequence();
4844 DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4845 ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4846
4847 DestroyWindow(hparent);
4848 flush_sequence();
4849
4850 /* Message sequence for SetMenu */
4851 ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a destroyed window\n");
4852 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "last error is %d\n", GetLastError());
4853 ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4854
4855 hmenu = CreateMenu();
4856 ok (hmenu != 0, "Failed to create menu\n");
4857 ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4858 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4859 100, 100, 200, 200, 0, hmenu, 0, NULL);
4860 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4861 ok (SetMenu(hwnd, 0), "SetMenu\n");
4862 ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4863 ok (SetMenu(hwnd, 0), "SetMenu\n");
4864 ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4865 ShowWindow(hwnd, SW_SHOW);
4866 UpdateWindow( hwnd );
4867 flush_events();
4868 flush_sequence();
4869 ok (SetMenu(hwnd, 0), "SetMenu\n");
4870 ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4871 ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4872 ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4873
4874 UpdateWindow( hwnd );
4875 flush_events();
4876 flush_sequence();
4877 ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4878 flush_events();
4879 ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4880
4881 DestroyWindow(hwnd);
4882 flush_sequence();
4883
4884 /* Message sequence for EnableWindow */
4885 hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4886 100, 100, 200, 200, 0, 0, 0, NULL);
4887 ok (hparent != 0, "Failed to create parent window\n");
4888 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4889 0, 0, 10, 10, hparent, 0, 0, NULL);
4890 ok (hchild != 0, "Failed to create child window\n");
4891
4892 SetFocus(hchild);
4893 flush_events();
4894 flush_sequence();
4895
4896 EnableWindow(hparent, FALSE);
4897 ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4898
4899 EnableWindow(hparent, TRUE);
4900 ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4901
4902 flush_events();
4903 flush_sequence();
4904
4905 test_MsgWaitForMultipleObjects(hparent);
4906
4907 /* the following test causes an exception in user.exe under win9x */
4908 if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4909 {
4910 DestroyWindow(hparent);
4911 flush_sequence();
4912 return;
4913 }
4914 PostMessageW( hparent, WM_USER+1, 0, 0 );
4915 /* PeekMessage(NULL) fails, but still removes the message */
4916 SetLastError(0xdeadbeef);
4917 ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4918 ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4919 GetLastError() == 0xdeadbeef, /* NT4 */
4920 "last error is %d\n", GetLastError() );
4921 ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4922 ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4923
4924 DestroyWindow(hchild);
4925 DestroyWindow(hparent);
4926 flush_sequence();
4927
4928 /* Message sequences for WM_SETICON */
4929 trace("testing WM_SETICON\n");
4930 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4931 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4932 NULL, NULL, 0);
4933 ShowWindow(hwnd, SW_SHOW);
4934 UpdateWindow(hwnd);
4935 flush_events();
4936 flush_sequence();
4937 SendMessageA(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIconA(0, (LPCSTR)IDI_APPLICATION));
4938 ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4939
4940 ShowWindow(hwnd, SW_HIDE);
4941 flush_events();
4942 flush_sequence();
4943 SendMessageA(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIconA(0, (LPCSTR)IDI_APPLICATION));
4944 ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4945 DestroyWindow(hwnd);
4946 flush_sequence();
4947
4948 hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4949 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4950 NULL, NULL, 0);
4951 ShowWindow(hwnd, SW_SHOW);
4952 UpdateWindow(hwnd);
4953 flush_events();
4954 flush_sequence();
4955 SendMessageA(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIconA(0, (LPCSTR)IDI_APPLICATION));
4956 ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4957
4958 ShowWindow(hwnd, SW_HIDE);
4959 flush_events();
4960 flush_sequence();
4961 SendMessageA(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIconA(0, (LPCSTR)IDI_APPLICATION));
4962 ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4963
4964 flush_sequence();
4965 res = SendMessageA(hwnd, 0x3B, 0x8000000b, 0);
4966 if (!res)
4967 {
4968 todo_wine win_skip( "Message 0x3b not supported\n" );
4969 goto done;
4970 }
4971 ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4972 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4973 res = SendMessageA(hwnd, 0x3B, 0x0000000b, 0);
4974 ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4975 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4976 res = SendMessageA(hwnd, 0x3B, 0x0000000f, 0);
4977 ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4978 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4979
4980 flush_sequence();
4981 res = SendMessageA(hwnd, 0x3B, 0x80000008, 0);
4982 ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4983 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4984 res = SendMessageA(hwnd, 0x3B, 0x00000008, 0);
4985 ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4986 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4987
4988 res = SendMessageA(hwnd, 0x3B, 0x80000004, 0);
4989 ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4990 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4991
4992 res = SendMessageA(hwnd, 0x3B, 0x80000001, 0);
4993 ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4994 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4995
4996 done:
4997 DestroyWindow(hwnd);
4998 flush_sequence();
4999 }
5000
5001 static void test_setwindowpos(void)
5002 {
5003 HWND hwnd;
5004 RECT rc;
5005 LRESULT res;
5006 const INT winX = 100;
5007 const INT winY = 100;
5008 const INT sysX = GetSystemMetrics(SM_CXMINTRACK);
5009
5010 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
5011 0, 0, winX, winY, 0,
5012 NULL, NULL, 0);
5013
5014 GetWindowRect(hwnd, &rc);
5015 expect(sysX, rc.right);
5016 expect(winY, rc.bottom);
5017
5018 flush_events();
5019 flush_sequence();
5020 res = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, winX, winY, 0);
5021 ok_sequence(WmZOrder, "Z-Order", TRUE);
5022 ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
5023
5024 GetWindowRect(hwnd, &rc);
5025 expect(sysX, rc.right);
5026 expect(winY, rc.bottom);
5027 DestroyWindow(hwnd);
5028 }
5029
5030 static void invisible_parent_tests(void)
5031 {
5032 HWND hparent, hchild;
5033
5034 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
5035 100, 100, 200, 200, 0, 0, 0, NULL);
5036 ok (hparent != 0, "Failed to create parent window\n");
5037 flush_sequence();
5038
5039 /* test showing child with hidden parent */
5040
5041 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5042 0, 0, 10, 10, hparent, 0, 0, NULL);
5043 ok (hchild != 0, "Failed to create child window\n");
5044 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
5045
5046 ShowWindow( hchild, SW_MINIMIZE );
5047 ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
5048 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5049 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5050
5051 /* repeat */
5052 flush_events();
5053 flush_sequence();
5054 ShowWindow( hchild, SW_MINIMIZE );
5055 ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
5056
5057 DestroyWindow(hchild);
5058 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5059 0, 0, 10, 10, hparent, 0, 0, NULL);
5060 flush_sequence();
5061
5062 ShowWindow( hchild, SW_MAXIMIZE );
5063 ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
5064 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5065 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5066
5067 /* repeat */
5068 flush_events();
5069 flush_sequence();
5070 ShowWindow( hchild, SW_MAXIMIZE );
5071 ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
5072
5073 DestroyWindow(hchild);
5074 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5075 0, 0, 10, 10, hparent, 0, 0, NULL);
5076 flush_sequence();
5077
5078 ShowWindow( hchild, SW_RESTORE );
5079 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
5080 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5081 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
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_SHOWMINIMIZED );
5089 ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) 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_SHOWMINIMIZED );
5097 ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
5098
5099 DestroyWindow(hchild);
5100 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5101 0, 0, 10, 10, hparent, 0, 0, NULL);
5102 flush_sequence();
5103
5104 /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
5105 ShowWindow( hchild, SW_SHOWMAXIMIZED );
5106 ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
5107 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5108 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5109
5110 DestroyWindow(hchild);
5111 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5112 0, 0, 10, 10, hparent, 0, 0, NULL);
5113 flush_sequence();
5114
5115 ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5116 ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5117 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5118 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5119
5120 /* repeat */
5121 flush_events();
5122 flush_sequence();
5123 ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5124 ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5125
5126 DestroyWindow(hchild);
5127 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5128 0, 0, 10, 10, hparent, 0, 0, NULL);
5129 flush_sequence();
5130
5131 /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
5132 ShowWindow( hchild, SW_FORCEMINIMIZE );
5133 ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
5134 todo_wine {
5135 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5136 }
5137 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5138
5139 DestroyWindow(hchild);
5140 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5141 0, 0, 10, 10, hparent, 0, 0, NULL);
5142 flush_sequence();
5143
5144 ShowWindow( hchild, SW_SHOWNA );
5145 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5146 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5147 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5148
5149 /* repeat */
5150 flush_events();
5151 flush_sequence();
5152 ShowWindow( hchild, SW_SHOWNA );
5153 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5154
5155 DestroyWindow(hchild);
5156 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5157 0, 0, 10, 10, hparent, 0, 0, NULL);
5158 flush_sequence();
5159
5160 ShowWindow( hchild, SW_SHOW );
5161 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5162 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5163 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5164
5165 /* repeat */
5166 flush_events();
5167 flush_sequence();
5168 ShowWindow( hchild, SW_SHOW );
5169 ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5170
5171 ShowWindow( hchild, SW_HIDE );
5172 ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
5173 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5174 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5175
5176 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5177 ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
5178 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5179 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5180
5181 SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5182 ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
5183 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
5184 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5185
5186 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5187 flush_sequence();
5188 DestroyWindow(hchild);
5189 ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
5190
5191 DestroyWindow(hparent);
5192 flush_sequence();
5193 }
5194
5195 /****************** button message test *************************/
5196 #define ID_BUTTON 0x000e
5197
5198 static const struct message WmSetFocusButtonSeq[] =
5199 {
5200 { HCBT_SETFOCUS, hook },
5201 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5202 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5203 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5204 { WM_SETFOCUS, sent|wparam, 0 },
5205 { WM_CTLCOLORBTN, sent|parent },
5206 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5207 { WM_APP, sent|wparam|lparam, 0, 0 },
5208 { 0 }
5209 };
5210 static const struct message WmKillFocusButtonSeq[] =
5211 {
5212 { HCBT_SETFOCUS, hook },
5213 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5214 { WM_KILLFOCUS, sent|wparam, 0 },
5215 { WM_CTLCOLORBTN, sent|parent },
5216 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5217 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5218 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5219 { WM_APP, sent|wparam|lparam, 0, 0 },
5220 { WM_PAINT, sent },
5221 { WM_CTLCOLORBTN, sent|parent },
5222 { 0 }
5223 };
5224 static const struct message WmSetFocusStaticSeq[] =
5225 {
5226 { HCBT_SETFOCUS, hook },
5227 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5228 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5229 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5230 { WM_SETFOCUS, sent|wparam, 0 },
5231 { WM_CTLCOLORSTATIC, sent|parent },
5232 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5233 { WM_COMMAND, sent|wparam|parent|optional, MAKEWPARAM(ID_BUTTON, BN_CLICKED) }, /* radio button */
5234 { WM_APP, sent|wparam|lparam, 0, 0 },
5235 { 0 }
5236 };
5237 static const struct message WmKillFocusStaticSeq[] =
5238 {
5239 { HCBT_SETFOCUS, hook },
5240 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5241 { WM_KILLFOCUS, sent|wparam, 0 },
5242 { WM_CTLCOLORSTATIC, sent|parent },
5243 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5244 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5245 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5246 { WM_APP, sent|wparam|lparam, 0, 0 },
5247 { WM_PAINT, sent },
5248 { WM_CTLCOLORSTATIC, sent|parent },
5249 { 0 }
5250 };
5251 static const struct message WmSetFocusOwnerdrawSeq[] =
5252 {
5253 { HCBT_SETFOCUS, hook },
5254 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5255 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5256 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5257 { WM_SETFOCUS, sent|wparam, 0 },
5258 { WM_CTLCOLORBTN, sent|parent },
5259 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x001040e4 },
5260 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5261 { WM_APP, sent|wparam|lparam, 0, 0 },
5262 { 0 }
5263 };
5264 static const struct message WmKillFocusOwnerdrawSeq[] =
5265 {
5266 { HCBT_SETFOCUS, hook },
5267 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5268 { WM_KILLFOCUS, sent|wparam, 0 },
5269 { WM_CTLCOLORBTN, sent|parent },
5270 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000040e4 },
5271 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5272 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5273 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5274 { WM_APP, sent|wparam|lparam, 0, 0 },
5275 { WM_PAINT, sent },
5276 { WM_CTLCOLORBTN, sent|parent },
5277 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 },
5278 { 0 }
5279 };
5280 static const struct message WmLButtonDownSeq[] =
5281 {
5282 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
5283 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5284 { HCBT_SETFOCUS, hook },
5285 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
5286 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5287 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5288 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
5289 { WM_CTLCOLORBTN, sent|defwinproc },
5290 { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
5291 { WM_CTLCOLORBTN, sent|defwinproc },
5292 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5293 { 0 }
5294 };
5295 static const struct message WmLButtonUpSeq[] =
5296 {
5297 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
5298 { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
5299 { WM_CTLCOLORBTN, sent|defwinproc },
5300 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5301 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5302 { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
5303 { 0 }
5304 };
5305 static const struct message WmSetFontButtonSeq[] =
5306 {
5307 { WM_SETFONT, sent },
5308 { WM_PAINT, sent },
5309 { WM_ERASEBKGND, sent|defwinproc|optional },
5310 { WM_CTLCOLORBTN, sent|defwinproc },
5311 { 0 }
5312 };
5313 static const struct message WmSetStyleButtonSeq[] =
5314 {
5315 { BM_SETSTYLE, sent },
5316 { WM_APP, sent|wparam|lparam, 0, 0 },
5317 { WM_PAINT, sent },
5318 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5319 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5320 { WM_CTLCOLORBTN, sent|parent },
5321 { 0 }
5322 };
5323 static const struct message WmSetStyleStaticSeq[] =
5324 {
5325 { BM_SETSTYLE, sent },
5326 { WM_APP, sent|wparam|lparam, 0, 0 },
5327 { WM_PAINT, sent },
5328 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5329 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5330 { WM_CTLCOLORSTATIC, sent|parent },
5331 { 0 }
5332 };
5333 static const struct message WmSetStyleUserSeq[] =
5334 {
5335 { BM_SETSTYLE, sent },
5336 { WM_APP, sent|wparam|lparam, 0, 0 },
5337 { WM_PAINT, sent },
5338 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5339 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5340 { WM_CTLCOLORBTN, sent|parent },
5341 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_PAINT) },
5342 { 0 }
5343 };
5344 static const struct message WmSetStyleOwnerdrawSeq[] =
5345 {
5346 { BM_SETSTYLE, sent },
5347 { WM_APP, sent|wparam|lparam, 0, 0 },
5348 { WM_PAINT, sent },
5349 { WM_NCPAINT, sent|optional }, /* FIXME: Wine sends it */
5350 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5351 { WM_CTLCOLORBTN, sent|parent },
5352 { WM_CTLCOLORBTN, sent|parent|optional }, /* Win9x doesn't send it */
5353 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 },
5354 { 0 }
5355 };
5356 static const struct message WmSetStateButtonSeq[] =
5357 {
5358 { BM_SETSTATE, sent },
5359 { WM_CTLCOLORBTN, sent|parent },
5360 { WM_APP, sent|wparam|lparam, 0, 0 },
5361 { 0 }
5362 };
5363 static const struct message WmSetStateStaticSeq[] =
5364 {
5365 { BM_SETSTATE, sent },
5366 { WM_CTLCOLORSTATIC, sent|parent },
5367 { WM_APP, sent|wparam|lparam, 0, 0 },
5368 { 0 }
5369 };
5370 static const struct message WmSetStateUserSeq[] =
5371 {
5372 { BM_SETSTATE, sent },
5373 { WM_CTLCOLORBTN, sent|parent },
5374 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_HILITE) },
5375 { WM_APP, sent|wparam|lparam, 0, 0 },
5376 { 0 }
5377 };
5378 static const struct message WmSetStateOwnerdrawSeq[] =
5379 {
5380 { BM_SETSTATE, sent },
5381 { WM_CTLCOLORBTN, sent|parent },
5382 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000120e4 },
5383 { WM_APP, sent|wparam|lparam, 0, 0 },
5384 { 0 }
5385 };
5386 static const struct message WmClearStateButtonSeq[] =
5387 {
5388 { BM_SETSTATE, sent },
5389 { WM_CTLCOLORBTN, sent|parent },
5390 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_UNHILITE) },
5391 { WM_APP, sent|wparam|lparam, 0, 0 },
5392 { 0 }
5393 };
5394 static const struct message WmClearStateOwnerdrawSeq[] =
5395 {
5396 { BM_SETSTATE, sent },
5397 { WM_CTLCOLORBTN, sent|parent },
5398 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000020e4 },
5399 { WM_APP, sent|wparam|lparam, 0, 0 },
5400 { 0 }
5401 };
5402 static const struct message WmSetCheckIgnoredSeq[] =
5403 {
5404 { BM_SETCHECK, sent },
5405 { WM_APP, sent|wparam|lparam, 0, 0 },
5406 { 0 }
5407 };
5408 static const struct message WmSetCheckStaticSeq[] =
5409 {
5410 { BM_SETCHECK, sent },
5411 { WM_CTLCOLORSTATIC, sent|parent },
5412 { WM_APP, sent|wparam|lparam, 0, 0 },
5413 { 0 }
5414 };
5415
5416 static WNDPROC old_button_proc;
5417
5418 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5419 {
5420 static LONG defwndproc_counter = 0;
5421 LRESULT ret;
5422 struct recvd_message msg;
5423
5424 if (ignore_message( message )) return 0;
5425
5426 switch (message)
5427 {
5428 case WM_SYNCPAINT:
5429 break;
5430 case BM_SETSTATE:
5431 if (GetCapture())
5432 ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
5433 /* fall through */
5434 default:
5435 msg.hwnd = hwnd;
5436 msg.message = message;
5437 msg.flags = sent|wparam|lparam;
5438 if (defwndproc_counter) msg.flags |= defwinproc;
5439 msg.wParam = wParam;
5440 msg.lParam = lParam;
5441 msg.descr = "button";
5442 add_message(&msg);
5443 }
5444
5445 defwndproc_counter++;
5446 ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
5447 defwndproc_counter--;
5448
5449 return ret;
5450 }
5451
5452 static void subclass_button(void)
5453 {
5454 WNDCLASSA cls;
5455
5456 if (!GetClassInfoA(0, "button", &cls)) assert(0);
5457
5458 old_button_proc = cls.lpfnWndProc;
5459
5460 cls.hInstance = GetModuleHandleA(NULL);
5461 cls.lpfnWndProc = button_hook_proc;
5462 cls.lpszClassName = "my_button_class";
5463 UnregisterClassA(cls.lpszClassName, cls.hInstance);
5464 if (!RegisterClassA(&cls)) assert(0);
5465 }
5466
5467 static void test_button_messages(void)
5468 {
5469 static const struct
5470 {
5471 DWORD style;
5472 DWORD dlg_code;
5473 const struct message *setfocus;
5474 const struct message *killfocus;
5475 const struct message *setstyle;
5476 const struct message *setstate;
5477 const struct message *clearstate;
5478 const struct message *setcheck;
5479 } button[] = {
5480 { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5481 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq,
5482 WmSetStateButtonSeq, WmSetStateButtonSeq, WmSetCheckIgnoredSeq },
5483 { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
5484 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq,
5485 WmSetStateButtonSeq, WmSetStateButtonSeq, WmSetCheckIgnoredSeq },
5486 { BS_CHECKBOX, DLGC_BUTTON,
5487 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5488 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5489 { BS_AUTOCHECKBOX, DLGC_BUTTON,
5490 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5491 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5492 { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5493 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5494 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5495 { BS_3STATE, DLGC_BUTTON,
5496 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5497 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5498 { BS_AUTO3STATE, DLGC_BUTTON,
5499 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5500 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5501 { BS_GROUPBOX, DLGC_STATIC,
5502 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5503 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckIgnoredSeq },
5504 { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5505 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleUserSeq,
5506 WmSetStateUserSeq, WmClearStateButtonSeq, WmSetCheckIgnoredSeq },
5507 { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5508 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq,
5509 WmSetStateStaticSeq, WmSetStateStaticSeq, WmSetCheckStaticSeq },
5510 { BS_OWNERDRAW, DLGC_BUTTON,
5511 WmSetFocusOwnerdrawSeq, WmKillFocusOwnerdrawSeq, WmSetStyleOwnerdrawSeq,
5512 WmSetStateOwnerdrawSeq, WmClearStateOwnerdrawSeq, WmSetCheckIgnoredSeq },
5513 };
5514 unsigned int i;
5515 HWND hwnd, parent;
5516 DWORD dlg_code;
5517 HFONT zfont;
5518
5519 /* selection with VK_SPACE should capture button window */
5520 hwnd = CreateWindowExA(0, "button", "test", BS_CHECKBOX | WS_VISIBLE | WS_POPUP,
5521 0, 0, 50, 14, 0, 0, 0, NULL);
5522 ok(hwnd != 0, "Failed to create button window\n");
5523 ReleaseCapture();
5524 SetFocus(hwnd);
5525 SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
5526 ok(GetCapture() == hwnd, "Should be captured on VK_SPACE WM_KEYDOWN\n");
5527 SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
5528 DestroyWindow(hwnd);
5529
5530 subclass_button();
5531
5532 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5533 100, 100, 200, 200, 0, 0, 0, NULL);
5534 ok(parent != 0, "Failed to create parent window\n");
5535
5536 for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
5537 {
5538 MSG msg;
5539 DWORD style, state;
5540
5541 trace("button style %08x\n", button[i].style);
5542
5543 hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_CHILD | BS_NOTIFY,
5544 0, 0, 50, 14, parent, (HMENU)ID_BUTTON, 0, NULL);
5545 ok(hwnd != 0, "Failed to create button window\n");
5546
5547 style = GetWindowLongA(hwnd, GWL_STYLE);
5548 style &= ~(WS_CHILD | BS_NOTIFY);
5549 /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
5550 if (button[i].style == BS_USERBUTTON)
5551 ok(style == BS_PUSHBUTTON, "expected style BS_PUSHBUTTON got %x\n", style);
5552 else
5553 ok(style == button[i].style, "expected style %x got %x\n", button[i].style, style);
5554
5555 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5556 ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5557
5558 ShowWindow(hwnd, SW_SHOW);
5559 UpdateWindow(hwnd);
5560 SetFocus(0);
5561 flush_events();
5562 SetFocus(0);
5563 flush_sequence();
5564
5565 log_all_parent_messages++;
5566
5567 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
5568 SetFocus(hwnd);
5569 SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5570 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
5571 ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
5572
5573 SetFocus(0);
5574 SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5575 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
5576 ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
5577
5578 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
5579
5580 SendMessageA(hwnd, BM_SETSTYLE, button[i].style | BS_BOTTOM, TRUE);
5581 SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5582 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
5583 ok_sequence(button[i].setstyle, "BM_SETSTYLE on a button", FALSE);
5584
5585 style = GetWindowLongA(hwnd, GWL_STYLE);
5586 style &= ~(WS_VISIBLE | WS_CHILD | BS_NOTIFY);
5587 /* XP doesn't turn a BS_USERBUTTON into BS_PUSHBUTTON here! */
5588 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5589
5590 state = SendMessageA(hwnd, BM_GETSTATE, 0, 0);
5591 ok(state == 0, "expected state 0, got %04x\n", state);
5592
5593 flush_sequence();
5594
5595 SendMessageA(hwnd, BM_SETSTATE, TRUE, 0);
5596 SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5597 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
5598 ok_sequence(button[i].setstate, "BM_SETSTATE/TRUE on a button", FALSE);
5599
5600 state = SendMessageA(hwnd, BM_GETSTATE, 0, 0);
5601 ok(state == 0x0004, "expected state 0x0004, got %04x\n", state);
5602
5603 style = GetWindowLongA(hwnd, GWL_STYLE);
5604 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5605 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5606
5607 flush_sequence();
5608
5609 SendMessageA(hwnd, BM_SETSTATE, FALSE, 0);
5610 SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5611 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
5612 ok_sequence(button[i].clearstate, "BM_SETSTATE/FALSE on a button", FALSE);
5613
5614 state = SendMessageA(hwnd, BM_GETSTATE, 0, 0);
5615 ok(state == 0, "expected state 0, got %04x\n", state);
5616
5617 style = GetWindowLongA(hwnd, GWL_STYLE);
5618 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5619 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5620
5621 state = SendMessageA(hwnd, BM_GETCHECK, 0, 0);
5622 ok(state == BST_UNCHECKED, "expected BST_UNCHECKED, got %04x\n", state);
5623
5624 flush_sequence();
5625
5626 SendMessageA(hwnd, BM_SETCHECK, BST_UNCHECKED, 0);
5627 SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5628 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
5629 ok_sequence(WmSetCheckIgnoredSeq, "BM_SETCHECK on a button", FALSE);
5630
5631 state = SendMessageA(hwnd, BM_GETCHECK, 0, 0);
5632 ok(state == BST_UNCHECKED, "expected BST_UNCHECKED, got %04x\n", state);
5633
5634 style = GetWindowLongA(hwnd, GWL_STYLE);
5635 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5636 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5637
5638 flush_sequence();
5639
5640 SendMessageA(hwnd, BM_SETCHECK, BST_CHECKED, 0);
5641 SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5642 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
5643 ok_sequence(button[i].setcheck, "BM_SETCHECK on a button", FALSE);
5644
5645 state = SendMessageA(hwnd, BM_GETCHECK, 0, 0);
5646 if (button[i].style == BS_PUSHBUTTON ||
5647 button[i].style == BS_DEFPUSHBUTTON ||
5648 button[i].style == BS_GROUPBOX ||
5649 button[i].style == BS_USERBUTTON ||
5650 button[i].style == BS_OWNERDRAW)
5651 ok(state == BST_UNCHECKED, "expected check 0, got %04x\n", state);
5652 else
5653 ok(state == BST_CHECKED, "expected check 1, got %04x\n", state);
5654
5655 style = GetWindowLongA(hwnd, GWL_STYLE);
5656 style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
5657 if (button[i].style == BS_RADIOBUTTON ||
5658 button[i].style == BS_AUTORADIOBUTTON)
5659 ok(style == (button[i].style | WS_TABSTOP), "expected style %04x | WS_TABSTOP got %04x\n", button[i].style, style);
5660 else
5661 ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
5662
5663 log_all_parent_messages--;
5664
5665 DestroyWindow(hwnd);
5666 }
5667
5668 DestroyWindow(parent);
5669
5670 hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
5671 0, 0, 50, 14, 0, 0, 0, NULL);
5672 ok(hwnd != 0, "Failed to create button window\n");
5673
5674 SetForegroundWindow(hwnd);
5675 flush_events();
5676
5677 SetActiveWindow(hwnd);
5678 SetFocus(0);
5679 flush_sequence();
5680
5681 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
5682 ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
5683
5684 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
5685 ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
5686
5687 flush_sequence();
5688 zfont = GetStockObject(SYSTEM_FONT);
5689 SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
5690 UpdateWindow(hwnd);
5691 ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
5692
5693 DestroyWindow(hwnd);
5694 }
5695
5696 /****************** static message test *************************/
5697 static const struct message WmSetFontStaticSeq[] =
5698 {
5699 { WM_SETFONT, sent },
5700 { WM_PAINT, sent|defwinproc|optional },
5701 { WM_ERASEBKGND, sent|defwinproc|optional },
5702 { WM_CTLCOLORSTATIC, sent|defwinproc|optional },
5703 { 0 }
5704 };
5705
5706 static WNDPROC old_static_proc;
5707
5708 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5709 {
5710 static LONG defwndproc_counter = 0;
5711 LRESULT ret;
5712 struct recvd_message msg;
5713
5714 if (ignore_message( message )) return 0;
5715
5716 msg.hwnd = hwnd;
5717 msg.message = message;
5718 msg.flags = sent|wparam|lparam;
5719 if (defwndproc_counter) msg.flags |= defwinproc;
5720 msg.wParam = wParam;
5721 msg.lParam = lParam;
5722 msg.descr = "static";
5723 add_message(&msg);
5724
5725 defwndproc_counter++;
5726 ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
5727 defwndproc_counter--;
5728
5729 return ret;
5730 }
5731
5732 static void subclass_static(void)
5733 {
5734 WNDCLASSA cls;
5735
5736 if (!GetClassInfoA(0, "static", &cls)) assert(0);
5737
5738 old_static_proc = cls.lpfnWndProc;
5739
5740 cls.hInstance = GetModuleHandleA(NULL);
5741 cls.lpfnWndProc = static_hook_proc;
5742 cls.lpszClassName = "my_static_class";
5743 UnregisterClassA(cls.lpszClassName, cls.hInstance);
5744 if (!RegisterClassA(&cls)) assert(0);
5745 }
5746
5747 static void test_static_messages(void)
5748 {
5749 /* FIXME: make as comprehensive as the button message test */
5750 static const struct
5751 {
5752 DWORD style;
5753 DWORD dlg_code;
5754 const struct message *setfont;
5755 } static_ctrl[] = {
5756 { SS_LEFT, DLGC_STATIC,
5757 WmSetFontStaticSeq }
5758 };
5759 unsigned int i;
5760 HWND hwnd;
5761 DWORD dlg_code;
5762
5763 subclass_static();
5764
5765 for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
5766 {
5767 hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
5768 0, 0, 50, 14, 0, 0, 0, NULL);
5769 ok(hwnd != 0, "Failed to create static window\n");
5770
5771 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5772 ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5773
5774 ShowWindow(hwnd, SW_SHOW);
5775 UpdateWindow(hwnd);
5776 SetFocus(0);
5777 flush_sequence();
5778
5779 trace("static style %08x\n", static_ctrl[i].style);
5780 SendMessageA(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
5781 ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
5782
5783 DestroyWindow(hwnd);
5784 }
5785 }
5786
5787 /****************** ComboBox message test *************************/
5788 #define ID_COMBOBOX 0x000f
5789
5790 static const struct message WmKeyDownComboSeq[] =
5791 {
5792 { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
5793 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
5794 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
5795 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
5796 { WM_CTLCOLOREDIT, sent|parent },
5797 { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
5798 { 0 }
5799 };
5800
5801 static const struct message WmSetPosComboSeq[] =
5802 {
5803 { WM_WINDOWPOSCHANGING, sent },
5804 { WM_NCCALCSIZE, sent|wparam, TRUE },
5805 { WM_CHILDACTIVATE, sent },
5806 { WM_WINDOWPOSCHANGED, sent },
5807 { WM_MOVE, sent|defwinproc },
5808 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
5809 { WM_WINDOWPOSCHANGING, sent|defwinproc },
5810 { WM_NCCALCSIZE, sent|defwinproc|wparam, TRUE },
5811 { WM_WINDOWPOSCHANGED, sent|defwinproc },
5812 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
5813 { 0 }
5814 };
5815
5816 static WNDPROC old_combobox_proc;
5817
5818 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5819 {
5820 static LONG defwndproc_counter = 0;
5821 LRESULT ret;
5822 struct recvd_message msg;
5823
5824 /* do not log painting messages */
5825 if (message != WM_PAINT &&
5826 message != WM_NCPAINT &&
5827 message != WM_SYNCPAINT &&
5828 message != WM_ERASEBKGND &&
5829 message != WM_NCHITTEST &&
5830 message != WM_GETTEXT &&
5831 !ignore_message( message ))
5832 {
5833 msg.hwnd = hwnd;
5834 msg.message = message;
5835 msg.flags = sent|wparam|lparam;
5836 if (defwndproc_counter) msg.flags |= defwinproc;
5837 msg.wParam = wParam;
5838 msg.lParam = lParam;
5839 msg.descr = "combo";
5840 add_message(&msg);
5841 }
5842
5843 defwndproc_counter++;
5844 ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5845 defwndproc_counter--;
5846
5847 return ret;
5848 }
5849
5850 static void subclass_combobox(void)
5851 {
5852 WNDCLASSA cls;
5853
5854 if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5855
5856 old_combobox_proc = cls.lpfnWndProc;
5857
5858 cls.hInstance = GetModuleHandleA(NULL);
5859 cls.lpfnWndProc = combobox_hook_proc;
5860 cls.lpszClassName = "my_combobox_class";
5861 UnregisterClassA(cls.lpszClassName, cls.hInstance);
5862 if (!RegisterClassA(&cls)) assert(0);
5863 }
5864
5865 static void test_combobox_messages(void)
5866 {
5867 HWND parent, combo;
5868 LRESULT ret;
5869
5870 subclass_combobox();
5871
5872 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5873 100, 100, 200, 200, 0, 0, 0, NULL);
5874 ok(parent != 0, "Failed to create parent window\n");
5875 flush_sequence();
5876
5877 combo = CreateWindowExA(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5878 0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5879 ok(combo != 0, "Failed to create combobox window\n");
5880
5881 UpdateWindow(combo);
5882
5883 ret = SendMessageA(combo, WM_GETDLGCODE, 0, 0);
5884 ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5885
5886 ret = SendMessageA(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5887 ok(ret == 0, "expected 0, got %ld\n", ret);
5888 ret = SendMessageA(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5889 ok(ret == 1, "expected 1, got %ld\n", ret);
5890 ret = SendMessageA(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5891 ok(ret == 2, "expected 2, got %ld\n", ret);
5892
5893 SendMessageA(combo, CB_SETCURSEL, 0, 0);
5894 SetFocus(combo);
5895 flush_sequence();
5896
5897 log_all_parent_messages++;
5898 SendMessageA(combo, WM_KEYDOWN, VK_DOWN, 0);
5899 SendMessageA(combo, WM_KEYUP, VK_DOWN, 0);
5900 log_all_parent_messages--;
5901 ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5902
5903 flush_sequence();
5904 SetWindowPos(combo, 0, 10, 10, 120, 130, SWP_NOZORDER);
5905 ok_sequence(WmSetPosComboSeq, "repositioning messages on a ComboBox", FALSE);
5906
5907 DestroyWindow(combo);
5908 DestroyWindow(parent);
5909 }
5910
5911 /****************** WM_IME_KEYDOWN message test *******************/
5912
5913 static const struct message WmImeKeydownMsgSeq_0[] =
5914 {
5915 { WM_IME_KEYDOWN, wparam, VK_RETURN },
5916 { WM_CHAR, wparam, 'A' },
5917 { 0 }
5918 };
5919
5920 static const struct message WmImeKeydownMsgSeq_1[] =
5921 {
5922 { WM_KEYDOWN, optional|wparam, VK_RETURN },
5923 { WM_CHAR, optional|wparam, VK_RETURN },
5924 { 0 }
5925 };
5926
5927 static LRESULT WINAPI wmime_keydown_procA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5928 {
5929 struct recvd_message msg;
5930
5931 msg.hwnd = hwnd;
5932 msg.message = message;
5933 msg.flags = wparam|lparam;
5934 msg.wParam = wParam;
5935 msg.lParam = lParam;
5936 msg.descr = "wmime_keydown";
5937 add_message(&msg);
5938
5939 return DefWindowProcA(hwnd, message, wParam, lParam);
5940 }
5941
5942 static void register_wmime_keydown_class(void)
5943 {
5944 WNDCLASSA cls;
5945
5946 ZeroMemory(&cls, sizeof(WNDCLASSA));
5947 cls.lpfnWndProc = wmime_keydown_procA;
5948 cls.hInstance = GetModuleHandleA(0);
5949 cls.lpszClassName = "wmime_keydown_class";
5950 if (!RegisterClassA(&cls)) assert(0);
5951 }
5952
5953 static void test_wmime_keydown_message(void)
5954 {
5955 HWND hwnd;
5956 MSG msg;
5957
5958 trace("Message sequences by WM_IME_KEYDOWN\n");
5959
5960 register_wmime_keydown_class();
5961 hwnd = CreateWindowExA(0, "wmime_keydown_class", NULL, WS_OVERLAPPEDWINDOW,
5962 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5963 NULL, NULL, 0);
5964 flush_events();
5965 flush_sequence();
5966
5967 SendMessageA(hwnd, WM_IME_KEYDOWN, VK_RETURN, 0x1c0001);
5968 SendMessageA(hwnd, WM_CHAR, 'A', 1);
5969 ok_sequence(WmImeKeydownMsgSeq_0, "WM_IME_KEYDOWN 0", FALSE);
5970
5971 while ( PeekMessageA(&msg, 0, 0, 0, PM_REMOVE) )
5972 {
5973 TranslateMessage(&msg);
5974 DispatchMessageA(&msg);
5975 }
5976 ok_sequence(WmImeKeydownMsgSeq_1, "WM_IME_KEYDOWN 1", FALSE);
5977
5978 DestroyWindow(hwnd);
5979 }
5980
5981 /************* painting message test ********************/
5982
5983 void dump_region(HRGN hrgn)
5984 {
5985 DWORD i, size;
5986 RGNDATA *data = NULL;
5987 RECT *rect;
5988
5989 if (!hrgn)
5990 {
5991 printf( "null region\n" );
5992 return;
5993 }
5994 if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5995 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5996 GetRegionData( hrgn, size, data );
5997 printf("%d rects:", data->rdh.nCount );
5998 for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5999 printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
6000 printf("\n");
6001 HeapFree( GetProcessHeap(), 0, data );
6002 }
6003
6004 static void check_update_rgn( HWND hwnd, HRGN hrgn )
6005 {
6006 INT ret;
6007 RECT r1, r2;
6008 HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
6009 HRGN update = CreateRectRgn( 0, 0, 0, 0 );
6010
6011 ret = GetUpdateRgn( hwnd, update, FALSE );
6012 ok( ret != ERROR, "GetUpdateRgn failed\n" );
6013 if (ret == NULLREGION)
6014 {
6015 ok( !hrgn, "Update region shouldn't be empty\n" );
6016 }
6017 else
6018 {
6019 if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
6020 {
6021 ok( 0, "Regions are different\n" );
6022 if (winetest_debug > 0)
6023 {
6024 printf( "Update region: " );
6025 dump_region( update );
6026 printf( "Wanted region: " );
6027 dump_region( hrgn );
6028 }
6029 }
6030 }
6031 GetRgnBox( update, &r1 );
6032 GetUpdateRect( hwnd, &r2, FALSE );
6033 ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
6034 "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
6035 r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
6036
6037 DeleteObject( tmp );
6038 DeleteObject( update );
6039 }
6040
6041 static const struct message WmInvalidateRgn[] = {
6042 { WM_NCPAINT, sent },
6043 { WM_GETTEXT, sent|defwinproc|optional },
6044 { 0 }
6045 };
6046
6047 static const struct message WmGetUpdateRect[] = {
6048 { WM_NCPAINT, sent },
6049 { WM_GETTEXT, sent|defwinproc|optional },
6050 { WM_PAINT, sent },
6051 { 0 }
6052 };
6053
6054 static const struct message WmInvalidateFull[] = {
6055 { WM_NCPAINT, sent|wparam, 1 },
6056 { WM_GETTEXT, sent|defwinproc|optional },
6057 { 0 }
6058 };
6059
6060 static const struct message WmInvalidateErase[] = {
6061 { WM_NCPAINT, sent|wparam, 1 },
6062 { WM_GETTEXT, sent|defwinproc|optional },
6063 { WM_ERASEBKGND, sent },
6064 { 0 }
6065 };
6066
6067 static const struct message WmInvalidatePaint[] = {
6068 { WM_PAINT, sent },
6069 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
6070 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6071 { 0 }
6072 };
6073
6074 static const struct message WmInvalidateErasePaint[] = {
6075 { WM_PAINT, sent },
6076 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
6077 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6078 { WM_ERASEBKGND, sent|beginpaint|optional },
6079 { 0 }
6080 };
6081
6082 static const struct message WmInvalidateErasePaint2[] = {
6083 { WM_PAINT, sent },
6084 { WM_NCPAINT, sent|beginpaint },
6085 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6086 { WM_ERASEBKGND, sent|beginpaint|optional },
6087 { 0 }
6088 };
6089
6090 static const struct message WmErase[] = {
6091 { WM_ERASEBKGND, sent },
6092 { 0 }
6093 };
6094
6095 static const struct message WmPaint[] = {
6096 { WM_PAINT, sent },
6097 { 0 }
6098 };
6099
6100 static const struct message WmParentOnlyPaint[] = {
6101 { WM_PAINT, sent|parent },
6102 { 0 }
6103 };
6104
6105 static const struct message WmInvalidateParent[] = {
6106 { WM_NCPAINT, sent|parent },
6107 { WM_GETTEXT, sent|defwinproc|parent|optional },
6108 { WM_ERASEBKGND, sent|parent },
6109 { 0 }
6110 };
6111
6112 static const struct message WmInvalidateParentChild[] = {
6113 { WM_NCPAINT, sent|parent },
6114 { WM_GETTEXT, sent|defwinproc|parent|optional },
6115 { WM_ERASEBKGND, sent|parent },
6116 { WM_NCPAINT, sent },
6117 { WM_GETTEXT, sent|defwinproc|optional },
6118 { WM_ERASEBKGND, sent },
6119 { 0 }
6120 };
6121
6122 static const struct message WmInvalidateParentChild2[] = {
6123 { WM_ERASEBKGND, sent|parent },
6124 { WM_NCPAINT, sent },
6125 { WM_GETTEXT, sent|defwinproc|optional },
6126 { WM_ERASEBKGND, sent },
6127 { 0 }
6128 };
6129
6130 static const struct message WmParentPaint[] = {
6131 { WM_PAINT, sent|parent },
6132 { WM_PAINT, sent },
6133 { 0 }
6134 };
6135
6136 static const struct message WmParentPaintNc[] = {
6137 { WM_PAINT, sent|parent },
6138 { WM_PAINT, sent },
6139 { WM_NCPAINT, sent|beginpaint },
6140 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6141 { WM_ERASEBKGND, sent|beginpaint|optional },
6142 { 0 }
6143 };
6144
6145 static const struct message WmChildPaintNc[] = {
6146 { WM_PAINT, sent },
6147 { WM_NCPAINT, sent|beginpaint },
6148 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6149 { WM_ERASEBKGND, sent|beginpaint|optional },
6150 { 0 }
6151 };
6152
6153 static const struct message WmParentErasePaint[] = {
6154 { WM_PAINT, sent|parent },
6155 { WM_NCPAINT, sent|parent|beginpaint },
6156 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
6157 { WM_ERASEBKGND, sent|parent|beginpaint|optional },
6158 { WM_PAINT, sent },
6159 { WM_NCPAINT, sent|beginpaint },
6160 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
6161 { WM_ERASEBKGND, sent|beginpaint|optional },
6162 { 0 }
6163 };
6164
6165 static const struct message WmParentOnlyNcPaint[] = {
6166 { WM_PAINT, sent|parent },
6167 { WM_NCPAINT, sent|parent|beginpaint },
6168 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
6169 { 0 }
6170 };
6171
6172 static const struct message WmSetParentStyle[] = {
6173 { WM_STYLECHANGING, sent|parent },
6174 { WM_STYLECHANGED, sent|parent },
6175 { 0 }
6176 };
6177
6178 static void test_paint_messages(void)
6179 {
6180 BOOL ret;
6181 RECT rect;
6182 POINT pt;
6183 MSG msg;
6184 HWND hparent, hchild;
6185 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
6186 HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
6187 HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
6188 100, 100, 200, 200, 0, 0, 0, NULL);
6189 ok (hwnd != 0, "Failed to create overlapped window\n");
6190
6191 ShowWindow( hwnd, SW_SHOW );
6192 UpdateWindow( hwnd );
6193 flush_events();
6194 flush_sequence();
6195
6196 check_update_rgn( hwnd, 0 );
6197 SetRectRgn( hrgn, 10, 10, 20, 20 );
6198 ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6199 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6200 check_update_rgn( hwnd, hrgn );
6201 SetRectRgn( hrgn2, 20, 20, 30, 30 );
6202 ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
6203 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6204 CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
6205 check_update_rgn( hwnd, hrgn );
6206 /* validate everything */
6207 ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6208 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6209 check_update_rgn( hwnd, 0 );
6210
6211 /* test empty region */
6212 SetRectRgn( hrgn, 10, 10, 10, 15 );
6213 ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6214 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6215 check_update_rgn( hwnd, 0 );
6216 /* test empty rect */
6217 SetRect( &rect, 10, 10, 10, 15 );
6218 ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
6219 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
6220 check_update_rgn( hwnd, 0 );
6221
6222 /* flush pending messages */
6223 flush_events();
6224 flush_sequence();
6225
6226 GetClientRect( hwnd, &rect );
6227 SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
6228 /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
6229 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
6230 */
6231 trace("testing InvalidateRect(0, NULL, FALSE)\n");
6232 SetRectEmpty( &rect );
6233 ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
6234 check_update_rgn( hwnd, hrgn );
6235 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6236 flush_events();
6237 ok_sequence( WmPaint, "Paint", FALSE );
6238 RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6239 check_update_rgn( hwnd, 0 );
6240
6241 /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
6242 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
6243 */
6244 trace("testing ValidateRect(0, NULL)\n");
6245 SetRectEmpty( &rect );
6246 if (ValidateRect(0, &rect)) /* not supported on Win9x */
6247 {
6248 check_update_rgn( hwnd, hrgn );
6249 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6250 flush_events();
6251 ok_sequence( WmPaint, "Paint", FALSE );
6252 RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
6253 check_update_rgn( hwnd, 0 );
6254 }
6255
6256 trace("testing InvalidateRgn(0, NULL, FALSE)\n");
6257 SetLastError(0xdeadbeef);
6258 ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
6259 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
6260 "wrong error code %d\n", GetLastError());
6261 check_update_rgn( hwnd, 0 );
6262 flush_events();
6263 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6264
6265 trace("testing ValidateRgn(0, NULL)\n");
6266 SetLastError(0xdeadbeef);
6267 ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
6268 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
6269 broken( GetLastError() == 0xdeadbeef ) /* win9x */,
6270 "wrong error code %d\n", GetLastError());
6271 check_update_rgn( hwnd, 0 );
6272 flush_events();
6273 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6274
6275 trace("testing UpdateWindow(NULL)\n");
6276 SetLastError(0xdeadbeef);
6277 ok(!UpdateWindow(NULL), "UpdateWindow(NULL) should fail\n");
6278 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
6279 broken( GetLastError() == 0xdeadbeef ) /* win9x */,
6280 "wrong error code %d\n", GetLastError());
6281 check_update_rgn( hwnd, 0 );
6282 flush_events();
6283 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6284
6285 /* now with frame */
6286 SetRectRgn( hrgn, -5, -5, 20, 20 );
6287
6288 /* flush pending messages */
6289 flush_events();
6290 flush_sequence();
6291 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6292 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
6293
6294 SetRectRgn( hrgn, 0, 0, 20, 20 ); /* GetUpdateRgn clips to client area */
6295 check_update_rgn( hwnd, hrgn );
6296
6297 flush_sequence();
6298 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
6299 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
6300
6301 flush_sequence();
6302 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
6303 ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
6304
6305 GetClientRect( hwnd, &rect );
6306 SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
6307 check_update_rgn( hwnd, hrgn );
6308
6309 flush_sequence();
6310 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
6311 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6312
6313 flush_sequence();
6314 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
6315 ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
6316 check_update_rgn( hwnd, 0 );
6317
6318 flush_sequence();
6319 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
6320 ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
6321 check_update_rgn( hwnd, 0 );
6322
6323 flush_sequence();
6324 SetRectRgn( hrgn, 0, 0, 100, 100 );
6325 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6326 SetRectRgn( hrgn, 0, 0, 50, 100 );
6327 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
6328 SetRectRgn( hrgn, 50, 0, 100, 100 );
6329 check_update_rgn( hwnd, hrgn );
6330 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
6331 ok_sequence( WmEmptySeq, "EmptySeq", FALSE ); /* must not generate messages, everything is valid */
6332 check_update_rgn( hwnd, 0 );
6333
6334 flush_sequence();
6335 SetRectRgn( hrgn, 0, 0, 100, 100 );
6336 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
6337 SetRectRgn( hrgn, 0, 0, 100, 50 );
6338 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
6339 ok_sequence( WmErase, "Erase", FALSE );
6340 SetRectRgn( hrgn, 0, 50, 100, 100 );
6341 check_update_rgn( hwnd, hrgn );
6342
6343 flush_sequence();
6344 SetRectRgn( hrgn, 0, 0, 100, 100 );
6345 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
6346 SetRectRgn( hrgn, 0, 0, 50, 50 );
6347 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
6348 ok_sequence( WmPaint, "Paint", FALSE );
6349
6350 flush_sequence();
6351 SetRectRgn( hrgn, -4, -4, -2, -2 );
6352 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6353 SetRectRgn( hrgn, -200, -200, -198, -198 );
6354 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
6355 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
6356
6357 flush_sequence();
6358 SetRectRgn( hrgn, -4, -4, -2, -2 );
6359 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6360 SetRectRgn( hrgn, -4, -4, -3, -3 );
6361 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
6362 SetRectRgn( hrgn, 0, 0, 1, 1 );
6363 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
6364 ok_sequence( WmPaint, "Paint", FALSE );
6365
6366 flush_sequence();
6367 SetRectRgn( hrgn, -4, -4, -1, -1 );
6368 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6369 RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
6370 /* make sure no WM_PAINT was generated */
6371 flush_events();
6372 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
6373
6374 flush_sequence();
6375 SetRectRgn( hrgn, -4, -4, -1, -1 );
6376 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6377 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ))
6378 {
6379 if (msg.hwnd == hwnd && msg.message == WM_PAINT)
6380 {
6381 /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
6382 INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
6383 ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
6384 ret = GetUpdateRect( hwnd, &rect, FALSE );
6385 ok( ret, "Invalid GetUpdateRect result %d\n", ret );
6386 /* this will send WM_NCPAINT and validate the non client area */
6387 ret = GetUpdateRect( hwnd, &rect, TRUE );
6388 ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
6389 }
6390 DispatchMessageA( &msg );
6391 }
6392 ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
6393
6394 DestroyWindow( hwnd );
6395
6396 /* now test with a child window */
6397
6398 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
6399 100, 100, 200, 200, 0, 0, 0, NULL);
6400 ok (hparent != 0, "Failed to create parent window\n");
6401
6402 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
6403 10, 10, 100, 100, hparent, 0, 0, NULL);
6404 ok (hchild != 0, "Failed to create child window\n");
6405
6406 ShowWindow( hparent, SW_SHOW );
6407 UpdateWindow( hparent );
6408 UpdateWindow( hchild );
6409 flush_events();
6410 flush_sequence();
6411 log_all_parent_messages++;
6412
6413 SetRect( &rect, 0, 0, 50, 50 );
6414 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6415 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6416 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
6417
6418 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6419 pt.x = pt.y = 0;
6420 MapWindowPoints( hchild, hparent, &pt, 1 );
6421 SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
6422 check_update_rgn( hchild, hrgn );
6423 SetRectRgn( hrgn, 0, 0, 50, 50 );
6424 check_update_rgn( hparent, hrgn );
6425 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6426 ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
6427 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6428 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6429
6430 flush_events();
6431 ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
6432
6433 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6434 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6435 ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
6436 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6437 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6438
6439 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6440 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6441 ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
6442
6443 SetWindowLongA( hparent, GWL_STYLE, GetWindowLongA(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6444 flush_sequence();
6445 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6446 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6447 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
6448
6449 /* flush all paint messages */
6450 flush_events();
6451 flush_sequence();
6452
6453 /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
6454 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6455 SetRectRgn( hrgn, 0, 0, 50, 50 );
6456 check_update_rgn( hparent, hrgn );
6457 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6458 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6459 SetRectRgn( hrgn, 0, 0, 50, 50 );
6460 check_update_rgn( hparent, hrgn );
6461
6462 /* flush all paint messages */
6463 flush_events();
6464 SetWindowLongA( hparent, GWL_STYLE, GetWindowLongA(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6465 flush_sequence();
6466
6467 /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
6468 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6469 SetRectRgn( hrgn, 0, 0, 50, 50 );
6470 check_update_rgn( hparent, hrgn );
6471 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6472 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6473 SetRectRgn( hrgn2, 10, 10, 50, 50 );
6474 CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
6475 check_update_rgn( hparent, hrgn );
6476 /* flush all paint messages */
6477 flush_events();
6478 flush_sequence();
6479
6480 /* same as above but parent gets completely validated */
6481 SetRect( &rect, 20, 20, 30, 30 );
6482 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6483 SetRectRgn( hrgn, 20, 20, 30, 30 );
6484 check_update_rgn( hparent, hrgn );
6485 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6486 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6487 check_update_rgn( hparent, 0 ); /* no update region */
6488 flush_events();
6489 ok_sequence( WmEmptySeq, "WmEmpty", FALSE ); /* and no paint messages */
6490
6491 /* make sure RDW_VALIDATE on child doesn't have the same effect */
6492 flush_sequence();
6493 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6494 SetRectRgn( hrgn, 20, 20, 30, 30 );
6495 check_update_rgn( hparent, hrgn );
6496 RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
6497 SetRectRgn( hrgn, 20, 20, 30, 30 );
6498 check_update_rgn( hparent, hrgn );
6499
6500 /* same as above but normal WM_PAINT doesn't validate parent */
6501 flush_sequence();
6502 SetRect( &rect, 20, 20, 30, 30 );
6503 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6504 SetRectRgn( hrgn, 20, 20, 30, 30 );
6505 check_update_rgn( hparent, hrgn );
6506 /* no WM_PAINT in child while parent still pending */
6507 while (PeekMessageA( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
6508 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6509 while (PeekMessageA( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
6510 ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
6511
6512 flush_sequence();
6513 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6514 /* no WM_PAINT in child while parent still pending */
6515 while (PeekMessageA( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
6516 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6517 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
6518 /* now that parent is valid child should get WM_PAINT */
6519 while (PeekMessageA( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
6520 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6521 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
6522 ok_sequence( WmEmptySeq, "No other message", FALSE );
6523
6524 /* same thing with WS_CLIPCHILDREN in parent */
6525 flush_sequence();
6526 SetWindowLongA( hparent, GWL_STYLE, GetWindowLongA(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6527 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6528 /* changing style invalidates non client area, but we need to invalidate something else to see it */
6529 RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
6530 ok_sequence( WmEmptySeq, "No message", FALSE );
6531 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
6532 ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
6533
6534 flush_sequence();
6535 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
6536 SetRectRgn( hrgn, 20, 20, 30, 30 );
6537 check_update_rgn( hparent, hrgn );
6538 /* no WM_PAINT in child while parent still pending */
6539 while (PeekMessageA( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
6540 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6541 /* WM_PAINT in parent first */
6542 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
6543 ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
6544
6545 /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
6546 flush_sequence();
6547 SetRect( &rect, 0, 0, 30, 30 );
6548 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
6549 SetRectRgn( hrgn, 0, 0, 30, 30 );
6550 check_update_rgn( hparent, hrgn );
6551 flush_events();
6552 ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
6553
6554 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6555 flush_sequence();
6556 SetRect( &rect, -10, 0, 30, 30 );
6557 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6558 SetRect( &rect, 0, 0, 20, 20 );
6559 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6560 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6561 ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
6562
6563 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6564 flush_sequence();
6565 SetRect( &rect, -10, 0, 30, 30 );
6566 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6567 SetRect( &rect, 0, 0, 100, 100 );
6568 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6569 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6570 ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
6571 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6572 ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
6573
6574 /* test RDW_INTERNALPAINT behavior */
6575
6576 flush_sequence();
6577 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
6578 flush_events();
6579 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6580
6581 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
6582 flush_events();
6583 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6584
6585 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6586 flush_events();
6587 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6588
6589 assert( GetWindowLongA(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
6590 UpdateWindow( hparent );
6591 flush_events();
6592 flush_sequence();
6593 trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
6594 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6595 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6596 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6597 flush_events();
6598 ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
6599
6600 UpdateWindow( hparent );
6601 flush_events();
6602 flush_sequence();
6603 trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
6604 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6605 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6606 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6607 flush_events();
6608 ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6609
6610 SetWindowLongA( hparent, GWL_STYLE, GetWindowLongA(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6611 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6612 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6613 flush_events();
6614 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6615
6616 assert( !(GetWindowLongA(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
6617 UpdateWindow( hparent );
6618 flush_events();
6619 flush_sequence();
6620 trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
6621 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6622 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6623 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6624 flush_events();
6625 ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
6626
6627 UpdateWindow( hparent );
6628 flush_events();
6629 flush_sequence();
6630 trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
6631 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6632 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6633 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6634 flush_events();
6635 ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6636
6637 ok(GetWindowLongA( hparent, GWL_STYLE ) & WS_VISIBLE, "parent should be visible\n");
6638 ok(GetWindowLongA( hchild, GWL_STYLE ) & WS_VISIBLE, "child should be visible\n");
6639
6640 UpdateWindow( hparent );
6641 flush_events();
6642 flush_sequence();
6643 trace("testing SetWindowPos(-10000, -10000) on child\n");
6644 SetWindowPos( hchild, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6645 check_update_rgn( hchild, 0 );
6646 flush_events();
6647
6648 #if 0 /* this one doesn't pass under Wine yet */
6649 UpdateWindow( hparent );
6650 flush_events();
6651 flush_sequence();
6652 trace("testing ShowWindow(SW_MINIMIZE) on child\n");
6653 ShowWindow( hchild, SW_MINIMIZE );
6654 check_update_rgn( hchild, 0 );
6655 flush_events();
6656 #endif
6657
6658 UpdateWindow( hparent );
6659 flush_events();
6660 flush_sequence();
6661 trace("testing SetWindowPos(-10000, -10000) on parent\n");
6662 SetWindowPos( hparent, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6663 check_update_rgn( hparent, 0 );
6664 flush_events();
6665
6666 log_all_parent_messages--;
6667 DestroyWindow( hparent );
6668 ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6669
6670 /* tests for moving windows off-screen (needs simple WS_POPUP windows) */
6671
6672 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_POPUP | WS_VISIBLE,
6673 100, 100, 200, 200, 0, 0, 0, NULL);
6674 ok (hparent != 0, "Failed to create parent window\n");
6675
6676 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
6677 10, 10, 100, 100, hparent, 0, 0, NULL);
6678 ok (hchild != 0, "Failed to create child window\n");
6679
6680 ShowWindow( hparent, SW_SHOW );
6681 UpdateWindow( hparent );
6682 UpdateWindow( hchild );
6683 flush_events();
6684 flush_sequence();
6685
6686 /* moving child outside of parent boundaries changes update region */
6687 SetRect( &rect, 0, 0, 40, 40 );
6688 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6689 SetRectRgn( hrgn, 0, 0, 40, 40 );
6690 check_update_rgn( hchild, hrgn );
6691 MoveWindow( hchild, -10, 10, 100, 100, FALSE );
6692 SetRectRgn( hrgn, 10, 0, 40, 40 );
6693 check_update_rgn( hchild, hrgn );
6694 MoveWindow( hchild, -10, -10, 100, 100, FALSE );
6695 SetRectRgn( hrgn, 10, 10, 40, 40 );
6696 check_update_rgn( hchild, hrgn );
6697
6698 /* moving parent off-screen does too */
6699 SetRect( &rect, 0, 0, 100, 100 );
6700 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
6701 SetRectRgn( hrgn, 0, 0, 100, 100 );
6702 check_update_rgn( hparent, hrgn );
6703 SetRectRgn( hrgn, 10, 10, 40, 40 );
6704 check_update_rgn( hchild, hrgn );
6705 MoveWindow( hparent, -20, -20, 200, 200, FALSE );
6706 SetRectRgn( hrgn, 20, 20, 100, 100 );
6707 check_update_rgn( hparent, hrgn );
6708 SetRectRgn( hrgn, 30, 30, 40, 40 );
6709 check_update_rgn( hchild, hrgn );
6710
6711 /* invalidated region is cropped by the parent rects */
6712 SetRect( &rect, 0, 0, 50, 50 );
6713 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6714 SetRectRgn( hrgn, 30, 30, 50, 50 );
6715 check_update_rgn( hchild, hrgn );
6716
6717 DestroyWindow( hparent );
6718 ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6719 flush_sequence();
6720
6721 DeleteObject( hrgn );
6722 DeleteObject( hrgn2 );
6723 }
6724
6725 struct wnd_event
6726 {
6727 HWND hwnd;
6728 HANDLE grand_child;
6729 HANDLE start_event;
6730 HANDLE stop_event;
6731 };
6732
6733 static DWORD WINAPI thread_proc(void *param)
6734 {
6735 MSG msg;
6736 struct wnd_event *wnd_event = param;
6737
6738 wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
6739 100, 100, 200, 200, 0, 0, 0, NULL);
6740 ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
6741
6742 SetEvent(wnd_event->start_event);
6743
6744 while (GetMessageA(&msg, 0, 0, 0))
6745 {
6746 TranslateMessage(&msg);
6747 DispatchMessageA(&msg);
6748 }
6749
6750 ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
6751
6752 return 0;
6753 }
6754
6755 static DWORD CALLBACK create_grand_child_thread( void *param )
6756 {
6757 struct wnd_event *wnd_event = param;
6758 HWND hchild;
6759 MSG msg;
6760
6761 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
6762 WS_CHILD | WS_VISIBLE, 0, 0, 10, 10, wnd_event->hwnd, 0, 0, NULL);
6763 ok (hchild != 0, "Failed to create child window\n");
6764 flush_events();
6765 flush_sequence();
6766 SetEvent( wnd_event->start_event );
6767
6768 for (;;)
6769 {
6770 MsgWaitForMultipleObjects(0, NULL, FALSE, 1000, QS_ALLINPUT);
6771 if (!IsWindow( hchild )) break; /* will be destroyed when parent thread exits */
6772 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
6773 }
6774 return 0;
6775 }
6776
6777 static DWORD CALLBACK create_child_thread( void *param )
6778 {
6779 struct wnd_event *wnd_event = param;
6780 struct wnd_event child_event;
6781 DWORD ret, tid;
6782 MSG msg;
6783
6784 child_event.hwnd = CreateWindowExA(0, "TestWindowClass", "Test child",
6785 WS_CHILD | WS_VISIBLE, 0, 0, 10, 10, wnd_event->hwnd, 0, 0, NULL);
6786 ok (child_event.hwnd != 0, "Failed to create child window\n");
6787 SetFocus( child_event.hwnd );
6788 flush_events();
6789 flush_sequence();
6790 child_event.start_event = wnd_event->start_event;
6791 wnd_event->grand_child = CreateThread(NULL, 0, create_grand_child_thread, &child_event, 0, &tid);
6792 for (;;)
6793 {
6794 DWORD ret = MsgWaitForMultipleObjects(1, &child_event.start_event, FALSE, 1000, QS_SENDMESSAGE);
6795 if (ret != 1) break;
6796 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
6797 }
6798 ret = WaitForSingleObject( wnd_event->stop_event, 5000 );
6799 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6800 return 0;
6801 }
6802
6803 static const char manifest_dep[] =
6804 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
6805 "<assemblyIdentity version=\"1.2.3.4\" name=\"testdep1\" type=\"win32\" processorArchitecture=\"" ARCH "\"/>"
6806 " <file name=\"testdep.dll\" />"
6807 "</assembly>";
6808
6809 static const char manifest_main[] =
6810 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
6811 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\" />"
6812 "<dependency>"
6813 " <dependentAssembly>"
6814 " <assemblyIdentity type=\"win32\" name=\"testdep1\" version=\"1.2.3.4\" processorArchitecture=\"" ARCH "\" />"
6815 " </dependentAssembly>"
6816 "</dependency>"
6817 "</assembly>";
6818
6819 static void create_manifest_file(const char *filename, const char *manifest)
6820 {
6821 WCHAR path[MAX_PATH];
6822 HANDLE file;
6823 DWORD size;
6824
6825 MultiByteToWideChar( CP_ACP, 0, filename, -1, path, MAX_PATH );
6826 file = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
6827 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
6828 WriteFile(file, manifest, strlen(manifest), &size, NULL);
6829 CloseHandle(file);
6830 }
6831
6832 static HANDLE test_create(const char *file)
6833 {
6834 WCHAR path[MAX_PATH];
6835 ACTCTXW actctx;
6836 HANDLE handle;
6837
6838 MultiByteToWideChar(CP_ACP, 0, file, -1, path, MAX_PATH);
6839 memset(&actctx, 0, sizeof(ACTCTXW));
6840 actctx.cbSize = sizeof(ACTCTXW);
6841 actctx.lpSource = path;
6842
6843 handle = pCreateActCtxW(&actctx);
6844 ok(handle != INVALID_HANDLE_VALUE, "failed to create context, error %u\n", GetLastError());
6845
6846 ok(actctx.cbSize == sizeof(actctx), "cbSize=%d\n", actctx.cbSize);
6847 ok(actctx.dwFlags == 0, "dwFlags=%d\n", actctx.dwFlags);
6848 ok(actctx.lpSource == path, "lpSource=%p\n", actctx.lpSource);
6849 ok(actctx.wProcessorArchitecture == 0, "wProcessorArchitecture=%d\n", actctx.wProcessorArchitecture);
6850 ok(actctx.wLangId == 0, "wLangId=%d\n", actctx.wLangId);
6851 ok(actctx.lpAssemblyDirectory == NULL, "lpAssemblyDirectory=%p\n", actctx.lpAssemblyDirectory);
6852 ok(actctx.lpResourceName == NULL, "lpResourceName=%p\n", actctx.lpResourceName);
6853 ok(actctx.lpApplicationName == NULL, "lpApplicationName=%p\n", actctx.lpApplicationName);
6854 ok(actctx.hModule == NULL, "hModule=%p\n", actctx.hModule);
6855
6856 return handle;
6857 }
6858
6859 static void test_interthread_messages(void)
6860 {
6861 HANDLE hThread, context, handle, event;
6862 ULONG_PTR cookie;
6863 DWORD tid;
6864 WNDPROC proc;
6865 MSG msg;
6866 char buf[256];
6867 int len, expected_len;
6868 struct wnd_event wnd_event;
6869 BOOL ret;
6870
6871 wnd_event.start_event = CreateEventW(NULL, 0, 0, NULL);
6872 if (!wnd_event.start_event)
6873 {
6874 win_skip("skipping interthread message test under win9x\n");
6875 return;
6876 }
6877
6878 hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
6879 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
6880
6881 ok(WaitForSingleObject(wnd_event.start_event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6882
6883 CloseHandle(wnd_event.start_event);
6884
6885 SetLastError(0xdeadbeef);
6886 ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeeded\n");
6887 ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
6888 "wrong error code %d\n", GetLastError());
6889
6890 proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6891 ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
6892
6893 expected_len = lstrlenA("window caption text");
6894 memset(buf, 0, sizeof(buf));
6895 SetLastError(0xdeadbeef);
6896 len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
6897 ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
6898 ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
6899
6900 msg.hwnd = wnd_event.hwnd;
6901 msg.message = WM_GETTEXT;
6902 msg.wParam = sizeof(buf);
6903 msg.lParam = (LPARAM)buf;
6904 memset(buf, 0, sizeof(buf));
6905 SetLastError(0xdeadbeef);
6906 len = DispatchMessageA(&msg);
6907 ok((!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY) || broken(len), /* nt4 */
6908 "DispatchMessageA(WM_GETTEXT) succeeded on another thread window: ret %d, error %d\n", len, GetLastError());
6909
6910 /* the following test causes an exception in user.exe under win9x */
6911 msg.hwnd = wnd_event.hwnd;
6912 msg.message = WM_TIMER;
6913 msg.wParam = 0;
6914 msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6915 SetLastError(0xdeadbeef);
6916 len = DispatchMessageA(&msg);
6917 ok(!len && GetLastError() == 0xdeadbeef,
6918 "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
6919
6920 ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
6921 ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
6922
6923 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6924 CloseHandle(hThread);
6925
6926 ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
6927
6928 wnd_event.hwnd = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6929 100, 100, 200, 200, 0, 0, 0, NULL);
6930 ok (wnd_event.hwnd != 0, "Failed to create parent window\n");
6931 flush_events();
6932 flush_sequence();
6933 log_all_parent_messages++;
6934 wnd_event.start_event = CreateEventA( NULL, TRUE, FALSE, NULL );
6935 wnd_event.stop_event = CreateEventA( NULL, TRUE, FALSE, NULL );
6936 hThread = CreateThread( NULL, 0, create_child_thread, &wnd_event, 0, &tid );
6937 for (;;)
6938 {
6939 ret = MsgWaitForMultipleObjects(1, &wnd_event.start_event, FALSE, 1000, QS_SENDMESSAGE);
6940 if (ret != 1) break;
6941 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
6942 }
6943 ok( !ret, "MsgWaitForMultipleObjects failed %x\n", ret );
6944 /* now wait for the thread without processing messages; this shouldn't deadlock */
6945 SetEvent( wnd_event.stop_event );
6946 ret = WaitForSingleObject( hThread, 5000 );
6947 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6948 CloseHandle( hThread );
6949
6950 ret = WaitForSingleObject( wnd_event.grand_child, 5000 );
6951 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6952 CloseHandle( wnd_event.grand_child );
6953
6954 CloseHandle( wnd_event.start_event );
6955 CloseHandle( wnd_event.stop_event );
6956 flush_events();
6957 ok_sequence(WmExitThreadSeq, "destroy child on thread exit", FALSE);
6958 log_all_parent_messages--;
6959 DestroyWindow( wnd_event.hwnd );
6960
6961 /* activation context tests */
6962 if (!pActivateActCtx)
6963 {
6964 win_skip("Activation contexts are not supported, skipping\n");
6965 return;
6966 }
6967
6968 create_manifest_file("testdep1.manifest", manifest_dep);
6969 create_manifest_file("main.manifest", manifest_main);
6970
6971 context = test_create("main.manifest");
6972 DeleteFileA("testdep1.manifest");
6973 DeleteFileA("main.manifest");
6974
6975 handle = (void*)0xdeadbeef;
6976 ret = pGetCurrentActCtx(&handle);
6977 ok(ret, "GetCurentActCtx failed: %u\n", GetLastError());
6978 ok(handle == 0, "active context %p\n", handle);
6979
6980 wnd_event.start_event = CreateEventW(NULL, 0, 0, NULL);
6981 hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
6982 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
6983 ok(WaitForSingleObject(wnd_event.start_event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6984 CloseHandle(wnd_event.start_event);
6985
6986 /* context is activated after thread creation, so it doesn't inherit it by default */
6987 ret = pActivateActCtx(context, &cookie);
6988 ok(ret, "activation failed: %u\n", GetLastError());
6989
6990 handle = 0;
6991 ret = pGetCurrentActCtx(&handle);
6992 ok(ret, "GetCurentActCtx failed: %u\n", GetLastError());
6993 ok(handle != 0, "active context %p\n", handle);
6994 pReleaseActCtx(handle);
6995
6996 /* destination window will test for active context */
6997 ret = SendMessageA(wnd_event.hwnd, WM_USER+10, 0, 0);
6998 ok(ret, "thread window returned %d\n", ret);
6999
7000 event = CreateEventW(NULL, 0, 0, NULL);
7001 ret = PostMessageA(wnd_event.hwnd, WM_USER+10, 0, (LPARAM)event);
7002 ok(ret, "thread window returned %d\n", ret);
7003 ok(WaitForSingleObject(event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7004 CloseHandle(event);
7005
7006 ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
7007 ok(ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
7008
7009 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7010 CloseHandle(hThread);
7011
7012 ret = pDeactivateActCtx(0, cookie);
7013 ok(ret, "DeactivateActCtx failed: %u\n", GetLastError());
7014 pReleaseActCtx(context);
7015 }
7016
7017
7018 static const struct message WmVkN[] = {
7019 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
7020 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
7021 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
7022 { WM_CHAR, wparam|lparam, 'n', 1 },
7023 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
7024 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
7025 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
7026 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
7027 { 0 }
7028 };
7029 static const struct message WmShiftVkN[] = {
7030 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
7031 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
7032 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
7033 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
7034 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
7035 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
7036 { WM_CHAR, wparam|lparam, 'N', 1 },
7037 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
7038 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
7039 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
7040 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
7041 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
7042 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
7043 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
7044 { 0 }
7045 };
7046 static const struct message WmCtrlVkN[] = {
7047 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
7048 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
7049 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
7050 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
7051 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
7052 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
7053 { WM_CHAR, wparam|lparam, 0x000e, 1 },
7054 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
7055 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
7056 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
7057 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
7058 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
7059 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
7060 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
7061 { 0 }
7062 };
7063 static const struct message WmCtrlVkN_2[] = {
7064 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
7065 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
7066 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
7067 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
7068 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
7069 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
7070 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
7071 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
7072 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
7073 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
7074 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
7075 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
7076 { 0 }
7077 };
7078 static const struct message WmAltVkN[] = {
7079 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
7080 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
7081 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
7082 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
7083 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
7084 { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
7085 { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
7086 { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
7087 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
7088 { HCBT_SYSCOMMAND, hook },
7089 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7090 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7091 { 0x00AE, sent|defwinproc|optional }, /* XP */
7092 { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
7093 { WM_INITMENU, sent|defwinproc },
7094 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7095 { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
7096 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
7097 { WM_CAPTURECHANGED, sent|defwinproc },
7098 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
7099 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7100 { WM_EXITMENULOOP, sent|defwinproc },
7101 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
7102 { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
7103 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
7104 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
7105 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
7106 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
7107 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
7108 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
7109 { 0 }
7110 };
7111 static const struct message WmAltVkN_2[] = {
7112 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
7113 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
7114 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
7115 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
7116 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
7117 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
7118 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
7119 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
7120 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
7121 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
7122 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
7123 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
7124 { 0 }
7125 };
7126 static const struct message WmCtrlAltVkN[] = {
7127 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
7128 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
7129 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
7130 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
7131 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
7132 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
7133 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
7134 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
7135 { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
7136 { WM_CHAR, optional },
7137 { WM_CHAR, sent|optional },
7138 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
7139 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
7140 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
7141 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
7142 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
7143 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
7144 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
7145 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
7146 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
7147 { 0 }
7148 };
7149 static const struct message WmCtrlShiftVkN[] = {
7150 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
7151 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
7152 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
7153 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
7154 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
7155 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
7156 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
7157 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
7158 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
7159 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
7160 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
7161 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
7162 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
7163 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
7164 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
7165 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
7166 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
7167 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
7168 { 0 }
7169 };
7170 static const struct message WmCtrlAltShiftVkN[] = {
7171 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
7172 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
7173 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
7174 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
7175 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
7176 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
7177 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
7178 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
7179 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
7180 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
7181 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
7182 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
7183 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
7184 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
7185 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
7186 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
7187 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
7188 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
7189 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
7190 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
7191 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
7192 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
7193 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
7194 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
7195 { 0 }
7196 };
7197 static const struct message WmAltPressRelease[] = {
7198 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
7199 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
7200 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
7201 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
7202 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
7203 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
7204 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
7205 { HCBT_SYSCOMMAND, hook },
7206 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7207 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7208 { WM_INITMENU, sent|defwinproc },
7209 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7210 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
7211 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7212
7213 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
7214
7215 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7216 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
7217 { WM_CAPTURECHANGED, sent|defwinproc },
7218 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
7219 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7220 { WM_EXITMENULOOP, sent|defwinproc },
7221 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
7222 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
7223 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
7224 { 0 }
7225 };
7226 static const struct message WmShiftMouseButton[] = {
7227 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
7228 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
7229 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
7230 { WM_MOUSEMOVE, wparam|optional, 0, 0 },
7231 { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
7232 { WM_LBUTTONDOWN, wparam, MK_LBUTTON|MK_SHIFT, 0 },
7233 { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON|MK_SHIFT, 0 },
7234 { WM_LBUTTONUP, wparam, MK_SHIFT, 0 },
7235 { WM_LBUTTONUP, sent|wparam, MK_SHIFT, 0 },
7236 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
7237 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
7238 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
7239 { 0 }
7240 };
7241 static const struct message WmF1Seq[] = {
7242 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
7243 { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
7244 { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
7245 { WM_KEYF1, wparam|lparam, 0, 0 },
7246 { WM_KEYF1, sent|wparam|lparam, 0, 0 },
7247 { WM_HELP, sent|defwinproc },
7248 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
7249 { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
7250 { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
7251 { 0 }
7252 };
7253 static const struct message WmVkAppsSeq[] = {
7254 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
7255 { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
7256 { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
7257 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
7258 { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
7259 { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
7260 { WM_CONTEXTMENU, lparam, /*hwnd*/0, -1 },
7261 { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, -1 },
7262 { 0 }
7263 };
7264 static const struct message WmVkF10Seq[] = {
7265 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7266 { WM_SYSKEYDOWN, wparam|lparam, VK_F10, 1 },
7267 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_F10, 0x00000001 },
7268 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7269 { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7270 { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7271 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_KEYMENU },
7272 { HCBT_SYSCOMMAND, hook },
7273 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7274 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
7275 { WM_INITMENU, sent|defwinproc },
7276 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7277 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
7278 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7279
7280 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0x10000001 }, /* XP */
7281
7282 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7283 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7284 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
7285 { WM_CAPTURECHANGED, sent|defwinproc },
7286 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
7287 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
7288 { WM_EXITMENULOOP, sent|defwinproc },
7289 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7290 { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7291 { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7292 { 0 }
7293 };
7294 static const struct message WmShiftF10Seq[] = {
7295 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
7296 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
7297 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x00000001 },
7298 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
7299 { WM_SYSKEYDOWN, wparam|lparam, VK_F10, 1 },
7300 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_F10, 0x00000001 },
7301 { WM_CONTEXTMENU, sent|defwinproc|lparam, /*hwnd*/0, -1 },
7302 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
7303 { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
7304 { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
7305 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_KEYMENU },
7306 { HCBT_SYSCOMMAND, hook },
7307 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7308 { WM_INITMENU, sent|defwinproc },
7309 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
7310 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xd0000001 }, /* XP */
7311 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0x10000001 }, /* XP */
7312 { WM_CAPTURECHANGED, sent|defwinproc|wparam|lparam, 0, 0 },
7313 { WM_MENUSELECT, sent|defwinproc|wparam|lparam, 0xffff0000, 0 },
7314 { WM_EXITMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
7315 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0xc0000001 }, /* XP */
7316 { WM_KEYUP, wparam|lparam, VK_ESCAPE, 0xc0000001 },
7317 { WM_KEYUP, sent|wparam|lparam, VK_ESCAPE, 0xc0000001 },
7318 { 0 }
7319 };
7320
7321 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
7322 {
7323 MSG msg;
7324
7325 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
7326 {
7327 struct recvd_message log_msg;
7328
7329 /* ignore some unwanted messages */
7330 if (msg.message == WM_MOUSEMOVE ||
7331 msg.message == WM_TIMER ||
7332 ignore_message( msg.message ))
7333 continue;
7334
7335 log_msg.hwnd = msg.hwnd;
7336 log_msg.message = msg.message;
7337 log_msg.flags = wparam|lparam;
7338 log_msg.wParam = msg.wParam;
7339 log_msg.lParam = msg.lParam;
7340 log_msg.descr = "accel";
7341 add_message(&log_msg);
7342
7343 if (!hAccel || !TranslateAcceleratorA(hwnd, hAccel, &msg))
7344 {
7345 TranslateMessage(&msg);
7346 DispatchMessageA(&msg);
7347 }
7348 }
7349 }
7350
7351 static void test_accelerators(void)
7352 {
7353 RECT rc;
7354 POINT pt;
7355 SHORT state;
7356 HACCEL hAccel;
7357 HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7358 100, 100, 200, 200, 0, 0, 0, NULL);
7359 BOOL ret;
7360
7361 assert(hwnd != 0);
7362 UpdateWindow(hwnd);
7363 flush_events();
7364 flush_sequence();
7365
7366 SetFocus(hwnd);
7367 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
7368
7369 state = GetKeyState(VK_SHIFT);
7370 ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
7371 state = GetKeyState(VK_CAPITAL);
7372 ok(state == 0, "wrong CapsLock state %04x\n", state);
7373
7374 hAccel = LoadAcceleratorsA(GetModuleHandleA(NULL), MAKEINTRESOURCEA(1));
7375 assert(hAccel != 0);
7376
7377 flush_events();
7378 pump_msg_loop(hwnd, 0);
7379 flush_sequence();
7380
7381 trace("testing VK_N press/release\n");
7382 flush_sequence();
7383 keybd_event('N', 0, 0, 0);
7384 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7385 pump_msg_loop(hwnd, hAccel);
7386 if (!sequence_cnt) /* we didn't get any message */
7387 {
7388 skip( "queuing key events not supported\n" );
7389 goto done;
7390 }
7391 ok_sequence(WmVkN, "VK_N press/release", FALSE);
7392
7393 trace("testing Shift+VK_N press/release\n");
7394 flush_sequence();
7395 keybd_event(VK_SHIFT, 0, 0, 0);
7396 keybd_event('N', 0, 0, 0);
7397 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7398 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7399 pump_msg_loop(hwnd, hAccel);
7400 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
7401
7402 trace("testing Ctrl+VK_N press/release\n");
7403 flush_sequence();
7404 keybd_event(VK_CONTROL, 0, 0, 0);
7405 keybd_event('N', 0, 0, 0);
7406 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7407 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7408 pump_msg_loop(hwnd, hAccel);
7409 ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
7410
7411 trace("testing Alt+VK_N press/release\n");
7412 flush_sequence();
7413 keybd_event(VK_MENU, 0, 0, 0);
7414 keybd_event('N', 0, 0, 0);
7415 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7416 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7417 pump_msg_loop(hwnd, hAccel);
7418 ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
7419
7420 trace("testing Ctrl+Alt+VK_N press/release 1\n");
7421 flush_sequence();
7422 keybd_event(VK_CONTROL, 0, 0, 0);
7423 keybd_event(VK_MENU, 0, 0, 0);
7424 keybd_event('N', 0, 0, 0);
7425 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7426 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7427 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7428 pump_msg_loop(hwnd, hAccel);
7429 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
7430
7431 ret = DestroyAcceleratorTable(hAccel);
7432 ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7433
7434 hAccel = LoadAcceleratorsA(GetModuleHandleA(NULL), MAKEINTRESOURCEA(2));
7435 assert(hAccel != 0);
7436
7437 trace("testing VK_N press/release\n");
7438 flush_sequence();
7439 keybd_event('N', 0, 0, 0);
7440 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7441 pump_msg_loop(hwnd, hAccel);
7442 ok_sequence(WmVkN, "VK_N press/release", FALSE);
7443
7444 trace("testing Shift+VK_N press/release\n");
7445 flush_sequence();
7446 keybd_event(VK_SHIFT, 0, 0, 0);
7447 keybd_event('N', 0, 0, 0);
7448 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7449 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7450 pump_msg_loop(hwnd, hAccel);
7451 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
7452
7453 trace("testing Ctrl+VK_N press/release 2\n");
7454 flush_sequence();
7455 keybd_event(VK_CONTROL, 0, 0, 0);
7456 keybd_event('N', 0, 0, 0);
7457 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7458 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7459 pump_msg_loop(hwnd, hAccel);
7460 ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
7461
7462 trace("testing Alt+VK_N press/release 2\n");
7463 flush_sequence();
7464 keybd_event(VK_MENU, 0, 0, 0);
7465 keybd_event('N', 0, 0, 0);
7466 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7467 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7468 pump_msg_loop(hwnd, hAccel);
7469 ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
7470
7471 trace("testing Ctrl+Alt+VK_N press/release 2\n");
7472 flush_sequence();
7473 keybd_event(VK_CONTROL, 0, 0, 0);
7474 keybd_event(VK_MENU, 0, 0, 0);
7475 keybd_event('N', 0, 0, 0);
7476 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7477 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7478 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7479 pump_msg_loop(hwnd, hAccel);
7480 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
7481
7482 trace("testing Ctrl+Shift+VK_N press/release\n");
7483 flush_sequence();
7484 keybd_event(VK_CONTROL, 0, 0, 0);
7485 keybd_event(VK_SHIFT, 0, 0, 0);
7486 keybd_event('N', 0, 0, 0);
7487 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7488 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7489 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7490 pump_msg_loop(hwnd, hAccel);
7491 ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
7492
7493 trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
7494 flush_sequence();
7495 keybd_event(VK_CONTROL, 0, 0, 0);
7496 keybd_event(VK_MENU, 0, 0, 0);
7497 keybd_event(VK_SHIFT, 0, 0, 0);
7498 keybd_event('N', 0, 0, 0);
7499 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7500 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7501 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7502 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7503 pump_msg_loop(hwnd, hAccel);
7504 ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
7505
7506 ret = DestroyAcceleratorTable(hAccel);
7507 ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7508 hAccel = 0;
7509
7510 trace("testing Alt press/release\n");
7511 flush_sequence();
7512 keybd_event(VK_MENU, 0, 0, 0);
7513 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7514 keybd_event(VK_MENU, 0, 0, 0);
7515 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7516 pump_msg_loop(hwnd, 0);
7517 /* this test doesn't pass in Wine for managed windows */
7518 ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
7519
7520 trace("testing VK_F1 press/release\n");
7521 keybd_event(VK_F1, 0, 0, 0);
7522 keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
7523 pump_msg_loop(hwnd, 0);
7524 ok_sequence(WmF1Seq, "F1 press/release", FALSE);
7525
7526 trace("testing VK_APPS press/release\n");
7527 keybd_event(VK_APPS, 0, 0, 0);
7528 keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
7529 pump_msg_loop(hwnd, 0);
7530 ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
7531
7532 trace("testing VK_F10 press/release\n");
7533 keybd_event(VK_F10, 0, 0, 0);
7534 keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7535 keybd_event(VK_F10, 0, 0, 0);
7536 keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7537 pump_msg_loop(hwnd, 0);
7538 ok_sequence(WmVkF10Seq, "VK_F10 press/release", TRUE);
7539
7540 trace("testing SHIFT+F10 press/release\n");
7541 keybd_event(VK_SHIFT, 0, 0, 0);
7542 keybd_event(VK_F10, 0, 0, 0);
7543 keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7544 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7545 keybd_event(VK_ESCAPE, 0, 0, 0);
7546 keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0);
7547 pump_msg_loop(hwnd, 0);
7548 ok_sequence(WmShiftF10Seq, "SHIFT+F10 press/release", TRUE);
7549
7550 trace("testing Shift+MouseButton press/release\n");
7551 /* first, move mouse pointer inside of the window client area */
7552 GetClientRect(hwnd, &rc);
7553 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
7554 rc.left += (rc.right - rc.left)/2;
7555 rc.top += (rc.bottom - rc.top)/2;
7556 SetCursorPos(rc.left, rc.top);
7557 SetActiveWindow(hwnd);
7558
7559 flush_events();
7560 flush_sequence();
7561 GetCursorPos(&pt);
7562 if (pt.x == rc.left && pt.y == rc.top)
7563 {
7564 int i;
7565 keybd_event(VK_SHIFT, 0, 0, 0);
7566 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
7567 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7568 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7569 pump_msg_loop(hwnd, 0);
7570 for (i = 0; i < sequence_cnt; i++) if (sequence[i].message == WM_LBUTTONDOWN) break;
7571 if (i < sequence_cnt)
7572 ok_sequence(WmShiftMouseButton, "Shift+MouseButton press/release", FALSE);
7573 else
7574 skip( "Shift+MouseButton event didn't get to the window\n" );
7575 }
7576
7577 done:
7578 if (hAccel) DestroyAcceleratorTable(hAccel);
7579 DestroyWindow(hwnd);
7580 }
7581
7582 /************* window procedures ********************/
7583
7584 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message,
7585 WPARAM wParam, LPARAM lParam)
7586 {
7587 static LONG defwndproc_counter = 0;
7588 static LONG beginpaint_counter = 0;
7589 LRESULT ret;
7590 struct recvd_message msg;
7591
7592 if (ignore_message( message )) return 0;
7593
7594 switch (message)
7595 {
7596 case WM_ENABLE:
7597 {
7598 LONG style = GetWindowLongA(hwnd, GWL_STYLE);
7599 ok((BOOL)wParam == !(style & WS_DISABLED),
7600 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
7601 break;
7602 }
7603
7604 case WM_CAPTURECHANGED:
7605 if (test_DestroyWindow_flag)
7606 {
7607 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7608 if (style & WS_CHILD)
7609 lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7610 else if (style & WS_POPUP)
7611 lParam = WND_POPUP_ID;
7612 else
7613 lParam = WND_PARENT_ID;
7614 }
7615 break;
7616
7617 case WM_NCDESTROY:
7618 {
7619 HWND capture;
7620
7621 ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
7622 capture = GetCapture();
7623 if (capture)
7624 {
7625 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
7626 trace("current capture %p, releasing...\n", capture);
7627 ReleaseCapture();
7628 }
7629 }
7630 /* fall through */
7631 case WM_DESTROY:
7632 if (pGetAncestor)
7633 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
7634 if (test_DestroyWindow_flag)
7635 {
7636 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7637 if (style & WS_CHILD)
7638 lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7639 else if (style & WS_POPUP)
7640 lParam = WND_POPUP_ID;
7641 else
7642 lParam = WND_PARENT_ID;
7643 }
7644 break;
7645
7646 /* test_accelerators() depends on this */
7647 case WM_NCHITTEST:
7648 return HTCLIENT;
7649
7650 case WM_USER+10:
7651 {
7652 HANDLE handle, event = (HANDLE)lParam;
7653 BOOL ret;
7654
7655 handle = (void*)0xdeadbeef;
7656 ret = pGetCurrentActCtx(&handle);
7657 ok(ret, "failed to get current context, %u\n", GetLastError());
7658 ok(handle == 0, "got active context %p\n", handle);
7659 if (event) SetEvent(event);
7660 return 1;
7661 }
7662
7663 /* ignore */
7664 case WM_MOUSEMOVE:
7665 case WM_MOUSEACTIVATE:
7666 case WM_NCMOUSEMOVE:
7667 case WM_SETCURSOR:
7668 case WM_IME_SELECT:
7669 return 0;
7670 }
7671
7672 msg.hwnd = hwnd;
7673 msg.message = message;
7674 msg.flags = sent|wparam|lparam;
7675 if (defwndproc_counter) msg.flags |= defwinproc;
7676 if (beginpaint_counter) msg.flags |= beginpaint;
7677 msg.wParam = wParam;
7678 msg.lParam = lParam;
7679 msg.descr = "MsgCheckProc";
7680 add_message(&msg);
7681
7682 if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
7683 {
7684 HWND parent = GetParent(hwnd);
7685 RECT rc;
7686 MINMAXINFO *minmax = (MINMAXINFO *)lParam;
7687
7688 GetClientRect(parent, &rc);
7689 trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
7690 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
7691 minmax->ptReserved.x, minmax->ptReserved.y,
7692 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
7693 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
7694 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
7695 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
7696
7697 ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
7698 minmax->ptMaxSize.x, rc.right);
7699 ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
7700 minmax->ptMaxSize.y, rc.bottom);
7701 }
7702
7703 if (message == WM_PAINT)
7704 {
7705 PAINTSTRUCT ps;
7706 beginpaint_counter++;
7707 BeginPaint( hwnd, &ps );
7708 beginpaint_counter--;
7709 EndPaint( hwnd, &ps );
7710 return 0;
7711 }
7712
7713 defwndproc_counter++;
7714 ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam)
7715 : DefWindowProcA(hwnd, message, wParam, lParam);
7716 defwndproc_counter--;
7717
7718 return ret;
7719 }
7720
7721 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7722 {
7723 return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
7724 }
7725
7726 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7727 {
7728 return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
7729 }
7730
7731 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7732 {
7733 static LONG defwndproc_counter = 0;
7734 LRESULT ret;
7735 struct recvd_message msg;
7736
7737 if (ignore_message( message )) return 0;
7738
7739 switch (message)
7740 {
7741 case WM_QUERYENDSESSION:
7742 case WM_ENDSESSION:
7743 lParam &= ~0x01; /* Vista adds a 0x01 flag */
7744 break;
7745 }
7746
7747 msg.hwnd = hwnd;
7748 msg.message = message;
7749 msg.flags = sent|wparam|lparam;
7750 if (defwndproc_counter) msg.flags |= defwinproc;
7751 msg.wParam = wParam;
7752 msg.lParam = lParam;
7753 msg.descr = "popup";
7754 add_message(&msg);
7755
7756 if (message == WM_CREATE)
7757 {
7758 DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
7759 SetWindowLongA(hwnd, GWL_STYLE, style);
7760 }
7761
7762 defwndproc_counter++;
7763 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7764 defwndproc_counter--;
7765
7766 return ret;
7767 }
7768
7769 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7770 {
7771 static LONG defwndproc_counter = 0;
7772 static LONG beginpaint_counter = 0;
7773 LRESULT ret;
7774 struct recvd_message msg;
7775
7776 if (ignore_message( message )) return 0;
7777
7778 if (log_all_parent_messages ||
7779 message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
7780 message == WM_SETFOCUS || message == WM_KILLFOCUS ||
7781 message == WM_ENABLE || message == WM_ENTERIDLE ||
7782 message == WM_DRAWITEM || message == WM_COMMAND ||
7783 message == WM_IME_SETCONTEXT)
7784 {
7785 switch (message)
7786 {
7787 /* ignore */
7788 case WM_NCHITTEST:
7789 return HTCLIENT;
7790 case WM_SETCURSOR:
7791 case WM_MOUSEMOVE:
7792 case WM_NCMOUSEMOVE:
7793 return 0;
7794
7795 case WM_ERASEBKGND:
7796 {
7797 RECT rc;
7798 INT ret = GetClipBox((HDC)wParam, &rc);
7799
7800 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
7801 ret, rc.left, rc.top, rc.right, rc.bottom);
7802 break;
7803 }
7804 }
7805
7806 msg.hwnd = hwnd;
7807 msg.message = message;
7808 msg.flags = sent|parent|wparam|lparam;
7809 if (defwndproc_counter) msg.flags |= defwinproc;
7810 if (beginpaint_counter) msg.flags |= beginpaint;
7811 msg.wParam = wParam;
7812 msg.lParam = lParam;
7813 msg.descr = "parent";
7814 add_message(&msg);
7815 }
7816
7817 if (message == WM_PAINT)
7818 {
7819 PAINTSTRUCT ps;
7820 beginpaint_counter++;
7821 BeginPaint( hwnd, &ps );
7822 beginpaint_counter--;
7823 EndPaint( hwnd, &ps );
7824 return 0;
7825 }
7826
7827 defwndproc_counter++;
7828 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7829 defwndproc_counter--;
7830
7831 return ret;
7832 }
7833
7834 static INT_PTR CALLBACK StopQuitMsgCheckProcA(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
7835 {
7836 if (message == WM_CREATE)
7837 PostMessageA(hwnd, WM_CLOSE, 0, 0);
7838 else if (message == WM_CLOSE)
7839 {
7840 /* Only the first WM_QUIT will survive the window destruction */
7841 PostMessageA(hwnd, WM_USER, 0x1234, 0x5678);
7842 PostMessageA(hwnd, WM_QUIT, 0x1234, 0x5678);
7843 PostMessageA(hwnd, WM_QUIT, 0x4321, 0x8765);
7844 }
7845
7846 return DefWindowProcA(hwnd, message, wp, lp);
7847 }
7848
7849 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7850 {
7851 static LONG defwndproc_counter = 0;
7852 LRESULT ret;
7853 struct recvd_message msg;
7854
7855 if (ignore_message( message )) return 0;
7856
7857 if (test_def_id)
7858 {
7859 DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
7860 ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
7861 if (after_end_dialog)
7862 ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
7863 else
7864 ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
7865 }
7866
7867 msg.hwnd = hwnd;
7868 msg.message = message;
7869 msg.flags = sent|wparam|lparam;
7870 if (defwndproc_counter) msg.flags |= defwinproc;
7871 msg.wParam = wParam;
7872 msg.lParam = lParam;
7873 msg.descr = "dialog";
7874 add_message(&msg);
7875
7876 defwndproc_counter++;
7877 ret = DefDlgProcA(hwnd, message, wParam, lParam);
7878 defwndproc_counter--;
7879
7880 return ret;
7881 }
7882
7883 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7884 {
7885 static LONG defwndproc_counter = 0;
7886 LRESULT ret;
7887 struct recvd_message msg;
7888
7889 /* log only specific messages we are interested in */
7890 switch (message)
7891 {
7892 #if 0 /* probably log these as well */
7893 case WM_ACTIVATE:
7894 case WM_SETFOCUS:
7895 case WM_KILLFOCUS:
7896 #endif
7897 case WM_SHOWWINDOW:
7898 case WM_SIZE:
7899 case WM_MOVE:
7900 case WM_GETMINMAXINFO:
7901 case WM_WINDOWPOSCHANGING:
7902 case WM_WINDOWPOSCHANGED:
7903 break;
7904
7905 default: /* ignore */
7906 /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
7907 return DefWindowProcA(hwnd, message, wParam, lParam);
7908 }
7909
7910 msg.hwnd = hwnd;
7911 msg.message = message;
7912 msg.flags = sent|wparam|lparam;
7913 if (defwndproc_counter) msg.flags |= defwinproc;
7914 msg.wParam = wParam;
7915 msg.lParam = lParam;
7916 msg.descr = "show";
7917 add_message(&msg);
7918
7919 defwndproc_counter++;
7920 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7921 defwndproc_counter--;
7922
7923 return ret;
7924 }
7925
7926 static LRESULT WINAPI PaintLoopProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
7927 {
7928 switch (msg)
7929 {
7930 case WM_CREATE: return 0;
7931 case WM_PAINT:
7932 {
7933 MSG msg2;
7934 static int i = 0;
7935
7936 if (i < 256)
7937 {
7938 i++;
7939 if (PeekMessageA(&msg2, 0, 0, 0, 1))
7940 {
7941 TranslateMessage(&msg2);
7942 DispatchMessageA(&msg2);
7943 }
7944 i--;
7945 }
7946 else ok(broken(1), "infinite loop\n");
7947 if ( i == 0)
7948 paint_loop_done = TRUE;
7949 return DefWindowProcA(hWnd,msg,wParam,lParam);
7950 }
7951 }
7952 return DefWindowProcA(hWnd,msg,wParam,lParam);
7953 }
7954
7955 static LRESULT WINAPI HotkeyMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7956 {
7957 static LONG defwndproc_counter = 0;
7958 LRESULT ret;
7959 struct recvd_message msg;
7960 DWORD queue_status;
7961
7962 if (ignore_message( message )) return 0;
7963
7964 if ((message >= WM_KEYFIRST && message <= WM_KEYLAST) ||
7965 message == WM_HOTKEY || message >= WM_APP)
7966 {
7967 msg.hwnd = hwnd;
7968 msg.message = message;
7969 msg.flags = sent|wparam|lparam;
7970 if (defwndproc_counter) msg.flags |= defwinproc;
7971 msg.wParam = wParam;
7972 msg.lParam = lParam;
7973 msg.descr = "HotkeyMsgCheckProcA";
7974 add_message(&msg);
7975 }
7976
7977 defwndproc_counter++;
7978 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7979 defwndproc_counter--;
7980
7981 if (message == WM_APP)
7982 {
7983 queue_status = GetQueueStatus(QS_HOTKEY);
7984 ok((queue_status & (QS_HOTKEY << 16)) == QS_HOTKEY << 16, "expected QS_HOTKEY << 16 set, got %x\n", queue_status);
7985 queue_status = GetQueueStatus(QS_POSTMESSAGE);
7986 ok((queue_status & (QS_POSTMESSAGE << 16)) == QS_POSTMESSAGE << 16, "expected QS_POSTMESSAGE << 16 set, got %x\n", queue_status);
7987 PostMessageA(hwnd, WM_APP+1, 0, 0);
7988 }
7989 else if (message == WM_APP+1)
7990 {
7991 queue_status = GetQueueStatus(QS_HOTKEY);
7992 ok((queue_status & (QS_HOTKEY << 16)) == 0, "expected QS_HOTKEY << 16 cleared, got %x\n", queue_status);
7993 }
7994
7995 return ret;
7996 }
7997
7998 static BOOL RegisterWindowClasses(void)
7999 {
8000 WNDCLASSA cls;
8001 WNDCLASSW clsW;
8002
8003 cls.style = 0;
8004 cls.lpfnWndProc = MsgCheckProcA;
8005 cls.cbClsExtra = 0;
8006 cls.cbWndExtra = 0;
8007 cls.hInstance = GetModuleHandleA(0);
8008 cls.hIcon = 0;
8009 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
8010 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
8011 cls.lpszMenuName = NULL;
8012 cls.lpszClassName = "TestWindowClass";
8013 if(!RegisterClassA(&cls)) return FALSE;
8014
8015 cls.lpfnWndProc = HotkeyMsgCheckProcA;
8016 cls.lpszClassName = "HotkeyWindowClass";
8017 if(!RegisterClassA(&cls)) return FALSE;
8018
8019 cls.lpfnWndProc = ShowWindowProcA;
8020 cls.lpszClassName = "ShowWindowClass";
8021 if(!RegisterClassA(&cls)) return FALSE;
8022
8023 cls.lpfnWndProc = PopupMsgCheckProcA;
8024 cls.lpszClassName = "TestPopupClass";
8025 if(!RegisterClassA(&cls)) return FALSE;
8026
8027 cls.lpfnWndProc = ParentMsgCheckProcA;
8028 cls.lpszClassName = "TestParentClass";
8029 if(!RegisterClassA(&cls)) return FALSE;
8030
8031 cls.lpfnWndProc = StopQuitMsgCheckProcA;
8032 cls.lpszClassName = "StopQuitClass";
8033 if(!RegisterClassA(&cls)) return FALSE;
8034
8035 cls.lpfnWndProc = DefWindowProcA;
8036 cls.lpszClassName = "SimpleWindowClass";
8037 if(!RegisterClassA(&cls)) return FALSE;
8038
8039 cls.lpfnWndProc = PaintLoopProcA;
8040 cls.lpszClassName = "PaintLoopWindowClass";
8041 if(!RegisterClassA(&cls)) return FALSE;
8042
8043 cls.style = CS_NOCLOSE;
8044 cls.lpszClassName = "NoCloseWindowClass";
8045 if(!RegisterClassA(&cls)) return FALSE;
8046
8047 ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
8048 cls.style = 0;
8049 cls.hInstance = GetModuleHandleA(0);
8050 cls.hbrBackground = 0;
8051 cls.lpfnWndProc = TestDlgProcA;
8052 cls.lpszClassName = "TestDialogClass";
8053 if(!RegisterClassA(&cls)) return FALSE;
8054
8055 clsW.style = 0;
8056 clsW.lpfnWndProc = MsgCheckProcW;
8057 clsW.cbClsExtra = 0;
8058 clsW.cbWndExtra = 0;
8059 clsW.hInstance = GetModuleHandleW(0);
8060 clsW.hIcon = 0;
8061 clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
8062 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
8063 clsW.lpszMenuName = NULL;
8064 clsW.lpszClassName = testWindowClassW;
8065 RegisterClassW(&clsW); /* ignore error, this fails on Win9x */
8066
8067 return TRUE;
8068 }
8069
8070 static BOOL is_our_logged_class(HWND hwnd)
8071 {
8072 char buf[256];
8073
8074 if (GetClassNameA(hwnd, buf, sizeof(buf)))
8075 {
8076 if (!lstrcmpiA(buf, "TestWindowClass") ||
8077 !lstrcmpiA(buf, "ShowWindowClass") ||
8078 !lstrcmpiA(buf, "TestParentClass") ||
8079 !lstrcmpiA(buf, "TestPopupClass") ||
8080 !lstrcmpiA(buf, "SimpleWindowClass") ||
8081 !lstrcmpiA(buf, "TestDialogClass") ||
8082 !lstrcmpiA(buf, "MDI_frame_class") ||
8083 !lstrcmpiA(buf, "MDI_client_class") ||
8084 !lstrcmpiA(buf, "MDI_child_class") ||
8085 !lstrcmpiA(buf, "my_button_class") ||
8086 !lstrcmpiA(buf, "my_edit_class") ||
8087 !lstrcmpiA(buf, "static") ||
8088 !lstrcmpiA(buf, "ListBox") ||
8089 !lstrcmpiA(buf, "ComboBox") ||
8090 !lstrcmpiA(buf, "MyDialogClass") ||
8091 !lstrcmpiA(buf, "#32770") ||
8092 !lstrcmpiA(buf, "#32768"))
8093 return TRUE;
8094 }
8095 return FALSE;
8096 }
8097
8098 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
8099 {
8100 HWND hwnd;
8101
8102 ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
8103
8104 if (nCode == HCBT_CLICKSKIPPED)
8105 {
8106 /* ignore this event, XP sends it a lot when switching focus between windows */
8107 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
8108 }
8109
8110 if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
8111 {
8112 struct recvd_message msg;
8113
8114 msg.hwnd = 0;
8115 msg.message = nCode;
8116 msg.flags = hook|wparam|lparam;
8117 msg.wParam = wParam;
8118 msg.lParam = lParam;
8119 msg.descr = "CBT";
8120 add_message(&msg);
8121
8122 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
8123 }
8124
8125 if (nCode == HCBT_DESTROYWND)
8126 {
8127 if (test_DestroyWindow_flag)
8128 {
8129 DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
8130 if (style & WS_CHILD)
8131 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
8132 else if (style & WS_POPUP)
8133 lParam = WND_POPUP_ID;
8134 else
8135 lParam = WND_PARENT_ID;
8136 }
8137 }
8138
8139 /* Log also SetFocus(0) calls */
8140 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
8141
8142 if (is_our_logged_class(hwnd))
8143 {
8144 struct recvd_message msg;
8145
8146 msg.hwnd = hwnd;
8147 msg.message = nCode;
8148 msg.flags = hook|wparam|lparam;
8149 msg.wParam = wParam;
8150 msg.lParam = lParam;
8151 msg.descr = "CBT";
8152 add_message(&msg);
8153 }
8154 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
8155 }
8156
8157 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
8158 DWORD event,
8159 HWND hwnd,
8160 LONG object_id,
8161 LONG child_id,
8162 DWORD thread_id,
8163 DWORD event_time)
8164 {
8165 ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
8166
8167 /* ignore mouse cursor events */
8168 if (object_id == OBJID_CURSOR) return;
8169
8170 if (!hwnd || is_our_logged_class(hwnd))
8171 {
8172 struct recvd_message msg;
8173
8174 msg.hwnd = hwnd;
8175 msg.message = event;
8176 msg.flags = winevent_hook|wparam|lparam;
8177 msg.wParam = object_id;
8178 msg.lParam = child_id;
8179 msg.descr = "WEH";
8180 add_message(&msg);
8181 }
8182 }
8183
8184 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
8185 static const WCHAR wszAnsi[] = {'U',0};
8186
8187 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
8188 {
8189 switch (uMsg)
8190 {
8191 case CB_FINDSTRINGEXACT:
8192 trace("String: %p\n", (LPCWSTR)lParam);
8193 if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
8194 return 1;
8195 if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
8196 return 0;
8197 return -1;
8198 }
8199 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
8200 }
8201
8202 static const struct message WmGetTextLengthAfromW[] = {
8203 { WM_GETTEXTLENGTH, sent },
8204 { WM_GETTEXT, sent|optional },
8205 { 0 }
8206 };
8207
8208 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
8209
8210 /* dummy window proc for WM_GETTEXTLENGTH test */
8211 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
8212 {
8213 switch(msg)
8214 {
8215 case WM_GETTEXTLENGTH:
8216 return lstrlenW(dummy_window_text) + 37; /* some random length */
8217 case WM_GETTEXT:
8218 lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
8219 return lstrlenW( (LPWSTR)lp );
8220 default:
8221 return DefWindowProcW( hwnd, msg, wp, lp );
8222 }
8223 }
8224
8225 static void test_message_conversion(void)
8226 {
8227 static const WCHAR wszMsgConversionClass[] =
8228 {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
8229 WNDCLASSW cls;
8230 LRESULT lRes;
8231 HWND hwnd;
8232 WNDPROC wndproc, newproc;
8233 BOOL ret;
8234
8235 cls.style = 0;
8236 cls.lpfnWndProc = MsgConversionProcW;
8237 cls.cbClsExtra = 0;
8238 cls.cbWndExtra = 0;
8239 cls.hInstance = GetModuleHandleW(NULL);
8240 cls.hIcon = NULL;
8241 cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
8242 cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
8243 cls.lpszMenuName = NULL;
8244 cls.lpszClassName = wszMsgConversionClass;
8245 /* this call will fail on Win9x, but that doesn't matter as this test is
8246 * meaningless on those platforms */
8247 if(!RegisterClassW(&cls)) return;
8248
8249 hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
8250 100, 100, 200, 200, 0, 0, 0, NULL);
8251 ok(hwnd != NULL, "Window creation failed\n");
8252
8253 /* {W, A} -> A */
8254
8255 wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
8256 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8257 ok(lRes == 0, "String should have been converted\n");
8258 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8259 ok(lRes == 1, "String shouldn't have been converted\n");
8260
8261 /* {W, A} -> W */
8262
8263 wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
8264 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8265 ok(lRes == 1, "String shouldn't have been converted\n");
8266 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8267 ok(lRes == 1, "String shouldn't have been converted\n");
8268
8269 /* Synchronous messages */
8270
8271 lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8272 ok(lRes == 0, "String should have been converted\n");
8273 lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8274 ok(lRes == 1, "String shouldn't have been converted\n");
8275
8276 /* Asynchronous messages */
8277
8278 SetLastError(0);
8279 lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8280 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8281 "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8282 SetLastError(0);
8283 lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8284 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8285 "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8286 SetLastError(0);
8287 lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8288 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8289 "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8290 SetLastError(0);
8291 lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8292 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8293 "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8294 SetLastError(0);
8295 lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8296 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8297 "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8298 SetLastError(0);
8299 lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
8300 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8301 "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8302 SetLastError(0);
8303 lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
8304 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8305 "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8306 SetLastError(0);
8307 lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
8308 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
8309 "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
8310
8311 /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
8312
8313 hwnd = CreateWindowW (testWindowClassW, wszUnicode,
8314 WS_OVERLAPPEDWINDOW,
8315 100, 100, 200, 200, 0, 0, 0, NULL);
8316 assert(hwnd);
8317 flush_sequence();
8318 lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
8319 ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
8320 ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
8321 "got bad length %ld\n", lRes );
8322
8323 flush_sequence();
8324 lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
8325 hwnd, WM_GETTEXTLENGTH, 0, 0);
8326 ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
8327 ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
8328 "got bad length %ld\n", lRes );
8329
8330 wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
8331 newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
8332 lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
8333 ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
8334 NULL, 0, NULL, NULL ) ||
8335 broken(lRes == lstrlenW(dummy_window_text) + 37),
8336 "got bad length %ld\n", lRes );
8337
8338 SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc ); /* restore old wnd proc */
8339 lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
8340 ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
8341 NULL, 0, NULL, NULL ) ||
8342 broken(lRes == lstrlenW(dummy_window_text) + 37),
8343 "got bad length %ld\n", lRes );
8344
8345 ret = DestroyWindow(hwnd);
8346 ok( ret, "DestroyWindow() error %d\n", GetLastError());
8347 }
8348
8349 struct timer_info
8350 {
8351 HWND hWnd;
8352 HANDLE handles[2];
8353 DWORD id;
8354 };
8355
8356 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
8357 {
8358 }
8359
8360 #define TIMER_ID 0x19
8361 #define TIMER_COUNT_EXPECTED 100
8362 #define TIMER_COUNT_TOLERANCE 10
8363
8364 static int count = 0;
8365 static void CALLBACK callback_count(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
8366 {
8367 count++;
8368 }
8369
8370 static DWORD exception;
8371 static void CALLBACK callback_exception(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
8372 {
8373 count++;
8374 RaiseException(exception, 0, 0, NULL);
8375 }
8376
8377 static DWORD WINAPI timer_thread_proc(LPVOID x)
8378 {
8379 struct timer_info *info = x;
8380 DWORD r;
8381
8382 r = KillTimer(info->hWnd, 0x19);
8383 ok(r,"KillTimer failed in thread\n");
8384 r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
8385 ok(r,"SetTimer failed in thread\n");
8386 ok(r==TIMER_ID,"SetTimer id different\n");
8387 r = SetEvent(info->handles[0]);
8388 ok(r,"SetEvent failed in thread\n");
8389 return 0;
8390 }
8391
8392 static void test_timers(void)
8393 {
8394 struct timer_info info;
8395 DWORD start;
8396 DWORD id;
8397 MSG msg;
8398
8399 info.hWnd = CreateWindowA("TestWindowClass", NULL,
8400 WS_OVERLAPPEDWINDOW ,
8401 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8402 NULL, NULL, 0);
8403
8404 info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
8405 ok(info.id, "SetTimer failed\n");
8406 ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
8407 info.handles[0] = CreateEventW(NULL,0,0,NULL);
8408 info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
8409
8410 WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
8411
8412 WaitForSingleObject(info.handles[1], INFINITE);
8413
8414 CloseHandle(info.handles[0]);
8415 CloseHandle(info.handles[1]);
8416
8417 ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
8418
8419 /* Check the minimum allowed timeout for a timer. MSDN indicates that it should be 10.0 ms,
8420 * which occurs sometimes, but most testing on the VMs indicates a minimum timeout closer to
8421 * 15.6 ms. Since there is some measurement error between test runs we are allowing for
8422 * ±9 counts (~4 ms) around the expected value.
8423 */
8424 count = 0;
8425 id = SetTimer(info.hWnd, TIMER_ID, 0, callback_count);
8426 ok(id != 0, "did not get id from SetTimer.\n");
8427 ok(id==TIMER_ID, "SetTimer timer ID different\n");
8428 start = GetTickCount();
8429 while (GetTickCount()-start < 1001 && GetMessageA(&msg, info.hWnd, 0, 0))
8430 DispatchMessageA(&msg);
8431 ok(abs(count-TIMER_COUNT_EXPECTED) < TIMER_COUNT_TOLERANCE /* xp */
8432 || broken(abs(count-64) < TIMER_COUNT_TOLERANCE) /* most common */
8433 || broken(abs(count-43) < TIMER_COUNT_TOLERANCE) /* w2k3, win8 */,
8434 "did not get expected count for minimum timeout (%d != ~%d).\n",
8435 count, TIMER_COUNT_EXPECTED);
8436 ok(KillTimer(info.hWnd, id), "KillTimer failed\n");
8437 /* Perform the same check on SetSystemTimer (only available on w2k3 and older) */
8438 if (pSetSystemTimer)
8439 {
8440 int syscount = 0;
8441
8442 count = 0;
8443 id = pSetSystemTimer(info.hWnd, TIMER_ID, 0, callback_count);
8444 ok(id != 0, "did not get id from SetSystemTimer.\n");
8445 ok(id==TIMER_ID, "SetTimer timer ID different\n");
8446 start = GetTickCount();
8447 while (GetTickCount()-start < 1001 && GetMessageA(&msg, info.hWnd, 0, 0))
8448 {
8449 if (msg.message == WM_SYSTIMER)
8450 syscount++;
8451 DispatchMessageA(&msg);
8452 }
8453 ok(abs(syscount-TIMER_COUNT_EXPECTED) < TIMER_COUNT_TOLERANCE
8454 || broken(abs(syscount-64) < TIMER_COUNT_TOLERANCE) /* most common */
8455 || broken(syscount > 4000 && syscount < 12000) /* win2k3sp0 */,
8456 "did not get expected count for minimum timeout (%d != ~%d).\n",
8457 syscount, TIMER_COUNT_EXPECTED);
8458 todo_wine ok(count == 0, "did not get expected count for callback timeout (%d != 0).\n",
8459 count);
8460 ok(pKillSystemTimer(info.hWnd, id), "KillSystemTimer failed\n");
8461 }
8462
8463 ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
8464 }
8465
8466 static void test_timers_no_wnd(void)
8467 {
8468 UINT_PTR id, id2;
8469 DWORD start;
8470 MSG msg;
8471
8472 count = 0;
8473 id = SetTimer(NULL, 0, 100, callback_count);
8474 ok(id != 0, "did not get id from SetTimer.\n");
8475 id2 = SetTimer(NULL, id, 200, callback_count);
8476 ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
8477 Sleep(150);
8478 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
8479 ok(count == 0, "did not get zero count as expected (%i).\n", count);
8480 Sleep(150);
8481 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
8482 ok(count == 1, "did not get one count as expected (%i).\n", count);
8483 KillTimer(NULL, id);
8484 Sleep(250);
8485 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
8486 ok(count == 1, "killing replaced timer did not work (%i).\n", count);
8487
8488 /* Check the minimum allowed timeout for a timer. MSDN indicates that it should be 10.0 ms,
8489 * which occurs sometimes, but most testing on the VMs indicates a minimum timeout closer to
8490 * 15.6 ms. Since there is some measurement error between test runs we are allowing for
8491 * ±9 counts (~4 ms) around the expected value.
8492 */
8493 count = 0;
8494 id = SetTimer(NULL, 0, 0, callback_count);
8495 ok(id != 0, "did not get id from SetTimer.\n");
8496 start = GetTickCount();
8497 while (GetTickCount()-start < 1001 && GetMessageA(&msg, NULL, 0, 0))
8498 DispatchMessageA(&msg);
8499 ok(abs(count-TIMER_COUNT_EXPECTED) < TIMER_COUNT_TOLERANCE /* xp */
8500 || broken(abs(count-64) < TIMER_COUNT_TOLERANCE) /* most common */,
8501 "did not get expected count for minimum timeout (%d != ~%d).\n",
8502 count, TIMER_COUNT_EXPECTED);
8503 KillTimer(NULL, id);
8504 /* Note: SetSystemTimer doesn't support a NULL window, see test_timers */
8505 }
8506
8507 static void test_timers_exception(DWORD code)
8508 {
8509 UINT_PTR id;
8510 MSG msg;
8511
8512 exception = code;
8513 id = SetTimer(NULL, 0, 1000, callback_exception);
8514 ok(id != 0, "did not get id from SetTimer.\n");
8515
8516 memset(&msg, 0, sizeof(msg));
8517 msg.message = WM_TIMER;
8518 msg.wParam = id;
8519 msg.lParam = (LPARAM)callback_exception;
8520
8521 count = 0;
8522 DispatchMessageA(&msg);
8523 ok(count == 1, "did not get one count as expected (%i).\n", count);
8524
8525 KillTimer(NULL, id);
8526 }
8527
8528 static void test_timers_exceptions(void)
8529 {
8530 test_timers_exception(EXCEPTION_ACCESS_VIOLATION);
8531 test_timers_exception(EXCEPTION_DATATYPE_MISALIGNMENT);
8532 test_timers_exception(EXCEPTION_BREAKPOINT);
8533 test_timers_exception(EXCEPTION_SINGLE_STEP);
8534 test_timers_exception(EXCEPTION_ARRAY_BOUNDS_EXCEEDED);
8535 test_timers_exception(EXCEPTION_FLT_DENORMAL_OPERAND);
8536 test_timers_exception(EXCEPTION_FLT_DIVIDE_BY_ZERO);
8537 test_timers_exception(EXCEPTION_FLT_INEXACT_RESULT);
8538 test_timers_exception(EXCEPTION_ILLEGAL_INSTRUCTION);
8539 test_timers_exception(0xE000BEEF); /* customer exception */
8540 }
8541
8542 /* Various win events with arbitrary parameters */
8543 static const struct message WmWinEventsSeq[] = {
8544 { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
8545 { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
8546 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
8547 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
8548 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
8549 { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
8550 { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
8551 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
8552 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
8553 /* our win event hook ignores OBJID_CURSOR events */
8554 /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
8555 { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
8556 { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
8557 { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
8558 { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
8559 { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
8560 { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
8561 { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
8562 { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
8563 { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
8564 { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
8565 { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
8566 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
8567 { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
8568 { 0 }
8569 };
8570 static const struct message WmWinEventCaretSeq[] = {
8571 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8572 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8573 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
8574 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
8575 { 0 }
8576 };
8577 static const struct message WmWinEventCaretSeq_2[] = {
8578 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8579 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8580 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
8581 { 0 }
8582 };
8583 static const struct message WmWinEventAlertSeq[] = {
8584 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
8585 { 0 }
8586 };
8587 static const struct message WmWinEventAlertSeq_2[] = {
8588 /* create window in the thread proc */
8589 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
8590 /* our test event */
8591 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
8592 { 0 }
8593 };
8594 static const struct message WmGlobalHookSeq_1[] = {
8595 /* create window in the thread proc */
8596 { HCBT_CREATEWND, hook|lparam, 0, 2 },
8597 /* our test events */
8598 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
8599 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
8600 { 0 }
8601 };
8602 static const struct message WmGlobalHookSeq_2[] = {
8603 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
8604 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
8605 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
8606 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
8607 { 0 }
8608 };
8609
8610 static const struct message WmMouseLLHookSeq[] = {
8611 { WM_MOUSEMOVE, hook },
8612 { WM_LBUTTONUP, hook },
8613 { WM_MOUSEMOVE, hook },
8614 { 0 }
8615 };
8616
8617 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
8618 DWORD event,
8619 HWND hwnd,
8620 LONG object_id,
8621 LONG child_id,
8622 DWORD thread_id,
8623 DWORD event_time)
8624 {
8625 char buf[256];
8626
8627 if (GetClassNameA(hwnd, buf, sizeof(buf)))
8628 {
8629 if (!lstrcmpiA(buf, "TestWindowClass") ||
8630 !lstrcmpiA(buf, "static"))
8631 {
8632 struct recvd_message msg;
8633
8634 msg.hwnd = hwnd;
8635 msg.message = event;
8636 msg.flags = winevent_hook|wparam|lparam;
8637 msg.wParam = object_id;
8638 msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
8639 msg.descr = "WEH_2";
8640 add_message(&msg);
8641 }
8642 }
8643 }
8644
8645 static HHOOK hCBT_global_hook;
8646 static DWORD cbt_global_hook_thread_id;
8647
8648 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
8649 {
8650 HWND hwnd;
8651 char buf[256];
8652
8653 if (nCode == HCBT_SYSCOMMAND)
8654 {
8655 struct recvd_message msg;
8656
8657 msg.hwnd = 0;
8658 msg.message = nCode;
8659 msg.flags = hook|wparam|lparam;
8660 msg.wParam = wParam;
8661 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8662 msg.descr = "CBT_2";
8663 add_message(&msg);
8664
8665 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8666 }
8667 /* WH_MOUSE_LL hook */
8668 if (nCode == HC_ACTION)
8669 {
8670 MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
8671
8672 /* we can't test for real mouse events */
8673 if (mhll->flags & LLMHF_INJECTED)
8674 {
8675 struct recvd_message msg;
8676
8677 memset (&msg, 0, sizeof (msg));
8678 msg.message = wParam;
8679 msg.flags = hook;
8680 msg.descr = "CBT_2";
8681 add_message(&msg);
8682 }
8683 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8684 }
8685
8686 /* Log also SetFocus(0) calls */
8687 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
8688
8689 if (GetClassNameA(hwnd, buf, sizeof(buf)))
8690 {
8691 if (!lstrcmpiA(buf, "TestWindowClass") ||
8692 !lstrcmpiA(buf, "static"))
8693 {
8694 struct recvd_message msg;
8695
8696 msg.hwnd = hwnd;
8697 msg.message = nCode;
8698 msg.flags = hook|wparam|lparam;
8699 msg.wParam = wParam;
8700 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8701 msg.descr = "CBT_2";
8702 add_message(&msg);
8703 }
8704 }
8705 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8706 }
8707
8708 static DWORD WINAPI win_event_global_thread_proc(void *param)
8709 {
8710 HWND hwnd;
8711 MSG msg;
8712 HANDLE hevent = *(HANDLE *)param;
8713
8714 assert(pNotifyWinEvent);
8715
8716 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8717 assert(hwnd);
8718 trace("created thread window %p\n", hwnd);
8719
8720 *(HWND *)param = hwnd;
8721
8722 flush_sequence();
8723 /* this event should be received only by our new hook proc,
8724 * an old one does not expect an event from another thread.
8725 */
8726 pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
8727 SetEvent(hevent);
8728
8729 while (GetMessageA(&msg, 0, 0, 0))
8730 {
8731 TranslateMessage(&msg);
8732 DispatchMessageA(&msg);
8733 }
8734 return 0;
8735 }
8736
8737 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
8738 {
8739 HWND hwnd;
8740 MSG msg;
8741 HANDLE hevent = *(HANDLE *)param;
8742
8743 flush_sequence();
8744 /* these events should be received only by our new hook proc,
8745 * an old one does not expect an event from another thread.
8746 */
8747
8748 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8749 assert(hwnd);
8750 trace("created thread window %p\n", hwnd);
8751
8752 *(HWND *)param = hwnd;
8753
8754 /* Windows doesn't like when a thread plays games with the focus,
8755 that leads to all kinds of misbehaviours and failures to activate
8756 a window. So, better keep next lines commented out.
8757 SetFocus(0);
8758 SetFocus(hwnd);*/
8759
8760 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8761 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8762
8763 SetEvent(hevent);
8764
8765 while (GetMessageA(&msg, 0, 0, 0))
8766 {
8767 TranslateMessage(&msg);
8768 DispatchMessageA(&msg);
8769 }
8770 return 0;
8771 }
8772
8773 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
8774 {
8775 HWND hwnd;
8776 MSG msg;
8777 HANDLE hevent = *(HANDLE *)param;
8778
8779 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8780 assert(hwnd);
8781 trace("created thread window %p\n", hwnd);
8782
8783 *(HWND *)param = hwnd;
8784
8785 flush_sequence();
8786
8787 /* Windows doesn't like when a thread plays games with the focus,
8788 * that leads to all kinds of misbehaviours and failures to activate
8789 * a window. So, better don't generate a mouse click message below.
8790 */
8791 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8792 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8793 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8794
8795 SetEvent(hevent);
8796 while (GetMessageA(&msg, 0, 0, 0))
8797 {
8798 TranslateMessage(&msg);
8799 DispatchMessageA(&msg);
8800 }
8801 return 0;
8802 }
8803
8804 static void test_winevents(void)
8805 {
8806 BOOL ret;
8807 MSG msg;
8808 HWND hwnd, hwnd2;
8809 UINT i;
8810 HANDLE hthread, hevent;
8811 DWORD tid;
8812 HWINEVENTHOOK hhook;
8813 const struct message *events = WmWinEventsSeq;
8814
8815 hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
8816 WS_OVERLAPPEDWINDOW,
8817 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8818 NULL, NULL, 0);
8819 assert(hwnd);
8820
8821 /****** start of global hook test *************/
8822 hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8823 if (!hCBT_global_hook)
8824 {
8825 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8826 skip( "cannot set global hook\n" );
8827 return;
8828 }
8829
8830 hevent = CreateEventA(NULL, 0, 0, NULL);
8831 assert(hevent);
8832 hwnd2 = hevent;
8833
8834 hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
8835 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8836
8837 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8838
8839 ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
8840
8841 flush_sequence();
8842 /* this one should be received only by old hook proc */
8843 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8844 /* this one should be received only by old hook proc */
8845 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8846
8847 ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
8848
8849 ret = UnhookWindowsHookEx(hCBT_global_hook);
8850 ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8851
8852 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8853 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8854 CloseHandle(hthread);
8855 CloseHandle(hevent);
8856 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8857 /****** end of global hook test *************/
8858
8859 if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
8860 {
8861 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8862 return;
8863 }
8864
8865 flush_sequence();
8866
8867 if (0)
8868 {
8869 /* this test doesn't pass under Win9x */
8870 /* win2k ignores events with hwnd == 0 */
8871 SetLastError(0xdeadbeef);
8872 pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
8873 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
8874 GetLastError() == 0xdeadbeef, /* Win9x */
8875 "unexpected error %d\n", GetLastError());
8876 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8877 }
8878
8879 for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
8880 pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
8881
8882 ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
8883
8884 /****** start of event filtering test *************/
8885 hhook = pSetWinEventHook(
8886 EVENT_OBJECT_SHOW, /* 0x8002 */
8887 EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
8888 GetModuleHandleA(0), win_event_global_hook_proc,
8889 GetCurrentProcessId(), 0,
8890 WINEVENT_INCONTEXT);
8891 ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8892
8893 hevent = CreateEventA(NULL, 0, 0, NULL);
8894 assert(hevent);
8895 hwnd2 = hevent;
8896
8897 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8898 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8899
8900 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8901
8902 ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
8903
8904 flush_sequence();
8905 /* this one should be received only by old hook proc */
8906 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8907 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8908 /* this one should be received only by old hook proc */
8909 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8910
8911 ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
8912
8913 ret = pUnhookWinEvent(hhook);
8914 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8915
8916 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8917 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8918 CloseHandle(hthread);
8919 CloseHandle(hevent);
8920 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8921 /****** end of event filtering test *************/
8922
8923 /****** start of out of context event test *************/
8924 hhook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0,
8925 win_event_global_hook_proc, GetCurrentProcessId(), 0,
8926 WINEVENT_OUTOFCONTEXT);
8927 ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8928
8929 hevent = CreateEventA(NULL, 0, 0, NULL);
8930 assert(hevent);
8931 hwnd2 = hevent;
8932
8933 flush_sequence();
8934
8935 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8936 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8937
8938 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8939
8940 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8941 /* process pending winevent messages */
8942 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8943 ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
8944
8945 flush_sequence();
8946 /* this one should be received only by old hook proc */
8947 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8948 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8949 /* this one should be received only by old hook proc */
8950 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8951
8952 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
8953 /* process pending winevent messages */
8954 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8955 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
8956
8957 ret = pUnhookWinEvent(hhook);
8958 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8959
8960 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8961 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8962 CloseHandle(hthread);
8963 CloseHandle(hevent);
8964 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8965 /****** end of out of context event test *************/
8966
8967 /****** start of MOUSE_LL hook test *************/
8968 hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8969 /* WH_MOUSE_LL is not supported on Win9x platforms */
8970 if (!hCBT_global_hook)
8971 {
8972 win_skip("Skipping WH_MOUSE_LL test on this platform\n");
8973 goto skip_mouse_ll_hook_test;
8974 }
8975
8976 hevent = CreateEventA(NULL, 0, 0, NULL);
8977 assert(hevent);
8978 hwnd2 = hevent;
8979
8980 hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
8981 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8982
8983 while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
8984 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
8985
8986 ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
8987 flush_sequence();
8988
8989 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8990 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8991 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8992
8993 ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
8994
8995 ret = UnhookWindowsHookEx(hCBT_global_hook);
8996 ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8997
8998 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8999 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
9000 CloseHandle(hthread);
9001 CloseHandle(hevent);
9002 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
9003 /****** end of MOUSE_LL hook test *************/
9004 skip_mouse_ll_hook_test:
9005
9006 ok(DestroyWindow(hwnd), "failed to destroy window\n");
9007 }
9008
9009 static void test_set_hook(void)
9010 {
9011 BOOL ret;
9012 HHOOK hhook;
9013 HWINEVENTHOOK hwinevent_hook;
9014
9015 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
9016 ok(hhook != 0, "local hook does not require hModule set to 0\n");
9017 UnhookWindowsHookEx(hhook);
9018
9019 if (0)
9020 {
9021 /* this test doesn't pass under Win9x: BUG! */
9022 SetLastError(0xdeadbeef);
9023 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
9024 ok(!hhook, "global hook requires hModule != 0\n");
9025 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
9026 }
9027
9028 SetLastError(0xdeadbeef);
9029 hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
9030 ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
9031 ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
9032 GetLastError() == 0xdeadbeef, /* Win9x */
9033 "unexpected error %d\n", GetLastError());
9034
9035 SetLastError(0xdeadbeef);
9036 ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
9037 ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
9038 GetLastError() == 0xdeadbeef, /* Win9x */
9039 "unexpected error %d\n", GetLastError());
9040
9041 if (!pSetWinEventHook || !pUnhookWinEvent) return;
9042
9043 /* even process local incontext hooks require hmodule */
9044 SetLastError(0xdeadbeef);
9045 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
9046 GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
9047 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
9048 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
9049 GetLastError() == 0xdeadbeef, /* Win9x */
9050 "unexpected error %d\n", GetLastError());
9051
9052 /* even thread local incontext hooks require hmodule */
9053 SetLastError(0xdeadbeef);
9054 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
9055 GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
9056 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
9057 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
9058 GetLastError() == 0xdeadbeef, /* Win9x */
9059 "unexpected error %d\n", GetLastError());
9060
9061 if (0)
9062 {
9063 /* these 3 tests don't pass under Win9x */
9064 SetLastError(0xdeadbeef);
9065 hwinevent_hook = pSetWinEventHook(1, 0, 0, win_event_proc,
9066 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
9067 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
9068 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
9069
9070 SetLastError(0xdeadbeef);
9071 hwinevent_hook = pSetWinEventHook(-1, 1, 0, win_event_proc,
9072 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
9073 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
9074 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
9075
9076 SetLastError(0xdeadbeef);
9077 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
9078 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
9079 ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
9080 ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
9081 }
9082
9083 SetLastError(0xdeadbeef);
9084 hwinevent_hook = pSetWinEventHook(0, 0, 0, win_event_proc,
9085 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
9086 ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
9087 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
9088 ret = pUnhookWinEvent(hwinevent_hook);
9089 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
9090
9091 todo_wine {
9092 /* This call succeeds under win2k SP4, but fails under Wine.
9093 Does win2k test/use passed process id? */
9094 SetLastError(0xdeadbeef);
9095 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
9096 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
9097 ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
9098 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
9099 ret = pUnhookWinEvent(hwinevent_hook);
9100 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
9101 }
9102
9103 SetLastError(0xdeadbeef);
9104 ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
9105 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
9106 GetLastError() == 0xdeadbeef, /* Win9x */
9107 "unexpected error %d\n", GetLastError());
9108 }
9109
9110 static const struct message ScrollWindowPaint1[] = {
9111 { WM_PAINT, sent },
9112 { WM_ERASEBKGND, sent|beginpaint },
9113 { WM_GETTEXTLENGTH, sent|optional },
9114 { WM_PAINT, sent|optional },
9115 { WM_NCPAINT, sent|beginpaint|optional },
9116 { WM_GETTEXT, sent|beginpaint|optional },
9117 { WM_GETTEXT, sent|beginpaint|optional },
9118 { WM_GETTEXT, sent|beginpaint|optional },
9119 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
9120 { WM_ERASEBKGND, sent|beginpaint|optional },
9121 { 0 }
9122 };
9123
9124 static const struct message ScrollWindowPaint2[] = {
9125 { WM_PAINT, sent },
9126 { 0 }
9127 };
9128
9129 static void test_scrollwindowex(void)
9130 {
9131 HWND hwnd, hchild;
9132 RECT rect={0,0,130,130};
9133
9134 hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
9135 WS_VISIBLE|WS_OVERLAPPEDWINDOW,
9136 100, 100, 200, 200, 0, 0, 0, NULL);
9137 ok (hwnd != 0, "Failed to create overlapped window\n");
9138 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
9139 WS_VISIBLE|WS_CAPTION|WS_CHILD,
9140 10, 10, 150, 150, hwnd, 0, 0, NULL);
9141 ok (hchild != 0, "Failed to create child\n");
9142 UpdateWindow(hwnd);
9143 flush_events();
9144 flush_sequence();
9145
9146 /* scroll without the child window */
9147 trace("start scroll\n");
9148 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
9149 SW_ERASE|SW_INVALIDATE);
9150 ok_sequence(WmEmptySeq, "ScrollWindowEx", FALSE);
9151 trace("end scroll\n");
9152 flush_sequence();
9153 flush_events();
9154 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", FALSE);
9155 flush_events();
9156 flush_sequence();
9157
9158 /* Now without the SW_ERASE flag */
9159 trace("start scroll\n");
9160 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
9161 ok_sequence(WmEmptySeq, "ScrollWindowEx", FALSE);
9162 trace("end scroll\n");
9163 flush_sequence();
9164 flush_events();
9165 ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", FALSE);
9166 flush_events();
9167 flush_sequence();
9168
9169 /* now scroll the child window as well */
9170 trace("start scroll\n");
9171 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
9172 SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
9173 /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
9174 /* windows sometimes a WM_MOVE */
9175 ok_sequence(WmEmptySeq, "ScrollWindowEx", TRUE);
9176 trace("end scroll\n");
9177 flush_sequence();
9178 flush_events();
9179 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", FALSE);
9180 flush_events();
9181 flush_sequence();
9182
9183 /* now scroll with ScrollWindow() */
9184 trace("start scroll with ScrollWindow\n");
9185 ScrollWindow( hwnd, 5, 5, NULL, NULL);
9186 trace("end scroll\n");
9187 flush_sequence();
9188 flush_events();
9189 ok_sequence(ScrollWindowPaint1, "ScrollWindow", FALSE);
9190
9191 ok(DestroyWindow(hchild), "failed to destroy window\n");
9192 ok(DestroyWindow(hwnd), "failed to destroy window\n");
9193 flush_sequence();
9194 }
9195
9196 static const struct message destroy_window_with_children[] = {
9197 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
9198 { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
9199 { 0x0090, sent|optional },
9200 { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
9201 { 0x0090, sent|optional },
9202 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
9203 { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
9204 { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
9205 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
9206 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
9207 { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
9208 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
9209 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
9210 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
9211 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
9212 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
9213 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
9214 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
9215 { 0 }
9216 };
9217
9218 static void test_DestroyWindow(void)
9219 {
9220 BOOL ret;
9221 HWND parent, child1, child2, child3, child4, test;
9222 UINT_PTR child_id = WND_CHILD_ID + 1;
9223
9224 parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9225 100, 100, 200, 200, 0, 0, 0, NULL);
9226 assert(parent != 0);
9227 child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
9228 0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
9229 assert(child1 != 0);
9230 child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
9231 0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
9232 assert(child2 != 0);
9233 child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
9234 0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
9235 assert(child3 != 0);
9236 child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
9237 0, 0, 50, 50, parent, 0, 0, NULL);
9238 assert(child4 != 0);
9239
9240 /* test owner/parent of child2 */
9241 test = GetParent(child2);
9242 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
9243 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
9244 if(pGetAncestor) {
9245 test = pGetAncestor(child2, GA_PARENT);
9246 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
9247 }
9248 test = GetWindow(child2, GW_OWNER);
9249 ok(!test, "wrong owner %p\n", test);
9250
9251 test = SetParent(child2, parent);
9252 ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
9253
9254 /* test owner/parent of the parent */
9255 test = GetParent(parent);
9256 ok(!test, "wrong parent %p\n", test);
9257 ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
9258 if(pGetAncestor) {
9259 test = pGetAncestor(parent, GA_PARENT);
9260 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
9261 }
9262 test = GetWindow(parent, GW_OWNER);
9263 ok(!test, "wrong owner %p\n", test);
9264
9265 /* test owner/parent of child1 */
9266 test = GetParent(child1);
9267 ok(test == parent, "wrong parent %p\n", test);
9268 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
9269 if(pGetAncestor) {
9270 test = pGetAncestor(child1, GA_PARENT);
9271 ok(test == parent, "wrong parent %p\n", test);
9272 }
9273 test = GetWindow(child1, GW_OWNER);
9274 ok(!test, "wrong owner %p\n", test);
9275
9276 /* test owner/parent of child2 */
9277 test = GetParent(child2);
9278 ok(test == parent, "wrong parent %p\n", test);
9279 ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
9280 if(pGetAncestor) {
9281 test = pGetAncestor(child2, GA_PARENT);
9282 ok(test == parent, "wrong parent %p\n", test);
9283 }
9284 test = GetWindow(child2, GW_OWNER);
9285 ok(!test, "wrong owner %p\n", test);
9286
9287 /* test owner/parent of child3 */
9288 test = GetParent(child3);
9289 ok(test == child1, "wrong parent %p\n", test);
9290 ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
9291 if(pGetAncestor) {
9292 test = pGetAncestor(child3, GA_PARENT);
9293 ok(test == child1, "wrong parent %p\n", test);
9294 }
9295 test = GetWindow(child3, GW_OWNER);
9296 ok(!test, "wrong owner %p\n", test);
9297
9298 /* test owner/parent of child4 */
9299 test = GetParent(child4);
9300 ok(test == parent, "wrong parent %p\n", test);
9301 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
9302 if(pGetAncestor) {
9303 test = pGetAncestor(child4, GA_PARENT);
9304 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
9305 }
9306 test = GetWindow(child4, GW_OWNER);
9307 ok(test == parent, "wrong owner %p\n", test);
9308
9309 flush_sequence();
9310
9311 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
9312 parent, child1, child2, child3, child4);
9313
9314 SetCapture(child4);
9315 test = GetCapture();
9316 ok(test == child4, "wrong capture window %p\n", test);
9317
9318 test_DestroyWindow_flag = TRUE;
9319 ret = DestroyWindow(parent);
9320 ok( ret, "DestroyWindow() error %d\n", GetLastError());
9321 test_DestroyWindow_flag = FALSE;
9322 ok_sequence(destroy_window_with_children, "destroy window with children", FALSE);
9323
9324 ok(!IsWindow(parent), "parent still exists\n");
9325 ok(!IsWindow(child1), "child1 still exists\n");
9326 ok(!IsWindow(child2), "child2 still exists\n");
9327 ok(!IsWindow(child3), "child3 still exists\n");
9328 ok(!IsWindow(child4), "child4 still exists\n");
9329
9330 test = GetCapture();
9331 ok(!test, "wrong capture window %p\n", test);
9332 }
9333
9334
9335 static const struct message WmDispatchPaint[] = {
9336 { WM_NCPAINT, sent },
9337 { WM_GETTEXT, sent|defwinproc|optional },
9338 { WM_GETTEXT, sent|defwinproc|optional },
9339 { WM_ERASEBKGND, sent },
9340 { 0 }
9341 };
9342
9343 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9344 {
9345 if (message == WM_PAINT) return 0;
9346 return MsgCheckProcA( hwnd, message, wParam, lParam );
9347 }
9348
9349 static void test_DispatchMessage(void)
9350 {
9351 RECT rect;
9352 MSG msg;
9353 int count;
9354 HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9355 100, 100, 200, 200, 0, 0, 0, NULL);
9356 ShowWindow( hwnd, SW_SHOW );
9357 UpdateWindow( hwnd );
9358 flush_events();
9359 flush_sequence();
9360 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
9361
9362 SetRect( &rect, -5, -5, 5, 5 );
9363 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
9364 count = 0;
9365 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ))
9366 {
9367 if (msg.message != WM_PAINT) DispatchMessageA( &msg );
9368 else
9369 {
9370 flush_sequence();
9371 DispatchMessageA( &msg );
9372 /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
9373 if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
9374 else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
9375 if (++count > 10) break;
9376 }
9377 }
9378 ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
9379
9380 trace("now without DispatchMessage\n");
9381 flush_sequence();
9382 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
9383 count = 0;
9384 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ))
9385 {
9386 if (msg.message != WM_PAINT) DispatchMessageA( &msg );
9387 else
9388 {
9389 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
9390 flush_sequence();
9391 /* this will send WM_NCCPAINT just like DispatchMessage does */
9392 GetUpdateRgn( hwnd, hrgn, TRUE );
9393 ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
9394 DeleteObject( hrgn );
9395 GetClientRect( hwnd, &rect );
9396 ValidateRect( hwnd, &rect ); /* this will stop WM_PAINTs */
9397 ok( !count, "Got multiple WM_PAINTs\n" );
9398 if (++count > 10) break;
9399 }
9400 }
9401
9402 flush_sequence();
9403 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
9404 count = 0;
9405 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ))
9406 {
9407 if (msg.message != WM_PAINT) DispatchMessageA( &msg );
9408 else
9409 {
9410 HDC hdc;
9411
9412 flush_sequence();
9413 hdc = BeginPaint( hwnd, NULL );
9414 ok( !hdc, "got valid hdc %p from BeginPaint\n", hdc );
9415 ok( !EndPaint( hwnd, NULL ), "EndPaint succeeded\n" );
9416 ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
9417 ok( !count, "Got multiple WM_PAINTs\n" );
9418 if (++count > 10) break;
9419 }
9420 }
9421 DestroyWindow(hwnd);
9422 }
9423
9424
9425 static const struct message WmUser[] = {
9426 { WM_USER, sent },
9427 { 0 }
9428 };
9429
9430 struct sendmsg_info
9431 {
9432 HWND hwnd;
9433 DWORD timeout;
9434 DWORD ret;
9435 };
9436
9437 static DWORD CALLBACK send_msg_thread( LPVOID arg )
9438 {
9439 struct sendmsg_info *info = arg;
9440 SetLastError( 0xdeadbeef );
9441 info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
9442 if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT ||
9443 broken(GetLastError() == 0), /* win9x */
9444 "unexpected error %d\n", GetLastError());
9445 return 0;
9446 }
9447
9448 static void wait_for_thread( HANDLE thread )
9449 {
9450 while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
9451 {
9452 MSG msg;
9453 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA(&msg);
9454 }
9455 }
9456
9457 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9458 {
9459 if (message == WM_USER) Sleep(200);
9460 return MsgCheckProcA( hwnd, message, wParam, lParam );
9461 }
9462
9463 static void test_SendMessageTimeout(void)
9464 {
9465 HANDLE thread;
9466 struct sendmsg_info info;
9467 DWORD tid;
9468 BOOL is_win9x;
9469
9470 info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9471 100, 100, 200, 200, 0, 0, 0, NULL);
9472 flush_events();
9473 flush_sequence();
9474
9475 info.timeout = 1000;
9476 info.ret = 0xdeadbeef;
9477 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9478 wait_for_thread( thread );
9479 CloseHandle( thread );
9480 ok( info.ret == 1, "SendMessageTimeout failed\n" );
9481 ok_sequence( WmUser, "WmUser", FALSE );
9482
9483 info.timeout = 1;
9484 info.ret = 0xdeadbeef;
9485 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9486 Sleep(100); /* SendMessageTimeout should time out here */
9487 wait_for_thread( thread );
9488 CloseHandle( thread );
9489 ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
9490 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9491
9492 /* 0 means infinite timeout (but not on win9x) */
9493 info.timeout = 0;
9494 info.ret = 0xdeadbeef;
9495 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9496 Sleep(100);
9497 wait_for_thread( thread );
9498 CloseHandle( thread );
9499 is_win9x = !info.ret;
9500 if (is_win9x) ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9501 else ok_sequence( WmUser, "WmUser", FALSE );
9502
9503 /* timeout is treated as signed despite the prototype (but not on win9x) */
9504 info.timeout = 0x7fffffff;
9505 info.ret = 0xdeadbeef;
9506 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9507 Sleep(100);
9508 wait_for_thread( thread );
9509 CloseHandle( thread );
9510 ok( info.ret == 1, "SendMessageTimeout failed\n" );
9511 ok_sequence( WmUser, "WmUser", FALSE );
9512
9513 info.timeout = 0x80000000;
9514 info.ret = 0xdeadbeef;
9515 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9516 Sleep(100);
9517 wait_for_thread( thread );
9518 CloseHandle( thread );
9519 if (is_win9x)
9520 {
9521 ok( info.ret == 1, "SendMessageTimeout failed\n" );
9522 ok_sequence( WmUser, "WmUser", FALSE );
9523 }
9524 else
9525 {
9526 ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
9527 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
9528 }
9529
9530 /* now check for timeout during message processing */
9531 SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
9532 info.timeout = 100;
9533 info.ret = 0xdeadbeef;
9534 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
9535 wait_for_thread( thread );
9536 CloseHandle( thread );
9537 /* we should time out but still get the message */
9538 ok( info.ret == 0, "SendMessageTimeout failed\n" );
9539 ok_sequence( WmUser, "WmUser", FALSE );
9540
9541 DestroyWindow( info.hwnd );
9542 }
9543
9544
9545 /****************** edit message test *************************/
9546 #define ID_EDIT 0x1234
9547 static const struct message sl_edit_setfocus[] =
9548 {
9549 { HCBT_SETFOCUS, hook },
9550 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9551 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9552 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9553 { WM_SETFOCUS, sent|wparam, 0 },
9554 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9555 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
9556 { WM_CTLCOLOREDIT, sent|parent },
9557 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9558 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9559 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9560 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9561 { 0 }
9562 };
9563 static const struct message sl_edit_invisible[] =
9564 {
9565 { HCBT_SETFOCUS, hook },
9566 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9567 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9568 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9569 { WM_KILLFOCUS, sent|parent },
9570 { WM_SETFOCUS, sent },
9571 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9572 { 0 }
9573 };
9574 static const struct message ml_edit_setfocus[] =
9575 {
9576 { HCBT_SETFOCUS, hook },
9577 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
9578 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9579 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9580 { WM_SETFOCUS, sent|wparam, 0 },
9581 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9582 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9583 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9584 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9585 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9586 { 0 }
9587 };
9588 static const struct message sl_edit_killfocus[] =
9589 {
9590 { HCBT_SETFOCUS, hook },
9591 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9592 { WM_KILLFOCUS, sent|wparam, 0 },
9593 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9594 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9595 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
9596 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
9597 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
9598 { 0 }
9599 };
9600 static const struct message sl_edit_lbutton_dblclk[] =
9601 {
9602 { WM_LBUTTONDBLCLK, sent },
9603 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9604 { 0 }
9605 };
9606 static const struct message sl_edit_lbutton_down[] =
9607 {
9608 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
9609 { HCBT_SETFOCUS, hook },
9610 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9611 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9612 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9613 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9614 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9615 { WM_CTLCOLOREDIT, sent|parent },
9616 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9617 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9618 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9619 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9620 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9621 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9622 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9623 { WM_CTLCOLOREDIT, sent|parent|optional },
9624 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9625 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9626 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9627 { 0 }
9628 };
9629 static const struct message ml_edit_lbutton_down[] =
9630 {
9631 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
9632 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9633 { HCBT_SETFOCUS, hook },
9634 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9635 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9636 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9637 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9638 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9639 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9640 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9641 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9642 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9643 { 0 }
9644 };
9645 static const struct message sl_edit_lbutton_up[] =
9646 {
9647 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9648 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9649 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9650 { WM_CAPTURECHANGED, sent|defwinproc },
9651 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9652 { 0 }
9653 };
9654 static const struct message ml_edit_lbutton_up[] =
9655 {
9656 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9657 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9658 { WM_CAPTURECHANGED, sent|defwinproc },
9659 { 0 }
9660 };
9661
9662 static WNDPROC old_edit_proc;
9663
9664 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9665 {
9666 static LONG defwndproc_counter = 0;
9667 LRESULT ret;
9668 struct recvd_message msg;
9669
9670 if (ignore_message( message )) return 0;
9671
9672 msg.hwnd = hwnd;
9673 msg.message = message;
9674 msg.flags = sent|wparam|lparam;
9675 if (defwndproc_counter) msg.flags |= defwinproc;
9676 msg.wParam = wParam;
9677 msg.lParam = lParam;
9678 msg.descr = "edit";
9679 add_message(&msg);
9680
9681 defwndproc_counter++;
9682 ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
9683 defwndproc_counter--;
9684
9685 return ret;
9686 }
9687
9688 static void subclass_edit(void)
9689 {
9690 WNDCLASSA cls;
9691
9692 if (!GetClassInfoA(0, "edit", &cls)) assert(0);
9693
9694 old_edit_proc = cls.lpfnWndProc;
9695
9696 cls.hInstance = GetModuleHandleA(NULL);
9697 cls.lpfnWndProc = edit_hook_proc;
9698 cls.lpszClassName = "my_edit_class";
9699 UnregisterClassA(cls.lpszClassName, cls.hInstance);
9700 if (!RegisterClassA(&cls)) assert(0);
9701 }
9702
9703 static void test_edit_messages(void)
9704 {
9705 HWND hwnd, parent;
9706 DWORD dlg_code;
9707
9708 subclass_edit();
9709 log_all_parent_messages++;
9710
9711 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9712 100, 100, 200, 200, 0, 0, 0, NULL);
9713 ok (parent != 0, "Failed to create parent window\n");
9714
9715 /* test single line edit */
9716 hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
9717 0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9718 ok(hwnd != 0, "Failed to create edit window\n");
9719
9720 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9721 ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
9722
9723 flush_sequence();
9724 SetFocus(hwnd);
9725 ok_sequence(sl_edit_invisible, "SetFocus(hwnd) on an invisible edit", FALSE);
9726
9727 ShowWindow(hwnd, SW_SHOW);
9728 UpdateWindow(hwnd);
9729 SetFocus(0);
9730 flush_sequence();
9731
9732 SetFocus(hwnd);
9733 ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
9734
9735 SetFocus(0);
9736 ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
9737
9738 SetFocus(0);
9739 ReleaseCapture();
9740 flush_sequence();
9741
9742 SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9743 ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
9744
9745 SetFocus(0);
9746 ReleaseCapture();
9747 flush_sequence();
9748
9749 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9750 ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
9751
9752 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9753 ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
9754
9755 DestroyWindow(hwnd);
9756
9757 /* test multiline edit */
9758 hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
9759 0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9760 ok(hwnd != 0, "Failed to create edit window\n");
9761
9762 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9763 ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
9764 "wrong dlg_code %08x\n", dlg_code);
9765
9766 ShowWindow(hwnd, SW_SHOW);
9767 UpdateWindow(hwnd);
9768 SetFocus(0);
9769 flush_sequence();
9770
9771 SetFocus(hwnd);
9772 ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
9773
9774 SetFocus(0);
9775 ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
9776
9777 SetFocus(0);
9778 ReleaseCapture();
9779 flush_sequence();
9780
9781 SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9782 ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
9783
9784 SetFocus(0);
9785 ReleaseCapture();
9786 flush_sequence();
9787
9788 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9789 ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
9790
9791 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9792 ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
9793
9794 DestroyWindow(hwnd);
9795 DestroyWindow(parent);
9796
9797 log_all_parent_messages--;
9798 }
9799
9800 /**************************** End of Edit test ******************************/
9801
9802 static const struct message WmKeyDownSkippedSeq[] =
9803 {
9804 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
9805 { 0 }
9806 };
9807 static const struct message WmKeyDownWasDownSkippedSeq[] =
9808 {
9809 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x40000001 }, /* XP */
9810 { 0 }
9811 };
9812 static const struct message WmKeyUpSkippedSeq[] =
9813 {
9814 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9815 { 0 }
9816 };
9817 static const struct message WmUserKeyUpSkippedSeq[] =
9818 {
9819 { WM_USER, sent },
9820 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9821 { 0 }
9822 };
9823
9824 #define EV_STOP 0
9825 #define EV_SENDMSG 1
9826 #define EV_ACK 2
9827
9828 struct peekmsg_info
9829 {
9830 HWND hwnd;
9831 HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
9832 };
9833
9834 static DWORD CALLBACK send_msg_thread_2(void *param)
9835 {
9836 DWORD ret;
9837 struct peekmsg_info *info = param;
9838
9839 trace("thread: looping\n");
9840 SetEvent(info->hevent[EV_ACK]);
9841
9842 while (1)
9843 {
9844 ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
9845
9846 switch (ret)
9847 {
9848 case WAIT_OBJECT_0 + EV_STOP:
9849 trace("thread: exiting\n");
9850 return 0;
9851
9852 case WAIT_OBJECT_0 + EV_SENDMSG:
9853 trace("thread: sending message\n");
9854 ret = SendNotifyMessageA(info->hwnd, WM_USER, 0, 0);
9855 ok(ret, "SendNotifyMessageA failed error %u\n", GetLastError());
9856 SetEvent(info->hevent[EV_ACK]);
9857 break;
9858
9859 default:
9860 trace("unexpected return: %04x\n", ret);
9861 assert(0);
9862 break;
9863 }
9864 }
9865 return 0;
9866 }
9867
9868 static void test_PeekMessage(void)
9869 {
9870 MSG msg;
9871 HANDLE hthread;
9872 DWORD tid, qstatus;
9873 UINT qs_all_input = QS_ALLINPUT;
9874 UINT qs_input = QS_INPUT;
9875 BOOL ret;
9876 struct peekmsg_info info;
9877
9878 info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9879 100, 100, 200, 200, 0, 0, 0, NULL);
9880 assert(info.hwnd);
9881 ShowWindow(info.hwnd, SW_SHOW);
9882 UpdateWindow(info.hwnd);
9883 SetFocus(info.hwnd);
9884
9885 info.hevent[EV_STOP] = CreateEventA(NULL, 0, 0, NULL);
9886 info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
9887 info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
9888
9889 hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
9890 WaitForSingleObject(info.hevent[EV_ACK], 10000);
9891
9892 flush_events();
9893 flush_sequence();
9894
9895 SetLastError(0xdeadbeef);
9896 qstatus = GetQueueStatus(qs_all_input);
9897 if (GetLastError() == ERROR_INVALID_FLAGS)
9898 {
9899 trace("QS_RAWINPUT not supported on this platform\n");
9900 qs_all_input &= ~QS_RAWINPUT;
9901 qs_input &= ~QS_RAWINPUT;
9902 }
9903 if (qstatus & QS_POSTMESSAGE)
9904 {
9905 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) /* nothing */ ;
9906 qstatus = GetQueueStatus(qs_all_input);
9907 }
9908 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9909
9910 trace("signalling to send message\n");
9911 SetEvent(info.hevent[EV_SENDMSG]);
9912 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9913
9914 /* pass invalid QS_xxxx flags */
9915 SetLastError(0xdeadbeef);
9916 qstatus = GetQueueStatus(0xffffffff);
9917 ok(qstatus == 0 || broken(qstatus) /* win9x */, "GetQueueStatus should fail: %08x\n", qstatus);
9918 if (!qstatus)
9919 {
9920 ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
9921 qstatus = GetQueueStatus(qs_all_input);
9922 }
9923 qstatus &= ~MAKELONG( 0x4000, 0x4000 ); /* sometimes set on Win95 */
9924 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
9925 "wrong qstatus %08x\n", qstatus);
9926
9927 msg.message = 0;
9928 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9929 ok(!ret,
9930 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9931 msg.message);
9932 ok_sequence(WmUser, "WmUser", FALSE);
9933
9934 qstatus = GetQueueStatus(qs_all_input);
9935 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9936
9937 keybd_event('N', 0, 0, 0);
9938 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9939 qstatus = GetQueueStatus(qs_all_input);
9940 if (!(qstatus & MAKELONG(QS_KEY, QS_KEY)))
9941 {
9942 skip( "queuing key events not supported\n" );
9943 goto done;
9944 }
9945 ok(qstatus == MAKELONG(QS_KEY, QS_KEY) ||
9946 /* keybd_event seems to trigger a sent message on NT4 */
9947 qstatus == MAKELONG(QS_KEY|QS_SENDMESSAGE, QS_KEY|QS_SENDMESSAGE),
9948 "wrong qstatus %08x\n", qstatus);
9949
9950 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9951 qstatus = GetQueueStatus(qs_all_input);
9952 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY) ||
9953 qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY|QS_SENDMESSAGE),
9954 "wrong qstatus %08x\n", qstatus);
9955
9956 InvalidateRect(info.hwnd, NULL, FALSE);
9957 qstatus = GetQueueStatus(qs_all_input);
9958 ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY) ||
9959 qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY|QS_SENDMESSAGE),
9960 "wrong qstatus %08x\n", qstatus);
9961
9962 trace("signalling to send message\n");
9963 SetEvent(info.hevent[EV_SENDMSG]);
9964 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9965
9966 qstatus = GetQueueStatus(qs_all_input);
9967 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9968 "wrong qstatus %08x\n", qstatus);
9969
9970 msg.message = 0;
9971 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
9972 if (ret && msg.message == WM_CHAR)
9973 {
9974 win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9975 goto done;
9976 }
9977 ok(!ret,
9978 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9979 msg.message);
9980 if (!sequence_cnt) /* nt4 doesn't fetch anything with PM_QS_* flags */
9981 {
9982 win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9983 goto done;
9984 }
9985 ok_sequence(WmUser, "WmUser", FALSE);
9986
9987 qstatus = GetQueueStatus(qs_all_input);
9988 ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9989 "wrong qstatus %08x\n", qstatus);
9990
9991 trace("signalling to send message\n");
9992 SetEvent(info.hevent[EV_SENDMSG]);
9993 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9994
9995 qstatus = GetQueueStatus(qs_all_input);
9996 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9997 "wrong qstatus %08x\n", qstatus);
9998
9999 msg.message = 0;
10000 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE );
10001 ok(!ret,
10002 "PeekMessageA should have returned FALSE instead of msg %04x\n",
10003 msg.message);
10004 ok_sequence(WmUser, "WmUser", FALSE);
10005
10006 qstatus = GetQueueStatus(qs_all_input);
10007 ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
10008 "wrong qstatus %08x\n", qstatus);
10009
10010 msg.message = 0;
10011 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
10012 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
10013 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
10014 ret, msg.message, msg.wParam);
10015 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
10016
10017 qstatus = GetQueueStatus(qs_all_input);
10018 ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
10019 "wrong qstatus %08x\n", qstatus);
10020
10021 msg.message = 0;
10022 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
10023 ok(!ret,
10024 "PeekMessageA should have returned FALSE instead of msg %04x\n",
10025 msg.message);
10026 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
10027
10028 qstatus = GetQueueStatus(qs_all_input);
10029 ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
10030 "wrong qstatus %08x\n", qstatus);
10031
10032 msg.message = 0;
10033 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
10034 ok(ret && msg.message == WM_PAINT,
10035 "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
10036 DispatchMessageA(&msg);
10037 ok_sequence(WmPaint, "WmPaint", FALSE);
10038
10039 qstatus = GetQueueStatus(qs_all_input);
10040 ok(qstatus == MAKELONG(0, QS_KEY),
10041 "wrong qstatus %08x\n", qstatus);
10042
10043 msg.message = 0;
10044 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
10045 ok(!ret,
10046 "PeekMessageA should have returned FALSE instead of msg %04x\n",
10047 msg.message);
10048 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
10049
10050 qstatus = GetQueueStatus(qs_all_input);
10051 ok(qstatus == MAKELONG(0, QS_KEY),
10052 "wrong qstatus %08x\n", qstatus);
10053
10054 trace("signalling to send message\n");
10055 SetEvent(info.hevent[EV_SENDMSG]);
10056 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
10057
10058 qstatus = GetQueueStatus(qs_all_input);
10059 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
10060 "wrong qstatus %08x\n", qstatus);
10061
10062 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
10063
10064 qstatus = GetQueueStatus(qs_all_input);
10065 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
10066 "wrong qstatus %08x\n", qstatus);
10067
10068 msg.message = 0;
10069 ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
10070 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
10071 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
10072 ret, msg.message, msg.wParam);
10073 ok_sequence(WmUser, "WmUser", FALSE);
10074
10075 qstatus = GetQueueStatus(qs_all_input);
10076 ok(qstatus == MAKELONG(0, QS_KEY),
10077 "wrong qstatus %08x\n", qstatus);
10078
10079 msg.message = 0;
10080 ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
10081 ok(!ret,
10082 "PeekMessageA should have returned FALSE instead of msg %04x\n",
10083 msg.message);
10084 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
10085
10086 qstatus = GetQueueStatus(qs_all_input);
10087 ok(qstatus == MAKELONG(0, QS_KEY),
10088 "wrong qstatus %08x\n", qstatus);
10089
10090 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
10091
10092 qstatus = GetQueueStatus(qs_all_input);
10093 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
10094 "wrong qstatus %08x\n", qstatus);
10095
10096 trace("signalling to send message\n");
10097 SetEvent(info.hevent[EV_SENDMSG]);
10098 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
10099
10100 qstatus = GetQueueStatus(qs_all_input);
10101 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
10102 "wrong qstatus %08x\n", qstatus);
10103
10104 msg.message = 0;
10105 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
10106 ok(!ret,
10107 "PeekMessageA should have returned FALSE instead of msg %04x\n",
10108 msg.message);
10109 ok_sequence(WmUser, "WmUser", FALSE);
10110
10111 qstatus = GetQueueStatus(qs_all_input);
10112 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
10113 "wrong qstatus %08x\n", qstatus);
10114
10115 msg.message = 0;
10116 if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
10117 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
10118 else /* workaround for a missing QS_RAWINPUT support */
10119 ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
10120 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
10121 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
10122 ret, msg.message, msg.wParam);
10123 ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
10124
10125 qstatus = GetQueueStatus(qs_all_input);
10126 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
10127 "wrong qstatus %08x\n", qstatus);
10128
10129 msg.message = 0;
10130 if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
10131 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
10132 else /* workaround for a missing QS_RAWINPUT support */
10133 ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
10134 ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
10135 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
10136 ret, msg.message, msg.wParam);
10137 ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
10138
10139 qstatus = GetQueueStatus(qs_all_input);
10140 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
10141 "wrong qstatus %08x\n", qstatus);
10142
10143 msg.message = 0;
10144 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
10145 ok(!ret,
10146 "PeekMessageA should have returned FALSE instead of msg %04x\n",
10147 msg.message);
10148 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
10149
10150 qstatus = GetQueueStatus(qs_all_input);
10151 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
10152 "wrong qstatus %08x\n", qstatus);
10153
10154 msg.message = 0;
10155 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
10156 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
10157 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
10158 ret, msg.message, msg.wParam);
10159 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
10160
10161 qstatus = GetQueueStatus(qs_all_input);
10162 ok(qstatus == 0,
10163 "wrong qstatus %08x\n", qstatus);
10164
10165 msg.message = 0;
10166 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
10167 ok(!ret,
10168 "PeekMessageA should have returned FALSE instead of msg %04x\n",
10169 msg.message);
10170 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
10171
10172 qstatus = GetQueueStatus(qs_all_input);
10173 ok(qstatus == 0,
10174 "wrong qstatus %08x\n", qstatus);
10175
10176 /* test whether presence of the quit flag in the queue affects
10177 * the queue state
10178 */
10179 PostQuitMessage(0x1234abcd);
10180
10181 qstatus = GetQueueStatus(qs_all_input);
10182 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
10183 "wrong qstatus %08x\n", qstatus);
10184
10185 PostMessageA(info.hwnd, WM_USER, 0, 0);
10186
10187 qstatus = GetQueueStatus(qs_all_input);
10188 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
10189 "wrong qstatus %08x\n", qstatus);
10190
10191 msg.message = 0;
10192 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
10193 ok(ret && msg.message == WM_USER,
10194 "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
10195 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
10196
10197 qstatus = GetQueueStatus(qs_all_input);
10198 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
10199 "wrong qstatus %08x\n", qstatus);
10200
10201 msg.message = 0;
10202 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
10203 ok(ret && msg.message == WM_QUIT,
10204 "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
10205 ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
10206 ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
10207 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
10208
10209 qstatus = GetQueueStatus(qs_all_input);
10210 todo_wine {
10211 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
10212 "wrong qstatus %08x\n", qstatus);
10213 }
10214
10215 msg.message = 0;
10216 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
10217 ok(!ret,
10218 "PeekMessageA should have returned FALSE instead of msg %04x\n",
10219 msg.message);
10220 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
10221
10222 qstatus = GetQueueStatus(qs_all_input);
10223 ok(qstatus == 0,
10224 "wrong qstatus %08x\n", qstatus);
10225
10226 /* some GetMessage tests */
10227
10228 keybd_event('N', 0, 0, 0);
10229 qstatus = GetQueueStatus(qs_all_input);
10230 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
10231
10232 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
10233 qstatus = GetQueueStatus(qs_all_input);
10234 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
10235
10236 if (qstatus)
10237 {
10238 ret = GetMessageA( &msg, 0, 0, 0 );
10239 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
10240 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
10241 ret, msg.message, msg.wParam);
10242 qstatus = GetQueueStatus(qs_all_input);
10243 ok(qstatus == MAKELONG(0, QS_KEY), "wrong qstatus %08x\n", qstatus);
10244 }
10245
10246 if (qstatus)
10247 {
10248 ret = GetMessageA( &msg, 0, 0, 0 );
10249 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
10250 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
10251 ret, msg.message, msg.wParam);
10252 ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
10253 qstatus = GetQueueStatus(qs_all_input);
10254 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
10255 }
10256
10257 keybd_event('N', 0, 0, 0);
10258 qstatus = GetQueueStatus(qs_all_input);
10259 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
10260
10261 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
10262 qstatus = GetQueueStatus(qs_all_input);
10263 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
10264
10265 if (qstatus & (QS_KEY << 16))
10266 {
10267 ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
10268 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
10269 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
10270 ret, msg.message, msg.wParam);
10271 ok_sequence(WmKeyDownWasDownSkippedSeq, "WmKeyDownWasDownSkippedSeq", FALSE);
10272 qstatus = GetQueueStatus(qs_all_input);
10273 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
10274 }
10275
10276 if (qstatus)
10277 {
10278 ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
10279 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
10280 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
10281 ret, msg.message, msg.wParam);
10282 qstatus = GetQueueStatus(qs_all_input);
10283 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
10284 }
10285
10286 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
10287 qstatus = GetQueueStatus(qs_all_input);
10288 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
10289
10290 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
10291 qstatus = GetQueueStatus(qs_all_input);
10292 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
10293
10294 trace("signalling to send message\n");
10295 SetEvent(info.hevent[EV_SENDMSG]);
10296 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
10297 qstatus = GetQueueStatus(qs_all_input);
10298 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
10299 "wrong qstatus %08x\n", qstatus);
10300
10301 if (qstatus & (QS_KEY << 16))
10302 {
10303 ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
10304 ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
10305 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
10306 ret, msg.message, msg.wParam);
10307 ok_sequence(WmUserKeyUpSkippedSeq, "WmUserKeyUpSkippedSeq", FALSE);
10308 qstatus = GetQueueStatus(qs_all_input);
10309 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
10310 }
10311
10312 if (qstatus)
10313 {
10314 ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
10315 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
10316 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
10317 ret, msg.message, msg.wParam);
10318 qstatus = GetQueueStatus(qs_all_input);
10319 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
10320 }
10321 done:
10322 trace("signalling to exit\n");
10323 SetEvent(info.hevent[EV_STOP]);
10324
10325 WaitForSingleObject(hthread, INFINITE);
10326
10327 CloseHandle(hthread);
10328 CloseHandle(info.hevent[0]);
10329 CloseHandle(info.hevent[1]);
10330 CloseHandle(info.hevent[2]);
10331
10332 DestroyWindow(info.hwnd);
10333 }
10334
10335 static void wait_move_event(HWND hwnd, int x, int y)
10336 {
10337 MSG msg;
10338 DWORD time;
10339 BOOL ret, go = FALSE;
10340
10341 time = GetTickCount();
10342 while (GetTickCount() - time < 200 && !go) {
10343 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
10344 go = ret && msg.pt.x > x && msg.pt.y > y;
10345 if (!ret) MsgWaitForMultipleObjects( 0, NULL, FALSE, GetTickCount() - time, QS_ALLINPUT );
10346 }
10347 }
10348
10349 #define STEP 5
10350 static void test_PeekMessage2(void)
10351 {
10352 HWND hwnd;
10353 BOOL ret;
10354 MSG msg;
10355 UINT message;
10356 DWORD time1, time2, time3;
10357 int x1, y1, x2, y2, x3, y3;
10358 POINT pos;
10359
10360 time1 = time2 = time3 = 0;
10361 x1 = y1 = x2 = y2 = x3 = y3 = 0;
10362
10363 /* Initialise window and make sure it is ready for events */
10364 hwnd = CreateWindowA("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
10365 10, 10, 800, 800, NULL, NULL, NULL, NULL);
10366 assert(hwnd);
10367 trace("Window for test_PeekMessage2 %p\n", hwnd);
10368 ShowWindow(hwnd, SW_SHOW);
10369 UpdateWindow(hwnd);
10370 SetFocus(hwnd);
10371 GetCursorPos(&pos);
10372 SetCursorPos(100, 100);
10373 mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
10374 flush_events();
10375
10376 /* Do initial mousemove, wait until we can see it
10377 and then do our test peek with PM_NOREMOVE. */
10378 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
10379 wait_move_event(hwnd, 100-STEP, 100-STEP);
10380
10381 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
10382 if (!ret)
10383 {
10384 skip( "queuing mouse events not supported\n" );
10385 goto done;
10386 }
10387 else
10388 {
10389 trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
10390 message = msg.message;
10391 time1 = msg.time;
10392 x1 = msg.pt.x;
10393 y1 = msg.pt.y;
10394 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
10395 }
10396
10397 /* Allow time to advance a bit, and then simulate the user moving their
10398 * mouse around. After that we peek again with PM_NOREMOVE.
10399 * Although the previous mousemove message was never removed, the
10400 * mousemove we now peek should reflect the recent mouse movements
10401 * because the input queue will merge the move events. */
10402 Sleep(100);
10403 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
10404 wait_move_event(hwnd, x1, y1);
10405
10406 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
10407 ok(ret, "no message available\n");
10408 if (ret) {
10409 trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
10410 message = msg.message;
10411 time2 = msg.time;
10412 x2 = msg.pt.x;
10413 y2 = msg.pt.y;
10414 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
10415 ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
10416 ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
10417 }
10418
10419 /* Have another go, to drive the point home */
10420 Sleep(100);
10421 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
10422 wait_move_event(hwnd, x2, y2);
10423
10424 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
10425 ok(ret, "no message available\n");
10426 if (ret) {
10427 trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
10428 message = msg.message;
10429 time3 = msg.time;
10430 x3 = msg.pt.x;
10431 y3 = msg.pt.y;
10432 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
10433 ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
10434 ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
10435 }
10436
10437 done:
10438 DestroyWindow(hwnd);
10439 SetCursorPos(pos.x, pos.y);
10440 flush_events();
10441 }
10442
10443 static INT_PTR CALLBACK wm_quit_dlg_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
10444 {
10445 struct recvd_message msg;
10446
10447 if (ignore_message( message )) return 0;
10448
10449 msg.hwnd = hwnd;
10450 msg.message = message;
10451 msg.flags = sent|wparam|lparam;
10452 msg.wParam = wp;
10453 msg.lParam = lp;
10454 msg.descr = "dialog";
10455 add_message(&msg);
10456
10457 switch (message)
10458 {
10459 case WM_INITDIALOG:
10460 PostMessageA(hwnd, WM_QUIT, 0x1234, 0x5678);
10461 PostMessageA(hwnd, WM_USER, 0xdead, 0xbeef);
10462 return 0;
10463
10464 case WM_GETDLGCODE:
10465 return 0;
10466
10467 case WM_USER:
10468 EndDialog(hwnd, 0);
10469 break;
10470 }
10471
10472 return 1;
10473 }
10474
10475 static const struct message WmQuitDialogSeq[] = {
10476 { HCBT_CREATEWND, hook },
10477 { WM_SETFONT, sent },
10478 { WM_INITDIALOG, sent },
10479 { WM_CHANGEUISTATE, sent|optional },
10480 { HCBT_DESTROYWND, hook },
10481 { 0x0090, sent|optional }, /* Vista */
10482 { WM_DESTROY, sent },
10483 { WM_NCDESTROY, sent },
10484 { 0 }
10485 };
10486
10487 static const struct message WmStopQuitSeq[] = {
10488 { WM_DWMNCRENDERINGCHANGED, posted|optional },
10489 { WM_CLOSE, posted },
10490 { WM_QUIT, posted|wparam|lparam, 0x1234, 0 },
10491 { 0 }
10492 };
10493
10494 static void test_quit_message(void)
10495 {
10496 MSG msg;
10497 BOOL ret;
10498
10499 /* test using PostQuitMessage */
10500 flush_events();
10501 PostQuitMessage(0xbeef);
10502
10503 msg.message = 0;
10504 ret = PeekMessageA(&msg, 0, 0, 0, PM_QS_SENDMESSAGE);
10505 ok(!ret, "got %x message\n", msg.message);
10506
10507 ret = PeekMessageA(&msg, NULL, 0, 0, PM_NOREMOVE);
10508 ok(ret, "PeekMessage failed with error %d\n", GetLastError());
10509 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10510 ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
10511
10512 ret = PostThreadMessageA(GetCurrentThreadId(), WM_USER, 0, 0);
10513 ok(ret, "PostMessage failed with error %d\n", GetLastError());
10514
10515 ret = GetMessageA(&msg, NULL, 0, 0);
10516 ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
10517 ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
10518
10519 /* note: WM_QUIT message received after WM_USER message */
10520 ret = GetMessageA(&msg, NULL, 0, 0);
10521 ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
10522 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10523 ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
10524
10525 ret = PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE);
10526 ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
10527
10528 /* now test with PostThreadMessage - different behaviour! */
10529 PostThreadMessageA(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
10530
10531 ret = PeekMessageA(&msg, NULL, 0, 0, PM_NOREMOVE);
10532 ok(ret, "PeekMessage failed with error %d\n", GetLastError());
10533 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10534 ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
10535
10536 ret = PostThreadMessageA(GetCurrentThreadId(), WM_USER, 0, 0);
10537 ok(ret, "PostMessage failed with error %d\n", GetLastError());
10538
10539 /* note: we receive the WM_QUIT message first this time */
10540 ret = GetMessageA(&msg, NULL, 0, 0);
10541 ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
10542 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10543 ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
10544
10545 ret = GetMessageA(&msg, NULL, 0, 0);
10546 ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
10547 ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
10548
10549 flush_events();
10550 flush_sequence();
10551 ret = DialogBoxParamA(GetModuleHandleA(NULL), "TEST_EMPTY_DIALOG", 0, wm_quit_dlg_proc, 0);
10552 ok(ret == 1, "expected 1, got %d\n", ret);
10553 ok_sequence(WmQuitDialogSeq, "WmQuitDialogSeq", FALSE);
10554 memset(&msg, 0xab, sizeof(msg));
10555 ret = PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE);
10556 ok(ret, "PeekMessage failed\n");
10557 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
10558 ok(msg.wParam == 0x1234, "wParam was 0x%lx instead of 0x1234\n", msg.wParam);
10559 ok(msg.lParam == 0, "lParam was 0x%lx instead of 0\n", msg.lParam);
10560
10561 /* Check what happens to a WM_QUIT message posted to a window that gets
10562 * destroyed.
10563 */
10564 CreateWindowExA(0, "StopQuitClass", "Stop Quit Test", WS_OVERLAPPEDWINDOW,
10565 0, 0, 100, 100, NULL, NULL, NULL, NULL);
10566 flush_sequence();
10567 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
10568 {
10569 struct recvd_message rmsg;
10570 rmsg.hwnd = msg.hwnd;
10571 rmsg.message = msg.message;
10572 rmsg.flags = posted|wparam|lparam;
10573 rmsg.wParam = msg.wParam;
10574 rmsg.lParam = msg.lParam;
10575 rmsg.descr = "stop/quit";
10576 if (msg.message == WM_QUIT)
10577 /* The hwnd can only be checked here */
10578 ok(!msg.hwnd, "The WM_QUIT hwnd was %p instead of NULL\n", msg.hwnd);
10579 add_message(&rmsg);
10580 DispatchMessageA(&msg);
10581 }
10582 ok_sequence(WmStopQuitSeq, "WmStopQuitSeq", FALSE);
10583 }
10584
10585 static const struct message WmMouseHoverSeq[] = {
10586 { WM_MOUSEACTIVATE, sent|optional }, /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
10587 { WM_MOUSEACTIVATE, sent|optional },
10588 { WM_TIMER, sent|optional }, /* XP sends it */
10589 { WM_SYSTIMER, sent },
10590 { WM_MOUSEHOVER, sent|wparam, 0 },
10591 { 0 }
10592 };
10593
10594 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
10595 {
10596 MSG msg;
10597 DWORD start_ticks, end_ticks;
10598
10599 start_ticks = GetTickCount();
10600 /* add some deviation (50%) to cover not expected delays */
10601 start_ticks += timeout / 2;
10602
10603 do
10604 {
10605 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
10606 {
10607 /* Timer proc messages are not dispatched to the window proc,
10608 * and therefore not logged.
10609 */
10610 if ((msg.message == WM_TIMER || msg.message == WM_SYSTIMER) && msg.hwnd)
10611 {
10612 struct recvd_message s_msg;
10613
10614 s_msg.hwnd = msg.hwnd;
10615 s_msg.message = msg.message;
10616 s_msg.flags = sent|wparam|lparam;
10617 s_msg.wParam = msg.wParam;
10618 s_msg.lParam = msg.lParam;
10619 s_msg.descr = "msg_loop";
10620 add_message(&s_msg);
10621 }
10622 DispatchMessageA(&msg);
10623 }
10624
10625 end_ticks = GetTickCount();
10626
10627 /* inject WM_MOUSEMOVE to see how it changes tracking */
10628 if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
10629 {
10630 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
10631 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
10632
10633 inject_mouse_move = FALSE;
10634 }
10635 } while (start_ticks + timeout >= end_ticks);
10636 }
10637
10638 static void test_TrackMouseEvent(void)
10639 {
10640 TRACKMOUSEEVENT tme;
10641 BOOL ret;
10642 HWND hwnd, hchild;
10643 RECT rc_parent, rc_child;
10644 UINT default_hover_time, hover_width = 0, hover_height = 0;
10645
10646 #define track_hover(track_hwnd, track_hover_time) \
10647 tme.cbSize = sizeof(tme); \
10648 tme.dwFlags = TME_HOVER; \
10649 tme.hwndTrack = track_hwnd; \
10650 tme.dwHoverTime = track_hover_time; \
10651 SetLastError(0xdeadbeef); \
10652 ret = pTrackMouseEvent(&tme); \
10653 ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
10654
10655 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
10656 tme.cbSize = sizeof(tme); \
10657 tme.dwFlags = TME_QUERY; \
10658 tme.hwndTrack = (HWND)0xdeadbeef; \
10659 tme.dwHoverTime = 0xdeadbeef; \
10660 SetLastError(0xdeadbeef); \
10661 ret = pTrackMouseEvent(&tme); \
10662 ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
10663 ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
10664 ok(tme.dwFlags == (expected_track_flags), \
10665 "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
10666 ok(tme.hwndTrack == (expected_track_hwnd), \
10667 "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
10668 ok(tme.dwHoverTime == (expected_hover_time), \
10669 "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
10670
10671 #define track_hover_cancel(track_hwnd) \
10672 tme.cbSize = sizeof(tme); \
10673 tme.dwFlags = TME_HOVER | TME_CANCEL; \
10674 tme.hwndTrack = track_hwnd; \
10675 tme.dwHoverTime = 0xdeadbeef; \
10676 SetLastError(0xdeadbeef); \
10677 ret = pTrackMouseEvent(&tme); \
10678 ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
10679
10680 default_hover_time = 0xdeadbeef;
10681 SetLastError(0xdeadbeef);
10682 ret = SystemParametersInfoA(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
10683 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
10684 "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
10685 if (!ret) default_hover_time = 400;
10686 trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
10687
10688 SetLastError(0xdeadbeef);
10689 ret = SystemParametersInfoA(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
10690 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
10691 "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
10692 if (!ret) hover_width = 4;
10693 SetLastError(0xdeadbeef);
10694 ret = SystemParametersInfoA(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
10695 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
10696 "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
10697 if (!ret) hover_height = 4;
10698 trace("hover rect is %u x %d\n", hover_width, hover_height);
10699
10700 hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
10701 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10702 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
10703 NULL, NULL, 0);
10704 assert(hwnd);
10705
10706 hchild = CreateWindowExA(0, "TestWindowClass", NULL,
10707 WS_CHILD | WS_BORDER | WS_VISIBLE,
10708 50, 50, 200, 200, hwnd,
10709 NULL, NULL, 0);
10710 assert(hchild);
10711
10712 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
10713 flush_events();
10714 flush_sequence();
10715
10716 tme.cbSize = 0;
10717 tme.dwFlags = TME_QUERY;
10718 tme.hwndTrack = (HWND)0xdeadbeef;
10719 tme.dwHoverTime = 0xdeadbeef;
10720 SetLastError(0xdeadbeef);
10721 ret = pTrackMouseEvent(&tme);
10722 ok(!ret, "TrackMouseEvent should fail\n");
10723 ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef),
10724 "not expected error %u\n", GetLastError());
10725
10726 tme.cbSize = sizeof(tme);
10727 tme.dwFlags = TME_HOVER;
10728 tme.hwndTrack = (HWND)0xdeadbeef;
10729 tme.dwHoverTime = 0xdeadbeef;
10730 SetLastError(0xdeadbeef);
10731 ret = pTrackMouseEvent(&tme);
10732 ok(!ret, "TrackMouseEvent should fail\n");
10733 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10734 "not expected error %u\n", GetLastError());
10735
10736 tme.cbSize = sizeof(tme);
10737 tme.dwFlags = TME_HOVER | TME_CANCEL;
10738 tme.hwndTrack = (HWND)0xdeadbeef;
10739 tme.dwHoverTime = 0xdeadbeef;
10740 SetLastError(0xdeadbeef);
10741 ret = pTrackMouseEvent(&tme);
10742 ok(!ret, "TrackMouseEvent should fail\n");
10743 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10744 "not expected error %u\n", GetLastError());
10745
10746 GetWindowRect(hwnd, &rc_parent);
10747 GetWindowRect(hchild, &rc_child);
10748 SetCursorPos(rc_child.left - 10, rc_child.top - 10);
10749
10750 /* Process messages so that the system updates its internal current
10751 * window and hittest, otherwise TrackMouseEvent calls don't have any
10752 * effect.
10753 */
10754 flush_events();
10755 flush_sequence();
10756
10757 track_query(0, NULL, 0);
10758 track_hover(hchild, 0);
10759 track_query(0, NULL, 0);
10760
10761 flush_events();
10762 flush_sequence();
10763
10764 track_hover(hwnd, 0);
10765 tme.cbSize = sizeof(tme);
10766 tme.dwFlags = TME_QUERY;
10767 tme.hwndTrack = (HWND)0xdeadbeef;
10768 tme.dwHoverTime = 0xdeadbeef;
10769 SetLastError(0xdeadbeef);
10770 ret = pTrackMouseEvent(&tme);
10771 ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());
10772 ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize);
10773 if (!tme.dwFlags)
10774 {
10775 skip( "Cursor not inside window, skipping TrackMouseEvent tests\n" );
10776 DestroyWindow( hwnd );
10777 return;
10778 }
10779 ok(tme.dwFlags == TME_HOVER, "wrong tme.dwFlags %08x, expected TME_HOVER\n", tme.dwFlags);
10780 ok(tme.hwndTrack == hwnd, "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, hwnd);
10781 ok(tme.dwHoverTime == default_hover_time, "wrong tme.dwHoverTime %u, expected %u\n",
10782 tme.dwHoverTime, default_hover_time);
10783
10784 pump_msg_loop_timeout(default_hover_time, FALSE);
10785 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10786
10787 track_query(0, NULL, 0);
10788
10789 track_hover(hwnd, HOVER_DEFAULT);
10790 track_query(TME_HOVER, hwnd, default_hover_time);
10791
10792 Sleep(default_hover_time / 2);
10793 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
10794 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
10795
10796 track_query(TME_HOVER, hwnd, default_hover_time);
10797
10798 pump_msg_loop_timeout(default_hover_time, FALSE);
10799 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10800
10801 track_query(0, NULL, 0);
10802
10803 track_hover(hwnd, HOVER_DEFAULT);
10804 track_query(TME_HOVER, hwnd, default_hover_time);
10805
10806 pump_msg_loop_timeout(default_hover_time, TRUE);
10807 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10808
10809 track_query(0, NULL, 0);
10810
10811 track_hover(hwnd, HOVER_DEFAULT);
10812 track_query(TME_HOVER, hwnd, default_hover_time);
10813 track_hover_cancel(hwnd);
10814
10815 DestroyWindow(hwnd);
10816
10817 #undef track_hover
10818 #undef track_query
10819 #undef track_hover_cancel
10820 }
10821
10822
10823 static const struct message WmSetWindowRgn[] = {
10824 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10825 { WM_NCCALCSIZE, sent|wparam, 1 },
10826 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
10827 { WM_GETTEXT, sent|defwinproc|optional },
10828 { WM_ERASEBKGND, sent|optional },
10829 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10830 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10831 { 0 }
10832 };
10833
10834 static const struct message WmSetWindowRgn_no_redraw[] = {
10835 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10836 { WM_NCCALCSIZE, sent|wparam, 1 },
10837 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10838 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10839 { 0 }
10840 };
10841
10842 static const struct message WmSetWindowRgn_clear[] = {
10843 { WM_WINDOWPOSCHANGING, sent/*|wparam*/, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE/*|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE only on some Windows versions */ },
10844 { WM_NCCALCSIZE, sent|wparam, 1 },
10845 { WM_NCPAINT, sent|optional },
10846 { WM_GETTEXT, sent|defwinproc|optional },
10847 { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
10848 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10849 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
10850 { WM_NCPAINT, sent|optional },
10851 { WM_GETTEXT, sent|defwinproc|optional },
10852 { WM_ERASEBKGND, sent|optional },
10853 { WM_WINDOWPOSCHANGING, sent|optional },
10854 { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10855 { WM_NCPAINT, sent|optional },
10856 { WM_GETTEXT, sent|defwinproc|optional },
10857 { WM_ERASEBKGND, sent|optional },
10858 { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10859 { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10860 { WM_NCPAINT, sent|optional },
10861 { WM_GETTEXT, sent|defwinproc|optional },
10862 { WM_ERASEBKGND, sent|optional },
10863 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10864 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10865 { 0 }
10866 };
10867
10868 static void test_SetWindowRgn(void)
10869 {
10870 HRGN hrgn;
10871 HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10872 100, 100, 200, 200, 0, 0, 0, NULL);
10873 ok( hwnd != 0, "Failed to create overlapped window\n" );
10874
10875 ShowWindow( hwnd, SW_SHOW );
10876 UpdateWindow( hwnd );
10877 flush_events();
10878 flush_sequence();
10879
10880 trace("testing SetWindowRgn\n");
10881 hrgn = CreateRectRgn( 0, 0, 150, 150 );
10882 SetWindowRgn( hwnd, hrgn, TRUE );
10883 ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
10884
10885 hrgn = CreateRectRgn( 30, 30, 160, 160 );
10886 SetWindowRgn( hwnd, hrgn, FALSE );
10887 ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
10888
10889 hrgn = CreateRectRgn( 0, 0, 180, 180 );
10890 SetWindowRgn( hwnd, hrgn, TRUE );
10891 ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
10892
10893 SetWindowRgn( hwnd, 0, TRUE );
10894 ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
10895
10896 DestroyWindow( hwnd );
10897 }
10898
10899 /*************************** ShowWindow() test ******************************/
10900 static const struct message WmShowNormal[] = {
10901 { WM_SHOWWINDOW, sent|wparam, 1 },
10902 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10903 { HCBT_ACTIVATE, hook },
10904 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10905 { HCBT_SETFOCUS, hook },
10906 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10907 { 0 }
10908 };
10909 static const struct message WmShow[] = {
10910 { WM_SHOWWINDOW, sent|wparam, 1 },
10911 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10912 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10913 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10914 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10915 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10916 { 0 }
10917 };
10918 static const struct message WmShowNoActivate_1[] = {
10919 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10920 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10921 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10922 { WM_MOVE, sent|defwinproc|optional },
10923 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10924 { 0 }
10925 };
10926 static const struct message WmShowNoActivate_2[] = {
10927 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10928 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
10929 { HCBT_ACTIVATE, hook|optional },
10930 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10931 { HCBT_SETFOCUS, hook|optional },
10932 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
10933 { WM_MOVE, sent|defwinproc },
10934 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10935 { HCBT_SETFOCUS, hook|optional },
10936 { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10937 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10938 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10939 { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10940 { 0 }
10941 };
10942 static const struct message WmShowNA_1[] = {
10943 { WM_SHOWWINDOW, sent|wparam, 1 },
10944 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10945 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10946 { 0 }
10947 };
10948 static const struct message WmShowNA_2[] = {
10949 { WM_SHOWWINDOW, sent|wparam, 1 },
10950 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10951 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10952 { 0 }
10953 };
10954 static const struct message WmRestore_1[] = {
10955 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10956 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10957 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10958 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10959 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10960 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10961 { WM_MOVE, sent|defwinproc },
10962 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10963 { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10964 { 0 }
10965 };
10966 static const struct message WmRestore_2[] = {
10967 { WM_SHOWWINDOW, sent|wparam, 1 },
10968 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10969 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10970 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10971 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10972 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10973 { 0 }
10974 };
10975 static const struct message WmRestore_3[] = {
10976 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10977 { WM_GETMINMAXINFO, sent },
10978 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10979 { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10980 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10981 { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10982 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10983 { WM_MOVE, sent|defwinproc },
10984 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10985 { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10986 { 0 }
10987 };
10988 static const struct message WmRestore_4[] = {
10989 { HCBT_MINMAX, hook|lparam|optional, 0, SW_RESTORE },
10990 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10991 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10992 { WM_MOVE, sent|defwinproc|optional },
10993 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10994 { 0 }
10995 };
10996 static const struct message WmRestore_5[] = {
10997 { HCBT_MINMAX, hook|lparam|optional, 0, SW_SHOWNORMAL },
10998 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10999 { HCBT_ACTIVATE, hook|optional },
11000 { HCBT_SETFOCUS, hook|optional },
11001 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
11002 { WM_MOVE, sent|defwinproc|optional },
11003 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
11004 { 0 }
11005 };
11006 static const struct message WmHide_1[] = {
11007 { WM_SHOWWINDOW, sent|wparam, 0 },
11008 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOACTIVATE },
11009 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOACTIVATE },
11010 { HCBT_ACTIVATE, hook|optional },
11011 { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
11012 { 0 }
11013 };
11014 static const struct message WmHide_2[] = {
11015 { WM_SHOWWINDOW, sent|wparam, 0 },
11016 { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
11017 { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
11018 { HCBT_ACTIVATE, hook|optional },
11019 { 0 }
11020 };
11021 static const struct message WmHide_3[] = {
11022 { WM_SHOWWINDOW, sent|wparam, 0 },
11023 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
11024 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11025 { HCBT_SETFOCUS, hook|optional },
11026 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
11027 { 0 }
11028 };
11029 static const struct message WmShowMinimized_1[] = {
11030 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
11031 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
11032 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
11033 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
11034 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
11035 { WM_MOVE, sent|defwinproc },
11036 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
11037 { 0 }
11038 };
11039 static const struct message WmMinimize_1[] = {
11040 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
11041 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
11042 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
11043 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
11044 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
11045 { WM_MOVE, sent|defwinproc },
11046 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
11047 { 0 }
11048 };
11049 static const struct message WmMinimize_2[] = {
11050 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
11051 { HCBT_SETFOCUS, hook|optional },
11052 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
11053 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
11054 { WM_MOVE, sent|defwinproc },
11055 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
11056 { 0 }
11057 };
11058 static const struct message WmMinimize_3[] = {
11059 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
11060 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
11061 { HCBT_ACTIVATE, hook|optional },
11062 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
11063 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
11064 { WM_MOVE, sent|defwinproc },
11065 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
11066 { 0 }
11067 };
11068 static const struct message WmShowMinNoActivate[] = {
11069 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
11070 { WM_WINDOWPOSCHANGING, sent },
11071 { WM_WINDOWPOSCHANGED, sent },
11072 { WM_MOVE, sent|defwinproc|optional },
11073 { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
11074 { 0 }
11075 };
11076 static const struct message WmMinMax_1[] = {
11077 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
11078 { 0 }
11079 };
11080 static const struct message WmMinMax_2[] = {
11081 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
11082 { WM_GETMINMAXINFO, sent|optional },
11083 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED },
11084 { HCBT_ACTIVATE, hook|optional },
11085 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
11086 { HCBT_SETFOCUS, hook|optional },
11087 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11088 { WM_MOVE, sent|defwinproc|optional },
11089 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MAXIMIZED },
11090 { HCBT_SETFOCUS, hook|optional },
11091 { 0 }
11092 };
11093 static const struct message WmMinMax_3[] = {
11094 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
11095 { HCBT_SETFOCUS, hook|optional },
11096 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
11097 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
11098 { WM_MOVE, sent|defwinproc|optional },
11099 { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
11100 { 0 }
11101 };
11102 static const struct message WmMinMax_4[] = {
11103 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
11104 { 0 }
11105 };
11106 static const struct message WmShowMaximized_1[] = {
11107 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
11108 { WM_GETMINMAXINFO, sent },
11109 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
11110 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
11111 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
11112 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
11113 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
11114 { WM_MOVE, sent|defwinproc },
11115 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
11116 { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
11117 { 0 }
11118 };
11119 static const struct message WmShowMaximized_2[] = {
11120 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
11121 { WM_GETMINMAXINFO, sent },
11122 { WM_WINDOWPOSCHANGING, sent|optional },
11123 { HCBT_ACTIVATE, hook|optional },
11124 { WM_WINDOWPOSCHANGED, sent|optional },
11125 { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
11126 { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
11127 { WM_WINDOWPOSCHANGING, sent|optional },
11128 { HCBT_SETFOCUS, hook|optional },
11129 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
11130 { WM_MOVE, sent|defwinproc },
11131 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
11132 { HCBT_SETFOCUS, hook|optional },
11133 { 0 }
11134 };
11135 static const struct message WmShowMaximized_3[] = {
11136 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
11137 { WM_GETMINMAXINFO, sent|optional },
11138 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
11139 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
11140 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
11141 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
11142 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
11143 { WM_MOVE, sent|defwinproc|optional },
11144 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
11145 { 0 }
11146 };
11147
11148 static void test_ShowWindow(void)
11149 {
11150 /* ShowWindow commands in random order */
11151 static const struct
11152 {
11153 INT cmd; /* ShowWindow command */
11154 LPARAM ret; /* ShowWindow return value */
11155 DWORD style; /* window style after the command */
11156 const struct message *msg; /* message sequence the command produces */
11157 INT wp_cmd, wp_flags; /* window placement after the command */
11158 POINT wp_min, wp_max; /* window placement after the command */
11159 BOOL todo_msg; /* message sequence doesn't match what Wine does */
11160 } sw[] =
11161 {
11162 /* 1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal,
11163 SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
11164 /* 2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq,
11165 SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
11166 /* 3 */ { SW_HIDE, TRUE, 0, WmHide_1,
11167 SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
11168 /* 4 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
11169 SW_SHOWNORMAL, 0, {-1,-1}, {-1,-1}, FALSE },
11170 /* 5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1,
11171 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
11172 /* 6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1,
11173 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
11174 /* 7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1,
11175 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
11176 /* 8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq,
11177 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
11178 /* 9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1,
11179 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
11180 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2,
11181 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
11182 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1,
11183 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
11184 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq,
11185 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
11186 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1,
11187 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
11188 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq,
11189 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
11190 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2,
11191 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
11192 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
11193 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
11194 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow,
11195 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
11196 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq,
11197 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
11198 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1,
11199 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
11200 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3,
11201 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
11202 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
11203 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
11204 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate,
11205 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, TRUE },
11206 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4,
11207 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
11208 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
11209 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
11210 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq,
11211 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
11212 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1,
11213 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
11214 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2,
11215 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
11216 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
11217 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
11218 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq,
11219 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
11220 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1,
11221 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
11222 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq,
11223 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
11224 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3,
11225 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
11226 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
11227 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
11228 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, /* what does this mean?! */
11229 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
11230 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq,
11231 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
11232 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
11233 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
11234 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2,
11235 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
11236 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq,
11237 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
11238 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq,
11239 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
11240 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2,
11241 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
11242 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3,
11243 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
11244 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2,
11245 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
11246 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2,
11247 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
11248 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1,
11249 SW_SHOWMINIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
11250 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3,
11251 SW_SHOWMINIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
11252 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3,
11253 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
11254 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4,
11255 SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
11256 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3,
11257 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
11258 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq,
11259 SW_SHOWMAXIMIZED, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
11260 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5,
11261 SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
11262 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5,
11263 SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
11264 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1,
11265 SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
11266 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq,
11267 SW_SHOWNORMAL, WPF_RESTORETOMAXIMIZED, {-32000,-32000}, {-1,-1}, FALSE },
11268 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3,
11269 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
11270 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2,
11271 SW_SHOWMINIMIZED, 0, {-32000,-32000}, {-1,-1}, FALSE },
11272 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2,
11273 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE },
11274 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq,
11275 SW_SHOWNORMAL, 0, {-32000,-32000}, {-1,-1}, FALSE }
11276 };
11277 HWND hwnd;
11278 DWORD style;
11279 LPARAM ret;
11280 INT i;
11281 WINDOWPLACEMENT wp;
11282 RECT win_rc, work_rc = {0, 0, 0, 0};
11283
11284 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
11285 hwnd = CreateWindowExA(0, "ShowWindowClass", NULL, WS_BASE,
11286 120, 120, 90, 90,
11287 0, 0, 0, NULL);
11288 assert(hwnd);
11289
11290 style = GetWindowLongA(hwnd, GWL_STYLE) & ~WS_BASE;
11291 ok(style == 0, "expected style 0, got %08x\n", style);
11292
11293 flush_events();
11294 flush_sequence();
11295
11296 if (pGetMonitorInfoA && pMonitorFromPoint)
11297 {
11298 HMONITOR hmon;
11299 MONITORINFO mi;
11300 POINT pt = {0, 0};
11301
11302 SetLastError(0xdeadbeef);
11303 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
11304 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
11305
11306 mi.cbSize = sizeof(mi);
11307 SetLastError(0xdeadbeef);
11308 ret = pGetMonitorInfoA(hmon, &mi);
11309 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
11310 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
11311 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
11312 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
11313 work_rc = mi.rcWork;
11314 }
11315
11316 GetWindowRect(hwnd, &win_rc);
11317 OffsetRect(&win_rc, -work_rc.left, -work_rc.top);
11318
11319 wp.length = sizeof(wp);
11320 SetLastError(0xdeadbeaf);
11321 ret = GetWindowPlacement(hwnd, &wp);
11322 ok(ret, "GetWindowPlacement error %u\n", GetLastError());
11323 ok(wp.flags == 0, "expected 0, got %#x\n", wp.flags);
11324 ok(wp.showCmd == SW_SHOWNORMAL, "expected SW_SHOWNORMAL, got %d\n", wp.showCmd);
11325 ok(wp.ptMinPosition.x == -1 && wp.ptMinPosition.y == -1,
11326 "expected -1,-1 got %d,%d\n", wp.ptMinPosition.x, wp.ptMinPosition.y);
11327 ok(wp.ptMaxPosition.x == -1 && wp.ptMaxPosition.y == -1,
11328 "expected -1,-1 got %d,%d\n", wp.ptMaxPosition.x, wp.ptMaxPosition.y);
11329 if (work_rc.left || work_rc.top) todo_wine /* FIXME: remove once Wine is fixed */
11330 ok(EqualRect(&win_rc, &wp.rcNormalPosition),
11331 "expected %d,%d-%d,%d got %d,%d-%d,%d\n",
11332 win_rc.left, win_rc.top, win_rc.right, win_rc.bottom,
11333 wp.rcNormalPosition.left, wp.rcNormalPosition.top,
11334 wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
11335 else
11336 ok(EqualRect(&win_rc, &wp.rcNormalPosition),
11337 "expected %d,%d-%d,%d got %d,%d-%d,%d\n",
11338 win_rc.left, win_rc.top, win_rc.right, win_rc.bottom,
11339 wp.rcNormalPosition.left, wp.rcNormalPosition.top,
11340 wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
11341
11342 for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
11343 {
11344 static const char * const sw_cmd_name[13] =
11345 {
11346 "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
11347 "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
11348 "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
11349 "SW_NORMALNA" /* 0xCC */
11350 };
11351 char comment[64];
11352 INT idx; /* index into the above array of names */
11353
11354 idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
11355
11356 style = GetWindowLongA(hwnd, GWL_STYLE);
11357 trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
11358 ret = ShowWindow(hwnd, sw[i].cmd);
11359 ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
11360 style = GetWindowLongA(hwnd, GWL_STYLE) & ~WS_BASE;
11361 ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
11362
11363 sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
11364 ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
11365
11366 wp.length = sizeof(wp);
11367 SetLastError(0xdeadbeaf);
11368 ret = GetWindowPlacement(hwnd, &wp);
11369 ok(ret, "GetWindowPlacement error %u\n", GetLastError());
11370 ok(wp.flags == sw[i].wp_flags, "expected %#x, got %#x\n", sw[i].wp_flags, wp.flags);
11371 ok(wp.showCmd == sw[i].wp_cmd, "expected %d, got %d\n", sw[i].wp_cmd, wp.showCmd);
11372
11373 /* NT moves the minimized window to -32000,-32000, win9x to 3000,3000 */
11374 if ((wp.ptMinPosition.x + work_rc.left == -32000 && wp.ptMinPosition.y + work_rc.top == -32000) ||
11375 (wp.ptMinPosition.x + work_rc.left == 3000 && wp.ptMinPosition.y + work_rc.top == 3000))
11376 {
11377 ok((wp.ptMinPosition.x + work_rc.left == sw[i].wp_min.x && wp.ptMinPosition.y + work_rc.top == sw[i].wp_min.y) ||
11378 (wp.ptMinPosition.x + work_rc.left == 3000 && wp.ptMinPosition.y + work_rc.top == 3000),
11379 "expected %d,%d got %d,%d\n", sw[i].wp_min.x, sw[i].wp_min.y, wp.ptMinPosition.x, wp.ptMinPosition.y);
11380 }
11381 else
11382 {
11383 ok(wp.ptMinPosition.x == sw[i].wp_min.x && wp.ptMinPosition.y == sw[i].wp_min.y,
11384 "expected %d,%d got %d,%d\n", sw[i].wp_min.x, sw[i].wp_min.y, wp.ptMinPosition.x, wp.ptMinPosition.y);
11385 }
11386
11387 if (wp.ptMaxPosition.x != sw[i].wp_max.x || wp.ptMaxPosition.y != sw[i].wp_max.y)
11388 todo_wine
11389 ok(wp.ptMaxPosition.x == sw[i].wp_max.x && wp.ptMaxPosition.y == sw[i].wp_max.y,
11390 "expected %d,%d got %d,%d\n", sw[i].wp_max.x, sw[i].wp_max.y, wp.ptMaxPosition.x, wp.ptMaxPosition.y);
11391 else
11392 ok(wp.ptMaxPosition.x == sw[i].wp_max.x && wp.ptMaxPosition.y == sw[i].wp_max.y,
11393 "expected %d,%d got %d,%d\n", sw[i].wp_max.x, sw[i].wp_max.y, wp.ptMaxPosition.x, wp.ptMaxPosition.y);
11394
11395 if (0) /* FIXME: Wine behaves completely different here */
11396 ok(EqualRect(&win_rc, &wp.rcNormalPosition),
11397 "expected %d,%d-%d,%d got %d,%d-%d,%d\n",
11398 win_rc.left, win_rc.top, win_rc.right, win_rc.bottom,
11399 wp.rcNormalPosition.left, wp.rcNormalPosition.top,
11400 wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
11401 }
11402 DestroyWindow(hwnd);
11403 flush_events();
11404 }
11405
11406 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
11407 {
11408 struct recvd_message msg;
11409
11410 if (ignore_message( message )) return 0;
11411
11412 msg.hwnd = hwnd;
11413 msg.message = message;
11414 msg.flags = sent|wparam|lparam;
11415 msg.wParam = wParam;
11416 msg.lParam = lParam;
11417 msg.descr = "dialog";
11418 add_message(&msg);
11419
11420 /* calling DefDlgProc leads to a recursion under XP */
11421
11422 switch (message)
11423 {
11424 case WM_INITDIALOG:
11425 case WM_GETDLGCODE:
11426 return 0;
11427 }
11428 return 1;
11429 }
11430
11431 static const struct message WmDefDlgSetFocus_1[] = {
11432 { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
11433 { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
11434 { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
11435 { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
11436 { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
11437 { HCBT_SETFOCUS, hook },
11438 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
11439 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11440 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
11441 { WM_SETFOCUS, sent|wparam, 0 },
11442 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
11443 { WM_CTLCOLOREDIT, sent },
11444 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
11445 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11446 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11447 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11448 { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
11449 { 0 }
11450 };
11451 static const struct message WmDefDlgSetFocus_2[] = {
11452 { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
11453 { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
11454 { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
11455 { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
11456 { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
11457 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11458 { WM_CTLCOLOREDIT, sent|optional }, /* XP */
11459 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
11460 { 0 }
11461 };
11462 /* Creation of a dialog */
11463 static const struct message WmCreateDialogParamSeq_1[] = {
11464 { HCBT_CREATEWND, hook },
11465 { WM_NCCREATE, sent },
11466 { WM_NCCALCSIZE, sent|wparam, 0 },
11467 { WM_CREATE, sent },
11468 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
11469 { WM_SIZE, sent|wparam, SIZE_RESTORED },
11470 { WM_MOVE, sent },
11471 { WM_SETFONT, sent },
11472 { WM_INITDIALOG, sent },
11473 { WM_CHANGEUISTATE, sent|optional },
11474 { 0 }
11475 };
11476 /* Creation of a dialog */
11477 static const struct message WmCreateDialogParamSeq_2[] = {
11478 { HCBT_CREATEWND, hook },
11479 { WM_NCCREATE, sent },
11480 { WM_NCCALCSIZE, sent|wparam, 0 },
11481 { WM_CREATE, sent },
11482 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
11483 { WM_SIZE, sent|wparam, SIZE_RESTORED },
11484 { WM_MOVE, sent },
11485 { WM_CHANGEUISTATE, sent|optional },
11486 { 0 }
11487 };
11488
11489 static void test_dialog_messages(void)
11490 {
11491 WNDCLASSA cls;
11492 HWND hdlg, hedit1, hedit2, hfocus;
11493 LRESULT ret;
11494
11495 #define set_selection(hctl, start, end) \
11496 ret = SendMessageA(hctl, EM_SETSEL, start, end); \
11497 ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
11498
11499 #define check_selection(hctl, start, end) \
11500 ret = SendMessageA(hctl, EM_GETSEL, 0, 0); \
11501 ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
11502
11503 subclass_edit();
11504
11505 hdlg = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
11506 WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
11507 0, 0, 100, 100, 0, 0, 0, NULL);
11508 ok(hdlg != 0, "Failed to create custom dialog window\n");
11509
11510 hedit1 = CreateWindowExA(0, "my_edit_class", NULL,
11511 WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
11512 0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
11513 ok(hedit1 != 0, "Failed to create edit control\n");
11514 hedit2 = CreateWindowExA(0, "my_edit_class", NULL,
11515 WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
11516 0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
11517 ok(hedit2 != 0, "Failed to create edit control\n");
11518
11519 SendMessageA(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
11520 SendMessageA(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
11521
11522 hfocus = GetFocus();
11523 ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
11524
11525 SetFocus(hedit2);
11526 hfocus = GetFocus();
11527 ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
11528
11529 check_selection(hedit1, 0, 0);
11530 check_selection(hedit2, 0, 0);
11531
11532 set_selection(hedit2, 0, -1);
11533 check_selection(hedit2, 0, 3);
11534
11535 SetFocus(0);
11536 hfocus = GetFocus();
11537 ok(hfocus == 0, "wrong focus %p\n", hfocus);
11538
11539 flush_sequence();
11540 ret = DefDlgProcA(hdlg, WM_SETFOCUS, 0, 0);
11541 ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
11542 ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
11543
11544 hfocus = GetFocus();
11545 ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
11546
11547 check_selection(hedit1, 0, 5);
11548 check_selection(hedit2, 0, 3);
11549
11550 flush_sequence();
11551 ret = DefDlgProcA(hdlg, WM_SETFOCUS, 0, 0);
11552 ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
11553 ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
11554
11555 hfocus = GetFocus();
11556 ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
11557
11558 check_selection(hedit1, 0, 5);
11559 check_selection(hedit2, 0, 3);
11560
11561 EndDialog(hdlg, 0);
11562 DestroyWindow(hedit1);
11563 DestroyWindow(hedit2);
11564 DestroyWindow(hdlg);
11565 flush_sequence();
11566
11567 #undef set_selection
11568 #undef check_selection
11569
11570 ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
11571 cls.lpszClassName = "MyDialogClass";
11572 cls.hInstance = GetModuleHandleA(NULL);
11573 /* need a cast since a dlgproc is used as a wndproc */
11574 cls.lpfnWndProc = test_dlg_proc;
11575 if (!RegisterClassA(&cls)) assert(0);
11576
11577 hdlg = CreateDialogParamA(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
11578 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
11579 ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
11580 EndDialog(hdlg, 0);
11581 DestroyWindow(hdlg);
11582 flush_sequence();
11583
11584 hdlg = CreateDialogParamA(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
11585 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
11586 ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
11587 EndDialog(hdlg, 0);
11588 DestroyWindow(hdlg);
11589 flush_sequence();
11590
11591 UnregisterClassA(cls.lpszClassName, cls.hInstance);
11592 }
11593
11594 static void test_EndDialog(void)
11595 {
11596 HWND hparent, hother, hactive, hdlg;
11597 WNDCLASSA cls;
11598
11599 hparent = CreateWindowExA(0, "TestParentClass", "Test parent",
11600 WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_DISABLED,
11601 100, 100, 200, 200, 0, 0, 0, NULL);
11602 ok (hparent != 0, "Failed to create parent window\n");
11603
11604 hother = CreateWindowExA(0, "TestParentClass", "Test parent 2",
11605 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11606 100, 100, 200, 200, 0, 0, 0, NULL);
11607 ok (hother != 0, "Failed to create parent window\n");
11608
11609 ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
11610 cls.lpszClassName = "MyDialogClass";
11611 cls.hInstance = GetModuleHandleA(NULL);
11612 cls.lpfnWndProc = test_dlg_proc;
11613 if (!RegisterClassA(&cls)) assert(0);
11614
11615 flush_sequence();
11616 SetForegroundWindow(hother);
11617 hactive = GetForegroundWindow();
11618 ok(hother == hactive, "Wrong window has focus (%p != %p)\n", hother, hactive);
11619
11620 /* create a dialog where the parent is disabled, this parent should still
11621 receive the focus when the dialog exits (even though "normally" a
11622 disabled window should not receive the focus) */
11623 hdlg = CreateDialogParamA(0, "CLASS_TEST_DIALOG_2", hparent, test_dlg_proc, 0);
11624 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
11625 SetForegroundWindow(hdlg);
11626 hactive = GetForegroundWindow();
11627 ok(hdlg == hactive, "Wrong window has focus (%p != %p)\n", hdlg, hactive);
11628 EndDialog(hdlg, 0);
11629 hactive = GetForegroundWindow();
11630 ok(hparent == hactive, "Wrong window has focus (parent != active) (active: %p, parent: %p, dlg: %p, other: %p)\n", hactive, hparent, hdlg, hother);
11631 DestroyWindow(hdlg);
11632 flush_sequence();
11633
11634 DestroyWindow( hother );
11635 DestroyWindow( hparent );
11636 UnregisterClassA(cls.lpszClassName, cls.hInstance);
11637 }
11638
11639 static void test_nullCallback(void)
11640 {
11641 HWND hwnd;
11642
11643 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
11644 100, 100, 200, 200, 0, 0, 0, NULL);
11645 ok (hwnd != 0, "Failed to create overlapped window\n");
11646
11647 SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
11648 flush_events();
11649 DestroyWindow(hwnd);
11650 }
11651
11652 /* SetActiveWindow( 0 ) hwnd visible */
11653 static const struct message SetActiveWindowSeq0[] =
11654 {
11655 { HCBT_ACTIVATE, hook|optional },
11656 { WM_NCACTIVATE, sent|wparam, 0 },
11657 { WM_GETTEXT, sent|defwinproc|optional },
11658 { WM_ACTIVATE, sent|wparam, 0 },
11659 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
11660 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
11661 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11662 { WM_KILLFOCUS, sent|optional },
11663 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11664 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
11665 { WM_NCACTIVATE, sent|wparam|optional, 1 },
11666 { WM_GETTEXT, sent|defwinproc|optional },
11667 { WM_ACTIVATE, sent|wparam|optional, 1 },
11668 { HCBT_SETFOCUS, hook|optional },
11669 { WM_KILLFOCUS, sent|defwinproc|optional },
11670 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
11671 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
11672 { WM_IME_SETCONTEXT, sent|optional },
11673 { WM_IME_SETCONTEXT, sent|optional },
11674 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
11675 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11676 { WM_SETFOCUS, sent|defwinproc|optional },
11677 { WM_GETTEXT, sent|optional },
11678 { 0 }
11679 };
11680 /* SetActiveWindow( hwnd ) hwnd visible */
11681 static const struct message SetActiveWindowSeq1[] =
11682 {
11683 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11684 { 0 }
11685 };
11686 /* SetActiveWindow( popup ) hwnd visible, popup visible */
11687 static const struct message SetActiveWindowSeq2[] =
11688 {
11689 { HCBT_ACTIVATE, hook },
11690 { WM_NCACTIVATE, sent|wparam, 0 },
11691 { WM_GETTEXT, sent|defwinproc|optional },
11692 { WM_ACTIVATE, sent|wparam, 0 },
11693 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11694 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
11695 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11696 { WM_NCPAINT, sent|optional },
11697 { WM_GETTEXT, sent|defwinproc|optional },
11698 { WM_ERASEBKGND, sent|optional },
11699 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11700 { WM_NCACTIVATE, sent|wparam, 1 },
11701 { WM_GETTEXT, sent|defwinproc|optional },
11702 { WM_ACTIVATE, sent|wparam, 1 },
11703 { HCBT_SETFOCUS, hook },
11704 { WM_KILLFOCUS, sent|defwinproc },
11705 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
11706 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11707 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
11708 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11709 { WM_SETFOCUS, sent|defwinproc },
11710 { WM_GETTEXT, sent|optional },
11711 { 0 }
11712 };
11713
11714 /* SetActiveWindow( hwnd ) hwnd not visible */
11715 static const struct message SetActiveWindowSeq3[] =
11716 {
11717 { HCBT_ACTIVATE, hook },
11718 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11719 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11720 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
11721 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11722 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11723 { WM_ACTIVATEAPP, sent|wparam, 1 },
11724 { WM_ACTIVATEAPP, sent|wparam, 1 },
11725 { WM_NCACTIVATE, sent|wparam, 1 },
11726 { WM_ACTIVATE, sent|wparam, 1 },
11727 { HCBT_SETFOCUS, hook },
11728 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11729 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11730 { WM_SETFOCUS, sent|defwinproc },
11731 { 0 }
11732 };
11733 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
11734 static const struct message SetActiveWindowSeq4[] =
11735 {
11736 { HCBT_ACTIVATE, hook },
11737 { WM_NCACTIVATE, sent|wparam, 0 },
11738 { WM_GETTEXT, sent|defwinproc|optional },
11739 { WM_ACTIVATE, sent|wparam, 0 },
11740 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
11741 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
11742 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
11743 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11744 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
11745 { WM_NCACTIVATE, sent|wparam, 1 },
11746 { WM_GETTEXT, sent|defwinproc|optional },
11747 { WM_ACTIVATE, sent|wparam, 1 },
11748 { HCBT_SETFOCUS, hook },
11749 { WM_KILLFOCUS, sent|defwinproc },
11750 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
11751 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11752 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
11753 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
11754 { WM_SETFOCUS, sent|defwinproc },
11755 { 0 }
11756 };
11757
11758
11759 static void test_SetActiveWindow(void)
11760 {
11761 HWND hwnd, popup, ret;
11762
11763 hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
11764 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11765 100, 100, 200, 200, 0, 0, 0, NULL);
11766
11767 popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
11768 WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
11769 100, 100, 200, 200, hwnd, 0, 0, NULL);
11770
11771 ok(hwnd != 0, "Failed to create overlapped window\n");
11772 ok(popup != 0, "Failed to create popup window\n");
11773 SetForegroundWindow( popup );
11774 flush_sequence();
11775
11776 trace("SetActiveWindow(0)\n");
11777 ret = SetActiveWindow(0);
11778 ok( ret == popup, "Failed to SetActiveWindow(0)\n");
11779 ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", FALSE);
11780 flush_sequence();
11781
11782 trace("SetActiveWindow(hwnd), hwnd visible\n");
11783 ret = SetActiveWindow(hwnd);
11784 if (ret == hwnd) ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
11785 flush_sequence();
11786
11787 trace("SetActiveWindow(popup), hwnd visible, popup visible\n");
11788 ret = SetActiveWindow(popup);
11789 ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visible\n");
11790 ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visible", FALSE);
11791 flush_sequence();
11792
11793 ShowWindow(hwnd, SW_HIDE);
11794 ShowWindow(popup, SW_HIDE);
11795 flush_sequence();
11796
11797 trace("SetActiveWindow(hwnd), hwnd not visible\n");
11798 ret = SetActiveWindow(hwnd);
11799 ok( ret == NULL, "SetActiveWindow(hwnd), hwnd not visible, previous is %p\n", ret );
11800 ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
11801 flush_sequence();
11802
11803 trace("SetActiveWindow(popup), hwnd not visible, popup not visible\n");
11804 ret = SetActiveWindow(popup);
11805 ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
11806 ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visible", TRUE);
11807 flush_sequence();
11808
11809 trace("done\n");
11810
11811 DestroyWindow(hwnd);
11812 }
11813
11814 static const struct message SetForegroundWindowSeq[] =
11815 {
11816 { WM_NCACTIVATE, sent|wparam, 0 },
11817 { WM_GETTEXT, sent|defwinproc|optional },
11818 { WM_ACTIVATE, sent|wparam, 0 },
11819 { WM_ACTIVATEAPP, sent|wparam, 0 },
11820 { WM_KILLFOCUS, sent },
11821 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
11822 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
11823 { 0 }
11824 };
11825
11826 static void test_SetForegroundWindow(void)
11827 {
11828 HWND hwnd;
11829
11830 hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
11831 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11832 100, 100, 200, 200, 0, 0, 0, NULL);
11833 ok (hwnd != 0, "Failed to create overlapped window\n");
11834 SetForegroundWindow( hwnd );
11835 flush_sequence();
11836
11837 trace("SetForegroundWindow( 0 )\n");
11838 SetForegroundWindow( 0 );
11839 ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
11840 trace("SetForegroundWindow( GetDesktopWindow() )\n");
11841 SetForegroundWindow( GetDesktopWindow() );
11842 ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
11843 "foreground top level window", FALSE);
11844 trace("done\n");
11845
11846 DestroyWindow(hwnd);
11847 }
11848
11849 static void test_dbcs_wm_char(void)
11850 {
11851 BYTE dbch[2];
11852 WCHAR wch, bad_wch;
11853 HWND hwnd, hwnd2;
11854 MSG msg;
11855 DWORD time;
11856 POINT pt;
11857 DWORD_PTR res;
11858 CPINFOEXA cpinfo;
11859 UINT i, j, k;
11860 struct message wmCharSeq[2];
11861 BOOL ret;
11862
11863 if (!pGetCPInfoExA)
11864 {
11865 win_skip("GetCPInfoExA is not available\n");
11866 return;
11867 }
11868
11869 pGetCPInfoExA( CP_ACP, 0, &cpinfo );
11870 if (cpinfo.MaxCharSize != 2)
11871 {
11872 skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
11873 return;
11874 }
11875
11876 dbch[0] = dbch[1] = 0;
11877 wch = 0;
11878 bad_wch = cpinfo.UnicodeDefaultChar;
11879 for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
11880 for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
11881 for (k = 128; k <= 255; k++)
11882 {
11883 char str[2];
11884 WCHAR wstr[2];
11885 str[0] = j;
11886 str[1] = k;
11887 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
11888 WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
11889 (BYTE)str[0] == j && (BYTE)str[1] == k &&
11890 HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
11891 {
11892 dbch[0] = j;
11893 dbch[1] = k;
11894 wch = wstr[0];
11895 break;
11896 }
11897 }
11898
11899 if (!wch)
11900 {
11901 skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
11902 return;
11903 }
11904 trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
11905 dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
11906
11907 hwnd = CreateWindowExW(0, testWindowClassW, NULL,
11908 WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11909 hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
11910 WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11911 ok (hwnd != 0, "Failed to create overlapped window\n");
11912 ok (hwnd2 != 0, "Failed to create overlapped window\n");
11913 flush_sequence();
11914
11915 memset( wmCharSeq, 0, sizeof(wmCharSeq) );
11916 wmCharSeq[0].message = WM_CHAR;
11917 wmCharSeq[0].flags = sent|wparam;
11918 wmCharSeq[0].wParam = wch;
11919
11920 /* posted message */
11921 PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11922 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11923 ok( !ret, "got message %x\n", msg.message );
11924 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11925 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11926 ok( ret, "no message\n" );
11927 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11928 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11929 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11930 ok( !ret, "got message %x\n", msg.message );
11931
11932 /* posted thread message */
11933 PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
11934 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11935 ok( !ret, "got message %x\n", msg.message );
11936 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11937 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11938 ok( ret, "no message\n" );
11939 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11940 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11941 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11942 ok( !ret, "got message %x\n", msg.message );
11943
11944 /* sent message */
11945 flush_sequence();
11946 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11947 ok_sequence( WmEmptySeq, "no messages", FALSE );
11948 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11949 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11950 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11951 ok( !ret, "got message %x\n", msg.message );
11952
11953 /* sent message with timeout */
11954 flush_sequence();
11955 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11956 ok_sequence( WmEmptySeq, "no messages", FALSE );
11957 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11958 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11959 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11960 ok( !ret, "got message %x\n", msg.message );
11961
11962 /* sent message with timeout and callback */
11963 flush_sequence();
11964 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11965 ok_sequence( WmEmptySeq, "no messages", FALSE );
11966 SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11967 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11968 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11969 ok( !ret, "got message %x\n", msg.message );
11970
11971 /* sent message with callback */
11972 flush_sequence();
11973 SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11974 ok_sequence( WmEmptySeq, "no messages", FALSE );
11975 SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11976 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11977 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
11978 ok( !ret, "got message %x\n", msg.message );
11979
11980 /* direct window proc call */
11981 flush_sequence();
11982 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11983 ok_sequence( WmEmptySeq, "no messages", FALSE );
11984 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11985 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11986
11987 /* dispatch message */
11988 msg.hwnd = hwnd;
11989 msg.message = WM_CHAR;
11990 msg.wParam = dbch[0];
11991 msg.lParam = 0;
11992 DispatchMessageA( &msg );
11993 ok_sequence( WmEmptySeq, "no messages", FALSE );
11994 msg.wParam = dbch[1];
11995 DispatchMessageA( &msg );
11996 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11997
11998 /* window handle is irrelevant */
11999 flush_sequence();
12000 SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
12001 ok_sequence( WmEmptySeq, "no messages", FALSE );
12002 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
12003 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
12004 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
12005 ok( !ret, "got message %x\n", msg.message );
12006
12007 /* interleaved post and send */
12008 flush_sequence();
12009 PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
12010 SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
12011 ok_sequence( WmEmptySeq, "no messages", FALSE );
12012 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
12013 ok( !ret, "got message %x\n", msg.message );
12014 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
12015 ok_sequence( WmEmptySeq, "no messages", FALSE );
12016 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
12017 ok( ret, "no message\n" );
12018 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
12019 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
12020 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
12021 ok( !ret, "got message %x\n", msg.message );
12022 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
12023 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
12024 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
12025 ok( !ret, "got message %x\n", msg.message );
12026
12027 /* interleaved sent message and winproc */
12028 flush_sequence();
12029 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
12030 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
12031 ok_sequence( WmEmptySeq, "no messages", FALSE );
12032 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
12033 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
12034 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
12035 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
12036
12037 /* interleaved winproc and dispatch */
12038 msg.hwnd = hwnd;
12039 msg.message = WM_CHAR;
12040 msg.wParam = dbch[0];
12041 msg.lParam = 0;
12042 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
12043 DispatchMessageA( &msg );
12044 ok_sequence( WmEmptySeq, "no messages", FALSE );
12045 msg.wParam = dbch[1];
12046 DispatchMessageA( &msg );
12047 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
12048 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
12049 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
12050
12051 /* interleaved sends */
12052 flush_sequence();
12053 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
12054 SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
12055 ok_sequence( WmEmptySeq, "no messages", FALSE );
12056 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
12057 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
12058 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
12059 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
12060
12061 /* dbcs WM_CHAR */
12062 flush_sequence();
12063 SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
12064 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
12065 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
12066 ok( !ret, "got message %x\n", msg.message );
12067
12068 /* other char messages are not magic */
12069 PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
12070 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
12071 ok( ret, "no message\n" );
12072 ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
12073 ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
12074 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
12075 ok( !ret, "got message %x\n", msg.message );
12076 PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
12077 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
12078 ok( ret, "no message\n" );
12079 ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
12080 ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
12081 ret = PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE );
12082 ok( !ret, "got message %x\n", msg.message );
12083
12084 /* test retrieving messages */
12085
12086 PostMessageW( hwnd, WM_CHAR, wch, 0 );
12087 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
12088 ok( ret, "no message\n" );
12089 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
12090 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
12091 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
12092 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
12093 ok( ret, "no message\n" );
12094 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
12095 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
12096 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
12097 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
12098 ok( !ret, "got message %x\n", msg.message );
12099
12100 /* message filters */
12101 PostMessageW( hwnd, WM_CHAR, wch, 0 );
12102 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
12103 ok( ret, "no message\n" );
12104 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
12105 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
12106 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
12107 /* message id is filtered, hwnd is not */
12108 ret = PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE );
12109 ok( !ret, "no message\n" );
12110 ret = PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE );
12111 ok( ret, "no message\n" );
12112 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
12113 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
12114 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
12115 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
12116 ok( !ret, "got message %x\n", msg.message );
12117
12118 /* mixing GetMessage and PostMessage */
12119 PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
12120 ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
12121 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
12122 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
12123 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
12124 ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
12125 time = msg.time;
12126 pt = msg.pt;
12127 ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
12128 ret = PeekMessageA( &msg, 0, 0, 0, PM_REMOVE );
12129 ok( ret, "no message\n" );
12130 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
12131 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
12132 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
12133 ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
12134 ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
12135 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 );
12136 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
12137 ok( !ret, "got message %x\n", msg.message );
12138
12139 /* without PM_REMOVE */
12140 PostMessageW( hwnd, WM_CHAR, wch, 0 );
12141 ret = PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE );
12142 ok( ret, "no message\n" );
12143 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
12144 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
12145 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
12146 ret = PeekMessageA( &msg, 0, 0, 0, PM_REMOVE );
12147 ok( ret, "no message\n" );
12148 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
12149 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
12150 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
12151 ret = PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE );
12152 ok( ret, "no message\n" );
12153 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
12154 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
12155 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
12156 ret = PeekMessageA( &msg, 0, 0, 0, PM_REMOVE );
12157 ok( ret, "no message\n" );
12158 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
12159 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
12160 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
12161 ret = PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE );
12162 ok( !ret, "got message %x\n", msg.message );
12163
12164 DestroyWindow(hwnd);
12165 DestroyWindow(hwnd2);
12166 }
12167
12168 static void test_unicode_wm_char(void)
12169 {
12170 HWND hwnd;
12171 MSG msg;
12172 struct message seq[2];
12173 HKL hkl_orig, hkl_greek;
12174 DWORD cp;
12175 LCID thread_locale;
12176
12177 hkl_orig = GetKeyboardLayout( 0 );
12178 GetLocaleInfoW( LOWORD( hkl_orig ), LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER, (WCHAR*)&cp, sizeof(cp) / sizeof(WCHAR) );
12179 if (cp != 1252)
12180 {
12181 skip( "Default codepage %d\n", cp );
12182 return;
12183 }
12184
12185 hkl_greek = LoadKeyboardLayoutA( "00000408", 0 );
12186 if (!hkl_greek || hkl_greek == hkl_orig /* win2k */)
12187 {
12188 skip( "Unable to load Greek keyboard layout\n" );
12189 return;
12190 }
12191
12192 hwnd = CreateWindowExW( 0, testWindowClassW, NULL, WS_OVERLAPPEDWINDOW,
12193 100, 100, 200, 200, 0, 0, 0, NULL );
12194 flush_sequence();
12195
12196 PostMessageW( hwnd, WM_CHAR, 0x3b1, 0 );
12197
12198 while (GetMessageW( &msg, hwnd, 0, 0 ))
12199 {
12200 if (!ignore_message( msg.message )) break;
12201 }
12202
12203 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
12204 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
12205 ok( msg.wParam == 0x3b1, "bad wparam %lx\n", msg.wParam );
12206 ok( msg.lParam == 0, "bad lparam %lx\n", msg.lParam );
12207
12208 DispatchMessageW( &msg );
12209
12210 memset( seq, 0, sizeof(seq) );
12211 seq[0].message = WM_CHAR;
12212 seq[0].flags = sent|wparam;
12213 seq[0].wParam = 0x3b1;
12214
12215 ok_sequence( seq, "unicode WM_CHAR", FALSE );
12216
12217 flush_sequence();
12218
12219 /* greek alpha -> 'a' in cp1252 */
12220 PostMessageW( hwnd, WM_CHAR, 0x3b1, 0 );
12221
12222 ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
12223 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
12224 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
12225 ok( msg.wParam == 0x61, "bad wparam %lx\n", msg.wParam );
12226 ok( msg.lParam == 0, "bad lparam %lx\n", msg.lParam );
12227
12228 DispatchMessageA( &msg );
12229
12230 seq[0].wParam = 0x61;
12231 ok_sequence( seq, "unicode WM_CHAR", FALSE );
12232
12233 thread_locale = GetThreadLocale();
12234 ActivateKeyboardLayout( hkl_greek, 0 );
12235 ok( GetThreadLocale() == thread_locale, "locale changed from %08x to %08x\n",
12236 thread_locale, GetThreadLocale() );
12237
12238 flush_sequence();
12239
12240 /* greek alpha -> 0xe1 in cp1253 */
12241 PostMessageW( hwnd, WM_CHAR, 0x3b1, 0 );
12242
12243 ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
12244 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
12245 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
12246 ok( msg.wParam == 0xe1, "bad wparam %lx\n", msg.wParam );
12247 ok( msg.lParam == 0, "bad lparam %lx\n", msg.lParam );
12248
12249 DispatchMessageA( &msg );
12250
12251 seq[0].wParam = 0x3b1;
12252 ok_sequence( seq, "unicode WM_CHAR", FALSE );
12253
12254 DestroyWindow( hwnd );
12255 ActivateKeyboardLayout( hkl_orig, 0 );
12256 UnloadKeyboardLayout( hkl_greek );
12257 }
12258
12259 #define ID_LISTBOX 0x000f
12260
12261 static const struct message wm_lb_setcursel_0[] =
12262 {
12263 { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
12264 { WM_CTLCOLORLISTBOX, sent|parent },
12265 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
12266 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
12267 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
12268 { 0 }
12269 };
12270 static const struct message wm_lb_setcursel_1[] =
12271 {
12272 { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
12273 { WM_CTLCOLORLISTBOX, sent|parent },
12274 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
12275 { WM_CTLCOLORLISTBOX, sent|parent },
12276 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
12277 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
12278 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
12279 { 0 }
12280 };
12281 static const struct message wm_lb_setcursel_2[] =
12282 {
12283 { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
12284 { WM_CTLCOLORLISTBOX, sent|parent },
12285 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
12286 { WM_CTLCOLORLISTBOX, sent|parent },
12287 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
12288 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
12289 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
12290 { 0 }
12291 };
12292 static const struct message wm_lb_click_0[] =
12293 {
12294 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
12295 { HCBT_SETFOCUS, hook },
12296 { WM_KILLFOCUS, sent|parent },
12297 { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
12298 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
12299 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
12300 { WM_SETFOCUS, sent|defwinproc },
12301
12302 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
12303 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
12304 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
12305 { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
12306 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
12307
12308 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
12309 { WM_CTLCOLORLISTBOX, sent|parent },
12310 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
12311 { WM_CTLCOLORLISTBOX, sent|parent },
12312 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
12313 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
12314
12315 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
12316 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
12317
12318 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
12319 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
12320 { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
12321 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
12322 { 0 }
12323 };
12324 static const struct message wm_lb_deletestring[] =
12325 {
12326 { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
12327 { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
12328 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
12329 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
12330 { 0 }
12331 };
12332 static const struct message wm_lb_deletestring_reset[] =
12333 {
12334 { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
12335 { LB_RESETCONTENT, sent|wparam|lparam|defwinproc|optional, 0, 0 },
12336 { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
12337 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
12338 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
12339 { 0 }
12340 };
12341
12342 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
12343
12344 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
12345
12346 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
12347 {
12348 static LONG defwndproc_counter = 0;
12349 LRESULT ret;
12350 struct recvd_message msg;
12351
12352 /* do not log painting messages */
12353 if (message != WM_PAINT &&
12354 message != WM_NCPAINT &&
12355 message != WM_SYNCPAINT &&
12356 message != WM_ERASEBKGND &&
12357 message != WM_NCHITTEST &&
12358 message != WM_GETTEXT &&
12359 !ignore_message( message ))
12360 {
12361 msg.hwnd = hwnd;
12362 msg.message = message;
12363 msg.flags = sent|wparam|lparam;
12364 if (defwndproc_counter) msg.flags |= defwinproc;
12365 msg.wParam = wp;
12366 msg.lParam = lp;
12367 msg.descr = "listbox";
12368 add_message(&msg);
12369 }
12370
12371 defwndproc_counter++;
12372 ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
12373 defwndproc_counter--;
12374
12375 return ret;
12376 }
12377
12378 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
12379 int caret_index, int top_index, int line)
12380 {
12381 LRESULT ret;
12382
12383 /* calling an orig proc helps to avoid unnecessary message logging */
12384 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
12385 ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
12386 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
12387 ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
12388 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
12389 ok_(__FILE__, line)(ret == caret_index ||
12390 broken(cur_sel == -1 && caret_index == 0 && ret == -1), /* nt4 */
12391 "expected caret index %d, got %ld\n", caret_index, ret);
12392 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
12393 ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
12394 }
12395
12396 static void test_listbox_messages(void)
12397 {
12398 HWND parent, listbox;
12399 LRESULT ret;
12400
12401 parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
12402 100, 100, 200, 200, 0, 0, 0, NULL);
12403 listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
12404 WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
12405 10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
12406 listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
12407
12408 check_lb_state(listbox, 0, LB_ERR, 0, 0);
12409
12410 ret = SendMessageA(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
12411 ok(ret == 0, "expected 0, got %ld\n", ret);
12412 ret = SendMessageA(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
12413 ok(ret == 1, "expected 1, got %ld\n", ret);
12414 ret = SendMessageA(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
12415 ok(ret == 2, "expected 2, got %ld\n", ret);
12416
12417 check_lb_state(listbox, 3, LB_ERR, 0, 0);
12418
12419 flush_sequence();
12420
12421 log_all_parent_messages++;
12422
12423 trace("selecting item 0\n");
12424 ret = SendMessageA(listbox, LB_SETCURSEL, 0, 0);
12425 ok(ret == 0, "expected 0, got %ld\n", ret);
12426 ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
12427 check_lb_state(listbox, 3, 0, 0, 0);
12428 flush_sequence();
12429
12430 trace("selecting item 1\n");
12431 ret = SendMessageA(listbox, LB_SETCURSEL, 1, 0);
12432 ok(ret == 1, "expected 1, got %ld\n", ret);
12433 ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
12434 check_lb_state(listbox, 3, 1, 1, 0);
12435
12436 trace("selecting item 2\n");
12437 ret = SendMessageA(listbox, LB_SETCURSEL, 2, 0);
12438 ok(ret == 2, "expected 2, got %ld\n", ret);
12439 ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
12440 check_lb_state(listbox, 3, 2, 2, 0);
12441
12442 trace("clicking on item 0\n");
12443 ret = SendMessageA(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
12444 ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
12445 ret = SendMessageA(listbox, WM_LBUTTONUP, 0, 0);
12446 ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
12447 ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
12448 check_lb_state(listbox, 3, 0, 0, 0);
12449 flush_sequence();
12450
12451 trace("deleting item 0\n");
12452 ret = SendMessageA(listbox, LB_DELETESTRING, 0, 0);
12453 ok(ret == 2, "expected 2, got %ld\n", ret);
12454 ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
12455 check_lb_state(listbox, 2, -1, 0, 0);
12456 flush_sequence();
12457
12458 trace("deleting item 0\n");
12459 ret = SendMessageA(listbox, LB_DELETESTRING, 0, 0);
12460 ok(ret == 1, "expected 1, got %ld\n", ret);
12461 ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
12462 check_lb_state(listbox, 1, -1, 0, 0);
12463 flush_sequence();
12464
12465 trace("deleting item 0\n");
12466 ret = SendMessageA(listbox, LB_DELETESTRING, 0, 0);
12467 ok(ret == 0, "expected 0, got %ld\n", ret);
12468 ok_sequence(wm_lb_deletestring_reset, "LB_DELETESTRING 0", FALSE );
12469 check_lb_state(listbox, 0, -1, 0, 0);
12470 flush_sequence();
12471
12472 trace("deleting item 0\n");
12473 ret = SendMessageA(listbox, LB_DELETESTRING, 0, 0);
12474 ok(ret == LB_ERR, "expected LB_ERR, got %ld\n", ret);
12475 check_lb_state(listbox, 0, -1, 0, 0);
12476 flush_sequence();
12477
12478 log_all_parent_messages--;
12479
12480 DestroyWindow(listbox);
12481 DestroyWindow(parent);
12482 }
12483
12484 /*************************** Menu test ******************************/
12485 static const struct message wm_popup_menu_1[] =
12486 {
12487 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
12488 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
12489 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
12490 { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
12491 { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
12492 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
12493 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
12494 { WM_INITMENU, sent|lparam, 0, 0 },
12495 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
12496 { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
12497 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
12498 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
12499 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
12500 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
12501 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001, 0, 0x40000000 },
12502 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
12503 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
12504 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
12505 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
12506 { WM_MENUCOMMAND, sent }, /* |wparam, 200 - Win9x */
12507 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
12508 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
12509 { 0 }
12510 };
12511 static const struct message wm_popup_menu_2[] =
12512 {
12513 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
12514 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
12515 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
12516 { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
12517 { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
12518 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
12519 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
12520 { WM_INITMENU, sent|lparam, 0, 0 },
12521 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
12522 { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
12523 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
12524 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
12525 { HCBT_CREATEWND, hook },
12526 { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
12527 |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
12528 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
12529 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
12530 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
12531 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
12532 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
12533 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
12534 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
12535 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
12536 { HCBT_DESTROYWND, hook },
12537 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
12538 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
12539 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
12540 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
12541 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
12542 { WM_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
12543 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
12544 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
12545 { 0 }
12546 };
12547 static const struct message wm_popup_menu_3[] =
12548 {
12549 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
12550 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
12551 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
12552 { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
12553 { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
12554 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
12555 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
12556 { WM_INITMENU, sent|lparam, 0, 0 },
12557 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
12558 { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
12559 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
12560 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
12561 { HCBT_CREATEWND, hook },
12562 { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
12563 |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
12564 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
12565 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
12566 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
12567 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
12568 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
12569 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
12570 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
12571 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
12572 { HCBT_DESTROYWND, hook },
12573 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
12574 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
12575 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
12576 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
12577 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
12578 { WM_COMMAND, sent|wparam|lparam, 100, 0 },
12579 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
12580 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
12581 { 0 }
12582 };
12583
12584 static const struct message wm_single_menu_item[] =
12585 {
12586 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
12587 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
12588 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'Q', 0x20000001 },
12589 { WM_SYSKEYDOWN, sent|wparam|lparam, 'Q', 0x20000001 },
12590 { WM_SYSCHAR, sent|wparam|lparam, 'q', 0x20000001 },
12591 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'q' },
12592 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
12593 { WM_INITMENU, sent|lparam, 0, 0 },
12594 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(300,MF_HILITE) },
12595 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
12596 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
12597 { WM_MENUCOMMAND, sent },
12598 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'Q', 0xe0000001 },
12599 { WM_SYSKEYUP, sent|wparam|lparam, 'Q', 0xe0000001 },
12600 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 },
12601 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
12602
12603 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 1 },
12604 { WM_KEYDOWN, sent|wparam|lparam, VK_ESCAPE, 1 },
12605 { WM_CHAR, sent|wparam|lparam, VK_ESCAPE, 0x00000001 },
12606 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_ESCAPE, 0xc0000001 },
12607 { WM_KEYUP, sent|wparam|lparam, VK_ESCAPE, 0xc0000001 },
12608 { 0 }
12609 };
12610
12611 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
12612 {
12613 if (message == WM_ENTERIDLE ||
12614 message == WM_INITMENU ||
12615 message == WM_INITMENUPOPUP ||
12616 message == WM_MENUSELECT ||
12617 message == WM_PARENTNOTIFY ||
12618 message == WM_ENTERMENULOOP ||
12619 message == WM_EXITMENULOOP ||
12620 message == WM_UNINITMENUPOPUP ||
12621 message == WM_KEYDOWN ||
12622 message == WM_KEYUP ||
12623 message == WM_CHAR ||
12624 message == WM_SYSKEYDOWN ||
12625 message == WM_SYSKEYUP ||
12626 message == WM_SYSCHAR ||
12627 message == WM_COMMAND ||
12628 message == WM_MENUCOMMAND)
12629 {
12630 struct recvd_message msg;
12631
12632 msg.hwnd = hwnd;
12633 msg.message = message;
12634 msg.flags = sent|wparam|lparam;
12635 msg.wParam = wp;
12636 msg.lParam = lp;
12637 msg.descr = "parent_menu_proc";
12638 add_message(&msg);
12639 }
12640
12641 return DefWindowProcA(hwnd, message, wp, lp);
12642 }
12643
12644 static void set_menu_style(HMENU hmenu, DWORD style)
12645 {
12646 MENUINFO mi;
12647 BOOL ret;
12648
12649 mi.cbSize = sizeof(mi);
12650 mi.fMask = MIM_STYLE;
12651 mi.dwStyle = style;
12652 SetLastError(0xdeadbeef);
12653 ret = pSetMenuInfo(hmenu, &mi);
12654 ok(ret, "SetMenuInfo error %u\n", GetLastError());
12655 }
12656
12657 static DWORD get_menu_style(HMENU hmenu)
12658 {
12659 MENUINFO mi;
12660 BOOL ret;
12661
12662 mi.cbSize = sizeof(mi);
12663 mi.fMask = MIM_STYLE;
12664 mi.dwStyle = 0;
12665 SetLastError(0xdeadbeef);
12666 ret = pGetMenuInfo(hmenu, &mi);
12667 ok(ret, "GetMenuInfo error %u\n", GetLastError());
12668
12669 return mi.dwStyle;
12670 }
12671
12672 static void test_menu_messages(void)
12673 {
12674 MSG msg;
12675 WNDCLASSA cls;
12676 HMENU hmenu, hmenu_popup;
12677 HWND hwnd;
12678 DWORD style;
12679
12680 if (!pGetMenuInfo || !pSetMenuInfo)
12681 {
12682 win_skip("GetMenuInfo and/or SetMenuInfo are not available\n");
12683 return;
12684 }
12685 cls.style = 0;
12686 cls.lpfnWndProc = parent_menu_proc;
12687 cls.cbClsExtra = 0;
12688 cls.cbWndExtra = 0;
12689 cls.hInstance = GetModuleHandleA(0);
12690 cls.hIcon = 0;
12691 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
12692 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
12693 cls.lpszMenuName = NULL;
12694 cls.lpszClassName = "TestMenuClass";
12695 UnregisterClassA(cls.lpszClassName, cls.hInstance);
12696 if (!RegisterClassA(&cls)) assert(0);
12697
12698 SetLastError(0xdeadbeef);
12699 hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
12700 100, 100, 200, 200, 0, 0, 0, NULL);
12701 ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
12702
12703 SetLastError(0xdeadbeef);
12704 hmenu = LoadMenuA(GetModuleHandleA(NULL), MAKEINTRESOURCEA(1));
12705 ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
12706
12707 SetMenu(hwnd, hmenu);
12708 SetForegroundWindow( hwnd );
12709 flush_events();
12710
12711 set_menu_style(hmenu, MNS_NOTIFYBYPOS);
12712 style = get_menu_style(hmenu);
12713 ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
12714
12715 hmenu_popup = GetSubMenu(hmenu, 0);
12716 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12717 style = get_menu_style(hmenu_popup);
12718 ok(style == 0, "expected 0, got %u\n", style);
12719
12720 hmenu_popup = GetSubMenu(hmenu_popup, 0);
12721 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12722 style = get_menu_style(hmenu_popup);
12723 ok(style == 0, "expected 0, got %u\n", style);
12724
12725 /* Alt+E, Enter */
12726 trace("testing a popup menu command\n");
12727 flush_sequence();
12728 keybd_event(VK_MENU, 0, 0, 0);
12729 keybd_event('E', 0, 0, 0);
12730 keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
12731 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12732 keybd_event(VK_RETURN, 0, 0, 0);
12733 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
12734 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
12735 {
12736 TranslateMessage(&msg);
12737 DispatchMessageA(&msg);
12738 }
12739 if (!sequence_cnt) /* we didn't get any message */
12740 {
12741 skip( "queuing key events not supported\n" );
12742 goto done;
12743 }
12744 /* win98 queues only a WM_KEYUP and doesn't start menu tracking */
12745 if (sequence[0].message == WM_KEYUP && sequence[0].wParam == VK_MENU)
12746 {
12747 win_skip( "menu tracking through VK_MENU not supported\n" );
12748 goto done;
12749 }
12750 ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
12751
12752 /* Alt+F, Right, Enter */
12753 trace("testing submenu of a popup menu command\n");
12754 flush_sequence();
12755 keybd_event(VK_MENU, 0, 0, 0);
12756 keybd_event('F', 0, 0, 0);
12757 keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
12758 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12759 keybd_event(VK_RIGHT, 0, 0, 0);
12760 keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
12761 keybd_event(VK_RETURN, 0, 0, 0);
12762 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
12763 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
12764 {
12765 TranslateMessage(&msg);
12766 DispatchMessageA(&msg);
12767 }
12768 ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
12769
12770 trace("testing single menu item command\n");
12771 flush_sequence();
12772 keybd_event(VK_MENU, 0, 0, 0);
12773 keybd_event('Q', 0, 0, 0);
12774 keybd_event('Q', 0, KEYEVENTF_KEYUP, 0);
12775 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12776 keybd_event(VK_ESCAPE, 0, 0, 0);
12777 keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0);
12778 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
12779 {
12780 TranslateMessage(&msg);
12781 DispatchMessageA(&msg);
12782 }
12783 ok_sequence(wm_single_menu_item, "single menu item command", FALSE);
12784
12785 set_menu_style(hmenu, 0);
12786 style = get_menu_style(hmenu);
12787 ok(style == 0, "expected 0, got %u\n", style);
12788
12789 hmenu_popup = GetSubMenu(hmenu, 0);
12790 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12791 set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
12792 style = get_menu_style(hmenu_popup);
12793 ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
12794
12795 hmenu_popup = GetSubMenu(hmenu_popup, 0);
12796 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
12797 style = get_menu_style(hmenu_popup);
12798 ok(style == 0, "expected 0, got %u\n", style);
12799
12800 /* Alt+F, Right, Enter */
12801 trace("testing submenu of a popup menu command\n");
12802 flush_sequence();
12803 keybd_event(VK_MENU, 0, 0, 0);
12804 keybd_event('F', 0, 0, 0);
12805 keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
12806 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
12807 keybd_event(VK_RIGHT, 0, 0, 0);
12808 keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
12809 keybd_event(VK_RETURN, 0, 0, 0);
12810 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
12811 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
12812 {
12813 TranslateMessage(&msg);
12814 DispatchMessageA(&msg);
12815 }
12816 ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
12817
12818 done:
12819 DestroyWindow(hwnd);
12820 DestroyMenu(hmenu);
12821 }
12822
12823
12824 static void test_paintingloop(void)
12825 {
12826 HWND hwnd;
12827
12828 paint_loop_done = FALSE;
12829 hwnd = CreateWindowExA(0x0,"PaintLoopWindowClass",
12830 "PaintLoopWindowClass",WS_OVERLAPPEDWINDOW,
12831 100, 100, 100, 100, 0, 0, 0, NULL );
12832 ok(hwnd != 0, "PaintLoop window error %u\n", GetLastError());
12833 ShowWindow(hwnd,SW_NORMAL);
12834 SetFocus(hwnd);
12835
12836 while (!paint_loop_done)
12837 {
12838 MSG msg;
12839 if (PeekMessageA(&msg, 0, 0, 0, 1))
12840 {
12841 TranslateMessage(&msg);
12842 DispatchMessageA(&msg);
12843 }
12844 }
12845 DestroyWindow(hwnd);
12846 }
12847
12848 static void test_defwinproc(void)
12849 {
12850 HWND hwnd;
12851 MSG msg;
12852 BOOL gotwmquit = FALSE;
12853 hwnd = CreateWindowExA(0, "static", "test_defwndproc", WS_POPUP, 0,0,0,0,0,0,0, NULL);
12854 assert(hwnd);
12855 DefWindowProcA( hwnd, WM_ENDSESSION, 1, 0);
12856 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) {
12857 if( msg.message == WM_QUIT) gotwmquit = TRUE;
12858 DispatchMessageA( &msg );
12859 }
12860 ok(!gotwmquit, "Unexpected WM_QUIT message!\n");
12861 DestroyWindow( hwnd);
12862 }
12863
12864 #define clear_clipboard(hwnd) clear_clipboard_(__LINE__, (hwnd))
12865 static void clear_clipboard_(int line, HWND hWnd)
12866 {
12867 BOOL succ;
12868 succ = OpenClipboard(hWnd);
12869 ok_(__FILE__, line)(succ, "OpenClipboard failed, err=%u\n", GetLastError());
12870 succ = EmptyClipboard();
12871 ok_(__FILE__, line)(succ, "EmptyClipboard failed, err=%u\n", GetLastError());
12872 succ = CloseClipboard();
12873 ok_(__FILE__, line)(succ, "CloseClipboard failed, err=%u\n", GetLastError());
12874 }
12875
12876 #define expect_HWND(expected, got) expect_HWND_(__LINE__, (expected), (got))
12877 static void expect_HWND_(int line, HWND expected, HWND got)
12878 {
12879 ok_(__FILE__, line)(got==expected, "Expected %p, got %p\n", expected, got);
12880 }
12881
12882 static WNDPROC pOldViewerProc;
12883
12884 static LRESULT CALLBACK recursive_viewer_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
12885 {
12886 static BOOL recursion_guard;
12887
12888 if (message == WM_DRAWCLIPBOARD && !recursion_guard)
12889 {
12890 recursion_guard = TRUE;
12891 clear_clipboard(hWnd);
12892 recursion_guard = FALSE;
12893 }
12894 return CallWindowProcA(pOldViewerProc, hWnd, message, wParam, lParam);
12895 }
12896
12897 static void test_clipboard_viewers(void)
12898 {
12899 static struct message wm_change_cb_chain[] =
12900 {
12901 { WM_CHANGECBCHAIN, sent|wparam|lparam, 0, 0 },
12902 { 0 }
12903 };
12904 static const struct message wm_clipboard_destroyed[] =
12905 {
12906 { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
12907 { 0 }
12908 };
12909 static struct message wm_clipboard_changed[] =
12910 {
12911 { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
12912 { 0 }
12913 };
12914 static struct message wm_clipboard_changed_and_owned[] =
12915 {
12916 { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
12917 { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
12918 { 0 }
12919 };
12920
12921 HINSTANCE hInst = GetModuleHandleA(NULL);
12922 HWND hWnd1, hWnd2, hWnd3;
12923 HWND hOrigViewer;
12924 HWND hRet;
12925
12926 hWnd1 = CreateWindowExA(0, "TestWindowClass", "Clipboard viewer test wnd 1",
12927 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12928 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12929 GetDesktopWindow(), NULL, hInst, NULL);
12930 hWnd2 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 2",
12931 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12932 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12933 GetDesktopWindow(), NULL, hInst, NULL);
12934 hWnd3 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 3",
12935 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
12936 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
12937 GetDesktopWindow(), NULL, hInst, NULL);
12938 trace("clipbd viewers: hWnd1=%p, hWnd2=%p, hWnd3=%p\n", hWnd1, hWnd2, hWnd3);
12939 assert(hWnd1 && hWnd2 && hWnd3);
12940
12941 flush_sequence();
12942
12943 /* Test getting the clipboard viewer and setting the viewer to NULL. */
12944 hOrigViewer = GetClipboardViewer();
12945 hRet = SetClipboardViewer(NULL);
12946 ok_sequence(WmEmptySeq, "set viewer to NULL", FALSE);
12947 expect_HWND(hOrigViewer, hRet);
12948 expect_HWND(NULL, GetClipboardViewer());
12949
12950 /* Test registering hWnd1 as a viewer. */
12951 hRet = SetClipboardViewer(hWnd1);
12952 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12953 ok_sequence(wm_clipboard_changed, "set viewer NULL->1", FALSE);
12954 expect_HWND(NULL, hRet);
12955 expect_HWND(hWnd1, GetClipboardViewer());
12956
12957 /* Test that changing the clipboard actually refreshes the registered viewer. */
12958 clear_clipboard(hWnd1);
12959 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12960 ok_sequence(wm_clipboard_changed, "clear clipbd (viewer=owner=1)", FALSE);
12961
12962 /* Again, but with different owner. */
12963 clear_clipboard(hWnd2);
12964 wm_clipboard_changed_and_owned[1].wParam = (WPARAM) GetClipboardOwner();
12965 ok_sequence(wm_clipboard_changed_and_owned, "clear clipbd (viewer=1, owner=2)", FALSE);
12966
12967 /* Test re-registering same window. */
12968 hRet = SetClipboardViewer(hWnd1);
12969 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
12970 ok_sequence(wm_clipboard_changed, "set viewer 1->1", FALSE);
12971 expect_HWND(hWnd1, hRet);
12972 expect_HWND(hWnd1, GetClipboardViewer());
12973
12974 /* Test ChangeClipboardChain. */
12975 ChangeClipboardChain(hWnd2, hWnd3);
12976 wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
12977 wm_change_cb_chain[0].lParam = (LPARAM) hWnd3;
12978 ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=3)", FALSE);
12979 expect_HWND(hWnd1, GetClipboardViewer());
12980
12981 ChangeClipboardChain(hWnd2, NULL);
12982 wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
12983 wm_change_cb_chain[0].lParam = 0;
12984 ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=NULL)", FALSE);
12985 expect_HWND(hWnd1, GetClipboardViewer());
12986
12987 ChangeClipboardChain(NULL, hWnd2);
12988 ok_sequence(WmEmptySeq, "change chain (viewer=1, remove=NULL, next=2)", TRUE);
12989 expect_HWND(hWnd1, GetClipboardViewer());
12990
12991 /* Actually change clipboard viewer with ChangeClipboardChain. */
12992 ChangeClipboardChain(hWnd1, hWnd2);
12993 ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=2)", FALSE);
12994 expect_HWND(hWnd2, GetClipboardViewer());
12995
12996 /* Test that no refresh messages are sent when viewer has unregistered. */
12997 clear_clipboard(hWnd2);
12998 ok_sequence(WmEmptySeq, "clear clipd (viewer=2, owner=1)", FALSE);
12999
13000 /* Register hWnd1 again. */
13001 ChangeClipboardChain(hWnd2, hWnd1);
13002 ok_sequence(WmEmptySeq, "change chain (viewer=remove=2, next=1)", FALSE);
13003 expect_HWND(hWnd1, GetClipboardViewer());
13004
13005 /* Subclass hWnd1 so that when it receives a WM_DRAWCLIPBOARD message, it
13006 * changes the clipboard. When this happens, the system shouldn't send
13007 * another WM_DRAWCLIPBOARD (as this could cause an infinite loop).
13008 */
13009 pOldViewerProc = (WNDPROC) SetWindowLongPtrA(hWnd1, GWLP_WNDPROC, (LONG_PTR) recursive_viewer_proc);
13010 clear_clipboard(hWnd2);
13011 /* The clipboard owner is changed in recursive_viewer_proc: */
13012 wm_clipboard_changed[0].wParam = (WPARAM) hWnd2;
13013 ok_sequence(wm_clipboard_changed, "recursive clear clipbd (viewer=1, owner=2)", TRUE);
13014
13015 /* Test unregistering. */
13016 ChangeClipboardChain(hWnd1, NULL);
13017 ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=NULL)", FALSE);
13018 expect_HWND(NULL, GetClipboardViewer());
13019
13020 clear_clipboard(hWnd1);
13021 ok_sequence(wm_clipboard_destroyed, "clear clipbd (no viewer, owner=1)", FALSE);
13022
13023 DestroyWindow(hWnd1);
13024 DestroyWindow(hWnd2);
13025 DestroyWindow(hWnd3);
13026 SetClipboardViewer(hOrigViewer);
13027 }
13028
13029 static void test_PostMessage(void)
13030 {
13031 static const struct
13032 {
13033 HWND hwnd;
13034 BOOL ret;
13035 } data[] =
13036 {
13037 { HWND_TOP /* 0 */, TRUE },
13038 { HWND_BROADCAST, TRUE },
13039 { HWND_BOTTOM, TRUE },
13040 { HWND_TOPMOST, TRUE },
13041 { HWND_NOTOPMOST, FALSE },
13042 { HWND_MESSAGE, FALSE },
13043 { (HWND)0xdeadbeef, FALSE }
13044 };
13045 int i;
13046 HWND hwnd;
13047 BOOL ret;
13048 MSG msg;
13049 static const WCHAR staticW[] = {'s','t','a','t','i','c',0};
13050
13051 SetLastError(0xdeadbeef);
13052 hwnd = CreateWindowExW(0, staticW, NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
13053 if (!hwnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
13054 {
13055 win_skip("Skipping some PostMessage tests on Win9x/WinMe\n");
13056 return;
13057 }
13058 assert(hwnd);
13059
13060 flush_events();
13061
13062 PostMessageA(hwnd, WM_USER+1, 0x1234, 0x5678);
13063 PostMessageA(0, WM_USER+2, 0x5678, 0x1234);
13064
13065 for (i = 0; i < sizeof(data)/sizeof(data[0]); i++)
13066 {
13067 memset(&msg, 0xab, sizeof(msg));
13068 ret = PeekMessageA(&msg, data[i].hwnd, 0, 0, PM_NOREMOVE);
13069 ok(ret == data[i].ret, "%d: hwnd %p expected %d, got %d\n", i, data[i].hwnd, data[i].ret, ret);
13070 if (data[i].ret)
13071 {
13072 if (data[i].hwnd)
13073 ok(ret && msg.hwnd == 0 && msg.message == WM_USER+2 &&
13074 msg.wParam == 0x5678 && msg.lParam == 0x1234,
13075 "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/0/WM_USER+2/0x5678/0x1234\n",
13076 i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam);
13077 else
13078 ok(ret && msg.hwnd == hwnd && msg.message == WM_USER+1 &&
13079 msg.wParam == 0x1234 && msg.lParam == 0x5678,
13080 "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/%p/WM_USER+1/0x1234/0x5678\n",
13081 i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam, msg.hwnd);
13082 }
13083 }
13084
13085 DestroyWindow(hwnd);
13086 flush_events();
13087 }
13088
13089 static const struct
13090 {
13091 DWORD exp, broken;
13092 BOOL todo;
13093 } wait_idle_expect[] =
13094 {
13095 /* 0 */ { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
13096 { WAIT_TIMEOUT, 0, FALSE },
13097 { WAIT_TIMEOUT, 0, FALSE },
13098 { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
13099 { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
13100 /* 5 */ { WAIT_TIMEOUT, 0, FALSE },
13101 { WAIT_TIMEOUT, 0, FALSE },
13102 { WAIT_TIMEOUT, WAIT_TIMEOUT, FALSE },
13103 { 0, 0, FALSE },
13104 { 0, 0, FALSE },
13105 /* 10 */ { 0, 0, FALSE },
13106 { 0, 0, FALSE },
13107 { 0, WAIT_TIMEOUT, FALSE },
13108 { 0, 0, FALSE },
13109 { 0, 0, FALSE },
13110 /* 15 */ { 0, 0, FALSE },
13111 { WAIT_TIMEOUT, 0, FALSE },
13112 { WAIT_TIMEOUT, 0, FALSE },
13113 { WAIT_TIMEOUT, 0, FALSE },
13114 { WAIT_TIMEOUT, 0, FALSE },
13115 /* 20 */ { WAIT_TIMEOUT, 0, FALSE },
13116 };
13117
13118 static DWORD CALLBACK do_wait_idle_child_thread( void *arg )
13119 {
13120 MSG msg;
13121
13122 PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE );
13123 Sleep( 200 );
13124 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
13125 return 0;
13126 }
13127
13128 static void do_wait_idle_child( int arg )
13129 {
13130 WNDCLASSA cls;
13131 MSG msg;
13132 HWND hwnd = 0;
13133 HANDLE thread;
13134 DWORD id;
13135 HANDLE start_event = OpenEventA( EVENT_ALL_ACCESS, FALSE, "test_WaitForInputIdle_start" );
13136 HANDLE end_event = OpenEventA( EVENT_ALL_ACCESS, FALSE, "test_WaitForInputIdle_end" );
13137
13138 memset( &cls, 0, sizeof(cls) );
13139 cls.lpfnWndProc = DefWindowProcA;
13140 cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
13141 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
13142 cls.lpszClassName = "TestClass";
13143 RegisterClassA( &cls );
13144
13145 PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ); /* create the msg queue */
13146
13147 ok( start_event != 0, "failed to create start event, error %u\n", GetLastError() );
13148 ok( end_event != 0, "failed to create end event, error %u\n", GetLastError() );
13149
13150 switch (arg)
13151 {
13152 case 0:
13153 SetEvent( start_event );
13154 break;
13155 case 1:
13156 SetEvent( start_event );
13157 Sleep( 200 );
13158 PeekMessageA( &msg, 0, 0, 0, PM_REMOVE );
13159 break;
13160 case 2:
13161 SetEvent( start_event );
13162 Sleep( 200 );
13163 PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE );
13164 PostThreadMessageA( GetCurrentThreadId(), WM_COMMAND, 0x1234, 0xabcd );
13165 PeekMessageA( &msg, 0, 0, 0, PM_REMOVE );
13166 break;
13167 case 3:
13168 SetEvent( start_event );
13169 Sleep( 200 );
13170 SendMessageA( HWND_BROADCAST, WM_WININICHANGE, 0, 0 );
13171 break;
13172 case 4:
13173 SetEvent( start_event );
13174 Sleep( 200 );
13175 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
13176 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessageA( &msg );
13177 break;
13178 case 5:
13179 SetEvent( start_event );
13180 Sleep( 200 );
13181 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
13182 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
13183 break;
13184 case 6:
13185 SetEvent( start_event );
13186 Sleep( 200 );
13187 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
13188 while (PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ))
13189 {
13190 GetMessageA( &msg, 0, 0, 0 );
13191 DispatchMessageA( &msg );
13192 }
13193 break;
13194 case 7:
13195 SetEvent( start_event );
13196 Sleep( 200 );
13197 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
13198 SetTimer( hwnd, 3, 1, NULL );
13199 Sleep( 200 );
13200 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessageA( &msg );
13201 break;
13202 case 8:
13203 SetEvent( start_event );
13204 Sleep( 200 );
13205 PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE );
13206 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
13207 break;
13208 case 9:
13209 SetEvent( start_event );
13210 Sleep( 200 );
13211 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
13212 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
13213 for (;;) GetMessageA( &msg, 0, 0, 0 );
13214 break;
13215 case 10:
13216 SetEvent( start_event );
13217 Sleep( 200 );
13218 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
13219 SetTimer( hwnd, 3, 1, NULL );
13220 Sleep( 200 );
13221 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
13222 break;
13223 case 11:
13224 SetEvent( start_event );
13225 Sleep( 200 );
13226 return; /* exiting the process makes WaitForInputIdle return success too */
13227 case 12:
13228 PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE );
13229 Sleep( 200 );
13230 MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT );
13231 SetEvent( start_event );
13232 break;
13233 case 13:
13234 SetEvent( start_event );
13235 PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE );
13236 Sleep( 200 );
13237 thread = CreateThread( NULL, 0, do_wait_idle_child_thread, NULL, 0, &id );
13238 WaitForSingleObject( thread, 10000 );
13239 CloseHandle( thread );
13240 break;
13241 case 14:
13242 SetEvent( start_event );
13243 Sleep( 200 );
13244 PeekMessageA( &msg, HWND_TOPMOST, 0, 0, PM_NOREMOVE );
13245 break;
13246 case 15:
13247 SetEvent( start_event );
13248 Sleep( 200 );
13249 PeekMessageA( &msg, HWND_BROADCAST, 0, 0, PM_NOREMOVE );
13250 break;
13251 case 16:
13252 SetEvent( start_event );
13253 Sleep( 200 );
13254 PeekMessageA( &msg, HWND_BOTTOM, 0, 0, PM_NOREMOVE );
13255 break;
13256 case 17:
13257 SetEvent( start_event );
13258 Sleep( 200 );
13259 PeekMessageA( &msg, (HWND)0xdeadbeef, 0, 0, PM_NOREMOVE );
13260 break;
13261 case 18:
13262 SetEvent( start_event );
13263 Sleep( 200 );
13264 PeekMessageA( &msg, HWND_NOTOPMOST, 0, 0, PM_NOREMOVE );
13265 break;
13266 case 19:
13267 SetEvent( start_event );
13268 Sleep( 200 );
13269 PeekMessageA( &msg, HWND_MESSAGE, 0, 0, PM_NOREMOVE );
13270 break;
13271 case 20:
13272 SetEvent( start_event );
13273 Sleep( 200 );
13274 PeekMessageA( &msg, GetDesktopWindow(), 0, 0, PM_NOREMOVE );
13275 break;
13276 }
13277 WaitForSingleObject( end_event, 2000 );
13278 CloseHandle( start_event );
13279 CloseHandle( end_event );
13280 if (hwnd) DestroyWindow( hwnd );
13281 }
13282
13283 static LRESULT CALLBACK wait_idle_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
13284 {
13285 if (msg == WM_WININICHANGE) Sleep( 200 ); /* make sure the child waits */
13286 return DefWindowProcA( hwnd, msg, wp, lp );
13287 }
13288
13289 static DWORD CALLBACK wait_idle_thread( void *arg )
13290 {
13291 WNDCLASSA cls;
13292 MSG msg;
13293 HWND hwnd;
13294
13295 memset( &cls, 0, sizeof(cls) );
13296 cls.lpfnWndProc = wait_idle_proc;
13297 cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
13298 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
13299 cls.lpszClassName = "TestClass";
13300 RegisterClassA( &cls );
13301
13302 hwnd = CreateWindowExA(0, "TestClass", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
13303 while (GetMessageA( &msg, 0, 0, 0 )) DispatchMessageA( &msg );
13304 DestroyWindow(hwnd);
13305 return 0;
13306 }
13307
13308 static void test_WaitForInputIdle( char *argv0 )
13309 {
13310 char path[MAX_PATH];
13311 PROCESS_INFORMATION pi;
13312 STARTUPINFOA startup;
13313 BOOL ret;
13314 HANDLE start_event, end_event, thread;
13315 unsigned int i;
13316 DWORD id;
13317 const IMAGE_DOS_HEADER *dos = (const IMAGE_DOS_HEADER *)GetModuleHandleA(0);
13318 const IMAGE_NT_HEADERS *nt = (const IMAGE_NT_HEADERS *)((const char *)dos + dos->e_lfanew);
13319 BOOL console_app = (nt->OptionalHeader.Subsystem != IMAGE_SUBSYSTEM_WINDOWS_GUI);
13320
13321 if (console_app) /* build the test with -mwindows for better coverage */
13322 trace( "not built as a GUI app, WaitForInputIdle may not be fully tested\n" );
13323
13324 start_event = CreateEventA(NULL, 0, 0, "test_WaitForInputIdle_start");
13325 end_event = CreateEventA(NULL, 0, 0, "test_WaitForInputIdle_end");
13326 ok(start_event != 0, "failed to create start event, error %u\n", GetLastError());
13327 ok(end_event != 0, "failed to create end event, error %u\n", GetLastError());
13328
13329 memset( &startup, 0, sizeof(startup) );
13330 startup.cb = sizeof(startup);
13331 startup.dwFlags = STARTF_USESHOWWINDOW;
13332 startup.wShowWindow = SW_SHOWNORMAL;
13333
13334 thread = CreateThread( NULL, 0, wait_idle_thread, NULL, 0, &id );
13335
13336 for (i = 0; i < sizeof(wait_idle_expect)/sizeof(wait_idle_expect[0]); i++)
13337 {
13338 ResetEvent( start_event );
13339 ResetEvent( end_event );
13340 #ifndef __REACTOS__
13341 sprintf( path, "%s msg %u", argv0, i );
13342 #else
13343 sprintf( path, "%s msg_queue %u", argv0, i );
13344 #endif
13345 ret = CreateProcessA( NULL, path, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &pi );
13346 ok( ret, "CreateProcess '%s' failed err %u.\n", path, GetLastError() );
13347 if (ret)
13348 {
13349 ret = WaitForSingleObject( start_event, 5000 );
13350 ok( ret == WAIT_OBJECT_0, "%u: WaitForSingleObject failed\n", i );
13351 if (ret == WAIT_OBJECT_0)
13352 {
13353 ret = WaitForInputIdle( pi.hProcess, 1000 );
13354 if (ret == WAIT_FAILED)
13355 ok( console_app ||
13356 ret == wait_idle_expect[i].exp ||
13357 broken(ret == wait_idle_expect[i].broken),
13358 "%u: WaitForInputIdle error %08x expected %08x\n",
13359 i, ret, wait_idle_expect[i].exp );
13360 else if (wait_idle_expect[i].todo)
13361 todo_wine
13362 ok( ret == wait_idle_expect[i].exp || broken(ret == wait_idle_expect[i].broken),
13363 "%u: WaitForInputIdle error %08x expected %08x\n",
13364 i, ret, wait_idle_expect[i].exp );
13365 else
13366 ok( ret == wait_idle_expect[i].exp || broken(ret == wait_idle_expect[i].broken),
13367 "%u: WaitForInputIdle error %08x expected %08x\n",
13368 i, ret, wait_idle_expect[i].exp );
13369 SetEvent( end_event );
13370 WaitForSingleObject( pi.hProcess, 1000 ); /* give it a chance to exit on its own */
13371 }
13372 TerminateProcess( pi.hProcess, 0 ); /* just in case */
13373 winetest_wait_child_process( pi.hProcess );
13374 ret = WaitForInputIdle( pi.hProcess, 100 );
13375 ok( ret == WAIT_FAILED, "%u: WaitForInputIdle after exit error %08x\n", i, ret );
13376 CloseHandle( pi.hProcess );
13377 CloseHandle( pi.hThread );
13378 }
13379 }
13380 CloseHandle( start_event );
13381 PostThreadMessageA( id, WM_QUIT, 0, 0 );
13382 WaitForSingleObject( thread, 10000 );
13383 CloseHandle( thread );
13384 }
13385
13386 static const struct message WmSetParentSeq_1[] = {
13387 { WM_SHOWWINDOW, sent|wparam, 0 },
13388 { EVENT_OBJECT_PARENTCHANGE, winevent_hook|wparam|lparam, 0, 0 },
13389 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
13390 { WM_CHILDACTIVATE, sent },
13391 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW|SWP_NOCLIENTSIZE },
13392 { WM_MOVE, sent|defwinproc|wparam, 0 },
13393 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
13394 { WM_SHOWWINDOW, sent|wparam, 1 },
13395 { 0 }
13396 };
13397
13398 static const struct message WmSetParentSeq_2[] = {
13399 { WM_SHOWWINDOW, sent|wparam, 0 },
13400 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
13401 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
13402 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
13403 { HCBT_SETFOCUS, hook|optional },
13404 { WM_NCACTIVATE, sent|wparam|optional, 0 },
13405 { WM_ACTIVATE, sent|wparam|optional, 0 },
13406 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
13407 { WM_KILLFOCUS, sent|wparam, 0 },
13408 { EVENT_OBJECT_PARENTCHANGE, winevent_hook|wparam|lparam, 0, 0 },
13409 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
13410 { HCBT_ACTIVATE, hook|optional },
13411 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
13412 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
13413 { WM_NCACTIVATE, sent|wparam|optional, 1 },
13414 { WM_ACTIVATE, sent|wparam|optional, 1 },
13415 { HCBT_SETFOCUS, hook|optional },
13416 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
13417 { WM_SETFOCUS, sent|optional|defwinproc },
13418 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOREDRAW|SWP_NOSIZE|SWP_NOCLIENTSIZE },
13419 { WM_MOVE, sent|defwinproc|wparam, 0 },
13420 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
13421 { WM_SHOWWINDOW, sent|wparam, 1 },
13422 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
13423 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
13424 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
13425 { 0 }
13426 };
13427
13428
13429 static void test_SetParent(void)
13430 {
13431 HWND parent1, parent2, child, popup;
13432 RECT rc, rc_old;
13433
13434 parent1 = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW,
13435 100, 100, 200, 200, 0, 0, 0, NULL);
13436 ok(parent1 != 0, "Failed to create parent1 window\n");
13437
13438 parent2 = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW,
13439 400, 100, 200, 200, 0, 0, 0, NULL);
13440 ok(parent2 != 0, "Failed to create parent2 window\n");
13441
13442 /* WS_CHILD window */
13443 child = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD | WS_VISIBLE,
13444 10, 10, 150, 150, parent1, 0, 0, NULL);
13445 ok(child != 0, "Failed to create child window\n");
13446
13447 GetWindowRect(parent1, &rc);
13448 trace("parent1 (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
13449 GetWindowRect(child, &rc_old);
13450 MapWindowPoints(0, parent1, (POINT *)&rc_old, 2);
13451 trace("child (%d,%d)-(%d,%d)\n", rc_old.left, rc_old.top, rc_old.right, rc_old.bottom);
13452
13453 flush_sequence();
13454
13455 SetParent(child, parent2);
13456 flush_events();
13457 ok_sequence(WmSetParentSeq_1, "SetParent() visible WS_CHILD", TRUE);
13458
13459 ok(GetWindowLongA(child, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
13460 ok(!IsWindowVisible(child), "IsWindowVisible() should return FALSE\n");
13461
13462 GetWindowRect(parent2, &rc);
13463 trace("parent2 (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
13464 GetWindowRect(child, &rc);
13465 MapWindowPoints(0, parent2, (POINT *)&rc, 2);
13466 trace("child (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
13467
13468 ok(EqualRect(&rc_old, &rc), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
13469 rc_old.left, rc_old.top, rc_old.right, rc_old.bottom,
13470 rc.left, rc.top, rc.right, rc.bottom );
13471
13472 /* WS_POPUP window */
13473 popup = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP | WS_VISIBLE,
13474 20, 20, 100, 100, 0, 0, 0, NULL);
13475 ok(popup != 0, "Failed to create popup window\n");
13476
13477 GetWindowRect(popup, &rc_old);
13478 trace("popup (%d,%d)-(%d,%d)\n", rc_old.left, rc_old.top, rc_old.right, rc_old.bottom);
13479
13480 flush_sequence();
13481
13482 SetParent(popup, child);
13483 flush_events();
13484 ok_sequence(WmSetParentSeq_2, "SetParent() visible WS_POPUP", TRUE);
13485
13486 ok(GetWindowLongA(popup, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
13487 ok(!IsWindowVisible(popup), "IsWindowVisible() should return FALSE\n");
13488
13489 GetWindowRect(child, &rc);
13490 trace("parent2 (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
13491 GetWindowRect(popup, &rc);
13492 MapWindowPoints(0, child, (POINT *)&rc, 2);
13493 trace("popup (%d,%d)-(%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
13494
13495 ok(EqualRect(&rc_old, &rc), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
13496 rc_old.left, rc_old.top, rc_old.right, rc_old.bottom,
13497 rc.left, rc.top, rc.right, rc.bottom );
13498
13499 DestroyWindow(popup);
13500 DestroyWindow(child);
13501 DestroyWindow(parent1);
13502 DestroyWindow(parent2);
13503
13504 flush_sequence();
13505 }
13506
13507 static const struct message WmKeyReleaseOnly[] = {
13508 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 0x41, 0x80000001 },
13509 { WM_KEYUP, sent|wparam|lparam, 0x41, 0x80000001 },
13510 { 0 }
13511 };
13512 static const struct message WmKeyPressNormal[] = {
13513 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 0x41, 0x1 },
13514 { WM_KEYDOWN, sent|wparam|lparam, 0x41, 0x1 },
13515 { 0 }
13516 };
13517 static const struct message WmKeyPressRepeat[] = {
13518 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 0x41, 0x40000001 },
13519 { WM_KEYDOWN, sent|wparam|lparam, 0x41, 0x40000001 },
13520 { 0 }
13521 };
13522 static const struct message WmKeyReleaseNormal[] = {
13523 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 0x41, 0xc0000001 },
13524 { WM_KEYUP, sent|wparam|lparam, 0x41, 0xc0000001 },
13525 { 0 }
13526 };
13527
13528 static void test_keyflags(void)
13529 {
13530 HWND test_window;
13531 SHORT key_state;
13532 BYTE keyboard_state[256];
13533 MSG msg;
13534
13535 test_window = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
13536 100, 100, 200, 200, 0, 0, 0, NULL);
13537
13538 flush_events();
13539 flush_sequence();
13540
13541 /* keyup without a keydown */
13542 keybd_event(0x41, 0, KEYEVENTF_KEYUP, 0);
13543 while (PeekMessageA(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13544 DispatchMessageA(&msg);
13545 ok_sequence(WmKeyReleaseOnly, "key release only", TRUE);
13546
13547 key_state = GetAsyncKeyState(0x41);
13548 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13549
13550 key_state = GetKeyState(0x41);
13551 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13552
13553 /* keydown */
13554 keybd_event(0x41, 0, 0, 0);
13555 while (PeekMessageA(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13556 DispatchMessageA(&msg);
13557 ok_sequence(WmKeyPressNormal, "key press only", FALSE);
13558
13559 key_state = GetAsyncKeyState(0x41);
13560 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13561
13562 key_state = GetKeyState(0x41);
13563 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13564
13565 /* keydown repeat */
13566 keybd_event(0x41, 0, 0, 0);
13567 while (PeekMessageA(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13568 DispatchMessageA(&msg);
13569 ok_sequence(WmKeyPressRepeat, "key press repeat", FALSE);
13570
13571 key_state = GetAsyncKeyState(0x41);
13572 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13573
13574 key_state = GetKeyState(0x41);
13575 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13576
13577 /* keyup */
13578 keybd_event(0x41, 0, KEYEVENTF_KEYUP, 0);
13579 while (PeekMessageA(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13580 DispatchMessageA(&msg);
13581 ok_sequence(WmKeyReleaseNormal, "key release repeat", FALSE);
13582
13583 key_state = GetAsyncKeyState(0x41);
13584 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13585
13586 key_state = GetKeyState(0x41);
13587 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13588
13589 /* set the key state in this thread */
13590 GetKeyboardState(keyboard_state);
13591 keyboard_state[0x41] = 0x80;
13592 SetKeyboardState(keyboard_state);
13593
13594 key_state = GetAsyncKeyState(0x41);
13595 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13596
13597 /* keydown */
13598 keybd_event(0x41, 0, 0, 0);
13599 while (PeekMessageA(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13600 DispatchMessageA(&msg);
13601 ok_sequence(WmKeyPressRepeat, "key press after setkeyboardstate", TRUE);
13602
13603 key_state = GetAsyncKeyState(0x41);
13604 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13605
13606 key_state = GetKeyState(0x41);
13607 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13608
13609 /* clear the key state in this thread */
13610 GetKeyboardState(keyboard_state);
13611 keyboard_state[0x41] = 0;
13612 SetKeyboardState(keyboard_state);
13613
13614 key_state = GetAsyncKeyState(0x41);
13615 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13616
13617 /* keyup */
13618 keybd_event(0x41, 0, KEYEVENTF_KEYUP, 0);
13619 while (PeekMessageA(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
13620 DispatchMessageA(&msg);
13621 ok_sequence(WmKeyReleaseOnly, "key release after setkeyboardstate", TRUE);
13622
13623 key_state = GetAsyncKeyState(0x41);
13624 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13625
13626 key_state = GetKeyState(0x41);
13627 ok((key_state & 0x8000) == 0, "unexpected key state %x\n", key_state);
13628
13629 DestroyWindow(test_window);
13630 flush_sequence();
13631 }
13632
13633 static const struct message WmHotkeyPressLWIN[] = {
13634 { WM_KEYDOWN, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED },
13635 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 1 },
13636 { WM_KEYDOWN, sent|wparam|lparam, VK_LWIN, 1 },
13637 { 0 }
13638 };
13639 static const struct message WmHotkeyPress[] = {
13640 { WM_KEYDOWN, kbd_hook|lparam, 0, LLKHF_INJECTED },
13641 { WM_HOTKEY, sent|wparam, 5 },
13642 { 0 }
13643 };
13644 static const struct message WmHotkeyRelease[] = {
13645 { WM_KEYUP, kbd_hook|lparam, 0, LLKHF_INJECTED|LLKHF_UP },
13646 { HCBT_KEYSKIPPED, hook|lparam|optional, 0, 0x80000001 },
13647 { WM_KEYUP, sent|lparam, 0, 0x80000001 },
13648 { 0 }
13649 };
13650 static const struct message WmHotkeyReleaseLWIN[] = {
13651 { WM_KEYUP, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED|LLKHF_UP },
13652 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 0xc0000001 },
13653 { WM_KEYUP, sent|wparam|lparam, VK_LWIN, 0xc0000001 },
13654 { 0 }
13655 };
13656 static const struct message WmHotkeyCombined[] = {
13657 { WM_KEYDOWN, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED },
13658 { WM_KEYDOWN, kbd_hook|lparam, 0, LLKHF_INJECTED },
13659 { WM_KEYUP, kbd_hook|lparam, 0, LLKHF_INJECTED|LLKHF_UP },
13660 { WM_KEYUP, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED|LLKHF_UP },
13661 { WM_APP, sent, 0, 0 },
13662 { WM_HOTKEY, sent|wparam, 5 },
13663 { WM_APP+1, sent, 0, 0 },
13664 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 1 },
13665 { WM_KEYDOWN, sent|wparam|lparam, VK_LWIN, 1 },
13666 { HCBT_KEYSKIPPED, hook|optional, 0, 0x80000001 },
13667 { WM_KEYUP, sent, 0, 0x80000001 }, /* lparam not checked so the sequence isn't a todo */
13668 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 0xc0000001 },
13669 { WM_KEYUP, sent|wparam|lparam, VK_LWIN, 0xc0000001 },
13670 { 0 }
13671 };
13672 static const struct message WmHotkeyPrevious[] = {
13673 { WM_KEYDOWN, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED },
13674 { WM_KEYDOWN, kbd_hook|lparam, 0, LLKHF_INJECTED },
13675 { WM_KEYUP, kbd_hook|lparam, 0, LLKHF_INJECTED|LLKHF_UP },
13676 { WM_KEYUP, kbd_hook|wparam|lparam, VK_LWIN, LLKHF_INJECTED|LLKHF_UP },
13677 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 1 },
13678 { WM_KEYDOWN, sent|wparam|lparam, VK_LWIN, 1 },
13679 { HCBT_KEYSKIPPED, hook|lparam|optional, 0, 1 },
13680 { WM_KEYDOWN, sent|lparam, 0, 1 },
13681 { HCBT_KEYSKIPPED, hook|optional|lparam, 0, 0xc0000001 },
13682 { WM_KEYUP, sent|lparam, 0, 0xc0000001 },
13683 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_LWIN, 0xc0000001 },
13684 { WM_KEYUP, sent|wparam|lparam, VK_LWIN, 0xc0000001 },
13685 { 0 }
13686 };
13687 static const struct message WmHotkeyNew[] = {
13688 { WM_KEYDOWN, kbd_hook|lparam, 0, LLKHF_INJECTED },
13689 { WM_KEYUP, kbd_hook|lparam, 0, LLKHF_INJECTED|LLKHF_UP },
13690 { WM_HOTKEY, sent|wparam, 5 },
13691 { HCBT_KEYSKIPPED, hook|optional, 0, 0x80000001 },
13692 { WM_KEYUP, sent, 0, 0x80000001 }, /* lparam not checked so the sequence isn't a todo */
13693 { 0 }
13694 };
13695
13696 static int hotkey_letter;
13697
13698 static LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
13699 {
13700 struct recvd_message msg;
13701
13702 if (nCode == HC_ACTION)
13703 {
13704 KBDLLHOOKSTRUCT *kdbhookstruct = (KBDLLHOOKSTRUCT*)lParam;
13705
13706 msg.hwnd = 0;
13707 msg.message = wParam;
13708 msg.flags = kbd_hook|wparam|lparam;
13709 msg.wParam = kdbhookstruct->vkCode;
13710 msg.lParam = kdbhookstruct->flags;
13711 msg.descr = "KeyboardHookProc";
13712 add_message(&msg);
13713
13714 if (wParam == WM_KEYUP || wParam == WM_KEYDOWN)
13715 {
13716 ok(kdbhookstruct->vkCode == VK_LWIN || kdbhookstruct->vkCode == hotkey_letter,
13717 "unexpected keycode %x\n", kdbhookstruct->vkCode);
13718 }
13719 }
13720
13721 return CallNextHookEx(hKBD_hook, nCode, wParam, lParam);
13722 }
13723
13724 static void test_hotkey(void)
13725 {
13726 HWND test_window, taskbar_window;
13727 BOOL ret;
13728 MSG msg;
13729 DWORD queue_status;
13730 SHORT key_state;
13731
13732 SetLastError(0xdeadbeef);
13733 ret = UnregisterHotKey(NULL, 0);
13734 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13735 ok(GetLastError() == ERROR_HOTKEY_NOT_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13736 "unexpected error %d\n", GetLastError());
13737
13738 if (ret == TRUE)
13739 {
13740 skip("hotkeys not supported\n");
13741 return;
13742 }
13743
13744 test_window = CreateWindowExA(0, "HotkeyWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
13745 100, 100, 200, 200, 0, 0, 0, NULL);
13746
13747 flush_sequence();
13748
13749 SetLastError(0xdeadbeef);
13750 ret = UnregisterHotKey(test_window, 0);
13751 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13752 ok(GetLastError() == ERROR_HOTKEY_NOT_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13753 "unexpected error %d\n", GetLastError());
13754
13755 /* Search for a Windows Key + letter combination that hasn't been registered */
13756 for (hotkey_letter = 0x41; hotkey_letter <= 0x51; hotkey_letter ++)
13757 {
13758 SetLastError(0xdeadbeef);
13759 ret = RegisterHotKey(test_window, 5, MOD_WIN, hotkey_letter);
13760
13761 if (ret == TRUE)
13762 {
13763 break;
13764 }
13765 else
13766 {
13767 ok(GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13768 "unexpected error %d\n", GetLastError());
13769 }
13770 }
13771
13772 if (hotkey_letter == 0x52)
13773 {
13774 ok(0, "Couldn't find any free Windows Key + letter combination\n");
13775 goto end;
13776 }
13777
13778 hKBD_hook = SetWindowsHookExA(WH_KEYBOARD_LL, KeyboardHookProc, GetModuleHandleA(NULL), 0);
13779 if (!hKBD_hook) win_skip("WH_KEYBOARD_LL is not supported\n");
13780
13781 /* Same key combination, different id */
13782 SetLastError(0xdeadbeef);
13783 ret = RegisterHotKey(test_window, 4, MOD_WIN, hotkey_letter);
13784 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13785 ok(GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13786 "unexpected error %d\n", GetLastError());
13787
13788 /* Same key combination, different window */
13789 SetLastError(0xdeadbeef);
13790 ret = RegisterHotKey(NULL, 5, MOD_WIN, hotkey_letter);
13791 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13792 ok(GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13793 "unexpected error %d\n", GetLastError());
13794
13795 /* Register the same hotkey twice */
13796 SetLastError(0xdeadbeef);
13797 ret = RegisterHotKey(test_window, 5, MOD_WIN, hotkey_letter);
13798 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13799 ok(GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13800 "unexpected error %d\n", GetLastError());
13801
13802 /* Window on another thread */
13803 taskbar_window = FindWindowA("Shell_TrayWnd", NULL);
13804 if (!taskbar_window)
13805 {
13806 skip("no taskbar?\n");
13807 }
13808 else
13809 {
13810 SetLastError(0xdeadbeef);
13811 ret = RegisterHotKey(taskbar_window, 5, 0, hotkey_letter);
13812 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13813 ok(GetLastError() == ERROR_WINDOW_OF_OTHER_THREAD || broken(GetLastError() == 0xdeadbeef),
13814 "unexpected error %d\n", GetLastError());
13815 }
13816
13817 /* Inject the appropriate key sequence */
13818 keybd_event(VK_LWIN, 0, 0, 0);
13819 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
13820 DispatchMessageA(&msg);
13821 ok_sequence(WmHotkeyPressLWIN, "window hotkey press LWIN", FALSE);
13822
13823 keybd_event(hotkey_letter, 0, 0, 0);
13824 queue_status = GetQueueStatus(QS_HOTKEY);
13825 ok((queue_status & (QS_HOTKEY << 16)) == QS_HOTKEY << 16, "expected QS_HOTKEY << 16 set, got %x\n", queue_status);
13826 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
13827 {
13828 if (msg.message == WM_HOTKEY)
13829 {
13830 ok(msg.hwnd == test_window, "unexpected hwnd %p\n", msg.hwnd);
13831 ok(msg.lParam == MAKELPARAM(MOD_WIN, hotkey_letter), "unexpected WM_HOTKEY lparam %lx\n", msg.lParam);
13832 }
13833 DispatchMessageA(&msg);
13834 }
13835 ok_sequence(WmHotkeyPress, "window hotkey press", FALSE);
13836
13837 queue_status = GetQueueStatus(QS_HOTKEY);
13838 ok((queue_status & (QS_HOTKEY << 16)) == 0, "expected QS_HOTKEY << 16 cleared, got %x\n", queue_status);
13839
13840 key_state = GetAsyncKeyState(hotkey_letter);
13841 ok((key_state & 0x8000) == 0x8000, "unexpected key state %x\n", key_state);
13842
13843 keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13844 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
13845 DispatchMessageA(&msg);
13846 ok_sequence(WmHotkeyRelease, "window hotkey release", TRUE);
13847
13848 keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
13849 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
13850 DispatchMessageA(&msg);
13851 ok_sequence(WmHotkeyReleaseLWIN, "window hotkey release LWIN", FALSE);
13852
13853 /* normal posted WM_HOTKEY messages set QS_HOTKEY */
13854 PostMessageA(test_window, WM_HOTKEY, 0, 0);
13855 queue_status = GetQueueStatus(QS_HOTKEY);
13856 ok((queue_status & (QS_HOTKEY << 16)) == QS_HOTKEY << 16, "expected QS_HOTKEY << 16 set, got %x\n", queue_status);
13857 queue_status = GetQueueStatus(QS_POSTMESSAGE);
13858 ok((queue_status & (QS_POSTMESSAGE << 16)) == QS_POSTMESSAGE << 16, "expected QS_POSTMESSAGE << 16 set, got %x\n", queue_status);
13859 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
13860 DispatchMessageA(&msg);
13861 flush_sequence();
13862
13863 /* Send and process all messages at once */
13864 PostMessageA(test_window, WM_APP, 0, 0);
13865 keybd_event(VK_LWIN, 0, 0, 0);
13866 keybd_event(hotkey_letter, 0, 0, 0);
13867 keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13868 keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
13869
13870 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
13871 {
13872 if (msg.message == WM_HOTKEY)
13873 {
13874 ok(msg.hwnd == test_window, "unexpected hwnd %p\n", msg.hwnd);
13875 ok(msg.lParam == MAKELPARAM(MOD_WIN, hotkey_letter), "unexpected WM_HOTKEY lparam %lx\n", msg.lParam);
13876 }
13877 DispatchMessageA(&msg);
13878 }
13879 ok_sequence(WmHotkeyCombined, "window hotkey combined", FALSE);
13880
13881 /* Register same hwnd/id with different key combination */
13882 ret = RegisterHotKey(test_window, 5, 0, hotkey_letter);
13883 ok(ret == TRUE, "expected TRUE, got %i, err=%d\n", ret, GetLastError());
13884
13885 /* Previous key combination does not work */
13886 keybd_event(VK_LWIN, 0, 0, 0);
13887 keybd_event(hotkey_letter, 0, 0, 0);
13888 keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13889 keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
13890
13891 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
13892 DispatchMessageA(&msg);
13893 ok_sequence(WmHotkeyPrevious, "window hotkey previous", FALSE);
13894
13895 /* New key combination works */
13896 keybd_event(hotkey_letter, 0, 0, 0);
13897 keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13898
13899 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
13900 {
13901 if (msg.message == WM_HOTKEY)
13902 {
13903 ok(msg.hwnd == test_window, "unexpected hwnd %p\n", msg.hwnd);
13904 ok(msg.lParam == MAKELPARAM(0, hotkey_letter), "unexpected WM_HOTKEY lparam %lx\n", msg.lParam);
13905 }
13906 DispatchMessageA(&msg);
13907 }
13908 ok_sequence(WmHotkeyNew, "window hotkey new", FALSE);
13909
13910 /* Unregister hotkey properly */
13911 ret = UnregisterHotKey(test_window, 5);
13912 ok(ret == TRUE, "expected TRUE, got %i, err=%d\n", ret, GetLastError());
13913
13914 /* Unregister hotkey again */
13915 SetLastError(0xdeadbeef);
13916 ret = UnregisterHotKey(test_window, 5);
13917 ok(ret == FALSE, "expected FALSE, got %i\n", ret);
13918 ok(GetLastError() == ERROR_HOTKEY_NOT_REGISTERED || broken(GetLastError() == 0xdeadbeef),
13919 "unexpected error %d\n", GetLastError());
13920
13921 /* Register thread hotkey */
13922 ret = RegisterHotKey(NULL, 5, MOD_WIN, hotkey_letter);
13923 ok(ret == TRUE, "expected TRUE, got %i, err=%d\n", ret, GetLastError());
13924
13925 /* Inject the appropriate key sequence */
13926 keybd_event(VK_LWIN, 0, 0, 0);
13927 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
13928 {
13929 ok(msg.hwnd != NULL, "unexpected thread message %x\n", msg.message);
13930 DispatchMessageA(&msg);
13931 }
13932 ok_sequence(WmHotkeyPressLWIN, "thread hotkey press LWIN", FALSE);
13933
13934 keybd_event(hotkey_letter, 0, 0, 0);
13935 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
13936 {
13937 if (msg.message == WM_HOTKEY)
13938 {
13939 struct recvd_message message;
13940 ok(msg.hwnd == NULL, "unexpected hwnd %p\n", msg.hwnd);
13941 ok(msg.lParam == MAKELPARAM(MOD_WIN, hotkey_letter), "unexpected WM_HOTKEY lparam %lx\n", msg.lParam);
13942 message.message = msg.message;
13943 message.flags = sent|wparam|lparam;
13944 message.wParam = msg.wParam;
13945 message.lParam = msg.lParam;
13946 message.descr = "test_hotkey thread message";
13947 add_message(&message);
13948 }
13949 else
13950 ok(msg.hwnd != NULL, "unexpected thread message %x\n", msg.message);
13951 DispatchMessageA(&msg);
13952 }
13953 ok_sequence(WmHotkeyPress, "thread hotkey press", FALSE);
13954
13955 keybd_event(hotkey_letter, 0, KEYEVENTF_KEYUP, 0);
13956 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
13957 {
13958 ok(msg.hwnd != NULL, "unexpected thread message %x\n", msg.message);
13959 DispatchMessageA(&msg);
13960 }
13961 ok_sequence(WmHotkeyRelease, "thread hotkey release", TRUE);
13962
13963 keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
13964 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
13965 {
13966 ok(msg.hwnd != NULL, "unexpected thread message %x\n", msg.message);
13967 DispatchMessageA(&msg);
13968 }
13969 ok_sequence(WmHotkeyReleaseLWIN, "thread hotkey release LWIN", FALSE);
13970
13971 /* Unregister thread hotkey */
13972 ret = UnregisterHotKey(NULL, 5);
13973 ok(ret == TRUE, "expected TRUE, got %i, err=%d\n", ret, GetLastError());
13974
13975 if (hKBD_hook) UnhookWindowsHookEx(hKBD_hook);
13976 hKBD_hook = NULL;
13977
13978 end:
13979 UnregisterHotKey(NULL, 5);
13980 UnregisterHotKey(test_window, 5);
13981 DestroyWindow(test_window);
13982 flush_sequence();
13983 }
13984
13985
13986 static const struct message WmSetFocus_1[] = {
13987 { HCBT_SETFOCUS, hook }, /* child */
13988 { HCBT_ACTIVATE, hook }, /* parent */
13989 { WM_QUERYNEWPALETTE, sent|wparam|lparam|parent|optional, 0, 0 },
13990 { WM_WINDOWPOSCHANGING, sent|parent, 0, SWP_NOSIZE|SWP_NOMOVE },
13991 { WM_ACTIVATEAPP, sent|wparam|parent, 1 },
13992 { WM_NCACTIVATE, sent|parent },
13993 { WM_GETTEXT, sent|defwinproc|parent|optional },
13994 { WM_GETTEXT, sent|defwinproc|parent|optional },
13995 { WM_ACTIVATE, sent|wparam|parent, 1 },
13996 { HCBT_SETFOCUS, hook }, /* parent */
13997 { WM_SETFOCUS, sent|defwinproc|parent },
13998 { WM_KILLFOCUS, sent|parent },
13999 { WM_SETFOCUS, sent },
14000 { 0 }
14001 };
14002 static const struct message WmSetFocus_2[] = {
14003 { HCBT_SETFOCUS, hook }, /* parent */
14004 { WM_KILLFOCUS, sent },
14005 { WM_SETFOCUS, sent|parent },
14006 { 0 }
14007 };
14008 static const struct message WmSetFocus_3[] = {
14009 { HCBT_SETFOCUS, hook }, /* child */
14010 { 0 }
14011 };
14012
14013 static void test_SetFocus(void)
14014 {
14015 HWND parent, old_parent, child, old_focus, old_active;
14016 MSG msg;
14017 struct wnd_event wnd_event;
14018 HANDLE hthread;
14019 DWORD ret, tid;
14020
14021 wnd_event.start_event = CreateEventW(NULL, 0, 0, NULL);
14022 ok(wnd_event.start_event != 0, "CreateEvent error %d\n", GetLastError());
14023 hthread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
14024 ok(hthread != 0, "CreateThread error %d\n", GetLastError());
14025 ret = WaitForSingleObject(wnd_event.start_event, INFINITE);
14026 ok(ret == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
14027 CloseHandle(wnd_event.start_event);
14028
14029 parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW,
14030 0, 0, 0, 0, 0, 0, 0, NULL);
14031 ok(parent != 0, "failed to create parent window\n");
14032 child = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
14033 0, 0, 0, 0, parent, 0, 0, NULL);
14034 ok(child != 0, "failed to create child window\n");
14035
14036 trace("parent %p, child %p, thread window %p\n", parent, child, wnd_event.hwnd);
14037
14038 SetFocus(0);
14039 SetActiveWindow(0);
14040
14041 flush_events();
14042 flush_sequence();
14043
14044 ok(GetActiveWindow() == 0, "expected active 0, got %p\n", GetActiveWindow());
14045 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
14046
14047 log_all_parent_messages++;
14048
14049 old_focus = SetFocus(child);
14050 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
14051 ok_sequence(WmSetFocus_1, "SetFocus on a child window", TRUE);
14052 ok(old_focus == parent, "expected old focus %p, got %p\n", parent, old_focus);
14053 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
14054 ok(GetFocus() == child, "expected focus %p, got %p\n", child, GetFocus());
14055
14056 old_focus = SetFocus(parent);
14057 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
14058 ok_sequence(WmSetFocus_2, "SetFocus on a parent window", FALSE);
14059 ok(old_focus == child, "expected old focus %p, got %p\n", child, old_focus);
14060 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
14061 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
14062
14063 SetLastError(0xdeadbeef);
14064 old_focus = SetFocus((HWND)0xdeadbeef);
14065 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
14066 "expected ERROR_INVALID_WINDOW_HANDLE, got %d\n", GetLastError());
14067 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
14068 ok_sequence(WmEmptySeq, "SetFocus on an invalid window", FALSE);
14069 ok(old_focus == 0, "expected old focus 0, got %p\n", old_focus);
14070 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
14071 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
14072
14073 SetLastError(0xdeadbeef);
14074 old_focus = SetFocus(GetDesktopWindow());
14075 ok(GetLastError() == ERROR_ACCESS_DENIED /* Vista+ */ ||
14076 broken(GetLastError() == 0xdeadbeef), "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
14077 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
14078 ok_sequence(WmEmptySeq, "SetFocus on a desktop window", TRUE);
14079 ok(old_focus == 0, "expected old focus 0, got %p\n", old_focus);
14080 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
14081 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
14082
14083 SetLastError(0xdeadbeef);
14084 old_focus = SetFocus(wnd_event.hwnd);
14085 ok(GetLastError() == ERROR_ACCESS_DENIED /* Vista+ */ ||
14086 broken(GetLastError() == 0xdeadbeef), "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
14087 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
14088 ok_sequence(WmEmptySeq, "SetFocus on another thread window", TRUE);
14089 ok(old_focus == 0, "expected old focus 0, got %p\n", old_focus);
14090 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
14091 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
14092
14093 SetLastError(0xdeadbeef);
14094 old_active = SetActiveWindow((HWND)0xdeadbeef);
14095 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
14096 "expected ERROR_INVALID_WINDOW_HANDLE, got %d\n", GetLastError());
14097 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
14098 ok_sequence(WmEmptySeq, "SetActiveWindow on an invalid window", FALSE);
14099 ok(old_active == 0, "expected old focus 0, got %p\n", old_active);
14100 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
14101 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
14102
14103 SetLastError(0xdeadbeef);
14104 old_active = SetActiveWindow(GetDesktopWindow());
14105 todo_wine
14106 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
14107 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
14108 ok_sequence(WmEmptySeq, "SetActiveWindow on a desktop window", TRUE);
14109 ok(old_active == 0, "expected old focus 0, got %p\n", old_focus);
14110 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
14111 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
14112
14113 SetLastError(0xdeadbeef);
14114 old_active = SetActiveWindow(wnd_event.hwnd);
14115 todo_wine
14116 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
14117 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
14118 ok_sequence(WmEmptySeq, "SetActiveWindow on another thread window", TRUE);
14119 ok(old_active == 0, "expected old focus 0, got %p\n", old_active);
14120 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
14121 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
14122
14123 SetLastError(0xdeadbeef);
14124 ret = AttachThreadInput(GetCurrentThreadId(), tid, TRUE);
14125 ok(ret, "AttachThreadInput error %d\n", GetLastError());
14126
14127 todo_wine {
14128 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
14129 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
14130 }
14131 flush_events();
14132 flush_sequence();
14133
14134 old_focus = SetFocus(wnd_event.hwnd);
14135 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
14136 ok(old_focus == wnd_event.hwnd, "expected old focus %p, got %p\n", wnd_event.hwnd, old_focus);
14137 ok(GetActiveWindow() == wnd_event.hwnd, "expected active %p, got %p\n", wnd_event.hwnd, GetActiveWindow());
14138 ok(GetFocus() == wnd_event.hwnd, "expected focus %p, got %p\n", wnd_event.hwnd, GetFocus());
14139
14140 old_focus = SetFocus(parent);
14141 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
14142 ok(old_focus == parent, "expected old focus %p, got %p\n", parent, old_focus);
14143 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
14144 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
14145
14146 flush_events();
14147 flush_sequence();
14148
14149 old_active = SetActiveWindow(wnd_event.hwnd);
14150 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
14151 ok(old_active == parent, "expected old focus %p, got %p\n", parent, old_active);
14152 ok(GetActiveWindow() == wnd_event.hwnd, "expected active %p, got %p\n", wnd_event.hwnd, GetActiveWindow());
14153 ok(GetFocus() == wnd_event.hwnd, "expected focus %p, got %p\n", wnd_event.hwnd, GetFocus());
14154
14155 SetLastError(0xdeadbeef);
14156 ret = AttachThreadInput(GetCurrentThreadId(), tid, FALSE);
14157 ok(ret, "AttachThreadInput error %d\n", GetLastError());
14158
14159 ok(GetActiveWindow() == 0, "expected active 0, got %p\n", GetActiveWindow());
14160 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
14161
14162 old_parent = SetParent(child, GetDesktopWindow());
14163 ok(old_parent == parent, "expected old parent %p, got %p\n", parent, old_parent);
14164
14165 ok(GetActiveWindow() == 0, "expected active 0, got %p\n", GetActiveWindow());
14166 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
14167
14168 old_focus = SetFocus(parent);
14169 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
14170 ok(old_focus == parent, "expected old focus %p, got %p\n", parent, old_focus);
14171 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
14172 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
14173
14174 flush_events();
14175 flush_sequence();
14176
14177 SetLastError(0xdeadbeef);
14178 old_focus = SetFocus(child);
14179 todo_wine
14180 ok(GetLastError() == ERROR_INVALID_PARAMETER /* Vista+ */ ||
14181 broken(GetLastError() == 0) /* XP */ ||
14182 broken(GetLastError() == 0xdeadbeef), "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
14183 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
14184 ok_sequence(WmSetFocus_3, "SetFocus on a child window", TRUE);
14185 ok(old_focus == 0, "expected old focus 0, got %p\n", old_focus);
14186 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
14187 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
14188
14189 SetLastError(0xdeadbeef);
14190 old_active = SetActiveWindow(child);
14191 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
14192 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
14193 ok_sequence(WmEmptySeq, "SetActiveWindow on a child window", FALSE);
14194 ok(old_active == parent, "expected old active %p, got %p\n", parent, old_active);
14195 ok(GetActiveWindow() == parent, "expected active %p, got %p\n", parent, GetActiveWindow());
14196 ok(GetFocus() == parent, "expected focus %p, got %p\n", parent, GetFocus());
14197
14198 log_all_parent_messages--;
14199
14200 DestroyWindow(child);
14201 DestroyWindow(parent);
14202
14203 ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
14204 ok(ret, "PostMessage(WM_QUIT) error %d\n", GetLastError());
14205 ret = WaitForSingleObject(hthread, INFINITE);
14206 ok(ret == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
14207 CloseHandle(hthread);
14208 }
14209
14210 static const struct message WmSetLayeredStyle[] = {
14211 { WM_STYLECHANGING, sent },
14212 { WM_STYLECHANGED, sent },
14213 { WM_GETTEXT, sent|defwinproc|optional },
14214 { 0 }
14215 };
14216
14217 static const struct message WmSetLayeredStyle2[] = {
14218 { WM_STYLECHANGING, sent },
14219 { WM_STYLECHANGED, sent },
14220 { WM_WINDOWPOSCHANGING, sent|optional|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
14221 { WM_NCCALCSIZE, sent|optional|wparam|defwinproc, 1 },
14222 { WM_WINDOWPOSCHANGED, sent|optional|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
14223 { WM_MOVE, sent|optional|defwinproc|wparam, 0 },
14224 { WM_SIZE, sent|optional|defwinproc|wparam, SIZE_RESTORED },
14225 { 0 }
14226 };
14227
14228 struct layered_window_info
14229 {
14230 HWND hwnd;
14231 HDC hdc;
14232 SIZE size;
14233 HANDLE event;
14234 BOOL ret;
14235 };
14236
14237 static DWORD CALLBACK update_layered_proc( void *param )
14238 {
14239 struct layered_window_info *info = param;
14240 POINT src = { 0, 0 };
14241
14242 info->ret = pUpdateLayeredWindow( info->hwnd, 0, NULL, &info->size,
14243 info->hdc, &src, 0, NULL, ULW_OPAQUE );
14244 ok( info->ret, "failed\n");
14245 SetEvent( info->event );
14246 return 0;
14247 }
14248
14249 static void test_layered_window(void)
14250 {
14251 HWND hwnd;
14252 HDC hdc;
14253 HBITMAP bmp;
14254 BOOL ret;
14255 SIZE size;
14256 POINT pos, src;
14257 RECT rect, client;
14258 HANDLE thread;
14259 DWORD tid;
14260 struct layered_window_info info;
14261
14262 if (!pUpdateLayeredWindow)
14263 {
14264 win_skip( "UpdateLayeredWindow not supported\n" );
14265 return;
14266 }
14267
14268 hdc = CreateCompatibleDC( 0 );
14269 bmp = CreateCompatibleBitmap( hdc, 300, 300 );
14270 SelectObject( hdc, bmp );
14271
14272 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_CAPTION | WS_THICKFRAME | WS_SYSMENU,
14273 100, 100, 300, 300, 0, 0, 0, NULL);
14274 ok( hwnd != 0, "failed to create window\n" );
14275 ShowWindow( hwnd, SW_SHOWNORMAL );
14276 UpdateWindow( hwnd );
14277 flush_events();
14278 flush_sequence();
14279
14280 GetWindowRect( hwnd, &rect );
14281 GetClientRect( hwnd, &client );
14282 ok( client.right < rect.right - rect.left, "wrong client area\n" );
14283 ok( client.bottom < rect.bottom - rect.top, "wrong client area\n" );
14284
14285 src.x = src.y = 0;
14286 pos.x = pos.y = 300;
14287 size.cx = size.cy = 250;
14288 ret = pUpdateLayeredWindow( hwnd, 0, &pos, &size, hdc, &src, 0, NULL, ULW_OPAQUE );
14289 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
14290 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
14291 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
14292 ok_sequence( WmSetLayeredStyle, "WmSetLayeredStyle", FALSE );
14293
14294 ret = pUpdateLayeredWindow( hwnd, 0, &pos, &size, hdc, &src, 0, NULL, ULW_OPAQUE );
14295 ok( ret, "UpdateLayeredWindow failed err %u\n", GetLastError() );
14296 ok_sequence( WmEmptySeq, "UpdateLayeredWindow", FALSE );
14297 GetWindowRect( hwnd, &rect );
14298 ok( rect.left == 300 && rect.top == 300 && rect.right == 550 && rect.bottom == 550,
14299 "wrong window rect %d,%d,%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
14300 GetClientRect( hwnd, &rect );
14301 ok( rect.right == client.right - 50 && rect.bottom == client.bottom - 50,
14302 "wrong client rect %d,%d,%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
14303
14304 size.cx = 150;
14305 pos.y = 200;
14306 ret = pUpdateLayeredWindow( hwnd, 0, &pos, &size, hdc, &src, 0, NULL, ULW_OPAQUE );
14307 ok( ret, "UpdateLayeredWindow failed err %u\n", GetLastError() );
14308 ok_sequence( WmEmptySeq, "UpdateLayeredWindow", FALSE );
14309 GetWindowRect( hwnd, &rect );
14310 ok( rect.left == 300 && rect.top == 200 && rect.right == 450 && rect.bottom == 450,
14311 "wrong window rect %d,%d,%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
14312 GetClientRect( hwnd, &rect );
14313 ok( rect.right == client.right - 150 && rect.bottom == client.bottom - 50,
14314 "wrong client rect %d,%d,%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
14315
14316 SetWindowLongA( hwnd, GWL_STYLE,
14317 GetWindowLongA(hwnd, GWL_STYLE) & ~(WS_CAPTION | WS_THICKFRAME | WS_SYSMENU) );
14318 ok_sequence( WmSetLayeredStyle2, "WmSetLayeredStyle2", FALSE );
14319
14320 size.cx = 200;
14321 pos.x = 200;
14322 ret = pUpdateLayeredWindow( hwnd, 0, &pos, &size, hdc, &src, 0, NULL, ULW_OPAQUE );
14323 ok( ret, "UpdateLayeredWindow failed err %u\n", GetLastError() );
14324 ok_sequence( WmEmptySeq, "UpdateLayeredWindow", FALSE );
14325 GetWindowRect( hwnd, &rect );
14326 ok( rect.left == 200 && rect.top == 200 && rect.right == 400 && rect.bottom == 450,
14327 "wrong window rect %d,%d,%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
14328 GetClientRect( hwnd, &rect );
14329 ok( (rect.right == 200 && rect.bottom == 250) ||
14330 broken(rect.right == client.right - 100 && rect.bottom == client.bottom - 50),
14331 "wrong client rect %d,%d,%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
14332
14333 size.cx = 0;
14334 ret = pUpdateLayeredWindow( hwnd, 0, &pos, &size, hdc, &src, 0, NULL, ULW_OPAQUE );
14335 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
14336 ok( GetLastError() == ERROR_INVALID_PARAMETER || broken(ERROR_MR_MID_NOT_FOUND) /* win7 */,
14337 "wrong error %u\n", GetLastError() );
14338 size.cx = 1;
14339 size.cy = -1;
14340 ret = pUpdateLayeredWindow( hwnd, 0, &pos, &size, hdc, &src, 0, NULL, ULW_OPAQUE );
14341 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
14342 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
14343
14344 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
14345 ok_sequence( WmSetLayeredStyle, "WmSetLayeredStyle", FALSE );
14346 GetWindowRect( hwnd, &rect );
14347 ok( rect.left == 200 && rect.top == 200 && rect.right == 400 && rect.bottom == 450,
14348 "wrong window rect %d,%d,%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
14349 GetClientRect( hwnd, &rect );
14350 ok( (rect.right == 200 && rect.bottom == 250) ||
14351 broken(rect.right == client.right - 100 && rect.bottom == client.bottom - 50),
14352 "wrong client rect %d,%d,%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
14353
14354 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
14355 info.hwnd = hwnd;
14356 info.hdc = hdc;
14357 info.size.cx = 250;
14358 info.size.cy = 300;
14359 info.event = CreateEventA( NULL, TRUE, FALSE, NULL );
14360 info.ret = FALSE;
14361 thread = CreateThread( NULL, 0, update_layered_proc, &info, 0, &tid );
14362 ok( WaitForSingleObject( info.event, 1000 ) == 0, "wait failed\n" );
14363 ok( info.ret, "UpdateLayeredWindow failed in other thread\n" );
14364 WaitForSingleObject( thread, 1000 );
14365 CloseHandle( thread );
14366 GetWindowRect( hwnd, &rect );
14367 ok( rect.left == 200 && rect.top == 200 && rect.right == 450 && rect.bottom == 500,
14368 "wrong window rect %d,%d,%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
14369 GetClientRect( hwnd, &rect );
14370 ok( (rect.right == 250 && rect.bottom == 300) ||
14371 broken(rect.right == client.right - 50 && rect.bottom == client.bottom),
14372 "wrong client rect %d,%d,%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
14373
14374 DestroyWindow( hwnd );
14375 DeleteDC( hdc );
14376 DeleteObject( bmp );
14377 }
14378
14379 static HMENU hpopupmenu;
14380
14381 static LRESULT WINAPI cancel_popup_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
14382 {
14383 if (ignore_message( message )) return 0;
14384
14385 switch (message) {
14386 case WM_ENTERIDLE:
14387 todo_wine ok(GetCapture() == hwnd, "expected %p, got %p\n", hwnd, GetCapture());
14388 EndMenu();
14389 break;
14390 case WM_INITMENU:
14391 case WM_INITMENUPOPUP:
14392 case WM_UNINITMENUPOPUP:
14393 ok((HMENU)wParam == hpopupmenu, "expected %p, got %lx\n", hpopupmenu, wParam);
14394 break;
14395 case WM_CAPTURECHANGED:
14396 todo_wine ok(!lParam || (HWND)lParam == hwnd, "lost capture to %lx\n", lParam);
14397 break;
14398 }
14399
14400 return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
14401 }
14402
14403 static LRESULT WINAPI cancel_init_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
14404 {
14405 if (ignore_message( message )) return 0;
14406
14407 switch (message) {
14408 case WM_ENTERMENULOOP:
14409 ok(EndMenu() == TRUE, "EndMenu() failed\n");
14410 break;
14411 }
14412
14413 return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
14414 }
14415
14416 static void test_TrackPopupMenu(void)
14417 {
14418 HWND hwnd;
14419 BOOL ret;
14420
14421 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
14422 0, 0, 1, 1, 0,
14423 NULL, NULL, 0);
14424 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
14425
14426 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)cancel_popup_proc);
14427
14428 hpopupmenu = CreatePopupMenu();
14429 ok(hpopupmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
14430
14431 AppendMenuA(hpopupmenu, MF_STRING, 100, "item 1");
14432 AppendMenuA(hpopupmenu, MF_STRING, 100, "item 2");
14433
14434 flush_events();
14435 flush_sequence();
14436 ret = TrackPopupMenu(hpopupmenu, 0, 100,100, 0, hwnd, NULL);
14437 ok_sequence(WmTrackPopupMenu, "TrackPopupMenu", TRUE);
14438 ok(ret == 1, "TrackPopupMenu failed with error %i\n", GetLastError());
14439
14440 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)cancel_init_proc);
14441
14442 flush_events();
14443 flush_sequence();
14444 ret = TrackPopupMenu(hpopupmenu, 0, 100,100, 0, hwnd, NULL);
14445 ok_sequence(WmTrackPopupMenuAbort, "WmTrackPopupMenuAbort", TRUE);
14446 ok(ret == TRUE, "TrackPopupMenu failed\n");
14447
14448 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)cancel_popup_proc);
14449
14450 SetCapture(hwnd);
14451
14452 flush_events();
14453 flush_sequence();
14454 ret = TrackPopupMenu(hpopupmenu, 0, 100,100, 0, hwnd, NULL);
14455 ok_sequence(WmTrackPopupMenuCapture, "TrackPopupMenuCapture", TRUE);
14456 ok(ret == 1, "TrackPopupMenuCapture failed with error %i\n", GetLastError());
14457
14458 DestroyMenu(hpopupmenu);
14459 DestroyWindow(hwnd);
14460 }
14461
14462 static void test_TrackPopupMenuEmpty(void)
14463 {
14464 HWND hwnd;
14465 BOOL ret;
14466
14467 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
14468 0, 0, 1, 1, 0,
14469 NULL, NULL, 0);
14470 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
14471
14472 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)cancel_popup_proc);
14473
14474 hpopupmenu = CreatePopupMenu();
14475 ok(hpopupmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
14476
14477 flush_events();
14478 flush_sequence();
14479 ret = TrackPopupMenu(hpopupmenu, 0, 100,100, 0, hwnd, NULL);
14480 ok_sequence(WmTrackPopupMenuEmpty, "TrackPopupMenuEmpty", TRUE);
14481 todo_wine ok(ret == 0, "TrackPopupMenu succeeded\n");
14482
14483 DestroyMenu(hpopupmenu);
14484 DestroyWindow(hwnd);
14485 }
14486
14487 static void init_funcs(void)
14488 {
14489 HMODULE hKernel32 = GetModuleHandleA("kernel32.dll");
14490
14491 #define X(f) p##f = (void*)GetProcAddress(hKernel32, #f)
14492 X(ActivateActCtx);
14493 X(CreateActCtxW);
14494 X(DeactivateActCtx);
14495 X(GetCurrentActCtx);
14496 X(ReleaseActCtx);
14497 #undef X
14498 }
14499
14500 #ifndef __REACTOS__
14501 START_TEST(msg)
14502 {
14503 char **test_argv;
14504 BOOL ret;
14505 BOOL (WINAPI *pIsWinEventHookInstalled)(DWORD)= 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
14506 HMODULE hModuleImm32;
14507 BOOL (WINAPI *pImmDisableIME)(DWORD);
14508 int argc;
14509
14510 init_funcs();
14511
14512 argc = winetest_get_mainargs( &test_argv );
14513 if (argc >= 3)
14514 {
14515 unsigned int arg;
14516 /* Child process. */
14517 sscanf (test_argv[2], "%d", (unsigned int *) &arg);
14518 do_wait_idle_child( arg );
14519 return;
14520 }
14521
14522 InitializeCriticalSection( &sequence_cs );
14523 init_procs();
14524
14525 hModuleImm32 = LoadLibraryA("imm32.dll");
14526 if (hModuleImm32) {
14527 pImmDisableIME = (void *)GetProcAddress(hModuleImm32, "ImmDisableIME");
14528 if (pImmDisableIME)
14529 pImmDisableIME(0);
14530 }
14531 pImmDisableIME = NULL;
14532 FreeLibrary(hModuleImm32);
14533
14534 if (!RegisterWindowClasses()) assert(0);
14535
14536 if (pSetWinEventHook)
14537 {
14538 hEvent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX,
14539 GetModuleHandleA(0), win_event_proc,
14540 0, GetCurrentThreadId(),
14541 WINEVENT_INCONTEXT);
14542 if (pIsWinEventHookInstalled && hEvent_hook)
14543 {
14544 UINT event;
14545 for (event = EVENT_MIN; event <= EVENT_MAX; event++)
14546 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
14547 }
14548 }
14549 if (!hEvent_hook) win_skip( "no win event hook support\n" );
14550
14551 cbt_hook_thread_id = GetCurrentThreadId();
14552 hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
14553 if (!hCBT_hook) win_skip( "cannot set global hook, will skip hook tests\n" );
14554
14555 test_winevents();
14556
14557 /* Fix message sequences before removing 4 lines below */
14558 if (pUnhookWinEvent && hEvent_hook)
14559 {
14560 ret = pUnhookWinEvent(hEvent_hook);
14561 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
14562 pUnhookWinEvent = 0;
14563 }
14564 hEvent_hook = 0;
14565 test_SetFocus();
14566 test_SetParent();
14567 test_PostMessage();
14568 test_ShowWindow();
14569 test_PeekMessage();
14570 test_PeekMessage2();
14571 test_WaitForInputIdle( test_argv[0] );
14572 test_scrollwindowex();
14573 test_messages();
14574 test_setwindowpos();
14575 test_showwindow();
14576 invisible_parent_tests();
14577 test_mdi_messages();
14578 test_button_messages();
14579 test_static_messages();
14580 test_listbox_messages();
14581 test_combobox_messages();
14582 test_wmime_keydown_message();
14583 test_paint_messages();
14584 test_interthread_messages();
14585 test_message_conversion();
14586 test_accelerators();
14587 test_timers();
14588 test_timers_no_wnd();
14589 test_timers_exceptions();
14590 if (hCBT_hook) test_set_hook();
14591 test_DestroyWindow();
14592 test_DispatchMessage();
14593 test_SendMessageTimeout();
14594 test_edit_messages();
14595 test_quit_message();
14596 test_SetActiveWindow();
14597
14598 if (!pTrackMouseEvent)
14599 win_skip("TrackMouseEvent is not available\n");
14600 else
14601 test_TrackMouseEvent();
14602
14603 test_SetWindowRgn();
14604 test_sys_menu();
14605 test_dialog_messages();
14606 test_EndDialog();
14607 test_nullCallback();
14608 test_dbcs_wm_char();
14609 test_unicode_wm_char();
14610 test_menu_messages();
14611 test_paintingloop();
14612 test_defwinproc();
14613 test_clipboard_viewers();
14614 test_keyflags();
14615 test_hotkey();
14616 test_layered_window();
14617 if(!winetest_interactive)
14618 skip("CORE-8299 : Skip Tracking popup menu tests.\n");
14619 else
14620 {
14621 test_TrackPopupMenu();
14622 test_TrackPopupMenuEmpty();
14623 }
14624 /* keep it the last test, under Windows it tends to break the tests
14625 * which rely on active/foreground windows being correct.
14626 */
14627 test_SetForegroundWindow();
14628
14629 UnhookWindowsHookEx(hCBT_hook);
14630 if (pUnhookWinEvent && hEvent_hook)
14631 {
14632 ret = pUnhookWinEvent(hEvent_hook);
14633 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
14634 SetLastError(0xdeadbeef);
14635 ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
14636 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
14637 GetLastError() == 0xdeadbeef, /* Win9x */
14638 "unexpected error %d\n", GetLastError());
14639 }
14640 DeleteCriticalSection( &sequence_cs );
14641 }
14642 #endif /* __REACTOS__ */
14643
14644 static void init_tests()
14645 {
14646 HMODULE hModuleImm32;
14647 BOOL (WINAPI *pImmDisableIME)(DWORD);
14648
14649 init_funcs();
14650
14651 InitializeCriticalSection( &sequence_cs );
14652 init_procs();
14653
14654 hModuleImm32 = LoadLibraryA("imm32.dll");
14655 if (hModuleImm32) {
14656 pImmDisableIME = (void *)GetProcAddress(hModuleImm32, "ImmDisableIME");
14657 if (pImmDisableIME)
14658 pImmDisableIME(0);
14659 }
14660 pImmDisableIME = NULL;
14661 FreeLibrary(hModuleImm32);
14662
14663 if (!RegisterWindowClasses()) assert(0);
14664
14665 cbt_hook_thread_id = GetCurrentThreadId();
14666 hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
14667 if (!hCBT_hook) win_skip( "cannot set global hook, will skip hook tests\n" );
14668 }
14669
14670 static void cleanup_tests()
14671 {
14672 BOOL ret;
14673 UnhookWindowsHookEx(hCBT_hook);
14674 if (pUnhookWinEvent && hEvent_hook)
14675 {
14676 ret = pUnhookWinEvent(hEvent_hook);
14677 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
14678 SetLastError(0xdeadbeef);
14679 ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
14680 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
14681 GetLastError() == 0xdeadbeef, /* Win9x */
14682 "unexpected error %d\n", GetLastError());
14683 }
14684 DeleteCriticalSection( &sequence_cs );
14685
14686 }
14687
14688 START_TEST(msg_queue)
14689 {
14690 int argc;
14691 char **test_argv;
14692 argc = winetest_get_mainargs( &test_argv );
14693 if (argc >= 3)
14694 {
14695 unsigned int arg;
14696 /* Child process. */
14697 sscanf (test_argv[2], "%d", (unsigned int *) &arg);
14698 do_wait_idle_child( arg );
14699 return;
14700 }
14701
14702 init_tests();
14703 test_PostMessage();
14704 test_PeekMessage();
14705 test_PeekMessage2();
14706 test_interthread_messages();
14707 test_DispatchMessage();
14708 test_SendMessageTimeout();
14709 test_quit_message();
14710 test_WaitForInputIdle( test_argv[0] );
14711 test_DestroyWindow();
14712 cleanup_tests();
14713 }
14714
14715 START_TEST(msg_messages)
14716 {
14717 init_tests();
14718 test_message_conversion();
14719 test_messages();
14720 test_wmime_keydown_message();
14721 test_nullCallback();
14722 test_dbcs_wm_char();
14723 test_unicode_wm_char();
14724 test_defwinproc();
14725 cleanup_tests();
14726 }
14727
14728 START_TEST(msg_focus)
14729 {
14730 init_tests();
14731
14732 test_SetFocus();
14733
14734 /* HACK: For some reason the tests fail on Windows if run consecutively.
14735 * Putting these in between helps, and is essentially what happens in the
14736 * "normal" msg test. */
14737 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
14738 flush_events();
14739
14740 test_SetActiveWindow();
14741
14742 /* HACK */
14743 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
14744 flush_events();
14745
14746 /* keep it the last test, under Windows it tends to break the tests
14747 * which rely on active/foreground windows being correct.
14748 */
14749 test_SetForegroundWindow();
14750 cleanup_tests();
14751 }
14752
14753 START_TEST(msg_winpos)
14754 {
14755 init_tests();
14756 test_SetParent();
14757 test_ShowWindow();
14758 test_setwindowpos();
14759 test_showwindow();
14760 test_SetWindowRgn();
14761 invisible_parent_tests();
14762 cleanup_tests();
14763 }
14764
14765 START_TEST(msg_paint)
14766 {
14767 init_tests();
14768 test_scrollwindowex();
14769 test_paint_messages();
14770 test_paintingloop();
14771 cleanup_tests();
14772 }
14773
14774 START_TEST(msg_input)
14775 {
14776 init_tests();
14777 test_accelerators();
14778 if (!pTrackMouseEvent)
14779 win_skip("TrackMouseEvent is not available\n");
14780 else
14781 test_TrackMouseEvent();
14782
14783 test_keyflags();
14784 test_hotkey();
14785 cleanup_tests();
14786 }
14787
14788 START_TEST(msg_timer)
14789 {
14790 init_tests();
14791 test_timers();
14792 test_timers_no_wnd();
14793 test_timers_exceptions();
14794 cleanup_tests();
14795 }
14796
14797 typedef BOOL (WINAPI *IS_WINEVENT_HOOK_INSTALLED)(DWORD);
14798
14799 START_TEST(msg_hook)
14800 {
14801 // HMODULE user32 = GetModuleHandleA("user32.dll");
14802 // IS_WINEVENT_HOOK_INSTALLED pIsWinEventHookInstalled = (IS_WINEVENT_HOOK_INSTALLED)GetProcAddress(user32, "IsWinEventHookInstalled");
14803 BOOL (WINAPI *pIsWinEventHookInstalled)(DWORD)= 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
14804
14805 init_tests();
14806
14807 if (pSetWinEventHook)
14808 {
14809 hEvent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX,
14810 GetModuleHandleA(0), win_event_proc,
14811 0, GetCurrentThreadId(),
14812 WINEVENT_INCONTEXT);
14813 if (pIsWinEventHookInstalled && hEvent_hook)
14814 {
14815 UINT event;
14816 for (event = EVENT_MIN; event <= EVENT_MAX; event++)
14817 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
14818 }
14819 }
14820 if (!hEvent_hook) win_skip( "no win event hook support\n" );
14821
14822 test_winevents();
14823
14824 /* Fix message sequences before removing 4 lines below */
14825 if (pUnhookWinEvent && hEvent_hook)
14826 {
14827 BOOL ret;
14828 ret = pUnhookWinEvent(hEvent_hook);
14829 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
14830 pUnhookWinEvent = 0;
14831 }
14832 hEvent_hook = 0;
14833 if (hCBT_hook) test_set_hook();
14834 cleanup_tests();
14835 }
14836
14837 START_TEST(msg_menu)
14838 {
14839 init_tests();
14840 test_sys_menu();
14841 test_menu_messages();
14842 if(!winetest_interactive)
14843 skip("CORE-8299 : Skip Tracking popup menu tests.\n");
14844 else
14845 {
14846 test_TrackPopupMenu();
14847 test_TrackPopupMenuEmpty();
14848 }
14849 cleanup_tests();
14850 }
14851
14852 START_TEST(msg_mdi)
14853 {
14854 init_tests();
14855 test_mdi_messages();
14856 cleanup_tests();
14857 }
14858
14859 START_TEST(msg_controls)
14860 {
14861 init_tests();
14862 test_button_messages();
14863 test_static_messages();
14864 test_listbox_messages();
14865 test_combobox_messages();
14866 test_edit_messages();
14867 cleanup_tests();
14868 }
14869
14870 START_TEST(msg_layered_window)
14871 {
14872 init_tests();
14873 test_layered_window();
14874 cleanup_tests();
14875 }
14876
14877 START_TEST(msg_dialog)
14878 {
14879 init_tests();
14880 test_dialog_messages();
14881 test_EndDialog();
14882 cleanup_tests();
14883 }
14884
14885 START_TEST(msg_clipboard)
14886 {
14887 init_tests();
14888 test_clipboard_viewers();
14889 cleanup_tests();
14890 }