Merge trunk HEAD (r46369)
[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 0x0501 /* For WM_CHANGEUISTATE,QS_RAWINPUT */
24
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winnls.h"
34
35 #include "wine/test.h"
36
37 #define MDI_FIRST_CHILD_ID 2004
38
39 /* undocumented SWP flags - from SDK 3.1 */
40 #define SWP_NOCLIENTSIZE 0x0800
41 #define SWP_NOCLIENTMOVE 0x1000
42 #define SWP_STATECHANGED 0x8000
43
44 #define SW_NORMALNA 0xCC /* undoc. flag in MinMaximize */
45
46 #ifndef WM_KEYF1
47 #define WM_KEYF1 0x004d
48 #endif
49
50 #ifndef WM_SYSTIMER
51 #define WM_SYSTIMER 0x0118
52 #endif
53
54 #define WND_PARENT_ID 1
55 #define WND_POPUP_ID 2
56 #define WND_CHILD_ID 3
57
58 #ifndef WM_LBTRACKPOINT
59 #define WM_LBTRACKPOINT 0x0131
60 #endif
61
62 /* encoded DRAWITEMSTRUCT into an LPARAM */
63 typedef struct
64 {
65 union
66 {
67 struct
68 {
69 UINT type : 4; /* ODT_* flags */
70 UINT ctl_id : 4; /* Control ID */
71 UINT item_id : 4; /* Menu item ID */
72 UINT action : 4; /* ODA_* flags */
73 UINT state : 16; /* ODS_* flags */
74 } item;
75 LPARAM lp;
76 } u;
77 } DRAW_ITEM_STRUCT;
78
79 static BOOL test_DestroyWindow_flag;
80 static HWINEVENTHOOK hEvent_hook;
81 static HHOOK hCBT_hook;
82 static DWORD cbt_hook_thread_id;
83
84 static const WCHAR testWindowClassW[] =
85 { 'T','e','s','t','W','i','n','d','o','w','C','l','a','s','s','W',0 };
86
87 /*
88 FIXME: add tests for these
89 Window Edge Styles (Win31/Win95/98 look), in order of precedence:
90 WS_EX_DLGMODALFRAME: double border, WS_CAPTION allowed
91 WS_THICKFRAME: thick border
92 WS_DLGFRAME: double border, WS_CAPTION not allowed (but possibly shown anyway)
93 WS_BORDER (default for overlapped windows): single black border
94 none (default for child (and popup?) windows): no border
95 */
96
97 typedef enum {
98 sent=0x1,
99 posted=0x2,
100 parent=0x4,
101 wparam=0x8,
102 lparam=0x10,
103 defwinproc=0x20,
104 beginpaint=0x40,
105 optional=0x80,
106 hook=0x100,
107 winevent_hook=0x200
108 } msg_flags_t;
109
110 struct message {
111 UINT message; /* the WM_* code */
112 msg_flags_t flags; /* message props */
113 WPARAM wParam; /* expected value of wParam */
114 LPARAM lParam; /* expected value of lParam */
115 WPARAM wp_mask; /* mask for wParam checks */
116 LPARAM lp_mask; /* mask for lParam checks */
117 };
118
119 struct recvd_message {
120 UINT message; /* the WM_* code */
121 msg_flags_t flags; /* message props */
122 HWND hwnd; /* window that received the message */
123 WPARAM wParam; /* expected value of wParam */
124 LPARAM lParam; /* expected value of lParam */
125 int line; /* source line where logged */
126 const char *descr; /* description for trace output */
127 char output[512]; /* trace output */
128 };
129
130 /* Empty message sequence */
131 static const struct message WmEmptySeq[] =
132 {
133 { 0 }
134 };
135 /* CreateWindow (for overlapped window, not initially visible) (16/32) */
136 static const struct message WmCreateOverlappedSeq[] = {
137 { HCBT_CREATEWND, hook },
138 { WM_GETMINMAXINFO, sent },
139 { WM_NCCREATE, sent },
140 { WM_NCCALCSIZE, sent|wparam, 0 },
141 { 0x0093, sent|defwinproc|optional },
142 { 0x0094, sent|defwinproc|optional },
143 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
144 { WM_CREATE, sent },
145 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
146 { 0 }
147 };
148 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
149 * for a not visible overlapped window.
150 */
151 static const struct message WmSWP_ShowOverlappedSeq[] = {
152 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
153 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
154 { WM_NCPAINT, sent|wparam|optional, 1 },
155 { WM_GETTEXT, sent|defwinproc|optional },
156 { WM_ERASEBKGND, sent|optional },
157 { HCBT_ACTIVATE, hook },
158 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
159 { WM_NOTIFYFORMAT, sent|optional },
160 { WM_QUERYUISTATE, sent|optional },
161 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
162 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x: SWP_NOSENDCHANGING */
163 { WM_ACTIVATEAPP, sent|wparam, 1 },
164 { WM_NCACTIVATE, sent|wparam, 1 },
165 { WM_GETTEXT, sent|defwinproc|optional },
166 { WM_ACTIVATE, sent|wparam, 1 },
167 { HCBT_SETFOCUS, hook },
168 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
169 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
170 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
171 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
172 { WM_GETTEXT, sent|optional },
173 { WM_NCPAINT, sent|wparam|optional, 1 },
174 { WM_GETTEXT, sent|defwinproc|optional },
175 { WM_ERASEBKGND, sent|optional },
176 /* Win9x adds SWP_NOZORDER below */
177 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
178 { WM_GETTEXT, sent|optional },
179 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
180 { WM_NCPAINT, sent|wparam|optional, 1 },
181 { WM_ERASEBKGND, sent|optional },
182 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
183 { WM_SYNCPAINT, sent|optional },
184 { WM_GETTITLEBARINFOEX, sent|optional },
185 { WM_PAINT, sent|optional },
186 { WM_NCPAINT, sent|beginpaint|optional },
187 { WM_GETTEXT, sent|defwinproc|optional },
188 { WM_ERASEBKGND, sent|beginpaint|optional },
189 { 0 }
190 };
191 /* SetWindowPos(SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE)
192 * for a visible overlapped window.
193 */
194 static const struct message WmSWP_HideOverlappedSeq[] = {
195 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
196 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
197 { HCBT_ACTIVATE, hook|optional },
198 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
199 { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
200 { WM_NCACTIVATE, sent|optional },
201 { WM_ACTIVATE, sent|optional },
202 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
203 { 0 }
204 };
205
206 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
207 * for a visible overlapped window.
208 */
209 static const struct message WmSWP_ResizeSeq[] = {
210 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
211 { WM_GETMINMAXINFO, sent|defwinproc },
212 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
213 { WM_NCPAINT, sent|optional },
214 { WM_GETTEXT, sent|defwinproc|optional },
215 { WM_ERASEBKGND, sent|optional },
216 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
217 { WM_SIZE, sent|defwinproc|optional },
218 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
219 { WM_NCPAINT, sent|optional },
220 { WM_GETTEXT, sent|defwinproc|optional },
221 { WM_ERASEBKGND, sent|optional },
222 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
223 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
224 { 0 }
225 };
226
227 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE)
228 * for a visible popup window.
229 */
230 static const struct message WmSWP_ResizePopupSeq[] = {
231 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE },
232 { WM_GETMINMAXINFO, sent|defwinproc|optional }, /* Win9x */
233 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
234 { WM_NCPAINT, sent|optional },
235 { WM_GETTEXT, sent|defwinproc|optional },
236 { WM_ERASEBKGND, sent|optional },
237 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
238 { WM_SIZE, sent|defwinproc|wparam|optional, SIZE_RESTORED },
239 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
240 { WM_NCPAINT, sent|optional },
241 { WM_GETTEXT, sent|defwinproc|optional },
242 { WM_ERASEBKGND, sent|optional },
243 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
244 { 0 }
245 };
246
247 /* SetWindowPos(SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE)
248 * for a visible overlapped window.
249 */
250 static const struct message WmSWP_MoveSeq[] = {
251 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE },
252 { WM_NCPAINT, sent|optional },
253 { WM_GETTEXT, sent|defwinproc|optional },
254 { WM_ERASEBKGND, sent|optional },
255 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
256 { WM_MOVE, sent|defwinproc|wparam, 0 },
257 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
258 { 0 }
259 };
260 /* Resize with SetWindowPos(SWP_NOZORDER)
261 * for a visible overlapped window
262 * SWP_NOZORDER is stripped by the logging code
263 */
264 static const struct message WmSWP_ResizeNoZOrder[] = {
265 { WM_WINDOWPOSCHANGING, sent|wparam, /*SWP_NOZORDER|*/SWP_NOACTIVATE },
266 { WM_GETMINMAXINFO, sent|defwinproc },
267 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
268 { WM_NCPAINT, sent|optional },
269 { WM_GETTEXT, sent|defwinproc|optional },
270 { WM_ERASEBKGND, sent|optional },
271 { WM_WINDOWPOSCHANGED, sent|wparam, /*SWP_NOZORDER|*/SWP_NOACTIVATE, 0,
272 SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE },
273 { WM_MOVE, sent|defwinproc|optional },
274 { WM_SIZE, sent|defwinproc|optional },
275 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
276 { WM_NCPAINT, sent|optional }, /* Win9x doesn't send it */
277 { WM_GETTEXT, sent|defwinproc|optional }, /* Win9x doesn't send it */
278 { WM_ERASEBKGND, sent|optional }, /* Win9x doesn't send it */
279 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
280 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
281 { 0 }
282 };
283
284 /* Switch visible mdi children */
285 static const struct message WmSwitchChild[] = {
286 /* Switch MDI child */
287 { WM_MDIACTIVATE, sent },/* in the MDI client */
288 { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 1st MDI child */
289 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
290 { WM_CHILDACTIVATE, sent },/* in the 1st MDI child */
291 /* Deactivate 2nd MDI child */
292 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
293 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
294 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
295 /* Preparing for maximize and maximaze the 1st MDI child */
296 { WM_GETMINMAXINFO, sent|defwinproc }, /* in the 1st MDI child */
297 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED }, /* in the 1st MDI child */
298 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
299 { WM_CHILDACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
300 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 1st MDI child */
301 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED }, /* in the 1st MDI child */
302 /* Lock redraw 2nd MDI child */
303 { WM_SETREDRAW, sent|wparam|defwinproc, 0 }, /* in the 2nd MDI child */
304 { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
305 /* Restore 2nd MDI child */
306 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },/* in the 2nd MDI child */
307 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
308 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
309 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED }, /* in the 2nd MDI child */
310 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED }, /* in the 2nd MDI child */
311 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 2nd MDI child */
312 /* Redraw 2nd MDI child */
313 { WM_SETREDRAW, sent|wparam|defwinproc, 1 },/* in the 2nd MDI child */
314 /* Redraw MDI frame */
315 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },/* in MDI frame */
316 { WM_NCCALCSIZE, sent|wparam, 1 },/* in MDI frame */
317 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in MDI frame */
318 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in MDI frame */
319 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
320 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
321 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 1st MDI child */
322 { HCBT_SETFOCUS, hook },
323 { WM_KILLFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
324 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },/* in the 1st MDI child */
325 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
326 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
327 { WM_SETFOCUS, sent },/* in the MDI client */
328 { HCBT_SETFOCUS, hook },
329 { WM_KILLFOCUS, sent },/* in the MDI client */
330 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
331 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 }, /* in the 1st MDI child */
332 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
333 { WM_SETFOCUS, sent|defwinproc }, /* in the 1st MDI child */
334 { WM_MDIACTIVATE, sent|defwinproc },/* in the 1st MDI child */
335 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE }, /* in the 1st MDI child */
336 { 0 }
337 };
338
339 /* Switch visible not maximized mdi children */
340 static const struct message WmSwitchNotMaximizedChild[] = {
341 /* Switch not maximized MDI child */
342 { WM_MDIACTIVATE, sent },/* in the MDI client */
343 { WM_WINDOWPOSCHANGING, sent|wparam,SWP_NOSIZE|SWP_NOMOVE },/* in the 2nd MDI child */
344 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
345 { WM_CHILDACTIVATE, sent },/* in the 2nd MDI child */
346 /* Deactivate 1st MDI child */
347 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
348 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
349 /* Activate 2nd MDI child */
350 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE}, /* in the 2nd MDI child */
351 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 }, /* in the 2nd MDI child */
352 { HCBT_SETFOCUS, hook }, /* in the 1st MDI child */
353 { WM_KILLFOCUS, sent|defwinproc }, /* in the 1st MDI child */
354 { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
355 { WM_IME_SETCONTEXT, sent|optional }, /* in the MDI client */
356 { WM_SETFOCUS, sent, 0 }, /* in the MDI client */
357 { HCBT_SETFOCUS, hook },
358 { WM_KILLFOCUS, sent }, /* in the MDI client */
359 { WM_IME_SETCONTEXT, sent|optional }, /* in the MDI client */
360 { WM_IME_SETCONTEXT, sent|defwinproc|optional }, /* in the 1st MDI child */
361 { WM_SETFOCUS, sent|defwinproc }, /* in the 2nd MDI child */
362 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 2nd MDI child */
363 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE}, /* in the 2nd MDI child */
364 { 0 }
365 };
366
367
368 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
369 SWP_NOZORDER|SWP_FRAMECHANGED)
370 * for a visible overlapped window with WS_CLIPCHILDREN style set.
371 */
372 static const struct message WmSWP_FrameChanged_clip[] = {
373 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
374 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
375 { WM_NCPAINT, sent|parent|optional }, /* wparam != 1 */
376 { WM_GETTEXT, sent|parent|defwinproc|optional },
377 { WM_ERASEBKGND, sent|parent|optional }, /* FIXME: remove optional once Wine is fixed */
378 { WM_NCPAINT, sent }, /* wparam != 1 */
379 { WM_ERASEBKGND, sent },
380 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
381 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
382 { WM_PAINT, sent },
383 { 0 }
384 };
385 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|
386 SWP_NOZORDER|SWP_FRAMECHANGED)
387 * for a visible overlapped window.
388 */
389 static const struct message WmSWP_FrameChangedDeferErase[] = {
390 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
391 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
392 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_DEFERERASE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
393 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
394 { WM_PAINT, sent|parent|optional },
395 { WM_NCPAINT, sent|beginpaint|parent|optional }, /* wparam != 1 */
396 { WM_GETTEXT, sent|beginpaint|parent|defwinproc|optional },
397 { WM_PAINT, sent },
398 { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
399 { WM_ERASEBKGND, sent|beginpaint|optional },
400 { 0 }
401 };
402
403 /* SetWindowPos(SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|
404 SWP_NOZORDER|SWP_FRAMECHANGED)
405 * for a visible overlapped window without WS_CLIPCHILDREN style set.
406 */
407 static const struct message WmSWP_FrameChanged_noclip[] = {
408 { WM_WINDOWPOSCHANGING, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED },
409 { WM_NCCALCSIZE, sent|wparam|parent, 1 },
410 { WM_NCPAINT, sent|parent|optional }, /* wparam != 1 */
411 { WM_GETTEXT, sent|parent|defwinproc|optional },
412 { WM_ERASEBKGND, sent|parent|optional },
413 { WM_WINDOWPOSCHANGED, sent|wparam|parent, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
414 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
415 { WM_PAINT, sent },
416 { WM_NCPAINT, sent|beginpaint }, /* wparam != 1 */
417 { WM_ERASEBKGND, sent|beginpaint|optional },
418 { 0 }
419 };
420
421 /* ShowWindow(SW_SHOW) for a not visible overlapped window */
422 static const struct message WmShowOverlappedSeq[] = {
423 { WM_SHOWWINDOW, sent|wparam, 1 },
424 { WM_NCPAINT, sent|wparam|optional, 1 },
425 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
426 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
427 { WM_NCPAINT, sent|wparam|optional, 1 },
428 { WM_GETTEXT, sent|defwinproc|optional },
429 { WM_ERASEBKGND, sent|optional },
430 { HCBT_ACTIVATE, hook },
431 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
432 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
433 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
434 { WM_NCPAINT, sent|wparam|optional, 1 },
435 { WM_ACTIVATEAPP, sent|wparam, 1 },
436 { WM_NCACTIVATE, sent|wparam, 1 },
437 { WM_GETTEXT, sent|defwinproc|optional },
438 { WM_ACTIVATE, sent|wparam, 1 },
439 { HCBT_SETFOCUS, hook },
440 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
441 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
442 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
443 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
444 { WM_GETTEXT, sent|optional },
445 { WM_NCPAINT, sent|wparam|optional, 1 },
446 { WM_GETTEXT, sent|defwinproc|optional },
447 { WM_ERASEBKGND, sent|optional },
448 /* Win9x adds SWP_NOZORDER below */
449 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
450 { WM_NCCALCSIZE, sent|optional },
451 { WM_GETTEXT, sent|optional },
452 { WM_NCPAINT, sent|optional },
453 { WM_ERASEBKGND, sent|optional },
454 { WM_SYNCPAINT, sent|optional },
455 #if 0 /* CreateWindow/ShowWindow(SW_SHOW) also generates WM_SIZE/WM_MOVE
456 * messages. Does that mean that CreateWindow doesn't set initial
457 * window dimensions for overlapped windows?
458 */
459 { WM_SIZE, sent },
460 { WM_MOVE, sent },
461 #endif
462 { WM_PAINT, sent|optional },
463 { WM_NCPAINT, sent|beginpaint|optional },
464 { 0 }
465 };
466 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible overlapped window */
467 static const struct message WmShowMaxOverlappedSeq[] = {
468 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
469 { WM_GETMINMAXINFO, sent },
470 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
471 { WM_GETMINMAXINFO, sent|defwinproc },
472 { WM_NCCALCSIZE, sent|wparam, TRUE },
473 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
474 { HCBT_ACTIVATE, hook },
475 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
476 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
477 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
478 { WM_ACTIVATEAPP, sent|wparam, 1 },
479 { WM_NCACTIVATE, sent|wparam, 1 },
480 { WM_GETTEXT, sent|defwinproc|optional },
481 { WM_ACTIVATE, sent|wparam, 1 },
482 { HCBT_SETFOCUS, hook },
483 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
484 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
485 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
486 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
487 { WM_GETTEXT, sent|optional },
488 { WM_NCPAINT, sent|wparam|optional, 1 },
489 { WM_GETTEXT, sent|defwinproc|optional },
490 { WM_ERASEBKGND, sent|optional },
491 /* Win9x adds SWP_NOZORDER below */
492 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
493 { WM_MOVE, sent|defwinproc },
494 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
495 { WM_GETTEXT, sent|optional },
496 { WM_NCCALCSIZE, sent|optional },
497 { WM_NCPAINT, sent|optional },
498 { WM_ERASEBKGND, sent|optional },
499 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
500 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
501 { WM_SYNCPAINT, sent|optional },
502 { WM_GETTITLEBARINFOEX, sent|optional },
503 { WM_PAINT, sent|optional },
504 { WM_NCPAINT, sent|beginpaint|optional },
505 { WM_ERASEBKGND, sent|beginpaint|optional },
506 { 0 }
507 };
508 /* ShowWindow(SW_RESTORE) for a not visible maximized overlapped window */
509 static const struct message WmShowRestoreMaxOverlappedSeq[] = {
510 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
511 { WM_GETTEXT, sent|optional },
512 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
513 { WM_GETMINMAXINFO, sent|defwinproc },
514 { WM_NCCALCSIZE, sent|wparam, TRUE },
515 { WM_NCPAINT, sent|optional },
516 { WM_GETTEXT, sent|defwinproc|optional },
517 { WM_ERASEBKGND, sent|optional },
518 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
519 { WM_MOVE, sent|defwinproc|optional },
520 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
521 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
522 { WM_NCPAINT, sent|optional },
523 { WM_ERASEBKGND, sent|optional },
524 { WM_PAINT, sent|optional },
525 { WM_GETTITLEBARINFOEX, sent|optional },
526 { WM_NCPAINT, sent|beginpaint|optional },
527 { WM_ERASEBKGND, sent|beginpaint|optional },
528 { 0 }
529 };
530 /* ShowWindow(SW_RESTORE) for a not visible minimized overlapped window */
531 static const struct message WmShowRestoreMinOverlappedSeq[] = {
532 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
533 { WM_QUERYOPEN, sent|optional },
534 { WM_GETTEXT, sent|optional },
535 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED|SWP_NOCOPYBITS },
536 { WM_GETMINMAXINFO, sent|defwinproc },
537 { WM_NCCALCSIZE, sent|wparam, TRUE },
538 { HCBT_ACTIVATE, hook },
539 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
540 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
541 { WM_ACTIVATEAPP, sent|wparam, 1 },
542 { WM_NCACTIVATE, sent|wparam, 1 },
543 { WM_GETTEXT, sent|defwinproc|optional },
544 { WM_ACTIVATE, sent|wparam, 1 },
545 { HCBT_SETFOCUS, hook },
546 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
547 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
548 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
549 { WM_GETTEXT, sent|optional },
550 { WM_NCPAINT, sent|wparam|optional, 1 },
551 { WM_GETTEXT, sent|defwinproc|optional },
552 { WM_ERASEBKGND, sent },
553 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_STATECHANGED|SWP_FRAMECHANGED|SWP_NOCOPYBITS },
554 { WM_MOVE, sent|defwinproc },
555 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
556 { WM_NCCALCSIZE, sent|wparam|optional, TRUE },
557 { WM_NCPAINT, sent|wparam|optional, 1 },
558 { WM_ERASEBKGND, sent|optional },
559 { WM_ACTIVATE, sent|wparam, 1 },
560 { WM_GETTEXT, sent|optional },
561 { WM_PAINT, sent|optional },
562 { WM_GETTITLEBARINFOEX, sent|optional },
563 { WM_NCPAINT, sent|beginpaint|optional },
564 { WM_ERASEBKGND, sent|beginpaint|optional },
565 { 0 }
566 };
567 /* ShowWindow(SW_SHOWMINIMIZED) for a not visible overlapped window */
568 static const struct message WmShowMinOverlappedSeq[] = {
569 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
570 { HCBT_SETFOCUS, hook },
571 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
572 { WM_KILLFOCUS, sent },
573 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
574 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
575 { WM_GETTEXT, sent|optional },
576 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCOPYBITS|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
577 { WM_GETMINMAXINFO, sent|defwinproc },
578 { WM_NCCALCSIZE, sent|wparam, TRUE },
579 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
580 { WM_NCPAINT, sent|optional },
581 { WM_GETTEXT, sent|defwinproc|optional },
582 { WM_WINDOWPOSCHANGED, sent },
583 { WM_MOVE, sent|defwinproc },
584 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
585 { WM_NCCALCSIZE, sent|optional },
586 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
587 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
588 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
589 { WM_NCACTIVATE, sent|wparam, 0 },
590 { WM_GETTEXT, sent|defwinproc|optional },
591 { WM_ACTIVATE, sent },
592 { WM_ACTIVATEAPP, sent|wparam, 0 },
593
594 /* Vista sometimes restores the window right away... */
595 { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
596 { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
597 { HCBT_MINMAX, hook|optional|lparam, 0, SW_RESTORE },
598 { WM_QUERYOPEN, sent|optional },
599 { WM_WINDOWPOSCHANGING, sent|optional|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
600 { WM_GETMINMAXINFO, sent|optional|defwinproc },
601 { WM_NCCALCSIZE, sent|optional|wparam, TRUE },
602 { HCBT_ACTIVATE, hook|optional },
603 { WM_ACTIVATEAPP, sent|optional|wparam, 1 },
604 { WM_NCACTIVATE, sent|optional },
605 { WM_GETTEXT, sent|optional },
606 { WM_ACTIVATE, sent|optional|wparam, 1 },
607 { HCBT_SETFOCUS, hook|optional },
608 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
609 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
610 { WM_SETFOCUS, sent|optional },
611 { WM_NCPAINT, sent|optional },
612 { WM_GETTEXT, sent|defwinproc|optional },
613 { WM_ERASEBKGND, sent|optional },
614 { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
615 { WM_MOVE, sent|defwinproc|optional },
616 { WM_SIZE, sent|defwinproc|optional|wparam, SIZE_RESTORED },
617 { WM_ACTIVATE, sent|optional|wparam, 1 },
618 { WM_SYSCOMMAND, sent|optional|wparam, SC_RESTORE },
619 { HCBT_SYSCOMMAND, hook|optional|wparam, SC_RESTORE },
620
621 { WM_PAINT, sent|optional },
622 { WM_NCPAINT, sent|beginpaint|optional },
623 { WM_ERASEBKGND, sent|beginpaint|optional },
624 { 0 }
625 };
626 /* ShowWindow(SW_HIDE) for a visible overlapped window */
627 static const struct message WmHideOverlappedSeq[] = {
628 { WM_SHOWWINDOW, sent|wparam, 0 },
629 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
630 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
631 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
632 { WM_SIZE, sent|optional }, /* XP doesn't send it */
633 { WM_MOVE, sent|optional }, /* XP doesn't send it */
634 { WM_NCACTIVATE, sent|wparam, 0 },
635 { WM_ACTIVATE, sent|wparam, 0 },
636 { WM_ACTIVATEAPP, sent|wparam, 0 },
637 { WM_KILLFOCUS, sent|wparam, 0 },
638 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
639 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
640 { 0 }
641 };
642 /* DestroyWindow for a visible overlapped window */
643 static const struct message WmDestroyOverlappedSeq[] = {
644 { HCBT_DESTROYWND, hook },
645 { 0x0090, sent|optional },
646 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
647 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
648 { 0x0090, sent|optional },
649 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
650 { WM_NCACTIVATE, sent|optional|wparam, 0 },
651 { WM_ACTIVATE, sent|optional },
652 { WM_ACTIVATEAPP, sent|optional|wparam, 0 },
653 { WM_KILLFOCUS, sent|optional|wparam, 0 },
654 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
655 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
656 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
657 { WM_DESTROY, sent },
658 { WM_NCDESTROY, sent },
659 { 0 }
660 };
661 /* CreateWindow(WS_MAXIMIZE|WS_VISIBLE) for popup window */
662 static const struct message WmCreateMaxPopupSeq[] = {
663 { HCBT_CREATEWND, hook },
664 { WM_NCCREATE, sent },
665 { WM_NCCALCSIZE, sent|wparam, 0 },
666 { WM_CREATE, sent },
667 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
668 { WM_SIZE, sent|wparam, SIZE_RESTORED },
669 { WM_MOVE, sent },
670 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
671 { WM_GETMINMAXINFO, sent },
672 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
673 { WM_NCCALCSIZE, sent|wparam, TRUE },
674 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
675 { WM_MOVE, sent|defwinproc },
676 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
677 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
678 { WM_SHOWWINDOW, sent|wparam, 1 },
679 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
680 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
681 { HCBT_ACTIVATE, hook },
682 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
683 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
684 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
685 { WM_NCPAINT, sent|wparam|optional, 1 },
686 { WM_ERASEBKGND, sent|optional },
687 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_NOMOVE|SWP_NOSIZE },
688 { WM_ACTIVATEAPP, sent|wparam, 1 },
689 { WM_NCACTIVATE, sent },
690 { WM_ACTIVATE, sent|wparam, 1 },
691 { HCBT_SETFOCUS, hook },
692 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
693 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
694 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
695 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
696 { WM_GETTEXT, sent|optional },
697 { WM_SYNCPAINT, sent|wparam|optional, 4 },
698 { WM_NCPAINT, sent|wparam|optional, 1 },
699 { WM_ERASEBKGND, sent|optional },
700 { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
701 { WM_ERASEBKGND, sent|defwinproc|optional },
702 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
703 { 0 }
704 };
705 /* CreateWindow(WS_MAXIMIZE) for popup window, not initially visible */
706 static const struct message WmCreateInvisibleMaxPopupSeq[] = {
707 { HCBT_CREATEWND, hook },
708 { WM_NCCREATE, sent },
709 { WM_NCCALCSIZE, sent|wparam, 0 },
710 { WM_CREATE, sent },
711 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
712 { WM_SIZE, sent|wparam, SIZE_RESTORED },
713 { WM_MOVE, sent },
714 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
715 { WM_GETMINMAXINFO, sent },
716 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED },
717 { WM_NCCALCSIZE, sent|wparam, TRUE },
718 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
719 { WM_MOVE, sent|defwinproc },
720 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
721 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
722 { 0 }
723 };
724 /* ShowWindow(SW_SHOWMAXIMIZED) for a resized not visible popup window */
725 static const struct message WmShowMaxPopupResizedSeq[] = {
726 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
727 { WM_GETMINMAXINFO, sent },
728 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
729 { WM_NCCALCSIZE, sent|wparam, TRUE },
730 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
731 { HCBT_ACTIVATE, hook },
732 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
733 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
734 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
735 { WM_NCPAINT, sent|wparam|optional, 1 },
736 { WM_ERASEBKGND, sent|optional },
737 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
738 { WM_ACTIVATEAPP, sent|wparam, 1 },
739 { WM_NCACTIVATE, sent },
740 { WM_ACTIVATE, sent|wparam, 1 },
741 { HCBT_SETFOCUS, hook },
742 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
743 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
744 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
745 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
746 { WM_GETTEXT, sent|optional },
747 { WM_NCPAINT, sent|wparam|optional, 1 },
748 { WM_ERASEBKGND, sent|optional },
749 { WM_WINDOWPOSCHANGED, sent },
750 /* WinNT4.0 sends WM_MOVE */
751 { WM_MOVE, sent|defwinproc|optional },
752 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
753 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
754 { 0 }
755 };
756 /* ShowWindow(SW_SHOWMAXIMIZED) for a not visible popup window */
757 static const struct message WmShowMaxPopupSeq[] = {
758 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
759 { WM_GETMINMAXINFO, sent },
760 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
761 { WM_NCCALCSIZE, sent|wparam, TRUE },
762 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
763 { HCBT_ACTIVATE, hook },
764 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
765 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
766 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
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_SYNCPAINT, sent|wparam|optional, 4 },
777 { WM_NCPAINT, sent|wparam|optional, 1 },
778 { WM_ERASEBKGND, sent|optional },
779 { WM_NCPAINT, sent|wparam|defwinproc|optional, 1 },
780 { WM_ERASEBKGND, sent|defwinproc|optional },
781 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE },
782 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
783 { 0 }
784 };
785 /* CreateWindow(WS_VISIBLE) for popup window */
786 static const struct message WmCreatePopupSeq[] = {
787 { HCBT_CREATEWND, hook },
788 { WM_NCCREATE, sent },
789 { WM_NCCALCSIZE, sent|wparam, 0 },
790 { WM_CREATE, sent },
791 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
792 { WM_SIZE, sent|wparam, SIZE_RESTORED },
793 { WM_MOVE, sent },
794 { WM_SHOWWINDOW, sent|wparam, 1 },
795 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
796 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
797 { HCBT_ACTIVATE, hook },
798 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
799 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
800 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
801 { WM_NCPAINT, sent|wparam|optional, 1 },
802 { WM_ERASEBKGND, sent|optional },
803 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
804 { WM_ACTIVATEAPP, sent|wparam, 1 },
805 { WM_NCACTIVATE, sent },
806 { WM_ACTIVATE, sent|wparam, 1 },
807 { HCBT_SETFOCUS, hook },
808 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
809 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
810 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
811 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
812 { WM_GETTEXT, sent|optional },
813 { WM_SYNCPAINT, sent|wparam|optional, 4 },
814 { WM_NCPAINT, sent|wparam|optional, 1 },
815 { WM_ERASEBKGND, sent|optional },
816 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE },
817 { 0 }
818 };
819 /* ShowWindow(SW_SHOWMAXIMIZED) for a visible popup window */
820 static const struct message WmShowVisMaxPopupSeq[] = {
821 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
822 { WM_GETMINMAXINFO, sent },
823 { WM_GETTEXT, sent|optional },
824 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
825 { WM_GETTEXT, sent|optional },
826 { WM_NCCALCSIZE, sent|wparam, TRUE },
827 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
828 { WM_NCPAINT, sent|wparam|optional, 1 },
829 { WM_ERASEBKGND, sent|optional },
830 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
831 { WM_MOVE, sent|defwinproc },
832 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
833 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
834 { 0 }
835 };
836 /* CreateWindow (for a child popup window, not initially visible) */
837 static const struct message WmCreateChildPopupSeq[] = {
838 { HCBT_CREATEWND, hook },
839 { WM_NCCREATE, sent },
840 { WM_NCCALCSIZE, sent|wparam, 0 },
841 { WM_CREATE, sent },
842 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
843 { WM_SIZE, sent|wparam, SIZE_RESTORED },
844 { WM_MOVE, sent },
845 { 0 }
846 };
847 /* CreateWindow (for a popup window, not initially visible,
848 * which sets WS_VISIBLE in WM_CREATE handler)
849 */
850 static const struct message WmCreateInvisiblePopupSeq[] = {
851 { HCBT_CREATEWND, hook },
852 { WM_NCCREATE, sent },
853 { WM_NCCALCSIZE, sent|wparam, 0 },
854 { WM_CREATE, sent },
855 { WM_STYLECHANGING, sent },
856 { WM_STYLECHANGED, sent },
857 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
858 { WM_SIZE, sent|wparam, SIZE_RESTORED },
859 { WM_MOVE, sent },
860 { 0 }
861 };
862 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER)
863 * for a popup window with WS_VISIBLE style set
864 */
865 static const struct message WmShowVisiblePopupSeq_2[] = {
866 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
867 { 0 }
868 };
869 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
870 * for a popup window with WS_VISIBLE style set
871 */
872 static const struct message WmShowVisiblePopupSeq_3[] = {
873 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
874 { HCBT_ACTIVATE, hook },
875 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
876 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
877 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
878 { WM_NCACTIVATE, sent },
879 { WM_ACTIVATE, sent|wparam, 1 },
880 { HCBT_SETFOCUS, hook },
881 { WM_KILLFOCUS, sent|parent },
882 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
883 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
884 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
885 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
886 { WM_SETFOCUS, sent|defwinproc },
887 { WM_GETTEXT, sent|optional },
888 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_SHOWWINDOW },
889 { 0 }
890 };
891 /* CreateWindow (for child window, not initially visible) */
892 static const struct message WmCreateChildSeq[] = {
893 { HCBT_CREATEWND, hook },
894 { WM_NCCREATE, sent },
895 /* child is inserted into parent's child list after WM_NCCREATE returns */
896 { WM_NCCALCSIZE, sent|wparam, 0 },
897 { WM_CREATE, sent },
898 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
899 { WM_SIZE, sent|wparam, SIZE_RESTORED },
900 { WM_MOVE, sent },
901 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
902 { 0 }
903 };
904 /* CreateWindow (for maximized child window, not initially visible) */
905 static const struct message WmCreateMaximizedChildSeq[] = {
906 { HCBT_CREATEWND, hook },
907 { WM_NCCREATE, sent },
908 { WM_NCCALCSIZE, sent|wparam, 0 },
909 { WM_CREATE, sent },
910 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
911 { WM_SIZE, sent|wparam, SIZE_RESTORED },
912 { WM_MOVE, sent },
913 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
914 { WM_GETMINMAXINFO, sent },
915 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
916 { WM_NCCALCSIZE, sent|wparam, 1 },
917 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
918 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
919 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
920 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
921 { 0 }
922 };
923 /* CreateWindow (for a child window, initially visible) */
924 static const struct message WmCreateVisibleChildSeq[] = {
925 { HCBT_CREATEWND, hook },
926 { WM_NCCREATE, sent },
927 /* child is inserted into parent's child list after WM_NCCREATE returns */
928 { WM_NCCALCSIZE, sent|wparam, 0 },
929 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
930 { WM_CREATE, sent },
931 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
932 { WM_SIZE, sent|wparam, SIZE_RESTORED },
933 { WM_MOVE, sent },
934 { WM_PARENTNOTIFY, sent|parent|wparam, WM_CREATE },
935 { WM_SHOWWINDOW, sent|wparam, 1 },
936 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
937 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
938 { WM_ERASEBKGND, sent|parent|optional },
939 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
940 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* WinXP */
941 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
942 { 0 }
943 };
944 /* ShowWindow(SW_SHOW) for a not visible child window */
945 static const struct message WmShowChildSeq[] = {
946 { WM_SHOWWINDOW, sent|wparam, 1 },
947 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
948 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
949 { WM_ERASEBKGND, sent|parent|optional },
950 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
951 { 0 }
952 };
953 /* ShowWindow(SW_HIDE) for a visible child window */
954 static const struct message WmHideChildSeq[] = {
955 { WM_SHOWWINDOW, sent|wparam, 0 },
956 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
957 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
958 { WM_ERASEBKGND, sent|parent|optional },
959 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
960 { 0 }
961 };
962 /* ShowWindow(SW_HIDE) for a visible child window checking all parent events*/
963 static const struct message WmHideChildSeq2[] = {
964 { WM_SHOWWINDOW, sent|wparam, 0 },
965 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
966 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
967 { WM_ERASEBKGND, sent|parent|optional },
968 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
969 { 0 }
970 };
971 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
972 * for a not visible child window
973 */
974 static const struct message WmShowChildSeq_2[] = {
975 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
976 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
977 { WM_CHILDACTIVATE, sent },
978 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
979 { 0 }
980 };
981 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE)
982 * for a not visible child window
983 */
984 static const struct message WmShowChildSeq_3[] = {
985 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
986 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
987 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
988 { 0 }
989 };
990 /* SetWindowPos(SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE)
991 * for a visible child window with a caption
992 */
993 static const struct message WmShowChildSeq_4[] = {
994 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
995 { WM_CHILDACTIVATE, sent },
996 { 0 }
997 };
998 /* ShowWindow(SW_MINIMIZE) for child with invisible parent */
999 static const struct message WmShowChildInvisibleParentSeq_1[] = {
1000 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
1001 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
1002 { WM_NCCALCSIZE, sent|wparam, 1 },
1003 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1004 { WM_CHILDACTIVATE, sent|optional },
1005 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED, 0, SWP_NOACTIVATE },
1006 { WM_MOVE, sent|defwinproc },
1007 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1008 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1009 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1010 /* FIXME: Wine creates an icon/title window while Windows doesn't */
1011 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1012 { WM_GETTEXT, sent|optional },
1013 { 0 }
1014 };
1015 /* repeated ShowWindow(SW_MINIMIZE) for child with invisible parent */
1016 static const struct message WmShowChildInvisibleParentSeq_1r[] = {
1017 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
1018 { 0 }
1019 };
1020 /* ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1021 static const struct message WmShowChildInvisibleParentSeq_2[] = {
1022 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1023 { WM_GETMINMAXINFO, sent },
1024 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
1025 { WM_NCCALCSIZE, sent|wparam, 1 },
1026 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1027 { WM_CHILDACTIVATE, sent },
1028 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
1029 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
1030 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1031 { 0 }
1032 };
1033 /* repeated ShowWindow(SW_MAXIMIZE) for child with invisible parent */
1034 static const struct message WmShowChildInvisibleParentSeq_2r[] = {
1035 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
1036 { 0 }
1037 };
1038 /* ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1039 static const struct message WmShowChildInvisibleParentSeq_3[] = {
1040 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1041 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
1042 { WM_NCCALCSIZE, sent|wparam, 1 },
1043 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1044 { WM_CHILDACTIVATE, sent },
1045 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1046 { WM_MOVE, sent|defwinproc },
1047 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1048 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1049 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1050 /* FIXME: Wine creates an icon/title window while Windows doesn't */
1051 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1052 { WM_GETTEXT, sent|optional },
1053 { 0 }
1054 };
1055 /* repeated ShowWindow(SW_SHOWMINIMIZED) for child with invisible parent */
1056 static const struct message WmShowChildInvisibleParentSeq_3r[] = {
1057 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
1058 { 0 }
1059 };
1060 /* ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1061 static const struct message WmShowChildInvisibleParentSeq_4[] = {
1062 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1063 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
1064 { WM_NCCALCSIZE, sent|wparam, 1 },
1065 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1066 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCOPYBITS|SWP_STATECHANGED },
1067 { WM_MOVE, sent|defwinproc },
1068 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
1069 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1070 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 },
1071 /* FIXME: Wine creates an icon/title window while Windows doesn't */
1072 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE },
1073 { WM_GETTEXT, sent|optional },
1074 { 0 }
1075 };
1076 /* repeated ShowWindow(SW_SHOWMINNOACTIVE) for child with invisible parent */
1077 static const struct message WmShowChildInvisibleParentSeq_4r[] = {
1078 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
1079 { 0 }
1080 };
1081 /* ShowWindow(SW_SHOW) for child with invisible parent */
1082 static const struct message WmShowChildInvisibleParentSeq_5[] = {
1083 { WM_SHOWWINDOW, sent|wparam, 1 },
1084 { 0 }
1085 };
1086 /* ShowWindow(SW_HIDE) for child with invisible parent */
1087 static const struct message WmHideChildInvisibleParentSeq[] = {
1088 { WM_SHOWWINDOW, sent|wparam, 0 },
1089 { 0 }
1090 };
1091 /* SetWindowPos(SWP_SHOWWINDOW) for child with invisible parent */
1092 static const struct message WmShowChildInvisibleParentSeq_6[] = {
1093 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1094 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1095 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1096 { 0 }
1097 };
1098 /* SetWindowPos(SWP_HIDEWINDOW) for child with invisible parent */
1099 static const struct message WmHideChildInvisibleParentSeq_2[] = {
1100 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1101 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1102 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1103 { 0 }
1104 };
1105 /* DestroyWindow for a visible child window */
1106 static const struct message WmDestroyChildSeq[] = {
1107 { HCBT_DESTROYWND, hook },
1108 { 0x0090, sent|optional },
1109 { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1110 { WM_SHOWWINDOW, sent|wparam, 0 },
1111 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1112 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1113 { WM_ERASEBKGND, sent|parent|optional },
1114 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1115 { HCBT_SETFOCUS, hook }, /* set focus to a parent */
1116 { WM_KILLFOCUS, sent },
1117 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1118 { WM_IME_SETCONTEXT, sent|wparam|parent|optional, 1 },
1119 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1120 { WM_SETFOCUS, sent|parent },
1121 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1122 { WM_DESTROY, sent },
1123 { WM_DESTROY, sent|optional }, /* some other (IME?) window */
1124 { WM_NCDESTROY, sent|optional }, /* some other (IME?) window */
1125 { WM_NCDESTROY, sent },
1126 { 0 }
1127 };
1128 /* visible child window destroyed by thread exit */
1129 static const struct message WmExitThreadSeq[] = {
1130 { WM_NCDESTROY, sent }, /* actually in grandchild */
1131 { WM_PAINT, sent|parent },
1132 { WM_ERASEBKGND, sent|parent|beginpaint },
1133 { 0 }
1134 };
1135 /* DestroyWindow for a visible child window with invisible parent */
1136 static const struct message WmDestroyInvisibleChildSeq[] = {
1137 { HCBT_DESTROYWND, hook },
1138 { 0x0090, sent|optional },
1139 { WM_PARENTNOTIFY, sent|parent|wparam, WM_DESTROY },
1140 { WM_SHOWWINDOW, sent|wparam, 0 },
1141 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1142 { WM_DESTROY, sent },
1143 { WM_NCDESTROY, sent },
1144 { 0 }
1145 };
1146 /* Moving the mouse in nonclient area */
1147 static const struct message WmMouseMoveInNonClientAreaSeq[] = { /* FIXME: add */
1148 { WM_NCHITTEST, sent },
1149 { WM_SETCURSOR, sent },
1150 { WM_NCMOUSEMOVE, posted },
1151 { 0 }
1152 };
1153 /* Moving the mouse in client area */
1154 static const struct message WmMouseMoveInClientAreaSeq[] = { /* FIXME: add */
1155 { WM_NCHITTEST, sent },
1156 { WM_SETCURSOR, sent },
1157 { WM_MOUSEMOVE, posted },
1158 { 0 }
1159 };
1160 /* Moving by dragging the title bar (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1161 static const struct message WmDragTitleBarSeq[] = { /* FIXME: add */
1162 { WM_NCLBUTTONDOWN, sent|wparam, HTCAPTION },
1163 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_MOVE+2 },
1164 { WM_GETMINMAXINFO, sent|defwinproc },
1165 { WM_ENTERSIZEMOVE, sent|defwinproc },
1166 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1167 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1168 { WM_MOVE, sent|defwinproc },
1169 { WM_EXITSIZEMOVE, sent|defwinproc },
1170 { 0 }
1171 };
1172 /* Sizing by dragging the thick borders (after WM_NCHITTEST and WM_SETCURSOR) (outline move) */
1173 static const struct message WmDragThickBordersBarSeq[] = { /* FIXME: add */
1174 { WM_NCLBUTTONDOWN, sent|wparam, 0xd },
1175 { WM_SYSCOMMAND, sent|defwinproc|wparam, 0xf004 },
1176 { WM_GETMINMAXINFO, sent|defwinproc },
1177 { WM_ENTERSIZEMOVE, sent|defwinproc },
1178 { WM_SIZING, sent|defwinproc|wparam, 4}, /* one for each mouse movement */
1179 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, 0 },
1180 { WM_GETMINMAXINFO, sent|defwinproc },
1181 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
1182 { WM_NCPAINT, sent|defwinproc|wparam, 1 },
1183 { WM_GETTEXT, sent|defwinproc },
1184 { WM_ERASEBKGND, sent|defwinproc },
1185 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, 0 },
1186 { WM_MOVE, sent|defwinproc },
1187 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1188 { WM_EXITSIZEMOVE, sent|defwinproc },
1189 { 0 }
1190 };
1191 /* Resizing child window with MoveWindow (32) */
1192 static const struct message WmResizingChildWithMoveWindowSeq[] = {
1193 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
1194 { WM_NCCALCSIZE, sent|wparam, 1 },
1195 { WM_ERASEBKGND, sent|parent|optional },
1196 { WM_ERASEBKGND, sent|optional },
1197 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE },
1198 { WM_MOVE, sent|defwinproc },
1199 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1200 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1201 { 0 }
1202 };
1203 /* Clicking on inactive button */
1204 static const struct message WmClickInactiveButtonSeq[] = { /* FIXME: add */
1205 { WM_NCHITTEST, sent },
1206 { WM_PARENTNOTIFY, sent|parent|wparam, WM_LBUTTONDOWN },
1207 { WM_MOUSEACTIVATE, sent },
1208 { WM_MOUSEACTIVATE, sent|parent|defwinproc },
1209 { WM_SETCURSOR, sent },
1210 { WM_SETCURSOR, sent|parent|defwinproc },
1211 { WM_LBUTTONDOWN, posted },
1212 { WM_KILLFOCUS, posted|parent },
1213 { WM_SETFOCUS, posted },
1214 { WM_CTLCOLORBTN, posted|parent },
1215 { BM_SETSTATE, posted },
1216 { WM_CTLCOLORBTN, posted|parent },
1217 { WM_LBUTTONUP, posted },
1218 { BM_SETSTATE, posted },
1219 { WM_CTLCOLORBTN, posted|parent },
1220 { WM_COMMAND, posted|parent },
1221 { 0 }
1222 };
1223 /* Reparenting a button (16/32) */
1224 /* The last child (button) reparented gets topmost for its new parent. */
1225 static const struct message WmReparentButtonSeq[] = { /* FIXME: add */
1226 { WM_SHOWWINDOW, sent|wparam, 0 },
1227 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1228 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1229 { WM_ERASEBKGND, sent|parent },
1230 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1231 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE },
1232 { WM_CHILDACTIVATE, sent },
1233 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOREDRAW },
1234 { WM_MOVE, sent|defwinproc },
1235 { WM_SHOWWINDOW, sent|wparam, 1 },
1236 { 0 }
1237 };
1238 /* Creation of a custom dialog (32) */
1239 static const struct message WmCreateCustomDialogSeq[] = {
1240 { HCBT_CREATEWND, hook },
1241 { WM_GETMINMAXINFO, sent },
1242 { WM_NCCREATE, sent },
1243 { WM_NCCALCSIZE, sent|wparam, 0 },
1244 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1245 { WM_CREATE, sent },
1246 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1247 { WM_NOTIFYFORMAT, sent|optional },
1248 { WM_QUERYUISTATE, sent|optional },
1249 { WM_WINDOWPOSCHANGING, sent|optional },
1250 { WM_GETMINMAXINFO, sent|optional },
1251 { WM_NCCALCSIZE, sent|optional },
1252 { WM_WINDOWPOSCHANGED, sent|optional },
1253 { WM_SHOWWINDOW, sent|wparam, 1 },
1254 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1255 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1256 { HCBT_ACTIVATE, hook },
1257 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1258
1259
1260 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1261
1262 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1263
1264 { WM_NCACTIVATE, sent },
1265 { WM_GETTEXT, sent|optional|defwinproc },
1266 { WM_GETTEXT, sent|optional|defwinproc },
1267 { WM_GETTEXT, sent|optional|defwinproc },
1268 { EVENT_OBJECT_DEFACTIONCHANGE, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
1269 { WM_ACTIVATE, sent|wparam, 1 },
1270 { WM_GETTEXT, sent|optional },
1271 { WM_KILLFOCUS, sent|parent },
1272 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1273 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1274 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1275 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1276 { WM_SETFOCUS, sent },
1277 { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1278 { WM_NCPAINT, sent|wparam, 1 },
1279 { WM_GETTEXT, sent|optional|defwinproc },
1280 { WM_GETTEXT, sent|optional|defwinproc },
1281 { WM_ERASEBKGND, sent },
1282 { WM_CTLCOLORDLG, sent|optional|defwinproc },
1283 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1284 { WM_GETTEXT, sent|optional },
1285 { WM_GETTEXT, sent|optional },
1286 { WM_NCCALCSIZE, sent|optional },
1287 { WM_NCPAINT, sent|optional },
1288 { WM_GETTEXT, sent|optional|defwinproc },
1289 { WM_GETTEXT, sent|optional|defwinproc },
1290 { WM_ERASEBKGND, sent|optional },
1291 { WM_CTLCOLORDLG, sent|optional|defwinproc },
1292 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1293 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1294 { WM_MOVE, sent },
1295 { 0 }
1296 };
1297 /* Calling EndDialog for a custom dialog (32) */
1298 static const struct message WmEndCustomDialogSeq[] = {
1299 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1300 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1301 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1302 { WM_GETTEXT, sent|optional },
1303 { HCBT_ACTIVATE, hook },
1304 { WM_NCACTIVATE, sent|wparam, 0 },
1305 { WM_GETTEXT, sent|optional|defwinproc },
1306 { WM_GETTEXT, sent|optional|defwinproc },
1307 { WM_ACTIVATE, sent|wparam, 0 },
1308 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1309 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1310 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOREDRAW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1311 { WM_GETTEXT, sent|optional|defwinproc },
1312 { WM_GETTEXT, sent|optional|defwinproc },
1313 { HCBT_SETFOCUS, hook },
1314 { WM_KILLFOCUS, sent },
1315 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
1316 { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1317 { WM_IME_NOTIFY, sent|wparam|optional, 1 },
1318 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1319 { WM_SETFOCUS, sent|parent|defwinproc },
1320 { 0 }
1321 };
1322 /* ShowWindow(SW_SHOW) for a custom dialog (initially invisible) */
1323 static const struct message WmShowCustomDialogSeq[] = {
1324 { WM_SHOWWINDOW, sent|wparam, 1 },
1325 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
1326 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1327 { HCBT_ACTIVATE, hook },
1328 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1329
1330 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1331
1332 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
1333 { WM_ACTIVATEAPP, sent|wparam|optional, 1 },
1334 { WM_NCACTIVATE, sent },
1335 { WM_ACTIVATE, sent|wparam, 1 },
1336 { WM_GETTEXT, sent|optional },
1337
1338 { WM_KILLFOCUS, sent|parent },
1339 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1340 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
1341 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
1342 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1343 { WM_SETFOCUS, sent },
1344 { WM_GETDLGCODE, sent|defwinproc|wparam, 0 },
1345 { WM_NCPAINT, sent|wparam, 1 },
1346 { WM_ERASEBKGND, sent },
1347 { WM_CTLCOLORDLG, sent|defwinproc },
1348 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1349 { 0 }
1350 };
1351 /* Creation and destruction of a modal dialog (32) */
1352 static const struct message WmModalDialogSeq[] = {
1353 { WM_CANCELMODE, sent|parent },
1354 { HCBT_SETFOCUS, hook },
1355 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1356 { WM_KILLFOCUS, sent|parent },
1357 { WM_IME_SETCONTEXT, sent|parent|wparam|optional, 0 },
1358 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1359 { WM_ENABLE, sent|parent|wparam, 0 },
1360 { HCBT_CREATEWND, hook },
1361 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1362 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
1363 { WM_SETFONT, sent },
1364 { WM_INITDIALOG, sent },
1365 { WM_CHANGEUISTATE, sent|optional },
1366 { WM_UPDATEUISTATE, sent|optional },
1367 { WM_SHOWWINDOW, sent },
1368 { HCBT_ACTIVATE, hook },
1369 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1370 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
1371 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
1372 { WM_NCACTIVATE, sent },
1373 { WM_GETTEXT, sent|optional },
1374 { WM_ACTIVATE, sent|wparam, 1 },
1375 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1376 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1377 { WM_NCPAINT, sent|optional },
1378 { WM_GETTEXT, sent|optional },
1379 { WM_ERASEBKGND, sent|optional },
1380 { WM_CTLCOLORDLG, sent|optional },
1381 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1382 { WM_GETTEXT, sent|optional },
1383 { WM_NCCALCSIZE, sent|optional },
1384 { WM_NCPAINT, sent|optional },
1385 { WM_GETTEXT, sent|optional },
1386 { WM_ERASEBKGND, sent|optional },
1387 { WM_CTLCOLORDLG, sent|optional },
1388 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1389 { WM_PAINT, sent|optional },
1390 { WM_CTLCOLORBTN, sent|optional },
1391 { WM_GETTITLEBARINFOEX, sent|optional },
1392 { WM_ENTERIDLE, sent|parent|optional },
1393 { WM_ENTERIDLE, sent|parent|optional },
1394 { WM_ENTERIDLE, sent|parent|optional },
1395 { WM_ENTERIDLE, sent|parent|optional },
1396 { WM_ENTERIDLE, sent|parent|optional },
1397 { WM_ENTERIDLE, sent|parent|optional },
1398 { WM_ENTERIDLE, sent|parent|optional },
1399 { WM_ENTERIDLE, sent|parent|optional },
1400 { WM_ENTERIDLE, sent|parent|optional },
1401 { WM_ENTERIDLE, sent|parent|optional },
1402 { WM_ENTERIDLE, sent|parent|optional },
1403 { WM_ENTERIDLE, sent|parent|optional },
1404 { WM_ENTERIDLE, sent|parent|optional },
1405 { WM_ENTERIDLE, sent|parent|optional },
1406 { WM_ENTERIDLE, sent|parent|optional },
1407 { WM_ENTERIDLE, sent|parent|optional },
1408 { WM_ENTERIDLE, sent|parent|optional },
1409 { WM_ENTERIDLE, sent|parent|optional },
1410 { WM_ENTERIDLE, sent|parent|optional },
1411 { WM_ENTERIDLE, sent|parent|optional },
1412 { WM_TIMER, sent },
1413 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1414 { WM_ENABLE, sent|parent|wparam, 1 },
1415 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1416 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
1417 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1418 { WM_GETTEXT, sent|optional },
1419 { HCBT_ACTIVATE, hook },
1420 { WM_NCACTIVATE, sent|wparam, 0 },
1421 { WM_GETTEXT, sent|optional },
1422 { WM_ACTIVATE, sent|wparam, 0 },
1423 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
1424 { WM_WINDOWPOSCHANGING, sent|optional },
1425 { WM_WINDOWPOSCHANGED, sent|optional },
1426 { HCBT_SETFOCUS, hook },
1427 { WM_IME_SETCONTEXT, sent|parent|wparam|defwinproc|optional, 1 },
1428 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
1429 { WM_SETFOCUS, sent|parent|defwinproc },
1430 { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, 0, 0 },
1431 { HCBT_DESTROYWND, hook },
1432 { 0x0090, sent|optional },
1433 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
1434 { WM_DESTROY, sent },
1435 { WM_NCDESTROY, sent },
1436 { 0 }
1437 };
1438 /* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */
1439 static const struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */
1440 /* (inside dialog proc, handling WM_INITDIALOG) */
1441 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1442 { WM_NCCALCSIZE, sent },
1443 { WM_NCACTIVATE, sent|parent|wparam, 0 },
1444 { WM_GETTEXT, sent|defwinproc },
1445 { WM_ACTIVATE, sent|parent|wparam, 0 },
1446 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1447 { WM_WINDOWPOSCHANGING, sent|parent },
1448 { WM_NCACTIVATE, sent|wparam, 1 },
1449 { WM_ACTIVATE, sent|wparam, 1 },
1450 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1451 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1452 /* (setting focus) */
1453 { WM_SHOWWINDOW, sent|wparam, 1 },
1454 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
1455 { WM_NCPAINT, sent },
1456 { WM_GETTEXT, sent|defwinproc },
1457 { WM_ERASEBKGND, sent },
1458 { WM_CTLCOLORDLG, sent|defwinproc },
1459 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
1460 { WM_PAINT, sent },
1461 /* (bunch of WM_CTLCOLOR* for each control) */
1462 { WM_PAINT, sent|parent },
1463 { WM_ENTERIDLE, sent|parent|wparam, 0 },
1464 { WM_SETCURSOR, sent|parent },
1465 { 0 }
1466 };
1467 /* SetMenu for NonVisible windows with size change*/
1468 static const struct message WmSetMenuNonVisibleSizeChangeSeq[] = {
1469 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1470 { WM_NCCALCSIZE, sent|wparam, 1 },
1471 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1472 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
1473 { WM_MOVE, sent|defwinproc },
1474 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1475 { WM_NCCALCSIZE,sent|wparam|optional, 1 }, /* XP */
1476 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1477 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1478 { WM_GETTEXT, sent|optional },
1479 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1480 { 0 }
1481 };
1482 /* SetMenu for NonVisible windows with no size change */
1483 static const struct message WmSetMenuNonVisibleNoSizeChangeSeq[] = {
1484 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1485 { WM_NCCALCSIZE, sent|wparam, 1 },
1486 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1487 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1488 { 0 }
1489 };
1490 /* SetMenu for Visible windows with size change */
1491 static const struct message WmSetMenuVisibleSizeChangeSeq[] = {
1492 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1493 { WM_NCCALCSIZE, sent|wparam, 1 },
1494 { 0x0093, sent|defwinproc|optional },
1495 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1496 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1497 { 0x0093, sent|defwinproc|optional },
1498 { 0x0093, sent|defwinproc|optional },
1499 { 0x0091, sent|defwinproc|optional },
1500 { 0x0092, sent|defwinproc|optional },
1501 { WM_GETTEXT, sent|defwinproc|optional },
1502 { WM_ERASEBKGND, sent|optional },
1503 { WM_ACTIVATE, sent|optional },
1504 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1505 { WM_MOVE, sent|defwinproc },
1506 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
1507 { 0x0093, sent|optional },
1508 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1509 { 0x0093, sent|defwinproc|optional },
1510 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1511 { 0x0093, sent|defwinproc|optional },
1512 { 0x0093, sent|defwinproc|optional },
1513 { 0x0091, sent|defwinproc|optional },
1514 { 0x0092, sent|defwinproc|optional },
1515 { WM_ERASEBKGND, sent|optional },
1516 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1517 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP sends a duplicate */
1518 { 0 }
1519 };
1520 /* SetMenu for Visible windows with no size change */
1521 static const struct message WmSetMenuVisibleNoSizeChangeSeq[] = {
1522 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1523 { WM_NCCALCSIZE, sent|wparam, 1 },
1524 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1525 { WM_GETTEXT, sent|defwinproc|optional },
1526 { WM_ERASEBKGND, sent|optional },
1527 { WM_ACTIVATE, sent|optional },
1528 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1529 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1530 { 0 }
1531 };
1532 /* DrawMenuBar for a visible window */
1533 static const struct message WmDrawMenuBarSeq[] =
1534 {
1535 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1536 { WM_NCCALCSIZE, sent|wparam, 1 },
1537 { 0x0093, sent|defwinproc|optional },
1538 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
1539 { 0x0093, sent|defwinproc|optional },
1540 { 0x0093, sent|defwinproc|optional },
1541 { 0x0091, sent|defwinproc|optional },
1542 { 0x0092, sent|defwinproc|optional },
1543 { WM_GETTEXT, sent|defwinproc|optional },
1544 { WM_ERASEBKGND, sent|optional },
1545 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1546 { 0x0093, sent|optional },
1547 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1548 { 0 }
1549 };
1550
1551 static const struct message WmSetRedrawFalseSeq[] =
1552 {
1553 { WM_SETREDRAW, sent|wparam, 0 },
1554 { 0 }
1555 };
1556
1557 static const struct message WmSetRedrawTrueSeq[] =
1558 {
1559 { WM_SETREDRAW, sent|wparam, 1 },
1560 { 0 }
1561 };
1562
1563 static const struct message WmEnableWindowSeq_1[] =
1564 {
1565 { WM_CANCELMODE, sent|wparam|lparam, 0, 0 },
1566 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1567 { HCBT_SETFOCUS, hook|optional },
1568 { WM_KILLFOCUS, sent|optional },
1569 { WM_ENABLE, sent|wparam|lparam, FALSE, 0 },
1570 { 0 }
1571 };
1572
1573 static const struct message WmEnableWindowSeq_2[] =
1574 {
1575 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, 0, 0 },
1576 { WM_ENABLE, sent|wparam|lparam, TRUE, 0 },
1577 { 0 }
1578 };
1579
1580 static const struct message WmGetScrollRangeSeq[] =
1581 {
1582 { SBM_GETRANGE, sent },
1583 { 0 }
1584 };
1585 static const struct message WmGetScrollInfoSeq[] =
1586 {
1587 { SBM_GETSCROLLINFO, sent },
1588 { 0 }
1589 };
1590 static const struct message WmSetScrollRangeSeq[] =
1591 {
1592 /* MSDN claims that Windows sends SBM_SETRANGE message, but win2k SP4
1593 sends SBM_SETSCROLLINFO.
1594 */
1595 { SBM_SETSCROLLINFO, sent },
1596 { 0 }
1597 };
1598 /* SetScrollRange for a window without a non-client area */
1599 static const struct message WmSetScrollRangeHSeq_empty[] =
1600 {
1601 { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_HSCROLL, 0 },
1602 { 0 }
1603 };
1604 static const struct message WmSetScrollRangeVSeq_empty[] =
1605 {
1606 { EVENT_OBJECT_VALUECHANGE, winevent_hook|wparam|lparam, OBJID_VSCROLL, 0 },
1607 { 0 }
1608 };
1609 static const struct message WmSetScrollRangeHVSeq[] =
1610 {
1611 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1612 { WM_NCCALCSIZE, sent|wparam, 1 },
1613 { WM_GETTEXT, sent|defwinproc|optional },
1614 { WM_ERASEBKGND, sent|optional },
1615 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1616 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1617 { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1618 { 0 }
1619 };
1620 /* SetScrollRange for a window with a non-client area */
1621 static const struct message WmSetScrollRangeHV_NC_Seq[] =
1622 {
1623 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE },
1624 { WM_NCCALCSIZE, sent|wparam, 1 },
1625 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
1626 { WM_NCPAINT, sent|optional },
1627 { WM_STYLECHANGING, sent|defwinproc|optional },
1628 { WM_STYLECHANGED, sent|defwinproc|optional },
1629 { WM_STYLECHANGING, sent|defwinproc|optional },
1630 { WM_STYLECHANGED, sent|defwinproc|optional },
1631 { WM_STYLECHANGING, sent|defwinproc|optional },
1632 { WM_STYLECHANGED, sent|defwinproc|optional },
1633 { WM_STYLECHANGING, sent|defwinproc|optional },
1634 { WM_STYLECHANGED, sent|defwinproc|optional },
1635 { WM_GETTEXT, sent|defwinproc|optional },
1636 { WM_GETTEXT, sent|defwinproc|optional },
1637 { WM_ERASEBKGND, sent|optional },
1638 { WM_CTLCOLORDLG, sent|defwinproc|optional }, /* sent to a parent of the dialog */
1639 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOCLIENTSIZE },
1640 { WM_SIZE, sent|defwinproc|optional },
1641 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1642 { EVENT_OBJECT_VALUECHANGE, winevent_hook|lparam|optional, 0/*OBJID_HSCROLL or OBJID_VSCROLL*/, 0 },
1643 { WM_GETTEXT, sent|optional },
1644 { WM_GETTEXT, sent|optional },
1645 { WM_GETTEXT, sent|optional },
1646 { WM_GETTEXT, sent|optional },
1647 { 0 }
1648 };
1649 /* test if we receive the right sequence of messages */
1650 /* after calling ShowWindow( SW_SHOWNA) */
1651 static const struct message WmSHOWNAChildInvisParInvis[] = {
1652 { WM_SHOWWINDOW, sent|wparam, 1 },
1653 { 0 }
1654 };
1655 static const struct message WmSHOWNAChildVisParInvis[] = {
1656 { WM_SHOWWINDOW, sent|wparam, 1 },
1657 { 0 }
1658 };
1659 static const struct message WmSHOWNAChildVisParVis[] = {
1660 { WM_SHOWWINDOW, sent|wparam, 1 },
1661 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1662 { 0 }
1663 };
1664 static const struct message WmSHOWNAChildInvisParVis[] = {
1665 { WM_SHOWWINDOW, sent|wparam, 1 },
1666 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1667 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1668 { WM_ERASEBKGND, sent|optional },
1669 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOACTIVATE|SWP_NOCLIENTMOVE },
1670 { 0 }
1671 };
1672 static const struct message WmSHOWNATopVisible[] = {
1673 { WM_SHOWWINDOW, sent|wparam, 1 },
1674 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
1675 { WM_NCPAINT, sent|wparam|optional, 1 },
1676 { WM_GETTEXT, sent|defwinproc|optional },
1677 { WM_ERASEBKGND, sent|optional },
1678 { WM_WINDOWPOSCHANGED, sent|optional },
1679 { 0 }
1680 };
1681 static const struct message WmSHOWNATopInvisible[] = {
1682 { WM_NOTIFYFORMAT, sent|optional },
1683 { WM_QUERYUISTATE, sent|optional },
1684 { WM_WINDOWPOSCHANGING, sent|optional },
1685 { WM_GETMINMAXINFO, sent|optional },
1686 { WM_NCCALCSIZE, sent|optional },
1687 { WM_WINDOWPOSCHANGED, sent|optional },
1688 { WM_SHOWWINDOW, sent|wparam, 1 },
1689 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
1690 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
1691 { WM_NCPAINT, sent|wparam|optional, 1 },
1692 { WM_GETTEXT, sent|defwinproc|optional },
1693 { WM_ERASEBKGND, sent|optional },
1694 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
1695 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
1696 { WM_NCPAINT, sent|wparam|optional, 1 },
1697 { WM_ERASEBKGND, sent|optional },
1698 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
1699 { WM_SIZE, sent|wparam, SIZE_RESTORED },
1700 { WM_MOVE, sent },
1701 { 0 }
1702 };
1703
1704 static int after_end_dialog, test_def_id;
1705 static int sequence_cnt, sequence_size;
1706 static struct recvd_message* sequence;
1707 static int log_all_parent_messages;
1708 static int paint_loop_done;
1709
1710 /* user32 functions */
1711 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
1712 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
1713 static void (WINAPI *pNotifyWinEvent)(DWORD, HWND, LONG, LONG);
1714 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
1715 static HWINEVENTHOOK (WINAPI *pSetWinEventHook)(DWORD, DWORD, HMODULE, WINEVENTPROC, DWORD, DWORD, DWORD);
1716 static BOOL (WINAPI *pTrackMouseEvent)(TRACKMOUSEEVENT*);
1717 static BOOL (WINAPI *pUnhookWinEvent)(HWINEVENTHOOK);
1718 /* kernel32 functions */
1719 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
1720
1721 static void init_procs(void)
1722 {
1723 HMODULE user32 = GetModuleHandleA("user32.dll");
1724 HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
1725
1726 #define GET_PROC(dll, func) \
1727 p ## func = (void*)GetProcAddress(dll, #func); \
1728 if(!p ## func) { \
1729 trace("GetProcAddress(%s) failed\n", #func); \
1730 }
1731
1732 GET_PROC(user32, GetAncestor)
1733 GET_PROC(user32, GetMenuInfo)
1734 GET_PROC(user32, NotifyWinEvent)
1735 GET_PROC(user32, SetMenuInfo)
1736 GET_PROC(user32, SetWinEventHook)
1737 GET_PROC(user32, TrackMouseEvent)
1738 GET_PROC(user32, UnhookWinEvent)
1739
1740 GET_PROC(kernel32, GetCPInfoExA)
1741
1742 #undef GET_PROC
1743 }
1744
1745 static const char *get_winpos_flags(UINT flags)
1746 {
1747 static char buffer[300];
1748
1749 buffer[0] = 0;
1750 #define DUMP(flag) do { if (flags & flag) { strcat( buffer, "|" #flag ); flags &= ~flag; } } while(0)
1751 DUMP( SWP_SHOWWINDOW );
1752 DUMP( SWP_HIDEWINDOW );
1753 DUMP( SWP_NOACTIVATE );
1754 DUMP( SWP_FRAMECHANGED );
1755 DUMP( SWP_NOCOPYBITS );
1756 DUMP( SWP_NOOWNERZORDER );
1757 DUMP( SWP_NOSENDCHANGING );
1758 DUMP( SWP_DEFERERASE );
1759 DUMP( SWP_ASYNCWINDOWPOS );
1760 DUMP( SWP_NOZORDER );
1761 DUMP( SWP_NOREDRAW );
1762 DUMP( SWP_NOSIZE );
1763 DUMP( SWP_NOMOVE );
1764 DUMP( SWP_NOCLIENTSIZE );
1765 DUMP( SWP_NOCLIENTMOVE );
1766 if (flags) sprintf(buffer + strlen(buffer),"|0x%04x", flags);
1767 return buffer + 1;
1768 #undef DUMP
1769 }
1770
1771 static BOOL ignore_message( UINT message )
1772 {
1773 /* these are always ignored */
1774 return (message >= 0xc000 ||
1775 message == WM_GETICON ||
1776 message == WM_GETOBJECT ||
1777 message == WM_TIMECHANGE ||
1778 message == WM_DISPLAYCHANGE ||
1779 message == WM_DEVICECHANGE);
1780 }
1781
1782
1783 #define add_message(msg) add_message_(__LINE__,msg);
1784 static void add_message_(int line, const struct recvd_message *msg)
1785 {
1786 struct recvd_message *seq;
1787
1788 if (!sequence)
1789 {
1790 sequence_size = 10;
1791 sequence = HeapAlloc( GetProcessHeap(), 0, sequence_size * sizeof(*sequence) );
1792 }
1793 if (sequence_cnt == sequence_size)
1794 {
1795 sequence_size *= 2;
1796 sequence = HeapReAlloc( GetProcessHeap(), 0, sequence, sequence_size * sizeof(*sequence) );
1797 }
1798 assert(sequence);
1799
1800 seq = &sequence[sequence_cnt];
1801 seq->hwnd = msg->hwnd;
1802 seq->message = msg->message;
1803 seq->flags = msg->flags;
1804 seq->wParam = msg->wParam;
1805 seq->lParam = msg->lParam;
1806 seq->line = line;
1807 seq->descr = msg->descr;
1808 seq->output[0] = 0;
1809
1810 if (msg->descr)
1811 {
1812 if (msg->flags & hook)
1813 {
1814 static const char * const CBT_code_name[10] =
1815 {
1816 "HCBT_MOVESIZE",
1817 "HCBT_MINMAX",
1818 "HCBT_QS",
1819 "HCBT_CREATEWND",
1820 "HCBT_DESTROYWND",
1821 "HCBT_ACTIVATE",
1822 "HCBT_CLICKSKIPPED",
1823 "HCBT_KEYSKIPPED",
1824 "HCBT_SYSCOMMAND",
1825 "HCBT_SETFOCUS"
1826 };
1827 const char *code_name = (msg->message <= HCBT_SETFOCUS) ? CBT_code_name[msg->message] : "Unknown";
1828
1829 sprintf( seq->output, "%s: hook %d (%s) wp %08lx lp %08lx",
1830 msg->descr, msg->message, code_name, msg->wParam, msg->lParam );
1831 }
1832 else if (msg->flags & winevent_hook)
1833 {
1834 sprintf( seq->output, "%s: winevent %p %08x %08lx %08lx",
1835 msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1836 }
1837 else
1838 {
1839 switch (msg->message)
1840 {
1841 case WM_WINDOWPOSCHANGING:
1842 case WM_WINDOWPOSCHANGED:
1843 {
1844 WINDOWPOS *winpos = (WINDOWPOS *)msg->lParam;
1845
1846 sprintf( seq->output, "%s: %p WM_WINDOWPOS%s wp %08lx lp %08lx after %p x %d y %d cx %d cy %d flags %s",
1847 msg->descr, msg->hwnd,
1848 (msg->message == WM_WINDOWPOSCHANGING) ? "CHANGING" : "CHANGED",
1849 msg->wParam, msg->lParam, winpos->hwndInsertAfter,
1850 winpos->x, winpos->y, winpos->cx, winpos->cy,
1851 get_winpos_flags(winpos->flags) );
1852
1853 /* Log only documented flags, win2k uses 0x1000 and 0x2000
1854 * in the high word for internal purposes
1855 */
1856 seq->wParam = winpos->flags & 0xffff;
1857 /* We are not interested in the flags that don't match under XP and Win9x */
1858 seq->wParam &= ~SWP_NOZORDER;
1859 break;
1860 }
1861
1862 case WM_DRAWITEM:
1863 {
1864 DRAW_ITEM_STRUCT di;
1865 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)msg->lParam;
1866
1867 sprintf( seq->output, "%s: %p WM_DRAWITEM: type %x, ctl_id %x, item_id %x, action %x, state %x",
1868 msg->descr, msg->hwnd, dis->CtlType, dis->CtlID,
1869 dis->itemID, dis->itemAction, dis->itemState);
1870
1871 di.u.lp = 0;
1872 di.u.item.type = dis->CtlType;
1873 di.u.item.ctl_id = dis->CtlID;
1874 if (dis->CtlType == ODT_LISTBOX ||
1875 dis->CtlType == ODT_COMBOBOX ||
1876 dis->CtlType == ODT_MENU)
1877 di.u.item.item_id = dis->itemID;
1878 di.u.item.action = dis->itemAction;
1879 di.u.item.state = dis->itemState;
1880
1881 seq->lParam = di.u.lp;
1882 break;
1883 }
1884 default:
1885 if (msg->message >= 0xc000) return; /* ignore registered messages */
1886 sprintf( seq->output, "%s: %p %04x wp %08lx lp %08lx",
1887 msg->descr, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1888 }
1889 if (msg->flags & (sent|posted|parent|defwinproc|beginpaint))
1890 sprintf( seq->output + strlen(seq->output), " (flags %x)", msg->flags );
1891 }
1892 }
1893
1894 sequence_cnt++;
1895 }
1896
1897 /* try to make sure pending X events have been processed before continuing */
1898 static void flush_events(void)
1899 {
1900 MSG msg;
1901 int diff = 200;
1902 int min_timeout = 100;
1903 DWORD time = GetTickCount() + diff;
1904
1905 while (diff > 0)
1906 {
1907 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
1908 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
1909 diff = time - GetTickCount();
1910 }
1911 }
1912
1913 static void flush_sequence(void)
1914 {
1915 HeapFree(GetProcessHeap(), 0, sequence);
1916 sequence = 0;
1917 sequence_cnt = sequence_size = 0;
1918 }
1919
1920 static void dump_sequence(const struct message *expected, const char *context, const char *file, int line)
1921 {
1922 const struct recvd_message *actual = sequence;
1923 unsigned int count = 0;
1924
1925 trace_(file, line)("Failed sequence %s:\n", context );
1926 while (expected->message && actual->message)
1927 {
1928 if (actual->output[0])
1929 {
1930 if (expected->flags & hook)
1931 {
1932 trace_(file, line)( " %u: expected: hook %04x - actual: %s\n",
1933 count, expected->message, actual->output );
1934 }
1935 else if (expected->flags & winevent_hook)
1936 {
1937 trace_(file, line)( " %u: expected: winevent %04x - actual: %s\n",
1938 count, expected->message, actual->output );
1939 }
1940 else
1941 {
1942 trace_(file, line)( " %u: expected: msg %04x - actual: %s\n",
1943 count, expected->message, actual->output );
1944 }
1945 }
1946
1947 if (expected->message == actual->message)
1948 {
1949 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) &&
1950 (expected->flags & optional))
1951 {
1952 /* don't match messages if their defwinproc status differs */
1953 expected++;
1954 }
1955 else
1956 {
1957 expected++;
1958 actual++;
1959 }
1960 }
1961 /* silently drop winevent messages if there is no support for them */
1962 else if ((expected->flags & optional) || ((expected->flags & winevent_hook) && !hEvent_hook))
1963 expected++;
1964 else
1965 {
1966 expected++;
1967 actual++;
1968 }
1969 count++;
1970 }
1971
1972 /* optional trailing messages */
1973 while (expected->message && ((expected->flags & optional) ||
1974 ((expected->flags & winevent_hook) && !hEvent_hook)))
1975 {
1976 trace_(file, line)( " %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1977 expected++;
1978 count++;
1979 }
1980
1981 if (expected->message)
1982 {
1983 trace_(file, line)( " %u: expected: msg %04x - actual: nothing\n", count, expected->message );
1984 return;
1985 }
1986
1987 while (actual->message && actual->output[0])
1988 {
1989 trace_(file, line)( " %u: expected: nothing - actual: %s\n", count, actual->output );
1990 actual++;
1991 count++;
1992 }
1993 }
1994
1995 #define ok_sequence( exp, contx, todo) \
1996 ok_sequence_( (exp), (contx), (todo), __FILE__, __LINE__)
1997
1998
1999 static void ok_sequence_(const struct message *expected_list, const char *context, int todo,
2000 const char *file, int line)
2001 {
2002 static const struct recvd_message end_of_sequence;
2003 const struct message *expected = expected_list;
2004 const struct recvd_message *actual;
2005 int failcount = 0, dump = 0;
2006 unsigned int count = 0;
2007
2008 add_message(&end_of_sequence);
2009
2010 actual = sequence;
2011
2012 while (expected->message && actual->message)
2013 {
2014 if (expected->message == actual->message)
2015 {
2016 if (expected->flags & wparam)
2017 {
2018 if (((expected->wParam ^ actual->wParam) & ~expected->wp_mask) && todo)
2019 {
2020 todo_wine {
2021 failcount ++;
2022 if (strcmp(winetest_platform, "wine")) dump++;
2023 ok_( file, line) (FALSE,
2024 "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2025 context, count, expected->message, expected->wParam, actual->wParam);
2026 }
2027 }
2028 else
2029 {
2030 ok_( file, line)( ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) == 0,
2031 "%s: %u: in msg 0x%04x expecting wParam 0x%lx got 0x%lx\n",
2032 context, count, expected->message, expected->wParam, actual->wParam);
2033 if ((expected->wParam ^ actual->wParam) & ~expected->wp_mask) dump++;
2034 }
2035
2036 }
2037 if (expected->flags & lparam)
2038 {
2039 if (((expected->lParam ^ actual->lParam) & ~expected->lp_mask) && todo)
2040 {
2041 todo_wine {
2042 failcount ++;
2043 if (strcmp(winetest_platform, "wine")) dump++;
2044 ok_( file, line) (FALSE,
2045 "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2046 context, count, expected->message, expected->lParam, actual->lParam);
2047 }
2048 }
2049 else
2050 {
2051 ok_( file, line)(((expected->lParam ^ actual->lParam) & ~expected->lp_mask) == 0,
2052 "%s: %u: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n",
2053 context, count, expected->message, expected->lParam, actual->lParam);
2054 if ((expected->lParam ^ actual->lParam) & ~expected->lp_mask) dump++;
2055 }
2056 }
2057 if ((expected->flags & optional) &&
2058 ((expected->flags ^ actual->flags) & (defwinproc|parent)))
2059 {
2060 /* don't match optional messages if their defwinproc or parent status differs */
2061 expected++;
2062 count++;
2063 continue;
2064 }
2065 if ((expected->flags & defwinproc) != (actual->flags & defwinproc) && todo)
2066 {
2067 todo_wine {
2068 failcount ++;
2069 if (strcmp(winetest_platform, "wine")) dump++;
2070 ok_( file, line) (FALSE,
2071 "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2072 context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2073 }
2074 }
2075 else
2076 {
2077 ok_( file, line) ((expected->flags & defwinproc) == (actual->flags & defwinproc),
2078 "%s: %u: the msg 0x%04x should %shave been sent by DefWindowProc\n",
2079 context, count, expected->message, (expected->flags & defwinproc) ? "" : "NOT ");
2080 if ((expected->flags & defwinproc) != (actual->flags & defwinproc)) dump++;
2081 }
2082
2083 ok_( file, line) ((expected->flags & beginpaint) == (actual->flags & beginpaint),
2084 "%s: %u: the msg 0x%04x should %shave been sent by BeginPaint\n",
2085 context, count, expected->message, (expected->flags & beginpaint) ? "" : "NOT ");
2086 if ((expected->flags & beginpaint) != (actual->flags & beginpaint)) dump++;
2087
2088 ok_( file, line) ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)),
2089 "%s: %u: the msg 0x%04x should have been %s\n",
2090 context, count, expected->message, (expected->flags & posted) ? "posted" : "sent");
2091 if ((expected->flags & (sent|posted)) != (actual->flags & (sent|posted))) dump++;
2092
2093 ok_( file, line) ((expected->flags & parent) == (actual->flags & parent),
2094 "%s: %u: the msg 0x%04x was expected in %s\n",
2095 context, count, expected->message, (expected->flags & parent) ? "parent" : "child");
2096 if ((expected->flags & parent) != (actual->flags & parent)) dump++;
2097
2098 ok_( file, line) ((expected->flags & hook) == (actual->flags & hook),
2099 "%s: %u: the msg 0x%04x should have been sent by a hook\n",
2100 context, count, expected->message);
2101 if ((expected->flags & hook) != (actual->flags & hook)) dump++;
2102
2103 ok_( file, line) ((expected->flags & winevent_hook) == (actual->flags & winevent_hook),
2104 "%s: %u: the msg 0x%04x should have been sent by a winevent hook\n",
2105 context, count, expected->message);
2106 if ((expected->flags & winevent_hook) != (actual->flags & winevent_hook)) dump++;
2107
2108 expected++;
2109 actual++;
2110 }
2111 /* silently drop hook messages if there is no support for them */
2112 else if ((expected->flags & optional) ||
2113 ((expected->flags & hook) && !hCBT_hook) ||
2114 ((expected->flags & winevent_hook) && !hEvent_hook))
2115 expected++;
2116 else if (todo)
2117 {
2118 failcount++;
2119 todo_wine {
2120 if (strcmp(winetest_platform, "wine")) dump++;
2121 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2122 context, count, expected->message, actual->message);
2123 }
2124 goto done;
2125 }
2126 else
2127 {
2128 ok_( file, line) (FALSE, "%s: %u: the msg 0x%04x was expected, but got msg 0x%04x instead\n",
2129 context, count, expected->message, actual->message);
2130 dump++;
2131 expected++;
2132 actual++;
2133 }
2134 count++;
2135 }
2136
2137 /* skip all optional trailing messages */
2138 while (expected->message && ((expected->flags & optional) ||
2139 ((expected->flags & hook) && !hCBT_hook) ||
2140 ((expected->flags & winevent_hook) && !hEvent_hook)))
2141 expected++;
2142
2143 if (todo)
2144 {
2145 todo_wine {
2146 if (expected->message || actual->message) {
2147 failcount++;
2148 if (strcmp(winetest_platform, "wine")) dump++;
2149 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2150 context, count, expected->message, actual->message);
2151 }
2152 }
2153 }
2154 else
2155 {
2156 if (expected->message || actual->message)
2157 {
2158 dump++;
2159 ok_( file, line) (FALSE, "%s: %u: the msg sequence is not complete: expected %04x - actual %04x\n",
2160 context, count, expected->message, actual->message);
2161 }
2162 }
2163 if( todo && !failcount) /* succeeded yet marked todo */
2164 todo_wine {
2165 if (!strcmp(winetest_platform, "wine")) dump++;
2166 ok_( file, line)( TRUE, "%s: marked \"todo_wine\" but succeeds\n", context);
2167 }
2168
2169 done:
2170 if (dump) dump_sequence(expected_list, context, file, line);
2171 flush_sequence();
2172 }
2173
2174 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
2175
2176 /******************************** MDI test **********************************/
2177
2178 /* CreateWindow for MDI frame window, initially visible */
2179 static const struct message WmCreateMDIframeSeq[] = {
2180 { HCBT_CREATEWND, hook },
2181 { WM_GETMINMAXINFO, sent },
2182 { WM_NCCREATE, sent },
2183 { WM_NCCALCSIZE, sent|wparam, 0 },
2184 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2185 { WM_CREATE, sent },
2186 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2187 { WM_NOTIFYFORMAT, sent|optional },
2188 { WM_QUERYUISTATE, sent|optional },
2189 { WM_WINDOWPOSCHANGING, sent|optional },
2190 { WM_GETMINMAXINFO, sent|optional },
2191 { WM_NCCALCSIZE, sent|optional },
2192 { WM_WINDOWPOSCHANGED, sent|optional },
2193 { WM_SHOWWINDOW, sent|wparam, 1 },
2194 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2195 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2196 { HCBT_ACTIVATE, hook },
2197 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, 0, 0 },
2198 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
2199 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* XP */
2200 { WM_ACTIVATEAPP, sent|wparam|optional, 1 }, /* Win9x doesn't send it */
2201 { WM_NCACTIVATE, sent },
2202 { WM_GETTEXT, sent|defwinproc|optional },
2203 { WM_ACTIVATE, sent|wparam, 1 },
2204 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* Win9x */
2205 { HCBT_SETFOCUS, hook },
2206 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2207 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
2208 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2209 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
2210 /* Win9x adds SWP_NOZORDER below */
2211 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2212 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2213 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2214 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2215 { WM_MOVE, sent },
2216 { 0 }
2217 };
2218 /* DestroyWindow for MDI frame window, initially visible */
2219 static const struct message WmDestroyMDIframeSeq[] = {
2220 { HCBT_DESTROYWND, hook },
2221 { 0x0090, sent|optional },
2222 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2223 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2224 { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2225 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2226 { WM_NCACTIVATE, sent|wparam|optional, 0 }, /* XP */
2227 { WM_ACTIVATE, sent|wparam|optional, 0 }, /* Win9x */
2228 { WM_ACTIVATEAPP, sent|wparam|optional, 0 }, /* Win9x */
2229 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
2230 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2231 { WM_DESTROY, sent },
2232 { WM_NCDESTROY, sent },
2233 { 0 }
2234 };
2235 /* CreateWindow for MDI client window, initially visible */
2236 static const struct message WmCreateMDIclientSeq[] = {
2237 { HCBT_CREATEWND, hook },
2238 { WM_NCCREATE, sent },
2239 { WM_NCCALCSIZE, sent|wparam, 0 },
2240 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2241 { WM_CREATE, sent },
2242 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2243 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2244 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2245 { WM_MOVE, sent },
2246 { WM_PARENTNOTIFY, sent|wparam, WM_CREATE }, /* in MDI frame */
2247 { WM_SHOWWINDOW, sent|wparam, 1 },
2248 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2249 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2250 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2251 { 0 }
2252 };
2253 /* ShowWindow(SW_SHOW) for MDI client window */
2254 static const struct message WmShowMDIclientSeq[] = {
2255 { WM_SHOWWINDOW, sent|wparam, 1 },
2256 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2257 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2258 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2259 { 0 }
2260 };
2261 /* ShowWindow(SW_HIDE) for MDI client window */
2262 static const struct message WmHideMDIclientSeq[] = {
2263 { WM_SHOWWINDOW, sent|wparam, 0 },
2264 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2265 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* win2000 */
2266 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP */
2267 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2268 { 0 }
2269 };
2270 /* DestroyWindow for MDI client window, initially visible */
2271 static const struct message WmDestroyMDIclientSeq[] = {
2272 { HCBT_DESTROYWND, hook },
2273 { 0x0090, sent|optional },
2274 { WM_PARENTNOTIFY, sent|wparam, WM_DESTROY }, /* in MDI frame */
2275 { WM_SHOWWINDOW, sent|wparam, 0 },
2276 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2277 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2278 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2279 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2280 { WM_DESTROY, sent },
2281 { WM_NCDESTROY, sent },
2282 { 0 }
2283 };
2284 /* CreateWindow for MDI child window, initially visible */
2285 static const struct message WmCreateMDIchildVisibleSeq[] = {
2286 { HCBT_CREATEWND, hook },
2287 { WM_NCCREATE, sent },
2288 { WM_NCCALCSIZE, sent|wparam, 0 },
2289 { WM_CREATE, sent },
2290 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2291 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2292 { WM_MOVE, sent },
2293 /* Win2k sends wparam set to
2294 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2295 * while Win9x doesn't bother to set child window id according to
2296 * CLIENTCREATESTRUCT.idFirstChild
2297 */
2298 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2299 { WM_SHOWWINDOW, sent|wparam, 1 },
2300 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2301 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2302 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2303 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2304 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2305 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2306 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2307
2308 /* Win9x: message sequence terminates here. */
2309
2310 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2311 { HCBT_SETFOCUS, hook }, /* in MDI client */
2312 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2313 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2314 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2315 { WM_SETFOCUS, sent }, /* in MDI client */
2316 { HCBT_SETFOCUS, hook },
2317 { WM_KILLFOCUS, sent }, /* in MDI client */
2318 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2319 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2320 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2321 { WM_SETFOCUS, sent|defwinproc },
2322 { WM_MDIACTIVATE, sent|defwinproc },
2323 { 0 }
2324 };
2325 /* CreateWindow for MDI child window with invisible parent */
2326 static const struct message WmCreateMDIchildInvisibleParentSeq[] = {
2327 { HCBT_CREATEWND, hook },
2328 { WM_GETMINMAXINFO, sent },
2329 { WM_NCCREATE, sent },
2330 { WM_NCCALCSIZE, sent|wparam, 0 },
2331 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam|optional, 0, 0 },
2332 { WM_CREATE, sent },
2333 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2334 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2335 { WM_MOVE, sent },
2336 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2337 { WM_SHOWWINDOW, sent|wparam, 1 },
2338 { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2339 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2340 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2341 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2342
2343 /* Win9x: message sequence terminates here. */
2344
2345 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2346 { HCBT_SETFOCUS, hook }, /* in MDI client */
2347 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2348 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2349 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2350 { WM_SETFOCUS, sent }, /* in MDI client */
2351 { HCBT_SETFOCUS, hook },
2352 { WM_KILLFOCUS, sent }, /* in MDI client */
2353 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2354 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2355 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2356 { WM_SETFOCUS, sent|defwinproc },
2357 { WM_MDIACTIVATE, sent|defwinproc },
2358 { 0 }
2359 };
2360 /* DestroyWindow for MDI child window, initially visible */
2361 static const struct message WmDestroyMDIchildVisibleSeq[] = {
2362 { HCBT_DESTROYWND, hook },
2363 /* Win2k sends wparam set to
2364 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2365 * while Win9x doesn't bother to set child window id according to
2366 * CLIENTCREATESTRUCT.idFirstChild
2367 */
2368 { 0x0090, sent|optional },
2369 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2370 { WM_SHOWWINDOW, sent|wparam, 0 },
2371 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2372 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2373 { WM_ERASEBKGND, sent|parent|optional },
2374 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2375
2376 /* { WM_DESTROY, sent }
2377 * Win9x: message sequence terminates here.
2378 */
2379
2380 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2381 { WM_KILLFOCUS, sent },
2382 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2383 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2384 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2385 { WM_SETFOCUS, sent }, /* in MDI client */
2386
2387 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2388 { WM_KILLFOCUS, sent }, /* in MDI client */
2389 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2390 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2391 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2392 { WM_SETFOCUS, sent }, /* in MDI client */
2393
2394 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2395
2396 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2397 { WM_KILLFOCUS, sent },
2398 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2399 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2400 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2401 { WM_SETFOCUS, sent }, /* in MDI client */
2402
2403 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2404 { WM_KILLFOCUS, sent }, /* in MDI client */
2405 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2406 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2407 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2408 { WM_SETFOCUS, sent }, /* in MDI client */
2409
2410 { WM_DESTROY, sent },
2411
2412 { HCBT_SETFOCUS, hook }, /* set focus to MDI client */
2413 { WM_KILLFOCUS, sent },
2414 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2415 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2416 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2417 { WM_SETFOCUS, sent }, /* in MDI client */
2418
2419 { HCBT_SETFOCUS, hook }, /* MDI client sets focus back to MDI child */
2420 { WM_KILLFOCUS, sent }, /* in MDI client */
2421 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2422 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2423 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2424 { WM_SETFOCUS, sent }, /* in MDI client */
2425
2426 { WM_NCDESTROY, sent },
2427 { 0 }
2428 };
2429 /* CreateWindow for MDI child window, initially invisible */
2430 static const struct message WmCreateMDIchildInvisibleSeq[] = {
2431 { HCBT_CREATEWND, hook },
2432 { WM_NCCREATE, sent },
2433 { WM_NCCALCSIZE, sent|wparam, 0 },
2434 { WM_CREATE, sent },
2435 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2436 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2437 { WM_MOVE, sent },
2438 /* Win2k sends wparam set to
2439 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2440 * while Win9x doesn't bother to set child window id according to
2441 * CLIENTCREATESTRUCT.idFirstChild
2442 */
2443 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2444 { 0 }
2445 };
2446 /* DestroyWindow for MDI child window, initially invisible */
2447 static const struct message WmDestroyMDIchildInvisibleSeq[] = {
2448 { HCBT_DESTROYWND, hook },
2449 /* Win2k sends wparam set to
2450 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2451 * while Win9x doesn't bother to set child window id according to
2452 * CLIENTCREATESTRUCT.idFirstChild
2453 */
2454 { 0x0090, sent|optional },
2455 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2456 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2457 { WM_DESTROY, sent },
2458 { WM_NCDESTROY, sent },
2459 /* FIXME: Wine destroys an icon/title window while Windows doesn't */
2460 { WM_PARENTNOTIFY, sent|wparam|optional, WM_DESTROY }, /* MDI client */
2461 { 0 }
2462 };
2463 /* CreateWindow for the 1st MDI child window, initially visible and maximized */
2464 static const struct message WmCreateMDIchildVisibleMaxSeq1[] = {
2465 { HCBT_CREATEWND, hook },
2466 { WM_NCCREATE, sent },
2467 { WM_NCCALCSIZE, sent|wparam, 0 },
2468 { WM_CREATE, sent },
2469 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2470 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2471 { WM_MOVE, sent },
2472 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2473 { WM_GETMINMAXINFO, sent },
2474 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2475 { WM_NCCALCSIZE, sent|wparam, 1 },
2476 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2477 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2478 /* in MDI frame */
2479 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2480 { WM_NCCALCSIZE, sent|wparam, 1 },
2481 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2482 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2483 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2484 /* Win2k sends wparam set to
2485 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2486 * while Win9x doesn't bother to set child window id according to
2487 * CLIENTCREATESTRUCT.idFirstChild
2488 */
2489 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2490 { WM_SHOWWINDOW, sent|wparam, 1 },
2491 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2492 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2493 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2494 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2495 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2496 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2497 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_FRAMECHANGED },
2498
2499 /* Win9x: message sequence terminates here. */
2500
2501 { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
2502 { HCBT_SETFOCUS, hook|optional }, /* in MDI client */
2503 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2504 { WM_IME_NOTIFY, sent|wparam|optional, 2 }, /* in MDI client */
2505 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2506 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2507 { HCBT_SETFOCUS, hook|optional },
2508 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
2509 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2510 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2511 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2512 { WM_SETFOCUS, sent|defwinproc|optional },
2513 { WM_MDIACTIVATE, sent|defwinproc|optional },
2514 /* in MDI frame */
2515 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2516 { WM_NCCALCSIZE, sent|wparam, 1 },
2517 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2518 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2519 { 0 }
2520 };
2521 /* CreateWindow for the 2nd MDI child window, initially visible and maximized */
2522 static const struct message WmCreateMDIchildVisibleMaxSeq2[] = {
2523 /* restore the 1st MDI child */
2524 { WM_SETREDRAW, sent|wparam, 0 },
2525 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2526 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
2527 { WM_NCCALCSIZE, sent|wparam, 1 },
2528 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2529 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2530 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2531 /* in MDI frame */
2532 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2533 { WM_NCCALCSIZE, sent|wparam, 1 },
2534 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2535 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2536 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2537 { WM_SETREDRAW, sent|wparam, 1 }, /* in the 1st MDI child */
2538 /* create the 2nd MDI child */
2539 { HCBT_CREATEWND, hook },
2540 { WM_NCCREATE, sent },
2541 { WM_NCCALCSIZE, sent|wparam, 0 },
2542 { WM_CREATE, sent },
2543 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2544 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2545 { WM_MOVE, sent },
2546 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2547 { WM_GETMINMAXINFO, sent },
2548 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2549 { WM_NCCALCSIZE, sent|wparam, 1 },
2550 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2551 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2552 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2553 /* in MDI frame */
2554 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2555 { WM_NCCALCSIZE, sent|wparam, 1 },
2556 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2557 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2558 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2559 /* Win2k sends wparam set to
2560 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2561 * while Win9x doesn't bother to set child window id according to
2562 * CLIENTCREATESTRUCT.idFirstChild
2563 */
2564 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2565 { WM_SHOWWINDOW, sent|wparam, 1 },
2566 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2567 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2568 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2569 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2570 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2571 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2572
2573 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2574 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2575
2576 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2577
2578 /* Win9x: message sequence terminates here. */
2579
2580 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2581 { HCBT_SETFOCUS, hook },
2582 { WM_KILLFOCUS, sent|defwinproc|optional }, /* in the 1st MDI child */
2583 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 }, /* in the 1st MDI child */
2584 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2585 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2586 { WM_SETFOCUS, sent }, /* in MDI client */
2587 { HCBT_SETFOCUS, hook },
2588 { WM_KILLFOCUS, sent }, /* in MDI client */
2589 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2590 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2591 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2592 { WM_SETFOCUS, sent|defwinproc },
2593
2594 { WM_MDIACTIVATE, sent|defwinproc },
2595 /* in MDI frame */
2596 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2597 { WM_NCCALCSIZE, sent|wparam, 1 },
2598 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2599 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2600 { 0 }
2601 };
2602 /* WM_MDICREATE MDI child window, initially visible and maximized */
2603 static const struct message WmCreateMDIchildVisibleMaxSeq3[] = {
2604 { WM_MDICREATE, sent },
2605 { HCBT_CREATEWND, hook },
2606 { WM_NCCREATE, sent },
2607 { WM_NCCALCSIZE, sent|wparam, 0 },
2608 { WM_CREATE, sent },
2609 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2610 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2611 { WM_MOVE, sent },
2612 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2613 { WM_GETMINMAXINFO, sent },
2614 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2615 { WM_NCCALCSIZE, sent|wparam, 1 },
2616 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2617 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2618
2619 /* in MDI frame */
2620 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2621 { WM_NCCALCSIZE, sent|wparam, 1 },
2622 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2623 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2624 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2625
2626 /* Win2k sends wparam set to
2627 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2628 * while Win9x doesn't bother to set child window id according to
2629 * CLIENTCREATESTRUCT.idFirstChild
2630 */
2631 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2632 { WM_SHOWWINDOW, sent|wparam, 1 },
2633 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2634
2635 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2636
2637 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2638 { WM_MDIREFRESHMENU, sent/*|wparam|lparam, 0, 0*/ },
2639 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
2640
2641 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2642 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2643
2644 /* Win9x: message sequence terminates here. */
2645
2646 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2647 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2648 { HCBT_SETFOCUS, hook }, /* in MDI client */
2649 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2650 { WM_IME_NOTIFY, sent|wparam|optional, 2 },
2651 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam|optional, OBJID_CLIENT, 0 },
2652 { WM_SETFOCUS, sent|optional }, /* in MDI client */
2653 { HCBT_SETFOCUS, hook|optional },
2654 { WM_KILLFOCUS, sent }, /* in MDI client */
2655 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2656 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2657 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2658 { WM_SETFOCUS, sent|defwinproc },
2659
2660 { WM_MDIACTIVATE, sent|defwinproc },
2661
2662 /* in MDI child */
2663 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2664 { WM_NCCALCSIZE, sent|wparam, 1 },
2665 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2666 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
2667
2668 /* in MDI frame */
2669 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2670 { WM_NCCALCSIZE, sent|wparam, 1 },
2671 { 0x0093, sent|defwinproc|optional },
2672 { 0x0093, sent|defwinproc|optional },
2673 { 0x0093, sent|defwinproc|optional },
2674 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2675 { WM_MOVE, sent|defwinproc },
2676 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2677
2678 /* in MDI client */
2679 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2680 { WM_NCCALCSIZE, sent|wparam, 1 },
2681 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2682 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2683
2684 /* in MDI child */
2685 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2686 { WM_NCCALCSIZE, sent|wparam, 1 },
2687 { 0x0093, sent|optional },
2688 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2689 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2690
2691 { 0x0093, sent|optional },
2692 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2693 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2694 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP sends it to MDI frame */
2695 { 0x0093, sent|defwinproc|optional },
2696 { 0x0093, sent|defwinproc|optional },
2697 { 0x0093, sent|defwinproc|optional },
2698 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2699 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2700
2701 { 0 }
2702 };
2703 /* CreateWindow for the 1st MDI child window, initially invisible and maximized */
2704 static const struct message WmCreateMDIchildInvisibleMaxSeq4[] = {
2705 { HCBT_CREATEWND, hook },
2706 { WM_GETMINMAXINFO, sent },
2707 { WM_NCCREATE, sent },
2708 { WM_NCCALCSIZE, sent|wparam, 0 },
2709 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, 0, 0 },
2710 { WM_CREATE, sent },
2711 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
2712 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2713 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2714 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI frame */
2715 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0, SWP_NOZORDER }, /* MDI frame */
2716 { WM_MOVE, sent },
2717 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2718 { WM_GETMINMAXINFO, sent },
2719 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_STATECHANGED },
2720 { WM_GETMINMAXINFO, sent|defwinproc },
2721 { WM_NCCALCSIZE, sent|wparam, 1 },
2722 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
2723 { WM_MOVE, sent|defwinproc },
2724 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2725 /* in MDI frame */
2726 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2727 { WM_NCCALCSIZE, sent|wparam, 1 },
2728 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2729 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2730 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* MDI child */
2731 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2732 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2733 /* Win2k sends wparam set to
2734 * MAKEWPARAM(WM_CREATE, MDI_FIRST_CHILD_ID + nTotalCreated),
2735 * while Win9x doesn't bother to set child window id according to
2736 * CLIENTCREATESTRUCT.idFirstChild
2737 */
2738 { WM_PARENTNOTIFY, sent /*|wparam, WM_CREATE*/ }, /* in MDI client */
2739 { 0 }
2740 };
2741 /* WM_SYSCOMMAND/SC_CLOSE for the 2nd MDI child window, initially visible and maximized */
2742 static const struct message WmDestroyMDIchildVisibleMaxSeq2[] = {
2743 { WM_SYSCOMMAND, sent|wparam, SC_CLOSE },
2744 { HCBT_SYSCOMMAND, hook },
2745 { WM_CLOSE, sent|defwinproc },
2746 { WM_MDIDESTROY, sent }, /* in MDI client */
2747
2748 /* bring the 1st MDI child to top */
2749 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE }, /* in the 1st MDI child */
2750 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE }, /* in the 2nd MDI child */
2751
2752 { EVENT_OBJECT_REORDER, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2753
2754 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 }, /* in the 1st MDI child */
2755 { WM_NCACTIVATE, sent|wparam|defwinproc, 0 }, /* in the 1st MDI child */
2756 { WM_MDIACTIVATE, sent|defwinproc }, /* in the 1st MDI child */
2757
2758 /* maximize the 1st MDI child */
2759 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
2760 { WM_GETMINMAXINFO, sent|defwinproc },
2761 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_STATECHANGED },
2762 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2763 { WM_CHILDACTIVATE, sent|defwinproc|wparam|lparam, 0, 0 },
2764 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2765 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2766
2767 /* restore the 2nd MDI child */
2768 { WM_SETREDRAW, sent|defwinproc|wparam, 0 },
2769 { HCBT_MINMAX, hook|lparam, 0, SW_NORMALNA },
2770 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2771 { WM_NCCALCSIZE, sent|defwinproc|wparam, 1 },
2772
2773 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2774
2775 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2776 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2777
2778 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2779
2780 { WM_SETREDRAW, sent|defwinproc|wparam, 1 },
2781 /* in MDI frame */
2782 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2783 { WM_NCCALCSIZE, sent|wparam, 1 },
2784 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2785 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2786 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2787
2788 /* bring the 1st MDI child to top */
2789 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2790 { WM_NCACTIVATE, sent|wparam|defwinproc, 1 },
2791 { HCBT_SETFOCUS, hook },
2792 { WM_KILLFOCUS, sent|defwinproc },
2793 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
2794 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2795 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2796 { WM_SETFOCUS, sent }, /* in MDI client */
2797 { HCBT_SETFOCUS, hook },
2798 { WM_KILLFOCUS, sent }, /* in MDI client */
2799 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2800 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
2801 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2802 { WM_SETFOCUS, sent|defwinproc },
2803 { WM_MDIACTIVATE, sent|defwinproc },
2804 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2805
2806 /* apparently ShowWindow(SW_SHOW) on an MDI client */
2807 { WM_SHOWWINDOW, sent|wparam, 1 },
2808 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2809 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2810 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2811 { WM_MDIREFRESHMENU, sent },
2812
2813 { HCBT_DESTROYWND, hook },
2814 /* Win2k sends wparam set to
2815 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2816 * while Win9x doesn't bother to set child window id according to
2817 * CLIENTCREATESTRUCT.idFirstChild
2818 */
2819 { 0x0090, sent|defwinproc|optional },
2820 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2821 { WM_SHOWWINDOW, sent|defwinproc|wparam, 0 },
2822 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2823 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2824 { WM_ERASEBKGND, sent|parent|optional },
2825 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2826
2827 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2828 { WM_DESTROY, sent|defwinproc },
2829 { WM_NCDESTROY, sent|defwinproc },
2830 { 0 }
2831 };
2832 /* WM_MDIDESTROY for the single MDI child window, initially visible and maximized */
2833 static const struct message WmDestroyMDIchildVisibleMaxSeq1[] = {
2834 { WM_MDIDESTROY, sent }, /* in MDI client */
2835 { WM_SHOWWINDOW, sent|wparam, 0 },
2836 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2837 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2838 { WM_ERASEBKGND, sent|parent|optional },
2839 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2840
2841 { HCBT_SETFOCUS, hook },
2842 { WM_KILLFOCUS, sent },
2843 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2844 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2845 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2846 { WM_SETFOCUS, sent }, /* in MDI client */
2847 { HCBT_SETFOCUS, hook },
2848 { WM_KILLFOCUS, sent }, /* in MDI client */
2849 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
2850 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
2851 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2852 { WM_SETFOCUS, sent },
2853
2854 /* in MDI child */
2855 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2856 { WM_NCCALCSIZE, sent|wparam, 1 },
2857 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2858 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2859
2860 /* in MDI frame */
2861 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2862 { WM_NCCALCSIZE, sent|wparam, 1 },
2863 { 0x0093, sent|defwinproc|optional },
2864 { 0x0093, sent|defwinproc|optional },
2865 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2866 { WM_MOVE, sent|defwinproc },
2867 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2868
2869 /* in MDI client */
2870 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2871 { WM_NCCALCSIZE, sent|wparam, 1 },
2872 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2873 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2874
2875 /* in MDI child */
2876 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2877 { WM_NCCALCSIZE, sent|wparam, 1 },
2878 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2879 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2880
2881 /* in MDI child */
2882 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2883 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2884 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2885 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2886
2887 /* in MDI frame */
2888 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2889 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2890 { 0x0093, sent|defwinproc|optional },
2891 { 0x0093, sent|defwinproc|optional },
2892 { 0x0093, sent|defwinproc|optional },
2893 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2894 { WM_MOVE, sent|defwinproc },
2895 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2896
2897 /* in MDI client */
2898 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2899 { WM_NCCALCSIZE, sent|wparam, 1 },
2900 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2901 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2902
2903 /* in MDI child */
2904 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
2905 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2906 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
2907 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
2908 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2909 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2910
2911 { 0x0093, sent|defwinproc|optional },
2912 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 }, /* XP sends it to MDI frame */
2913 { 0x0093, sent|defwinproc|optional },
2914 { 0x0093, sent|defwinproc|optional },
2915 { 0x0093, sent|defwinproc|optional },
2916 { 0x0093, sent|optional },
2917
2918 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
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 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2922 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2923
2924 /* in MDI frame */
2925 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2926 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
2927 { 0x0093, sent|defwinproc|optional },
2928 { 0x0093, sent|defwinproc|optional },
2929 { 0x0093, sent|defwinproc|optional },
2930 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2931 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2932 { 0x0093, sent|optional },
2933
2934 { WM_NCACTIVATE, sent|wparam, 0 },
2935 { WM_MDIACTIVATE, sent },
2936
2937 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNORMAL },
2938 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_STATECHANGED },
2939 { WM_NCCALCSIZE, sent|wparam, 1 },
2940
2941 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
2942
2943 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
2944 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
2945 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2946
2947 /* in MDI child */
2948 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2949 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
2950 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2951 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2952
2953 /* in MDI frame */
2954 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2955 { WM_NCCALCSIZE, sent|wparam, 1 },
2956 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2957 { WM_MOVE, sent|defwinproc },
2958 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
2959
2960 /* in MDI client */
2961 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
2962 { WM_NCCALCSIZE, sent|wparam, 1 },
2963 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOCLIENTMOVE },
2964 { WM_SIZE, sent|wparam, SIZE_RESTORED },
2965 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
2966 { WM_NCCALCSIZE, sent|wparam|optional, 1 }, /* XP */
2967 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI client */
2968 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
2969 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* XP sends a duplicate */
2970
2971 { HCBT_SETFOCUS, hook },
2972 { WM_KILLFOCUS, sent },
2973 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
2974 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
2975 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
2976 { WM_SETFOCUS, sent }, /* in MDI client */
2977
2978 { WM_MDIREFRESHMENU, sent }, /* in MDI client */
2979
2980 { HCBT_DESTROYWND, hook },
2981 /* Win2k sends wparam set to
2982 * MAKEWPARAM(WM_DESTROY, MDI_FIRST_CHILD_ID + nTotalCreated),
2983 * while Win9x doesn't bother to set child window id according to
2984 * CLIENTCREATESTRUCT.idFirstChild
2985 */
2986 { 0x0090, sent|optional },
2987 { WM_PARENTNOTIFY, sent /*|wparam, WM_DESTROY*/ }, /* in MDI client */
2988
2989 { WM_SHOWWINDOW, sent|wparam, 0 },
2990 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
2991 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, 0, 0 },
2992 { WM_ERASEBKGND, sent|parent|optional },
2993 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
2994
2995 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 },
2996 { WM_DESTROY, sent },
2997 { WM_NCDESTROY, sent },
2998 { 0 }
2999 };
3000 /* ShowWindow(SW_MAXIMIZE) for a not visible MDI child window */
3001 static const struct message WmMaximizeMDIchildInvisibleSeq[] = {
3002 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3003 { WM_GETMINMAXINFO, sent },
3004 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
3005 { WM_NCCALCSIZE, sent|wparam, 1 },
3006 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3007 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3008
3009 { WM_WINDOWPOSCHANGING, sent|wparam|optional|defwinproc, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3010 { WM_NCACTIVATE, sent|wparam|optional|defwinproc, 1 },
3011 { HCBT_SETFOCUS, hook|optional },
3012 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3013 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3014 { WM_SETFOCUS, sent|optional }, /* in MDI client */
3015 { HCBT_SETFOCUS, hook|optional },
3016 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3017 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3018 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3019 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3020 { WM_SETFOCUS, sent|optional|defwinproc },
3021 { WM_MDIACTIVATE, sent|optional|defwinproc },
3022 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3023 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3024 /* in MDI frame */
3025 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3026 { WM_NCCALCSIZE, sent|wparam, 1 },
3027 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3028 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3029 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3030 { 0 }
3031 };
3032 /* ShowWindow(SW_MAXIMIZE) for a not visible maximized MDI child window */
3033 static const struct message WmMaximizeMDIchildInvisibleSeq2[] = {
3034 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3035 { WM_GETMINMAXINFO, sent },
3036 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED },
3037 { WM_GETMINMAXINFO, sent|defwinproc },
3038 { WM_NCCALCSIZE, sent|wparam, 1 },
3039 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3040 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3041
3042 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3043 { WM_NCACTIVATE, sent|wparam|defwinproc|optional, 1 },
3044 { HCBT_SETFOCUS, hook|optional },
3045 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 }, /* in MDI client */
3046 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3047 { WM_SETFOCUS, sent|optional }, /* in MDI client */
3048 { HCBT_SETFOCUS, hook|optional },
3049 { WM_KILLFOCUS, sent|optional }, /* in MDI client */
3050 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 }, /* in MDI client */
3051 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
3052 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3053 { WM_SETFOCUS, sent|defwinproc|optional },
3054 { WM_MDIACTIVATE, sent|defwinproc|optional },
3055 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3056 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3057 { 0 }
3058 };
3059 /* WM_MDIMAXIMIZE for an MDI child window with invisible parent */
3060 static const struct message WmMaximizeMDIchildInvisibleParentSeq[] = {
3061 { WM_MDIMAXIMIZE, sent }, /* in MDI client */
3062 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3063 { WM_GETMINMAXINFO, sent },
3064 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3065 { WM_GETMINMAXINFO, sent|defwinproc },
3066 { WM_NCCALCSIZE, sent|wparam, 1 },
3067 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam|optional, 0, 0 }, /* XP doesn't send it */
3068 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3069 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOREDRAW|SWP_STATECHANGED },
3070 { WM_MOVE, sent|defwinproc },
3071 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3072
3073 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3074 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3075 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3076 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3077 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3078 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3079 /* in MDI frame */
3080 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3081 { WM_NCCALCSIZE, sent|wparam, 1 },
3082 { 0x0093, sent|defwinproc|optional },
3083 { 0x0094, sent|defwinproc|optional },
3084 { 0x0094, sent|defwinproc|optional },
3085 { 0x0094, sent|defwinproc|optional },
3086 { 0x0094, sent|defwinproc|optional },
3087 { 0x0093, sent|defwinproc|optional },
3088 { 0x0093, sent|defwinproc|optional },
3089 { 0x0091, sent|defwinproc|optional },
3090 { 0x0092, sent|defwinproc|optional },
3091 { 0x0092, sent|defwinproc|optional },
3092 { 0x0092, sent|defwinproc|optional },
3093 { 0x0092, sent|defwinproc|optional },
3094 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3095 { WM_MOVE, sent|defwinproc },
3096 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3097 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame win2000 */
3098 /* in MDI client */
3099 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOACTIVATE },
3100 { WM_NCCALCSIZE, sent|wparam, 1 },
3101 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3102 { WM_SIZE, sent|wparam, SIZE_RESTORED },
3103 /* in MDI child */
3104 { WM_WINDOWPOSCHANGING, sent|wparam|defwinproc, SWP_NOACTIVATE },
3105 { WM_GETMINMAXINFO, sent|defwinproc },
3106 { WM_NCCALCSIZE, sent|wparam|defwinproc, 1 },
3107 { WM_WINDOWPOSCHANGED, sent|wparam|defwinproc, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTMOVE },
3108 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3109 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child win2000 */
3110 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, 1 },
3111 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3112 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3113 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI client XP */
3114 /* in MDI frame */
3115 { 0x0093, sent|optional },
3116 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
3117 { 0x0093, sent|defwinproc|optional },
3118 { 0x0093, sent|defwinproc|optional },
3119 { 0x0093, sent|defwinproc|optional },
3120 { 0x0091, sent|defwinproc|optional },
3121 { 0x0092, sent|defwinproc|optional },
3122 { 0x0092, sent|defwinproc|optional },
3123 { 0x0092, sent|defwinproc|optional },
3124 { 0x0092, sent|defwinproc|optional },
3125 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3126 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI frame XP */
3127 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam|optional, 0, 0 }, /* MDI child XP */
3128 { 0 }
3129 };
3130 /* ShowWindow(SW_MAXIMIZE) for a visible MDI child window */
3131 static const struct message WmMaximizeMDIchildVisibleSeq[] = {
3132 { HCBT_MINMAX, hook|lparam, 0, SW_MAXIMIZE },
3133 { WM_GETMINMAXINFO, sent },
3134 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3135 { WM_NCCALCSIZE, sent|wparam, 1 },
3136 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3137 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3138 { WM_SIZE, sent|defwinproc|wparam, SIZE_MAXIMIZED },
3139 /* in MDI frame */
3140 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3141 { WM_NCCALCSIZE, sent|wparam, 1 },
3142 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3143 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3144 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3145 { 0 }
3146 };
3147 /* ShowWindow(SW_RESTORE) for a visible maximized MDI child window */
3148 static const struct message WmRestoreMDIchildVisibleSeq[] = {
3149 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3150 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED },
3151 { WM_NCCALCSIZE, sent|wparam, 1 },
3152 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3153 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3154 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3155 /* in MDI frame */
3156 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3157 { WM_NCCALCSIZE, sent|wparam, 1 },
3158 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3159 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3160 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3161 { 0 }
3162 };
3163 /* ShowWindow(SW_RESTORE) for a visible minimized MDI child window */
3164 static const struct message WmRestoreMDIchildVisibleSeq_2[] = {
3165 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3166 { WM_QUERYOPEN, sent|wparam|lparam, 0, 0 },
3167 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
3168 { WM_NCCALCSIZE, sent|wparam, 1 },
3169 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3170 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
3171 { WM_MOVE, sent|defwinproc },
3172 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3173 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3174 { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3175 { HCBT_SETFOCUS, hook },
3176 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
3177 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
3178 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
3179 { WM_SETFOCUS, sent },
3180 { 0 }
3181 };
3182 /* ShowWindow(SW_MINIMIZE) for a visible restored MDI child window */
3183 static const struct message WmMinimizeMDIchildVisibleSeq[] = {
3184 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
3185 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_STATECHANGED },
3186 { WM_NCCALCSIZE, sent|wparam, 1 },
3187 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOCLIENTSIZE|SWP_STATECHANGED },
3188 { WM_MOVE, sent|defwinproc },
3189 { WM_SIZE, sent|defwinproc|wparam|lparam, SIZE_MINIMIZED, 0 },
3190 { WM_CHILDACTIVATE, sent|wparam|lparam|defwinproc, 0, 0 },
3191 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3192 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3193 /* FIXME: Wine creates an icon/title window while Windows doesn't */
3194 { WM_PARENTNOTIFY, sent|parent|wparam|optional, WM_CREATE }, /* MDI client */
3195 { 0 }
3196 };
3197 /* ShowWindow(SW_RESTORE) for a not visible MDI child window */
3198 static const struct message WmRestoreMDIchildInisibleSeq[] = {
3199 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
3200 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_STATECHANGED },
3201 { WM_NCCALCSIZE, sent|wparam, 1 },
3202 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, 0, 0 },
3203 { WM_CHILDACTIVATE, sent|wparam|lparam, 0, 0 },
3204 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_STATECHANGED },
3205 { WM_SIZE, sent|defwinproc|wparam, SIZE_RESTORED },
3206 /* in MDI frame */
3207 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
3208 { WM_NCCALCSIZE, sent|wparam, 1 },
3209 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
3210 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI frame */
3211 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 }, /* MDI child */
3212 { 0 }
3213 };
3214
3215 static HWND mdi_client;
3216 static WNDPROC old_mdi_client_proc;
3217
3218 static LRESULT WINAPI mdi_client_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3219 {
3220 struct recvd_message msg;
3221
3222 /* do not log painting messages */
3223 if (message != WM_PAINT &&
3224 message != WM_NCPAINT &&
3225 message != WM_SYNCPAINT &&
3226 message != WM_ERASEBKGND &&
3227 message != WM_NCHITTEST &&
3228 message != WM_GETTEXT &&
3229 message != WM_MDIGETACTIVE &&
3230 !ignore_message( message ))
3231 {
3232 msg.hwnd = hwnd;
3233 msg.message = message;
3234 msg.flags = sent|wparam|lparam;
3235 msg.wParam = wParam;
3236 msg.lParam = lParam;
3237 msg.descr = "mdi client";
3238 add_message(&msg);
3239 }
3240
3241 return CallWindowProcA(old_mdi_client_proc, hwnd, message, wParam, lParam);
3242 }
3243
3244 static LRESULT WINAPI mdi_child_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3245 {
3246 static LONG defwndproc_counter = 0;
3247 LRESULT ret;
3248 struct recvd_message msg;
3249
3250 /* do not log painting messages */
3251 if (message != WM_PAINT &&
3252 message != WM_NCPAINT &&
3253 message != WM_SYNCPAINT &&
3254 message != WM_ERASEBKGND &&
3255 message != WM_NCHITTEST &&
3256 message != WM_GETTEXT &&
3257 !ignore_message( message ))
3258 {
3259 switch (message)
3260 {
3261 case WM_MDIACTIVATE:
3262 {
3263 HWND active, client = GetParent(hwnd);
3264
3265 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
3266
3267 if (hwnd == (HWND)lParam) /* if we are being activated */
3268 ok (active == (HWND)lParam, "new active %p != active %p\n", (HWND)lParam, active);
3269 else
3270 ok (active == (HWND)wParam, "old active %p != active %p\n", (HWND)wParam, active);
3271 break;
3272 }
3273 }
3274
3275 msg.hwnd = hwnd;
3276 msg.message = message;
3277 msg.flags = sent|wparam|lparam;
3278 if (defwndproc_counter) msg.flags |= defwinproc;
3279 msg.wParam = wParam;
3280 msg.lParam = lParam;
3281 msg.descr = "mdi child";
3282 add_message(&msg);
3283 }
3284
3285 defwndproc_counter++;
3286 ret = DefMDIChildProcA(hwnd, message, wParam, lParam);
3287 defwndproc_counter--;
3288
3289 return ret;
3290 }
3291
3292 static LRESULT WINAPI mdi_frame_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3293 {
3294 static LONG defwndproc_counter = 0;
3295 LRESULT ret;
3296 struct recvd_message msg;
3297
3298 /* do not log painting messages */
3299 if (message != WM_PAINT &&
3300 message != WM_NCPAINT &&
3301 message != WM_SYNCPAINT &&
3302 message != WM_ERASEBKGND &&
3303 message != WM_NCHITTEST &&
3304 message != WM_GETTEXT &&
3305 !ignore_message( message ))
3306 {
3307 msg.hwnd = hwnd;
3308 msg.message = message;
3309 msg.flags = sent|wparam|lparam;
3310 if (defwndproc_counter) msg.flags |= defwinproc;
3311 msg.wParam = wParam;
3312 msg.lParam = lParam;
3313 msg.descr = "mdi frame";
3314 add_message(&msg);
3315 }
3316
3317 defwndproc_counter++;
3318 ret = DefFrameProcA(hwnd, mdi_client, message, wParam, lParam);
3319 defwndproc_counter--;
3320
3321 return ret;
3322 }
3323
3324 static BOOL mdi_RegisterWindowClasses(void)
3325 {
3326 WNDCLASSA cls;
3327
3328 cls.style = 0;
3329 cls.lpfnWndProc = mdi_frame_wnd_proc;
3330 cls.cbClsExtra = 0;
3331 cls.cbWndExtra = 0;
3332 cls.hInstance = GetModuleHandleA(0);
3333 cls.hIcon = 0;
3334 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3335 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3336 cls.lpszMenuName = NULL;
3337 cls.lpszClassName = "MDI_frame_class";
3338 if (!RegisterClassA(&cls)) return FALSE;
3339
3340 cls.lpfnWndProc = mdi_child_wnd_proc;
3341 cls.lpszClassName = "MDI_child_class";
3342 if (!RegisterClassA(&cls)) return FALSE;
3343
3344 if (!GetClassInfoA(0, "MDIClient", &cls)) assert(0);
3345 old_mdi_client_proc = cls.lpfnWndProc;
3346 cls.hInstance = GetModuleHandleA(0);
3347 cls.lpfnWndProc = mdi_client_hook_proc;
3348 cls.lpszClassName = "MDI_client_class";
3349 if (!RegisterClassA(&cls)) assert(0);
3350
3351 return TRUE;
3352 }
3353
3354 static void test_mdi_messages(void)
3355 {
3356 MDICREATESTRUCTA mdi_cs;
3357 CLIENTCREATESTRUCT client_cs;
3358 HWND mdi_frame, mdi_child, mdi_child2, active_child;
3359 BOOL zoomed;
3360 HMENU hMenu = CreateMenu();
3361
3362 assert(mdi_RegisterWindowClasses());
3363
3364 flush_sequence();
3365
3366 trace("creating MDI frame window\n");
3367 mdi_frame = CreateWindowExA(0, "MDI_frame_class", "MDI frame window",
3368 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3369 WS_MAXIMIZEBOX | WS_VISIBLE,
3370 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
3371 GetDesktopWindow(), hMenu,
3372 GetModuleHandleA(0), NULL);
3373 assert(mdi_frame);
3374 ok_sequence(WmCreateMDIframeSeq, "Create MDI frame window", FALSE);
3375
3376 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3377 ok(GetFocus() == mdi_frame, "wrong focus window %p\n", GetFocus());
3378
3379 trace("creating MDI client window\n");
3380 client_cs.hWindowMenu = 0;
3381 client_cs.idFirstChild = MDI_FIRST_CHILD_ID;
3382 mdi_client = CreateWindowExA(0, "MDI_client_class",
3383 NULL,
3384 WS_CHILD | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
3385 0, 0, 0, 0,
3386 mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3387 assert(mdi_client);
3388 ok_sequence(WmCreateMDIclientSeq, "Create visible MDI client window", FALSE);
3389
3390 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3391 ok(GetFocus() == mdi_frame, "input focus should be on MDI frame not on %p\n", GetFocus());
3392
3393 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3394 ok(!active_child, "wrong active MDI child %p\n", active_child);
3395 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3396
3397 SetFocus(0);
3398 flush_sequence();
3399
3400 trace("creating invisible MDI child window\n");
3401 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3402 WS_CHILD,
3403 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3404 mdi_client, 0, GetModuleHandleA(0), NULL);
3405 assert(mdi_child);
3406
3407 flush_sequence();
3408 ShowWindow(mdi_child, SW_SHOWNORMAL);
3409 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOWNORMAL) MDI child window", FALSE);
3410
3411 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3412 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3413
3414 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3415 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3416
3417 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3418 ok(!active_child, "wrong active MDI child %p\n", active_child);
3419 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3420
3421 ShowWindow(mdi_child, SW_HIDE);
3422 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE) MDI child window", FALSE);
3423 flush_sequence();
3424
3425 ShowWindow(mdi_child, SW_SHOW);
3426 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW) MDI child window", FALSE);
3427
3428 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3429 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3430
3431 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3432 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3433
3434 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3435 ok(!active_child, "wrong active MDI child %p\n", active_child);
3436 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3437
3438 DestroyWindow(mdi_child);
3439 flush_sequence();
3440
3441 trace("creating visible MDI child window\n");
3442 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3443 WS_CHILD | WS_VISIBLE,
3444 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3445 mdi_client, 0, GetModuleHandleA(0), NULL);
3446 assert(mdi_child);
3447 ok_sequence(WmCreateMDIchildVisibleSeq, "Create visible MDI child window", FALSE);
3448
3449 ok(GetWindowLongA(mdi_child, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3450 ok(IsWindowVisible(mdi_child), "MDI child should be visible\n");
3451
3452 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3453 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3454
3455 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3456 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3457 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3458 flush_sequence();
3459
3460 DestroyWindow(mdi_child);
3461 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3462
3463 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3464 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3465
3466 /* Win2k: MDI client still returns a just destroyed child as active
3467 * Win9x: MDI client returns 0
3468 */
3469 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3470 ok(active_child == mdi_child || /* win2k */
3471 !active_child, /* win9x */
3472 "wrong active MDI child %p\n", active_child);
3473 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3474
3475 flush_sequence();
3476
3477 trace("creating invisible MDI child window\n");
3478 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3479 WS_CHILD,
3480 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3481 mdi_client, 0, GetModuleHandleA(0), NULL);
3482 assert(mdi_child2);
3483 ok_sequence(WmCreateMDIchildInvisibleSeq, "Create invisible MDI child window", FALSE);
3484
3485 ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should not be visible\n");
3486 ok(!IsWindowVisible(mdi_child2), "MDI child should not be visible\n");
3487
3488 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3489 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3490
3491 /* Win2k: MDI client still returns a just destroyed child as active
3492 * Win9x: MDI client returns mdi_child2
3493 */
3494 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3495 ok(active_child == mdi_child || /* win2k */
3496 active_child == mdi_child2, /* win9x */
3497 "wrong active MDI child %p\n", active_child);
3498 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3499 flush_sequence();
3500
3501 ShowWindow(mdi_child2, SW_MAXIMIZE);
3502 ok_sequence(WmMaximizeMDIchildInvisibleSeq, "ShowWindow(SW_MAXIMIZE):invisible MDI child", FALSE);
3503
3504 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3505 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3506
3507 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3508 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3509 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3510 flush_sequence();
3511
3512 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3513 ok(GetFocus() == mdi_child2 || /* win2k */
3514 GetFocus() == 0, /* win9x */
3515 "wrong focus window %p\n", GetFocus());
3516
3517 SetFocus(0);
3518 flush_sequence();
3519
3520 ShowWindow(mdi_child2, SW_HIDE);
3521 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3522
3523 ShowWindow(mdi_child2, SW_RESTORE);
3524 ok_sequence(WmRestoreMDIchildInisibleSeq, "ShowWindow(SW_RESTORE):invisible MDI child", FALSE);
3525 flush_sequence();
3526
3527 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3528 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3529
3530 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3531 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3532 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3533 flush_sequence();
3534
3535 SetFocus(0);
3536 flush_sequence();
3537
3538 ShowWindow(mdi_child2, SW_HIDE);
3539 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3540
3541 ShowWindow(mdi_child2, SW_SHOW);
3542 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):MDI child", FALSE);
3543
3544 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3545 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3546
3547 ShowWindow(mdi_child2, SW_MAXIMIZE);
3548 ok_sequence(WmMaximizeMDIchildVisibleSeq, "ShowWindow(SW_MAXIMIZE):MDI child", FALSE);
3549
3550 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3551 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3552
3553 ShowWindow(mdi_child2, SW_RESTORE);
3554 ok_sequence(WmRestoreMDIchildVisibleSeq, "ShowWindow(SW_RESTORE):maximized MDI child", FALSE);
3555
3556 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3557 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3558
3559 ShowWindow(mdi_child2, SW_MINIMIZE);
3560 ok_sequence(WmMinimizeMDIchildVisibleSeq, "ShowWindow(SW_MINIMIZE):MDI child", TRUE);
3561
3562 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3563 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3564
3565 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3566 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3567 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3568 flush_sequence();
3569
3570 ShowWindow(mdi_child2, SW_RESTORE);
3571 ok_sequence(WmRestoreMDIchildVisibleSeq_2, "ShowWindow(SW_RESTORE):minimized MDI child", TRUE);
3572
3573 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3574 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3575
3576 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3577 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3578 ok(!zoomed, "wrong zoomed state %d\n", zoomed);
3579 flush_sequence();
3580
3581 SetFocus(0);
3582 flush_sequence();
3583
3584 ShowWindow(mdi_child2, SW_HIDE);
3585 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):MDI child", FALSE);
3586
3587 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3588 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3589
3590 DestroyWindow(mdi_child2);
3591 ok_sequence(WmDestroyMDIchildInvisibleSeq, "Destroy invisible MDI child window", FALSE);
3592
3593 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3594 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3595
3596 /* test for maximized MDI children */
3597 trace("creating maximized visible MDI child window 1\n");
3598 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3599 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3600 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3601 mdi_client, 0, GetModuleHandleA(0), NULL);
3602 assert(mdi_child);
3603 ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window", TRUE);
3604 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3605
3606 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3607 ok(GetFocus() == mdi_child || /* win2k */
3608 GetFocus() == 0, /* win9x */
3609 "wrong focus window %p\n", GetFocus());
3610
3611 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3612 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3613 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3614 flush_sequence();
3615
3616 trace("creating maximized visible MDI child window 2\n");
3617 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3618 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3619 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3620 mdi_client, 0, GetModuleHandleA(0), NULL);
3621 assert(mdi_child2);
3622 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3623 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3624 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3625
3626 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3627 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3628
3629 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3630 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3631 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3632 flush_sequence();
3633
3634 trace("destroying maximized visible MDI child window 2\n");
3635 DestroyWindow(mdi_child2);
3636 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3637
3638 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3639
3640 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3641 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3642
3643 /* Win2k: MDI client still returns a just destroyed child as active
3644 * Win9x: MDI client returns 0
3645 */
3646 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3647 ok(active_child == mdi_child2 || /* win2k */
3648 !active_child, /* win9x */
3649 "wrong active MDI child %p\n", active_child);
3650 flush_sequence();
3651
3652 ShowWindow(mdi_child, SW_MAXIMIZE);
3653 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3654 flush_sequence();
3655
3656 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3657 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3658
3659 trace("re-creating maximized visible MDI child window 2\n");
3660 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3661 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3662 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3663 mdi_client, 0, GetModuleHandleA(0), NULL);
3664 assert(mdi_child2);
3665 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child 2 window", TRUE);
3666 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized\n");
3667 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized\n");
3668
3669 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3670 ok(GetFocus() == mdi_child2, "wrong focus window %p\n", GetFocus());
3671
3672 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3673 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3674 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3675 flush_sequence();
3676
3677 SendMessageA(mdi_child2, WM_SYSCOMMAND, SC_CLOSE, 0);
3678 ok_sequence(WmDestroyMDIchildVisibleMaxSeq2, "WM_SYSCOMMAND/SC_CLOSE on a visible maximized MDI child window", TRUE);
3679 ok(!IsWindow(mdi_child2), "MDI child 2 should be destroyed\n");
3680
3681 ok(IsZoomed(mdi_child), "1st MDI child should be maximized\n");
3682 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3683 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3684
3685 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3686 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3687 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3688 flush_sequence();
3689
3690 DestroyWindow(mdi_child);
3691 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible MDI child window", TRUE);
3692
3693 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3694 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3695
3696 /* Win2k: MDI client still returns a just destroyed child as active
3697 * Win9x: MDI client returns 0
3698 */
3699 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3700 ok(active_child == mdi_child || /* win2k */
3701 !active_child, /* win9x */
3702 "wrong active MDI child %p\n", active_child);
3703 flush_sequence();
3704
3705 trace("creating maximized invisible MDI child window\n");
3706 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3707 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
3708 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3709 mdi_client, 0, GetModuleHandleA(0), NULL);
3710 assert(mdi_child2);
3711 ok_sequence(WmCreateMDIchildInvisibleMaxSeq4, "Create maximized invisible MDI child window", FALSE);
3712 ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3713 ok(!(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE), "MDI child should be not visible\n");
3714 ok(!IsWindowVisible(mdi_child2), "MDI child should be not visible\n");
3715
3716 /* Win2k: MDI client still returns a just destroyed child as active
3717 * Win9x: MDI client returns 0
3718 */
3719 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3720 ok(active_child == mdi_child || /* win2k */
3721 !active_child || active_child == mdi_child2, /* win9x */
3722 "wrong active MDI child %p\n", active_child);
3723 flush_sequence();
3724
3725 trace("call ShowWindow(mdi_child, SW_MAXIMIZE)\n");
3726 ShowWindow(mdi_child2, SW_MAXIMIZE);
3727 ok_sequence(WmMaximizeMDIchildInvisibleSeq2, "ShowWindow(SW_MAXIMIZE):invisible maximized MDI child", FALSE);
3728 ok(IsZoomed(mdi_child2), "MDI child should be maximized\n");
3729 ok(GetWindowLongA(mdi_child2, GWL_STYLE) & WS_VISIBLE, "MDI child should be visible\n");
3730 ok(IsWindowVisible(mdi_child2), "MDI child should be visible\n");
3731
3732 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3733 ok(active_child == mdi_child2, "wrong active MDI child %p\n", active_child);
3734 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3735 flush_sequence();
3736
3737 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3738 flush_sequence();
3739
3740 /* end of test for maximized MDI children */
3741 SetFocus(0);
3742 flush_sequence();
3743 trace("creating maximized visible MDI child window 1(Switch test)\n");
3744 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3745 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3746 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3747 mdi_client, 0, GetModuleHandleA(0), NULL);
3748 assert(mdi_child);
3749 ok_sequence(WmCreateMDIchildVisibleMaxSeq1, "Create maximized visible 1st MDI child window(Switch test)", TRUE);
3750 ok(IsZoomed(mdi_child), "1st MDI child should be maximized(Switch test)\n");
3751
3752 ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3753 ok(GetFocus() == mdi_child || /* win2k */
3754 GetFocus() == 0, /* win9x */
3755 "wrong focus window %p(Switch test)\n", GetFocus());
3756
3757 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3758 ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3759 ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3760 flush_sequence();
3761
3762 trace("creating maximized visible MDI child window 2(Switch test)\n");
3763 mdi_child2 = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3764 WS_CHILD | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE,
3765 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
3766 mdi_client, 0, GetModuleHandleA(0), NULL);
3767 assert(mdi_child2);
3768 ok_sequence(WmCreateMDIchildVisibleMaxSeq2, "Create maximized visible 2nd MDI child window (Switch test)", TRUE);
3769
3770 ok(IsZoomed(mdi_child2), "2nd MDI child should be maximized(Switch test)\n");
3771 ok(!IsZoomed(mdi_child), "1st MDI child should NOT be maximized(Switch test)\n");
3772
3773 ok(GetActiveWindow() == mdi_frame, "wrong active window %p(Switch test)\n", GetActiveWindow());
3774 ok(GetFocus() == mdi_child2, "wrong focus window %p(Switch test)\n", GetFocus());
3775
3776 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3777 ok(active_child == mdi_child2, "wrong active MDI child %p(Switch test)\n", active_child);
3778 ok(zoomed, "wrong zoomed state %d(Switch test)\n", zoomed);
3779 flush_sequence();
3780
3781 trace("Switch child window.\n");
3782 SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child, 0);
3783 ok_sequence(WmSwitchChild, "Child did not switch correctly", TRUE);
3784 trace("end of test for switch maximized MDI children\n");
3785 flush_sequence();
3786
3787 /* Prepare for switching test of not maximized MDI children */
3788 ShowWindow( mdi_child, SW_NORMAL );
3789 ok(!IsZoomed(mdi_child), "wrong zoomed state for %p(Switch test)\n", mdi_child);
3790 ok(!IsZoomed(mdi_child2), "wrong zoomed state for %p(Switch test)\n", mdi_child2);
3791 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
3792 ok(active_child == mdi_child, "wrong active MDI child %p(Switch test)\n", active_child);
3793 flush_sequence();
3794
3795 SendMessageA(mdi_client, WM_MDIACTIVATE, (WPARAM)mdi_child2, 0);
3796 ok_sequence(WmSwitchNotMaximizedChild, "Not maximized child did not switch correctly", FALSE);
3797 trace("end of test for switch not maximized MDI children\n");
3798 flush_sequence();
3799
3800 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3801 flush_sequence();
3802
3803 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child2, 0);
3804 flush_sequence();
3805
3806 SetFocus(0);
3807 flush_sequence();
3808 /* end of tests for switch maximized/not maximized MDI children */
3809
3810 mdi_cs.szClass = "MDI_child_Class";
3811 mdi_cs.szTitle = "MDI child";
3812 mdi_cs.hOwner = GetModuleHandleA(0);
3813 mdi_cs.x = 0;
3814 mdi_cs.y = 0;
3815 mdi_cs.cx = CW_USEDEFAULT;
3816 mdi_cs.cy = CW_USEDEFAULT;
3817 mdi_cs.style = WS_CHILD | WS_SYSMENU | WS_VISIBLE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
3818 mdi_cs.lParam = 0;
3819 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
3820 ok(mdi_child != 0, "MDI child creation failed\n");
3821 ok_sequence(WmCreateMDIchildVisibleMaxSeq3, "WM_MDICREATE for maximized visible MDI child window", TRUE);
3822
3823 ok(GetMenuItemID(hMenu, GetMenuItemCount(hMenu) - 1) == SC_CLOSE, "SC_CLOSE menu item not found\n");
3824
3825 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3826 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3827
3828 ok(IsZoomed(mdi_child), "MDI child should be maximized\n");
3829 ok(GetActiveWindow() == mdi_frame, "wrong active window %p\n", GetActiveWindow());
3830 ok(GetFocus() == mdi_child, "wrong focus window %p\n", GetFocus());
3831
3832 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3833 ok(active_child == mdi_child, "wrong active MDI child %p\n", active_child);
3834 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3835 flush_sequence();
3836
3837 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
3838 ok_sequence(WmDestroyMDIchildVisibleMaxSeq1, "Destroy visible maximized MDI child window", TRUE);
3839
3840 ok(!IsWindow(mdi_child), "MDI child should be destroyed\n");
3841 active_child = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, (LPARAM)&zoomed);
3842 ok(!active_child, "wrong active MDI child %p\n", active_child);
3843
3844 SetFocus(0);
3845 flush_sequence();
3846
3847 DestroyWindow(mdi_client);
3848 ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3849
3850 /* test maximization of MDI child with invisible parent */
3851 client_cs.hWindowMenu = 0;
3852 mdi_client = CreateWindow("MDI_client_class",
3853 NULL,
3854 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
3855 0, 0, 660, 430,
3856 mdi_frame, 0, GetModuleHandleA(0), &client_cs);
3857 ok_sequence(WmCreateMDIclientSeq, "Create MDI client window", FALSE);
3858
3859 ShowWindow(mdi_client, SW_HIDE);
3860 ok_sequence(WmHideMDIclientSeq, "Hide MDI client window", FALSE);
3861
3862 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_class", "MDI child",
3863 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
3864 0, 0, 650, 440,
3865 mdi_client, 0, GetModuleHandleA(0), NULL);
3866 ok_sequence(WmCreateMDIchildInvisibleParentSeq, "Create MDI child window with invisible parent", FALSE);
3867
3868 SendMessage(mdi_client, WM_MDIMAXIMIZE, (WPARAM) mdi_child, 0);
3869 ok_sequence(WmMaximizeMDIchildInvisibleParentSeq, "Maximize MDI child window with invisible parent", TRUE);
3870 zoomed = IsZoomed(mdi_child);
3871 ok(zoomed, "wrong zoomed state %d\n", zoomed);
3872
3873 ShowWindow(mdi_client, SW_SHOW);
3874 ok_sequence(WmShowMDIclientSeq, "Show MDI client window", FALSE);
3875
3876 DestroyWindow(mdi_child);
3877 ok_sequence(WmDestroyMDIchildVisibleSeq, "Destroy visible maximized MDI child window", TRUE);
3878
3879 /* end of test for maximization of MDI child with invisible parent */
3880
3881 DestroyWindow(mdi_client);
3882 ok_sequence(WmDestroyMDIclientSeq, "Destroy MDI client window", FALSE);
3883
3884 DestroyWindow(mdi_frame);
3885 ok_sequence(WmDestroyMDIframeSeq, "Destroy MDI frame window", FALSE);
3886 }
3887 /************************* End of MDI test **********************************/
3888
3889 static void test_WM_SETREDRAW(HWND hwnd)
3890 {
3891 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
3892
3893 flush_events();
3894 flush_sequence();
3895
3896 SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3897 ok_sequence(WmSetRedrawFalseSeq, "SetRedraw:FALSE", FALSE);
3898
3899 ok(!(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should NOT be set\n");
3900 ok(!IsWindowVisible(hwnd), "IsWindowVisible() should return FALSE\n");
3901
3902 flush_sequence();
3903 SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3904 ok_sequence(WmSetRedrawTrueSeq, "SetRedraw:TRUE", FALSE);
3905
3906 ok(GetWindowLongA(hwnd, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
3907 ok(IsWindowVisible(hwnd), "IsWindowVisible() should return TRUE\n");
3908
3909 /* restore original WS_VISIBLE state */
3910 SetWindowLongA(hwnd, GWL_STYLE, style);
3911
3912 flush_events();
3913 flush_sequence();
3914 }
3915
3916 static INT_PTR CALLBACK TestModalDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
3917 {
3918 struct recvd_message msg;
3919
3920 if (ignore_message( message )) return 0;
3921
3922 switch (message)
3923 {
3924 /* ignore */
3925 case WM_MOUSEMOVE:
3926 case WM_NCMOUSEMOVE:
3927 case WM_NCMOUSELEAVE:
3928 case WM_SETCURSOR:
3929 return 0;
3930 case WM_NCHITTEST:
3931 return HTCLIENT;
3932 }
3933
3934 msg.hwnd = hwnd;
3935 msg.message = message;
3936 msg.flags = sent|wparam|lparam;
3937 msg.wParam = wParam;
3938 msg.lParam = lParam;
3939 msg.descr = "dialog";
3940 add_message(&msg);
3941
3942 if (message == WM_INITDIALOG) SetTimer( hwnd, 1, 100, NULL );
3943 if (message == WM_TIMER) EndDialog( hwnd, 0 );
3944 return 0;
3945 }
3946
3947 static void test_hv_scroll_1(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3948 {
3949 DWORD style, exstyle;
3950 INT xmin, xmax;
3951 BOOL ret;
3952
3953 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3954 style = GetWindowLongA(hwnd, GWL_STYLE);
3955 /* do not be confused by WS_DLGFRAME set */
3956 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3957
3958 if (clear) ok(style & clear, "style %08x should be set\n", clear);
3959 if (set) ok(!(style & set), "style %08x should not be set\n", set);
3960
3961 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3962 ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3963 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
3964 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollRange(SB_HORZ/SB_VERT) NC", FALSE);
3965 else
3966 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollRange(SB_HORZ/SB_VERT)", FALSE);
3967
3968 style = GetWindowLongA(hwnd, GWL_STYLE);
3969 if (set) ok(style & set, "style %08x should be set\n", set);
3970 if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
3971
3972 /* a subsequent call should do nothing */
3973 ret = SetScrollRange(hwnd, ctl, min, max, FALSE);
3974 ok( ret, "SetScrollRange(%d) error %d\n", ctl, GetLastError());
3975 ok_sequence(WmEmptySeq, "SetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3976
3977 xmin = 0xdeadbeef;
3978 xmax = 0xdeadbeef;
3979 ret = GetScrollRange(hwnd, ctl, &xmin, &xmax);
3980 ok( ret, "GetScrollRange(%d) error %d\n", ctl, GetLastError());
3981 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
3982 ok(xmin == min, "unexpected min scroll value %d\n", xmin);
3983 ok(xmax == max, "unexpected max scroll value %d\n", xmax);
3984 }
3985
3986 static void test_hv_scroll_2(HWND hwnd, INT ctl, DWORD clear, DWORD set, INT min, INT max)
3987 {
3988 DWORD style, exstyle;
3989 SCROLLINFO si;
3990 BOOL ret;
3991
3992 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3993 style = GetWindowLongA(hwnd, GWL_STYLE);
3994 /* do not be confused by WS_DLGFRAME set */
3995 if ((style & WS_CAPTION) == WS_CAPTION) style &= ~WS_CAPTION;
3996
3997 if (clear) ok(style & clear, "style %08x should be set\n", clear);
3998 if (set) ok(!(style & set), "style %08x should not be set\n", set);
3999
4000 si.cbSize = sizeof(si);
4001 si.fMask = SIF_RANGE;
4002 si.nMin = min;
4003 si.nMax = max;
4004 SetScrollInfo(hwnd, ctl, &si, TRUE);
4005 if ((style & (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME)) || (exstyle & WS_EX_DLGMODALFRAME))
4006 ok_sequence(WmSetScrollRangeHV_NC_Seq, "SetScrollInfo(SB_HORZ/SB_VERT) NC", FALSE);
4007 else
4008 ok_sequence(WmSetScrollRangeHVSeq, "SetScrollInfo(SB_HORZ/SB_VERT)", FALSE);
4009
4010 style = GetWindowLongA(hwnd, GWL_STYLE);
4011 if (set) ok(style & set, "style %08x should be set\n", set);
4012 if (clear) ok(!(style & clear), "style %08x should not be set\n", clear);
4013
4014 /* a subsequent call should do nothing */
4015 SetScrollInfo(hwnd, ctl, &si, TRUE);
4016 if (style & WS_HSCROLL)
4017 ok_sequence(WmSetScrollRangeHSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4018 else if (style & WS_VSCROLL)
4019 ok_sequence(WmSetScrollRangeVSeq_empty, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4020 else
4021 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4022
4023 si.fMask = SIF_PAGE;
4024 si.nPage = 5;
4025 SetScrollInfo(hwnd, ctl, &si, FALSE);
4026 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4027
4028 si.fMask = SIF_POS;
4029 si.nPos = max - 1;
4030 SetScrollInfo(hwnd, ctl, &si, FALSE);
4031 ok_sequence(WmEmptySeq, "SetScrollInfo(SB_HORZ/SB_VERT) empty sequence", FALSE);
4032
4033 si.fMask = SIF_RANGE;
4034 si.nMin = 0xdeadbeef;
4035 si.nMax = 0xdeadbeef;
4036 ret = GetScrollInfo(hwnd, ctl, &si);
4037 ok( ret, "GetScrollInfo error %d\n", GetLastError());
4038 ok_sequence(WmEmptySeq, "GetScrollRange(SB_HORZ/SB_VERT) empty sequence", FALSE);
4039 ok(si.nMin == min, "unexpected min scroll value %d\n", si.nMin);
4040 ok(si.nMax == max, "unexpected max scroll value %d\n", si.nMax);
4041 }
4042
4043 /* Win9x sends WM_USER+xxx while and NT versions send SBM_xxx messages */
4044 static void test_scroll_messages(HWND hwnd)
4045 {
4046 SCROLLINFO si;
4047 INT min, max;
4048 BOOL ret;
4049
4050 flush_events();
4051 flush_sequence();
4052
4053 min = 0xdeadbeef;
4054 max = 0xdeadbeef;
4055 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4056 ok( ret, "GetScrollRange error %d\n", GetLastError());
4057 if (sequence->message != WmGetScrollRangeSeq[0].message)
4058 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4059 /* values of min and max are undefined */
4060 flush_sequence();
4061
4062 ret = SetScrollRange(hwnd, SB_CTL, 10, 150, FALSE);
4063 ok( ret, "SetScrollRange error %d\n", GetLastError());
4064 if (sequence->message != WmSetScrollRangeSeq[0].message)
4065 trace("SetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4066 flush_sequence();
4067
4068 min = 0xdeadbeef;
4069 max = 0xdeadbeef;
4070 ret = GetScrollRange(hwnd, SB_CTL, &min, &max);
4071 ok( ret, "GetScrollRange error %d\n", GetLastError());
4072 if (sequence->message != WmGetScrollRangeSeq[0].message)
4073 trace("GetScrollRange(SB_CTL) generated unknown message %04x\n", sequence->message);
4074 /* values of min and max are undefined */
4075 flush_sequence();
4076
4077 si.cbSize = sizeof(si);
4078 si.fMask = SIF_RANGE;
4079 si.nMin = 20;
4080 si.nMax = 160;
4081 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4082 if (sequence->message != WmSetScrollRangeSeq[0].message)
4083 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4084 flush_sequence();
4085
4086 si.fMask = SIF_PAGE;
4087 si.nPage = 10;
4088 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4089 if (sequence->message != WmSetScrollRangeSeq[0].message)
4090 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4091 flush_sequence();
4092
4093 si.fMask = SIF_POS;
4094 si.nPos = 20;
4095 SetScrollInfo(hwnd, SB_CTL, &si, FALSE);
4096 if (sequence->message != WmSetScrollRangeSeq[0].message)
4097 trace("SetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4098 flush_sequence();
4099
4100 si.fMask = SIF_RANGE;
4101 si.nMin = 0xdeadbeef;
4102 si.nMax = 0xdeadbeef;
4103 ret = GetScrollInfo(hwnd, SB_CTL, &si);
4104 ok( ret, "GetScrollInfo error %d\n", GetLastError());
4105 if (sequence->message != WmGetScrollInfoSeq[0].message)
4106 trace("GetScrollInfo(SB_CTL) generated unknown message %04x\n", sequence->message);
4107 /* values of min and max are undefined */
4108 flush_sequence();
4109
4110 /* set WS_HSCROLL */
4111 test_hv_scroll_1(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4112 /* clear WS_HSCROLL */
4113 test_hv_scroll_1(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4114
4115 /* set WS_HSCROLL */
4116 test_hv_scroll_2(hwnd, SB_HORZ, 0, WS_HSCROLL, 10, 150);
4117 /* clear WS_HSCROLL */
4118 test_hv_scroll_2(hwnd, SB_HORZ, WS_HSCROLL, 0, 0, 0);
4119
4120 /* set WS_VSCROLL */
4121 test_hv_scroll_1(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4122 /* clear WS_VSCROLL */
4123 test_hv_scroll_1(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4124
4125 /* set WS_VSCROLL */
4126 test_hv_scroll_2(hwnd, SB_VERT, 0, WS_VSCROLL, 10, 150);
4127 /* clear WS_VSCROLL */
4128 test_hv_scroll_2(hwnd, SB_VERT, WS_VSCROLL, 0, 0, 0);
4129 }
4130
4131 static void test_showwindow(void)
4132 {
4133 HWND hwnd, hchild;
4134 RECT rc;
4135
4136 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4137 100, 100, 200, 200, 0, 0, 0, NULL);
4138 ok (hwnd != 0, "Failed to create overlapped window\n");
4139 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4140 0, 0, 10, 10, hwnd, 0, 0, NULL);
4141 ok (hchild != 0, "Failed to create child\n");
4142 flush_sequence();
4143
4144 /* ShowWindow( SW_SHOWNA) for invisible top level window */
4145 trace("calling ShowWindow( SW_SHOWNA) for invisible top level window\n");
4146 ok( ShowWindow(hwnd, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4147 ok_sequence(WmSHOWNATopInvisible, "ShowWindow(SW_SHOWNA) on invisible top level window", FALSE);
4148
4149 /* ShowWindow( SW_SHOWNA) for now visible top level window */
4150 trace("calling ShowWindow( SW_SHOWNA) for now visible top level window\n");
4151 ok( ShowWindow(hwnd, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4152 ok_sequence(WmSHOWNATopVisible, "ShowWindow(SW_SHOWNA) on visible top level window", FALSE);
4153 /* back to invisible */
4154 ShowWindow(hchild, SW_HIDE);
4155 ShowWindow(hwnd, SW_HIDE);
4156 flush_sequence();
4157 /* ShowWindow(SW_SHOWNA) with child and parent invisible */
4158 trace("calling ShowWindow( SW_SHOWNA) for invisible child with invisible parent\n");
4159 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4160 ok_sequence(WmSHOWNAChildInvisParInvis, "ShowWindow(SW_SHOWNA) invisible child and parent", FALSE);
4161 /* ShowWindow(SW_SHOWNA) with child visible and parent invisible */
4162 ok( ShowWindow(hchild, SW_SHOW) != FALSE, "ShowWindow: window was invisible\n" );
4163 flush_sequence();
4164 trace("calling ShowWindow( SW_SHOWNA) for the visible child and invisible parent\n");
4165 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4166 ok_sequence(WmSHOWNAChildVisParInvis, "ShowWindow(SW_SHOWNA) visible child and invisible parent", FALSE);
4167 /* ShowWindow(SW_SHOWNA) with child visible and parent visible */
4168 ShowWindow( hwnd, SW_SHOW);
4169 flush_sequence();
4170 trace("calling ShowWindow( SW_SHOWNA) for the visible child and parent\n");
4171 ok( ShowWindow(hchild, SW_SHOWNA) != FALSE, "ShowWindow: window was invisible\n" );
4172 ok_sequence(WmSHOWNAChildVisParVis, "ShowWindow(SW_SHOWNA) for the visible child and parent", FALSE);
4173
4174 /* ShowWindow(SW_SHOWNA) with child invisible and parent visible */
4175 ShowWindow( hchild, SW_HIDE);
4176 flush_sequence();
4177 trace("calling ShowWindow( SW_SHOWNA) for the invisible child and visible parent\n");
4178 ok( ShowWindow(hchild, SW_SHOWNA) == FALSE, "ShowWindow: window was visible\n" );
4179 ok_sequence(WmSHOWNAChildInvisParVis, "ShowWindow(SW_SHOWNA) for the invisible child and visible parent", FALSE);
4180
4181 SetCapture(hchild);
4182 ok(GetCapture() == hchild, "wrong capture window %p\n", GetCapture());
4183 DestroyWindow(hchild);
4184 ok(!GetCapture(), "wrong capture window %p\n", GetCapture());
4185
4186 DestroyWindow(hwnd);
4187 flush_sequence();
4188
4189 /* Popup windows */
4190 /* Test 1:
4191 * 1. Create invisible maximized popup window.
4192 * 2. Move and resize it.
4193 * 3. Show it maximized.
4194 */
4195 trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4196 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4197 100, 100, 200, 200, 0, 0, 0, NULL);
4198 ok (hwnd != 0, "Failed to create popup window\n");
4199 ok(IsZoomed(hwnd), "window should be maximized\n");
4200 ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4201
4202 GetWindowRect(hwnd, &rc);
4203 ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4204 rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4205 "Invalid maximized size before ShowWindow (%d,%d)-(%d,%d)\n",
4206 rc.left, rc.top, rc.right, rc.bottom);
4207 /* Reset window's size & position */
4208 SetWindowPos(hwnd, 0, 10, 10, 200, 200, SWP_NOZORDER | SWP_NOACTIVATE);
4209 ok(IsZoomed(hwnd), "window should be maximized\n");
4210 flush_sequence();
4211
4212 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4213 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4214 ok(IsZoomed(hwnd), "window should be maximized\n");
4215 ok_sequence(WmShowMaxPopupResizedSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized and resized popup", FALSE);
4216
4217 GetWindowRect(hwnd, &rc);
4218 ok( rc.right-rc.left == GetSystemMetrics(SM_CXSCREEN) &&
4219 rc.bottom-rc.top == GetSystemMetrics(SM_CYSCREEN),
4220 "Invalid maximized size after ShowWindow (%d,%d)-(%d,%d)\n",
4221 rc.left, rc.top, rc.right, rc.bottom);
4222 DestroyWindow(hwnd);
4223 flush_sequence();
4224
4225 /* Test 2:
4226 * 1. Create invisible maximized popup window.
4227 * 2. Show it maximized.
4228 */
4229 trace("calling CreateWindowExA( WS_MAXIMIZE ) for invisible maximized popup window\n");
4230 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE,
4231 100, 100, 200, 200, 0, 0, 0, NULL);
4232 ok (hwnd != 0, "Failed to create popup window\n");
4233 ok(IsZoomed(hwnd), "window should be maximized\n");
4234 ok_sequence(WmCreateInvisibleMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4235
4236 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for invisible maximized popup window\n");
4237 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4238 ok(IsZoomed(hwnd), "window should be maximized\n");
4239 ok_sequence(WmShowMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):invisible maximized popup", FALSE);
4240 DestroyWindow(hwnd);
4241 flush_sequence();
4242
4243 /* Test 3:
4244 * 1. Create visible maximized popup window.
4245 */
4246 trace("calling CreateWindowExA( WS_MAXIMIZE ) for maximized popup window\n");
4247 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4248 100, 100, 200, 200, 0, 0, 0, NULL);
4249 ok (hwnd != 0, "Failed to create popup window\n");
4250 ok(IsZoomed(hwnd), "window should be maximized\n");
4251 ok_sequence(WmCreateMaxPopupSeq, "CreateWindow(WS_MAXIMIZED):popup", FALSE);
4252 DestroyWindow(hwnd);
4253 flush_sequence();
4254
4255 /* Test 4:
4256 * 1. Create visible popup window.
4257 * 2. Maximize it.
4258 */
4259 trace("calling CreateWindowExA( WS_VISIBLE ) for popup window\n");
4260 hwnd = CreateWindowExA(0, "TestWindowClass", "Test popup", WS_POPUP | 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 NOT be maximized\n");
4264 ok_sequence(WmCreatePopupSeq, "CreateWindow(WS_VISIBLE):popup", FALSE);
4265
4266 trace("calling ShowWindow( SW_SHOWMAXIMIZE ) for visible popup window\n");
4267 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4268 ok(IsZoomed(hwnd), "window should be maximized\n");
4269 ok_sequence(WmShowVisMaxPopupSeq, "ShowWindow(SW_SHOWMAXIMIZED):popup", FALSE);
4270 DestroyWindow(hwnd);
4271 flush_sequence();
4272 }
4273
4274 static void test_sys_menu(void)
4275 {
4276 HWND hwnd;
4277 HMENU hmenu;
4278 UINT state;
4279
4280 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4281 100, 100, 200, 200, 0, 0, 0, NULL);
4282 ok (hwnd != 0, "Failed to create overlapped window\n");
4283
4284 flush_sequence();
4285
4286 /* test existing window without CS_NOCLOSE style */
4287 hmenu = GetSystemMenu(hwnd, FALSE);
4288 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4289
4290 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4291 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4292 ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4293
4294 EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
4295 ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4296
4297 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4298 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4299 ok((state & (MF_DISABLED | MF_GRAYED)) == MF_GRAYED, "wrong SC_CLOSE state %x\n", state);
4300
4301 EnableMenuItem(hmenu, SC_CLOSE, 0);
4302 ok_sequence(WmEmptySeq, "WmEnableMenuItem", FALSE);
4303
4304 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4305 ok(state != 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4306 ok(!(state & (MF_DISABLED | MF_GRAYED)), "wrong SC_CLOSE state %x\n", state);
4307
4308 /* test whether removing WS_SYSMENU destroys a system menu */
4309 SetWindowLongW(hwnd, GWL_STYLE, WS_POPUP);
4310 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4311 flush_sequence();
4312 hmenu = GetSystemMenu(hwnd, FALSE);
4313 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4314
4315 DestroyWindow(hwnd);
4316
4317 /* test new window with CS_NOCLOSE style */
4318 hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4319 100, 100, 200, 200, 0, 0, 0, NULL);
4320 ok (hwnd != 0, "Failed to create overlapped window\n");
4321
4322 hmenu = GetSystemMenu(hwnd, FALSE);
4323 ok(hmenu != 0, "GetSystemMenu error %d\n", GetLastError());
4324
4325 state = GetMenuState(hmenu, SC_CLOSE, MF_BYCOMMAND);
4326 ok(state == 0xffffffff, "wrong SC_CLOSE state %x\n", state);
4327
4328 DestroyWindow(hwnd);
4329
4330 /* test new window without WS_SYSMENU style */
4331 hwnd = CreateWindowExA(0, "NoCloseWindowClass", NULL, WS_OVERLAPPEDWINDOW & ~WS_SYSMENU,
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, "GetSystemMenu error %d\n", GetLastError());
4337
4338 DestroyWindow(hwnd);
4339 }
4340
4341 /* For shown WS_OVERLAPPEDWINDOW */
4342 static const struct message WmSetIcon_1[] = {
4343 { WM_SETICON, sent },
4344 { 0x00AE, sent|defwinproc|optional }, /* XP */
4345 { WM_GETTEXT, sent|defwinproc|optional },
4346 { WM_GETTEXT, sent|defwinproc|optional }, /* XP sends a duplicate */
4347 { 0 }
4348 };
4349
4350 /* For WS_POPUP and hidden WS_OVERLAPPEDWINDOW */
4351 static const struct message WmSetIcon_2[] = {
4352 { WM_SETICON, sent },
4353 { 0 }
4354 };
4355
4356 /* Sending undocumented 0x3B message with wparam = 0x8000000b */
4357 static const struct message WmInitEndSession[] = {
4358 { 0x003B, sent },
4359 { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4360 { 0 }
4361 };
4362
4363 /* Sending undocumented 0x3B message with wparam = 0x0000000b */
4364 static const struct message WmInitEndSession_2[] = {
4365 { 0x003B, sent },
4366 { WM_QUERYENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4367 { 0 }
4368 };
4369
4370 /* Sending undocumented 0x3B message with wparam = 0x80000008 */
4371 static const struct message WmInitEndSession_3[] = {
4372 { 0x003B, sent },
4373 { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, ENDSESSION_LOGOFF },
4374 { 0 }
4375 };
4376
4377 /* Sending undocumented 0x3B message with wparam = 0x00000008 */
4378 static const struct message WmInitEndSession_4[] = {
4379 { 0x003B, sent },
4380 { WM_ENDSESSION, sent|defwinproc|wparam|lparam, 0, 0 },
4381 { 0 }
4382 };
4383
4384 /* Sending undocumented 0x3B message with wparam = 0x80000001 */
4385 static const struct message WmInitEndSession_5[] = {
4386 { 0x003B, sent },
4387 { WM_ENDSESSION, sent|defwinproc/*|wparam*/|lparam, 1, ENDSESSION_LOGOFF },
4388 { 0 }
4389 };
4390
4391 static const struct message WmOptionalPaint[] = {
4392 { WM_PAINT, sent|optional },
4393 { WM_NCPAINT, sent|beginpaint|optional },
4394 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
4395 { WM_ERASEBKGND, sent|beginpaint|optional },
4396 { 0 }
4397 };
4398
4399 static const struct message WmZOrder[] = {
4400 { WM_WINDOWPOSCHANGING, sent|wparam, 0, 0 },
4401 { WM_GETMINMAXINFO, sent|defwinproc|wparam, 0, 0 },
4402 { HCBT_ACTIVATE, hook },
4403 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
4404 { WM_WINDOWPOSCHANGING, sent|wparam, 3, 0 },
4405 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE, 0 },
4406 { WM_GETTEXT, sent|optional },
4407 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
4408 { WM_ACTIVATEAPP, sent|wparam, 1, 0 },
4409 { WM_NCACTIVATE, sent|lparam, 1, 0 },
4410 { WM_GETTEXT, sent|defwinproc|optional },
4411 { WM_GETTEXT, sent|defwinproc|optional },
4412 { WM_ACTIVATE, sent|wparam|lparam, 1, 0 },
4413 { HCBT_SETFOCUS, hook },
4414 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
4415 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
4416 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
4417 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
4418 { WM_GETTEXT, sent|optional },
4419 { WM_NCCALCSIZE, sent|optional },
4420 { 0 }
4421 };
4422
4423 static void test_MsgWaitForMultipleObjects(HWND hwnd)
4424 {
4425 DWORD ret;
4426 MSG msg;
4427
4428 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4429 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4430
4431 PostMessageA(hwnd, WM_USER, 0, 0);
4432
4433 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4434 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4435
4436 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4437 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4438
4439 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4440 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4441
4442 PostMessageA(hwnd, WM_USER, 0, 0);
4443
4444 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4445 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4446
4447 ok(PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "PeekMessage should succeed\n");
4448 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4449
4450 /* shows QS_POSTMESSAGE flag is cleared in the PeekMessage call */
4451 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4452 ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
4453
4454 PostMessageA(hwnd, WM_USER, 0, 0);
4455
4456 /* new incoming message causes it to become signaled again */
4457 ret = MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_POSTMESSAGE);
4458 ok(ret == WAIT_OBJECT_0, "MsgWaitForMultipleObjects returned %x\n", ret);
4459
4460 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4461 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4462 ok(PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n");
4463 ok(msg.message == WM_USER, "got %04x instead of WM_USER\n", msg.message);
4464 }
4465
4466 /* test if we receive the right sequence of messages */
4467 static void test_messages(void)
4468 {
4469 HWND hwnd, hparent, hchild;
4470 HWND hchild2, hbutton;
4471 HMENU hmenu;
4472 MSG msg;
4473 LRESULT res;
4474
4475 flush_sequence();
4476
4477 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4478 100, 100, 200, 200, 0, 0, 0, NULL);
4479 ok (hwnd != 0, "Failed to create overlapped window\n");
4480 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4481
4482 /* test ShowWindow(SW_HIDE) on a newly created invisible window */
4483 ok( ShowWindow(hwnd, SW_HIDE) == FALSE, "ShowWindow: window was visible\n" );
4484 ok_sequence(WmEmptySeq, "ShowWindow(SW_HIDE):overlapped, invisible", FALSE);
4485
4486 /* test WM_SETREDRAW on a not visible top level window */
4487 test_WM_SETREDRAW(hwnd);
4488
4489 SetWindowPos(hwnd, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4490 flush_events();
4491 ok_sequence(WmSWP_ShowOverlappedSeq, "SetWindowPos:SWP_SHOWWINDOW:overlapped", FALSE);
4492 ok(IsWindowVisible(hwnd), "window should be visible at this point\n");
4493
4494 ok(GetActiveWindow() == hwnd, "window should be active\n");
4495 ok(GetFocus() == hwnd, "window should have input focus\n");
4496 ShowWindow(hwnd, SW_HIDE);
4497 flush_events();
4498 ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4499
4500 ShowWindow(hwnd, SW_SHOW);
4501 flush_events();
4502 ok_sequence(WmShowOverlappedSeq, "ShowWindow(SW_SHOW):overlapped", TRUE);
4503
4504 ShowWindow(hwnd, SW_HIDE);
4505 flush_events();
4506 ok_sequence(WmHideOverlappedSeq, "ShowWindow(SW_HIDE):overlapped", FALSE);
4507
4508 ShowWindow(hwnd, SW_SHOWMAXIMIZED);
4509 flush_events();
4510 ok_sequence(WmShowMaxOverlappedSeq, "ShowWindow(SW_SHOWMAXIMIZED):overlapped", TRUE);
4511 flush_sequence();
4512
4513 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MAXIMIZE)
4514 {
4515 ShowWindow(hwnd, SW_RESTORE);
4516 flush_events();
4517 ok_sequence(WmShowRestoreMaxOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4518 flush_sequence();
4519 }
4520
4521 ShowWindow(hwnd, SW_MINIMIZE);
4522 flush_events();
4523 ok_sequence(WmShowMinOverlappedSeq, "ShowWindow(SW_SHOWMINIMIZED):overlapped", TRUE);
4524 flush_sequence();
4525
4526 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MINIMIZE)
4527 {
4528 ShowWindow(hwnd, SW_RESTORE);
4529 flush_events();
4530 ok_sequence(WmShowRestoreMinOverlappedSeq, "ShowWindow(SW_RESTORE):overlapped", TRUE);
4531 flush_sequence();
4532 }
4533
4534 ShowWindow(hwnd, SW_SHOW);
4535 flush_events();
4536 ok_sequence(WmOptionalPaint, "ShowWindow(SW_SHOW):overlapped already visible", FALSE);
4537
4538 SetWindowPos(hwnd, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4539 ok_sequence(WmSWP_HideOverlappedSeq, "SetWindowPos:SWP_HIDEWINDOW:overlapped", FALSE);
4540 ok(!IsWindowVisible(hwnd), "window should not be visible at this point\n");
4541 ok(GetActiveWindow() == hwnd, "window should still be active\n");
4542
4543 /* test WM_SETREDRAW on a visible top level window */
4544 ShowWindow(hwnd, SW_SHOW);
4545 flush_events();
4546 test_WM_SETREDRAW(hwnd);
4547
4548 trace("testing scroll APIs on a visible top level window %p\n", hwnd);
4549 test_scroll_messages(hwnd);
4550
4551 /* test resizing and moving */
4552 SetWindowPos( hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOACTIVATE );
4553 ok_sequence(WmSWP_ResizeSeq, "SetWindowPos:Resize", FALSE );
4554 flush_events();
4555 flush_sequence();
4556 SetWindowPos( hwnd, 0, 200, 200, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE );
4557 ok_sequence(WmSWP_MoveSeq, "SetWindowPos:Move", FALSE );
4558 flush_events();
4559 flush_sequence();
4560 SetWindowPos( hwnd, 0, 200, 200, 250, 250, SWP_NOZORDER|SWP_NOACTIVATE );
4561 ok_sequence(WmSWP_ResizeNoZOrder, "SetWindowPos:WmSWP_ResizeNoZOrder", FALSE );
4562 flush_events();
4563 flush_sequence();
4564
4565 /* popups don't get WM_GETMINMAXINFO */
4566 SetWindowLongW( hwnd, GWL_STYLE, WS_VISIBLE|WS_POPUP );
4567 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED);
4568 flush_sequence();
4569 SetWindowPos( hwnd, 0, 0, 0, 200, 200, SWP_NOMOVE|SWP_NOACTIVATE );
4570 ok_sequence(WmSWP_ResizePopupSeq, "SetWindowPos:ResizePopup", FALSE );
4571
4572 DestroyWindow(hwnd);
4573 ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped", FALSE);
4574
4575 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4576 100, 100, 200, 200, 0, 0, 0, NULL);
4577 ok (hparent != 0, "Failed to create parent window\n");
4578 flush_sequence();
4579
4580 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_MAXIMIZE,
4581 0, 0, 10, 10, hparent, 0, 0, NULL);
4582 ok (hchild != 0, "Failed to create child window\n");
4583 ok_sequence(WmCreateMaximizedChildSeq, "CreateWindow:maximized child", FALSE);
4584 DestroyWindow(hchild);
4585 flush_sequence();
4586
4587 /* visible child window with a caption */
4588 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
4589 WS_CHILD | WS_VISIBLE | WS_CAPTION,
4590 0, 0, 10, 10, hparent, 0, 0, NULL);
4591 ok (hchild != 0, "Failed to create child window\n");
4592 ok_sequence(WmCreateVisibleChildSeq, "CreateWindow:visible child", FALSE);
4593
4594 trace("testing scroll APIs on a visible child window %p\n", hchild);
4595 test_scroll_messages(hchild);
4596
4597 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4598 ok_sequence(WmShowChildSeq_4, "SetWindowPos(SWP_SHOWWINDOW):child with a caption", FALSE);
4599
4600 DestroyWindow(hchild);
4601 flush_sequence();
4602
4603 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4604 0, 0, 10, 10, hparent, 0, 0, NULL);
4605 ok (hchild != 0, "Failed to create child window\n");
4606 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4607
4608 hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILD,
4609 100, 100, 50, 50, hparent, 0, 0, NULL);
4610 ok (hchild2 != 0, "Failed to create child2 window\n");
4611 flush_sequence();
4612
4613 hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILD,
4614 0, 100, 50, 50, hchild, 0, 0, NULL);
4615 ok (hbutton != 0, "Failed to create button window\n");
4616
4617 /* test WM_SETREDRAW on a not visible child window */
4618 test_WM_SETREDRAW(hchild);
4619
4620 ShowWindow(hchild, SW_SHOW);
4621 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4622
4623 /* check parent messages too */
4624 log_all_parent_messages++;
4625 ShowWindow(hchild, SW_HIDE);
4626 ok_sequence(WmHideChildSeq2, "ShowWindow(SW_HIDE):child", FALSE);
4627 log_all_parent_messages--;
4628
4629 ShowWindow(hchild, SW_SHOW);
4630 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4631
4632 ShowWindow(hchild, SW_HIDE);
4633 ok_sequence(WmHideChildSeq, "ShowWindow(SW_HIDE):child", FALSE);
4634
4635 ShowWindow(hchild, SW_SHOW);
4636 ok_sequence(WmShowChildSeq, "ShowWindow(SW_SHOW):child", FALSE);
4637
4638 /* test WM_SETREDRAW on a visible child window */
4639 test_WM_SETREDRAW(hchild);
4640
4641 log_all_parent_messages++;
4642 MoveWindow(hchild, 10, 10, 20, 20, TRUE);
4643 ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child", FALSE);
4644 log_all_parent_messages--;
4645
4646 ShowWindow(hchild, SW_HIDE);
4647 flush_sequence();
4648 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4649 ok_sequence(WmShowChildSeq_2, "SetWindowPos:show_child_2", FALSE);
4650
4651 ShowWindow(hchild, SW_HIDE);
4652 flush_sequence();
4653 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
4654 ok_sequence(WmShowChildSeq_3, "SetWindowPos:show_child_3", FALSE);
4655
4656 /* DestroyWindow sequence below expects that a child has focus */
4657 SetFocus(hchild);
4658 flush_sequence();
4659
4660 DestroyWindow(hchild);
4661 ok_sequence(WmDestroyChildSeq, "DestroyWindow:child", FALSE);
4662 DestroyWindow(hchild2);
4663 DestroyWindow(hbutton);
4664
4665 flush_sequence();
4666 hchild = CreateWindowExA(0, "TestWindowClass", "Test Child Popup", WS_CHILD | WS_POPUP,
4667 0, 0, 100, 100, hparent, 0, 0, NULL);
4668 ok (hchild != 0, "Failed to create child popup window\n");
4669 ok_sequence(WmCreateChildPopupSeq, "CreateWindow:child_popup", FALSE);
4670 DestroyWindow(hchild);
4671
4672 /* test what happens to a window which sets WS_VISIBLE in WM_CREATE */
4673 flush_sequence();
4674 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP,
4675 0, 0, 100, 100, hparent, 0, 0, NULL);
4676 ok (hchild != 0, "Failed to create popup window\n");
4677 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4678 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4679 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4680 flush_sequence();
4681 ShowWindow(hchild, SW_SHOW);
4682 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4683 flush_sequence();
4684 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4685 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4686 flush_sequence();
4687 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
4688 ok_sequence(WmShowVisiblePopupSeq_3, "SetWindowPos:show_visible_popup_3", FALSE);
4689 DestroyWindow(hchild);
4690
4691 /* this time add WS_VISIBLE for CreateWindowEx, but this fact actually
4692 * changes nothing in message sequences.
4693 */
4694 flush_sequence();
4695 hchild = CreateWindowExA(0, "TestPopupClass", "Test Popup", WS_POPUP | WS_VISIBLE,
4696 0, 0, 100, 100, hparent, 0, 0, NULL);
4697 ok (hchild != 0, "Failed to create popup window\n");
4698 ok_sequence(WmCreateInvisiblePopupSeq, "CreateWindow:invisible_popup", FALSE);
4699 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4700 ok(IsWindowVisible(hchild), "IsWindowVisible() should return TRUE\n");
4701 flush_sequence();
4702 ShowWindow(hchild, SW_SHOW);
4703 ok_sequence(WmEmptySeq, "ShowWindow:show_visible_popup", FALSE);
4704 flush_sequence();
4705 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
4706 ok_sequence(WmShowVisiblePopupSeq_2, "SetWindowPos:show_visible_popup_2", FALSE);
4707 DestroyWindow(hchild);
4708
4709 flush_sequence();
4710 hwnd = CreateWindowExA(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL, WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
4711 0, 0, 100, 100, hparent, 0, 0, NULL);
4712 ok(hwnd != 0, "Failed to create custom dialog window\n");
4713 ok_sequence(WmCreateCustomDialogSeq, "CreateCustomDialog", TRUE);
4714
4715 /*
4716 trace("testing scroll APIs on a visible dialog %p\n", hwnd);
4717 test_scroll_messages(hwnd);
4718 */
4719
4720 flush_sequence();
4721
4722 test_def_id = 1;
4723 SendMessage(hwnd, WM_NULL, 0, 0);
4724
4725 flush_sequence();
4726 after_end_dialog = 1;
4727 EndDialog( hwnd, 0 );
4728 ok_sequence(WmEndCustomDialogSeq, "EndCustomDialog", FALSE);
4729
4730 DestroyWindow(hwnd);
4731 after_end_dialog = 0;
4732 test_def_id = 0;
4733
4734 hwnd = CreateWindowExA(0, "TestDialogClass", NULL, WS_POPUP,
4735 0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL);
4736 ok(hwnd != 0, "Failed to create custom dialog window\n");
4737 flush_sequence();
4738 trace("call ShowWindow(%p, SW_SHOW)\n", hwnd);
4739 ShowWindow(hwnd, SW_SHOW);
4740 ok_sequence(WmShowCustomDialogSeq, "ShowCustomDialog", TRUE);
4741 DestroyWindow(hwnd);
4742
4743 flush_sequence();
4744 DialogBoxA( 0, "TEST_DIALOG", hparent, TestModalDlgProcA );
4745 ok_sequence(WmModalDialogSeq, "ModalDialog", TRUE);
4746
4747 DestroyWindow(hparent);
4748 flush_sequence();
4749
4750 /* Message sequence for SetMenu */
4751 ok(!DrawMenuBar(hwnd), "DrawMenuBar should return FALSE for a window without a menu\n");
4752 ok_sequence(WmEmptySeq, "DrawMenuBar for a window without a menu", FALSE);
4753
4754 hmenu = CreateMenu();
4755 ok (hmenu != 0, "Failed to create menu\n");
4756 ok (InsertMenuA(hmenu, -1, MF_BYPOSITION, 0x1000, "foo"), "InsertMenu failed\n");
4757 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
4758 100, 100, 200, 200, 0, hmenu, 0, NULL);
4759 ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped", FALSE);
4760 ok (SetMenu(hwnd, 0), "SetMenu\n");
4761 ok_sequence(WmSetMenuNonVisibleSizeChangeSeq, "SetMenu:NonVisibleSizeChange", FALSE);
4762 ok (SetMenu(hwnd, 0), "SetMenu\n");
4763 ok_sequence(WmSetMenuNonVisibleNoSizeChangeSeq, "SetMenu:NonVisibleNoSizeChange", FALSE);
4764 ShowWindow(hwnd, SW_SHOW);
4765 UpdateWindow( hwnd );
4766 flush_events();
4767 flush_sequence();
4768 ok (SetMenu(hwnd, 0), "SetMenu\n");
4769 ok_sequence(WmSetMenuVisibleNoSizeChangeSeq, "SetMenu:VisibleNoSizeChange", FALSE);
4770 ok (SetMenu(hwnd, hmenu), "SetMenu\n");
4771 ok_sequence(WmSetMenuVisibleSizeChangeSeq, "SetMenu:VisibleSizeChange", FALSE);
4772
4773 UpdateWindow( hwnd );
4774 flush_events();
4775 flush_sequence();
4776 ok(DrawMenuBar(hwnd), "DrawMenuBar\n");
4777 flush_events();
4778 ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar", FALSE);
4779
4780 DestroyWindow(hwnd);
4781 flush_sequence();
4782
4783 /* Message sequence for EnableWindow */
4784 hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4785 100, 100, 200, 200, 0, 0, 0, NULL);
4786 ok (hparent != 0, "Failed to create parent window\n");
4787 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
4788 0, 0, 10, 10, hparent, 0, 0, NULL);
4789 ok (hchild != 0, "Failed to create child window\n");
4790
4791 SetFocus(hchild);
4792 flush_events();
4793 flush_sequence();
4794
4795 EnableWindow(hparent, FALSE);
4796 ok_sequence(WmEnableWindowSeq_1, "EnableWindow(FALSE)", FALSE);
4797
4798 EnableWindow(hparent, TRUE);
4799 ok_sequence(WmEnableWindowSeq_2, "EnableWindow(TRUE)", FALSE);
4800
4801 flush_events();
4802 flush_sequence();
4803
4804 test_MsgWaitForMultipleObjects(hparent);
4805
4806 /* the following test causes an exception in user.exe under win9x */
4807 if (!PostMessageW( hparent, WM_USER, 0, 0 ))
4808 {
4809 DestroyWindow(hparent);
4810 flush_sequence();
4811 return;
4812 }
4813 PostMessageW( hparent, WM_USER+1, 0, 0 );
4814 /* PeekMessage(NULL) fails, but still removes the message */
4815 SetLastError(0xdeadbeef);
4816 ok( !PeekMessageW( NULL, 0, 0, 0, PM_REMOVE ), "PeekMessage(NULL) should fail\n" );
4817 ok( GetLastError() == ERROR_NOACCESS || /* Win2k */
4818 GetLastError() == 0xdeadbeef, /* NT4 */
4819 "last error is %d\n", GetLastError() );
4820 ok( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ), "PeekMessage should succeed\n" );
4821 ok( msg.message == WM_USER+1, "got %x instead of WM_USER+1\n", msg.message );
4822
4823 DestroyWindow(hchild);
4824 DestroyWindow(hparent);
4825 flush_sequence();
4826
4827 /* Message sequences for WM_SETICON */
4828 trace("testing WM_SETICON\n");
4829 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
4830 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4831 NULL, NULL, 0);
4832 ShowWindow(hwnd, SW_SHOW);
4833 UpdateWindow(hwnd);
4834 flush_events();
4835 flush_sequence();
4836 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4837 ok_sequence(WmSetIcon_1, "WM_SETICON for shown window with caption", FALSE);
4838
4839 ShowWindow(hwnd, SW_HIDE);
4840 flush_events();
4841 flush_sequence();
4842 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4843 ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window with caption", FALSE);
4844 DestroyWindow(hwnd);
4845 flush_sequence();
4846
4847 hwnd = CreateWindowExA(0, "TestPopupClass", NULL, WS_POPUP,
4848 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
4849 NULL, NULL, 0);
4850 ShowWindow(hwnd, SW_SHOW);
4851 UpdateWindow(hwnd);
4852 flush_events();
4853 flush_sequence();
4854 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4855 ok_sequence(WmSetIcon_2, "WM_SETICON for shown window without caption", FALSE);
4856
4857 ShowWindow(hwnd, SW_HIDE);
4858 flush_events();
4859 flush_sequence();
4860 SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(0, IDI_APPLICATION));
4861 ok_sequence(WmSetIcon_2, "WM_SETICON for hidden window without caption", FALSE);
4862
4863 flush_sequence();
4864 res = SendMessage(hwnd, 0x3B, 0x8000000b, 0);
4865 if (!res)
4866 {
4867 todo_wine win_skip( "Message 0x3b not supported\n" );
4868 goto done;
4869 }
4870 ok_sequence(WmInitEndSession, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x8000000b", TRUE);
4871 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x8000000b, 0) should have returned 1 instead of %ld\n", res);
4872 res = SendMessage(hwnd, 0x3B, 0x0000000b, 0);
4873 ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000b", TRUE);
4874 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000b, 0) should have returned 1 instead of %ld\n", res);
4875 res = SendMessage(hwnd, 0x3B, 0x0000000f, 0);
4876 ok_sequence(WmInitEndSession_2, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x0000000f", TRUE);
4877 ok(res == 1, "SendMessage(hwnd, 0x3B, 0x0000000f, 0) should have returned 1 instead of %ld\n", res);
4878
4879 flush_sequence();
4880 res = SendMessage(hwnd, 0x3B, 0x80000008, 0);
4881 ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000008", TRUE);
4882 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000008, 0) should have returned 2 instead of %ld\n", res);
4883 res = SendMessage(hwnd, 0x3B, 0x00000008, 0);
4884 ok_sequence(WmInitEndSession_4, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x00000008", TRUE);
4885 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x00000008, 0) should have returned 2 instead of %ld\n", res);
4886
4887 res = SendMessage(hwnd, 0x3B, 0x80000004, 0);
4888 ok_sequence(WmInitEndSession_3, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000004", TRUE);
4889 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000004, 0) should have returned 2 instead of %ld\n", res);
4890
4891 res = SendMessage(hwnd, 0x3B, 0x80000001, 0);
4892 ok_sequence(WmInitEndSession_5, "Handling of undocumented 0x3B message by DefWindowProc wparam=0x80000001", TRUE);
4893 ok(res == 2, "SendMessage(hwnd, 0x3B, 0x80000001, 0) should have returned 2 instead of %ld\n", res);
4894
4895 done:
4896 DestroyWindow(hwnd);
4897 flush_sequence();
4898 }
4899
4900 static void test_setwindowpos(void)
4901 {
4902 HWND hwnd;
4903 RECT rc;
4904 LRESULT res;
4905 const INT winX = 100;
4906 const INT winY = 100;
4907 const INT sysX = GetSystemMetrics(SM_CXMINTRACK);
4908
4909 hwnd = CreateWindowExA(0, "TestWindowClass", NULL, 0,
4910 0, 0, winX, winY, 0,
4911 NULL, NULL, 0);
4912
4913 GetWindowRect(hwnd, &rc);
4914 expect(sysX, rc.right);
4915 expect(winY, rc.bottom);
4916
4917 flush_events();
4918 flush_sequence();
4919 res = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, winX, winY, 0);
4920 ok_sequence(WmZOrder, "Z-Order", TRUE);
4921 ok(res == TRUE, "SetWindowPos expected TRUE, got %ld\n", res);
4922
4923 GetWindowRect(hwnd, &rc);
4924 expect(sysX, rc.right);
4925 expect(winY, rc.bottom);
4926 DestroyWindow(hwnd);
4927 }
4928
4929 static void invisible_parent_tests(void)
4930 {
4931 HWND hparent, hchild;
4932
4933 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
4934 100, 100, 200, 200, 0, 0, 0, NULL);
4935 ok (hparent != 0, "Failed to create parent window\n");
4936 flush_sequence();
4937
4938 /* test showing child with hidden parent */
4939
4940 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4941 0, 0, 10, 10, hparent, 0, 0, NULL);
4942 ok (hchild != 0, "Failed to create child window\n");
4943 ok_sequence(WmCreateChildSeq, "CreateWindow:child", FALSE);
4944
4945 ShowWindow( hchild, SW_MINIMIZE );
4946 ok_sequence(WmShowChildInvisibleParentSeq_1, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4947 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4948 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4949
4950 /* repeat */
4951 flush_events();
4952 flush_sequence();
4953 ShowWindow( hchild, SW_MINIMIZE );
4954 ok_sequence(WmShowChildInvisibleParentSeq_1r, "ShowWindow(SW_MINIMIZE) child with invisible parent", FALSE);
4955
4956 DestroyWindow(hchild);
4957 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4958 0, 0, 10, 10, hparent, 0, 0, NULL);
4959 flush_sequence();
4960
4961 ShowWindow( hchild, SW_MAXIMIZE );
4962 ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4963 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4964 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4965
4966 /* repeat */
4967 flush_events();
4968 flush_sequence();
4969 ShowWindow( hchild, SW_MAXIMIZE );
4970 ok_sequence(WmShowChildInvisibleParentSeq_2r, "ShowWindow(SW_MAXIMIZE) child with invisible parent", FALSE);
4971
4972 DestroyWindow(hchild);
4973 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4974 0, 0, 10, 10, hparent, 0, 0, NULL);
4975 flush_sequence();
4976
4977 ShowWindow( hchild, SW_RESTORE );
4978 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_RESTORE) child with invisible parent", FALSE);
4979 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4980 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4981
4982 DestroyWindow(hchild);
4983 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
4984 0, 0, 10, 10, hparent, 0, 0, NULL);
4985 flush_sequence();
4986
4987 ShowWindow( hchild, SW_SHOWMINIMIZED );
4988 ok_sequence(WmShowChildInvisibleParentSeq_3, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4989 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
4990 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
4991
4992 /* repeat */
4993 flush_events();
4994 flush_sequence();
4995 ShowWindow( hchild, SW_SHOWMINIMIZED );
4996 ok_sequence(WmShowChildInvisibleParentSeq_3r, "ShowWindow(SW_SHOWMINIMIZED) child with invisible parent", FALSE);
4997
4998 DestroyWindow(hchild);
4999 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5000 0, 0, 10, 10, hparent, 0, 0, NULL);
5001 flush_sequence();
5002
5003 /* same as ShowWindow( hchild, SW_MAXIMIZE ); */
5004 ShowWindow( hchild, SW_SHOWMAXIMIZED );
5005 ok_sequence(WmShowChildInvisibleParentSeq_2, "ShowWindow(SW_SHOWMAXIMIZED) child with invisible parent", FALSE);
5006 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5007 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5008
5009 DestroyWindow(hchild);
5010 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5011 0, 0, 10, 10, hparent, 0, 0, NULL);
5012 flush_sequence();
5013
5014 ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5015 ok_sequence(WmShowChildInvisibleParentSeq_4, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5016 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5017 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5018
5019 /* repeat */
5020 flush_events();
5021 flush_sequence();
5022 ShowWindow( hchild, SW_SHOWMINNOACTIVE );
5023 ok_sequence(WmShowChildInvisibleParentSeq_4r, "ShowWindow(SW_SHOWMINNOACTIVE) child with invisible parent", FALSE);
5024
5025 DestroyWindow(hchild);
5026 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5027 0, 0, 10, 10, hparent, 0, 0, NULL);
5028 flush_sequence();
5029
5030 /* FIXME: looks like XP SP2 doesn't know about SW_FORCEMINIMIZE at all */
5031 ShowWindow( hchild, SW_FORCEMINIMIZE );
5032 ok_sequence(WmEmptySeq, "ShowWindow(SW_FORCEMINIMIZE) child with invisible parent", TRUE);
5033 todo_wine {
5034 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5035 }
5036 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5037
5038 DestroyWindow(hchild);
5039 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5040 0, 0, 10, 10, hparent, 0, 0, NULL);
5041 flush_sequence();
5042
5043 ShowWindow( hchild, SW_SHOWNA );
5044 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5045 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5046 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5047
5048 /* repeat */
5049 flush_events();
5050 flush_sequence();
5051 ShowWindow( hchild, SW_SHOWNA );
5052 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOWNA) child with invisible parent", FALSE);
5053
5054 DestroyWindow(hchild);
5055 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD,
5056 0, 0, 10, 10, hparent, 0, 0, NULL);
5057 flush_sequence();
5058
5059 ShowWindow( hchild, SW_SHOW );
5060 ok_sequence(WmShowChildInvisibleParentSeq_5, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5061 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5062 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5063
5064 /* repeat */
5065 flush_events();
5066 flush_sequence();
5067 ShowWindow( hchild, SW_SHOW );
5068 ok_sequence(WmEmptySeq, "ShowWindow(SW_SHOW) child with invisible parent", FALSE);
5069
5070 ShowWindow( hchild, SW_HIDE );
5071 ok_sequence(WmHideChildInvisibleParentSeq, "ShowWindow:hide child with invisible parent", FALSE);
5072 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should be not set\n");
5073 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5074
5075 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5076 ok_sequence(WmShowChildInvisibleParentSeq_6, "SetWindowPos:show child with invisible parent", FALSE);
5077 ok(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE, "WS_VISIBLE should be set\n");
5078 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5079
5080 SetWindowPos(hchild, 0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5081 ok_sequence(WmHideChildInvisibleParentSeq_2, "SetWindowPos:hide child with invisible parent", FALSE);
5082 ok(!(GetWindowLongA(hchild, GWL_STYLE) & WS_VISIBLE), "WS_VISIBLE should not be set\n");
5083 ok(!IsWindowVisible(hchild), "IsWindowVisible() should return FALSE\n");
5084
5085 SetWindowPos(hchild, 0,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
5086 flush_sequence();
5087 DestroyWindow(hchild);
5088 ok_sequence(WmDestroyInvisibleChildSeq, "DestroyInvisibleChildSeq", FALSE);
5089
5090 DestroyWindow(hparent);
5091 flush_sequence();
5092 }
5093
5094 /****************** button message test *************************/
5095 #define ID_BUTTON 0x000e
5096
5097 static const struct message WmSetFocusButtonSeq[] =
5098 {
5099 { HCBT_SETFOCUS, hook },
5100 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5101 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5102 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5103 { WM_SETFOCUS, sent|wparam, 0 },
5104 { WM_CTLCOLORBTN, sent|parent },
5105 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5106 { WM_APP, sent|wparam|lparam, 0, 0 },
5107 { 0 }
5108 };
5109 static const struct message WmKillFocusButtonSeq[] =
5110 {
5111 { HCBT_SETFOCUS, hook },
5112 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5113 { WM_KILLFOCUS, sent|wparam, 0 },
5114 { WM_CTLCOLORBTN, sent|parent },
5115 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5116 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5117 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5118 { WM_APP, sent|wparam|lparam, 0, 0 },
5119 { WM_PAINT, sent },
5120 { WM_CTLCOLORBTN, sent|parent },
5121 { 0 }
5122 };
5123 static const struct message WmSetFocusStaticSeq[] =
5124 {
5125 { HCBT_SETFOCUS, hook },
5126 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5127 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5128 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5129 { WM_SETFOCUS, sent|wparam, 0 },
5130 { WM_CTLCOLORSTATIC, sent|parent },
5131 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5132 { WM_COMMAND, sent|wparam|parent|optional, MAKEWPARAM(ID_BUTTON, BN_CLICKED) }, /* radio button */
5133 { WM_APP, sent|wparam|lparam, 0, 0 },
5134 { 0 }
5135 };
5136 static const struct message WmKillFocusStaticSeq[] =
5137 {
5138 { HCBT_SETFOCUS, hook },
5139 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5140 { WM_KILLFOCUS, sent|wparam, 0 },
5141 { WM_CTLCOLORSTATIC, sent|parent },
5142 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5143 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5144 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5145 { WM_APP, sent|wparam|lparam, 0, 0 },
5146 { WM_PAINT, sent },
5147 { WM_CTLCOLORSTATIC, sent|parent },
5148 { 0 }
5149 };
5150 static const struct message WmSetFocusOwnerdrawSeq[] =
5151 {
5152 { HCBT_SETFOCUS, hook },
5153 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
5154 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5155 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5156 { WM_SETFOCUS, sent|wparam, 0 },
5157 { WM_CTLCOLORBTN, sent|parent },
5158 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x001040e4 },
5159 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_SETFOCUS) },
5160 { WM_APP, sent|wparam|lparam, 0, 0 },
5161 { 0 }
5162 };
5163 static const struct message WmKillFocusOwnerdrawSeq[] =
5164 {
5165 { HCBT_SETFOCUS, hook },
5166 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5167 { WM_KILLFOCUS, sent|wparam, 0 },
5168 { WM_CTLCOLORBTN, sent|parent },
5169 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000040e4 },
5170 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_KILLFOCUS) },
5171 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
5172 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
5173 { WM_APP, sent|wparam|lparam, 0, 0 },
5174 { WM_PAINT, sent },
5175 { WM_CTLCOLORBTN, sent|parent },
5176 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 },
5177 { 0 }
5178 };
5179 static const struct message WmLButtonDownSeq[] =
5180 {
5181 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
5182 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
5183 { HCBT_SETFOCUS, hook },
5184 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
5185 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
5186 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5187 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
5188 { WM_CTLCOLORBTN, sent|defwinproc },
5189 { BM_SETSTATE, sent|wparam|defwinproc, TRUE },
5190 { WM_CTLCOLORBTN, sent|defwinproc },
5191 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5192 { 0 }
5193 };
5194 static const struct message WmLButtonUpSeq[] =
5195 {
5196 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
5197 { BM_SETSTATE, sent|wparam|defwinproc, FALSE },
5198 { WM_CTLCOLORBTN, sent|defwinproc },
5199 { EVENT_OBJECT_STATECHANGE, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
5200 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
5201 { WM_CAPTURECHANGED, sent|wparam|defwinproc, 0 },
5202 { 0 }
5203 };
5204 static const struct message WmSetFontButtonSeq[] =
5205 {
5206 { WM_SETFONT, sent },
5207 { WM_PAINT, sent },
5208 { WM_ERASEBKGND, sent|defwinproc|optional },
5209 { WM_CTLCOLORBTN, sent|defwinproc },
5210 { 0 }
5211 };
5212 static const struct message WmSetStyleButtonSeq[] =
5213 {
5214 { BM_SETSTYLE, sent },
5215 { WM_APP, sent|wparam|lparam, 0, 0 },
5216 { WM_PAINT, sent },
5217 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5218 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5219 { WM_CTLCOLORBTN, sent|parent },
5220 { 0 }
5221 };
5222 static const struct message WmSetStyleStaticSeq[] =
5223 {
5224 { BM_SETSTYLE, sent },
5225 { WM_APP, sent|wparam|lparam, 0, 0 },
5226 { WM_PAINT, sent },
5227 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5228 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5229 { WM_CTLCOLORSTATIC, sent|parent },
5230 { 0 }
5231 };
5232 static const struct message WmSetStyleUserSeq[] =
5233 {
5234 { BM_SETSTYLE, sent },
5235 { WM_APP, sent|wparam|lparam, 0, 0 },
5236 { WM_PAINT, sent },
5237 { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */
5238 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5239 { WM_CTLCOLORBTN, sent|parent },
5240 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_PAINT) },
5241 { 0 }
5242 };
5243 static const struct message WmSetStyleOwnerdrawSeq[] =
5244 {
5245 { BM_SETSTYLE, sent },
5246 { WM_APP, sent|wparam|lparam, 0, 0 },
5247 { WM_PAINT, sent },
5248 { WM_NCPAINT, sent|optional }, /* FIXME: Wine sends it */
5249 { WM_ERASEBKGND, sent|defwinproc|optional }, /* Win9x doesn't send it */
5250 { WM_CTLCOLORBTN, sent|parent },
5251 { WM_CTLCOLORBTN, sent|parent|optional }, /* Win9x doesn't send it */
5252 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 },
5253 { 0 }
5254 };
5255
5256 static WNDPROC old_button_proc;
5257
5258 static LRESULT CALLBACK button_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5259 {
5260 static LONG defwndproc_counter = 0;
5261 LRESULT ret;
5262 struct recvd_message msg;
5263
5264 if (ignore_message( message )) return 0;
5265
5266 switch (message)
5267 {
5268 case WM_SYNCPAINT:
5269 break;
5270 case BM_SETSTATE:
5271 ok(GetCapture() == hwnd, "GetCapture() = %p\n", GetCapture());
5272 /* fall through */
5273 default:
5274 msg.hwnd = hwnd;
5275 msg.message = message;
5276 msg.flags = sent|wparam|lparam;
5277 if (defwndproc_counter) msg.flags |= defwinproc;
5278 msg.wParam = wParam;
5279 msg.lParam = lParam;
5280 msg.descr = "button";
5281 add_message(&msg);
5282 }
5283
5284 defwndproc_counter++;
5285 ret = CallWindowProcA(old_button_proc, hwnd, message, wParam, lParam);
5286 defwndproc_counter--;
5287
5288 return ret;
5289 }
5290
5291 static void subclass_button(void)
5292 {
5293 WNDCLASSA cls;
5294
5295 if (!GetClassInfoA(0, "button", &cls)) assert(0);
5296
5297 old_button_proc = cls.lpfnWndProc;
5298
5299 cls.hInstance = GetModuleHandle(0);
5300 cls.lpfnWndProc = button_hook_proc;
5301 cls.lpszClassName = "my_button_class";
5302 UnregisterClass(cls.lpszClassName, cls.hInstance);
5303 if (!RegisterClassA(&cls)) assert(0);
5304 }
5305
5306 static void test_button_messages(void)
5307 {
5308 static const struct
5309 {
5310 DWORD style;
5311 DWORD dlg_code;
5312 const struct message *setfocus;
5313 const struct message *killfocus;
5314 const struct message *setstyle;
5315 } button[] = {
5316 { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5317 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq },
5318 { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
5319 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq },
5320 { BS_CHECKBOX, DLGC_BUTTON,
5321 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5322 { BS_AUTOCHECKBOX, DLGC_BUTTON,
5323 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5324 { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5325 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5326 { BS_3STATE, DLGC_BUTTON,
5327 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5328 { BS_AUTO3STATE, DLGC_BUTTON,
5329 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5330 { BS_GROUPBOX, DLGC_STATIC,
5331 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5332 { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
5333 WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleUserSeq },
5334 { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
5335 WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq },
5336 { BS_OWNERDRAW, DLGC_BUTTON,
5337 WmSetFocusOwnerdrawSeq, WmKillFocusOwnerdrawSeq, WmSetStyleOwnerdrawSeq }
5338 };
5339 unsigned int i;
5340 HWND hwnd, parent;
5341 DWORD dlg_code;
5342 HFONT zfont;
5343
5344 /* selection with VK_SPACE should capture button window */
5345 hwnd = CreateWindowExA(0, "button", "test", BS_CHECKBOX | WS_VISIBLE | WS_POPUP,
5346 0, 0, 50, 14, 0, 0, 0, NULL);
5347 ok(hwnd != 0, "Failed to create button window\n");
5348 ReleaseCapture();
5349 SetFocus(hwnd);
5350 SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
5351 ok(GetCapture() == hwnd, "Should be captured on VK_SPACE WM_KEYDOWN\n");
5352 SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
5353 DestroyWindow(hwnd);
5354
5355 subclass_button();
5356
5357 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5358 100, 100, 200, 200, 0, 0, 0, NULL);
5359 ok(parent != 0, "Failed to create parent window\n");
5360
5361 for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
5362 {
5363 MSG msg;
5364 DWORD style;
5365
5366 trace("button style %08x\n", button[i].style);
5367
5368 hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_CHILD | BS_NOTIFY,
5369 0, 0, 50, 14, parent, (HMENU)ID_BUTTON, 0, NULL);
5370 ok(hwnd != 0, "Failed to create button window\n");
5371
5372 style = GetWindowLongA(hwnd, GWL_STYLE);
5373 style &= ~(WS_CHILD | BS_NOTIFY);
5374 /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
5375 if (button[i].style == BS_USERBUTTON)
5376 ok(style == BS_PUSHBUTTON, "expected style BS_PUSHBUTTON got %x\n", style);
5377 else
5378 ok(style == button[i].style, "expected style %x got %x\n", button[i].style, style);
5379
5380 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5381 ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5382
5383 ShowWindow(hwnd, SW_SHOW);
5384 UpdateWindow(hwnd);
5385 SetFocus(0);
5386 flush_events();
5387 flush_sequence();
5388
5389 log_all_parent_messages++;
5390
5391 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
5392 SetFocus(hwnd);
5393 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5394 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5395 ok_sequence(button[i].setfocus, "SetFocus(hwnd) on a button", FALSE);
5396
5397 SetFocus(0);
5398 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5399 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5400 ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE);
5401
5402 ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
5403
5404 SendMessage(hwnd, BM_SETSTYLE, button[i].style | BS_BOTTOM, TRUE);
5405 SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */
5406 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
5407 ok_sequence(button[i].setstyle, "BM_SETSTYLE on a button", FALSE);
5408
5409 style = GetWindowLongA(hwnd, GWL_STYLE);
5410 style &= ~(WS_VISIBLE | WS_CHILD | BS_NOTIFY);
5411 /* XP doesn't turn a BS_USERBUTTON into BS_PUSHBUTTON here! */
5412 ok(style == button[i].style, "expected style %x got %x\n", button[i].style, style);
5413
5414 log_all_parent_messages--;
5415
5416 DestroyWindow(hwnd);
5417 }
5418
5419 DestroyWindow(parent);
5420
5421 hwnd = CreateWindowExA(0, "my_button_class", "test", BS_PUSHBUTTON | WS_POPUP | WS_VISIBLE,
5422 0, 0, 50, 14, 0, 0, 0, NULL);
5423 ok(hwnd != 0, "Failed to create button window\n");
5424
5425 SetForegroundWindow(hwnd);
5426 flush_events();
5427
5428 SetActiveWindow(hwnd);
5429 SetFocus(0);
5430 flush_sequence();
5431
5432 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
5433 ok_sequence(WmLButtonDownSeq, "WM_LBUTTONDOWN on a button", FALSE);
5434
5435 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
5436 ok_sequence(WmLButtonUpSeq, "WM_LBUTTONUP on a button", FALSE);
5437
5438 flush_sequence();
5439 zfont = GetStockObject(SYSTEM_FONT);
5440 SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
5441 UpdateWindow(hwnd);
5442 ok_sequence(WmSetFontButtonSeq, "WM_SETFONT on a button", FALSE);
5443
5444 DestroyWindow(hwnd);
5445 }
5446
5447 /****************** static message test *************************/
5448 static const struct message WmSetFontStaticSeq[] =
5449 {
5450 { WM_SETFONT, sent },
5451 { WM_PAINT, sent|defwinproc|optional },
5452 { WM_ERASEBKGND, sent|defwinproc|optional },
5453 { WM_CTLCOLORSTATIC, sent|defwinproc|optional },
5454 { 0 }
5455 };
5456
5457 static WNDPROC old_static_proc;
5458
5459 static LRESULT CALLBACK static_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5460 {
5461 static LONG defwndproc_counter = 0;
5462 LRESULT ret;
5463 struct recvd_message msg;
5464
5465 if (ignore_message( message )) return 0;
5466
5467 msg.hwnd = hwnd;
5468 msg.message = message;
5469 msg.flags = sent|wparam|lparam;
5470 if (defwndproc_counter) msg.flags |= defwinproc;
5471 msg.wParam = wParam;
5472 msg.lParam = lParam;
5473 msg.descr = "static";
5474 add_message(&msg);
5475
5476 defwndproc_counter++;
5477 ret = CallWindowProcA(old_static_proc, hwnd, message, wParam, lParam);
5478 defwndproc_counter--;
5479
5480 return ret;
5481 }
5482
5483 static void subclass_static(void)
5484 {
5485 WNDCLASSA cls;
5486
5487 if (!GetClassInfoA(0, "static", &cls)) assert(0);
5488
5489 old_static_proc = cls.lpfnWndProc;
5490
5491 cls.hInstance = GetModuleHandle(0);
5492 cls.lpfnWndProc = static_hook_proc;
5493 cls.lpszClassName = "my_static_class";
5494 UnregisterClass(cls.lpszClassName, cls.hInstance);
5495 if (!RegisterClassA(&cls)) assert(0);
5496 }
5497
5498 static void test_static_messages(void)
5499 {
5500 /* FIXME: make as comprehensive as the button message test */
5501 static const struct
5502 {
5503 DWORD style;
5504 DWORD dlg_code;
5505 const struct message *setfont;
5506 } static_ctrl[] = {
5507 { SS_LEFT, DLGC_STATIC,
5508 WmSetFontStaticSeq }
5509 };
5510 unsigned int i;
5511 HWND hwnd;
5512 DWORD dlg_code;
5513
5514 subclass_static();
5515
5516 for (i = 0; i < sizeof(static_ctrl)/sizeof(static_ctrl[0]); i++)
5517 {
5518 hwnd = CreateWindowExA(0, "my_static_class", "test", static_ctrl[i].style | WS_POPUP,
5519 0, 0, 50, 14, 0, 0, 0, NULL);
5520 ok(hwnd != 0, "Failed to create static window\n");
5521
5522 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
5523 ok(dlg_code == static_ctrl[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);
5524
5525 ShowWindow(hwnd, SW_SHOW);
5526 UpdateWindow(hwnd);
5527 SetFocus(0);
5528 flush_sequence();
5529
5530 trace("static style %08x\n", static_ctrl[i].style);
5531 SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
5532 ok_sequence(static_ctrl[i].setfont, "WM_SETFONT on a static", FALSE);
5533
5534 DestroyWindow(hwnd);
5535 }
5536 }
5537
5538 /****************** ComboBox message test *************************/
5539 #define ID_COMBOBOX 0x000f
5540
5541 static const struct message WmKeyDownComboSeq[] =
5542 {
5543 { WM_KEYDOWN, sent|wparam|lparam, VK_DOWN, 0 },
5544 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(1000, LBN_SELCHANGE) },
5545 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELENDOK) },
5546 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_COMBOBOX, CBN_SELCHANGE) },
5547 { WM_CTLCOLOREDIT, sent|parent },
5548 { WM_KEYUP, sent|wparam|lparam, VK_DOWN, 0 },
5549 { 0 }
5550 };
5551
5552 static WNDPROC old_combobox_proc;
5553
5554 static LRESULT CALLBACK combobox_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5555 {
5556 static LONG defwndproc_counter = 0;
5557 LRESULT ret;
5558 struct recvd_message msg;
5559
5560 /* do not log painting messages */
5561 if (message != WM_PAINT &&
5562 message != WM_NCPAINT &&
5563 message != WM_SYNCPAINT &&
5564 message != WM_ERASEBKGND &&
5565 message != WM_NCHITTEST &&
5566 message != WM_GETTEXT &&
5567 !ignore_message( message ))
5568 {
5569 msg.hwnd = hwnd;
5570 msg.message = message;
5571 msg.flags = sent|wparam|lparam;
5572 if (defwndproc_counter) msg.flags |= defwinproc;
5573 msg.wParam = wParam;
5574 msg.lParam = lParam;
5575 msg.descr = "combo";
5576 add_message(&msg);
5577 }
5578
5579 defwndproc_counter++;
5580 ret = CallWindowProcA(old_combobox_proc, hwnd, message, wParam, lParam);
5581 defwndproc_counter--;
5582
5583 return ret;
5584 }
5585
5586 static void subclass_combobox(void)
5587 {
5588 WNDCLASSA cls;
5589
5590 if (!GetClassInfoA(0, "ComboBox", &cls)) assert(0);
5591
5592 old_combobox_proc = cls.lpfnWndProc;
5593
5594 cls.hInstance = GetModuleHandle(0);
5595 cls.lpfnWndProc = combobox_hook_proc;
5596 cls.lpszClassName = "my_combobox_class";
5597 UnregisterClass(cls.lpszClassName, cls.hInstance);
5598 if (!RegisterClassA(&cls)) assert(0);
5599 }
5600
5601 static void test_combobox_messages(void)
5602 {
5603 HWND parent, combo;
5604 LRESULT ret;
5605
5606 subclass_combobox();
5607
5608 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
5609 100, 100, 200, 200, 0, 0, 0, NULL);
5610 ok(parent != 0, "Failed to create parent window\n");
5611 flush_sequence();
5612
5613 combo = CreateWindowEx(0, "my_combobox_class", "test", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
5614 0, 0, 100, 150, parent, (HMENU)ID_COMBOBOX, 0, NULL);
5615 ok(combo != 0, "Failed to create combobox window\n");
5616
5617 UpdateWindow(combo);
5618
5619 ret = SendMessage(combo, WM_GETDLGCODE, 0, 0);
5620 ok(ret == (DLGC_WANTCHARS | DLGC_WANTARROWS), "wrong dlg_code %08lx\n", ret);
5621
5622 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 0");
5623 ok(ret == 0, "expected 0, got %ld\n", ret);
5624 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 1");
5625 ok(ret == 1, "expected 1, got %ld\n", ret);
5626 ret = SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)"item 2");
5627 ok(ret == 2, "expected 2, got %ld\n", ret);
5628
5629 SendMessage(combo, CB_SETCURSEL, 0, 0);
5630 SetFocus(combo);
5631 flush_sequence();
5632
5633 log_all_parent_messages++;
5634 SendMessage(combo, WM_KEYDOWN, VK_DOWN, 0);
5635 SendMessage(combo, WM_KEYUP, VK_DOWN, 0);
5636 log_all_parent_messages--;
5637 ok_sequence(WmKeyDownComboSeq, "WM_KEYDOWN/VK_DOWN on a ComboBox", FALSE);
5638
5639 DestroyWindow(combo);
5640 DestroyWindow(parent);
5641 }
5642
5643 /****************** WM_IME_KEYDOWN message test *******************/
5644
5645 static const struct message WmImeKeydownMsgSeq_0[] =
5646 {
5647 { WM_IME_KEYDOWN, wparam, VK_RETURN },
5648 { WM_CHAR, wparam, 'A' },
5649 { 0 }
5650 };
5651
5652 static const struct message WmImeKeydownMsgSeq_1[] =
5653 {
5654 { WM_KEYDOWN, optional|wparam, VK_RETURN },
5655 { WM_CHAR, optional|wparam, VK_RETURN },
5656 { 0 }
5657 };
5658
5659 static LRESULT WINAPI wmime_keydown_procA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
5660 {
5661 struct recvd_message msg;
5662
5663 msg.hwnd = hwnd;
5664 msg.message = message;
5665 msg.flags = wparam|lparam;
5666 msg.wParam = wParam;
5667 msg.lParam = lParam;
5668 msg.descr = "wmime_keydown";
5669 add_message(&msg);
5670
5671 return DefWindowProcA(hwnd, message, wParam, lParam);
5672 }
5673
5674 static void register_wmime_keydown_class(void)
5675 {
5676 WNDCLASSA cls;
5677
5678 ZeroMemory(&cls, sizeof(WNDCLASSA));
5679 cls.lpfnWndProc = wmime_keydown_procA;
5680 cls.hInstance = GetModuleHandleA(0);
5681 cls.lpszClassName = "wmime_keydown_class";
5682 if (!RegisterClassA(&cls)) assert(0);
5683 }
5684
5685 static void test_wmime_keydown_message(void)
5686 {
5687 HWND hwnd;
5688 MSG msg;
5689
5690 trace("Message sequences by WM_IME_KEYDOWN\n");
5691
5692 register_wmime_keydown_class();
5693 hwnd = CreateWindowExA(0, "wmime_keydown_class", NULL, WS_OVERLAPPEDWINDOW,
5694 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
5695 NULL, NULL, 0);
5696 flush_events();
5697 flush_sequence();
5698
5699 SendMessage(hwnd, WM_IME_KEYDOWN, VK_RETURN, 0x1c0001);
5700 SendMessage(hwnd, WM_CHAR, 'A', 1);
5701 ok_sequence(WmImeKeydownMsgSeq_0, "WM_IME_KEYDOWN 0", FALSE);
5702
5703 while ( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
5704 {
5705 TranslateMessage(&msg);
5706 DispatchMessage(&msg);
5707 }
5708 ok_sequence(WmImeKeydownMsgSeq_1, "WM_IME_KEYDOWN 1", FALSE);
5709
5710 DestroyWindow(hwnd);
5711 }
5712
5713 /************* painting message test ********************/
5714
5715 void dump_region(HRGN hrgn)
5716 {
5717 DWORD i, size;
5718 RGNDATA *data = NULL;
5719 RECT *rect;
5720
5721 if (!hrgn)
5722 {
5723 printf( "null region\n" );
5724 return;
5725 }
5726 if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
5727 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
5728 GetRegionData( hrgn, size, data );
5729 printf("%d rects:", data->rdh.nCount );
5730 for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
5731 printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
5732 printf("\n");
5733 HeapFree( GetProcessHeap(), 0, data );
5734 }
5735
5736 static void check_update_rgn( HWND hwnd, HRGN hrgn )
5737 {
5738 INT ret;
5739 RECT r1, r2;
5740 HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
5741 HRGN update = CreateRectRgn( 0, 0, 0, 0 );
5742
5743 ret = GetUpdateRgn( hwnd, update, FALSE );
5744 ok( ret != ERROR, "GetUpdateRgn failed\n" );
5745 if (ret == NULLREGION)
5746 {
5747 ok( !hrgn, "Update region shouldn't be empty\n" );
5748 }
5749 else
5750 {
5751 if (CombineRgn( tmp, hrgn, update, RGN_XOR ) != NULLREGION)
5752 {
5753 ok( 0, "Regions are different\n" );
5754 if (winetest_debug > 0)
5755 {
5756 printf( "Update region: " );
5757 dump_region( update );
5758 printf( "Wanted region: " );
5759 dump_region( hrgn );
5760 }
5761 }
5762 }
5763 GetRgnBox( update, &r1 );
5764 GetUpdateRect( hwnd, &r2, FALSE );
5765 ok( r1.left == r2.left && r1.top == r2.top && r1.right == r2.right && r1.bottom == r2.bottom,
5766 "Rectangles are different: %d,%d-%d,%d / %d,%d-%d,%d\n",
5767 r1.left, r1.top, r1.right, r1.bottom, r2.left, r2.top, r2.right, r2.bottom );
5768
5769 DeleteObject( tmp );
5770 DeleteObject( update );
5771 }
5772
5773 static const struct message WmInvalidateRgn[] = {
5774 { WM_NCPAINT, sent },
5775 { WM_GETTEXT, sent|defwinproc|optional },
5776 { 0 }
5777 };
5778
5779 static const struct message WmGetUpdateRect[] = {
5780 { WM_NCPAINT, sent },
5781 { WM_GETTEXT, sent|defwinproc|optional },
5782 { WM_PAINT, sent },
5783 { 0 }
5784 };
5785
5786 static const struct message WmInvalidateFull[] = {
5787 { WM_NCPAINT, sent|wparam, 1 },
5788 { WM_GETTEXT, sent|defwinproc|optional },
5789 { 0 }
5790 };
5791
5792 static const struct message WmInvalidateErase[] = {
5793 { WM_NCPAINT, sent|wparam, 1 },
5794 { WM_GETTEXT, sent|defwinproc|optional },
5795 { WM_ERASEBKGND, sent },
5796 { 0 }
5797 };
5798
5799 static const struct message WmInvalidatePaint[] = {
5800 { WM_PAINT, sent },
5801 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5802 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5803 { 0 }
5804 };
5805
5806 static const struct message WmInvalidateErasePaint[] = {
5807 { WM_PAINT, sent },
5808 { WM_NCPAINT, sent|wparam|beginpaint, 1 },
5809 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5810 { WM_ERASEBKGND, sent|beginpaint|optional },
5811 { 0 }
5812 };
5813
5814 static const struct message WmInvalidateErasePaint2[] = {
5815 { WM_PAINT, sent },
5816 { WM_NCPAINT, sent|beginpaint },
5817 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5818 { WM_ERASEBKGND, sent|beginpaint|optional },
5819 { 0 }
5820 };
5821
5822 static const struct message WmErase[] = {
5823 { WM_ERASEBKGND, sent },
5824 { 0 }
5825 };
5826
5827 static const struct message WmPaint[] = {
5828 { WM_PAINT, sent },
5829 { 0 }
5830 };
5831
5832 static const struct message WmParentOnlyPaint[] = {
5833 { WM_PAINT, sent|parent },
5834 { 0 }
5835 };
5836
5837 static const struct message WmInvalidateParent[] = {
5838 { WM_NCPAINT, sent|parent },
5839 { WM_GETTEXT, sent|defwinproc|parent|optional },
5840 { WM_ERASEBKGND, sent|parent },
5841 { 0 }
5842 };
5843
5844 static const struct message WmInvalidateParentChild[] = {
5845 { WM_NCPAINT, sent|parent },
5846 { WM_GETTEXT, sent|defwinproc|parent|optional },
5847 { WM_ERASEBKGND, sent|parent },
5848 { WM_NCPAINT, sent },
5849 { WM_GETTEXT, sent|defwinproc|optional },
5850 { WM_ERASEBKGND, sent },
5851 { 0 }
5852 };
5853
5854 static const struct message WmInvalidateParentChild2[] = {
5855 { WM_ERASEBKGND, sent|parent },
5856 { WM_NCPAINT, sent },
5857 { WM_GETTEXT, sent|defwinproc|optional },
5858 { WM_ERASEBKGND, sent },
5859 { 0 }
5860 };
5861
5862 static const struct message WmParentPaint[] = {
5863 { WM_PAINT, sent|parent },
5864 { WM_PAINT, sent },
5865 { 0 }
5866 };
5867
5868 static const struct message WmParentPaintNc[] = {
5869 { WM_PAINT, sent|parent },
5870 { WM_PAINT, sent },
5871 { WM_NCPAINT, sent|beginpaint },
5872 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5873 { WM_ERASEBKGND, sent|beginpaint|optional },
5874 { 0 }
5875 };
5876
5877 static const struct message WmChildPaintNc[] = {
5878 { WM_PAINT, sent },
5879 { WM_NCPAINT, sent|beginpaint },
5880 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5881 { WM_ERASEBKGND, sent|beginpaint|optional },
5882 { 0 }
5883 };
5884
5885 static const struct message WmParentErasePaint[] = {
5886 { WM_PAINT, sent|parent },
5887 { WM_NCPAINT, sent|parent|beginpaint },
5888 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5889 { WM_ERASEBKGND, sent|parent|beginpaint|optional },
5890 { WM_PAINT, sent },
5891 { WM_NCPAINT, sent|beginpaint },
5892 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
5893 { WM_ERASEBKGND, sent|beginpaint|optional },
5894 { 0 }
5895 };
5896
5897 static const struct message WmParentOnlyNcPaint[] = {
5898 { WM_PAINT, sent|parent },
5899 { WM_NCPAINT, sent|parent|beginpaint },
5900 { WM_GETTEXT, sent|parent|beginpaint|defwinproc|optional },
5901 { 0 }
5902 };
5903
5904 static const struct message WmSetParentStyle[] = {
5905 { WM_STYLECHANGING, sent|parent },
5906 { WM_STYLECHANGED, sent|parent },
5907 { 0 }
5908 };
5909
5910 static void test_paint_messages(void)
5911 {
5912 BOOL ret;
5913 RECT rect;
5914 POINT pt;
5915 MSG msg;
5916 HWND hparent, hchild;
5917 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
5918 HRGN hrgn2 = CreateRectRgn( 0, 0, 0, 0 );
5919 HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
5920 100, 100, 200, 200, 0, 0, 0, NULL);
5921 ok (hwnd != 0, "Failed to create overlapped window\n");
5922
5923 ShowWindow( hwnd, SW_SHOW );
5924 UpdateWindow( hwnd );
5925 flush_events();
5926 flush_sequence();
5927
5928 check_update_rgn( hwnd, 0 );
5929 SetRectRgn( hrgn, 10, 10, 20, 20 );
5930 ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5931 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5932 check_update_rgn( hwnd, hrgn );
5933 SetRectRgn( hrgn2, 20, 20, 30, 30 );
5934 ret = RedrawWindow( hwnd, NULL, hrgn2, RDW_INVALIDATE );
5935 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5936 CombineRgn( hrgn, hrgn, hrgn2, RGN_OR );
5937 check_update_rgn( hwnd, hrgn );
5938 /* validate everything */
5939 ret = RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5940 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5941 check_update_rgn( hwnd, 0 );
5942
5943 /* test empty region */
5944 SetRectRgn( hrgn, 10, 10, 10, 15 );
5945 ret = RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
5946 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5947 check_update_rgn( hwnd, 0 );
5948 /* test empty rect */
5949 SetRect( &rect, 10, 10, 10, 15 );
5950 ret = RedrawWindow( hwnd, &rect, NULL, RDW_INVALIDATE );
5951 ok(ret, "RedrawWindow returned %d instead of TRUE\n", ret);
5952 check_update_rgn( hwnd, 0 );
5953
5954 /* flush pending messages */
5955 flush_events();
5956 flush_sequence();
5957
5958 GetClientRect( hwnd, &rect );
5959 SetRectRgn( hrgn, 0, 0, rect.right - rect.left, rect.bottom - rect.top );
5960 /* MSDN: if hwnd parameter is NULL, InvalidateRect invalidates and redraws
5961 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5962 */
5963 trace("testing InvalidateRect(0, NULL, FALSE)\n");
5964 SetRectEmpty( &rect );
5965 ok(InvalidateRect(0, &rect, FALSE), "InvalidateRect(0, &rc, FALSE) should fail\n");
5966 check_update_rgn( hwnd, hrgn );
5967 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5968 flush_events();
5969 ok_sequence( WmPaint, "Paint", FALSE );
5970 RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5971 check_update_rgn( hwnd, 0 );
5972
5973 /* MSDN: if hwnd parameter is NULL, ValidateRect invalidates and redraws
5974 * all windows and sends WM_ERASEBKGND and WM_NCPAINT.
5975 */
5976 trace("testing ValidateRect(0, NULL)\n");
5977 SetRectEmpty( &rect );
5978 if (ValidateRect(0, &rect)) /* not supported on Win9x */
5979 {
5980 check_update_rgn( hwnd, hrgn );
5981 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
5982 flush_events();
5983 ok_sequence( WmPaint, "Paint", FALSE );
5984 RedrawWindow( hwnd, NULL, NULL, RDW_VALIDATE );
5985 check_update_rgn( hwnd, 0 );
5986 }
5987
5988 trace("testing InvalidateRgn(0, NULL, FALSE)\n");
5989 SetLastError(0xdeadbeef);
5990 ok(!InvalidateRgn(0, NULL, FALSE), "InvalidateRgn(0, NULL, FALSE) should fail\n");
5991 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || GetLastError() == 0xdeadbeef,
5992 "wrong error code %d\n", GetLastError());
5993 check_update_rgn( hwnd, 0 );
5994 flush_events();
5995 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
5996
5997 trace("testing ValidateRgn(0, NULL)\n");
5998 SetLastError(0xdeadbeef);
5999 ok(!ValidateRgn(0, NULL), "ValidateRgn(0, NULL) should fail\n");
6000 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
6001 broken( GetLastError() == 0xdeadbeef ) /* win9x */,
6002 "wrong error code %d\n", GetLastError());
6003 check_update_rgn( hwnd, 0 );
6004 flush_events();
6005 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
6006
6007 /* now with frame */
6008 SetRectRgn( hrgn, -5, -5, 20, 20 );
6009
6010 /* flush pending messages */
6011 flush_events();
6012 flush_sequence();
6013 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6014 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
6015
6016 SetRectRgn( hrgn, 0, 0, 20, 20 ); /* GetUpdateRgn clips to client area */
6017 check_update_rgn( hwnd, hrgn );
6018
6019 flush_sequence();
6020 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
6021 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
6022
6023 flush_sequence();
6024 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW );
6025 ok_sequence( WmInvalidateFull, "InvalidateFull", FALSE );
6026
6027 GetClientRect( hwnd, &rect );
6028 SetRectRgn( hrgn, rect.left, rect.top, rect.right, rect.bottom );
6029 check_update_rgn( hwnd, hrgn );
6030
6031 flush_sequence();
6032 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ERASENOW );
6033 ok_sequence( WmInvalidateErase, "InvalidateErase", FALSE );
6034
6035 flush_sequence();
6036 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW | RDW_UPDATENOW );
6037 ok_sequence( WmInvalidatePaint, "InvalidatePaint", FALSE );
6038 check_update_rgn( hwnd, 0 );
6039
6040 flush_sequence();
6041 RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_UPDATENOW );
6042 ok_sequence( WmInvalidateErasePaint, "InvalidateErasePaint", FALSE );
6043 check_update_rgn( hwnd, 0 );
6044
6045 flush_sequence();
6046 SetRectRgn( hrgn, 0, 0, 100, 100 );
6047 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE );
6048 SetRectRgn( hrgn, 0, 0, 50, 100 );
6049 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
6050 SetRectRgn( hrgn, 50, 0, 100, 100 );
6051 check_update_rgn( hwnd, hrgn );
6052 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
6053 ok_sequence( WmEmptySeq, "EmptySeq", FALSE ); /* must not generate messages, everything is valid */
6054 check_update_rgn( hwnd, 0 );
6055
6056 flush_sequence();
6057 SetRectRgn( hrgn, 0, 0, 100, 100 );
6058 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
6059 SetRectRgn( hrgn, 0, 0, 100, 50 );
6060 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_ERASENOW );
6061 ok_sequence( WmErase, "Erase", FALSE );
6062 SetRectRgn( hrgn, 0, 50, 100, 100 );
6063 check_update_rgn( hwnd, hrgn );
6064
6065 flush_sequence();
6066 SetRectRgn( hrgn, 0, 0, 100, 100 );
6067 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE );
6068 SetRectRgn( hrgn, 0, 0, 50, 50 );
6069 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOERASE | RDW_UPDATENOW );
6070 ok_sequence( WmPaint, "Paint", FALSE );
6071
6072 flush_sequence();
6073 SetRectRgn( hrgn, -4, -4, -2, -2 );
6074 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6075 SetRectRgn( hrgn, -200, -200, -198, -198 );
6076 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME | RDW_ERASENOW );
6077 ok_sequence( WmEmptySeq, "EmptySeq", FALSE );
6078
6079 flush_sequence();
6080 SetRectRgn( hrgn, -4, -4, -2, -2 );
6081 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6082 SetRectRgn( hrgn, -4, -4, -3, -3 );
6083 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOFRAME );
6084 SetRectRgn( hrgn, 0, 0, 1, 1 );
6085 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_UPDATENOW );
6086 ok_sequence( WmPaint, "Paint", FALSE );
6087
6088 flush_sequence();
6089 SetRectRgn( hrgn, -4, -4, -1, -1 );
6090 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6091 RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW );
6092 /* make sure no WM_PAINT was generated */
6093 flush_events();
6094 ok_sequence( WmInvalidateRgn, "InvalidateRgn", FALSE );
6095
6096 flush_sequence();
6097 SetRectRgn( hrgn, -4, -4, -1, -1 );
6098 RedrawWindow( hwnd, NULL, hrgn, RDW_INVALIDATE | RDW_FRAME );
6099 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
6100 {
6101 if (msg.hwnd == hwnd && msg.message == WM_PAINT)
6102 {
6103 /* GetUpdateRgn must return empty region since only nonclient area is invalidated */
6104 INT ret = GetUpdateRgn( hwnd, hrgn, FALSE );
6105 ok( ret == NULLREGION, "Invalid GetUpdateRgn result %d\n", ret );
6106 ret = GetUpdateRect( hwnd, &rect, FALSE );
6107 ok( ret, "Invalid GetUpdateRect result %d\n", ret );
6108 /* this will send WM_NCPAINT and validate the non client area */
6109 ret = GetUpdateRect( hwnd, &rect, TRUE );
6110 ok( !ret, "Invalid GetUpdateRect result %d\n", ret );
6111 }
6112 DispatchMessage( &msg );
6113 }
6114 ok_sequence( WmGetUpdateRect, "GetUpdateRect", FALSE );
6115
6116 DestroyWindow( hwnd );
6117
6118 /* now test with a child window */
6119
6120 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW,
6121 100, 100, 200, 200, 0, 0, 0, NULL);
6122 ok (hparent != 0, "Failed to create parent window\n");
6123
6124 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE | WS_BORDER,
6125 10, 10, 100, 100, hparent, 0, 0, NULL);
6126 ok (hchild != 0, "Failed to create child window\n");
6127
6128 ShowWindow( hparent, SW_SHOW );
6129 UpdateWindow( hparent );
6130 UpdateWindow( hchild );
6131 flush_events();
6132 flush_sequence();
6133 log_all_parent_messages++;
6134
6135 SetRect( &rect, 0, 0, 50, 50 );
6136 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6137 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6138 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild", FALSE );
6139
6140 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6141 pt.x = pt.y = 0;
6142 MapWindowPoints( hchild, hparent, &pt, 1 );
6143 SetRectRgn( hrgn, 0, 0, 50 - pt.x, 50 - pt.y );
6144 check_update_rgn( hchild, hrgn );
6145 SetRectRgn( hrgn, 0, 0, 50, 50 );
6146 check_update_rgn( hparent, hrgn );
6147 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6148 ok_sequence( WmInvalidateParent, "InvalidateParent", FALSE );
6149 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6150 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6151
6152 flush_events();
6153 ok_sequence( WmParentPaintNc, "WmParentPaintNc", FALSE );
6154
6155 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6156 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6157 ok_sequence( WmInvalidateParent, "InvalidateParent2", FALSE );
6158 RedrawWindow( hchild, NULL, 0, RDW_ERASENOW );
6159 ok_sequence( WmEmptySeq, "EraseNow child", FALSE );
6160
6161 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6162 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW | RDW_ALLCHILDREN );
6163 ok_sequence( WmInvalidateParentChild2, "InvalidateParentChild2", FALSE );
6164
6165 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6166 flush_sequence();
6167 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6168 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6169 ok_sequence( WmInvalidateParentChild, "InvalidateParentChild3", FALSE );
6170
6171 /* flush all paint messages */
6172 flush_events();
6173 flush_sequence();
6174
6175 /* RDW_UPDATENOW on child with WS_CLIPCHILDREN doesn't change corresponding parent area */
6176 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
6177 SetRectRgn( hrgn, 0, 0, 50, 50 );
6178 check_update_rgn( hparent, hrgn );
6179 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6180 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6181 SetRectRgn( hrgn, 0, 0, 50, 50 );
6182 check_update_rgn( hparent, hrgn );
6183
6184 /* flush all paint messages */
6185 flush_events();
6186 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6187 flush_sequence();
6188
6189 /* RDW_UPDATENOW on child without WS_CLIPCHILDREN will validate corresponding parent area */
6190 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6191 SetRectRgn( hrgn, 0, 0, 50, 50 );
6192 check_update_rgn( hparent, hrgn );
6193 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6194 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6195 SetRectRgn( hrgn2, 10, 10, 50, 50 );
6196 CombineRgn( hrgn, hrgn, hrgn2, RGN_DIFF );
6197 check_update_rgn( hparent, hrgn );
6198 /* flush all paint messages */
6199 flush_events();
6200 flush_sequence();
6201
6202 /* same as above but parent gets completely validated */
6203 SetRect( &rect, 20, 20, 30, 30 );
6204 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6205 SetRectRgn( hrgn, 20, 20, 30, 30 );
6206 check_update_rgn( hparent, hrgn );
6207 RedrawWindow( hchild, NULL, 0, RDW_UPDATENOW );
6208 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6209 check_update_rgn( hparent, 0 ); /* no update region */
6210 flush_events();
6211 ok_sequence( WmEmptySeq, "WmEmpty", FALSE ); /* and no paint messages */
6212
6213 /* make sure RDW_VALIDATE on child doesn't have the same effect */
6214 flush_sequence();
6215 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6216 SetRectRgn( hrgn, 20, 20, 30, 30 );
6217 check_update_rgn( hparent, hrgn );
6218 RedrawWindow( hchild, NULL, 0, RDW_VALIDATE | RDW_NOERASE );
6219 SetRectRgn( hrgn, 20, 20, 30, 30 );
6220 check_update_rgn( hparent, hrgn );
6221
6222 /* same as above but normal WM_PAINT doesn't validate parent */
6223 flush_sequence();
6224 SetRect( &rect, 20, 20, 30, 30 );
6225 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6226 SetRectRgn( hrgn, 20, 20, 30, 30 );
6227 check_update_rgn( hparent, hrgn );
6228 /* no WM_PAINT in child while parent still pending */
6229 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6230 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6231 while (PeekMessage( &msg, hparent, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6232 ok_sequence( WmParentErasePaint, "WmParentErasePaint", FALSE );
6233
6234 flush_sequence();
6235 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6236 /* no WM_PAINT in child while parent still pending */
6237 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6238 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6239 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_NOERASE | RDW_NOCHILDREN );
6240 /* now that parent is valid child should get WM_PAINT */
6241 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6242 ok_sequence( WmInvalidateErasePaint2, "WmInvalidateErasePaint2", FALSE );
6243 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6244 ok_sequence( WmEmptySeq, "No other message", FALSE );
6245
6246 /* same thing with WS_CLIPCHILDREN in parent */
6247 flush_sequence();
6248 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) | WS_CLIPCHILDREN );
6249 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6250 /* changing style invalidates non client area, but we need to invalidate something else to see it */
6251 RedrawWindow( hparent, &rect, 0, RDW_UPDATENOW );
6252 ok_sequence( WmEmptySeq, "No message", FALSE );
6253 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_UPDATENOW );
6254 ok_sequence( WmParentOnlyNcPaint, "WmParentOnlyNcPaint", FALSE );
6255
6256 flush_sequence();
6257 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
6258 SetRectRgn( hrgn, 20, 20, 30, 30 );
6259 check_update_rgn( hparent, hrgn );
6260 /* no WM_PAINT in child while parent still pending */
6261 while (PeekMessage( &msg, hchild, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6262 ok_sequence( WmEmptySeq, "No WM_PAINT", FALSE );
6263 /* WM_PAINT in parent first */
6264 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
6265 ok_sequence( WmParentPaintNc, "WmParentPaintNc2", FALSE );
6266
6267 /* no RDW_ERASE in parent still causes RDW_ERASE and RDW_FRAME in child */
6268 flush_sequence();
6269 SetRect( &rect, 0, 0, 30, 30 );
6270 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN );
6271 SetRectRgn( hrgn, 0, 0, 30, 30 );
6272 check_update_rgn( hparent, hrgn );
6273 flush_events();
6274 ok_sequence( WmParentPaintNc, "WmParentPaintNc3", FALSE );
6275
6276 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6277 flush_sequence();
6278 SetRect( &rect, -10, 0, 30, 30 );
6279 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6280 SetRect( &rect, 0, 0, 20, 20 );
6281 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6282 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6283 ok_sequence( WmChildPaintNc, "WmChildPaintNc", FALSE );
6284
6285 /* validate doesn't cause RDW_NOERASE or RDW_NOFRAME in child */
6286 flush_sequence();
6287 SetRect( &rect, -10, 0, 30, 30 );
6288 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE );
6289 SetRect( &rect, 0, 0, 100, 100 );
6290 RedrawWindow( hparent, &rect, 0, RDW_VALIDATE | RDW_ALLCHILDREN );
6291 RedrawWindow( hparent, NULL, 0, RDW_UPDATENOW );
6292 ok_sequence( WmEmptySeq, "WmChildPaintNc2", FALSE );
6293 RedrawWindow( hparent, NULL, 0, RDW_ERASENOW );
6294 ok_sequence( WmEmptySeq, "WmChildPaintNc3", FALSE );
6295
6296 /* test RDW_INTERNALPAINT behavior */
6297
6298 flush_sequence();
6299 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_NOCHILDREN );
6300 flush_events();
6301 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6302
6303 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT | RDW_ALLCHILDREN );
6304 flush_events();
6305 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6306
6307 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6308 flush_events();
6309 ok_sequence( WmParentOnlyPaint, "WmParentOnlyPaint", FALSE );
6310
6311 assert( GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN );
6312 UpdateWindow( hparent );
6313 flush_events();
6314 flush_sequence();
6315 trace("testing SWP_FRAMECHANGED on parent with WS_CLIPCHILDREN\n");
6316 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6317 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6318 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6319 flush_events();
6320 ok_sequence(WmSWP_FrameChanged_clip, "SetWindowPos:FrameChanged_clip", FALSE );
6321
6322 UpdateWindow( hparent );
6323 flush_events();
6324 flush_sequence();
6325 trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent with WS_CLIPCHILDREN\n");
6326 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6327 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6328 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6329 flush_events();
6330 ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6331
6332 SetWindowLong( hparent, GWL_STYLE, GetWindowLong(hparent,GWL_STYLE) & ~WS_CLIPCHILDREN );
6333 ok_sequence( WmSetParentStyle, "WmSetParentStyle", FALSE );
6334 RedrawWindow( hparent, NULL, 0, RDW_INTERNALPAINT );
6335 flush_events();
6336 ok_sequence( WmParentPaint, "WmParentPaint", FALSE );
6337
6338 assert( !(GetWindowLong(hparent, GWL_STYLE) & WS_CLIPCHILDREN) );
6339 UpdateWindow( hparent );
6340 flush_events();
6341 flush_sequence();
6342 trace("testing SWP_FRAMECHANGED on parent without WS_CLIPCHILDREN\n");
6343 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6344 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
6345 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6346 flush_events();
6347 ok_sequence(WmSWP_FrameChanged_noclip, "SetWindowPos:FrameChanged_noclip", FALSE );
6348
6349 UpdateWindow( hparent );
6350 flush_events();
6351 flush_sequence();
6352 trace("testing SWP_FRAMECHANGED|SWP_DEFERERASE on parent without WS_CLIPCHILDREN\n");
6353 RedrawWindow( hchild, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME );
6354 SetWindowPos( hparent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_DEFERERASE |
6355 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
6356 flush_events();
6357 ok_sequence(WmSWP_FrameChangedDeferErase, "SetWindowPos:FrameChangedDeferErase", FALSE );
6358
6359 ok(GetWindowLong( hparent, GWL_STYLE ) & WS_VISIBLE, "parent should be visible\n");
6360 ok(GetWindowLong( hchild, GWL_STYLE ) & WS_VISIBLE, "child should be visible\n");
6361
6362 UpdateWindow( hparent );
6363 flush_events();
6364 flush_sequence();
6365 trace("testing SetWindowPos(-10000, -10000) on child\n");
6366 SetWindowPos( hchild, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6367 check_update_rgn( hchild, 0 );
6368 flush_events();
6369
6370 #if 0 /* this one doesn't pass under Wine yet */
6371 UpdateWindow( hparent );
6372 flush_events();
6373 flush_sequence();
6374 trace("testing ShowWindow(SW_MINIMIZE) on child\n");
6375 ShowWindow( hchild, SW_MINIMIZE );
6376 check_update_rgn( hchild, 0 );
6377 flush_events();
6378 #endif
6379
6380 UpdateWindow( hparent );
6381 flush_events();
6382 flush_sequence();
6383 trace("testing SetWindowPos(-10000, -10000) on parent\n");
6384 SetWindowPos( hparent, 0, -10000, -10000, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER );
6385 check_update_rgn( hparent, 0 );
6386 flush_events();
6387
6388 log_all_parent_messages--;
6389 DestroyWindow( hparent );
6390 ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6391
6392 /* tests for moving windows off-screen (needs simple WS_POPUP windows) */
6393
6394 hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_POPUP | WS_VISIBLE,
6395 100, 100, 200, 200, 0, 0, 0, NULL);
6396 ok (hparent != 0, "Failed to create parent window\n");
6397
6398 hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILD | WS_VISIBLE,
6399 10, 10, 100, 100, hparent, 0, 0, NULL);
6400 ok (hchild != 0, "Failed to create child window\n");
6401
6402 ShowWindow( hparent, SW_SHOW );
6403 UpdateWindow( hparent );
6404 UpdateWindow( hchild );
6405 flush_events();
6406 flush_sequence();
6407
6408 /* moving child outside of parent boundaries changes update region */
6409 SetRect( &rect, 0, 0, 40, 40 );
6410 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6411 SetRectRgn( hrgn, 0, 0, 40, 40 );
6412 check_update_rgn( hchild, hrgn );
6413 MoveWindow( hchild, -10, 10, 100, 100, FALSE );
6414 SetRectRgn( hrgn, 10, 0, 40, 40 );
6415 check_update_rgn( hchild, hrgn );
6416 MoveWindow( hchild, -10, -10, 100, 100, FALSE );
6417 SetRectRgn( hrgn, 10, 10, 40, 40 );
6418 check_update_rgn( hchild, hrgn );
6419
6420 /* moving parent off-screen does too */
6421 SetRect( &rect, 0, 0, 100, 100 );
6422 RedrawWindow( hparent, &rect, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
6423 SetRectRgn( hrgn, 0, 0, 100, 100 );
6424 check_update_rgn( hparent, hrgn );
6425 SetRectRgn( hrgn, 10, 10, 40, 40 );
6426 check_update_rgn( hchild, hrgn );
6427 MoveWindow( hparent, -20, -20, 200, 200, FALSE );
6428 SetRectRgn( hrgn, 20, 20, 100, 100 );
6429 check_update_rgn( hparent, hrgn );
6430 SetRectRgn( hrgn, 30, 30, 40, 40 );
6431 check_update_rgn( hchild, hrgn );
6432
6433 /* invalidated region is cropped by the parent rects */
6434 SetRect( &rect, 0, 0, 50, 50 );
6435 RedrawWindow( hchild, &rect, 0, RDW_INVALIDATE | RDW_ERASE );
6436 SetRectRgn( hrgn, 30, 30, 50, 50 );
6437 check_update_rgn( hchild, hrgn );
6438
6439 DestroyWindow( hparent );
6440 ok(!IsWindow(hchild), "child must be destroyed with its parent\n");
6441 flush_sequence();
6442
6443 DeleteObject( hrgn );
6444 DeleteObject( hrgn2 );
6445 }
6446
6447 struct wnd_event
6448 {
6449 HWND hwnd;
6450 HANDLE grand_child;
6451 HANDLE start_event;
6452 HANDLE stop_event;
6453 };
6454
6455 static DWORD WINAPI thread_proc(void *param)
6456 {
6457 MSG msg;
6458 struct wnd_event *wnd_event = param;
6459
6460 wnd_event->hwnd = CreateWindowExA(0, "TestWindowClass", "window caption text", WS_OVERLAPPEDWINDOW,
6461 100, 100, 200, 200, 0, 0, 0, NULL);
6462 ok(wnd_event->hwnd != 0, "Failed to create overlapped window\n");
6463
6464 SetEvent(wnd_event->start_event);
6465
6466 while (GetMessage(&msg, 0, 0, 0))
6467 {
6468 TranslateMessage(&msg);
6469 DispatchMessage(&msg);
6470 }
6471
6472 ok(IsWindow(wnd_event->hwnd), "window should still exist\n");
6473
6474 return 0;
6475 }
6476
6477 static DWORD CALLBACK create_grand_child_thread( void *param )
6478 {
6479 struct wnd_event *wnd_event = param;
6480 HWND hchild;
6481 MSG msg;
6482
6483 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
6484 WS_CHILD | WS_VISIBLE, 0, 0, 10, 10, wnd_event->hwnd, 0, 0, NULL);
6485 ok (hchild != 0, "Failed to create child window\n");
6486 flush_events();
6487 flush_sequence();
6488 SetEvent( wnd_event->start_event );
6489
6490 for (;;)
6491 {
6492 MsgWaitForMultipleObjects(0, NULL, FALSE, 1000, QS_ALLINPUT);
6493 if (!IsWindow( hchild )) break; /* will be destroyed when parent thread exits */
6494 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6495 }
6496 return 0;
6497 }
6498
6499 static DWORD CALLBACK create_child_thread( void *param )
6500 {
6501 struct wnd_event *wnd_event = param;
6502 struct wnd_event child_event;
6503 DWORD ret, tid;
6504 MSG msg;
6505
6506 child_event.hwnd = CreateWindowExA(0, "TestWindowClass", "Test child",
6507 WS_CHILD | WS_VISIBLE, 0, 0, 10, 10, wnd_event->hwnd, 0, 0, NULL);
6508 ok (child_event.hwnd != 0, "Failed to create child window\n");
6509 SetFocus( child_event.hwnd );
6510 flush_events();
6511 flush_sequence();
6512 child_event.start_event = wnd_event->start_event;
6513 wnd_event->grand_child = CreateThread(NULL, 0, create_grand_child_thread, &child_event, 0, &tid);
6514 for (;;)
6515 {
6516 DWORD ret = MsgWaitForMultipleObjects(1, &child_event.start_event, FALSE, 1000, QS_SENDMESSAGE);
6517 if (ret != 1) break;
6518 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6519 }
6520 ret = WaitForSingleObject( wnd_event->stop_event, 5000 );
6521 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6522 return 0;
6523 }
6524
6525 static void test_interthread_messages(void)
6526 {
6527 HANDLE hThread;
6528 DWORD tid;
6529 WNDPROC proc;
6530 MSG msg;
6531 char buf[256];
6532 int len, expected_len;
6533 struct wnd_event wnd_event;
6534 BOOL ret;
6535
6536 wnd_event.start_event = CreateEventW(NULL, 0, 0, NULL);
6537 if (!wnd_event.start_event)
6538 {
6539 win_skip("skipping interthread message test under win9x\n");
6540 return;
6541 }
6542
6543 hThread = CreateThread(NULL, 0, thread_proc, &wnd_event, 0, &tid);
6544 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
6545
6546 ok(WaitForSingleObject(wnd_event.start_event, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6547
6548 CloseHandle(wnd_event.start_event);
6549
6550 SetLastError(0xdeadbeef);
6551 ok(!DestroyWindow(wnd_event.hwnd), "DestroyWindow succeded\n");
6552 ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == 0xdeadbeef,
6553 "wrong error code %d\n", GetLastError());
6554
6555 proc = (WNDPROC)GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6556 ok(proc != NULL, "GetWindowLongPtrA(GWLP_WNDPROC) error %d\n", GetLastError());
6557
6558 expected_len = lstrlenA("window caption text");
6559 memset(buf, 0, sizeof(buf));
6560 SetLastError(0xdeadbeef);
6561 len = CallWindowProcA(proc, wnd_event.hwnd, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
6562 ok(len == expected_len, "CallWindowProcA(WM_GETTEXT) error %d, len %d, expected len %d\n", GetLastError(), len, expected_len);
6563 ok(!lstrcmpA(buf, "window caption text"), "window text mismatch\n");
6564
6565 msg.hwnd = wnd_event.hwnd;
6566 msg.message = WM_GETTEXT;
6567 msg.wParam = sizeof(buf);
6568 msg.lParam = (LPARAM)buf;
6569 memset(buf, 0, sizeof(buf));
6570 SetLastError(0xdeadbeef);
6571 len = DispatchMessageA(&msg);
6572 ok((!len && GetLastError() == ERROR_MESSAGE_SYNC_ONLY) || broken(len), /* nt4 */
6573 "DispatchMessageA(WM_GETTEXT) succeded on another thread window: ret %d, error %d\n", len, GetLastError());
6574
6575 /* the following test causes an exception in user.exe under win9x */
6576 msg.hwnd = wnd_event.hwnd;
6577 msg.message = WM_TIMER;
6578 msg.wParam = 0;
6579 msg.lParam = GetWindowLongPtrA(wnd_event.hwnd, GWLP_WNDPROC);
6580 SetLastError(0xdeadbeef);
6581 len = DispatchMessageA(&msg);
6582 ok(!len && GetLastError() == 0xdeadbeef,
6583 "DispatchMessageA(WM_TIMER) failed on another thread window: ret %d, error %d\n", len, GetLastError());
6584
6585 ret = PostMessageA(wnd_event.hwnd, WM_QUIT, 0, 0);
6586 ok( ret, "PostMessageA(WM_QUIT) error %d\n", GetLastError());
6587
6588 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
6589 CloseHandle(hThread);
6590
6591 ok(!IsWindow(wnd_event.hwnd), "window should be destroyed on thread exit\n");
6592
6593 wnd_event.hwnd = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6594 100, 100, 200, 200, 0, 0, 0, NULL);
6595 ok (wnd_event.hwnd != 0, "Failed to create parent window\n");
6596 flush_sequence();
6597 log_all_parent_messages++;
6598 wnd_event.start_event = CreateEventA( NULL, TRUE, FALSE, NULL );
6599 wnd_event.stop_event = CreateEventA( NULL, TRUE, FALSE, NULL );
6600 hThread = CreateThread( NULL, 0, create_child_thread, &wnd_event, 0, &tid );
6601 for (;;)
6602 {
6603 ret = MsgWaitForMultipleObjects(1, &wnd_event.start_event, FALSE, 1000, QS_SENDMESSAGE);
6604 if (ret != 1) break;
6605 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
6606 }
6607 ok( !ret, "MsgWaitForMultipleObjects failed %x\n", ret );
6608 /* now wait for the thread without processing messages; this shouldn't deadlock */
6609 SetEvent( wnd_event.stop_event );
6610 ret = WaitForSingleObject( hThread, 5000 );
6611 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6612 CloseHandle( hThread );
6613
6614 ret = WaitForSingleObject( wnd_event.grand_child, 5000 );
6615 ok( !ret, "WaitForSingleObject failed %x\n", ret );
6616 CloseHandle( wnd_event.grand_child );
6617
6618 CloseHandle( wnd_event.start_event );
6619 CloseHandle( wnd_event.stop_event );
6620 flush_events();
6621 ok_sequence(WmExitThreadSeq, "destroy child on thread exit", FALSE);
6622 log_all_parent_messages--;
6623 DestroyWindow( wnd_event.hwnd );
6624 }
6625
6626
6627 static const struct message WmVkN[] = {
6628 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6629 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6630 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6631 { WM_CHAR, wparam|lparam, 'n', 1 },
6632 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1002,1), 0 },
6633 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6634 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6635 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6636 { 0 }
6637 };
6638 static const struct message WmShiftVkN[] = {
6639 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6640 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6641 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6642 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6643 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6644 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6645 { WM_CHAR, wparam|lparam, 'N', 1 },
6646 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1001,1), 0 },
6647 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6648 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6649 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6650 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6651 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6652 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6653 { 0 }
6654 };
6655 static const struct message WmCtrlVkN[] = {
6656 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6657 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6658 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6659 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6660 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6661 { WM_KEYDOWN, sent|wparam|lparam, 'N', 1 },
6662 { WM_CHAR, wparam|lparam, 0x000e, 1 },
6663 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6664 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6665 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6666 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6667 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6668 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6669 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6670 { 0 }
6671 };
6672 static const struct message WmCtrlVkN_2[] = {
6673 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6674 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6675 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6676 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6677 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6678 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1000,1), 0 },
6679 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6680 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6681 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6682 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6683 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6684 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6685 { 0 }
6686 };
6687 static const struct message WmAltVkN[] = {
6688 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6689 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6690 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6691 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6692 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6693 { WM_SYSKEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6694 { WM_SYSCHAR, wparam|lparam, 'n', 0x20000001 },
6695 { WM_SYSCHAR, sent|wparam|lparam, 'n', 0x20000001 },
6696 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 'n' },
6697 { HCBT_SYSCOMMAND, hook },
6698 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6699 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6700 { 0x00AE, sent|defwinproc|optional }, /* XP */
6701 { WM_GETTEXT, sent|defwinproc|optional }, /* XP */
6702 { WM_INITMENU, sent|defwinproc },
6703 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6704 { WM_MENUCHAR, sent|defwinproc|wparam, MAKEWPARAM('n',MF_SYSMENU) },
6705 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
6706 { WM_CAPTURECHANGED, sent|defwinproc },
6707 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,0xffff) },
6708 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6709 { WM_EXITMENULOOP, sent|defwinproc },
6710 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) }, /* Win95 bug */
6711 { WM_EXITMENULOOP, sent|defwinproc|optional }, /* Win95 bug */
6712 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6713 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6714 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6715 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6716 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6717 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6718 { 0 }
6719 };
6720 static const struct message WmAltVkN_2[] = {
6721 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6722 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6723 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6724 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6725 { WM_SYSKEYDOWN, wparam|lparam, 'N', 0x20000001 },
6726 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1003,1), 0 },
6727 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6728 { WM_SYSKEYUP, wparam|lparam, 'N', 0xe0000001 },
6729 { WM_SYSKEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6730 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6731 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6732 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6733 { 0 }
6734 };
6735 static const struct message WmCtrlAltVkN[] = {
6736 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6737 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6738 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6739 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6740 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6741 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6742 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6743 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6744 { WM_KEYDOWN, sent|wparam|lparam, 'N', 0x20000001 },
6745 { WM_CHAR, optional },
6746 { WM_CHAR, sent|optional },
6747 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6748 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6749 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6750 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6751 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6752 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6753 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6754 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6755 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6756 { 0 }
6757 };
6758 static const struct message WmCtrlShiftVkN[] = {
6759 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6760 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6761 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6762 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6763 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6764 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6765 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
6766 { WM_KEYDOWN, wparam|lparam, 'N', 1 },
6767 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1004,1), 0 },
6768 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
6769 { WM_KEYUP, wparam|lparam, 'N', 0xc0000001 },
6770 { WM_KEYUP, sent|wparam|lparam, 'N', 0xc0000001 },
6771 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6772 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6773 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6774 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6775 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6776 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6777 { 0 }
6778 };
6779 static const struct message WmCtrlAltShiftVkN[] = {
6780 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 1 }, /* XP */
6781 { WM_KEYDOWN, wparam|lparam, VK_CONTROL, 1 },
6782 { WM_KEYDOWN, sent|wparam|lparam, VK_CONTROL, 1 },
6783 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6784 { WM_KEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6785 { WM_KEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6786 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0x20000001 }, /* XP */
6787 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 0x20000001 },
6788 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 0x20000001 },
6789 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x20000001 }, /* XP */
6790 { WM_KEYDOWN, wparam|lparam, 'N', 0x20000001 },
6791 { WM_COMMAND, sent|wparam|lparam, MAKEWPARAM(1005,1), 0 },
6792 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xe0000001 }, /* XP */
6793 { WM_KEYUP, wparam|lparam, 'N', 0xe0000001 },
6794 { WM_KEYUP, sent|wparam|lparam, 'N', 0xe0000001 },
6795 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xe0000001 }, /* XP */
6796 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xe0000001 },
6797 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xe0000001 },
6798 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6799 { WM_KEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6800 { WM_KEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6801 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_CONTROL, 0xc0000001 }, /* XP */
6802 { WM_KEYUP, wparam|lparam, VK_CONTROL, 0xc0000001 },
6803 { WM_KEYUP, sent|wparam|lparam, VK_CONTROL, 0xc0000001 },
6804 { 0 }
6805 };
6806 static const struct message WmAltPressRelease[] = {
6807 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 }, /* XP */
6808 { WM_SYSKEYDOWN, wparam|lparam, VK_MENU, 0x20000001 },
6809 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
6810 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6811 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6812 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6813 { WM_SYSCOMMAND, sent|defwinproc|wparam|lparam, SC_KEYMENU, 0 },
6814 { HCBT_SYSCOMMAND, hook },
6815 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6816 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6817 { WM_INITMENU, sent|defwinproc },
6818 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6819 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6820 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6821
6822 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x30000001 }, /* XP */
6823
6824 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6825 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
6826 { WM_CAPTURECHANGED, sent|defwinproc },
6827 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
6828 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6829 { WM_EXITMENULOOP, sent|defwinproc },
6830 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xc0000001 }, /* XP */
6831 { WM_SYSKEYUP, wparam|lparam, VK_MENU, 0xc0000001 },
6832 { WM_SYSKEYUP, sent|wparam|lparam, VK_MENU, 0xc0000001 },
6833 { 0 }
6834 };
6835 static const struct message WmShiftMouseButton[] = {
6836 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 1 }, /* XP */
6837 { WM_KEYDOWN, wparam|lparam, VK_SHIFT, 1 },
6838 { WM_KEYDOWN, sent|wparam|lparam, VK_SHIFT, 1 },
6839 { WM_MOUSEMOVE, wparam|optional, 0, 0 },
6840 { WM_MOUSEMOVE, sent|wparam|optional, 0, 0 },
6841 { WM_LBUTTONDOWN, wparam, MK_LBUTTON|MK_SHIFT, 0 },
6842 { WM_LBUTTONDOWN, sent|wparam, MK_LBUTTON|MK_SHIFT, 0 },
6843 { WM_LBUTTONUP, wparam, MK_SHIFT, 0 },
6844 { WM_LBUTTONUP, sent|wparam, MK_SHIFT, 0 },
6845 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_SHIFT, 0xc0000001 }, /* XP */
6846 { WM_KEYUP, wparam|lparam, VK_SHIFT, 0xc0000001 },
6847 { WM_KEYUP, sent|wparam|lparam, VK_SHIFT, 0xc0000001 },
6848 { 0 }
6849 };
6850 static const struct message WmF1Seq[] = {
6851 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 1 }, /* XP */
6852 { WM_KEYDOWN, wparam|lparam, VK_F1, 1 },
6853 { WM_KEYDOWN, sent|wparam|lparam, VK_F1, 0x00000001 },
6854 { WM_KEYF1, wparam|lparam, 0, 0 },
6855 { WM_KEYF1, sent|wparam|lparam, 0, 0 },
6856 { WM_HELP, sent|defwinproc },
6857 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F1, 0xc0000001 }, /* XP */
6858 { WM_KEYUP, wparam|lparam, VK_F1, 0xc0000001 },
6859 { WM_KEYUP, sent|wparam|lparam, VK_F1, 0xc0000001 },
6860 { 0 }
6861 };
6862 static const struct message WmVkAppsSeq[] = {
6863 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 1 }, /* XP */
6864 { WM_KEYDOWN, wparam|lparam, VK_APPS, 1 },
6865 { WM_KEYDOWN, sent|wparam|lparam, VK_APPS, 0x00000001 },
6866 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_APPS, 0xc0000001 }, /* XP */
6867 { WM_KEYUP, wparam|lparam, VK_APPS, 0xc0000001 },
6868 { WM_KEYUP, sent|wparam|lparam, VK_APPS, 0xc0000001 },
6869 { WM_CONTEXTMENU, lparam, /*hwnd*/0, (LPARAM)-1 },
6870 { WM_CONTEXTMENU, sent|lparam, /*hwnd*/0, (LPARAM)-1 },
6871 { 0 }
6872 };
6873 static const struct message WmVkF10Seq[] = {
6874 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
6875 { WM_SYSKEYDOWN, wparam|lparam, VK_F10, 1 },
6876 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_F10, 0x00000001 },
6877 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
6878 { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
6879 { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
6880 { WM_SYSCOMMAND, sent|defwinproc|wparam, SC_KEYMENU },
6881 { HCBT_SYSCOMMAND, hook },
6882 { WM_ENTERMENULOOP, sent|defwinproc|wparam|lparam, 0, 0 },
6883 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
6884 { WM_INITMENU, sent|defwinproc },
6885 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6886 { WM_MENUSELECT, sent|defwinproc|wparam, MAKEWPARAM(0,MF_SYSMENU|MF_POPUP|MF_HILITE) },
6887 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
6888
6889 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0x10000001 }, /* XP */
6890
6891 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 1 }, /* XP */
6892 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6893 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0, },
6894 { WM_CAPTURECHANGED, sent|defwinproc },
6895 { WM_MENUSELECT, sent|defwinproc|wparam|optional, MAKEWPARAM(0,0xffff) },
6896 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_SYSMENU, 0 },
6897 { WM_EXITMENULOOP, sent|defwinproc },
6898 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_F10, 0xc0000001 }, /* XP */
6899 { WM_SYSKEYUP, wparam|lparam, VK_F10, 0xc0000001 },
6900 { WM_SYSKEYUP, sent|wparam|lparam, VK_F10, 0xc0000001 },
6901 { 0 }
6902 };
6903
6904 static void pump_msg_loop(HWND hwnd, HACCEL hAccel)
6905 {
6906 MSG msg;
6907
6908 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
6909 {
6910 struct recvd_message log_msg;
6911
6912 /* ignore some unwanted messages */
6913 if (msg.message == WM_MOUSEMOVE ||
6914 msg.message == WM_TIMER ||
6915 ignore_message( msg.message ))
6916 continue;
6917
6918 log_msg.hwnd = msg.hwnd;
6919 log_msg.message = msg.message;
6920 log_msg.flags = wparam|lparam;
6921 log_msg.wParam = msg.wParam;
6922 log_msg.lParam = msg.lParam;
6923 log_msg.descr = "accel";
6924 add_message(&log_msg);
6925
6926 if (!hAccel || !TranslateAccelerator(hwnd, hAccel, &msg))
6927 {
6928 TranslateMessage(&msg);
6929 DispatchMessage(&msg);
6930 }
6931 }
6932 }
6933
6934 static void test_accelerators(void)
6935 {
6936 RECT rc;
6937 POINT pt;
6938 SHORT state;
6939 HACCEL hAccel;
6940 HWND hwnd = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6941 100, 100, 200, 200, 0, 0, 0, NULL);
6942 BOOL ret;
6943
6944 assert(hwnd != 0);
6945 UpdateWindow(hwnd);
6946 flush_events();
6947 flush_sequence();
6948
6949 SetFocus(hwnd);
6950 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
6951
6952 state = GetKeyState(VK_SHIFT);
6953 ok(!(state & 0x8000), "wrong Shift state %04x\n", state);
6954 state = GetKeyState(VK_CAPITAL);
6955 ok(state == 0, "wrong CapsLock state %04x\n", state);
6956
6957 hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(1));
6958 assert(hAccel != 0);
6959
6960 flush_events();
6961 pump_msg_loop(hwnd, 0);
6962 flush_sequence();
6963
6964 trace("testing VK_N press/release\n");
6965 flush_sequence();
6966 keybd_event('N', 0, 0, 0);
6967 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6968 pump_msg_loop(hwnd, hAccel);
6969 if (!sequence_cnt) /* we didn't get any message */
6970 {
6971 skip( "queuing key events not supported\n" );
6972 goto done;
6973 }
6974 ok_sequence(WmVkN, "VK_N press/release", FALSE);
6975
6976 trace("testing Shift+VK_N press/release\n");
6977 flush_sequence();
6978 keybd_event(VK_SHIFT, 0, 0, 0);
6979 keybd_event('N', 0, 0, 0);
6980 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6981 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
6982 pump_msg_loop(hwnd, hAccel);
6983 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
6984
6985 trace("testing Ctrl+VK_N press/release\n");
6986 flush_sequence();
6987 keybd_event(VK_CONTROL, 0, 0, 0);
6988 keybd_event('N', 0, 0, 0);
6989 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6990 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
6991 pump_msg_loop(hwnd, hAccel);
6992 ok_sequence(WmCtrlVkN, "Ctrl+VK_N press/release", FALSE);
6993
6994 trace("testing Alt+VK_N press/release\n");
6995 flush_sequence();
6996 keybd_event(VK_MENU, 0, 0, 0);
6997 keybd_event('N', 0, 0, 0);
6998 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
6999 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7000 pump_msg_loop(hwnd, hAccel);
7001 ok_sequence(WmAltVkN, "Alt+VK_N press/release", FALSE);
7002
7003 trace("testing Ctrl+Alt+VK_N press/release 1\n");
7004 flush_sequence();
7005 keybd_event(VK_CONTROL, 0, 0, 0);
7006 keybd_event(VK_MENU, 0, 0, 0);
7007 keybd_event('N', 0, 0, 0);
7008 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7009 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7010 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7011 pump_msg_loop(hwnd, hAccel);
7012 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 1", FALSE);
7013
7014 ret = DestroyAcceleratorTable(hAccel);
7015 ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7016
7017 hAccel = LoadAccelerators(GetModuleHandleA(0), MAKEINTRESOURCE(2));
7018 assert(hAccel != 0);
7019
7020 trace("testing VK_N press/release\n");
7021 flush_sequence();
7022 keybd_event('N', 0, 0, 0);
7023 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7024 pump_msg_loop(hwnd, hAccel);
7025 ok_sequence(WmVkN, "VK_N press/release", FALSE);
7026
7027 trace("testing Shift+VK_N press/release\n");
7028 flush_sequence();
7029 keybd_event(VK_SHIFT, 0, 0, 0);
7030 keybd_event('N', 0, 0, 0);
7031 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7032 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7033 pump_msg_loop(hwnd, hAccel);
7034 ok_sequence(WmShiftVkN, "Shift+VK_N press/release", FALSE);
7035
7036 trace("testing Ctrl+VK_N press/release 2\n");
7037 flush_sequence();
7038 keybd_event(VK_CONTROL, 0, 0, 0);
7039 keybd_event('N', 0, 0, 0);
7040 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7041 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7042 pump_msg_loop(hwnd, hAccel);
7043 ok_sequence(WmCtrlVkN_2, "Ctrl+VK_N press/release 2", FALSE);
7044
7045 trace("testing Alt+VK_N press/release 2\n");
7046 flush_sequence();
7047 keybd_event(VK_MENU, 0, 0, 0);
7048 keybd_event('N', 0, 0, 0);
7049 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7050 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7051 pump_msg_loop(hwnd, hAccel);
7052 ok_sequence(WmAltVkN_2, "Alt+VK_N press/release 2", FALSE);
7053
7054 trace("testing Ctrl+Alt+VK_N press/release 2\n");
7055 flush_sequence();
7056 keybd_event(VK_CONTROL, 0, 0, 0);
7057 keybd_event(VK_MENU, 0, 0, 0);
7058 keybd_event('N', 0, 0, 0);
7059 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7060 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7061 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7062 pump_msg_loop(hwnd, hAccel);
7063 ok_sequence(WmCtrlAltVkN, "Ctrl+Alt+VK_N press/release 2", FALSE);
7064
7065 trace("testing Ctrl+Shift+VK_N press/release\n");
7066 flush_sequence();
7067 keybd_event(VK_CONTROL, 0, 0, 0);
7068 keybd_event(VK_SHIFT, 0, 0, 0);
7069 keybd_event('N', 0, 0, 0);
7070 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7071 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7072 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7073 pump_msg_loop(hwnd, hAccel);
7074 ok_sequence(WmCtrlShiftVkN, "Ctrl+Shift+VK_N press/release", FALSE);
7075
7076 trace("testing Ctrl+Alt+Shift+VK_N press/release\n");
7077 flush_sequence();
7078 keybd_event(VK_CONTROL, 0, 0, 0);
7079 keybd_event(VK_MENU, 0, 0, 0);
7080 keybd_event(VK_SHIFT, 0, 0, 0);
7081 keybd_event('N', 0, 0, 0);
7082 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
7083 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7084 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7085 keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
7086 pump_msg_loop(hwnd, hAccel);
7087 ok_sequence(WmCtrlAltShiftVkN, "Ctrl+Alt+Shift+VK_N press/release", FALSE);
7088
7089 ret = DestroyAcceleratorTable(hAccel);
7090 ok( ret, "DestroyAcceleratorTable error %d\n", GetLastError());
7091 hAccel = 0;
7092
7093 trace("testing Alt press/release\n");
7094 flush_sequence();
7095 keybd_event(VK_MENU, 0, 0, 0);
7096 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7097 keybd_event(VK_MENU, 0, 0, 0);
7098 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
7099 pump_msg_loop(hwnd, 0);
7100 /* this test doesn't pass in Wine for managed windows */
7101 ok_sequence(WmAltPressRelease, "Alt press/release", TRUE);
7102
7103 trace("testing VK_F1 press/release\n");
7104 keybd_event(VK_F1, 0, 0, 0);
7105 keybd_event(VK_F1, 0, KEYEVENTF_KEYUP, 0);
7106 pump_msg_loop(hwnd, 0);
7107 ok_sequence(WmF1Seq, "F1 press/release", FALSE);
7108
7109 trace("testing VK_APPS press/release\n");
7110 keybd_event(VK_APPS, 0, 0, 0);
7111 keybd_event(VK_APPS, 0, KEYEVENTF_KEYUP, 0);
7112 pump_msg_loop(hwnd, 0);
7113 ok_sequence(WmVkAppsSeq, "VK_APPS press/release", FALSE);
7114
7115 trace("testing VK_F10 press/release\n");
7116 keybd_event(VK_F10, 0, 0, 0);
7117 keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7118 keybd_event(VK_F10, 0, 0, 0);
7119 keybd_event(VK_F10, 0, KEYEVENTF_KEYUP, 0);
7120 pump_msg_loop(hwnd, 0);
7121 ok_sequence(WmVkF10Seq, "VK_F10 press/release", TRUE);
7122
7123 trace("testing Shift+MouseButton press/release\n");
7124 /* first, move mouse pointer inside of the window client area */
7125 GetClientRect(hwnd, &rc);
7126 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
7127 rc.left += (rc.right - rc.left)/2;
7128 rc.top += (rc.bottom - rc.top)/2;
7129 SetCursorPos(rc.left, rc.top);
7130 SetActiveWindow(hwnd);
7131
7132 flush_events();
7133 flush_sequence();
7134 GetCursorPos(&pt);
7135 if (pt.x == rc.left && pt.y == rc.top)
7136 {
7137 int i;
7138 keybd_event(VK_SHIFT, 0, 0, 0);
7139 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
7140 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
7141 keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
7142 pump_msg_loop(hwnd, 0);
7143 for (i = 0; i < sequence_cnt; i++) if (sequence[i].message == WM_LBUTTONDOWN) break;
7144 if (i < sequence_cnt)
7145 ok_sequence(WmShiftMouseButton, "Shift+MouseButton press/release", FALSE);
7146 else
7147 skip( "Shift+MouseButton event didn't get to the window\n" );
7148 }
7149
7150 done:
7151 if (hAccel) DestroyAcceleratorTable(hAccel);
7152 DestroyWindow(hwnd);
7153 }
7154
7155 /************* window procedures ********************/
7156
7157 static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message,
7158 WPARAM wParam, LPARAM lParam)
7159 {
7160 static LONG defwndproc_counter = 0;
7161 static LONG beginpaint_counter = 0;
7162 LRESULT ret;
7163 struct recvd_message msg;
7164
7165 if (ignore_message( message )) return 0;
7166
7167 switch (message)
7168 {
7169 case WM_ENABLE:
7170 {
7171 LONG style = GetWindowLongA(hwnd, GWL_STYLE);
7172 ok((BOOL)wParam == !(style & WS_DISABLED),
7173 "wrong WS_DISABLED state: %ld != %d\n", wParam, !(style & WS_DISABLED));
7174 break;
7175 }
7176
7177 case WM_CAPTURECHANGED:
7178 if (test_DestroyWindow_flag)
7179 {
7180 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7181 if (style & WS_CHILD)
7182 lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7183 else if (style & WS_POPUP)
7184 lParam = WND_POPUP_ID;
7185 else
7186 lParam = WND_PARENT_ID;
7187 }
7188 break;
7189
7190 case WM_NCDESTROY:
7191 {
7192 HWND capture;
7193
7194 ok(!GetWindow(hwnd, GW_CHILD), "children should be unlinked at this point\n");
7195 capture = GetCapture();
7196 if (capture)
7197 {
7198 ok(capture == hwnd, "capture should NOT be released at this point (capture %p)\n", capture);
7199 trace("current capture %p, releasing...\n", capture);
7200 ReleaseCapture();
7201 }
7202 }
7203 /* fall through */
7204 case WM_DESTROY:
7205 if (pGetAncestor)
7206 ok(pGetAncestor(hwnd, GA_PARENT) != 0, "parent should NOT be unlinked at this point\n");
7207 if (test_DestroyWindow_flag)
7208 {
7209 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
7210 if (style & WS_CHILD)
7211 lParam = GetWindowLongPtrA(hwnd, GWLP_ID);
7212 else if (style & WS_POPUP)
7213 lParam = WND_POPUP_ID;
7214 else
7215 lParam = WND_PARENT_ID;
7216 }
7217 break;
7218
7219 /* test_accelerators() depends on this */
7220 case WM_NCHITTEST:
7221 return HTCLIENT;
7222
7223 /* ignore */
7224 case WM_MOUSEMOVE:
7225 case WM_MOUSEACTIVATE:
7226 case WM_NCMOUSEMOVE:
7227 case WM_SETCURSOR:
7228 case WM_IME_SELECT:
7229 return 0;
7230 }
7231
7232 msg.hwnd = hwnd;
7233 msg.message = message;
7234 msg.flags = sent|wparam|lparam;
7235 if (defwndproc_counter) msg.flags |= defwinproc;
7236 if (beginpaint_counter) msg.flags |= beginpaint;
7237 msg.wParam = wParam;
7238 msg.lParam = lParam;
7239 msg.descr = "MsgCheckProc";
7240 add_message(&msg);
7241
7242 if (message == WM_GETMINMAXINFO && (GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
7243 {
7244 HWND parent = GetParent(hwnd);
7245 RECT rc;
7246 MINMAXINFO *minmax = (MINMAXINFO *)lParam;
7247
7248 GetClientRect(parent, &rc);
7249 trace("parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
7250 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
7251 minmax->ptReserved.x, minmax->ptReserved.y,
7252 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
7253 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
7254 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
7255 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
7256
7257 ok(minmax->ptMaxSize.x == rc.right, "default width of maximized child %d != %d\n",
7258 minmax->ptMaxSize.x, rc.right);
7259 ok(minmax->ptMaxSize.y == rc.bottom, "default height of maximized child %d != %d\n",
7260 minmax->ptMaxSize.y, rc.bottom);
7261 }
7262
7263 if (message == WM_PAINT)
7264 {
7265 PAINTSTRUCT ps;
7266 beginpaint_counter++;
7267 BeginPaint( hwnd, &ps );
7268 beginpaint_counter--;
7269 EndPaint( hwnd, &ps );
7270 return 0;
7271 }
7272
7273 defwndproc_counter++;
7274 ret = unicode ? DefWindowProcW(hwnd, message, wParam, lParam)
7275 : DefWindowProcA(hwnd, message, wParam, lParam);
7276 defwndproc_counter--;
7277
7278 return ret;
7279 }
7280
7281 static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7282 {
7283 return MsgCheckProc (FALSE, hwnd, message, wParam, lParam);
7284 }
7285
7286 static LRESULT WINAPI MsgCheckProcW(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7287 {
7288 return MsgCheckProc (TRUE, hwnd, message, wParam, lParam);
7289 }
7290
7291 static LRESULT WINAPI PopupMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7292 {
7293 static LONG defwndproc_counter = 0;
7294 LRESULT ret;
7295 struct recvd_message msg;
7296
7297 if (ignore_message( message )) return 0;
7298
7299 switch (message)
7300 {
7301 case WM_QUERYENDSESSION:
7302 case WM_ENDSESSION:
7303 lParam &= ~0x01; /* Vista adds a 0x01 flag */
7304 break;
7305 }
7306
7307 msg.hwnd = hwnd;
7308 msg.message = message;
7309 msg.flags = sent|wparam|lparam;
7310 if (defwndproc_counter) msg.flags |= defwinproc;
7311 msg.wParam = wParam;
7312 msg.lParam = lParam;
7313 msg.descr = "popup";
7314 add_message(&msg);
7315
7316 if (message == WM_CREATE)
7317 {
7318 DWORD style = GetWindowLongA(hwnd, GWL_STYLE) | WS_VISIBLE;
7319 SetWindowLongA(hwnd, GWL_STYLE, style);
7320 }
7321
7322 defwndproc_counter++;
7323 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7324 defwndproc_counter--;
7325
7326 return ret;
7327 }
7328
7329 static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7330 {
7331 static LONG defwndproc_counter = 0;
7332 static LONG beginpaint_counter = 0;
7333 LRESULT ret;
7334 struct recvd_message msg;
7335
7336 if (ignore_message( message )) return 0;
7337
7338 if (log_all_parent_messages ||
7339 message == WM_PARENTNOTIFY || message == WM_CANCELMODE ||
7340 message == WM_SETFOCUS || message == WM_KILLFOCUS ||
7341 message == WM_ENABLE || message == WM_ENTERIDLE ||
7342 message == WM_DRAWITEM || message == WM_COMMAND ||
7343 message == WM_IME_SETCONTEXT)
7344 {
7345 switch (message)
7346 {
7347 /* ignore */
7348 case WM_NCHITTEST:
7349 return HTCLIENT;
7350 case WM_SETCURSOR:
7351 case WM_MOUSEMOVE:
7352 case WM_NCMOUSEMOVE:
7353 return 0;
7354
7355 case WM_ERASEBKGND:
7356 {
7357 RECT rc;
7358 INT ret = GetClipBox((HDC)wParam, &rc);
7359
7360 trace("WM_ERASEBKGND: GetClipBox()=%d, (%d,%d-%d,%d)\n",
7361 ret, rc.left, rc.top, rc.right, rc.bottom);
7362 break;
7363 }
7364 }
7365
7366 msg.hwnd = hwnd;
7367 msg.message = message;
7368 msg.flags = sent|parent|wparam|lparam;
7369 if (defwndproc_counter) msg.flags |= defwinproc;
7370 if (beginpaint_counter) msg.flags |= beginpaint;
7371 msg.wParam = wParam;
7372 msg.lParam = lParam;
7373 msg.descr = "parent";
7374 add_message(&msg);
7375 }
7376
7377 if (message == WM_PAINT)
7378 {
7379 PAINTSTRUCT ps;
7380 beginpaint_counter++;
7381 BeginPaint( hwnd, &ps );
7382 beginpaint_counter--;
7383 EndPaint( hwnd, &ps );
7384 return 0;
7385 }
7386
7387 defwndproc_counter++;
7388 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7389 defwndproc_counter--;
7390
7391 return ret;
7392 }
7393
7394 static LRESULT WINAPI TestDlgProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7395 {
7396 static LONG defwndproc_counter = 0;
7397 LRESULT ret;
7398 struct recvd_message msg;
7399
7400 if (ignore_message( message )) return 0;
7401
7402 if (test_def_id)
7403 {
7404 DefDlgProcA(hwnd, DM_SETDEFID, 1, 0);
7405 ret = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
7406 if (after_end_dialog)
7407 ok( ret == 0, "DM_GETDEFID should return 0 after EndDialog, got %lx\n", ret );
7408 else
7409 ok(HIWORD(ret) == DC_HASDEFID, "DM_GETDEFID should return DC_HASDEFID, got %lx\n", ret);
7410 }
7411
7412 msg.hwnd = hwnd;
7413 msg.message = message;
7414 msg.flags = sent|wparam|lparam;
7415 if (defwndproc_counter) msg.flags |= defwinproc;
7416 msg.wParam = wParam;
7417 msg.lParam = lParam;
7418 msg.descr = "dialog";
7419 add_message(&msg);
7420
7421 defwndproc_counter++;
7422 ret = DefDlgProcA(hwnd, message, wParam, lParam);
7423 defwndproc_counter--;
7424
7425 return ret;
7426 }
7427
7428 static LRESULT WINAPI ShowWindowProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
7429 {
7430 static LONG defwndproc_counter = 0;
7431 LRESULT ret;
7432 struct recvd_message msg;
7433
7434 /* log only specific messages we are interested in */
7435 switch (message)
7436 {
7437 #if 0 /* probably log these as well */
7438 case WM_ACTIVATE:
7439 case WM_SETFOCUS:
7440 case WM_KILLFOCUS:
7441 #endif
7442 case WM_SHOWWINDOW:
7443 case WM_SIZE:
7444 case WM_MOVE:
7445 case WM_GETMINMAXINFO:
7446 case WM_WINDOWPOSCHANGING:
7447 case WM_WINDOWPOSCHANGED:
7448 break;
7449
7450 default: /* ignore */
7451 /*trace("showwindow: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);*/
7452 return DefWindowProcA(hwnd, message, wParam, lParam);
7453 }
7454
7455 msg.hwnd = hwnd;
7456 msg.message = message;
7457 msg.flags = sent|wparam|lparam;
7458 if (defwndproc_counter) msg.flags |= defwinproc;
7459 msg.wParam = wParam;
7460 msg.lParam = lParam;
7461 msg.descr = "show";
7462 add_message(&msg);
7463
7464 defwndproc_counter++;
7465 ret = DefWindowProcA(hwnd, message, wParam, lParam);
7466 defwndproc_counter--;
7467
7468 return ret;
7469 }
7470
7471 static LRESULT WINAPI PaintLoopProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
7472 {
7473 switch (msg)
7474 {
7475 case WM_CREATE: return 0;
7476 case WM_PAINT:
7477 {
7478 MSG msg2;
7479 static int i = 0;
7480
7481 if (i < 256)
7482 {
7483 i++;
7484 if (PeekMessageA(&msg2, 0, 0, 0, 1))
7485 {
7486 TranslateMessage(&msg2);
7487 DispatchMessage(&msg2);
7488 }
7489 i--;
7490 }
7491 else ok(broken(1), "infinite loop\n");
7492 if ( i == 0)
7493 paint_loop_done = 1;
7494 return DefWindowProcA(hWnd,msg,wParam,lParam);
7495 }
7496 }
7497 return DefWindowProcA(hWnd,msg,wParam,lParam);
7498 }
7499
7500 static BOOL RegisterWindowClasses(void)
7501 {
7502 WNDCLASSA cls;
7503 WNDCLASSW clsW;
7504
7505 cls.style = 0;
7506 cls.lpfnWndProc = MsgCheckProcA;
7507 cls.cbClsExtra = 0;
7508 cls.cbWndExtra = 0;
7509 cls.hInstance = GetModuleHandleA(0);
7510 cls.hIcon = 0;
7511 cls.hCursor = LoadCursorA(0, IDC_ARROW);
7512 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7513 cls.lpszMenuName = NULL;
7514 cls.lpszClassName = "TestWindowClass";
7515 if(!RegisterClassA(&cls)) return FALSE;
7516
7517 cls.lpfnWndProc = ShowWindowProcA;
7518 cls.lpszClassName = "ShowWindowClass";
7519 if(!RegisterClassA(&cls)) return FALSE;
7520
7521 cls.lpfnWndProc = PopupMsgCheckProcA;
7522 cls.lpszClassName = "TestPopupClass";
7523 if(!RegisterClassA(&cls)) return FALSE;
7524
7525 cls.lpfnWndProc = ParentMsgCheckProcA;
7526 cls.lpszClassName = "TestParentClass";
7527 if(!RegisterClassA(&cls)) return FALSE;
7528
7529 cls.lpfnWndProc = DefWindowProcA;
7530 cls.lpszClassName = "SimpleWindowClass";
7531 if(!RegisterClassA(&cls)) return FALSE;
7532
7533 cls.lpfnWndProc = PaintLoopProcA;
7534 cls.lpszClassName = "PaintLoopWindowClass";
7535 if(!RegisterClassA(&cls)) return FALSE;
7536
7537 cls.style = CS_NOCLOSE;
7538 cls.lpszClassName = "NoCloseWindowClass";
7539 if(!RegisterClassA(&cls)) return FALSE;
7540
7541 ok(GetClassInfoA(0, "#32770", &cls), "GetClassInfo failed\n");
7542 cls.style = 0;
7543 cls.hInstance = GetModuleHandleA(0);
7544 cls.hbrBackground = 0;
7545 cls.lpfnWndProc = TestDlgProcA;
7546 cls.lpszClassName = "TestDialogClass";
7547 if(!RegisterClassA(&cls)) return FALSE;
7548
7549 clsW.style = 0;
7550 clsW.lpfnWndProc = MsgCheckProcW;
7551 clsW.cbClsExtra = 0;
7552 clsW.cbWndExtra = 0;
7553 clsW.hInstance = GetModuleHandleW(0);
7554 clsW.hIcon = 0;
7555 clsW.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
7556 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
7557 clsW.lpszMenuName = NULL;
7558 clsW.lpszClassName = testWindowClassW;
7559 RegisterClassW(&clsW); /* ignore error, this fails on Win9x */
7560
7561 return TRUE;
7562 }
7563
7564 static BOOL is_our_logged_class(HWND hwnd)
7565 {
7566 char buf[256];
7567
7568 if (GetClassNameA(hwnd, buf, sizeof(buf)))
7569 {
7570 if (!lstrcmpiA(buf, "TestWindowClass") ||
7571 !lstrcmpiA(buf, "ShowWindowClass") ||
7572 !lstrcmpiA(buf, "TestParentClass") ||
7573 !lstrcmpiA(buf, "TestPopupClass") ||
7574 !lstrcmpiA(buf, "SimpleWindowClass") ||
7575 !lstrcmpiA(buf, "TestDialogClass") ||
7576 !lstrcmpiA(buf, "MDI_frame_class") ||
7577 !lstrcmpiA(buf, "MDI_client_class") ||
7578 !lstrcmpiA(buf, "MDI_child_class") ||
7579 !lstrcmpiA(buf, "my_button_class") ||
7580 !lstrcmpiA(buf, "my_edit_class") ||
7581 !lstrcmpiA(buf, "static") ||
7582 !lstrcmpiA(buf, "ListBox") ||
7583 !lstrcmpiA(buf, "ComboBox") ||
7584 !lstrcmpiA(buf, "MyDialogClass") ||
7585 !lstrcmpiA(buf, "#32770") ||
7586 !lstrcmpiA(buf, "#32768"))
7587 return TRUE;
7588 }
7589 return FALSE;
7590 }
7591
7592 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
7593 {
7594 HWND hwnd;
7595
7596 ok(cbt_hook_thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7597
7598 if (nCode == HCBT_CLICKSKIPPED)
7599 {
7600 /* ignore this event, XP sends it a lot when switching focus between windows */
7601 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7602 }
7603
7604 if (nCode == HCBT_SYSCOMMAND || nCode == HCBT_KEYSKIPPED)
7605 {
7606 struct recvd_message msg;
7607
7608 msg.hwnd = 0;
7609 msg.message = nCode;
7610 msg.flags = hook|wparam|lparam;
7611 msg.wParam = wParam;
7612 msg.lParam = lParam;
7613 msg.descr = "CBT";
7614 add_message(&msg);
7615
7616 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7617 }
7618
7619 if (nCode == HCBT_DESTROYWND)
7620 {
7621 if (test_DestroyWindow_flag)
7622 {
7623 DWORD style = GetWindowLongA((HWND)wParam, GWL_STYLE);
7624 if (style & WS_CHILD)
7625 lParam = GetWindowLongPtrA((HWND)wParam, GWLP_ID);
7626 else if (style & WS_POPUP)
7627 lParam = WND_POPUP_ID;
7628 else
7629 lParam = WND_PARENT_ID;
7630 }
7631 }
7632
7633 /* Log also SetFocus(0) calls */
7634 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
7635
7636 if (is_our_logged_class(hwnd))
7637 {
7638 struct recvd_message msg;
7639
7640 msg.hwnd = hwnd;
7641 msg.message = nCode;
7642 msg.flags = hook|wparam|lparam;
7643 msg.wParam = wParam;
7644 msg.lParam = lParam;
7645 msg.descr = "CBT";
7646 add_message(&msg);
7647 }
7648 return CallNextHookEx(hCBT_hook, nCode, wParam, lParam);
7649 }
7650
7651 static void CALLBACK win_event_proc(HWINEVENTHOOK hevent,
7652 DWORD event,
7653 HWND hwnd,
7654 LONG object_id,
7655 LONG child_id,
7656 DWORD thread_id,
7657 DWORD event_time)
7658 {
7659 ok(thread_id == GetCurrentThreadId(), "we didn't ask for events from other threads\n");
7660
7661 /* ignore mouse cursor events */
7662 if (object_id == OBJID_CURSOR) return;
7663
7664 if (!hwnd || is_our_logged_class(hwnd))
7665 {
7666 struct recvd_message msg;
7667
7668 msg.hwnd = hwnd;
7669 msg.message = event;
7670 msg.flags = winevent_hook|wparam|lparam;
7671 msg.wParam = object_id;
7672 msg.lParam = child_id;
7673 msg.descr = "WEH";
7674 add_message(&msg);
7675 }
7676 }
7677
7678 static const WCHAR wszUnicode[] = {'U','n','i','c','o','d','e',0};
7679 static const WCHAR wszAnsi[] = {'U',0};
7680
7681 static LRESULT CALLBACK MsgConversionProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
7682 {
7683 switch (uMsg)
7684 {
7685 case CB_FINDSTRINGEXACT:
7686 trace("String: %p\n", (LPCWSTR)lParam);
7687 if (!lstrcmpW((LPCWSTR)lParam, wszUnicode))
7688 return 1;
7689 if (!lstrcmpW((LPCWSTR)lParam, wszAnsi))
7690 return 0;
7691 return -1;
7692 }
7693 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
7694 }
7695
7696 static const struct message WmGetTextLengthAfromW[] = {
7697 { WM_GETTEXTLENGTH, sent },
7698 { WM_GETTEXT, sent|optional },
7699 { 0 }
7700 };
7701
7702 static const WCHAR dummy_window_text[] = {'d','u','m','m','y',' ','t','e','x','t',0};
7703
7704 /* dummy window proc for WM_GETTEXTLENGTH test */
7705 static LRESULT CALLBACK get_text_len_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
7706 {
7707 switch(msg)
7708 {
7709 case WM_GETTEXTLENGTH:
7710 return lstrlenW(dummy_window_text) + 37; /* some random length */
7711 case WM_GETTEXT:
7712 lstrcpynW( (LPWSTR)lp, dummy_window_text, wp );
7713 return lstrlenW( (LPWSTR)lp );
7714 default:
7715 return DefWindowProcW( hwnd, msg, wp, lp );
7716 }
7717 }
7718
7719 static void test_message_conversion(void)
7720 {
7721 static const WCHAR wszMsgConversionClass[] =
7722 {'M','s','g','C','o','n','v','e','r','s','i','o','n','C','l','a','s','s',0};
7723 WNDCLASSW cls;
7724 LRESULT lRes;
7725 HWND hwnd;
7726 WNDPROC wndproc, newproc;
7727 BOOL ret;
7728
7729 cls.style = 0;
7730 cls.lpfnWndProc = MsgConversionProcW;
7731 cls.cbClsExtra = 0;
7732 cls.cbWndExtra = 0;
7733 cls.hInstance = GetModuleHandleW(NULL);
7734 cls.hIcon = NULL;
7735 cls.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW);
7736 cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
7737 cls.lpszMenuName = NULL;
7738 cls.lpszClassName = wszMsgConversionClass;
7739 /* this call will fail on Win9x, but that doesn't matter as this test is
7740 * meaningless on those platforms */
7741 if(!RegisterClassW(&cls)) return;
7742
7743 hwnd = CreateWindowExW(0, wszMsgConversionClass, NULL, WS_OVERLAPPED,
7744 100, 100, 200, 200, 0, 0, 0, NULL);
7745 ok(hwnd != NULL, "Window creation failed\n");
7746
7747 /* {W, A} -> A */
7748
7749 wndproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
7750 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7751 ok(lRes == 0, "String should have been converted\n");
7752 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7753 ok(lRes == 1, "String shouldn't have been converted\n");
7754
7755 /* {W, A} -> W */
7756
7757 wndproc = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
7758 lRes = CallWindowProcA(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7759 ok(lRes == 1, "String shouldn't have been converted\n");
7760 lRes = CallWindowProcW(wndproc, hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7761 ok(lRes == 1, "String shouldn't have been converted\n");
7762
7763 /* Synchronous messages */
7764
7765 lRes = SendMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7766 ok(lRes == 0, "String should have been converted\n");
7767 lRes = SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7768 ok(lRes == 1, "String shouldn't have been converted\n");
7769
7770 /* Asynchronous messages */
7771
7772 SetLastError(0);
7773 lRes = PostMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7774 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7775 "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7776 SetLastError(0);
7777 lRes = PostMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7778 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7779 "PostMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7780 SetLastError(0);
7781 lRes = PostThreadMessageA(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7782 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7783 "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7784 SetLastError(0);
7785 lRes = PostThreadMessageW(GetCurrentThreadId(), CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7786 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7787 "PosThreadtMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7788 SetLastError(0);
7789 lRes = SendNotifyMessageA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7790 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7791 "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7792 SetLastError(0);
7793 lRes = SendNotifyMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode);
7794 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7795 "SendNotifyMessage on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7796 SetLastError(0);
7797 lRes = SendMessageCallbackA(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7798 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7799 "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7800 SetLastError(0);
7801 lRes = SendMessageCallbackW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)wszUnicode, NULL, 0);
7802 ok(lRes == 0 && (GetLastError() == ERROR_MESSAGE_SYNC_ONLY || GetLastError() == ERROR_INVALID_PARAMETER),
7803 "SendMessageCallback on sync only message returned %ld, last error %d\n", lRes, GetLastError());
7804
7805 /* Check WM_GETTEXTLENGTH A->W behaviour, whether WM_GETTEXT is also sent or not */
7806
7807 hwnd = CreateWindowW (testWindowClassW, wszUnicode,
7808 WS_OVERLAPPEDWINDOW,
7809 100, 100, 200, 200, 0, 0, 0, NULL);
7810 assert(hwnd);
7811 flush_sequence();
7812 lRes = SendMessageA (hwnd, WM_GETTEXTLENGTH, 0, 0);
7813 ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7814 ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7815 "got bad length %ld\n", lRes );
7816
7817 flush_sequence();
7818 lRes = CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ),
7819 hwnd, WM_GETTEXTLENGTH, 0, 0);
7820 ok_sequence(WmGetTextLengthAfromW, "ANSI WM_GETTEXTLENGTH to Unicode window", FALSE);
7821 ok( lRes == WideCharToMultiByte( CP_ACP, 0, wszUnicode, lstrlenW(wszUnicode), NULL, 0, NULL, NULL ),
7822 "got bad length %ld\n", lRes );
7823
7824 wndproc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)get_text_len_proc );
7825 newproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC );
7826 lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7827 ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7828 NULL, 0, NULL, NULL ) ||
7829 broken(lRes == lstrlenW(dummy_window_text) + 37),
7830 "got bad length %ld\n", lRes );
7831
7832 SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc ); /* restore old wnd proc */
7833 lRes = CallWindowProcA( newproc, hwnd, WM_GETTEXTLENGTH, 0, 0 );
7834 ok( lRes == WideCharToMultiByte( CP_ACP, 0, dummy_window_text, lstrlenW(dummy_window_text),
7835 NULL, 0, NULL, NULL ) ||
7836 broken(lRes == lstrlenW(dummy_window_text) + 37),
7837 "got bad length %ld\n", lRes );
7838
7839 ret = DestroyWindow(hwnd);
7840 ok( ret, "DestroyWindow() error %d\n", GetLastError());
7841 }
7842
7843 struct timer_info
7844 {
7845 HWND hWnd;
7846 HANDLE handles[2];
7847 DWORD id;
7848 };
7849
7850 static VOID CALLBACK tfunc(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
7851 {
7852 }
7853
7854 static VOID CALLBACK tfunc_crash(HWND hwnd, UINT uMsg, UINT_PTR id, DWORD dwTime)
7855 {
7856 /* Crash on purpose */
7857 *(volatile int *)0 = 2;
7858 }
7859
7860 #define TIMER_ID 0x19
7861
7862 static DWORD WINAPI timer_thread_proc(LPVOID x)
7863 {
7864 struct timer_info *info = x;
7865 DWORD r;
7866
7867 r = KillTimer(info->hWnd, 0x19);
7868 ok(r,"KillTimer failed in thread\n");
7869 r = SetTimer(info->hWnd,TIMER_ID,10000,tfunc);
7870 ok(r,"SetTimer failed in thread\n");
7871 ok(r==TIMER_ID,"SetTimer id different\n");
7872 r = SetEvent(info->handles[0]);
7873 ok(r,"SetEvent failed in thread\n");
7874 return 0;
7875 }
7876
7877 static void test_timers(void)
7878 {
7879 struct timer_info info;
7880 DWORD id;
7881 MSG msg;
7882
7883 info.hWnd = CreateWindow ("TestWindowClass", NULL,
7884 WS_OVERLAPPEDWINDOW ,
7885 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7886 NULL, NULL, 0);
7887
7888 info.id = SetTimer(info.hWnd,TIMER_ID,10000,tfunc);
7889 ok(info.id, "SetTimer failed\n");
7890 ok(info.id==TIMER_ID, "SetTimer timer ID different\n");
7891 info.handles[0] = CreateEvent(NULL,0,0,NULL);
7892 info.handles[1] = CreateThread(NULL,0,timer_thread_proc,&info,0,&id);
7893
7894 WaitForMultipleObjects(2, info.handles, FALSE, INFINITE);
7895
7896 WaitForSingleObject(info.handles[1], INFINITE);
7897
7898 CloseHandle(info.handles[0]);
7899 CloseHandle(info.handles[1]);
7900
7901 ok( KillTimer(info.hWnd, TIMER_ID), "KillTimer failed\n");
7902
7903 ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
7904
7905 /* Test timer callback with crash */
7906 SetLastError(0xdeadbeef);
7907 info.hWnd = CreateWindowW(testWindowClassW, NULL,
7908 WS_OVERLAPPEDWINDOW ,
7909 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
7910 NULL, NULL, 0);
7911 if ((!info.hWnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) || /* Win9x/Me */
7912 (!pGetMenuInfo)) /* Win95/NT4 */
7913 {
7914 win_skip("Test would crash on Win9x/WinMe/NT4\n");
7915 DestroyWindow(info.hWnd);
7916 return;
7917 }
7918 info.id = SetTimer(info.hWnd, TIMER_ID, 0, tfunc_crash);
7919 ok(info.id, "SetTimer failed\n");
7920 Sleep(150);
7921 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7922
7923 ok(DestroyWindow(info.hWnd), "failed to destroy window\n");
7924 }
7925
7926 static int count = 0;
7927 static VOID CALLBACK callback_count(
7928 HWND hwnd,
7929 UINT uMsg,
7930 UINT_PTR idEvent,
7931 DWORD dwTime
7932 )
7933 {
7934 count++;
7935 }
7936
7937 static void test_timers_no_wnd(void)
7938 {
7939 UINT_PTR id, id2;
7940 MSG msg;
7941
7942 count = 0;
7943 id = SetTimer(NULL, 0, 100, callback_count);
7944 ok(id != 0, "did not get id from SetTimer.\n");
7945 id2 = SetTimer(NULL, id, 200, callback_count);
7946 ok(id2 == id, "did not get same id from SetTimer when replacing (%li expected %li).\n", id2, id);
7947 Sleep(150);
7948 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7949 ok(count == 0, "did not get zero count as expected (%i).\n", count);
7950 Sleep(150);
7951 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7952 ok(count == 1, "did not get one count as expected (%i).\n", count);
7953 KillTimer(NULL, id);
7954 Sleep(250);
7955 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
7956 ok(count == 1, "killing replaced timer did not work (%i).\n", count);
7957 }
7958
7959 /* Various win events with arbitrary parameters */
7960 static const struct message WmWinEventsSeq[] = {
7961 { EVENT_SYSTEM_SOUND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7962 { EVENT_SYSTEM_ALERT, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7963 { EVENT_SYSTEM_FOREGROUND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7964 { EVENT_SYSTEM_MENUSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7965 { EVENT_SYSTEM_MENUEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7966 { EVENT_SYSTEM_MENUPOPUPSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7967 { EVENT_SYSTEM_MENUPOPUPEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7968 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7969 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7970 /* our win event hook ignores OBJID_CURSOR events */
7971 /*{ EVENT_SYSTEM_MOVESIZESTART, winevent_hook|wparam|lparam, OBJID_CURSOR, 9 },*/
7972 { EVENT_SYSTEM_MOVESIZEEND, winevent_hook|wparam|lparam, OBJID_ALERT, 10 },
7973 { EVENT_SYSTEM_CONTEXTHELPSTART, winevent_hook|wparam|lparam, OBJID_SOUND, 11 },
7974 { EVENT_SYSTEM_CONTEXTHELPEND, winevent_hook|wparam|lparam, OBJID_QUERYCLASSNAMEIDX, 12 },
7975 { EVENT_SYSTEM_DRAGDROPSTART, winevent_hook|wparam|lparam, OBJID_NATIVEOM, 13 },
7976 { EVENT_SYSTEM_DRAGDROPEND, winevent_hook|wparam|lparam, OBJID_WINDOW, 0 },
7977 { EVENT_SYSTEM_DIALOGSTART, winevent_hook|wparam|lparam, OBJID_SYSMENU, 1 },
7978 { EVENT_SYSTEM_DIALOGEND, winevent_hook|wparam|lparam, OBJID_TITLEBAR, 2 },
7979 { EVENT_SYSTEM_SCROLLINGSTART, winevent_hook|wparam|lparam, OBJID_MENU, 3 },
7980 { EVENT_SYSTEM_SCROLLINGEND, winevent_hook|wparam|lparam, OBJID_CLIENT, 4 },
7981 { EVENT_SYSTEM_SWITCHSTART, winevent_hook|wparam|lparam, OBJID_VSCROLL, 5 },
7982 { EVENT_SYSTEM_SWITCHEND, winevent_hook|wparam|lparam, OBJID_HSCROLL, 6 },
7983 { EVENT_SYSTEM_MINIMIZESTART, winevent_hook|wparam|lparam, OBJID_SIZEGRIP, 7 },
7984 { EVENT_SYSTEM_MINIMIZEEND, winevent_hook|wparam|lparam, OBJID_CARET, 8 },
7985 { 0 }
7986 };
7987 static const struct message WmWinEventCaretSeq[] = {
7988 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7989 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7990 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 2 */
7991 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1 */
7992 { 0 }
7993 };
7994 static const struct message WmWinEventCaretSeq_2[] = {
7995 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7996 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7997 { EVENT_OBJECT_NAMECHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 }, /* hook 1/2 */
7998 { 0 }
7999 };
8000 static const struct message WmWinEventAlertSeq[] = {
8001 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 0 },
8002 { 0 }
8003 };
8004 static const struct message WmWinEventAlertSeq_2[] = {
8005 /* create window in the thread proc */
8006 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_WINDOW, 2 },
8007 /* our test event */
8008 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_ALERT, 2 },
8009 { 0 }
8010 };
8011 static const struct message WmGlobalHookSeq_1[] = {
8012 /* create window in the thread proc */
8013 { HCBT_CREATEWND, hook|lparam, 0, 2 },
8014 /* our test events */
8015 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 },
8016 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 },
8017 { 0 }
8018 };
8019 static const struct message WmGlobalHookSeq_2[] = {
8020 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 0 }, /* old local hook */
8021 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_NEXTWINDOW, 2 }, /* new global hook */
8022 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 0 }, /* old local hook */
8023 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_PREVWINDOW, 2 }, /* new global hook */
8024 { 0 }
8025 };
8026
8027 static const struct message WmMouseLLHookSeq[] = {
8028 { WM_MOUSEMOVE, hook },
8029 { WM_LBUTTONUP, hook },
8030 { WM_MOUSEMOVE, hook },
8031 { 0 }
8032 };
8033
8034 static void CALLBACK win_event_global_hook_proc(HWINEVENTHOOK hevent,
8035 DWORD event,
8036 HWND hwnd,
8037 LONG object_id,
8038 LONG child_id,
8039 DWORD thread_id,
8040 DWORD event_time)
8041 {
8042 char buf[256];
8043
8044 if (GetClassNameA(hwnd, buf, sizeof(buf)))
8045 {
8046 if (!lstrcmpiA(buf, "TestWindowClass") ||
8047 !lstrcmpiA(buf, "static"))
8048 {
8049 struct recvd_message msg;
8050
8051 msg.hwnd = hwnd;
8052 msg.message = event;
8053 msg.flags = winevent_hook|wparam|lparam;
8054 msg.wParam = object_id;
8055 msg.lParam = (thread_id == GetCurrentThreadId()) ? child_id : (child_id + 2);
8056 msg.descr = "WEH_2";
8057 add_message(&msg);
8058 }
8059 }
8060 }
8061
8062 static HHOOK hCBT_global_hook;
8063 static DWORD cbt_global_hook_thread_id;
8064
8065 static LRESULT CALLBACK cbt_global_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
8066 {
8067 HWND hwnd;
8068 char buf[256];
8069
8070 if (nCode == HCBT_SYSCOMMAND)
8071 {
8072 struct recvd_message msg;
8073
8074 msg.hwnd = 0;
8075 msg.message = nCode;
8076 msg.flags = hook|wparam|lparam;
8077 msg.wParam = wParam;
8078 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8079 msg.descr = "CBT_2";
8080 add_message(&msg);
8081
8082 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8083 }
8084 /* WH_MOUSE_LL hook */
8085 if (nCode == HC_ACTION)
8086 {
8087 MSLLHOOKSTRUCT *mhll = (MSLLHOOKSTRUCT *)lParam;
8088
8089 /* we can't test for real mouse events */
8090 if (mhll->flags & LLMHF_INJECTED)
8091 {
8092 struct recvd_message msg;
8093
8094 memset (&msg, 0, sizeof (msg));
8095 msg.message = wParam;
8096 msg.flags = hook;
8097 msg.descr = "CBT_2";
8098 add_message(&msg);
8099 }
8100 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8101 }
8102
8103 /* Log also SetFocus(0) calls */
8104 hwnd = wParam ? (HWND)wParam : (HWND)lParam;
8105
8106 if (GetClassNameA(hwnd, buf, sizeof(buf)))
8107 {
8108 if (!lstrcmpiA(buf, "TestWindowClass") ||
8109 !lstrcmpiA(buf, "static"))
8110 {
8111 struct recvd_message msg;
8112
8113 msg.hwnd = hwnd;
8114 msg.message = nCode;
8115 msg.flags = hook|wparam|lparam;
8116 msg.wParam = wParam;
8117 msg.lParam = (cbt_global_hook_thread_id == GetCurrentThreadId()) ? 1 : 2;
8118 msg.descr = "CBT_2";
8119 add_message(&msg);
8120 }
8121 }
8122 return CallNextHookEx(hCBT_global_hook, nCode, wParam, lParam);
8123 }
8124
8125 static DWORD WINAPI win_event_global_thread_proc(void *param)
8126 {
8127 HWND hwnd;
8128 MSG msg;
8129 HANDLE hevent = *(HANDLE *)param;
8130
8131 assert(pNotifyWinEvent);
8132
8133 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8134 assert(hwnd);
8135 trace("created thread window %p\n", hwnd);
8136
8137 *(HWND *)param = hwnd;
8138
8139 flush_sequence();
8140 /* this event should be received only by our new hook proc,
8141 * an old one does not expect an event from another thread.
8142 */
8143 pNotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, hwnd, OBJID_ALERT, 0);
8144 SetEvent(hevent);
8145
8146 while (GetMessage(&msg, 0, 0, 0))
8147 {
8148 TranslateMessage(&msg);
8149 DispatchMessage(&msg);
8150 }
8151 return 0;
8152 }
8153
8154 static DWORD WINAPI cbt_global_hook_thread_proc(void *param)
8155 {
8156 HWND hwnd;
8157 MSG msg;
8158 HANDLE hevent = *(HANDLE *)param;
8159
8160 flush_sequence();
8161 /* these events should be received only by our new hook proc,
8162 * an old one does not expect an event from another thread.
8163 */
8164
8165 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8166 assert(hwnd);
8167 trace("created thread window %p\n", hwnd);
8168
8169 *(HWND *)param = hwnd;
8170
8171 /* Windows doesn't like when a thread plays games with the focus,
8172 that leads to all kinds of misbehaviours and failures to activate
8173 a window. So, better keep next lines commented out.
8174 SetFocus(0);
8175 SetFocus(hwnd);*/
8176
8177 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8178 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8179
8180 SetEvent(hevent);
8181
8182 while (GetMessage(&msg, 0, 0, 0))
8183 {
8184 TranslateMessage(&msg);
8185 DispatchMessage(&msg);
8186 }
8187 return 0;
8188 }
8189
8190 static DWORD WINAPI mouse_ll_global_thread_proc(void *param)
8191 {
8192 HWND hwnd;
8193 MSG msg;
8194 HANDLE hevent = *(HANDLE *)param;
8195
8196 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
8197 assert(hwnd);
8198 trace("created thread window %p\n", hwnd);
8199
8200 *(HWND *)param = hwnd;
8201
8202 flush_sequence();
8203
8204 /* Windows doesn't like when a thread plays games with the focus,
8205 * that leads to all kinds of misbehaviours and failures to activate
8206 * a window. So, better don't generate a mouse click message below.
8207 */
8208 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8209 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8210 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8211
8212 SetEvent(hevent);
8213 while (GetMessage(&msg, 0, 0, 0))
8214 {
8215 TranslateMessage(&msg);
8216 DispatchMessage(&msg);
8217 }
8218 return 0;
8219 }
8220
8221 static void test_winevents(void)
8222 {
8223 BOOL ret;
8224 MSG msg;
8225 HWND hwnd, hwnd2;
8226 UINT i;
8227 HANDLE hthread, hevent;
8228 DWORD tid;
8229 HWINEVENTHOOK hhook;
8230 const struct message *events = WmWinEventsSeq;
8231
8232 hwnd = CreateWindowExA(0, "TestWindowClass", NULL,
8233 WS_OVERLAPPEDWINDOW,
8234 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
8235 NULL, NULL, 0);
8236 assert(hwnd);
8237
8238 /****** start of global hook test *************/
8239 hCBT_global_hook = SetWindowsHookExA(WH_CBT, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8240 if (!hCBT_global_hook)
8241 {
8242 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8243 skip( "cannot set global hook\n" );
8244 return;
8245 }
8246
8247 hevent = CreateEventA(NULL, 0, 0, NULL);
8248 assert(hevent);
8249 hwnd2 = hevent;
8250
8251 hthread = CreateThread(NULL, 0, cbt_global_hook_thread_proc, &hwnd2, 0, &tid);
8252 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8253
8254 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8255
8256 ok_sequence(WmGlobalHookSeq_1, "global hook 1", FALSE);
8257
8258 flush_sequence();
8259 /* this one should be received only by old hook proc */
8260 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_NEXTWINDOW, 0);
8261 /* this one should be received only by old hook proc */
8262 DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_PREVWINDOW, 0);
8263
8264 ok_sequence(WmGlobalHookSeq_2, "global hook 2", FALSE);
8265
8266 ret = UnhookWindowsHookEx(hCBT_global_hook);
8267 ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8268
8269 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8270 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8271 CloseHandle(hthread);
8272 CloseHandle(hevent);
8273 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8274 /****** end of global hook test *************/
8275
8276 if (!pSetWinEventHook || !pNotifyWinEvent || !pUnhookWinEvent)
8277 {
8278 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8279 return;
8280 }
8281
8282 flush_sequence();
8283
8284 if (0)
8285 {
8286 /* this test doesn't pass under Win9x */
8287 /* win2k ignores events with hwnd == 0 */
8288 SetLastError(0xdeadbeef);
8289 pNotifyWinEvent(events[0].message, 0, events[0].wParam, events[0].lParam);
8290 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || /* Win2k */
8291 GetLastError() == 0xdeadbeef, /* Win9x */
8292 "unexpected error %d\n", GetLastError());
8293 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8294 }
8295
8296 for (i = 0; i < sizeof(WmWinEventsSeq)/sizeof(WmWinEventsSeq[0]); i++)
8297 pNotifyWinEvent(events[i].message, hwnd, events[i].wParam, events[i].lParam);
8298
8299 ok_sequence(WmWinEventsSeq, "notify winevents", FALSE);
8300
8301 /****** start of event filtering test *************/
8302 hhook = pSetWinEventHook(
8303 EVENT_OBJECT_SHOW, /* 0x8002 */
8304 EVENT_OBJECT_LOCATIONCHANGE, /* 0x800B */
8305 GetModuleHandleA(0), win_event_global_hook_proc,
8306 GetCurrentProcessId(), 0,
8307 WINEVENT_INCONTEXT);
8308 ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8309
8310 hevent = CreateEventA(NULL, 0, 0, NULL);
8311 assert(hevent);
8312 hwnd2 = hevent;
8313
8314 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8315 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8316
8317 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8318
8319 ok_sequence(WmWinEventAlertSeq, "alert winevent", FALSE);
8320
8321 flush_sequence();
8322 /* this one should be received only by old hook proc */
8323 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8324 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8325 /* this one should be received only by old hook proc */
8326 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8327
8328 ok_sequence(WmWinEventCaretSeq, "caret winevent", FALSE);
8329
8330 ret = pUnhookWinEvent(hhook);
8331 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8332
8333 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8334 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8335 CloseHandle(hthread);
8336 CloseHandle(hevent);
8337 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8338 /****** end of event filtering test *************/
8339
8340 /****** start of out of context event test *************/
8341 hhook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0,
8342 win_event_global_hook_proc, GetCurrentProcessId(), 0,
8343 WINEVENT_OUTOFCONTEXT);
8344 ok(hhook != 0, "SetWinEventHook error %d\n", GetLastError());
8345
8346 hevent = CreateEventA(NULL, 0, 0, NULL);
8347 assert(hevent);
8348 hwnd2 = hevent;
8349
8350 flush_sequence();
8351
8352 hthread = CreateThread(NULL, 0, win_event_global_thread_proc, &hwnd2, 0, &tid);
8353 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8354
8355 ok(WaitForSingleObject(hevent, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8356
8357 ok_sequence(WmEmptySeq, "empty notify winevents", FALSE);
8358 /* process pending winevent messages */
8359 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8360 ok_sequence(WmWinEventAlertSeq_2, "alert winevent for out of context proc", FALSE);
8361
8362 flush_sequence();
8363 /* this one should be received only by old hook proc */
8364 pNotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_CARET, 0); /* 0x8000 */
8365 pNotifyWinEvent(EVENT_OBJECT_SHOW, hwnd, OBJID_CARET, 0); /* 0x8002 */
8366 /* this one should be received only by old hook proc */
8367 pNotifyWinEvent(EVENT_OBJECT_NAMECHANGE, hwnd, OBJID_CARET, 0); /* 0x800C */
8368
8369 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for incontext proc", FALSE);
8370 /* process pending winevent messages */
8371 ok(!PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE), "msg queue should be empty\n");
8372 ok_sequence(WmWinEventCaretSeq_2, "caret winevent for out of context proc", FALSE);
8373
8374 ret = pUnhookWinEvent(hhook);
8375 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8376
8377 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8378 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8379 CloseHandle(hthread);
8380 CloseHandle(hevent);
8381 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8382 /****** end of out of context event test *************/
8383
8384 /****** start of MOUSE_LL hook test *************/
8385 hCBT_global_hook = SetWindowsHookExA(WH_MOUSE_LL, cbt_global_hook_proc, GetModuleHandleA(0), 0);
8386 /* WH_MOUSE_LL is not supported on Win9x platforms */
8387 if (!hCBT_global_hook)
8388 {
8389 win_skip("Skipping WH_MOUSE_LL test on this platform\n");
8390 goto skip_mouse_ll_hook_test;
8391 }
8392
8393 hevent = CreateEventA(NULL, 0, 0, NULL);
8394 assert(hevent);
8395 hwnd2 = hevent;
8396
8397 hthread = CreateThread(NULL, 0, mouse_ll_global_thread_proc, &hwnd2, 0, &tid);
8398 ok(hthread != NULL, "CreateThread failed, error %d\n", GetLastError());
8399
8400 while (WaitForSingleObject(hevent, 100) == WAIT_TIMEOUT)
8401 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
8402
8403 ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook other thread", FALSE);
8404 flush_sequence();
8405
8406 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
8407 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
8408 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
8409
8410 ok_sequence(WmMouseLLHookSeq, "MOUSE_LL hook same thread", FALSE);
8411
8412 ret = UnhookWindowsHookEx(hCBT_global_hook);
8413 ok( ret, "UnhookWindowsHookEx error %d\n", GetLastError());
8414
8415 PostThreadMessageA(tid, WM_QUIT, 0, 0);
8416 ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8417 CloseHandle(hthread);
8418 CloseHandle(hevent);
8419 ok(!IsWindow(hwnd2), "window should be destroyed on thread exit\n");
8420 /****** end of MOUSE_LL hook test *************/
8421 skip_mouse_ll_hook_test:
8422
8423 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8424 }
8425
8426 static void test_set_hook(void)
8427 {
8428 BOOL ret;
8429 HHOOK hhook;
8430 HWINEVENTHOOK hwinevent_hook;
8431
8432 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, GetModuleHandleA(0), GetCurrentThreadId());
8433 ok(hhook != 0, "local hook does not require hModule set to 0\n");
8434 UnhookWindowsHookEx(hhook);
8435
8436 if (0)
8437 {
8438 /* this test doesn't pass under Win9x: BUG! */
8439 SetLastError(0xdeadbeef);
8440 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, 0);
8441 ok(!hhook, "global hook requires hModule != 0\n");
8442 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD, "unexpected error %d\n", GetLastError());
8443 }
8444
8445 SetLastError(0xdeadbeef);
8446 hhook = SetWindowsHookExA(WH_CBT, 0, GetModuleHandleA(0), GetCurrentThreadId());
8447 ok(!hhook, "SetWinEventHook with invalid proc should fail\n");
8448 ok(GetLastError() == ERROR_INVALID_FILTER_PROC || /* Win2k */
8449 GetLastError() == 0xdeadbeef, /* Win9x */
8450 "unexpected error %d\n", GetLastError());
8451
8452 SetLastError(0xdeadbeef);
8453 ok(!UnhookWindowsHookEx((HHOOK)0xdeadbeef), "UnhookWindowsHookEx succeeded\n");
8454 ok(GetLastError() == ERROR_INVALID_HOOK_HANDLE || /* Win2k */
8455 GetLastError() == 0xdeadbeef, /* Win9x */
8456 "unexpected error %d\n", GetLastError());
8457
8458 if (!pSetWinEventHook || !pUnhookWinEvent) return;
8459
8460 /* even process local incontext hooks require hmodule */
8461 SetLastError(0xdeadbeef);
8462 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8463 GetCurrentProcessId(), 0, WINEVENT_INCONTEXT);
8464 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8465 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8466 GetLastError() == 0xdeadbeef, /* Win9x */
8467 "unexpected error %d\n", GetLastError());
8468
8469 /* even thread local incontext hooks require hmodule */
8470 SetLastError(0xdeadbeef);
8471 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8472 GetCurrentProcessId(), GetCurrentThreadId(), WINEVENT_INCONTEXT);
8473 ok(!hwinevent_hook, "WINEVENT_INCONTEXT requires hModule != 0\n");
8474 ok(GetLastError() == ERROR_HOOK_NEEDS_HMOD || /* Win2k */
8475 GetLastError() == 0xdeadbeef, /* Win9x */
8476 "unexpected error %d\n", GetLastError());
8477
8478 if (0)
8479 {
8480 /* these 3 tests don't pass under Win9x */
8481 SetLastError(0xdeadbeef);
8482 hwinevent_hook = pSetWinEventHook(1, 0, 0, win_event_proc,
8483 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8484 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8485 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8486
8487 SetLastError(0xdeadbeef);
8488 hwinevent_hook = pSetWinEventHook(-1, 1, 0, win_event_proc,
8489 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8490 ok(!hwinevent_hook, "SetWinEventHook with invalid event range should fail\n");
8491 ok(GetLastError() == ERROR_INVALID_HOOK_FILTER, "unexpected error %d\n", GetLastError());
8492
8493 SetLastError(0xdeadbeef);
8494 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8495 0, 0xdeadbeef, WINEVENT_OUTOFCONTEXT);
8496 ok(!hwinevent_hook, "SetWinEventHook with invalid tid should fail\n");
8497 ok(GetLastError() == ERROR_INVALID_THREAD_ID, "unexpected error %d\n", GetLastError());
8498 }
8499
8500 SetLastError(0xdeadbeef);
8501 hwinevent_hook = pSetWinEventHook(0, 0, 0, win_event_proc,
8502 GetCurrentProcessId(), 0, WINEVENT_OUTOFCONTEXT);
8503 ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8504 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8505 ret = pUnhookWinEvent(hwinevent_hook);
8506 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8507
8508 todo_wine {
8509 /* This call succeeds under win2k SP4, but fails under Wine.
8510 Does win2k test/use passed process id? */
8511 SetLastError(0xdeadbeef);
8512 hwinevent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX, 0, win_event_proc,
8513 0xdeadbeef, 0, WINEVENT_OUTOFCONTEXT);
8514 ok(hwinevent_hook != 0, "SetWinEventHook error %d\n", GetLastError());
8515 ok(GetLastError() == 0xdeadbeef, "unexpected error %d\n", GetLastError());
8516 ret = pUnhookWinEvent(hwinevent_hook);
8517 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
8518 }
8519
8520 SetLastError(0xdeadbeef);
8521 ok(!pUnhookWinEvent((HWINEVENTHOOK)0xdeadbeef), "UnhookWinEvent succeeded\n");
8522 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
8523 GetLastError() == 0xdeadbeef, /* Win9x */
8524 "unexpected error %d\n", GetLastError());
8525 }
8526
8527 static const struct message ScrollWindowPaint1[] = {
8528 { WM_PAINT, sent },
8529 { WM_ERASEBKGND, sent|beginpaint },
8530 { WM_GETTEXTLENGTH, sent|optional },
8531 { WM_PAINT, sent|optional },
8532 { WM_NCPAINT, sent|beginpaint|optional },
8533 { WM_GETTEXT, sent|beginpaint|optional },
8534 { WM_GETTEXT, sent|beginpaint|optional },
8535 { WM_GETTEXT, sent|beginpaint|optional },
8536 { WM_GETTEXT, sent|beginpaint|defwinproc|optional },
8537 { WM_ERASEBKGND, sent|beginpaint|optional },
8538 { 0 }
8539 };
8540
8541 static const struct message ScrollWindowPaint2[] = {
8542 { WM_PAINT, sent },
8543 { 0 }
8544 };
8545
8546 static void test_scrollwindowex(void)
8547 {
8548 HWND hwnd, hchild;
8549 RECT rect={0,0,130,130};
8550
8551 hwnd = CreateWindowExA(0, "TestWindowClass", "Test Scroll",
8552 WS_VISIBLE|WS_OVERLAPPEDWINDOW,
8553 100, 100, 200, 200, 0, 0, 0, NULL);
8554 ok (hwnd != 0, "Failed to create overlapped window\n");
8555 hchild = CreateWindowExA(0, "TestWindowClass", "Test child",
8556 WS_VISIBLE|WS_CAPTION|WS_CHILD,
8557 10, 10, 150, 150, hwnd, 0, 0, NULL);
8558 ok (hchild != 0, "Failed to create child\n");
8559 UpdateWindow(hwnd);
8560 flush_events();
8561 flush_sequence();
8562
8563 /* scroll without the child window */
8564 trace("start scroll\n");
8565 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8566 SW_ERASE|SW_INVALIDATE);
8567 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8568 trace("end scroll\n");
8569 flush_sequence();
8570 flush_events();
8571 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8572 flush_events();
8573 flush_sequence();
8574
8575 /* Now without the SW_ERASE flag */
8576 trace("start scroll\n");
8577 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL, SW_INVALIDATE);
8578 ok_sequence(WmEmptySeq, "ScrollWindowEx", 0);
8579 trace("end scroll\n");
8580 flush_sequence();
8581 flush_events();
8582 ok_sequence(ScrollWindowPaint2, "ScrollWindowEx", 0);
8583 flush_events();
8584 flush_sequence();
8585
8586 /* now scroll the child window as well */
8587 trace("start scroll\n");
8588 ScrollWindowEx( hwnd, 10, 10, &rect, NULL, NULL, NULL,
8589 SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
8590 /* wine sends WM_POSCHANGING, WM_POSCHANGED messages */
8591 /* windows sometimes a WM_MOVE */
8592 ok_sequence(WmEmptySeq, "ScrollWindowEx", TRUE);
8593 trace("end scroll\n");
8594 flush_sequence();
8595 flush_events();
8596 ok_sequence(ScrollWindowPaint1, "ScrollWindowEx", 0);
8597 flush_events();
8598 flush_sequence();
8599
8600 /* now scroll with ScrollWindow() */
8601 trace("start scroll with ScrollWindow\n");
8602 ScrollWindow( hwnd, 5, 5, NULL, NULL);
8603 trace("end scroll\n");
8604 flush_sequence();
8605 flush_events();
8606 ok_sequence(ScrollWindowPaint1, "ScrollWindow", 0);
8607
8608 ok(DestroyWindow(hchild), "failed to destroy window\n");
8609 ok(DestroyWindow(hwnd), "failed to destroy window\n");
8610 flush_sequence();
8611 }
8612
8613 static const struct message destroy_window_with_children[] = {
8614 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8615 { HCBT_DESTROYWND, hook|lparam, 0, WND_PARENT_ID }, /* parent */
8616 { 0x0090, sent|optional },
8617 { HCBT_DESTROYWND, hook|lparam, 0, WND_POPUP_ID }, /* popup */
8618 { 0x0090, sent|optional },
8619 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* popup */
8620 { WM_DESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8621 { WM_CAPTURECHANGED, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8622 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_POPUP_ID }, /* popup */
8623 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, 0, 0 }, /* parent */
8624 { WM_DESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8625 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8626 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8627 { WM_DESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8628 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 2 }, /* child2 */
8629 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 3 }, /* child3 */
8630 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_CHILD_ID + 1 }, /* child1 */
8631 { WM_NCDESTROY, sent|wparam|lparam, 0, WND_PARENT_ID }, /* parent */
8632 { 0 }
8633 };
8634
8635 static void test_DestroyWindow(void)
8636 {
8637 BOOL ret;
8638 HWND parent, child1, child2, child3, child4, test;
8639 UINT_PTR child_id = WND_CHILD_ID + 1;
8640
8641 parent = CreateWindowExA(0, "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8642 100, 100, 200, 200, 0, 0, 0, NULL);
8643 assert(parent != 0);
8644 child1 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8645 0, 0, 50, 50, parent, (HMENU)child_id++, 0, NULL);
8646 assert(child1 != 0);
8647 child2 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8648 0, 0, 50, 50, GetDesktopWindow(), (HMENU)child_id++, 0, NULL);
8649 assert(child2 != 0);
8650 child3 = CreateWindowExA(0, "TestWindowClass", NULL, WS_CHILD,
8651 0, 0, 50, 50, child1, (HMENU)child_id++, 0, NULL);
8652 assert(child3 != 0);
8653 child4 = CreateWindowExA(0, "TestWindowClass", NULL, WS_POPUP,
8654 0, 0, 50, 50, parent, 0, 0, NULL);
8655 assert(child4 != 0);
8656
8657 /* test owner/parent of child2 */
8658 test = GetParent(child2);
8659 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8660 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8661 if(pGetAncestor) {
8662 test = pGetAncestor(child2, GA_PARENT);
8663 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8664 }
8665 test = GetWindow(child2, GW_OWNER);
8666 ok(!test, "wrong owner %p\n", test);
8667
8668 test = SetParent(child2, parent);
8669 ok(test == GetDesktopWindow(), "wrong old parent %p\n", test);
8670
8671 /* test owner/parent of the parent */
8672 test = GetParent(parent);
8673 ok(!test, "wrong parent %p\n", test);
8674 ok(!IsChild(GetDesktopWindow(), parent), "wrong parent/child %p/%p\n", GetDesktopWindow(), parent);
8675 if(pGetAncestor) {
8676 test = pGetAncestor(parent, GA_PARENT);
8677 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8678 }
8679 test = GetWindow(parent, GW_OWNER);
8680 ok(!test, "wrong owner %p\n", test);
8681
8682 /* test owner/parent of child1 */
8683 test = GetParent(child1);
8684 ok(test == parent, "wrong parent %p\n", test);
8685 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
8686 if(pGetAncestor) {
8687 test = pGetAncestor(child1, GA_PARENT);
8688 ok(test == parent, "wrong parent %p\n", test);
8689 }
8690 test = GetWindow(child1, GW_OWNER);
8691 ok(!test, "wrong owner %p\n", test);
8692
8693 /* test owner/parent of child2 */
8694 test = GetParent(child2);
8695 ok(test == parent, "wrong parent %p\n", test);
8696 ok(IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
8697 if(pGetAncestor) {
8698 test = pGetAncestor(child2, GA_PARENT);
8699 ok(test == parent, "wrong parent %p\n", test);
8700 }
8701 test = GetWindow(child2, GW_OWNER);
8702 ok(!test, "wrong owner %p\n", test);
8703
8704 /* test owner/parent of child3 */
8705 test = GetParent(child3);
8706 ok(test == child1, "wrong parent %p\n", test);
8707 ok(IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
8708 if(pGetAncestor) {
8709 test = pGetAncestor(child3, GA_PARENT);
8710 ok(test == child1, "wrong parent %p\n", test);
8711 }
8712 test = GetWindow(child3, GW_OWNER);
8713 ok(!test, "wrong owner %p\n", test);
8714
8715 /* test owner/parent of child4 */
8716 test = GetParent(child4);
8717 ok(test == parent, "wrong parent %p\n", test);
8718 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
8719 if(pGetAncestor) {
8720 test = pGetAncestor(child4, GA_PARENT);
8721 ok(test == GetDesktopWindow(), "wrong parent %p\n", test);
8722 }
8723 test = GetWindow(child4, GW_OWNER);
8724 ok(test == parent, "wrong owner %p\n", test);
8725
8726 flush_sequence();
8727
8728 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
8729 parent, child1, child2, child3, child4);
8730
8731 SetCapture(child4);
8732 test = GetCapture();
8733 ok(test == child4, "wrong capture window %p\n", test);
8734
8735 test_DestroyWindow_flag = TRUE;
8736 ret = DestroyWindow(parent);
8737 ok( ret, "DestroyWindow() error %d\n", GetLastError());
8738 test_DestroyWindow_flag = FALSE;
8739 ok_sequence(destroy_window_with_children, "destroy window with children", 0);
8740
8741 ok(!IsWindow(parent), "parent still exists\n");
8742 ok(!IsWindow(child1), "child1 still exists\n");
8743 ok(!IsWindow(child2), "child2 still exists\n");
8744 ok(!IsWindow(child3), "child3 still exists\n");
8745 ok(!IsWindow(child4), "child4 still exists\n");
8746
8747 test = GetCapture();
8748 ok(!test, "wrong capture window %p\n", test);
8749 }
8750
8751
8752 static const struct message WmDispatchPaint[] = {
8753 { WM_NCPAINT, sent },
8754 { WM_GETTEXT, sent|defwinproc|optional },
8755 { WM_GETTEXT, sent|defwinproc|optional },
8756 { WM_ERASEBKGND, sent },
8757 { 0 }
8758 };
8759
8760 static LRESULT WINAPI DispatchMessageCheckProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8761 {
8762 if (message == WM_PAINT) return 0;
8763 return MsgCheckProcA( hwnd, message, wParam, lParam );
8764 }
8765
8766 static void test_DispatchMessage(void)
8767 {
8768 RECT rect;
8769 MSG msg;
8770 int count;
8771 HWND hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8772 100, 100, 200, 200, 0, 0, 0, NULL);
8773 ShowWindow( hwnd, SW_SHOW );
8774 UpdateWindow( hwnd );
8775 flush_events();
8776 flush_sequence();
8777 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)DispatchMessageCheckProc );
8778
8779 SetRect( &rect, -5, -5, 5, 5 );
8780 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8781 count = 0;
8782 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8783 {
8784 if (msg.message != WM_PAINT) DispatchMessage( &msg );
8785 else
8786 {
8787 flush_sequence();
8788 DispatchMessage( &msg );
8789 /* DispatchMessage will send WM_NCPAINT if non client area is still invalid after WM_PAINT */
8790 if (!count) ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8791 else ok_sequence( WmEmptySeq, "WmEmpty", FALSE );
8792 if (++count > 10) break;
8793 }
8794 }
8795 ok( msg.message == WM_PAINT && count > 10, "WM_PAINT messages stopped\n" );
8796
8797 trace("now without DispatchMessage\n");
8798 flush_sequence();
8799 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE|RDW_ERASE|RDW_FRAME );
8800 count = 0;
8801 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
8802 {
8803 if (msg.message != WM_PAINT) DispatchMessage( &msg );
8804 else
8805 {
8806 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
8807 flush_sequence();
8808 /* this will send WM_NCCPAINT just like DispatchMessage does */
8809 GetUpdateRgn( hwnd, hrgn, TRUE );
8810 ok_sequence( WmDispatchPaint, "WmDispatchPaint", FALSE );
8811 DeleteObject( hrgn );
8812 GetClientRect( hwnd, &rect );
8813 ValidateRect( hwnd, &rect ); /* this will stop WM_PAINTs */
8814 ok( !count, "Got multiple WM_PAINTs\n" );
8815 if (++count > 10) break;
8816 }
8817 }
8818 DestroyWindow(hwnd);
8819 }
8820
8821
8822 static const struct message WmUser[] = {
8823 { WM_USER, sent },
8824 { 0 }
8825 };
8826
8827 struct sendmsg_info
8828 {
8829 HWND hwnd;
8830 DWORD timeout;
8831 DWORD ret;
8832 };
8833
8834 static DWORD CALLBACK send_msg_thread( LPVOID arg )
8835 {
8836 struct sendmsg_info *info = arg;
8837 SetLastError( 0xdeadbeef );
8838 info->ret = SendMessageTimeoutA( info->hwnd, WM_USER, 0, 0, 0, info->timeout, NULL );
8839 if (!info->ret) ok( GetLastError() == ERROR_TIMEOUT ||
8840 broken(GetLastError() == 0), /* win9x */
8841 "unexpected error %d\n", GetLastError());
8842 return 0;
8843 }
8844
8845 static void wait_for_thread( HANDLE thread )
8846 {
8847 while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_SENDMESSAGE) != WAIT_OBJECT_0)
8848 {
8849 MSG msg;
8850 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage(&msg);
8851 }
8852 }
8853
8854 static LRESULT WINAPI send_msg_delay_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8855 {
8856 if (message == WM_USER) Sleep(200);
8857 return MsgCheckProcA( hwnd, message, wParam, lParam );
8858 }
8859
8860 static void test_SendMessageTimeout(void)
8861 {
8862 HANDLE thread;
8863 struct sendmsg_info info;
8864 DWORD tid;
8865 BOOL is_win9x;
8866
8867 info.hwnd = CreateWindowA( "TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
8868 100, 100, 200, 200, 0, 0, 0, NULL);
8869 flush_events();
8870 flush_sequence();
8871
8872 info.timeout = 1000;
8873 info.ret = 0xdeadbeef;
8874 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8875 wait_for_thread( thread );
8876 CloseHandle( thread );
8877 ok( info.ret == 1, "SendMessageTimeout failed\n" );
8878 ok_sequence( WmUser, "WmUser", FALSE );
8879
8880 info.timeout = 1;
8881 info.ret = 0xdeadbeef;
8882 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8883 Sleep(100); /* SendMessageTimeout should time out here */
8884 wait_for_thread( thread );
8885 CloseHandle( thread );
8886 ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8887 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8888
8889 /* 0 means infinite timeout (but not on win9x) */
8890 info.timeout = 0;
8891 info.ret = 0xdeadbeef;
8892 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8893 Sleep(100);
8894 wait_for_thread( thread );
8895 CloseHandle( thread );
8896 is_win9x = !info.ret;
8897 if (is_win9x) ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8898 else ok_sequence( WmUser, "WmUser", FALSE );
8899
8900 /* timeout is treated as signed despite the prototype (but not on win9x) */
8901 info.timeout = 0x7fffffff;
8902 info.ret = 0xdeadbeef;
8903 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8904 Sleep(100);
8905 wait_for_thread( thread );
8906 CloseHandle( thread );
8907 ok( info.ret == 1, "SendMessageTimeout failed\n" );
8908 ok_sequence( WmUser, "WmUser", FALSE );
8909
8910 info.timeout = 0x80000000;
8911 info.ret = 0xdeadbeef;
8912 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8913 Sleep(100);
8914 wait_for_thread( thread );
8915 CloseHandle( thread );
8916 if (is_win9x)
8917 {
8918 ok( info.ret == 1, "SendMessageTimeout failed\n" );
8919 ok_sequence( WmUser, "WmUser", FALSE );
8920 }
8921 else
8922 {
8923 ok( info.ret == 0, "SendMessageTimeout succeeded\n" );
8924 ok_sequence( WmEmptySeq, "WmEmptySeq", FALSE );
8925 }
8926
8927 /* now check for timeout during message processing */
8928 SetWindowLongPtrA( info.hwnd, GWLP_WNDPROC, (LONG_PTR)send_msg_delay_proc );
8929 info.timeout = 100;
8930 info.ret = 0xdeadbeef;
8931 thread = CreateThread( NULL, 0, send_msg_thread, &info, 0, &tid );
8932 wait_for_thread( thread );
8933 CloseHandle( thread );
8934 /* we should time out but still get the message */
8935 ok( info.ret == 0, "SendMessageTimeout failed\n" );
8936 ok_sequence( WmUser, "WmUser", FALSE );
8937
8938 DestroyWindow( info.hwnd );
8939 }
8940
8941
8942 /****************** edit message test *************************/
8943 #define ID_EDIT 0x1234
8944 static const struct message sl_edit_setfocus[] =
8945 {
8946 { HCBT_SETFOCUS, hook },
8947 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8948 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8949 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8950 { WM_SETFOCUS, sent|wparam, 0 },
8951 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8952 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 15 },
8953 { WM_CTLCOLOREDIT, sent|parent },
8954 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8955 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8956 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8957 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8958 { 0 }
8959 };
8960 static const struct message ml_edit_setfocus[] =
8961 {
8962 { HCBT_SETFOCUS, hook },
8963 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
8964 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8965 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8966 { WM_SETFOCUS, sent|wparam, 0 },
8967 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
8968 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
8969 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8970 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8971 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
8972 { 0 }
8973 };
8974 static const struct message sl_edit_killfocus[] =
8975 {
8976 { HCBT_SETFOCUS, hook },
8977 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8978 { WM_KILLFOCUS, sent|wparam, 0 },
8979 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8980 { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
8981 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_KILLFOCUS) },
8982 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
8983 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
8984 { 0 }
8985 };
8986 static const struct message sl_edit_lbutton_dblclk[] =
8987 {
8988 { WM_LBUTTONDBLCLK, sent },
8989 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
8990 { 0 }
8991 };
8992 static const struct message sl_edit_lbutton_down[] =
8993 {
8994 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
8995 { HCBT_SETFOCUS, hook },
8996 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
8997 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
8998 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
8999 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9000 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9001 { WM_CTLCOLOREDIT, sent|parent },
9002 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9003 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9004 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9005 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9006 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9007 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9008 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9009 { WM_CTLCOLOREDIT, sent|parent|optional },
9010 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9011 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9012 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9013 { 0 }
9014 };
9015 static const struct message ml_edit_lbutton_down[] =
9016 {
9017 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, 0 },
9018 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
9019 { HCBT_SETFOCUS, hook },
9020 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
9021 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
9022 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
9023 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
9024 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
9025 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
9026 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9027 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9028 { WM_COMMAND, sent|parent|wparam, MAKEWPARAM(ID_EDIT, EN_SETFOCUS) },
9029 { 0 }
9030 };
9031 static const struct message sl_edit_lbutton_up[] =
9032 {
9033 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9034 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9035 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9036 { WM_CAPTURECHANGED, sent|defwinproc },
9037 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
9038 { 0 }
9039 };
9040 static const struct message ml_edit_lbutton_up[] =
9041 {
9042 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
9043 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
9044 { WM_CAPTURECHANGED, sent|defwinproc },
9045 { 0 }
9046 };
9047
9048 static WNDPROC old_edit_proc;
9049
9050 static LRESULT CALLBACK edit_hook_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
9051 {
9052 static LONG defwndproc_counter = 0;
9053 LRESULT ret;
9054 struct recvd_message msg;
9055
9056 if (ignore_message( message )) return 0;
9057
9058 msg.hwnd = hwnd;
9059 msg.message = message;
9060 msg.flags = sent|wparam|lparam;
9061 if (defwndproc_counter) msg.flags |= defwinproc;
9062 msg.wParam = wParam;
9063 msg.lParam = lParam;
9064 msg.descr = "edit";
9065 add_message(&msg);
9066
9067 defwndproc_counter++;
9068 ret = CallWindowProcA(old_edit_proc, hwnd, message, wParam, lParam);
9069 defwndproc_counter--;
9070
9071 return ret;
9072 }
9073
9074 static void subclass_edit(void)
9075 {
9076 WNDCLASSA cls;
9077
9078 if (!GetClassInfoA(0, "edit", &cls)) assert(0);
9079
9080 old_edit_proc = cls.lpfnWndProc;
9081
9082 cls.hInstance = GetModuleHandle(0);
9083 cls.lpfnWndProc = edit_hook_proc;
9084 cls.lpszClassName = "my_edit_class";
9085 UnregisterClass(cls.lpszClassName, cls.hInstance);
9086 if (!RegisterClassA(&cls)) assert(0);
9087 }
9088
9089 static void test_edit_messages(void)
9090 {
9091 HWND hwnd, parent;
9092 DWORD dlg_code;
9093
9094 subclass_edit();
9095 log_all_parent_messages++;
9096
9097 parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9098 100, 100, 200, 200, 0, 0, 0, NULL);
9099 ok (parent != 0, "Failed to create parent window\n");
9100
9101 /* test single line edit */
9102 hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD,
9103 0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9104 ok(hwnd != 0, "Failed to create edit window\n");
9105
9106 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9107 ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS), "wrong dlg_code %08x\n", dlg_code);
9108
9109 ShowWindow(hwnd, SW_SHOW);
9110 UpdateWindow(hwnd);
9111 SetFocus(0);
9112 flush_sequence();
9113
9114 SetFocus(hwnd);
9115 ok_sequence(sl_edit_setfocus, "SetFocus(hwnd) on an edit", FALSE);
9116
9117 SetFocus(0);
9118 ok_sequence(sl_edit_killfocus, "SetFocus(0) on an edit", FALSE);
9119
9120 SetFocus(0);
9121 ReleaseCapture();
9122 flush_sequence();
9123
9124 SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9125 ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on an edit", FALSE);
9126
9127 SetFocus(0);
9128 ReleaseCapture();
9129 flush_sequence();
9130
9131 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9132 ok_sequence(sl_edit_lbutton_down, "WM_LBUTTONDOWN on an edit", FALSE);
9133
9134 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9135 ok_sequence(sl_edit_lbutton_up, "WM_LBUTTONUP on an edit", FALSE);
9136
9137 DestroyWindow(hwnd);
9138
9139 /* test multiline edit */
9140 hwnd = CreateWindowExA(0, "my_edit_class", "test", WS_CHILD | ES_MULTILINE,
9141 0, 0, 80, 20, parent, (HMENU)ID_EDIT, 0, NULL);
9142 ok(hwnd != 0, "Failed to create edit window\n");
9143
9144 dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
9145 ok(dlg_code == (DLGC_WANTCHARS|DLGC_HASSETSEL|DLGC_WANTARROWS|DLGC_WANTALLKEYS),
9146 "wrong dlg_code %08x\n", dlg_code);
9147
9148 ShowWindow(hwnd, SW_SHOW);
9149 UpdateWindow(hwnd);
9150 SetFocus(0);
9151 flush_sequence();
9152
9153 SetFocus(hwnd);
9154 ok_sequence(ml_edit_setfocus, "SetFocus(hwnd) on multiline edit", FALSE);
9155
9156 SetFocus(0);
9157 ok_sequence(sl_edit_killfocus, "SetFocus(0) on multiline edit", FALSE);
9158
9159 SetFocus(0);
9160 ReleaseCapture();
9161 flush_sequence();
9162
9163 SendMessageA(hwnd, WM_LBUTTONDBLCLK, 0, 0);
9164 ok_sequence(sl_edit_lbutton_dblclk, "WM_LBUTTONDBLCLK on multiline edit", FALSE);
9165
9166 SetFocus(0);
9167 ReleaseCapture();
9168 flush_sequence();
9169
9170 SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
9171 ok_sequence(ml_edit_lbutton_down, "WM_LBUTTONDOWN on multiline edit", FALSE);
9172
9173 SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
9174 ok_sequence(ml_edit_lbutton_up, "WM_LBUTTONUP on multiline edit", FALSE);
9175
9176 DestroyWindow(hwnd);
9177 DestroyWindow(parent);
9178
9179 log_all_parent_messages--;
9180 }
9181
9182 /**************************** End of Edit test ******************************/
9183
9184 static const struct message WmKeyDownSkippedSeq[] =
9185 {
9186 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 1 }, /* XP */
9187 { 0 }
9188 };
9189 static const struct message WmKeyDownWasDownSkippedSeq[] =
9190 {
9191 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0x40000001 }, /* XP */
9192 { 0 }
9193 };
9194 static const struct message WmKeyUpSkippedSeq[] =
9195 {
9196 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9197 { 0 }
9198 };
9199 static const struct message WmUserKeyUpSkippedSeq[] =
9200 {
9201 { WM_USER, sent },
9202 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'N', 0xc0000001 }, /* XP */
9203 { 0 }
9204 };
9205
9206 #define EV_STOP 0
9207 #define EV_SENDMSG 1
9208 #define EV_ACK 2
9209
9210 struct peekmsg_info
9211 {
9212 HWND hwnd;
9213 HANDLE hevent[3]; /* 0 - start/stop, 1 - SendMessage, 2 - ack */
9214 };
9215
9216 static DWORD CALLBACK send_msg_thread_2(void *param)
9217 {
9218 DWORD ret;
9219 struct peekmsg_info *info = param;
9220
9221 trace("thread: looping\n");
9222 SetEvent(info->hevent[EV_ACK]);
9223
9224 while (1)
9225 {
9226 ret = WaitForMultipleObjects(2, info->hevent, FALSE, INFINITE);
9227
9228 switch (ret)
9229 {
9230 case WAIT_OBJECT_0 + EV_STOP:
9231 trace("thread: exiting\n");
9232 return 0;
9233
9234 case WAIT_OBJECT_0 + EV_SENDMSG:
9235 trace("thread: sending message\n");
9236 ok( SendNotifyMessageA(info->hwnd, WM_USER, 0, 0),
9237 "SendNotifyMessageA failed error %u\n", GetLastError());
9238 SetEvent(info->hevent[EV_ACK]);
9239 break;
9240
9241 default:
9242 trace("unexpected return: %04x\n", ret);
9243 assert(0);
9244 break;
9245 }
9246 }
9247 return 0;
9248 }
9249
9250 static void test_PeekMessage(void)
9251 {
9252 MSG msg;
9253 HANDLE hthread;
9254 DWORD tid, qstatus;
9255 UINT qs_all_input = QS_ALLINPUT;
9256 UINT qs_input = QS_INPUT;
9257 BOOL ret;
9258 struct peekmsg_info info;
9259
9260 info.hwnd = CreateWindowA("TestWindowClass", NULL, WS_OVERLAPPEDWINDOW,
9261 100, 100, 200, 200, 0, 0, 0, NULL);
9262 assert(info.hwnd);
9263 ShowWindow(info.hwnd, SW_SHOW);
9264 UpdateWindow(info.hwnd);
9265 SetFocus(info.hwnd);
9266
9267 info.hevent[EV_STOP] = CreateEventA(NULL, 0, 0, NULL);
9268 info.hevent[EV_SENDMSG] = CreateEventA(NULL, 0, 0, NULL);
9269 info.hevent[EV_ACK] = CreateEventA(NULL, 0, 0, NULL);
9270
9271 hthread = CreateThread(NULL, 0, send_msg_thread_2, &info, 0, &tid);
9272 WaitForSingleObject(info.hevent[EV_ACK], 10000);
9273
9274 flush_events();
9275 flush_sequence();
9276
9277 SetLastError(0xdeadbeef);
9278 qstatus = GetQueueStatus(qs_all_input);
9279 if (GetLastError() == ERROR_INVALID_FLAGS)
9280 {
9281 trace("QS_RAWINPUT not supported on this platform\n");
9282 qs_all_input &= ~QS_RAWINPUT;
9283 qs_input &= ~QS_RAWINPUT;
9284 }
9285 if (qstatus & QS_POSTMESSAGE)
9286 {
9287 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) /* nothing */ ;
9288 qstatus = GetQueueStatus(qs_all_input);
9289 }
9290 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9291
9292 trace("signalling to send message\n");
9293 SetEvent(info.hevent[EV_SENDMSG]);
9294 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9295
9296 /* pass invalid QS_xxxx flags */
9297 SetLastError(0xdeadbeef);
9298 qstatus = GetQueueStatus(0xffffffff);
9299 ok(qstatus == 0 || broken(qstatus) /* win9x */, "GetQueueStatus should fail: %08x\n", qstatus);
9300 if (!qstatus)
9301 {
9302 ok(GetLastError() == ERROR_INVALID_FLAGS, "wrong error %d\n", GetLastError());
9303 qstatus = GetQueueStatus(qs_all_input);
9304 }
9305 qstatus &= ~MAKELONG( 0x4000, 0x4000 ); /* sometimes set on Win95 */
9306 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE),
9307 "wrong qstatus %08x\n", qstatus);
9308
9309 msg.message = 0;
9310 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9311 ok(!ret,
9312 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9313 msg.message);
9314 ok_sequence(WmUser, "WmUser", FALSE);
9315
9316 qstatus = GetQueueStatus(qs_all_input);
9317 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9318
9319 keybd_event('N', 0, 0, 0);
9320 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9321 qstatus = GetQueueStatus(qs_all_input);
9322 if (!(qstatus & MAKELONG(QS_KEY, QS_KEY)))
9323 {
9324 skip( "queuing key events not supported\n" );
9325 goto done;
9326 }
9327 ok(qstatus == MAKELONG(QS_KEY, QS_KEY),
9328 "wrong qstatus %08x\n", qstatus);
9329
9330 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9331 qstatus = GetQueueStatus(qs_all_input);
9332 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9333 "wrong qstatus %08x\n", qstatus);
9334
9335 InvalidateRect(info.hwnd, NULL, FALSE);
9336 qstatus = GetQueueStatus(qs_all_input);
9337 ok(qstatus == MAKELONG(QS_PAINT, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9338 "wrong qstatus %08x\n", qstatus);
9339
9340 trace("signalling to send message\n");
9341 SetEvent(info.hevent[EV_SENDMSG]);
9342 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9343
9344 qstatus = GetQueueStatus(qs_all_input);
9345 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9346 "wrong qstatus %08x\n", qstatus);
9347
9348 msg.message = 0;
9349 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (qs_input << 16));
9350 if (ret && msg.message == WM_CHAR)
9351 {
9352 win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9353 goto done;
9354 }
9355 ok(!ret,
9356 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9357 msg.message);
9358 if (!sequence_cnt) /* nt4 doesn't fetch anything with PM_QS_* flags */
9359 {
9360 win_skip( "PM_QS_* flags not supported in PeekMessage\n" );
9361 goto done;
9362 }
9363 ok_sequence(WmUser, "WmUser", FALSE);
9364
9365 qstatus = GetQueueStatus(qs_all_input);
9366 ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9367 "wrong qstatus %08x\n", qstatus);
9368
9369 trace("signalling to send message\n");
9370 SetEvent(info.hevent[EV_SENDMSG]);
9371 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9372
9373 qstatus = GetQueueStatus(qs_all_input);
9374 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9375 "wrong qstatus %08x\n", qstatus);
9376
9377 msg.message = 0;
9378 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9379 ok(!ret,
9380 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9381 msg.message);
9382 ok_sequence(WmUser, "WmUser", FALSE);
9383
9384 qstatus = GetQueueStatus(qs_all_input);
9385 ok(qstatus == MAKELONG(0, QS_PAINT|QS_POSTMESSAGE|QS_KEY),
9386 "wrong qstatus %08x\n", qstatus);
9387
9388 msg.message = 0;
9389 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9390 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9391 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9392 ret, msg.message, msg.wParam);
9393 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9394
9395 qstatus = GetQueueStatus(qs_all_input);
9396 ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9397 "wrong qstatus %08x\n", qstatus);
9398
9399 msg.message = 0;
9400 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_POSTMESSAGE);
9401 ok(!ret,
9402 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9403 msg.message);
9404 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9405
9406 qstatus = GetQueueStatus(qs_all_input);
9407 ok(qstatus == MAKELONG(0, QS_PAINT|QS_KEY),
9408 "wrong qstatus %08x\n", qstatus);
9409
9410 msg.message = 0;
9411 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9412 ok(ret && msg.message == WM_PAINT,
9413 "got %d and %04x instead of TRUE and WM_PAINT\n", ret, msg.message);
9414 DispatchMessageA(&msg);
9415 ok_sequence(WmPaint, "WmPaint", FALSE);
9416
9417 qstatus = GetQueueStatus(qs_all_input);
9418 ok(qstatus == MAKELONG(0, QS_KEY),
9419 "wrong qstatus %08x\n", qstatus);
9420
9421 msg.message = 0;
9422 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_PAINT);
9423 ok(!ret,
9424 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9425 msg.message);
9426 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9427
9428 qstatus = GetQueueStatus(qs_all_input);
9429 ok(qstatus == MAKELONG(0, QS_KEY),
9430 "wrong qstatus %08x\n", qstatus);
9431
9432 trace("signalling to send message\n");
9433 SetEvent(info.hevent[EV_SENDMSG]);
9434 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9435
9436 qstatus = GetQueueStatus(qs_all_input);
9437 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_KEY),
9438 "wrong qstatus %08x\n", qstatus);
9439
9440 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9441
9442 qstatus = GetQueueStatus(qs_all_input);
9443 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9444 "wrong qstatus %08x\n", qstatus);
9445
9446 msg.message = 0;
9447 ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9448 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9449 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9450 ret, msg.message, msg.wParam);
9451 ok_sequence(WmUser, "WmUser", FALSE);
9452
9453 qstatus = GetQueueStatus(qs_all_input);
9454 ok(qstatus == MAKELONG(0, QS_KEY),
9455 "wrong qstatus %08x\n", qstatus);
9456
9457 msg.message = 0;
9458 ret = PeekMessageA(&msg, 0, WM_CHAR, WM_CHAR, PM_REMOVE);
9459 ok(!ret,
9460 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9461 msg.message);
9462 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9463
9464 qstatus = GetQueueStatus(qs_all_input);
9465 ok(qstatus == MAKELONG(0, QS_KEY),
9466 "wrong qstatus %08x\n", qstatus);
9467
9468 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9469
9470 qstatus = GetQueueStatus(qs_all_input);
9471 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY),
9472 "wrong qstatus %08x\n", qstatus);
9473
9474 trace("signalling to send message\n");
9475 SetEvent(info.hevent[EV_SENDMSG]);
9476 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9477
9478 qstatus = GetQueueStatus(qs_all_input);
9479 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9480 "wrong qstatus %08x\n", qstatus);
9481
9482 msg.message = 0;
9483 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_KEY << 16));
9484 ok(!ret,
9485 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9486 msg.message);
9487 ok_sequence(WmUser, "WmUser", FALSE);
9488
9489 qstatus = GetQueueStatus(qs_all_input);
9490 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9491 "wrong qstatus %08x\n", qstatus);
9492
9493 msg.message = 0;
9494 if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9495 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9496 else /* workaround for a missing QS_RAWINPUT support */
9497 ret = PeekMessageA(&msg, 0, WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE);
9498 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9499 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9500 ret, msg.message, msg.wParam);
9501 ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9502
9503 qstatus = GetQueueStatus(qs_all_input);
9504 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE|QS_KEY),
9505 "wrong qstatus %08x\n", qstatus);
9506
9507 msg.message = 0;
9508 if (qs_all_input & QS_RAWINPUT) /* use QS_RAWINPUT only if supported */
9509 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | (QS_RAWINPUT << 16));
9510 else /* workaround for a missing QS_RAWINPUT support */
9511 ret = PeekMessageA(&msg, 0, WM_KEYUP, WM_KEYUP, PM_REMOVE);
9512 ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9513 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYUP wParam 'N'\n",
9514 ret, msg.message, msg.wParam);
9515 ok_sequence(WmKeyUpSkippedSeq, "WmKeyUpSkippedSeq", FALSE);
9516
9517 qstatus = GetQueueStatus(qs_all_input);
9518 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9519 "wrong qstatus %08x\n", qstatus);
9520
9521 msg.message = 0;
9522 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE);
9523 ok(!ret,
9524 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9525 msg.message);
9526 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9527
9528 qstatus = GetQueueStatus(qs_all_input);
9529 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9530 "wrong qstatus %08x\n", qstatus);
9531
9532 msg.message = 0;
9533 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9534 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9535 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9536 ret, msg.message, msg.wParam);
9537 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9538
9539 qstatus = GetQueueStatus(qs_all_input);
9540 ok(qstatus == 0,
9541 "wrong qstatus %08x\n", qstatus);
9542
9543 msg.message = 0;
9544 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9545 ok(!ret,
9546 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9547 msg.message);
9548 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9549
9550 qstatus = GetQueueStatus(qs_all_input);
9551 ok(qstatus == 0,
9552 "wrong qstatus %08x\n", qstatus);
9553
9554 /* test whether presence of the quit flag in the queue affects
9555 * the queue state
9556 */
9557 PostQuitMessage(0x1234abcd);
9558
9559 qstatus = GetQueueStatus(qs_all_input);
9560 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9561 "wrong qstatus %08x\n", qstatus);
9562
9563 PostMessageA(info.hwnd, WM_USER, 0, 0);
9564
9565 qstatus = GetQueueStatus(qs_all_input);
9566 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE),
9567 "wrong qstatus %08x\n", qstatus);
9568
9569 msg.message = 0;
9570 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9571 ok(ret && msg.message == WM_USER,
9572 "got %d and %04x instead of TRUE and WM_USER\n", ret, msg.message);
9573 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9574
9575 qstatus = GetQueueStatus(qs_all_input);
9576 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9577 "wrong qstatus %08x\n", qstatus);
9578
9579 msg.message = 0;
9580 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9581 ok(ret && msg.message == WM_QUIT,
9582 "got %d and %04x instead of TRUE and WM_QUIT\n", ret, msg.message);
9583 ok(msg.wParam == 0x1234abcd, "got wParam %08lx instead of 0x1234abcd\n", msg.wParam);
9584 ok(msg.lParam == 0, "got lParam %08lx instead of 0\n", msg.lParam);
9585 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9586
9587 qstatus = GetQueueStatus(qs_all_input);
9588 todo_wine {
9589 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE),
9590 "wrong qstatus %08x\n", qstatus);
9591 }
9592
9593 msg.message = 0;
9594 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
9595 ok(!ret,
9596 "PeekMessageA should have returned FALSE instead of msg %04x\n",
9597 msg.message);
9598 ok_sequence(WmEmptySeq, "WmEmptySeq", FALSE);
9599
9600 qstatus = GetQueueStatus(qs_all_input);
9601 ok(qstatus == 0,
9602 "wrong qstatus %08x\n", qstatus);
9603
9604 /* some GetMessage tests */
9605
9606 keybd_event('N', 0, 0, 0);
9607 qstatus = GetQueueStatus(qs_all_input);
9608 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9609
9610 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9611 qstatus = GetQueueStatus(qs_all_input);
9612 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9613
9614 if (qstatus)
9615 {
9616 ret = GetMessageA( &msg, 0, 0, 0 );
9617 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9618 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9619 ret, msg.message, msg.wParam);
9620 qstatus = GetQueueStatus(qs_all_input);
9621 ok(qstatus == MAKELONG(0, QS_KEY), "wrong qstatus %08x\n", qstatus);
9622 }
9623
9624 if (qstatus)
9625 {
9626 ret = GetMessageA( &msg, 0, 0, 0 );
9627 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9628 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9629 ret, msg.message, msg.wParam);
9630 ok_sequence(WmKeyDownSkippedSeq, "WmKeyDownSkippedSeq", FALSE);
9631 qstatus = GetQueueStatus(qs_all_input);
9632 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9633 }
9634
9635 keybd_event('N', 0, 0, 0);
9636 qstatus = GetQueueStatus(qs_all_input);
9637 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9638
9639 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9640 qstatus = GetQueueStatus(qs_all_input);
9641 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9642
9643 if (qstatus & (QS_KEY << 16))
9644 {
9645 ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9646 ok(ret && msg.message == WM_KEYDOWN && msg.wParam == 'N',
9647 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9648 ret, msg.message, msg.wParam);
9649 ok_sequence(WmKeyDownWasDownSkippedSeq, "WmKeyDownWasDownSkippedSeq", FALSE);
9650 qstatus = GetQueueStatus(qs_all_input);
9651 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9652 }
9653
9654 if (qstatus)
9655 {
9656 ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9657 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9658 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9659 ret, msg.message, msg.wParam);
9660 qstatus = GetQueueStatus(qs_all_input);
9661 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9662 }
9663
9664 keybd_event('N', 0, KEYEVENTF_KEYUP, 0);
9665 qstatus = GetQueueStatus(qs_all_input);
9666 ok(qstatus == MAKELONG(QS_KEY, QS_KEY), "wrong qstatus %08x\n", qstatus);
9667
9668 PostMessageA(info.hwnd, WM_CHAR, 'z', 0);
9669 qstatus = GetQueueStatus(qs_all_input);
9670 ok(qstatus == MAKELONG(QS_POSTMESSAGE, QS_POSTMESSAGE|QS_KEY), "wrong qstatus %08x\n", qstatus);
9671
9672 trace("signalling to send message\n");
9673 SetEvent(info.hevent[EV_SENDMSG]);
9674 WaitForSingleObject(info.hevent[EV_ACK], INFINITE);
9675 qstatus = GetQueueStatus(qs_all_input);
9676 ok(qstatus == MAKELONG(QS_SENDMESSAGE, QS_SENDMESSAGE|QS_POSTMESSAGE|QS_KEY),
9677 "wrong qstatus %08x\n", qstatus);
9678
9679 if (qstatus & (QS_KEY << 16))
9680 {
9681 ret = GetMessageA( &msg, 0, WM_KEYDOWN, WM_KEYUP );
9682 ok(ret && msg.message == WM_KEYUP && msg.wParam == 'N',
9683 "got %d and %04x wParam %08lx instead of TRUE and WM_KEYDOWN wParam 'N'\n",
9684 ret, msg.message, msg.wParam);
9685 ok_sequence(WmUserKeyUpSkippedSeq, "WmUserKeyUpSkippedSeq", FALSE);
9686 qstatus = GetQueueStatus(qs_all_input);
9687 ok(qstatus == MAKELONG(0, QS_POSTMESSAGE), "wrong qstatus %08x\n", qstatus);
9688 }
9689
9690 if (qstatus)
9691 {
9692 ret = GetMessageA( &msg, 0, WM_CHAR, WM_CHAR );
9693 ok(ret && msg.message == WM_CHAR && msg.wParam == 'z',
9694 "got %d and %04x wParam %08lx instead of TRUE and WM_CHAR wParam 'z'\n",
9695 ret, msg.message, msg.wParam);
9696 qstatus = GetQueueStatus(qs_all_input);
9697 ok(qstatus == 0, "wrong qstatus %08x\n", qstatus);
9698 }
9699 done:
9700 trace("signalling to exit\n");
9701 SetEvent(info.hevent[EV_STOP]);
9702
9703 WaitForSingleObject(hthread, INFINITE);
9704
9705 CloseHandle(hthread);
9706 CloseHandle(info.hevent[0]);
9707 CloseHandle(info.hevent[1]);
9708 CloseHandle(info.hevent[2]);
9709
9710 DestroyWindow(info.hwnd);
9711 }
9712
9713 static void wait_move_event(HWND hwnd, int x, int y)
9714 {
9715 MSG msg;
9716 DWORD time;
9717 BOOL ret;
9718 int go = 0;
9719
9720 time = GetTickCount();
9721 while (GetTickCount() - time < 200 && !go) {
9722 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9723 go = ret && msg.pt.x > x && msg.pt.y > y;
9724 if (!ret) MsgWaitForMultipleObjects( 0, NULL, FALSE, GetTickCount() - time, QS_ALLINPUT );
9725 }
9726 }
9727
9728 #define STEP 5
9729 static void test_PeekMessage2(void)
9730 {
9731 HWND hwnd;
9732 BOOL ret;
9733 MSG msg;
9734 UINT message;
9735 DWORD time1, time2, time3;
9736 int x1, y1, x2, y2, x3, y3;
9737 POINT pos;
9738
9739 time1 = time2 = time3 = 0;
9740 x1 = y1 = x2 = y2 = x3 = y3 = 0;
9741
9742 /* Initialise window and make sure it is ready for events */
9743 hwnd = CreateWindow("TestWindowClass", "PeekMessage2", WS_OVERLAPPEDWINDOW,
9744 10, 10, 800, 800, NULL, NULL, NULL, NULL);
9745 assert(hwnd);
9746 trace("Window for test_PeekMessage2 %p\n", hwnd);
9747 ShowWindow(hwnd, SW_SHOW);
9748 UpdateWindow(hwnd);
9749 SetFocus(hwnd);
9750 GetCursorPos(&pos);
9751 SetCursorPos(100, 100);
9752 mouse_event(MOUSEEVENTF_MOVE, -STEP, -STEP, 0, 0);
9753 flush_events();
9754
9755 /* Do initial mousemove, wait until we can see it
9756 and then do our test peek with PM_NOREMOVE. */
9757 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9758 wait_move_event(hwnd, 100-STEP, 100-STEP);
9759
9760 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9761 if (!ret)
9762 {
9763 skip( "queuing mouse events not supported\n" );
9764 goto done;
9765 }
9766 else
9767 {
9768 trace("1st move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9769 message = msg.message;
9770 time1 = msg.time;
9771 x1 = msg.pt.x;
9772 y1 = msg.pt.y;
9773 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9774 }
9775
9776 /* Allow time to advance a bit, and then simulate the user moving their
9777 * mouse around. After that we peek again with PM_NOREMOVE.
9778 * Although the previous mousemove message was never removed, the
9779 * mousemove we now peek should reflect the recent mouse movements
9780 * because the input queue will merge the move events. */
9781 Sleep(100);
9782 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9783 wait_move_event(hwnd, x1, y1);
9784
9785 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9786 ok(ret, "no message available\n");
9787 if (ret) {
9788 trace("2nd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9789 message = msg.message;
9790 time2 = msg.time;
9791 x2 = msg.pt.x;
9792 y2 = msg.pt.y;
9793 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9794 ok(time2 > time1, "message time not advanced: %x %x\n", time1, time2);
9795 ok(x2 != x1 && y2 != y1, "coords not changed: (%d %d) (%d %d)\n", x1, y1, x2, y2);
9796 }
9797
9798 /* Have another go, to drive the point home */
9799 Sleep(100);
9800 mouse_event(MOUSEEVENTF_MOVE, STEP, STEP, 0, 0);
9801 wait_move_event(hwnd, x2, y2);
9802
9803 ret = PeekMessageA(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_NOREMOVE);
9804 ok(ret, "no message available\n");
9805 if (ret) {
9806 trace("3rd move event: %04x %x %d %d\n", msg.message, msg.time, msg.pt.x, msg.pt.y);
9807 message = msg.message;
9808 time3 = msg.time;
9809 x3 = msg.pt.x;
9810 y3 = msg.pt.y;
9811 ok(message == WM_MOUSEMOVE, "message not WM_MOUSEMOVE, %04x instead\n", message);
9812 ok(time3 > time2, "message time not advanced: %x %x\n", time2, time3);
9813 ok(x3 != x2 && y3 != y2, "coords not changed: (%d %d) (%d %d)\n", x2, y2, x3, y3);
9814 }
9815
9816 done:
9817 DestroyWindow(hwnd);
9818 SetCursorPos(pos.x, pos.y);
9819 flush_events();
9820 }
9821
9822 static void test_quit_message(void)
9823 {
9824 MSG msg;
9825 BOOL ret;
9826
9827 /* test using PostQuitMessage */
9828 flush_events();
9829 PostQuitMessage(0xbeef);
9830
9831 ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9832 ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9833 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9834 ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9835
9836 ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9837 ok(ret, "PostMessage failed with error %d\n", GetLastError());
9838
9839 ret = GetMessage(&msg, NULL, 0, 0);
9840 ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9841 ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9842
9843 /* note: WM_QUIT message received after WM_USER message */
9844 ret = GetMessage(&msg, NULL, 0, 0);
9845 ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9846 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9847 ok(msg.wParam == 0xbeef, "wParam was 0x%lx instead of 0xbeef\n", msg.wParam);
9848
9849 ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
9850 ok( !ret || msg.message != WM_QUIT, "Received WM_QUIT again\n" );
9851
9852 /* now test with PostThreadMessage - different behaviour! */
9853 PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0xdead, 0);
9854
9855 ret = PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
9856 ok(ret, "PeekMessage failed with error %d\n", GetLastError());
9857 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9858 ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9859
9860 ret = PostThreadMessage(GetCurrentThreadId(), WM_USER, 0, 0);
9861 ok(ret, "PostMessage failed with error %d\n", GetLastError());
9862
9863 /* note: we receive the WM_QUIT message first this time */
9864 ret = GetMessage(&msg, NULL, 0, 0);
9865 ok(!ret, "GetMessage return %d with error %d instead of FALSE\n", ret, GetLastError());
9866 ok(msg.message == WM_QUIT, "Received message 0x%04x instead of WM_QUIT\n", msg.message);
9867 ok(msg.wParam == 0xdead, "wParam was 0x%lx instead of 0xdead\n", msg.wParam);
9868
9869 ret = GetMessage(&msg, NULL, 0, 0);
9870 ok(ret > 0, "GetMessage failed with error %d\n", GetLastError());
9871 ok(msg.message == WM_USER, "Received message 0x%04x instead of WM_USER\n", msg.message);
9872 }
9873
9874 static const struct message WmMouseHoverSeq[] = {
9875 { WM_MOUSEACTIVATE, sent|optional }, /* we can get those when moving the mouse in focus-follow-mouse mode under X11 */
9876 { WM_MOUSEACTIVATE, sent|optional },
9877 { WM_TIMER, sent|optional }, /* XP sends it */
9878 { WM_SYSTIMER, sent },
9879 { WM_MOUSEHOVER, sent|wparam, 0 },
9880 { 0 }
9881 };
9882
9883 static void pump_msg_loop_timeout(DWORD timeout, BOOL inject_mouse_move)
9884 {
9885 MSG msg;
9886 DWORD start_ticks, end_ticks;
9887
9888 start_ticks = GetTickCount();
9889 /* add some deviation (50%) to cover not expected delays */
9890 start_ticks += timeout / 2;
9891
9892 do
9893 {
9894 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
9895 {
9896 /* Timer proc messages are not dispatched to the window proc,
9897 * and therefore not logged.
9898 */
9899 if (msg.message == WM_TIMER || msg.message == WM_SYSTIMER)
9900 {
9901 struct recvd_message s_msg;
9902
9903 s_msg.hwnd = msg.hwnd;
9904 s_msg.message = msg.message;
9905 s_msg.flags = sent|wparam|lparam;
9906 s_msg.wParam = msg.wParam;
9907 s_msg.lParam = msg.lParam;
9908 s_msg.descr = "msg_loop";
9909 add_message(&s_msg);
9910 }
9911 DispatchMessage(&msg);
9912 }
9913
9914 end_ticks = GetTickCount();
9915
9916 /* inject WM_MOUSEMOVE to see how it changes tracking */
9917 if (inject_mouse_move && start_ticks + timeout / 2 >= end_ticks)
9918 {
9919 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
9920 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
9921
9922 inject_mouse_move = FALSE;
9923 }
9924 } while (start_ticks + timeout >= end_ticks);
9925 }
9926
9927 static void test_TrackMouseEvent(void)
9928 {
9929 TRACKMOUSEEVENT tme;
9930 BOOL ret;
9931 HWND hwnd, hchild;
9932 RECT rc_parent, rc_child;
9933 UINT default_hover_time, hover_width = 0, hover_height = 0;
9934
9935 #define track_hover(track_hwnd, track_hover_time) \
9936 tme.cbSize = sizeof(tme); \
9937 tme.dwFlags = TME_HOVER; \
9938 tme.hwndTrack = track_hwnd; \
9939 tme.dwHoverTime = track_hover_time; \
9940 SetLastError(0xdeadbeef); \
9941 ret = pTrackMouseEvent(&tme); \
9942 ok(ret, "TrackMouseEvent(TME_HOVER) error %d\n", GetLastError())
9943
9944 #define track_query(expected_track_flags, expected_track_hwnd, expected_hover_time) \
9945 tme.cbSize = sizeof(tme); \
9946 tme.dwFlags = TME_QUERY; \
9947 tme.hwndTrack = (HWND)0xdeadbeef; \
9948 tme.dwHoverTime = 0xdeadbeef; \
9949 SetLastError(0xdeadbeef); \
9950 ret = pTrackMouseEvent(&tme); \
9951 ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());\
9952 ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize); \
9953 ok(tme.dwFlags == (expected_track_flags), \
9954 "wrong tme.dwFlags %08x, expected %08x\n", tme.dwFlags, (expected_track_flags)); \
9955 ok(tme.hwndTrack == (expected_track_hwnd), \
9956 "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, (expected_track_hwnd)); \
9957 ok(tme.dwHoverTime == (expected_hover_time), \
9958 "wrong tme.dwHoverTime %u, expected %u\n", tme.dwHoverTime, (expected_hover_time))
9959
9960 #define track_hover_cancel(track_hwnd) \
9961 tme.cbSize = sizeof(tme); \
9962 tme.dwFlags = TME_HOVER | TME_CANCEL; \
9963 tme.hwndTrack = track_hwnd; \
9964 tme.dwHoverTime = 0xdeadbeef; \
9965 SetLastError(0xdeadbeef); \
9966 ret = pTrackMouseEvent(&tme); \
9967 ok(ret, "TrackMouseEvent(TME_HOVER | TME_CANCEL) error %d\n", GetLastError())
9968
9969 default_hover_time = 0xdeadbeef;
9970 SetLastError(0xdeadbeef);
9971 ret = SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &default_hover_time, 0);
9972 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
9973 "SystemParametersInfo(SPI_GETMOUSEHOVERTIME) error %u\n", GetLastError());
9974 if (!ret) default_hover_time = 400;
9975 trace("SPI_GETMOUSEHOVERTIME returned %u ms\n", default_hover_time);
9976
9977 SetLastError(0xdeadbeef);
9978 ret = SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH, 0, &hover_width, 0);
9979 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
9980 "SystemParametersInfo(SPI_GETMOUSEHOVERWIDTH) error %u\n", GetLastError());
9981 if (!ret) hover_width = 4;
9982 SetLastError(0xdeadbeef);
9983 ret = SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT, 0, &hover_height, 0);
9984 ok(ret || broken(GetLastError() == 0xdeadbeef), /* win9x */
9985 "SystemParametersInfo(SPI_GETMOUSEHOVERHEIGHT) error %u\n", GetLastError());
9986 if (!ret) hover_height = 4;
9987 trace("hover rect is %u x %d\n", hover_width, hover_height);
9988
9989 hwnd = CreateWindowEx(0, "TestWindowClass", NULL,
9990 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9991 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
9992 NULL, NULL, 0);
9993 assert(hwnd);
9994
9995 hchild = CreateWindowEx(0, "TestWindowClass", NULL,
9996 WS_CHILD | WS_BORDER | WS_VISIBLE,
9997 50, 50, 200, 200, hwnd,
9998 NULL, NULL, 0);
9999 assert(hchild);
10000
10001 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
10002 flush_events();
10003 flush_sequence();
10004
10005 tme.cbSize = 0;
10006 tme.dwFlags = TME_QUERY;
10007 tme.hwndTrack = (HWND)0xdeadbeef;
10008 tme.dwHoverTime = 0xdeadbeef;
10009 SetLastError(0xdeadbeef);
10010 ret = pTrackMouseEvent(&tme);
10011 ok(!ret, "TrackMouseEvent should fail\n");
10012 ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef),
10013 "not expected error %u\n", GetLastError());
10014
10015 tme.cbSize = sizeof(tme);
10016 tme.dwFlags = TME_HOVER;
10017 tme.hwndTrack = (HWND)0xdeadbeef;
10018 tme.dwHoverTime = 0xdeadbeef;
10019 SetLastError(0xdeadbeef);
10020 ret = pTrackMouseEvent(&tme);
10021 ok(!ret, "TrackMouseEvent should fail\n");
10022 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10023 "not expected error %u\n", GetLastError());
10024
10025 tme.cbSize = sizeof(tme);
10026 tme.dwFlags = TME_HOVER | TME_CANCEL;
10027 tme.hwndTrack = (HWND)0xdeadbeef;
10028 tme.dwHoverTime = 0xdeadbeef;
10029 SetLastError(0xdeadbeef);
10030 ret = pTrackMouseEvent(&tme);
10031 ok(!ret, "TrackMouseEvent should fail\n");
10032 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef),
10033 "not expected error %u\n", GetLastError());
10034
10035 GetWindowRect(hwnd, &rc_parent);
10036 GetWindowRect(hchild, &rc_child);
10037 SetCursorPos(rc_child.left - 10, rc_child.top - 10);
10038
10039 /* Process messages so that the system updates its internal current
10040 * window and hittest, otherwise TrackMouseEvent calls don't have any
10041 * effect.
10042 */
10043 flush_events();
10044 flush_sequence();
10045
10046 track_query(0, NULL, 0);
10047 track_hover(hchild, 0);
10048 track_query(0, NULL, 0);
10049
10050 flush_events();
10051 flush_sequence();
10052
10053 track_hover(hwnd, 0);
10054 tme.cbSize = sizeof(tme);
10055 tme.dwFlags = TME_QUERY;
10056 tme.hwndTrack = (HWND)0xdeadbeef;
10057 tme.dwHoverTime = 0xdeadbeef;
10058 SetLastError(0xdeadbeef);
10059 ret = pTrackMouseEvent(&tme);
10060 ok(ret, "TrackMouseEvent(TME_QUERY) error %d\n", GetLastError());
10061 ok(tme.cbSize == sizeof(tme), "wrong tme.cbSize %u\n", tme.cbSize);
10062 if (!tme.dwFlags)
10063 {
10064 skip( "Cursor not inside window, skipping TrackMouseEvent tests\n" );
10065 DestroyWindow( hwnd );
10066 return;
10067 }
10068 ok(tme.dwFlags == TME_HOVER, "wrong tme.dwFlags %08x, expected TME_HOVER\n", tme.dwFlags);
10069 ok(tme.hwndTrack == hwnd, "wrong tme.hwndTrack %p, expected %p\n", tme.hwndTrack, hwnd);
10070 ok(tme.dwHoverTime == default_hover_time, "wrong tme.dwHoverTime %u, expected %u\n",
10071 tme.dwHoverTime, default_hover_time);
10072
10073 pump_msg_loop_timeout(default_hover_time, FALSE);
10074 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10075
10076 track_query(0, NULL, 0);
10077
10078 track_hover(hwnd, HOVER_DEFAULT);
10079 track_query(TME_HOVER, hwnd, default_hover_time);
10080
10081 Sleep(default_hover_time / 2);
10082 mouse_event(MOUSEEVENTF_MOVE, -1, 0, 0, 0);
10083 mouse_event(MOUSEEVENTF_MOVE, 1, 0, 0, 0);
10084
10085 track_query(TME_HOVER, hwnd, default_hover_time);
10086
10087 pump_msg_loop_timeout(default_hover_time, FALSE);
10088 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10089
10090 track_query(0, NULL, 0);
10091
10092 track_hover(hwnd, HOVER_DEFAULT);
10093 track_query(TME_HOVER, hwnd, default_hover_time);
10094
10095 pump_msg_loop_timeout(default_hover_time, TRUE);
10096 ok_sequence(WmMouseHoverSeq, "WmMouseHoverSeq", FALSE);
10097
10098 track_query(0, NULL, 0);
10099
10100 track_hover(hwnd, HOVER_DEFAULT);
10101 track_query(TME_HOVER, hwnd, default_hover_time);
10102 track_hover_cancel(hwnd);
10103
10104 DestroyWindow(hwnd);
10105
10106 #undef track_hover
10107 #undef track_query
10108 #undef track_hover_cancel
10109 }
10110
10111
10112 static const struct message WmSetWindowRgn[] = {
10113 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10114 { WM_NCCALCSIZE, sent|wparam, 1 },
10115 { WM_NCPAINT, sent|optional }, /* wparam != 1 */
10116 { WM_GETTEXT, sent|defwinproc|optional },
10117 { WM_ERASEBKGND, sent|optional },
10118 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10119 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10120 { 0 }
10121 };
10122
10123 static const struct message WmSetWindowRgn_no_redraw[] = {
10124 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10125 { WM_NCCALCSIZE, sent|wparam, 1 },
10126 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW },
10127 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10128 { 0 }
10129 };
10130
10131 static const struct message WmSetWindowRgn_clear[] = {
10132 { WM_WINDOWPOSCHANGING, sent/*|wparam*/, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE/*|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE only on some Windows versions */ },
10133 { WM_NCCALCSIZE, sent|wparam, 1 },
10134 { WM_NCPAINT, sent|optional },
10135 { WM_GETTEXT, sent|defwinproc|optional },
10136 { WM_ERASEBKGND, sent|optional }, /* FIXME: remove optional once Wine is fixed */
10137 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10138 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
10139 { WM_NCPAINT, sent|optional },
10140 { WM_GETTEXT, sent|defwinproc|optional },
10141 { WM_ERASEBKGND, sent|optional },
10142 { WM_WINDOWPOSCHANGING, sent|optional },
10143 { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10144 { WM_NCPAINT, sent|optional },
10145 { WM_GETTEXT, sent|defwinproc|optional },
10146 { WM_ERASEBKGND, sent|optional },
10147 { WM_WINDOWPOSCHANGED, sent|optional|wparam, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE },
10148 { WM_NCCALCSIZE, sent|optional|wparam, 1 },
10149 { WM_NCPAINT, sent|optional },
10150 { WM_GETTEXT, sent|defwinproc|optional },
10151 { WM_ERASEBKGND, sent|optional },
10152 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10153 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, 0, 0 },
10154 { 0 }
10155 };
10156
10157 static void test_SetWindowRgn(void)
10158 {
10159 HRGN hrgn;
10160 HWND hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10161 100, 100, 200, 200, 0, 0, 0, NULL);
10162 ok( hwnd != 0, "Failed to create overlapped window\n" );
10163
10164 ShowWindow( hwnd, SW_SHOW );
10165 UpdateWindow( hwnd );
10166 flush_events();
10167 flush_sequence();
10168
10169 trace("testing SetWindowRgn\n");
10170 hrgn = CreateRectRgn( 0, 0, 150, 150 );
10171 SetWindowRgn( hwnd, hrgn, TRUE );
10172 ok_sequence( WmSetWindowRgn, "WmSetWindowRgn", FALSE );
10173
10174 hrgn = CreateRectRgn( 30, 30, 160, 160 );
10175 SetWindowRgn( hwnd, hrgn, FALSE );
10176 ok_sequence( WmSetWindowRgn_no_redraw, "WmSetWindowRgn_no_redraw", FALSE );
10177
10178 hrgn = CreateRectRgn( 0, 0, 180, 180 );
10179 SetWindowRgn( hwnd, hrgn, TRUE );
10180 ok_sequence( WmSetWindowRgn, "WmSetWindowRgn2", FALSE );
10181
10182 SetWindowRgn( hwnd, 0, TRUE );
10183 ok_sequence( WmSetWindowRgn_clear, "WmSetWindowRgn_clear", FALSE );
10184
10185 DestroyWindow( hwnd );
10186 }
10187
10188 /*************************** ShowWindow() test ******************************/
10189 static const struct message WmShowNormal[] = {
10190 { WM_SHOWWINDOW, sent|wparam, 1 },
10191 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10192 { HCBT_ACTIVATE, hook },
10193 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10194 { HCBT_SETFOCUS, hook },
10195 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10196 { 0 }
10197 };
10198 static const struct message WmShow[] = {
10199 { WM_SHOWWINDOW, sent|wparam, 1 },
10200 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10201 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10202 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10203 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10204 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10205 { 0 }
10206 };
10207 static const struct message WmShowNoActivate_1[] = {
10208 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10209 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10210 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10211 { WM_MOVE, sent|defwinproc|optional },
10212 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10213 { 0 }
10214 };
10215 static const struct message WmShowNoActivate_2[] = {
10216 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWNOACTIVATE },
10217 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10218 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10219 { WM_MOVE, sent|defwinproc },
10220 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10221 { HCBT_SETFOCUS, hook|optional },
10222 { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10223 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10224 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10225 { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10226 { 0 }
10227 };
10228 static const struct message WmShowNA_1[] = {
10229 { WM_SHOWWINDOW, sent|wparam, 1 },
10230 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10231 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10232 { 0 }
10233 };
10234 static const struct message WmShowNA_2[] = {
10235 { WM_SHOWWINDOW, sent|wparam, 1 },
10236 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE },
10237 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10238 { 0 }
10239 };
10240 static const struct message WmRestore_1[] = {
10241 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10242 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10243 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10244 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10245 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10246 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10247 { WM_MOVE, sent|defwinproc },
10248 { WM_SIZE, sent|wparam|defwinproc, SIZE_RESTORED },
10249 { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10250 { 0 }
10251 };
10252 static const struct message WmRestore_2[] = {
10253 { WM_SHOWWINDOW, sent|wparam, 1 },
10254 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10255 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10256 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10257 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10258 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10259 { 0 }
10260 };
10261 static const struct message WmRestore_3[] = {
10262 { HCBT_MINMAX, hook|lparam, 0, SW_RESTORE },
10263 { WM_GETMINMAXINFO, sent },
10264 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10265 { HCBT_ACTIVATE, hook|optional }, /* win2003 doesn't send it */
10266 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2003 doesn't send it */
10267 { HCBT_SETFOCUS, hook|optional }, /* win2003 doesn't send it */
10268 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10269 { WM_MOVE, sent|defwinproc },
10270 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10271 { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10272 { 0 }
10273 };
10274 static const struct message WmRestore_4[] = {
10275 { HCBT_MINMAX, hook|lparam|optional, 0, SW_RESTORE },
10276 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10277 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10278 { WM_MOVE, sent|defwinproc|optional },
10279 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10280 { 0 }
10281 };
10282 static const struct message WmRestore_5[] = {
10283 { HCBT_MINMAX, hook|lparam|optional, 0, SW_SHOWNORMAL },
10284 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10285 { HCBT_ACTIVATE, hook|optional },
10286 { HCBT_SETFOCUS, hook|optional },
10287 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10288 { WM_MOVE, sent|defwinproc|optional },
10289 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_RESTORED },
10290 { 0 }
10291 };
10292 static const struct message WmHide_1[] = {
10293 { WM_SHOWWINDOW, sent|wparam, 0 },
10294 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10295 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10296 { HCBT_ACTIVATE, hook|optional },
10297 { HCBT_SETFOCUS, hook|optional }, /* win2000 sends it */
10298 { 0 }
10299 };
10300 static const struct message WmHide_2[] = {
10301 { WM_SHOWWINDOW, sent|wparam, 0 },
10302 { WM_WINDOWPOSCHANGING, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10303 { WM_WINDOWPOSCHANGED, sent /*|wparam, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ }, /* win2000 doesn't add SWP_NOACTIVATE */
10304 { HCBT_ACTIVATE, hook|optional },
10305 { 0 }
10306 };
10307 static const struct message WmHide_3[] = {
10308 { WM_SHOWWINDOW, sent|wparam, 0 },
10309 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE },
10310 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10311 { HCBT_SETFOCUS, hook|optional },
10312 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10313 { 0 }
10314 };
10315 static const struct message WmShowMinimized_1[] = {
10316 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10317 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10318 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10319 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10320 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10321 { WM_MOVE, sent|defwinproc },
10322 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10323 { 0 }
10324 };
10325 static const struct message WmMinimize_1[] = {
10326 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10327 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10328 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10329 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10330 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10331 { WM_MOVE, sent|defwinproc },
10332 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10333 { 0 }
10334 };
10335 static const struct message WmMinimize_2[] = {
10336 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10337 { HCBT_SETFOCUS, hook|optional },
10338 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10339 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10340 { WM_MOVE, sent|defwinproc },
10341 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10342 { 0 }
10343 };
10344 static const struct message WmMinimize_3[] = {
10345 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10346 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10347 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10348 { WM_MOVE, sent|defwinproc },
10349 { WM_SIZE, sent|wparam|lparam|defwinproc, SIZE_MINIMIZED, 0 },
10350 { 0 }
10351 };
10352 static const struct message WmShowMinNoActivate[] = {
10353 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10354 { WM_WINDOWPOSCHANGING, sent },
10355 { WM_WINDOWPOSCHANGED, sent },
10356 { WM_MOVE, sent|defwinproc|optional },
10357 { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
10358 { 0 }
10359 };
10360 static const struct message WmMinMax_1[] = {
10361 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINIMIZED },
10362 { 0 }
10363 };
10364 static const struct message WmMinMax_2[] = {
10365 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10366 { WM_GETMINMAXINFO, sent|optional },
10367 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED },
10368 { HCBT_ACTIVATE, hook|optional },
10369 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10370 { HCBT_SETFOCUS, hook|optional },
10371 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10372 { WM_MOVE, sent|defwinproc|optional },
10373 { WM_SIZE, sent|wparam|defwinproc|optional, SIZE_MAXIMIZED },
10374 { HCBT_SETFOCUS, hook|optional },
10375 { 0 }
10376 };
10377 static const struct message WmMinMax_3[] = {
10378 { HCBT_MINMAX, hook|lparam, 0, SW_MINIMIZE },
10379 { HCBT_SETFOCUS, hook|optional },
10380 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10381 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10382 { WM_MOVE, sent|defwinproc|optional },
10383 { WM_SIZE, sent|wparam|lparam|defwinproc|optional, SIZE_MINIMIZED, 0 },
10384 { 0 }
10385 };
10386 static const struct message WmMinMax_4[] = {
10387 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMINNOACTIVE },
10388 { 0 }
10389 };
10390 static const struct message WmShowMaximized_1[] = {
10391 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10392 { WM_GETMINMAXINFO, sent },
10393 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10394 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10395 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10396 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10397 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10398 { WM_MOVE, sent|defwinproc },
10399 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10400 { HCBT_SETFOCUS, hook|optional }, /* win2003 sends it */
10401 { 0 }
10402 };
10403 static const struct message WmShowMaximized_2[] = {
10404 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10405 { WM_GETMINMAXINFO, sent },
10406 { WM_WINDOWPOSCHANGING, sent|optional },
10407 { HCBT_ACTIVATE, hook|optional },
10408 { WM_WINDOWPOSCHANGED, sent|optional },
10409 { WM_MOVE, sent|optional }, /* Win9x doesn't send it */
10410 { WM_SIZE, sent|wparam|optional, SIZE_MAXIMIZED }, /* Win9x doesn't send it */
10411 { WM_WINDOWPOSCHANGING, sent|optional },
10412 { HCBT_SETFOCUS, hook|optional },
10413 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_STATECHANGED },
10414 { WM_MOVE, sent|defwinproc },
10415 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10416 { HCBT_SETFOCUS, hook|optional },
10417 { 0 }
10418 };
10419 static const struct message WmShowMaximized_3[] = {
10420 { HCBT_MINMAX, hook|lparam, 0, SW_SHOWMAXIMIZED },
10421 { WM_GETMINMAXINFO, sent|optional },
10422 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10423 { HCBT_ACTIVATE, hook|optional }, /* win2000 doesn't send it */
10424 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE }, /* win2000 doesn't send it */
10425 { HCBT_SETFOCUS, hook|optional }, /* win2000 doesn't send it */
10426 { WM_WINDOWPOSCHANGED, sent|wparam, SWP_FRAMECHANGED|SWP_STATECHANGED, 0, SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE|SWP_NOSIZE|SWP_NOMOVE },
10427 { WM_MOVE, sent|defwinproc|optional },
10428 { WM_SIZE, sent|wparam|defwinproc, SIZE_MAXIMIZED },
10429 { 0 }
10430 };
10431
10432 static void test_ShowWindow(void)
10433 {
10434 /* ShowWindow commands in random order */
10435 static const struct
10436 {
10437 INT cmd; /* ShowWindow command */
10438 LPARAM ret; /* ShowWindow return value */
10439 DWORD style; /* window style after the command */
10440 const struct message *msg; /* message sequence the command produces */
10441 BOOL todo_msg; /* message sequence doesn't match what Wine does */
10442 } sw[] =
10443 {
10444 /* 1 */ { SW_SHOWNORMAL, FALSE, WS_VISIBLE, WmShowNormal, FALSE },
10445 /* 2 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10446 /* 3 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10447 /* 4 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10448 /* 5 */ { SW_SHOWMINIMIZED, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinimized_1, FALSE },
10449 /* 6 */ { SW_SHOWMINIMIZED, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_1, FALSE },
10450 /* 7 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_1, FALSE },
10451 /* 8 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10452 /* 9 */ { SW_SHOWMAXIMIZED, FALSE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_1, FALSE },
10453 /* 10 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10454 /* 11 */ { SW_HIDE, TRUE, WS_MAXIMIZE, WmHide_1, FALSE },
10455 /* 12 */ { SW_HIDE, FALSE, WS_MAXIMIZE, WmEmptySeq, FALSE },
10456 /* 13 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_1, FALSE },
10457 /* 14 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10458 /* 15 */ { SW_HIDE, TRUE, 0, WmHide_2, FALSE },
10459 /* 16 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10460 /* 17 */ { SW_SHOW, FALSE, WS_VISIBLE, WmShow, FALSE },
10461 /* 18 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10462 /* 19 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10463 /* 20 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10464 /* 21 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10465 /* 22 */ { SW_SHOWMINNOACTIVE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowMinNoActivate, TRUE },
10466 /* 23 */ { SW_SHOWMINNOACTIVE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_4, FALSE },
10467 /* 24 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10468 /* 25 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10469 /* 26 */ { SW_SHOWNA, FALSE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_1, FALSE },
10470 /* 27 */ { SW_SHOWNA, TRUE, WS_VISIBLE|WS_MINIMIZE, WmShowNA_2, FALSE },
10471 /* 28 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10472 /* 29 */ { SW_HIDE, FALSE, WS_MINIMIZE, WmEmptySeq, FALSE },
10473 /* 30 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_1, FALSE },
10474 /* 31 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10475 /* 32 */ { SW_HIDE, TRUE, 0, WmHide_3, FALSE },
10476 /* 33 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10477 /* 34 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE }, /* what does this mean?! */
10478 /* 35 */ { SW_NORMALNA, FALSE, 0, WmEmptySeq, FALSE },
10479 /* 36 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10480 /* 37 */ { SW_RESTORE, FALSE, WS_VISIBLE, WmRestore_2, FALSE },
10481 /* 38 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10482 /* 39 */ { SW_SHOWNOACTIVATE, TRUE, WS_VISIBLE, WmEmptySeq, FALSE },
10483 /* 40 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_2, FALSE },
10484 /* 41 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10485 /* 42 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_2, FALSE },
10486 /* 43 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmMinMax_2, FALSE },
10487 /* 44 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_1, FALSE },
10488 /* 45 */ { SW_MINIMIZE, TRUE, WS_VISIBLE|WS_MINIMIZE, WmMinMax_3, FALSE },
10489 /* 46 */ { SW_RESTORE, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmRestore_3, FALSE },
10490 /* 47 */ { SW_RESTORE, TRUE, WS_VISIBLE, WmRestore_4, FALSE },
10491 /* 48 */ { SW_SHOWMAXIMIZED, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmShowMaximized_3, FALSE },
10492 /* 49 */ { SW_SHOW, TRUE, WS_VISIBLE|WS_MAXIMIZE, WmEmptySeq, FALSE },
10493 /* 50 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
10494 /* 51 */ { SW_SHOWNORMAL, TRUE, WS_VISIBLE, WmRestore_5, FALSE },
10495 /* 52 */ { SW_HIDE, TRUE, 0, WmHide_1, FALSE },
10496 /* 53 */ { SW_HIDE, FALSE, 0, WmEmptySeq, FALSE },
10497 /* 54 */ { SW_MINIMIZE, FALSE, WS_VISIBLE|WS_MINIMIZE, WmMinimize_3, FALSE },
10498 /* 55 */ { SW_HIDE, TRUE, WS_MINIMIZE, WmHide_2, FALSE },
10499 /* 56 */ { SW_SHOWNOACTIVATE, FALSE, WS_VISIBLE, WmShowNoActivate_2, FALSE },
10500 /* 57 */ { SW_SHOW, TRUE, WS_VISIBLE, WmEmptySeq, FALSE }
10501 };
10502 HWND hwnd;
10503 DWORD style;
10504 LPARAM ret;
10505 INT i;
10506
10507 #define WS_BASE (WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_POPUP|WS_CLIPSIBLINGS)
10508 hwnd = CreateWindowEx(0, "ShowWindowClass", NULL, WS_BASE,
10509 120, 120, 90, 90,
10510 0, 0, 0, NULL);
10511 assert(hwnd);
10512
10513 style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10514 ok(style == 0, "expected style 0, got %08x\n", style);
10515
10516 flush_events();
10517 flush_sequence();
10518
10519 for (i = 0; i < sizeof(sw)/sizeof(sw[0]); i++)
10520 {
10521 static const char * const sw_cmd_name[13] =
10522 {
10523 "SW_HIDE", "SW_SHOWNORMAL", "SW_SHOWMINIMIZED", "SW_SHOWMAXIMIZED",
10524 "SW_SHOWNOACTIVATE", "SW_SHOW", "SW_MINIMIZE", "SW_SHOWMINNOACTIVE",
10525 "SW_SHOWNA", "SW_RESTORE", "SW_SHOWDEFAULT", "SW_FORCEMINIMIZE",
10526 "SW_NORMALNA" /* 0xCC */
10527 };
10528 char comment[64];
10529 INT idx; /* index into the above array of names */
10530
10531 idx = (sw[i].cmd == SW_NORMALNA) ? 12 : sw[i].cmd;
10532
10533 style = GetWindowLong(hwnd, GWL_STYLE);
10534 trace("%d: sending %s, current window style %08x\n", i+1, sw_cmd_name[idx], style);
10535 ret = ShowWindow(hwnd, sw[i].cmd);
10536 ok(!ret == !sw[i].ret, "%d: cmd %s: expected ret %lu, got %lu\n", i+1, sw_cmd_name[idx], sw[i].ret, ret);
10537 style = GetWindowLong(hwnd, GWL_STYLE) & ~WS_BASE;
10538 ok(style == sw[i].style, "%d: expected style %08x, got %08x\n", i+1, sw[i].style, style);
10539
10540 sprintf(comment, "%d: ShowWindow(%s)", i+1, sw_cmd_name[idx]);
10541 ok_sequence(sw[i].msg, comment, sw[i].todo_msg);
10542
10543 flush_events();
10544 flush_sequence();
10545 }
10546
10547 DestroyWindow(hwnd);
10548 }
10549
10550 static INT_PTR WINAPI test_dlg_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
10551 {
10552 struct recvd_message msg;
10553
10554 if (ignore_message( message )) return 0;
10555
10556 msg.hwnd = hwnd;
10557 msg.message = message;
10558 msg.flags = sent|wparam|lparam;
10559 msg.wParam = wParam;
10560 msg.lParam = lParam;
10561 msg.descr = "dialog";
10562 add_message(&msg);
10563
10564 /* calling DefDlgProc leads to a recursion under XP */
10565
10566 switch (message)
10567 {
10568 case WM_INITDIALOG:
10569 case WM_GETDLGCODE:
10570 return 0;
10571 }
10572 return 1;
10573 }
10574
10575 static const struct message WmDefDlgSetFocus_1[] = {
10576 { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10577 { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10578 { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10579 { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10580 { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10581 { HCBT_SETFOCUS, hook },
10582 { WM_IME_SETCONTEXT, sent|wparam|optional, 1 },
10583 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10584 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
10585 { WM_SETFOCUS, sent|wparam, 0 },
10586 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 10 },
10587 { WM_CTLCOLOREDIT, sent },
10588 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 11 },
10589 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10590 { EVENT_OBJECT_LOCATIONCHANGE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10591 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10592 { WM_COMMAND, sent|wparam, MAKEWPARAM(1, EN_SETFOCUS) },
10593 { 0 }
10594 };
10595 static const struct message WmDefDlgSetFocus_2[] = {
10596 { WM_GETDLGCODE, sent|wparam|lparam, 0, 0 },
10597 { WM_GETTEXTLENGTH, sent|wparam|lparam|optional, 0, 0 }, /* XP */
10598 { WM_GETTEXT, sent|wparam|optional, 6 }, /* XP */
10599 { WM_GETTEXT, sent|wparam|optional, 12 }, /* XP */
10600 { EM_SETSEL, sent|wparam, 0 }, /* XP sets lparam to text length, Win9x to -2 */
10601 { EVENT_OBJECT_HIDE, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10602 { WM_CTLCOLOREDIT, sent|optional }, /* XP */
10603 { EVENT_OBJECT_SHOW, winevent_hook|wparam|lparam, OBJID_CARET, 0 },
10604 { 0 }
10605 };
10606 /* Creation of a dialog */
10607 static const struct message WmCreateDialogParamSeq_1[] = {
10608 { HCBT_CREATEWND, hook },
10609 { WM_NCCREATE, sent },
10610 { WM_NCCALCSIZE, sent|wparam, 0 },
10611 { WM_CREATE, sent },
10612 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10613 { WM_SIZE, sent|wparam, SIZE_RESTORED },
10614 { WM_MOVE, sent },
10615 { WM_SETFONT, sent },
10616 { WM_INITDIALOG, sent },
10617 { WM_CHANGEUISTATE, sent|optional },
10618 { 0 }
10619 };
10620 /* Creation of a dialog */
10621 static const struct message WmCreateDialogParamSeq_2[] = {
10622 { HCBT_CREATEWND, hook },
10623 { WM_NCCREATE, sent },
10624 { WM_NCCALCSIZE, sent|wparam, 0 },
10625 { WM_CREATE, sent },
10626 { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, 0, 0 },
10627 { WM_SIZE, sent|wparam, SIZE_RESTORED },
10628 { WM_MOVE, sent },
10629 { WM_CHANGEUISTATE, sent|optional },
10630 { 0 }
10631 };
10632
10633 static void test_dialog_messages(void)
10634 {
10635 WNDCLASS cls;
10636 HWND hdlg, hedit1, hedit2, hfocus;
10637 LRESULT ret;
10638
10639 #define set_selection(hctl, start, end) \
10640 ret = SendMessage(hctl, EM_SETSEL, start, end); \
10641 ok(ret == 1, "EM_SETSEL returned %ld\n", ret);
10642
10643 #define check_selection(hctl, start, end) \
10644 ret = SendMessage(hctl, EM_GETSEL, 0, 0); \
10645 ok(ret == MAKELRESULT(start, end), "wrong selection (%d - %d)\n", LOWORD(ret), HIWORD(ret));
10646
10647 subclass_edit();
10648
10649 hdlg = CreateWindowEx(WS_EX_DLGMODALFRAME, "TestDialogClass", NULL,
10650 WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,
10651 0, 0, 100, 100, 0, 0, 0, NULL);
10652 ok(hdlg != 0, "Failed to create custom dialog window\n");
10653
10654 hedit1 = CreateWindowEx(0, "my_edit_class", NULL,
10655 WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10656 0, 0, 80, 20, hdlg, (HMENU)1, 0, NULL);
10657 ok(hedit1 != 0, "Failed to create edit control\n");
10658 hedit2 = CreateWindowEx(0, "my_edit_class", NULL,
10659 WS_CHILD|WS_BORDER|WS_VISIBLE|WS_TABSTOP,
10660 0, 40, 80, 20, hdlg, (HMENU)2, 0, NULL);
10661 ok(hedit2 != 0, "Failed to create edit control\n");
10662
10663 SendMessage(hedit1, WM_SETTEXT, 0, (LPARAM)"hello");
10664 SendMessage(hedit2, WM_SETTEXT, 0, (LPARAM)"bye");
10665
10666 hfocus = GetFocus();
10667 ok(hfocus == hdlg, "wrong focus %p\n", hfocus);
10668
10669 SetFocus(hedit2);
10670 hfocus = GetFocus();
10671 ok(hfocus == hedit2, "wrong focus %p\n", hfocus);
10672
10673 check_selection(hedit1, 0, 0);
10674 check_selection(hedit2, 0, 0);
10675
10676 set_selection(hedit2, 0, -1);
10677 check_selection(hedit2, 0, 3);
10678
10679 SetFocus(0);
10680 hfocus = GetFocus();
10681 ok(hfocus == 0, "wrong focus %p\n", hfocus);
10682
10683 flush_sequence();
10684 ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10685 ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10686 ok_sequence(WmDefDlgSetFocus_1, "DefDlgProc(WM_SETFOCUS) 1", FALSE);
10687
10688 hfocus = GetFocus();
10689 ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10690
10691 check_selection(hedit1, 0, 5);
10692 check_selection(hedit2, 0, 3);
10693
10694 flush_sequence();
10695 ret = DefDlgProc(hdlg, WM_SETFOCUS, 0, 0);
10696 ok(ret == 0, "WM_SETFOCUS returned %ld\n", ret);
10697 ok_sequence(WmDefDlgSetFocus_2, "DefDlgProc(WM_SETFOCUS) 2", FALSE);
10698
10699 hfocus = GetFocus();
10700 ok(hfocus == hedit1, "wrong focus %p\n", hfocus);
10701
10702 check_selection(hedit1, 0, 5);
10703 check_selection(hedit2, 0, 3);
10704
10705 EndDialog(hdlg, 0);
10706 DestroyWindow(hedit1);
10707 DestroyWindow(hedit2);
10708 DestroyWindow(hdlg);
10709 flush_sequence();
10710
10711 #undef set_selection
10712 #undef check_selection
10713
10714 ok(GetClassInfo(0, "#32770", &cls), "GetClassInfo failed\n");
10715 cls.lpszClassName = "MyDialogClass";
10716 cls.hInstance = GetModuleHandle(0);
10717 /* need a cast since a dlgproc is used as a wndproc */
10718 cls.lpfnWndProc = (WNDPROC)test_dlg_proc;
10719 if (!RegisterClass(&cls)) assert(0);
10720
10721 hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, test_dlg_proc, 0);
10722 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10723 ok_sequence(WmCreateDialogParamSeq_1, "CreateDialogParam_1", FALSE);
10724 EndDialog(hdlg, 0);
10725 DestroyWindow(hdlg);
10726 flush_sequence();
10727
10728 hdlg = CreateDialogParam(0, "CLASS_TEST_DIALOG_2", 0, NULL, 0);
10729 ok(IsWindow(hdlg), "CreateDialogParam failed\n");
10730 ok_sequence(WmCreateDialogParamSeq_2, "CreateDialogParam_2", FALSE);
10731 EndDialog(hdlg, 0);
10732 DestroyWindow(hdlg);
10733 flush_sequence();
10734
10735 UnregisterClass(cls.lpszClassName, cls.hInstance);
10736 }
10737
10738 static void test_nullCallback(void)
10739 {
10740 HWND hwnd;
10741
10742 hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW,
10743 100, 100, 200, 200, 0, 0, 0, NULL);
10744 ok (hwnd != 0, "Failed to create overlapped window\n");
10745
10746 SendMessageCallbackA(hwnd,WM_NULL,0,0,NULL,0);
10747 flush_events();
10748 DestroyWindow(hwnd);
10749 }
10750
10751 /* SetActiveWindow( 0 ) hwnd visible */
10752 static const struct message SetActiveWindowSeq0[] =
10753 {
10754 { HCBT_ACTIVATE, hook|optional },
10755 { WM_NCACTIVATE, sent|wparam, 0 },
10756 { WM_GETTEXT, sent|defwinproc|optional },
10757 { WM_ACTIVATE, sent|wparam, 0 },
10758 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
10759 { WM_ACTIVATEAPP, sent|wparam|optional, 0 },
10760 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10761 { WM_KILLFOCUS, sent|optional },
10762 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10763 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10764 { WM_NCACTIVATE, sent|wparam|optional, 1 },
10765 { WM_GETTEXT, sent|defwinproc|optional },
10766 { WM_ACTIVATE, sent|wparam|optional, 1 },
10767 { HCBT_SETFOCUS, hook|optional },
10768 { WM_KILLFOCUS, sent|defwinproc|optional },
10769 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
10770 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
10771 { WM_IME_SETCONTEXT, sent|optional },
10772 { WM_IME_SETCONTEXT, sent|optional },
10773 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10774 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10775 { WM_SETFOCUS, sent|defwinproc|optional },
10776 { WM_GETTEXT, sent|optional },
10777 { 0 }
10778 };
10779 /* SetActiveWindow( hwnd ) hwnd visible */
10780 static const struct message SetActiveWindowSeq1[] =
10781 {
10782 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10783 { 0 }
10784 };
10785 /* SetActiveWindow( popup ) hwnd visible, popup visible */
10786 static const struct message SetActiveWindowSeq2[] =
10787 {
10788 { HCBT_ACTIVATE, hook },
10789 { WM_NCACTIVATE, sent|wparam, 0 },
10790 { WM_GETTEXT, sent|defwinproc|optional },
10791 { WM_ACTIVATE, sent|wparam, 0 },
10792 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10793 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE },
10794 { WM_WINDOWPOSCHANGING, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10795 { WM_NCPAINT, sent|optional },
10796 { WM_GETTEXT, sent|defwinproc|optional },
10797 { WM_ERASEBKGND, sent|optional },
10798 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10799 { WM_NCACTIVATE, sent|wparam, 1 },
10800 { WM_GETTEXT, sent|defwinproc|optional },
10801 { WM_ACTIVATE, sent|wparam, 1 },
10802 { HCBT_SETFOCUS, hook },
10803 { WM_KILLFOCUS, sent|defwinproc },
10804 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10805 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10806 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10807 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10808 { WM_SETFOCUS, sent|defwinproc },
10809 { WM_GETTEXT, sent|optional },
10810 { 0 }
10811 };
10812
10813 /* SetActiveWindow( hwnd ) hwnd not visible */
10814 static const struct message SetActiveWindowSeq3[] =
10815 {
10816 { HCBT_ACTIVATE, hook },
10817 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10818 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10819 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10820 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10821 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10822 { WM_ACTIVATEAPP, sent|wparam, 1 },
10823 { WM_ACTIVATEAPP, sent|wparam, 1 },
10824 { WM_NCACTIVATE, sent|wparam, 1 },
10825 { WM_ACTIVATE, sent|wparam, 1 },
10826 { HCBT_SETFOCUS, hook },
10827 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10828 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10829 { WM_SETFOCUS, sent|defwinproc },
10830 { 0 }
10831 };
10832 /* SetActiveWindow( popup ) hwnd not visible, popup not visible */
10833 static const struct message SetActiveWindowSeq4[] =
10834 {
10835 { HCBT_ACTIVATE, hook },
10836 { WM_NCACTIVATE, sent|wparam, 0 },
10837 { WM_GETTEXT, sent|defwinproc|optional },
10838 { WM_ACTIVATE, sent|wparam, 0 },
10839 { WM_QUERYNEWPALETTE, sent|wparam|lparam|optional, 0, 0 },
10840 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE },
10841 { WM_WINDOWPOSCHANGING, sent|wparam, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE },
10842 { WM_WINDOWPOSCHANGED, sent|wparam|optional, SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE },
10843 { WM_NCACTIVATE, sent|wparam, 1 },
10844 { WM_GETTEXT, sent|defwinproc|optional },
10845 { WM_ACTIVATE, sent|wparam, 1 },
10846 { HCBT_SETFOCUS, hook },
10847 { WM_KILLFOCUS, sent|defwinproc },
10848 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 0 },
10849 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
10850 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 1 },
10851 { WM_IME_NOTIFY, sent|wparam|defwinproc|optional, 2 },
10852 { WM_SETFOCUS, sent|defwinproc },
10853 { 0 }
10854 };
10855
10856
10857 static void test_SetActiveWindow(void)
10858 {
10859 HWND hwnd, popup, ret;
10860
10861 hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10862 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10863 100, 100, 200, 200, 0, 0, 0, NULL);
10864
10865 popup = CreateWindowExA(0, "TestWindowClass", "Test SetActiveWindow",
10866 WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_POPUP,
10867 100, 100, 200, 200, hwnd, 0, 0, NULL);
10868
10869 ok(hwnd != 0, "Failed to create overlapped window\n");
10870 ok(popup != 0, "Failed to create popup window\n");
10871 SetForegroundWindow( popup );
10872 flush_sequence();
10873
10874 trace("SetActiveWindow(0)\n");
10875 ret = SetActiveWindow(0);
10876 ok( ret == popup, "Failed to SetActiveWindow(0)\n");
10877 ok_sequence(SetActiveWindowSeq0, "SetActiveWindow(0)", FALSE);
10878 flush_sequence();
10879
10880 trace("SetActiveWindow(hwnd), hwnd visible\n");
10881 ret = SetActiveWindow(hwnd);
10882 if (ret == hwnd) ok_sequence(SetActiveWindowSeq1, "SetActiveWindow(hwnd), hwnd visible", TRUE);
10883 flush_sequence();
10884
10885 trace("SetActiveWindow(popup), hwnd visible, popup visible\n");
10886 ret = SetActiveWindow(popup);
10887 ok( ret == hwnd, "Failed to SetActiveWindow(popup), popup visible\n");
10888 ok_sequence(SetActiveWindowSeq2, "SetActiveWindow(popup), hwnd visible, popup visible", FALSE);
10889 flush_sequence();
10890
10891 ShowWindow(hwnd, SW_HIDE);
10892 ShowWindow(popup, SW_HIDE);
10893 flush_sequence();
10894
10895 trace("SetActiveWindow(hwnd), hwnd not visible\n");
10896 ret = SetActiveWindow(hwnd);
10897 ok( ret == NULL, "SetActiveWindow(hwnd), hwnd not visible, previous is %p\n", ret );
10898 ok_sequence(SetActiveWindowSeq3, "SetActiveWindow(hwnd), hwnd not visible", TRUE);
10899 flush_sequence();
10900
10901 trace("SetActiveWindow(popup), hwnd not visible, popup not visible\n");
10902 ret = SetActiveWindow(popup);
10903 ok( ret == hwnd, "Failed to SetActiveWindow(popup)\n");
10904 ok_sequence(SetActiveWindowSeq4, "SetActiveWindow(popup), hwnd not visible, popup not visible", TRUE);
10905 flush_sequence();
10906
10907 trace("done\n");
10908
10909 DestroyWindow(hwnd);
10910 }
10911
10912 static const struct message SetForegroundWindowSeq[] =
10913 {
10914 { WM_NCACTIVATE, sent|wparam, 0 },
10915 { WM_GETTEXT, sent|defwinproc|optional },
10916 { WM_ACTIVATE, sent|wparam, 0 },
10917 { WM_ACTIVATEAPP, sent|wparam, 0 },
10918 { WM_KILLFOCUS, sent },
10919 { WM_IME_SETCONTEXT, sent|wparam|optional, 0 },
10920 { WM_IME_NOTIFY, sent|wparam|optional|defwinproc, 1 },
10921 { 0 }
10922 };
10923
10924 static void test_SetForegroundWindow(void)
10925 {
10926 HWND hwnd;
10927
10928 hwnd = CreateWindowExA(0, "TestWindowClass", "Test SetForegroundWindow",
10929 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10930 100, 100, 200, 200, 0, 0, 0, NULL);
10931 ok (hwnd != 0, "Failed to create overlapped window\n");
10932 SetForegroundWindow( hwnd );
10933 flush_sequence();
10934
10935 trace("SetForegroundWindow( 0 )\n");
10936 SetForegroundWindow( 0 );
10937 ok_sequence(WmEmptySeq, "SetForegroundWindow( 0 ) away from foreground top level window", FALSE);
10938 trace("SetForegroundWindow( GetDesktopWindow() )\n");
10939 SetForegroundWindow( GetDesktopWindow() );
10940 ok_sequence(SetForegroundWindowSeq, "SetForegroundWindow( desktop ) away from "
10941 "foreground top level window", FALSE);
10942 trace("done\n");
10943
10944 DestroyWindow(hwnd);
10945 }
10946
10947 static void test_dbcs_wm_char(void)
10948 {
10949 BYTE dbch[2];
10950 WCHAR wch, bad_wch;
10951 HWND hwnd, hwnd2;
10952 MSG msg;
10953 DWORD time;
10954 POINT pt;
10955 DWORD_PTR res;
10956 CPINFOEXA cpinfo;
10957 UINT i, j, k;
10958 struct message wmCharSeq[2];
10959
10960 if (!pGetCPInfoExA)
10961 {
10962 win_skip("GetCPInfoExA is not available\n");
10963 return;
10964 }
10965
10966 pGetCPInfoExA( CP_ACP, 0, &cpinfo );
10967 if (cpinfo.MaxCharSize != 2)
10968 {
10969 skip( "Skipping DBCS WM_CHAR test in SBCS codepage '%s'\n", cpinfo.CodePageName );
10970 return;
10971 }
10972
10973 dbch[0] = dbch[1] = 0;
10974 wch = 0;
10975 bad_wch = cpinfo.UnicodeDefaultChar;
10976 for (i = 0; !wch && i < MAX_LEADBYTES && cpinfo.LeadByte[i]; i += 2)
10977 for (j = cpinfo.LeadByte[i]; !wch && j <= cpinfo.LeadByte[i+1]; j++)
10978 for (k = 128; k <= 255; k++)
10979 {
10980 char str[2];
10981 WCHAR wstr[2];
10982 str[0] = j;
10983 str[1] = k;
10984 if (MultiByteToWideChar( CP_ACP, 0, str, 2, wstr, 2 ) == 1 &&
10985 WideCharToMultiByte( CP_ACP, 0, wstr, 1, str, 2, NULL, NULL ) == 2 &&
10986 (BYTE)str[0] == j && (BYTE)str[1] == k &&
10987 HIBYTE(wstr[0]) && HIBYTE(wstr[0]) != 0xff)
10988 {
10989 dbch[0] = j;
10990 dbch[1] = k;
10991 wch = wstr[0];
10992 break;
10993 }
10994 }
10995
10996 if (!wch)
10997 {
10998 skip( "Skipping DBCS WM_CHAR test, no appropriate char found\n" );
10999 return;
11000 }
11001 trace( "using dbcs char %02x,%02x wchar %04x bad wchar %04x codepage '%s'\n",
11002 dbch[0], dbch[1], wch, bad_wch, cpinfo.CodePageName );
11003
11004 hwnd = CreateWindowExW(0, testWindowClassW, NULL,
11005 WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11006 hwnd2 = CreateWindowExW(0, testWindowClassW, NULL,
11007 WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL);
11008 ok (hwnd != 0, "Failed to create overlapped window\n");
11009 ok (hwnd2 != 0, "Failed to create overlapped window\n");
11010 flush_sequence();
11011
11012 memset( wmCharSeq, 0, sizeof(wmCharSeq) );
11013 wmCharSeq[0].message = WM_CHAR;
11014 wmCharSeq[0].flags = sent|wparam;
11015 wmCharSeq[0].wParam = wch;
11016
11017 /* posted message */
11018 PostMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11019 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11020 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11021 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11022 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11023 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11024 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11025
11026 /* posted thread message */
11027 PostThreadMessageA( GetCurrentThreadId(), WM_CHAR, dbch[0], 0 );
11028 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11029 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11030 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11031 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11032 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11033 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11034
11035 /* sent message */
11036 flush_sequence();
11037 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11038 ok_sequence( WmEmptySeq, "no messages", FALSE );
11039 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11040 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11041 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11042
11043 /* sent message with timeout */
11044 flush_sequence();
11045 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11046 ok_sequence( WmEmptySeq, "no messages", FALSE );
11047 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11048 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11049 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11050
11051 /* sent message with timeout and callback */
11052 flush_sequence();
11053 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[0], 0, SMTO_NORMAL, 0, &res );
11054 ok_sequence( WmEmptySeq, "no messages", FALSE );
11055 SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11056 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11057 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11058
11059 /* sent message with callback */
11060 flush_sequence();
11061 SendNotifyMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11062 ok_sequence( WmEmptySeq, "no messages", FALSE );
11063 SendMessageCallbackA( hwnd, WM_CHAR, dbch[1], 0, NULL, 0 );
11064 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11065 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11066
11067 /* direct window proc call */
11068 flush_sequence();
11069 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11070 ok_sequence( WmEmptySeq, "no messages", FALSE );
11071 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11072 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11073
11074 /* dispatch message */
11075 msg.hwnd = hwnd;
11076 msg.message = WM_CHAR;
11077 msg.wParam = dbch[0];
11078 msg.lParam = 0;
11079 DispatchMessageA( &msg );
11080 ok_sequence( WmEmptySeq, "no messages", FALSE );
11081 msg.wParam = dbch[1];
11082 DispatchMessageA( &msg );
11083 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11084
11085 /* window handle is irrelevant */
11086 flush_sequence();
11087 SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11088 ok_sequence( WmEmptySeq, "no messages", FALSE );
11089 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11090 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11091 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11092
11093 /* interleaved post and send */
11094 flush_sequence();
11095 PostMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11096 SendMessageA( hwnd2, WM_CHAR, dbch[0], 0 );
11097 ok_sequence( WmEmptySeq, "no messages", FALSE );
11098 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11099 PostMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11100 ok_sequence( WmEmptySeq, "no messages", FALSE );
11101 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11102 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11103 ok( msg.wParam == wch, "bad wparam %lx/%x\n", msg.wParam, wch );
11104 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11105 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11106 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11107 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11108
11109 /* interleaved sent message and winproc */
11110 flush_sequence();
11111 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11112 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11113 ok_sequence( WmEmptySeq, "no messages", FALSE );
11114 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11115 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11116 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11117 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11118
11119 /* interleaved winproc and dispatch */
11120 msg.hwnd = hwnd;
11121 msg.message = WM_CHAR;
11122 msg.wParam = dbch[0];
11123 msg.lParam = 0;
11124 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[0], 0 );
11125 DispatchMessageA( &msg );
11126 ok_sequence( WmEmptySeq, "no messages", FALSE );
11127 msg.wParam = dbch[1];
11128 DispatchMessageA( &msg );
11129 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11130 CallWindowProcA( (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ), hwnd, WM_CHAR, dbch[1], 0 );
11131 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11132
11133 /* interleaved sends */
11134 flush_sequence();
11135 SendMessageA( hwnd, WM_CHAR, dbch[0], 0 );
11136 SendMessageCallbackA( hwnd, WM_CHAR, dbch[0], 0, NULL, 0 );
11137 ok_sequence( WmEmptySeq, "no messages", FALSE );
11138 SendMessageTimeoutA( hwnd, WM_CHAR, dbch[1], 0, SMTO_NORMAL, 0, &res );
11139 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11140 SendMessageA( hwnd, WM_CHAR, dbch[1], 0 );
11141 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11142
11143 /* dbcs WM_CHAR */
11144 flush_sequence();
11145 SendMessageA( hwnd2, WM_CHAR, (dbch[1] << 8) | dbch[0], 0 );
11146 ok_sequence( wmCharSeq, "Unicode WM_CHAR", FALSE );
11147 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11148
11149 /* other char messages are not magic */
11150 PostMessageA( hwnd, WM_SYSCHAR, dbch[0], 0 );
11151 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11152 ok( msg.message == WM_SYSCHAR, "unexpected message %x\n", msg.message );
11153 ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
11154 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11155 PostMessageA( hwnd, WM_DEADCHAR, dbch[0], 0 );
11156 ok( PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11157 ok( msg.message == WM_DEADCHAR, "unexpected message %x\n", msg.message );
11158 ok( msg.wParam == bad_wch, "bad wparam %lx/%x\n", msg.wParam, bad_wch );
11159 ok( !PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11160
11161 /* test retrieving messages */
11162
11163 PostMessageW( hwnd, WM_CHAR, wch, 0 );
11164 ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11165 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11166 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11167 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11168 ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11169 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11170 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11171 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11172 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11173
11174 /* message filters */
11175 PostMessageW( hwnd, WM_CHAR, wch, 0 );
11176 ok( PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "no message\n" );
11177 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11178 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11179 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11180 /* message id is filtered, hwnd is not */
11181 ok( !PeekMessageA( &msg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ), "no message\n" );
11182 ok( PeekMessageA( &msg, hwnd2, 0, 0, PM_REMOVE ), "no message\n" );
11183 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11184 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11185 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11186 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11187
11188 /* mixing GetMessage and PostMessage */
11189 PostMessageW( hwnd, WM_CHAR, wch, 0xbeef );
11190 ok( GetMessageA( &msg, hwnd, 0, 0 ), "no message\n" );
11191 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11192 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11193 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11194 ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
11195 time = msg.time;
11196 pt = msg.pt;
11197 ok( time - GetTickCount() <= 100, "bad time %x\n", msg.time );
11198 ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11199 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11200 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11201 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11202 ok( msg.lParam == 0xbeef, "bad lparam %lx\n", msg.lParam );
11203 ok( msg.time == time, "bad time %x/%x\n", msg.time, time );
11204 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 );
11205 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11206
11207 /* without PM_REMOVE */
11208 PostMessageW( hwnd, WM_CHAR, wch, 0 );
11209 ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
11210 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11211 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11212 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11213 ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11214 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11215 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11216 ok( msg.wParam == dbch[0], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11217 ok( PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ), "no message\n" );
11218 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11219 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11220 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11221 ok( PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ), "no message\n" );
11222 ok( msg.hwnd == hwnd, "unexpected hwnd %p\n", msg.hwnd );
11223 ok( msg.message == WM_CHAR, "unexpected message %x\n", msg.message );
11224 ok( msg.wParam == dbch[1], "bad wparam %lx/%x\n", msg.wParam, dbch[0] );
11225 ok( !PeekMessageA( &msg, hwnd, 0, 0, PM_REMOVE ), "got message %x\n", msg.message );
11226
11227 DestroyWindow(hwnd);
11228 }
11229
11230 #define ID_LISTBOX 0x000f
11231
11232 static const struct message wm_lb_setcursel_0[] =
11233 {
11234 { LB_SETCURSEL, sent|wparam|lparam, 0, 0 },
11235 { WM_CTLCOLORLISTBOX, sent|parent },
11236 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
11237 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11238 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11239 { 0 }
11240 };
11241 static const struct message wm_lb_setcursel_1[] =
11242 {
11243 { LB_SETCURSEL, sent|wparam|lparam, 1, 0 },
11244 { WM_CTLCOLORLISTBOX, sent|parent },
11245 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000020f2 },
11246 { WM_CTLCOLORLISTBOX, sent|parent },
11247 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000121f2 },
11248 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
11249 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
11250 { 0 }
11251 };
11252 static const struct message wm_lb_setcursel_2[] =
11253 {
11254 { LB_SETCURSEL, sent|wparam|lparam, 2, 0 },
11255 { WM_CTLCOLORLISTBOX, sent|parent },
11256 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000021f2 },
11257 { WM_CTLCOLORLISTBOX, sent|parent },
11258 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000122f2 },
11259 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11260 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11261 { 0 }
11262 };
11263 static const struct message wm_lb_click_0[] =
11264 {
11265 { WM_LBUTTONDOWN, sent|wparam|lparam, 0, MAKELPARAM(1,1) },
11266 { HCBT_SETFOCUS, hook },
11267 { WM_KILLFOCUS, sent|parent },
11268 { WM_IME_SETCONTEXT, sent|wparam|optional|parent, 0 },
11269 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
11270 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
11271 { WM_SETFOCUS, sent|defwinproc },
11272
11273 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001142f2 },
11274 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SETFOCUS) },
11275 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
11276 { WM_LBTRACKPOINT, sent|wparam|lparam|parent, 0, MAKELPARAM(1,1) },
11277 { EVENT_SYSTEM_CAPTURESTART, winevent_hook|wparam|lparam, 0, 0 },
11278
11279 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000142f2 },
11280 { WM_CTLCOLORLISTBOX, sent|parent },
11281 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000022f2 },
11282 { WM_CTLCOLORLISTBOX, sent|parent },
11283 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x000120f2 },
11284 { WM_DRAWITEM, sent|wparam|lparam|parent, ID_LISTBOX, 0x001140f2 },
11285
11286 { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11287 { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
11288
11289 { WM_LBUTTONUP, sent|wparam|lparam, 0, 0 },
11290 { EVENT_SYSTEM_CAPTUREEND, winevent_hook|wparam|lparam, 0, 0 },
11291 { WM_CAPTURECHANGED, sent|wparam|lparam|defwinproc, 0, 0 },
11292 { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_LISTBOX, LBN_SELCHANGE) },
11293 { 0 }
11294 };
11295 static const struct message wm_lb_deletestring[] =
11296 {
11297 { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
11298 { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
11299 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11300 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11301 { 0 }
11302 };
11303 static const struct message wm_lb_deletestring_reset[] =
11304 {
11305 { LB_DELETESTRING, sent|wparam|lparam, 0, 0 },
11306 { LB_RESETCONTENT, sent|wparam|lparam|defwinproc|optional, 0, 0 },
11307 { WM_DELETEITEM, sent|wparam|parent|optional, ID_LISTBOX, 0 },
11308 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11309 { WM_DRAWITEM, sent|wparam|parent|optional, ID_LISTBOX },
11310 { 0 }
11311 };
11312
11313 #define check_lb_state(a1, a2, a3, a4, a5) check_lb_state_dbg(a1, a2, a3, a4, a5, __LINE__)
11314
11315 static LRESULT (WINAPI *listbox_orig_proc)(HWND, UINT, WPARAM, LPARAM);
11316
11317 static LRESULT WINAPI listbox_hook_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11318 {
11319 static LONG defwndproc_counter = 0;
11320 LRESULT ret;
11321 struct recvd_message msg;
11322
11323 /* do not log painting messages */
11324 if (message != WM_PAINT &&
11325 message != WM_NCPAINT &&
11326 message != WM_SYNCPAINT &&
11327 message != WM_ERASEBKGND &&
11328 message != WM_NCHITTEST &&
11329 message != WM_GETTEXT &&
11330 !ignore_message( message ))
11331 {
11332 msg.hwnd = hwnd;
11333 msg.message = message;
11334 msg.flags = sent|wparam|lparam;
11335 if (defwndproc_counter) msg.flags |= defwinproc;
11336 msg.wParam = wp;
11337 msg.lParam = lp;
11338 msg.descr = "listbox";
11339 add_message(&msg);
11340 }
11341
11342 defwndproc_counter++;
11343 ret = CallWindowProcA(listbox_orig_proc, hwnd, message, wp, lp);
11344 defwndproc_counter--;
11345
11346 return ret;
11347 }
11348
11349 static void check_lb_state_dbg(HWND listbox, int count, int cur_sel,
11350 int caret_index, int top_index, int line)
11351 {
11352 LRESULT ret;
11353
11354 /* calling an orig proc helps to avoid unnecessary message logging */
11355 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCOUNT, 0, 0);
11356 ok_(__FILE__, line)(ret == count, "expected count %d, got %ld\n", count, ret);
11357 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCURSEL, 0, 0);
11358 ok_(__FILE__, line)(ret == cur_sel, "expected cur sel %d, got %ld\n", cur_sel, ret);
11359 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETCARETINDEX, 0, 0);
11360 ok_(__FILE__, line)(ret == caret_index ||
11361 broken(cur_sel == -1 && caret_index == 0 && ret == -1), /* nt4 */
11362 "expected caret index %d, got %ld\n", caret_index, ret);
11363 ret = CallWindowProcA(listbox_orig_proc, listbox, LB_GETTOPINDEX, 0, 0);
11364 ok_(__FILE__, line)(ret == top_index, "expected top index %d, got %ld\n", top_index, ret);
11365 }
11366
11367 static void test_listbox_messages(void)
11368 {
11369 HWND parent, listbox;
11370 LRESULT ret;
11371
11372 parent = CreateWindowExA(0, "TestParentClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11373 100, 100, 200, 200, 0, 0, 0, NULL);
11374 listbox = CreateWindowExA(WS_EX_NOPARENTNOTIFY, "ListBox", NULL,
11375 WS_CHILD | LBS_NOTIFY | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS | WS_VISIBLE,
11376 10, 10, 80, 80, parent, (HMENU)ID_LISTBOX, 0, NULL);
11377 listbox_orig_proc = (WNDPROC)SetWindowLongPtrA(listbox, GWLP_WNDPROC, (ULONG_PTR)listbox_hook_proc);
11378
11379 check_lb_state(listbox, 0, LB_ERR, 0, 0);
11380
11381 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 0");
11382 ok(ret == 0, "expected 0, got %ld\n", ret);
11383 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 1");
11384 ok(ret == 1, "expected 1, got %ld\n", ret);
11385 ret = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
11386 ok(ret == 2, "expected 2, got %ld\n", ret);
11387
11388 check_lb_state(listbox, 3, LB_ERR, 0, 0);
11389
11390 flush_sequence();
11391
11392 log_all_parent_messages++;
11393
11394 trace("selecting item 0\n");
11395 ret = SendMessage(listbox, LB_SETCURSEL, 0, 0);
11396 ok(ret == 0, "expected 0, got %ld\n", ret);
11397 ok_sequence(wm_lb_setcursel_0, "LB_SETCURSEL 0", FALSE );
11398 check_lb_state(listbox, 3, 0, 0, 0);
11399 flush_sequence();
11400
11401 trace("selecting item 1\n");
11402 ret = SendMessage(listbox, LB_SETCURSEL, 1, 0);
11403 ok(ret == 1, "expected 1, got %ld\n", ret);
11404 ok_sequence(wm_lb_setcursel_1, "LB_SETCURSEL 1", FALSE );
11405 check_lb_state(listbox, 3, 1, 1, 0);
11406
11407 trace("selecting item 2\n");
11408 ret = SendMessage(listbox, LB_SETCURSEL, 2, 0);
11409 ok(ret == 2, "expected 2, got %ld\n", ret);
11410 ok_sequence(wm_lb_setcursel_2, "LB_SETCURSEL 2", FALSE );
11411 check_lb_state(listbox, 3, 2, 2, 0);
11412
11413 trace("clicking on item 0\n");
11414 ret = SendMessage(listbox, WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1));
11415 ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11416 ret = SendMessage(listbox, WM_LBUTTONUP, 0, 0);
11417 ok(ret == LB_OKAY, "expected LB_OKAY, got %ld\n", ret);
11418 ok_sequence(wm_lb_click_0, "WM_LBUTTONDOWN 0", FALSE );
11419 check_lb_state(listbox, 3, 0, 0, 0);
11420 flush_sequence();
11421
11422 trace("deleting item 0\n");
11423 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11424 ok(ret == 2, "expected 2, got %ld\n", ret);
11425 ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
11426 check_lb_state(listbox, 2, -1, 0, 0);
11427 flush_sequence();
11428
11429 trace("deleting item 0\n");
11430 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11431 ok(ret == 1, "expected 1, got %ld\n", ret);
11432 ok_sequence(wm_lb_deletestring, "LB_DELETESTRING 0", FALSE );
11433 check_lb_state(listbox, 1, -1, 0, 0);
11434 flush_sequence();
11435
11436 trace("deleting item 0\n");
11437 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11438 ok(ret == 0, "expected 0, got %ld\n", ret);
11439 ok_sequence(wm_lb_deletestring_reset, "LB_DELETESTRING 0", FALSE );
11440 check_lb_state(listbox, 0, -1, 0, 0);
11441 flush_sequence();
11442
11443 trace("deleting item 0\n");
11444 ret = SendMessage(listbox, LB_DELETESTRING, 0, 0);
11445 ok(ret == LB_ERR, "expected LB_ERR, got %ld\n", ret);
11446 check_lb_state(listbox, 0, -1, 0, 0);
11447 flush_sequence();
11448
11449 log_all_parent_messages--;
11450
11451 DestroyWindow(listbox);
11452 DestroyWindow(parent);
11453 }
11454
11455 /*************************** Menu test ******************************/
11456 static const struct message wm_popup_menu_1[] =
11457 {
11458 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11459 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11460 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0x20000001 },
11461 { WM_SYSKEYDOWN, sent|wparam|lparam, 'E', 0x20000001 },
11462 { WM_SYSCHAR, sent|wparam|lparam, 'e', 0x20000001 },
11463 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'e' },
11464 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11465 { WM_INITMENU, sent|lparam, 0, 0 },
11466 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(1,MF_HILITE|MF_POPUP) },
11467 { WM_INITMENUPOPUP, sent|lparam, 0, 1 },
11468 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't create a window */
11469 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(200,MF_HILITE) },
11470 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'E', 0xf0000001 },
11471 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11472 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11473 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't create a window */
11474 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11475 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11476 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11477 { WM_MENUCOMMAND, sent }, /* |wparam, 200 - Win9x */
11478 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11479 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11480 { 0 }
11481 };
11482 static const struct message wm_popup_menu_2[] =
11483 {
11484 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11485 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11486 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11487 { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11488 { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11489 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11490 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11491 { WM_INITMENU, sent|lparam, 0, 0 },
11492 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11493 { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11494 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11495 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11496 { HCBT_CREATEWND, hook },
11497 { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11498 |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11499 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11500 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11501 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11502 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11503 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11504 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11505 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11506 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11507 { HCBT_DESTROYWND, hook },
11508 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11509 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11510 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11511 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11512 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11513 { WM_MENUCOMMAND, sent }, /* |wparam, 100 - Win9x */
11514 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11515 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11516 { 0 }
11517 };
11518 static const struct message wm_popup_menu_3[] =
11519 {
11520 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0x20000001 },
11521 { WM_SYSKEYDOWN, sent|wparam|lparam, VK_MENU, 0x20000001 },
11522 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0x20000001 },
11523 { WM_SYSKEYDOWN, sent|wparam|lparam, 'F', 0x20000001 },
11524 { WM_SYSCHAR, sent|wparam|lparam, 'f', 0x20000001 },
11525 { HCBT_SYSCOMMAND, hook|wparam|lparam, SC_KEYMENU, 'f' },
11526 { WM_ENTERMENULOOP, sent|wparam|lparam, 0, 0 },
11527 { WM_INITMENU, sent|lparam, 0, 0 },
11528 { WM_MENUSELECT, sent|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) },
11529 { WM_INITMENUPOPUP, sent|lparam, 0, 0 },
11530 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(0,MF_HILITE|MF_POPUP) }, /* Win9x */
11531 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x */
11532 { HCBT_CREATEWND, hook },
11533 { WM_MENUSELECT, sent }, /*|wparam, MAKEWPARAM(0,MF_HILITE|MF_POPUP) - XP
11534 |wparam, MAKEWPARAM(100,MF_HILITE) - Win9x */
11535 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, 'F', 0xf0000001 },
11536 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_MENU, 0xd0000001 },
11537 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0x10000001 },
11538 { WM_INITMENUPOPUP, sent|lparam|optional, 0, 0 }, /* Win9x doesn't send it */
11539 { HCBT_CREATEWND, hook|optional }, /* Win9x doesn't send it */
11540 { WM_MENUSELECT, sent|wparam|optional, MAKEWPARAM(100,MF_HILITE) },
11541 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RIGHT, 0xd0000001 },
11542 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0x10000001 },
11543 { HCBT_DESTROYWND, hook },
11544 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11545 { HCBT_DESTROYWND, hook|optional }, /* Win9x doesn't send it */
11546 { WM_UNINITMENUPOPUP, sent|lparam, 0, 0 },
11547 { WM_MENUSELECT, sent|wparam|lparam, MAKEWPARAM(0,0xffff), 0 },
11548 { WM_EXITMENULOOP, sent|wparam|lparam, 0, 0 },
11549 { WM_COMMAND, sent|wparam|lparam, 100, 0 },
11550 { HCBT_KEYSKIPPED, hook|wparam|lparam|optional, VK_RETURN, 0xc0000001 },
11551 { WM_KEYUP, sent|wparam|lparam, VK_RETURN, 0xc0000001 },
11552 { 0 }
11553 };
11554
11555 static LRESULT WINAPI parent_menu_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp)
11556 {
11557 if (message == WM_ENTERIDLE ||
11558 message == WM_INITMENU ||
11559 message == WM_INITMENUPOPUP ||
11560 message == WM_MENUSELECT ||
11561 message == WM_PARENTNOTIFY ||
11562 message == WM_ENTERMENULOOP ||
11563 message == WM_EXITMENULOOP ||
11564 message == WM_UNINITMENUPOPUP ||
11565 message == WM_KEYDOWN ||
11566 message == WM_KEYUP ||
11567 message == WM_CHAR ||
11568 message == WM_SYSKEYDOWN ||
11569 message == WM_SYSKEYUP ||
11570 message == WM_SYSCHAR ||
11571 message == WM_COMMAND ||
11572 message == WM_MENUCOMMAND)
11573 {
11574 struct recvd_message msg;
11575
11576 msg.hwnd = hwnd;
11577 msg.message = message;
11578 msg.flags = sent|wparam|lparam;
11579 msg.wParam = wp;
11580 msg.lParam = lp;
11581 msg.descr = "parent_menu_proc";
11582 add_message(&msg);
11583 }
11584
11585 return DefWindowProcA(hwnd, message, wp, lp);
11586 }
11587
11588 static void set_menu_style(HMENU hmenu, DWORD style)
11589 {
11590 MENUINFO mi;
11591 BOOL ret;
11592
11593 mi.cbSize = sizeof(mi);
11594 mi.fMask = MIM_STYLE;
11595 mi.dwStyle = style;
11596 SetLastError(0xdeadbeef);
11597 ret = pSetMenuInfo(hmenu, &mi);
11598 ok(ret, "SetMenuInfo error %u\n", GetLastError());
11599 }
11600
11601 static DWORD get_menu_style(HMENU hmenu)
11602 {
11603 MENUINFO mi;
11604 BOOL ret;
11605
11606 mi.cbSize = sizeof(mi);
11607 mi.fMask = MIM_STYLE;
11608 mi.dwStyle = 0;
11609 SetLastError(0xdeadbeef);
11610 ret = pGetMenuInfo(hmenu, &mi);
11611 ok(ret, "GetMenuInfo error %u\n", GetLastError());
11612
11613 return mi.dwStyle;
11614 }
11615
11616 static void test_menu_messages(void)
11617 {
11618 MSG msg;
11619 WNDCLASSA cls;
11620 HMENU hmenu, hmenu_popup;
11621 HWND hwnd;
11622 DWORD style;
11623
11624 if (!pGetMenuInfo || !pSetMenuInfo)
11625 {
11626 win_skip("GetMenuInfo and/or SetMenuInfo are not available\n");
11627 return;
11628 }
11629 cls.style = 0;
11630 cls.lpfnWndProc = parent_menu_proc;
11631 cls.cbClsExtra = 0;
11632 cls.cbWndExtra = 0;
11633 cls.hInstance = GetModuleHandleA(0);
11634 cls.hIcon = 0;
11635 cls.hCursor = LoadCursorA(0, IDC_ARROW);
11636 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
11637 cls.lpszMenuName = NULL;
11638 cls.lpszClassName = "TestMenuClass";
11639 UnregisterClass(cls.lpszClassName, cls.hInstance);
11640 if (!RegisterClassA(&cls)) assert(0);
11641
11642 SetLastError(0xdeadbeef);
11643 hwnd = CreateWindowExA(0, "TestMenuClass", NULL, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11644 100, 100, 200, 200, 0, 0, 0, NULL);
11645 ok(hwnd != 0, "LoadMenuA error %u\n", GetLastError());
11646
11647 SetLastError(0xdeadbeef);
11648 hmenu = LoadMenuA(GetModuleHandle(0), MAKEINTRESOURCE(1));
11649 ok(hmenu != 0, "LoadMenuA error %u\n", GetLastError());
11650
11651 SetMenu(hwnd, hmenu);
11652 SetForegroundWindow( hwnd );
11653
11654 set_menu_style(hmenu, MNS_NOTIFYBYPOS);
11655 style = get_menu_style(hmenu);
11656 ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11657
11658 hmenu_popup = GetSubMenu(hmenu, 0);
11659 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11660 style = get_menu_style(hmenu_popup);
11661 ok(style == 0, "expected 0, got %u\n", style);
11662
11663 hmenu_popup = GetSubMenu(hmenu_popup, 0);
11664 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11665 style = get_menu_style(hmenu_popup);
11666 ok(style == 0, "expected 0, got %u\n", style);
11667
11668 /* Alt+E, Enter */
11669 trace("testing a popup menu command\n");
11670 flush_sequence();
11671 keybd_event(VK_MENU, 0, 0, 0);
11672 keybd_event('E', 0, 0, 0);
11673 keybd_event('E', 0, KEYEVENTF_KEYUP, 0);
11674 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11675 keybd_event(VK_RETURN, 0, 0, 0);
11676 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11677 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11678 {
11679 TranslateMessage(&msg);
11680 DispatchMessage(&msg);
11681 }
11682 if (!sequence_cnt) /* we didn't get any message */
11683 {
11684 skip( "queuing key events not supported\n" );
11685 goto done;
11686 }
11687 /* win98 queues only a WM_KEYUP and doesn't start menu tracking */
11688 if (sequence[0].message == WM_KEYUP && sequence[0].wParam == VK_MENU)
11689 {
11690 win_skip( "menu tracking through VK_MENU not supported\n" );
11691 goto done;
11692 }
11693 ok_sequence(wm_popup_menu_1, "popup menu command", FALSE);
11694
11695 /* Alt+F, Right, Enter */
11696 trace("testing submenu of a popup menu command\n");
11697 flush_sequence();
11698 keybd_event(VK_MENU, 0, 0, 0);
11699 keybd_event('F', 0, 0, 0);
11700 keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11701 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11702 keybd_event(VK_RIGHT, 0, 0, 0);
11703 keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11704 keybd_event(VK_RETURN, 0, 0, 0);
11705 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11706 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11707 {
11708 TranslateMessage(&msg);
11709 DispatchMessage(&msg);
11710 }
11711 ok_sequence(wm_popup_menu_2, "submenu of a popup menu command", FALSE);
11712
11713 set_menu_style(hmenu, 0);
11714 style = get_menu_style(hmenu);
11715 ok(style == 0, "expected 0, got %u\n", style);
11716
11717 hmenu_popup = GetSubMenu(hmenu, 0);
11718 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11719 set_menu_style(hmenu_popup, MNS_NOTIFYBYPOS);
11720 style = get_menu_style(hmenu_popup);
11721 ok(style == MNS_NOTIFYBYPOS, "expected MNS_NOTIFYBYPOS, got %u\n", style);
11722
11723 hmenu_popup = GetSubMenu(hmenu_popup, 0);
11724 ok(hmenu_popup != 0, "GetSubMenu returned 0 for submenu 0\n");
11725 style = get_menu_style(hmenu_popup);
11726 ok(style == 0, "expected 0, got %u\n", style);
11727
11728 /* Alt+F, Right, Enter */
11729 trace("testing submenu of a popup menu command\n");
11730 flush_sequence();
11731 keybd_event(VK_MENU, 0, 0, 0);
11732 keybd_event('F', 0, 0, 0);
11733 keybd_event('F', 0, KEYEVENTF_KEYUP, 0);
11734 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
11735 keybd_event(VK_RIGHT, 0, 0, 0);
11736 keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
11737 keybd_event(VK_RETURN, 0, 0, 0);
11738 keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
11739 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
11740 {
11741 TranslateMessage(&msg);
11742 DispatchMessage(&msg);
11743 }
11744 ok_sequence(wm_popup_menu_3, "submenu of a popup menu command", FALSE);
11745
11746 done:
11747 DestroyWindow(hwnd);
11748 DestroyMenu(hmenu);
11749 }
11750
11751
11752 static void test_paintingloop(void)
11753 {
11754 HWND hwnd;
11755
11756 paint_loop_done = 0;
11757 hwnd = CreateWindowExA(0x0,"PaintLoopWindowClass",
11758 "PaintLoopWindowClass",WS_OVERLAPPEDWINDOW,
11759 100, 100, 100, 100, 0, 0, 0, NULL );
11760 ok(hwnd != 0, "PaintLoop window error %u\n", GetLastError());
11761 ShowWindow(hwnd,SW_NORMAL);
11762 SetFocus(hwnd);
11763
11764 while (!paint_loop_done)
11765 {
11766 MSG msg;
11767 if (PeekMessageA(&msg, 0, 0, 0, 1))
11768 {
11769 TranslateMessage(&msg);
11770 DispatchMessage(&msg);
11771 }
11772 }
11773 DestroyWindow(hwnd);
11774 }
11775
11776 static void test_defwinproc(void)
11777 {
11778 HWND hwnd;
11779 MSG msg;
11780 int gotwmquit = FALSE;
11781 hwnd = CreateWindowExA(0, "static", "test_defwndproc", WS_POPUP, 0,0,0,0,0,0,0, NULL);
11782 assert(hwnd);
11783 DefWindowProcA( hwnd, WM_ENDSESSION, 1, 0);
11784 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) {
11785 if( msg.message == WM_QUIT) gotwmquit = TRUE;
11786 DispatchMessageA( &msg );
11787 }
11788 ok( gotwmquit == FALSE, "Unexpected WM_QUIT message!\n");
11789 DestroyWindow( hwnd);
11790 }
11791
11792 #define clear_clipboard(hwnd) clear_clipboard_(__LINE__, (hwnd))
11793 static void clear_clipboard_(int line, HWND hWnd)
11794 {
11795 BOOL succ;
11796 succ = OpenClipboard(hWnd);
11797 ok_(__FILE__, line)(succ, "OpenClipboard failed, err=%u\n", GetLastError());
11798 succ = EmptyClipboard();
11799 ok_(__FILE__, line)(succ, "EmptyClipboard failed, err=%u\n", GetLastError());
11800 succ = CloseClipboard();
11801 ok_(__FILE__, line)(succ, "CloseClipboard failed, err=%u\n", GetLastError());
11802 }
11803
11804 #define expect_HWND(expected, got) expect_HWND_(__LINE__, (expected), (got))
11805 static void expect_HWND_(int line, HWND expected, HWND got)
11806 {
11807 ok_(__FILE__, line)(got==expected, "Expected %p, got %p\n", expected, got);
11808 }
11809
11810 static WNDPROC pOldViewerProc;
11811
11812 static LRESULT CALLBACK recursive_viewer_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
11813 {
11814 static BOOL recursion_guard;
11815
11816 if (message == WM_DRAWCLIPBOARD && !recursion_guard)
11817 {
11818 recursion_guard = TRUE;
11819 clear_clipboard(hWnd);
11820 recursion_guard = FALSE;
11821 }
11822 return CallWindowProcA(pOldViewerProc, hWnd, message, wParam, lParam);
11823 }
11824
11825 static void test_clipboard_viewers(void)
11826 {
11827 static struct message wm_change_cb_chain[] =
11828 {
11829 { WM_CHANGECBCHAIN, sent|wparam|lparam, 0, 0 },
11830 { 0 }
11831 };
11832 static const struct message wm_clipboard_destroyed[] =
11833 {
11834 { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
11835 { 0 }
11836 };
11837 static struct message wm_clipboard_changed[] =
11838 {
11839 { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
11840 { 0 }
11841 };
11842 static struct message wm_clipboard_changed_and_owned[] =
11843 {
11844 { WM_DESTROYCLIPBOARD, sent|wparam|lparam, 0, 0 },
11845 { WM_DRAWCLIPBOARD, sent|wparam|lparam, 0, 0 },
11846 { 0 }
11847 };
11848
11849 HINSTANCE hInst = GetModuleHandleA(NULL);
11850 HWND hWnd1, hWnd2, hWnd3;
11851 HWND hOrigViewer;
11852 HWND hRet;
11853
11854 hWnd1 = CreateWindowExA(0, "TestWindowClass", "Clipboard viewer test wnd 1",
11855 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
11856 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
11857 GetDesktopWindow(), NULL, hInst, NULL);
11858 hWnd2 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 2",
11859 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
11860 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
11861 GetDesktopWindow(), NULL, hInst, NULL);
11862 hWnd3 = CreateWindowExA(0, "SimpleWindowClass", "Clipboard viewer test wnd 3",
11863 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
11864 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
11865 GetDesktopWindow(), NULL, hInst, NULL);
11866 trace("clipbd viewers: hWnd1=%p, hWnd2=%p, hWnd3=%p\n", hWnd1, hWnd2, hWnd3);
11867 assert(hWnd1 && hWnd2 && hWnd3);
11868
11869 flush_sequence();
11870
11871 /* Test getting the clipboard viewer and setting the viewer to NULL. */
11872 hOrigViewer = GetClipboardViewer();
11873 hRet = SetClipboardViewer(NULL);
11874 ok_sequence(WmEmptySeq, "set viewer to NULL", FALSE);
11875 expect_HWND(hOrigViewer, hRet);
11876 expect_HWND(NULL, GetClipboardViewer());
11877
11878 /* Test registering hWnd1 as a viewer. */
11879 hRet = SetClipboardViewer(hWnd1);
11880 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
11881 ok_sequence(wm_clipboard_changed, "set viewer NULL->1", FALSE);
11882 expect_HWND(NULL, hRet);
11883 expect_HWND(hWnd1, GetClipboardViewer());
11884
11885 /* Test that changing the clipboard actually refreshes the registered viewer. */
11886 clear_clipboard(hWnd1);
11887 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
11888 ok_sequence(wm_clipboard_changed, "clear clipbd (viewer=owner=1)", FALSE);
11889
11890 /* Again, but with different owner. */
11891 clear_clipboard(hWnd2);
11892 wm_clipboard_changed_and_owned[1].wParam = (WPARAM) GetClipboardOwner();
11893 ok_sequence(wm_clipboard_changed_and_owned, "clear clipbd (viewer=1, owner=2)", FALSE);
11894
11895 /* Test re-registering same window. */
11896 hRet = SetClipboardViewer(hWnd1);
11897 wm_clipboard_changed[0].wParam = (WPARAM) GetClipboardOwner();
11898 ok_sequence(wm_clipboard_changed, "set viewer 1->1", FALSE);
11899 expect_HWND(hWnd1, hRet);
11900 expect_HWND(hWnd1, GetClipboardViewer());
11901
11902 /* Test ChangeClipboardChain. */
11903 ChangeClipboardChain(hWnd2, hWnd3);
11904 wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
11905 wm_change_cb_chain[0].lParam = (LPARAM) hWnd3;
11906 ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=3)", FALSE);
11907 expect_HWND(hWnd1, GetClipboardViewer());
11908
11909 ChangeClipboardChain(hWnd2, NULL);
11910 wm_change_cb_chain[0].wParam = (WPARAM) hWnd2;
11911 wm_change_cb_chain[0].lParam = 0;
11912 ok_sequence(wm_change_cb_chain, "change chain (viewer=1, remove=2, next=NULL)", FALSE);
11913 expect_HWND(hWnd1, GetClipboardViewer());
11914
11915 ChangeClipboardChain(NULL, hWnd2);
11916 ok_sequence(WmEmptySeq, "change chain (viewer=1, remove=NULL, next=2)", TRUE);
11917 expect_HWND(hWnd1, GetClipboardViewer());
11918
11919 /* Actually change clipboard viewer with ChangeClipboardChain. */
11920 ChangeClipboardChain(hWnd1, hWnd2);
11921 ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=2)", FALSE);
11922 expect_HWND(hWnd2, GetClipboardViewer());
11923
11924 /* Test that no refresh messages are sent when viewer has unregistered. */
11925 clear_clipboard(hWnd2);
11926 ok_sequence(WmEmptySeq, "clear clipd (viewer=2, owner=1)", FALSE);
11927
11928 /* Register hWnd1 again. */
11929 ChangeClipboardChain(hWnd2, hWnd1);
11930 ok_sequence(WmEmptySeq, "change chain (viewer=remove=2, next=1)", FALSE);
11931 expect_HWND(hWnd1, GetClipboardViewer());
11932
11933 /* Subclass hWnd1 so that when it receives a WM_DRAWCLIPBOARD message, it
11934 * changes the clipboard. When this happens, the system shouldn't send
11935 * another WM_DRAWCLIPBOARD (as this could cause an infinite loop).
11936 */
11937 pOldViewerProc = (WNDPROC) SetWindowLongPtrA(hWnd1, GWLP_WNDPROC, (LONG_PTR) recursive_viewer_proc);
11938 clear_clipboard(hWnd2);
11939 /* The clipboard owner is changed in recursive_viewer_proc: */
11940 wm_clipboard_changed[0].wParam = (WPARAM) hWnd2;
11941 ok_sequence(wm_clipboard_changed, "recursive clear clipbd (viewer=1, owner=2)", TRUE);
11942
11943 /* Test unregistering. */
11944 ChangeClipboardChain(hWnd1, NULL);
11945 ok_sequence(WmEmptySeq, "change chain (viewer=remove=1, next=NULL)", FALSE);
11946 expect_HWND(NULL, GetClipboardViewer());
11947
11948 clear_clipboard(hWnd1);
11949 ok_sequence(wm_clipboard_destroyed, "clear clipbd (no viewer, owner=1)", FALSE);
11950
11951 DestroyWindow(hWnd1);
11952 DestroyWindow(hWnd2);
11953 DestroyWindow(hWnd3);
11954 SetClipboardViewer(hOrigViewer);
11955 }
11956
11957 static void test_PostMessage(void)
11958 {
11959 static const struct
11960 {
11961 HWND hwnd;
11962 BOOL ret;
11963 } data[] =
11964 {
11965 { HWND_TOP /* 0 */, TRUE },
11966 { HWND_BROADCAST, TRUE },
11967 { HWND_BOTTOM, TRUE },
11968 { HWND_TOPMOST, TRUE },
11969 { HWND_NOTOPMOST, FALSE },
11970 { HWND_MESSAGE, FALSE },
11971 { (HWND)0xdeadbeef, FALSE }
11972 };
11973 int i;
11974 HWND hwnd;
11975 BOOL ret;
11976 MSG msg;
11977 static const WCHAR staticW[] = {'s','t','a','t','i','c',0};
11978
11979 SetLastError(0xdeadbeef);
11980 hwnd = CreateWindowExW(0, staticW, NULL, WS_POPUP, 0,0,0,0,0,0,0, NULL);
11981 if (!hwnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
11982 {
11983 win_skip("Skipping some PostMessage tests on Win9x/WinMe\n");
11984 return;
11985 }
11986 assert(hwnd);
11987
11988 flush_events();
11989
11990 PostMessage(hwnd, WM_USER+1, 0x1234, 0x5678);
11991 PostMessage(0, WM_USER+2, 0x5678, 0x1234);
11992
11993 for (i = 0; i < sizeof(data)/sizeof(data[0]); i++)
11994 {
11995 memset(&msg, 0xab, sizeof(msg));
11996 ret = PeekMessageA(&msg, data[i].hwnd, 0, 0, PM_NOREMOVE);
11997 ok(ret == data[i].ret, "%d: hwnd %p expected %d, got %d\n", i, data[i].hwnd, data[i].ret, ret);
11998 if (data[i].ret)
11999 {
12000 if (data[i].hwnd)
12001 ok(ret && msg.hwnd == 0 && msg.message == WM_USER+2 &&
12002 msg.wParam == 0x5678 && msg.lParam == 0x1234,
12003 "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/0/WM_USER+2/0x5678/0x1234\n",
12004 i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam);
12005 else
12006 ok(ret && msg.hwnd == hwnd && msg.message == WM_USER+1 &&
12007 msg.wParam == 0x1234 && msg.lParam == 0x5678,
12008 "%d: got ret %d hwnd %p msg %04x wParam %08lx lParam %08lx instead of TRUE/%p/WM_USER+1/0x1234/0x5678\n",
12009 i, ret, msg.hwnd, msg.message, msg.wParam, msg.lParam, msg.hwnd);
12010 }
12011 }
12012
12013 DestroyWindow(hwnd);
12014 flush_events();
12015 }
12016
12017 START_TEST(msg)
12018 {
12019 BOOL ret;
12020 BOOL (WINAPI *pIsWinEventHookInstalled)(DWORD)= 0;/*GetProcAddress(user32, "IsWinEventHookInstalled");*/
12021
12022 init_procs();
12023
12024 if (!RegisterWindowClasses()) assert(0);
12025
12026 if (pSetWinEventHook)
12027 {
12028 hEvent_hook = pSetWinEventHook(EVENT_MIN, EVENT_MAX,
12029 GetModuleHandleA(0), win_event_proc,
12030 0, GetCurrentThreadId(),
12031 WINEVENT_INCONTEXT);
12032 if (pIsWinEventHookInstalled && hEvent_hook)
12033 {
12034 UINT event;
12035 for (event = EVENT_MIN; event <= EVENT_MAX; event++)
12036 ok(pIsWinEventHookInstalled(event), "IsWinEventHookInstalled(%u) failed\n", event);
12037 }
12038 }
12039 if (!hEvent_hook) win_skip( "no win event hook support\n" );
12040
12041 cbt_hook_thread_id = GetCurrentThreadId();
12042 hCBT_hook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
12043 if (!hCBT_hook) win_skip( "cannot set global hook, will skip hook tests\n" );
12044
12045 test_winevents();
12046
12047 /* Fix message sequences before removing 4 lines below */
12048 #if 1
12049 if (pUnhookWinEvent && hEvent_hook)
12050 {
12051 ret = pUnhookWinEvent(hEvent_hook);
12052 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
12053 pUnhookWinEvent = 0;
12054 }
12055 hEvent_hook = 0;
12056 #endif
12057
12058 test_PostMessage();
12059 test_ShowWindow();
12060 test_PeekMessage();
12061 test_PeekMessage2();
12062 test_scrollwindowex();
12063 test_messages();
12064 test_setwindowpos();
12065 test_showwindow();
12066 invisible_parent_tests();
12067 test_mdi_messages();
12068 test_button_messages();
12069 test_static_messages();
12070 test_listbox_messages();
12071 test_combobox_messages();
12072 test_wmime_keydown_message();
12073 test_paint_messages();
12074 test_interthread_messages();
12075 test_message_conversion();
12076 test_accelerators();
12077 test_timers();
12078 test_timers_no_wnd();
12079 if (hCBT_hook) test_set_hook();
12080 test_DestroyWindow();
12081 test_DispatchMessage();
12082 test_SendMessageTimeout();
12083 test_edit_messages();
12084 test_quit_message();
12085 test_SetActiveWindow();
12086
12087 if (!pTrackMouseEvent)
12088 win_skip("TrackMouseEvent is not available\n");
12089 else
12090 test_TrackMouseEvent();
12091
12092 test_SetWindowRgn();
12093 test_sys_menu();
12094 test_dialog_messages();
12095 test_nullCallback();
12096 test_dbcs_wm_char();
12097 test_menu_messages();
12098 test_paintingloop();
12099 test_defwinproc();
12100 test_clipboard_viewers();
12101 /* keep it the last test, under Windows it tends to break the tests
12102 * which rely on active/foreground windows being correct.
12103 */
12104 test_SetForegroundWindow();
12105
12106 UnhookWindowsHookEx(hCBT_hook);
12107 if (pUnhookWinEvent && hEvent_hook)
12108 {
12109 ret = pUnhookWinEvent(hEvent_hook);
12110 ok( ret, "UnhookWinEvent error %d\n", GetLastError());
12111 SetLastError(0xdeadbeef);
12112 ok(!pUnhookWinEvent(hEvent_hook), "UnhookWinEvent succeeded\n");
12113 ok(GetLastError() == ERROR_INVALID_HANDLE || /* Win2k */
12114 GetLastError() == 0xdeadbeef, /* Win9x */
12115 "unexpected error %d\n", GetLastError());
12116 }
12117 }